diff options
author | Dianne Hackborn <hackbod@google.com> | 2015-11-02 13:43:29 -0800 |
---|---|---|
committer | The Android Automerger <android-build@google.com> | 2015-11-03 14:35:16 -0800 |
commit | 423244469797cbaccd66f5ed210841647d7072e8 (patch) | |
tree | ee1d1177550ef0c4a9fbf34200527ad4c314429f /services/usage/java | |
parent | 73546bb6d6b0854ed1774569d9537f6fa242311b (diff) | |
download | frameworks_base-423244469797cbaccd66f5ed210841647d7072e8.zip frameworks_base-423244469797cbaccd66f5ed210841647d7072e8.tar.gz frameworks_base-423244469797cbaccd66f5ed210841647d7072e8.tar.bz2 |
Fix issue #25357209: Could not send SMS or MMS messages, had to reboot
I think what probably happened is that since we only report an app
going in to the "interaction" state as an interaction event to usage
stats, apps that sit around in that state forever will only see one
interaction at the start and never again. So usage stats could start
thinking they are idle.
Fix this by having the activity manager report an interaction event
for such long running applications at least once a day.
Also, because it is correct and for paranoia by protected us another
way, system uids should never go in to standby.
Change-Id: I8a3805bfca86cbe78560488a649ecd07427da99a
Diffstat (limited to 'services/usage/java')
-rw-r--r-- | services/usage/java/com/android/server/usage/UsageStatsService.java | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/services/usage/java/com/android/server/usage/UsageStatsService.java b/services/usage/java/com/android/server/usage/UsageStatsService.java index 5ad796f..2b8afba 100644 --- a/services/usage/java/com/android/server/usage/UsageStatsService.java +++ b/services/usage/java/com/android/server/usage/UsageStatsService.java @@ -385,9 +385,11 @@ public class UsageStatsService extends SystemService implements timeNow); final int packageCount = packages.size(); for (int p = 0; p < packageCount; p++) { - final String packageName = packages.get(p).packageName; - final boolean isIdle = isAppIdleFiltered(packageName, userId, service, timeNow, - screenOnTime); + final PackageInfo pi = packages.get(p); + final String packageName = pi.packageName; + final boolean isIdle = isAppIdleFiltered(packageName, + UserHandle.getAppId(pi.applicationInfo.uid), + userId, service, timeNow, screenOnTime); mHandler.sendMessage(mHandler.obtainMessage(MSG_INFORM_LISTENERS, userId, isIdle ? 1 : 0, packageName)); mAppIdleHistory.addEntry(packageName, userId, isIdle, timeNow); @@ -769,10 +771,17 @@ public class UsageStatsService extends SystemService implements if (mAppIdleParoled) { return false; } - return isAppIdleFiltered(packageName, userId, timeNow); + try { + ApplicationInfo ai = getContext().getPackageManager().getApplicationInfo(packageName, + PackageManager.GET_UNINSTALLED_PACKAGES + | PackageManager.GET_DISABLED_COMPONENTS); + return isAppIdleFiltered(packageName, ai.uid, userId, timeNow); + } catch (PackageManager.NameNotFoundException e) { + } + return false; } - boolean isAppIdleFiltered(String packageName, int userId, long timeNow) { + boolean isAppIdleFiltered(String packageName, int uidForAppId, int userId, long timeNow) { final UserUsageStatsService userService; final long screenOnTime; synchronized (mLock) { @@ -782,7 +791,8 @@ public class UsageStatsService extends SystemService implements userService = getUserDataAndInitializeIfNeededLocked(userId, timeNow); screenOnTime = getScreenOnTimeLocked(timeNow); } - return isAppIdleFiltered(packageName, userId, userService, timeNow, screenOnTime); + return isAppIdleFiltered(packageName, UserHandle.getAppId(uidForAppId), userId, + userService, timeNow, screenOnTime); } /** @@ -791,14 +801,22 @@ public class UsageStatsService extends SystemService implements * This happens if the device is plugged in or temporarily allowed to make exceptions. * Called by interface impls. */ - private boolean isAppIdleFiltered(String packageName, int userId, + private boolean isAppIdleFiltered(String packageName, int appId, int userId, UserUsageStatsService userService, long timeNow, long screenOnTime) { if (packageName == null) return false; // If not enabled at all, of course nobody is ever idle. if (!mAppIdleEnabled) { return false; } - if (packageName.equals("android")) return false; + if (appId < Process.FIRST_APPLICATION_UID) { + // System uids never go idle. + return false; + } + if (packageName.equals("android")) { + // Nor does the framework (which should be redundant with the above, but for MR1 we will + // retain this for safety). + return false; + } try { // We allow all whitelisted apps, including those that don't want to be whitelisted // for idle mode, because app idle (aka app standby) is really not as big an issue @@ -865,8 +883,8 @@ public class UsageStatsService extends SystemService implements ApplicationInfo ai = apps.get(i); // Check whether this app is idle. - boolean idle = isAppIdleFiltered(ai.packageName, userId, userService, timeNow, - screenOnTime); + boolean idle = isAppIdleFiltered(ai.packageName, UserHandle.getAppId(ai.uid), + userId, userService, timeNow, screenOnTime); int index = uidStates.indexOfKey(ai.uid); if (index < 0) { @@ -1352,8 +1370,8 @@ public class UsageStatsService extends SystemService implements } @Override - public boolean isAppIdle(String packageName, int userId) { - return UsageStatsService.this.isAppIdleFiltered(packageName, userId, -1); + public boolean isAppIdle(String packageName, int uidForAppId, int userId) { + return UsageStatsService.this.isAppIdleFiltered(packageName, uidForAppId, userId, -1); } @Override |