Loading services/usage/java/com/android/server/usage/AppIdleHistory.java +13 −1 Original line number Original line Diff line number Diff line Loading @@ -340,15 +340,27 @@ public class AppIdleHistory { public void setAppStandbyBucket(String packageName, int userId, long elapsedRealtime, public void setAppStandbyBucket(String packageName, int userId, long elapsedRealtime, int bucket, int reason) { int bucket, int reason) { setAppStandbyBucket(packageName, userId, elapsedRealtime, bucket, reason, false); } public void setAppStandbyBucket(String packageName, int userId, long elapsedRealtime, int bucket, int reason, boolean resetTimeout) { ArrayMap<String, AppUsageHistory> userHistory = getUserHistory(userId); ArrayMap<String, AppUsageHistory> userHistory = getUserHistory(userId); AppUsageHistory appUsageHistory = AppUsageHistory appUsageHistory = getPackageHistory(userHistory, packageName, elapsedRealtime, true); getPackageHistory(userHistory, packageName, elapsedRealtime, true); appUsageHistory.currentBucket = bucket; appUsageHistory.currentBucket = bucket; appUsageHistory.bucketingReason = reason; appUsageHistory.bucketingReason = reason; final long elapsed = getElapsedTime(elapsedRealtime); if ((reason & REASON_MAIN_MASK) == REASON_MAIN_PREDICTED) { if ((reason & REASON_MAIN_MASK) == REASON_MAIN_PREDICTED) { appUsageHistory.lastPredictedTime = getElapsedTime(elapsedRealtime); appUsageHistory.lastPredictedTime = elapsed; appUsageHistory.lastPredictedBucket = bucket; appUsageHistory.lastPredictedBucket = bucket; } } if (resetTimeout) { appUsageHistory.bucketActiveTimeoutTime = elapsed; appUsageHistory.bucketWorkingSetTimeoutTime = elapsed; } if (DEBUG) { if (DEBUG) { Slog.d(TAG, "Moved " + packageName + " to bucket=" + appUsageHistory.currentBucket Slog.d(TAG, "Moved " + packageName + " to bucket=" + appUsageHistory.currentBucket + ", reason=0x0" + Integer.toHexString(appUsageHistory.bucketingReason)); + ", reason=0x0" + Integer.toHexString(appUsageHistory.bucketingReason)); Loading services/usage/java/com/android/server/usage/AppStandbyController.java +9 −1 Original line number Original line Diff line number Diff line Loading @@ -113,6 +113,9 @@ import java.util.concurrent.CountDownLatch; /** /** * Manages the standby state of an app, listening to various events. * Manages the standby state of an app, listening to various events. * * Unit test: atest ${ANDROID_BUILD_TOP}/frameworks/base/services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java */ */ public class AppStandbyController { public class AppStandbyController { Loading Loading @@ -1106,6 +1109,11 @@ public class AppStandbyController { void setAppStandbyBucket(String packageName, int userId, @StandbyBuckets int newBucket, void setAppStandbyBucket(String packageName, int userId, @StandbyBuckets int newBucket, int reason, long elapsedRealtime) { int reason, long elapsedRealtime) { setAppStandbyBucket(packageName, userId, newBucket, reason, elapsedRealtime, false); } void setAppStandbyBucket(String packageName, int userId, @StandbyBuckets int newBucket, int reason, long elapsedRealtime, boolean resetTimeout) { synchronized (mAppIdleLock) { synchronized (mAppIdleLock) { AppIdleHistory.AppUsageHistory app = mAppIdleHistory.getAppUsageHistory(packageName, AppIdleHistory.AppUsageHistory app = mAppIdleHistory.getAppUsageHistory(packageName, userId, elapsedRealtime); userId, elapsedRealtime); Loading Loading @@ -1155,7 +1163,7 @@ public class AppStandbyController { } } mAppIdleHistory.setAppStandbyBucket(packageName, userId, elapsedRealtime, newBucket, mAppIdleHistory.setAppStandbyBucket(packageName, userId, elapsedRealtime, newBucket, reason); reason, resetTimeout); } } maybeInformListeners(packageName, userId, elapsedRealtime, newBucket, reason, false); maybeInformListeners(packageName, userId, elapsedRealtime, newBucket, reason, false); } } Loading services/usage/java/com/android/server/usage/UsageStatsService.java +3 −2 Original line number Original line Diff line number Diff line Loading @@ -900,6 +900,7 @@ public class UsageStatsService extends SystemService implements } catch (RemoteException re) { } catch (RemoteException re) { throw re.rethrowFromSystemServer(); throw re.rethrowFromSystemServer(); } } final boolean shellCaller = callingUid == 0 || callingUid == Process.SHELL_UID; final boolean systemCaller = UserHandle.isCore(callingUid); final boolean systemCaller = UserHandle.isCore(callingUid); final int reason = systemCaller final int reason = systemCaller ? UsageStatsManager.REASON_MAIN_FORCED ? UsageStatsManager.REASON_MAIN_FORCED Loading @@ -918,7 +919,7 @@ public class UsageStatsService extends SystemService implements + ")"); + ")"); } } mAppStandby.setAppStandbyBucket(packageName, userId, bucket, reason, mAppStandby.setAppStandbyBucket(packageName, userId, bucket, reason, SystemClock.elapsedRealtime()); SystemClock.elapsedRealtime(), shellCaller); } finally { } finally { Binder.restoreCallingIdentity(token); Binder.restoreCallingIdentity(token); } } Loading Loading @@ -985,7 +986,7 @@ public class UsageStatsService extends SystemService implements throw new IllegalArgumentException("Cannot set your own standby bucket"); throw new IllegalArgumentException("Cannot set your own standby bucket"); } } mAppStandby.setAppStandbyBucket(packageName, userId, bucket, reason, mAppStandby.setAppStandbyBucket(packageName, userId, bucket, reason, elapsedRealtime); elapsedRealtime, shellCaller); } } } finally { } finally { Binder.restoreCallingIdentity(token); Binder.restoreCallingIdentity(token); Loading Loading
services/usage/java/com/android/server/usage/AppIdleHistory.java +13 −1 Original line number Original line Diff line number Diff line Loading @@ -340,15 +340,27 @@ public class AppIdleHistory { public void setAppStandbyBucket(String packageName, int userId, long elapsedRealtime, public void setAppStandbyBucket(String packageName, int userId, long elapsedRealtime, int bucket, int reason) { int bucket, int reason) { setAppStandbyBucket(packageName, userId, elapsedRealtime, bucket, reason, false); } public void setAppStandbyBucket(String packageName, int userId, long elapsedRealtime, int bucket, int reason, boolean resetTimeout) { ArrayMap<String, AppUsageHistory> userHistory = getUserHistory(userId); ArrayMap<String, AppUsageHistory> userHistory = getUserHistory(userId); AppUsageHistory appUsageHistory = AppUsageHistory appUsageHistory = getPackageHistory(userHistory, packageName, elapsedRealtime, true); getPackageHistory(userHistory, packageName, elapsedRealtime, true); appUsageHistory.currentBucket = bucket; appUsageHistory.currentBucket = bucket; appUsageHistory.bucketingReason = reason; appUsageHistory.bucketingReason = reason; final long elapsed = getElapsedTime(elapsedRealtime); if ((reason & REASON_MAIN_MASK) == REASON_MAIN_PREDICTED) { if ((reason & REASON_MAIN_MASK) == REASON_MAIN_PREDICTED) { appUsageHistory.lastPredictedTime = getElapsedTime(elapsedRealtime); appUsageHistory.lastPredictedTime = elapsed; appUsageHistory.lastPredictedBucket = bucket; appUsageHistory.lastPredictedBucket = bucket; } } if (resetTimeout) { appUsageHistory.bucketActiveTimeoutTime = elapsed; appUsageHistory.bucketWorkingSetTimeoutTime = elapsed; } if (DEBUG) { if (DEBUG) { Slog.d(TAG, "Moved " + packageName + " to bucket=" + appUsageHistory.currentBucket Slog.d(TAG, "Moved " + packageName + " to bucket=" + appUsageHistory.currentBucket + ", reason=0x0" + Integer.toHexString(appUsageHistory.bucketingReason)); + ", reason=0x0" + Integer.toHexString(appUsageHistory.bucketingReason)); Loading
services/usage/java/com/android/server/usage/AppStandbyController.java +9 −1 Original line number Original line Diff line number Diff line Loading @@ -113,6 +113,9 @@ import java.util.concurrent.CountDownLatch; /** /** * Manages the standby state of an app, listening to various events. * Manages the standby state of an app, listening to various events. * * Unit test: atest ${ANDROID_BUILD_TOP}/frameworks/base/services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java */ */ public class AppStandbyController { public class AppStandbyController { Loading Loading @@ -1106,6 +1109,11 @@ public class AppStandbyController { void setAppStandbyBucket(String packageName, int userId, @StandbyBuckets int newBucket, void setAppStandbyBucket(String packageName, int userId, @StandbyBuckets int newBucket, int reason, long elapsedRealtime) { int reason, long elapsedRealtime) { setAppStandbyBucket(packageName, userId, newBucket, reason, elapsedRealtime, false); } void setAppStandbyBucket(String packageName, int userId, @StandbyBuckets int newBucket, int reason, long elapsedRealtime, boolean resetTimeout) { synchronized (mAppIdleLock) { synchronized (mAppIdleLock) { AppIdleHistory.AppUsageHistory app = mAppIdleHistory.getAppUsageHistory(packageName, AppIdleHistory.AppUsageHistory app = mAppIdleHistory.getAppUsageHistory(packageName, userId, elapsedRealtime); userId, elapsedRealtime); Loading Loading @@ -1155,7 +1163,7 @@ public class AppStandbyController { } } mAppIdleHistory.setAppStandbyBucket(packageName, userId, elapsedRealtime, newBucket, mAppIdleHistory.setAppStandbyBucket(packageName, userId, elapsedRealtime, newBucket, reason); reason, resetTimeout); } } maybeInformListeners(packageName, userId, elapsedRealtime, newBucket, reason, false); maybeInformListeners(packageName, userId, elapsedRealtime, newBucket, reason, false); } } Loading
services/usage/java/com/android/server/usage/UsageStatsService.java +3 −2 Original line number Original line Diff line number Diff line Loading @@ -900,6 +900,7 @@ public class UsageStatsService extends SystemService implements } catch (RemoteException re) { } catch (RemoteException re) { throw re.rethrowFromSystemServer(); throw re.rethrowFromSystemServer(); } } final boolean shellCaller = callingUid == 0 || callingUid == Process.SHELL_UID; final boolean systemCaller = UserHandle.isCore(callingUid); final boolean systemCaller = UserHandle.isCore(callingUid); final int reason = systemCaller final int reason = systemCaller ? UsageStatsManager.REASON_MAIN_FORCED ? UsageStatsManager.REASON_MAIN_FORCED Loading @@ -918,7 +919,7 @@ public class UsageStatsService extends SystemService implements + ")"); + ")"); } } mAppStandby.setAppStandbyBucket(packageName, userId, bucket, reason, mAppStandby.setAppStandbyBucket(packageName, userId, bucket, reason, SystemClock.elapsedRealtime()); SystemClock.elapsedRealtime(), shellCaller); } finally { } finally { Binder.restoreCallingIdentity(token); Binder.restoreCallingIdentity(token); } } Loading Loading @@ -985,7 +986,7 @@ public class UsageStatsService extends SystemService implements throw new IllegalArgumentException("Cannot set your own standby bucket"); throw new IllegalArgumentException("Cannot set your own standby bucket"); } } mAppStandby.setAppStandbyBucket(packageName, userId, bucket, reason, mAppStandby.setAppStandbyBucket(packageName, userId, bucket, reason, elapsedRealtime); elapsedRealtime, shellCaller); } } } finally { } finally { Binder.restoreCallingIdentity(token); Binder.restoreCallingIdentity(token); Loading