Loading core/java/android/app/usage/UsageStatsManagerInternal.java +2 −1 Original line number Diff line number Diff line Loading @@ -71,10 +71,11 @@ public abstract class UsageStatsManagerInternal { * Could be hours, could be days, who knows? * * @param packageName * @param uidForAppId The uid of the app, which will be used for its app id * @param userId * @return */ public abstract boolean isAppIdle(String packageName, int userId); public abstract boolean isAppIdle(String packageName, int uidForAppId, int userId); /** * Returns all of the uids for a given user where all packages associating with that uid Loading services/core/java/com/android/server/am/ActivityManagerService.java +26 −11 Original line number Diff line number Diff line Loading @@ -368,6 +368,10 @@ public final class ActivityManagerService extends ActivityManagerNative // we will consider it to be doing interaction for usage stats. static final int SERVICE_USAGE_INTERACTION_TIME = 30*60*1000; // Maximum amount of time we will allow to elapse before re-reporting usage stats // interaction with foreground processes. static final long USAGE_STATS_INTERACTION_INTERVAL = 24*60*60*1000L; // Maximum number of users we allow to be running at a time. static final int MAX_RUNNING_USERS = 3; Loading Loading @@ -18656,7 +18660,8 @@ public final class ActivityManagerService extends ActivityManagerNative } } private final boolean applyOomAdjLocked(ProcessRecord app, boolean doingAll, long now) { private final boolean applyOomAdjLocked(ProcessRecord app, boolean doingAll, long now, long nowElapsed) { boolean success = true; if (app.curRawAdj != app.setRawAdj) { Loading Loading @@ -18771,14 +18776,14 @@ public final class ActivityManagerService extends ActivityManagerNative BatteryStatsImpl stats = mBatteryStatsService.getActiveStatistics(); synchronized (stats) { app.lastWakeTime = stats.getProcessWakeTime(app.info.uid, app.pid, SystemClock.elapsedRealtime()); app.pid, nowElapsed); } app.lastCpuTime = app.curCpuTime; } // Inform UsageStats of important process state change // Must be called before updating setProcState maybeUpdateUsageStatsLocked(app); maybeUpdateUsageStatsLocked(app, nowElapsed); app.setProcState = app.curProcState; if (app.setProcState >= ActivityManager.PROCESS_STATE_HOME) { Loading @@ -18789,6 +18794,11 @@ public final class ActivityManagerService extends ActivityManagerNative } else { app.procStateChanged = true; } } else if (app.reportedInteraction && (nowElapsed-app.interactionEventTime) > USAGE_STATS_INTERACTION_INTERVAL) { // For apps that sit around for a long time in the interactive state, we need // to report this at least once a day so they don't go idle. maybeUpdateUsageStatsLocked(app, nowElapsed); } if (changes != 0) { Loading Loading @@ -18883,7 +18893,7 @@ public final class ActivityManagerService extends ActivityManagerNative } } private void maybeUpdateUsageStatsLocked(ProcessRecord app) { private void maybeUpdateUsageStatsLocked(ProcessRecord app, long nowElapsed) { if (DEBUG_USAGE_STATS) { Slog.d(TAG, "Checking proc [" + Arrays.toString(app.getPackageList()) + "] state changes: old = " + app.setProcState + ", new = " Loading @@ -18900,19 +18910,20 @@ public final class ActivityManagerService extends ActivityManagerNative isInteraction = true; app.fgInteractionTime = 0; } else if (app.curProcState <= ActivityManager.PROCESS_STATE_TOP_SLEEPING) { final long now = SystemClock.elapsedRealtime(); if (app.fgInteractionTime == 0) { app.fgInteractionTime = now; app.fgInteractionTime = nowElapsed; isInteraction = false; } else { isInteraction = now > app.fgInteractionTime + SERVICE_USAGE_INTERACTION_TIME; isInteraction = nowElapsed > app.fgInteractionTime + SERVICE_USAGE_INTERACTION_TIME; } } else { isInteraction = app.curProcState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND; app.fgInteractionTime = 0; } if (isInteraction && !app.reportedInteraction) { if (isInteraction && (!app.reportedInteraction || (nowElapsed-app.interactionEventTime) > USAGE_STATS_INTERACTION_INTERVAL)) { app.interactionEventTime = nowElapsed; String[] packages = app.getPackageList(); if (packages != null) { for (int i = 0; i < packages.length; i++) { Loading @@ -18922,6 +18933,9 @@ public final class ActivityManagerService extends ActivityManagerNative } } app.reportedInteraction = isInteraction; if (!isInteraction) { app.interactionEventTime = 0; } } private final void setProcessTrackerStateLocked(ProcessRecord proc, int memFactor, long now) { Loading @@ -18944,7 +18958,7 @@ public final class ActivityManagerService extends ActivityManagerNative computeOomAdjLocked(app, cachedAdj, TOP_APP, doingAll, now); return applyOomAdjLocked(app, doingAll, now); return applyOomAdjLocked(app, doingAll, now, SystemClock.elapsedRealtime()); } final void updateProcessForegroundLocked(ProcessRecord proc, boolean isForeground, Loading Loading @@ -19036,6 +19050,7 @@ public final class ActivityManagerService extends ActivityManagerNative final ActivityRecord TOP_ACT = resumedAppLocked(); final ProcessRecord TOP_APP = TOP_ACT != null ? TOP_ACT.app : null; final long now = SystemClock.uptimeMillis(); final long nowElapsed = SystemClock.elapsedRealtime(); final long oldTime = now - ProcessList.MAX_EMPTY_TIME; final int N = mLruProcesses.size(); Loading Loading @@ -19162,7 +19177,7 @@ public final class ActivityManagerService extends ActivityManagerNative } } applyOomAdjLocked(app, true, now); applyOomAdjLocked(app, true, now, nowElapsed); // Count the number of process types. switch (app.curProcState) { services/core/java/com/android/server/am/ProcessRecord.java +5 −0 Original line number Diff line number Diff line Loading @@ -114,6 +114,7 @@ final class ProcessRecord { boolean killed; // True once we know the process has been killed boolean procStateChanged; // Keep track of whether we changed 'setAdj'. boolean reportedInteraction;// Whether we have told usage stats about it being an interaction long interactionEventTime; // The time we sent the last interaction event long fgInteractionTime; // When we became foreground for interaction purposes String waitingToKill; // Process is waiting to be killed when in the bg, and reason IBinder forcingToForeground;// Token that is forcing this process to be foreground Loading Loading @@ -297,6 +298,10 @@ final class ProcessRecord { if (reportedInteraction || fgInteractionTime != 0) { pw.print(prefix); pw.print("reportedInteraction="); pw.print(reportedInteraction); if (interactionEventTime != 0) { pw.print(" time="); TimeUtils.formatDuration(interactionEventTime, SystemClock.elapsedRealtime(), pw); } if (fgInteractionTime != 0) { pw.print(" fgInteractionTime="); TimeUtils.formatDuration(fgInteractionTime, SystemClock.elapsedRealtime(), pw); Loading services/core/java/com/android/server/content/AppIdleMonitor.java +2 −2 Original line number Diff line number Diff line Loading @@ -50,8 +50,8 @@ class AppIdleMonitor extends AppIdleStateChangeListener { } } boolean isAppIdle(String packageName, int userId) { return !mAppIdleParoleOn && mUsageStats.isAppIdle(packageName, userId); boolean isAppIdle(String packageName, int uidForAppId, int userId) { return !mAppIdleParoleOn && mUsageStats.isAppIdle(packageName, uidForAppId, userId); } @Override Loading services/core/java/com/android/server/content/SyncManager.java +11 −2 Original line number Diff line number Diff line Loading @@ -2623,9 +2623,18 @@ public class SyncManager { continue; } String packageName = getPackageName(op.target); ApplicationInfo ai = null; if (packageName != null) { try { ai = mContext.getPackageManager().getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_DISABLED_COMPONENTS); } catch (NameNotFoundException e) { } } // If app is considered idle, then skip for now and backoff if (packageName != null && mAppIdleMonitor.isAppIdle(packageName, op.target.userId)) { if (ai != null && mAppIdleMonitor.isAppIdle(packageName, ai.uid, op.target.userId)) { increaseBackoffSetting(op); op.appIdle = true; if (isLoggable) { Loading Loading
core/java/android/app/usage/UsageStatsManagerInternal.java +2 −1 Original line number Diff line number Diff line Loading @@ -71,10 +71,11 @@ public abstract class UsageStatsManagerInternal { * Could be hours, could be days, who knows? * * @param packageName * @param uidForAppId The uid of the app, which will be used for its app id * @param userId * @return */ public abstract boolean isAppIdle(String packageName, int userId); public abstract boolean isAppIdle(String packageName, int uidForAppId, int userId); /** * Returns all of the uids for a given user where all packages associating with that uid Loading
services/core/java/com/android/server/am/ActivityManagerService.java +26 −11 Original line number Diff line number Diff line Loading @@ -368,6 +368,10 @@ public final class ActivityManagerService extends ActivityManagerNative // we will consider it to be doing interaction for usage stats. static final int SERVICE_USAGE_INTERACTION_TIME = 30*60*1000; // Maximum amount of time we will allow to elapse before re-reporting usage stats // interaction with foreground processes. static final long USAGE_STATS_INTERACTION_INTERVAL = 24*60*60*1000L; // Maximum number of users we allow to be running at a time. static final int MAX_RUNNING_USERS = 3; Loading Loading @@ -18656,7 +18660,8 @@ public final class ActivityManagerService extends ActivityManagerNative } } private final boolean applyOomAdjLocked(ProcessRecord app, boolean doingAll, long now) { private final boolean applyOomAdjLocked(ProcessRecord app, boolean doingAll, long now, long nowElapsed) { boolean success = true; if (app.curRawAdj != app.setRawAdj) { Loading Loading @@ -18771,14 +18776,14 @@ public final class ActivityManagerService extends ActivityManagerNative BatteryStatsImpl stats = mBatteryStatsService.getActiveStatistics(); synchronized (stats) { app.lastWakeTime = stats.getProcessWakeTime(app.info.uid, app.pid, SystemClock.elapsedRealtime()); app.pid, nowElapsed); } app.lastCpuTime = app.curCpuTime; } // Inform UsageStats of important process state change // Must be called before updating setProcState maybeUpdateUsageStatsLocked(app); maybeUpdateUsageStatsLocked(app, nowElapsed); app.setProcState = app.curProcState; if (app.setProcState >= ActivityManager.PROCESS_STATE_HOME) { Loading @@ -18789,6 +18794,11 @@ public final class ActivityManagerService extends ActivityManagerNative } else { app.procStateChanged = true; } } else if (app.reportedInteraction && (nowElapsed-app.interactionEventTime) > USAGE_STATS_INTERACTION_INTERVAL) { // For apps that sit around for a long time in the interactive state, we need // to report this at least once a day so they don't go idle. maybeUpdateUsageStatsLocked(app, nowElapsed); } if (changes != 0) { Loading Loading @@ -18883,7 +18893,7 @@ public final class ActivityManagerService extends ActivityManagerNative } } private void maybeUpdateUsageStatsLocked(ProcessRecord app) { private void maybeUpdateUsageStatsLocked(ProcessRecord app, long nowElapsed) { if (DEBUG_USAGE_STATS) { Slog.d(TAG, "Checking proc [" + Arrays.toString(app.getPackageList()) + "] state changes: old = " + app.setProcState + ", new = " Loading @@ -18900,19 +18910,20 @@ public final class ActivityManagerService extends ActivityManagerNative isInteraction = true; app.fgInteractionTime = 0; } else if (app.curProcState <= ActivityManager.PROCESS_STATE_TOP_SLEEPING) { final long now = SystemClock.elapsedRealtime(); if (app.fgInteractionTime == 0) { app.fgInteractionTime = now; app.fgInteractionTime = nowElapsed; isInteraction = false; } else { isInteraction = now > app.fgInteractionTime + SERVICE_USAGE_INTERACTION_TIME; isInteraction = nowElapsed > app.fgInteractionTime + SERVICE_USAGE_INTERACTION_TIME; } } else { isInteraction = app.curProcState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND; app.fgInteractionTime = 0; } if (isInteraction && !app.reportedInteraction) { if (isInteraction && (!app.reportedInteraction || (nowElapsed-app.interactionEventTime) > USAGE_STATS_INTERACTION_INTERVAL)) { app.interactionEventTime = nowElapsed; String[] packages = app.getPackageList(); if (packages != null) { for (int i = 0; i < packages.length; i++) { Loading @@ -18922,6 +18933,9 @@ public final class ActivityManagerService extends ActivityManagerNative } } app.reportedInteraction = isInteraction; if (!isInteraction) { app.interactionEventTime = 0; } } private final void setProcessTrackerStateLocked(ProcessRecord proc, int memFactor, long now) { Loading @@ -18944,7 +18958,7 @@ public final class ActivityManagerService extends ActivityManagerNative computeOomAdjLocked(app, cachedAdj, TOP_APP, doingAll, now); return applyOomAdjLocked(app, doingAll, now); return applyOomAdjLocked(app, doingAll, now, SystemClock.elapsedRealtime()); } final void updateProcessForegroundLocked(ProcessRecord proc, boolean isForeground, Loading Loading @@ -19036,6 +19050,7 @@ public final class ActivityManagerService extends ActivityManagerNative final ActivityRecord TOP_ACT = resumedAppLocked(); final ProcessRecord TOP_APP = TOP_ACT != null ? TOP_ACT.app : null; final long now = SystemClock.uptimeMillis(); final long nowElapsed = SystemClock.elapsedRealtime(); final long oldTime = now - ProcessList.MAX_EMPTY_TIME; final int N = mLruProcesses.size(); Loading Loading @@ -19162,7 +19177,7 @@ public final class ActivityManagerService extends ActivityManagerNative } } applyOomAdjLocked(app, true, now); applyOomAdjLocked(app, true, now, nowElapsed); // Count the number of process types. switch (app.curProcState) {
services/core/java/com/android/server/am/ProcessRecord.java +5 −0 Original line number Diff line number Diff line Loading @@ -114,6 +114,7 @@ final class ProcessRecord { boolean killed; // True once we know the process has been killed boolean procStateChanged; // Keep track of whether we changed 'setAdj'. boolean reportedInteraction;// Whether we have told usage stats about it being an interaction long interactionEventTime; // The time we sent the last interaction event long fgInteractionTime; // When we became foreground for interaction purposes String waitingToKill; // Process is waiting to be killed when in the bg, and reason IBinder forcingToForeground;// Token that is forcing this process to be foreground Loading Loading @@ -297,6 +298,10 @@ final class ProcessRecord { if (reportedInteraction || fgInteractionTime != 0) { pw.print(prefix); pw.print("reportedInteraction="); pw.print(reportedInteraction); if (interactionEventTime != 0) { pw.print(" time="); TimeUtils.formatDuration(interactionEventTime, SystemClock.elapsedRealtime(), pw); } if (fgInteractionTime != 0) { pw.print(" fgInteractionTime="); TimeUtils.formatDuration(fgInteractionTime, SystemClock.elapsedRealtime(), pw); Loading
services/core/java/com/android/server/content/AppIdleMonitor.java +2 −2 Original line number Diff line number Diff line Loading @@ -50,8 +50,8 @@ class AppIdleMonitor extends AppIdleStateChangeListener { } } boolean isAppIdle(String packageName, int userId) { return !mAppIdleParoleOn && mUsageStats.isAppIdle(packageName, userId); boolean isAppIdle(String packageName, int uidForAppId, int userId) { return !mAppIdleParoleOn && mUsageStats.isAppIdle(packageName, uidForAppId, userId); } @Override Loading
services/core/java/com/android/server/content/SyncManager.java +11 −2 Original line number Diff line number Diff line Loading @@ -2623,9 +2623,18 @@ public class SyncManager { continue; } String packageName = getPackageName(op.target); ApplicationInfo ai = null; if (packageName != null) { try { ai = mContext.getPackageManager().getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_DISABLED_COMPONENTS); } catch (NameNotFoundException e) { } } // If app is considered idle, then skip for now and backoff if (packageName != null && mAppIdleMonitor.isAppIdle(packageName, op.target.userId)) { if (ai != null && mAppIdleMonitor.isAppIdle(packageName, ai.uid, op.target.userId)) { increaseBackoffSetting(op); op.appIdle = true; if (isLoggable) { Loading