Loading services/core/java/com/android/server/am/ActivityManagerService.java +13 −3 Original line number Diff line number Diff line Loading @@ -2484,7 +2484,11 @@ public class ActivityManagerService extends IActivityManager.Stub mAppProfiler = new AppProfiler(this, BackgroundThread.getHandler().getLooper(), new LowMemDetector(this)); mPhantomProcessList = new PhantomProcessList(this); final Looper activityTaskLooper = DisplayThread.get().getLooper(); mProcessStateController = new ProcessStateController.Builder(this, mProcessList, activeUids) .setLockObject(this) .setActivityStateLooper(activityTaskLooper) .setTopProcessChangeCallback(this::updateTopAppListeners) .build(); mOomAdjuster = mProcessStateController.getOomAdjuster(); Loading Loading @@ -2527,7 +2531,7 @@ public class ActivityManagerService extends IActivityManager.Stub mActivityTaskManager = atm; mActivityTaskManager.initialize(mIntentFirewall, mPendingIntentController, DisplayThread.get().getLooper()); mProcessStateController, activityTaskLooper); mAtmInternal = LocalServices.getService(ActivityTaskManagerInternal.class); mHiddenApiBlacklist = new HiddenApiSettings(mHandler, mContext); Loading Loading @@ -15526,6 +15530,13 @@ public class ActivityManagerService extends IActivityManager.Stub ProcessRecord getTopApp() { final WindowProcessController wpc = mAtmInternal != null ? mAtmInternal.getTopApp() : null; final ProcessRecord r = wpc != null ? (ProcessRecord) wpc.mOwner : null; if (!Flags.pushActivityStateToOomadjuster()) { updateTopAppListeners(r); } return r; } void updateTopAppListeners(ProcessRecord r) { String pkg; int uid; if (r != null) { Loading Loading @@ -15557,7 +15568,6 @@ public class ActivityManagerService extends IActivityManager.Stub } } } return r; } /** services/core/java/com/android/server/am/OomAdjuster.java +90 −2 Original line number Diff line number Diff line Loading @@ -470,6 +470,30 @@ public abstract class OomAdjuster { /** Is memory level normal since last evaluation. */ boolean isLastMemoryLevelNormal(); /** The ProcessState to assign to the Top process. */ @ActivityManager.ProcessState int getTopProcessState(); /** Keyguard is in the process of unlocking. */ boolean isUnlocking(); /** The notification shade is expanded. */ boolean hasExpandedNotificationShade(); /** The current Top process. */ @Nullable ProcessRecord getTopProcess(); /** The current Home process. */ @Nullable ProcessRecord getHomeProcess(); /** The current Heavy Weight process. */ @Nullable ProcessRecord getHeavyWeightProcess(); /** The current process showing UI if the device is in doze. */ @Nullable ProcessRecord getShowingUiWhileDozingProcess(); /** The previous process that showed an activity. */ @Nullable ProcessRecord getPreviousProcess(); } boolean isChangeEnabled(@CachedCompatChangeId int cachedCompatChangeId, Loading Loading @@ -661,9 +685,9 @@ public abstract class OomAdjuster { @GuardedBy({"mService", "mProcLock"}) protected int enqueuePendingTopAppIfNecessaryLSP() { final int prevTopProcessState = mService.mAtmInternal.getTopProcessState(); final int prevTopProcessState = getTopProcessState(); mService.enqueuePendingTopAppIfNecessaryLocked(); final int topProcessState = mService.mAtmInternal.getTopProcessState(); final int topProcessState = getTopProcessState(); if (prevTopProcessState != topProcessState) { // Unlikely but possible: WM just updated the top process state, it may have // enqueued the new top app to the pending top UID list. Enqueue that one here too. Loading Loading @@ -1719,6 +1743,70 @@ public abstract class OomAdjuster { } } protected int getTopProcessState() { if (Flags.pushActivityStateToOomadjuster()) { return mGlobalState.getTopProcessState(); } else { return mService.mAtmInternal.getTopProcessState(); } } protected boolean useTopSchedGroupForTopProcess() { if (Flags.pushActivityStateToOomadjuster()) { if (mGlobalState.isUnlocking()) { // Keyguard is unlocking, suppress the top process priority for now. return false; } if (mGlobalState.hasExpandedNotificationShade()) { // The notification shade is occluding the top process, suppress top. return false; } return true; } else { return mService.mAtmInternal.useTopSchedGroupForTopProcess(); } } protected ProcessRecord getTopProcess() { if (Flags.pushActivityStateToOomadjuster()) { return mGlobalState.getTopProcess(); } else { return mService.getTopApp(); } } protected boolean isHomeProcess(ProcessRecord proc) { if (Flags.pushActivityStateToOomadjuster()) { return mGlobalState.getHomeProcess() == proc; } else { return proc.mState.getCachedIsHomeProcess(); } } protected boolean isHeavyWeightProcess(ProcessRecord proc) { if (Flags.pushActivityStateToOomadjuster()) { return mGlobalState.getHeavyWeightProcess() == proc; } else { return proc.mState.getCachedIsHeavyWeight(); } } protected boolean isVisibleDozeUiProcess(ProcessRecord proc) { if (Flags.pushActivityStateToOomadjuster()) { return mGlobalState.getShowingUiWhileDozingProcess() == proc; } else { return proc.getWindowProcessController().isShowingUiWhileDozing(); } } protected boolean isPreviousProcess(ProcessRecord proc) { if (Flags.pushActivityStateToOomadjuster()) { return mGlobalState.getPreviousProcess() == proc; } else { return proc.mState.getCachedIsPreviousProcess(); } } /** * @return The proposed change to the schedGroup. */ Loading services/core/java/com/android/server/am/OomAdjusterImpl.java +16 −17 Original line number Diff line number Diff line Loading @@ -705,8 +705,7 @@ public class OomAdjusterImpl extends OomAdjuster { @Override protected void performUpdateOomAdjLSP(@OomAdjReason int oomAdjReason) { final ProcessRecord topApp = mService.getTopApp(); mProcessStateCurTop = mService.mAtmInternal.getTopProcessState(); mProcessStateCurTop = getTopProcessState(); // Clear any pending ones because we are doing a full update now. mPendingProcessSet.clear(); Loading Loading @@ -746,7 +745,7 @@ public class OomAdjusterImpl extends OomAdjuster { */ @GuardedBy({"mService", "mProcLock"}) private void fullUpdateLSP(@OomAdjReason int oomAdjReason) { final ProcessRecord topApp = mService.getTopApp(); final ProcessRecord topApp = getTopProcess(); final long now = mInjector.getUptimeMillis(); final long nowElapsed = mInjector.getElapsedRealtimeMillis(); final long oldTime = now - mConstants.mMaxEmptyTimeMillis; Loading Loading @@ -819,7 +818,7 @@ public class OomAdjusterImpl extends OomAdjuster { */ @GuardedBy({"mService", "mProcLock"}) private void partialUpdateLSP(@OomAdjReason int oomAdjReason, ArraySet<ProcessRecord> targets) { final ProcessRecord topApp = mService.getTopApp(); final ProcessRecord topApp = getTopProcess(); final long now = mInjector.getUptimeMillis(); final long nowElapsed = mInjector.getElapsedRealtimeMillis(); final long oldTime = now - mConstants.mMaxEmptyTimeMillis; Loading Loading @@ -1196,7 +1195,7 @@ public class OomAdjusterImpl extends OomAdjuster { // sched group/proc state adjustment is below state.setSystemNoUi(false); state.setAdjType("pers-top-ui"); } else if (state.getCachedHasVisibleActivities()) { } else if (state.getHasVisibleActivities()) { state.setSystemNoUi(false); } if (!state.isSystemNoUi()) { Loading @@ -1204,7 +1203,7 @@ public class OomAdjusterImpl extends OomAdjuster { // screen on or animating, promote UI state.setCurProcState(ActivityManager.PROCESS_STATE_PERSISTENT_UI); state.setCurrentSchedulingGroup(SCHED_GROUP_TOP_APP); } else if (!app.getWindowProcessController().isShowingUiWhileDozing()) { } else if (!isVisibleDozeUiProcess(app)) { // screen off, restrict UI scheduling state.setCurProcState(PROCESS_STATE_BOUND_FOREGROUND_SERVICE); state.setCurrentSchedulingGroup(SCHED_GROUP_RESTRICTED); Loading @@ -1231,7 +1230,7 @@ public class OomAdjusterImpl extends OomAdjuster { if (app == topApp && PROCESS_STATE_CUR_TOP == PROCESS_STATE_TOP) { // The last app on the list is the foreground app. adj = FOREGROUND_APP_ADJ; if (mService.mAtmInternal.useTopSchedGroupForTopProcess()) { if (useTopSchedGroupForTopProcess()) { schedGroup = SCHED_GROUP_TOP_APP; state.setAdjType("top-activity"); } else { Loading Loading @@ -1313,20 +1312,20 @@ public class OomAdjusterImpl extends OomAdjuster { // Examine all non-top activities. boolean foregroundActivities = app == topApp; if (!foregroundActivities && state.getCachedHasActivities()) { if (!foregroundActivities && state.getHasActivities()) { state.computeOomAdjFromActivitiesIfNecessary(mTmpComputeOomAdjWindowCallback, adj, foregroundActivities, hasVisibleActivities, procState, schedGroup, appUid, logUid, PROCESS_STATE_CUR_TOP); adj = state.getCachedAdj(); foregroundActivities = state.getCachedForegroundActivities(); hasVisibleActivities = state.getCachedHasVisibleActivities(); hasVisibleActivities = state.getHasVisibleActivities(); procState = state.getCachedProcState(); schedGroup = state.getCachedSchedGroup(); state.setAdjType(state.getCachedAdjType()); } if (procState > PROCESS_STATE_CACHED_RECENT && state.getCachedHasRecentTasks()) { if (procState > PROCESS_STATE_CACHED_RECENT && state.getHasRecentTasks()) { procState = PROCESS_STATE_CACHED_RECENT; state.setAdjType("cch-rec"); if (DEBUG_OOM_ADJ_REASON || logUid == appUid) { Loading Loading @@ -1452,7 +1451,7 @@ public class OomAdjusterImpl extends OomAdjuster { } } if (state.getCachedIsHeavyWeight()) { if (isHeavyWeightProcess(app)) { if (adj > HEAVY_WEIGHT_APP_ADJ) { // We don't want to kill the current heavy-weight process. adj = HEAVY_WEIGHT_APP_ADJ; Loading @@ -1471,7 +1470,7 @@ public class OomAdjusterImpl extends OomAdjuster { } } if (state.getCachedIsHomeProcess()) { if (isHomeProcess(app)) { if (adj > HOME_APP_ADJ) { // This process is hosting what we currently consider to be the // home app, so we don't want to let it go into the background. Loading @@ -1490,7 +1489,7 @@ public class OomAdjusterImpl extends OomAdjuster { } } } if (state.getCachedIsPreviousProcess() && state.getCachedHasActivities()) { if (isPreviousProcess(app) && state.getHasActivities()) { // This was the previous process that showed UI to the user. We want to // try to keep it around more aggressively, to give a good experience // around switching between two apps. However, we don't want to keep the Loading Loading @@ -1580,7 +1579,7 @@ public class OomAdjusterImpl extends OomAdjuster { "Raise procstate to started service: " + app); } } if (!s.mKeepWarming && state.hasShownUi() && !state.getCachedIsHomeProcess()) { if (!s.mKeepWarming && state.hasShownUi() && !isHomeProcess(app)) { // If this process has shown some UI, let it immediately // go to the LRU list because it may be pretty heavy with // UI stuff. We'll tag it with a label just to help Loading Loading @@ -1922,7 +1921,7 @@ public class OomAdjusterImpl extends OomAdjuster { } // Not doing bind OOM management, so treat // this guy more like a started service. if (state.hasShownUi() && !state.getCachedIsHomeProcess()) { if (state.hasShownUi() && !isHomeProcess(app)) { // If this process has shown some UI, let it immediately // go to the LRU list because it may be pretty heavy with // UI stuff. We'll tag it with a label just to help Loading Loading @@ -1958,7 +1957,7 @@ public class OomAdjusterImpl extends OomAdjuster { // is less important than a state that can be actively running, then we don't // care about the binding as much as we care about letting this process get into // the LRU list to be killed and restarted if needed for memory. if (state.hasShownUi() && !state.getCachedIsHomeProcess() if (state.hasShownUi() && !isHomeProcess(app) && clientAdj > CACHING_UI_SERVICE_CLIENT_ADJ_THRESHOLD) { if (adj >= CACHED_APP_MIN_ADJ) { adjType = "cch-bound-ui-services"; Loading Loading @@ -2322,7 +2321,7 @@ public class OomAdjusterImpl extends OomAdjuster { String adjType = null; if (adj > clientAdj) { if (state.hasShownUi() && !state.getCachedIsHomeProcess() if (state.hasShownUi() && !isHomeProcess(app) && clientAdj > PERCEPTIBLE_APP_ADJ) { adjType = "cch-ui-provider"; } else { Loading services/core/java/com/android/server/am/ProcessStateController.java +350 −52 File changed.Preview size limit exceeded, changes collapsed. Show changes services/core/java/com/android/server/am/ProcessStateRecord.java +78 −4 Original line number Diff line number Diff line Loading @@ -385,6 +385,18 @@ final class ProcessStateRecord { @GuardedBy("mService") private @ElapsedRealtimeLong long mLastCachedTime; @GuardedBy("mService") private boolean mHasActivities = false; @GuardedBy("mService") private int mActivityStateFlags = ACTIVITY_STATE_FLAG_MASK_MIN_TASK_LAYER; @GuardedBy("mService") private long mPerceptibleTaskStoppedTimeMillis = Long.MIN_VALUE; @GuardedBy("mService") private boolean mHasRecentTask = false; // Below are the cached task info for OomAdjuster only private static final int VALUE_INVALID = -1; private static final int VALUE_FALSE = 0; Loading Loading @@ -962,6 +974,26 @@ final class ProcessStateRecord { mReachable = reachable; } @GuardedBy("mService") void setHasActivities(boolean hasActivities) { mHasActivities = hasActivities; } @GuardedBy("mService") void setActivityStateFlags(int flags) { mActivityStateFlags = flags; } @GuardedBy("mService") void setPerceptibleTaskStoppedTimeMillis(long uptimeMs) { mPerceptibleTaskStoppedTimeMillis = uptimeMs; } @GuardedBy("mService") void setHasRecentTask(boolean hasRecentTask) { mHasRecentTask = hasRecentTask; } @GuardedBy("mService") void resetCachedInfo() { mCachedHasActivities = VALUE_INVALID; Loading @@ -979,7 +1011,7 @@ final class ProcessStateRecord { } @GuardedBy("mService") boolean getCachedHasActivities() { private boolean getCachedHasActivities() { if (mCachedHasActivities == VALUE_INVALID) { mCachedHasActivities = mApp.getWindowProcessController().hasActivities() ? VALUE_TRUE : VALUE_FALSE; Loading @@ -992,6 +1024,15 @@ final class ProcessStateRecord { return mCachedHasActivities == VALUE_TRUE; } @GuardedBy("mService") boolean getHasActivities() { if (Flags.pushActivityStateToOomadjuster()) { return mHasActivities; } else { return getCachedHasActivities(); } } @GuardedBy("mService") boolean getCachedIsHeavyWeight() { if (mCachedIsHeavyWeight == VALUE_INVALID) { Loading @@ -1002,7 +1043,7 @@ final class ProcessStateRecord { } @GuardedBy("mService") boolean getCachedHasVisibleActivities() { private boolean getCachedHasVisibleActivities() { if (mCachedHasVisibleActivities == VALUE_INVALID) { mCachedHasVisibleActivities = mApp.getWindowProcessController().hasVisibleActivities() ? VALUE_TRUE : VALUE_FALSE; Loading @@ -1010,6 +1051,15 @@ final class ProcessStateRecord { return mCachedHasVisibleActivities == VALUE_TRUE; } @GuardedBy("mService") boolean getHasVisibleActivities() { if (Flags.pushActivityStateToOomadjuster()) { return (mActivityStateFlags & ACTIVITY_STATE_FLAG_IS_VISIBLE) != 0; } else { return getCachedHasVisibleActivities(); } } @GuardedBy("mService") boolean getCachedIsHomeProcess() { if (mCachedIsHomeProcess == VALUE_INVALID) { Loading Loading @@ -1043,6 +1093,15 @@ final class ProcessStateRecord { return mCachedHasRecentTasks == VALUE_TRUE; } @GuardedBy("mService") boolean getHasRecentTasks() { if (Flags.pushActivityStateToOomadjuster()) { return mHasRecentTask; } else { return getCachedHasRecentTasks(); } } @GuardedBy("mService") boolean getCachedIsReceivingBroadcast(int[] outSchedGroup) { if (mCachedIsReceivingBroadcast == VALUE_INVALID) { Loading Loading @@ -1078,7 +1137,12 @@ final class ProcessStateRecord { } callback.initialize(mApp, adj, foregroundActivities, hasVisibleActivities, procState, schedGroup, appUid, logUid, processCurTop); final int flags = mApp.getWindowProcessController().getActivityStateFlags(); final int flags; if (Flags.pushActivityStateToOomadjuster()) { flags = mActivityStateFlags; } else { flags = mApp.getWindowProcessController().getActivityStateFlags(); } if ((flags & ACTIVITY_STATE_FLAG_IS_VISIBLE) != 0) { callback.onVisibleActivity(flags); Loading @@ -1087,7 +1151,13 @@ final class ProcessStateRecord { } else if ((flags & ACTIVITY_STATE_FLAG_IS_STOPPING) != 0) { callback.onStoppingActivity((flags & ACTIVITY_STATE_FLAG_IS_STOPPING_FINISHING) != 0); } else { final long ts = mApp.getWindowProcessController().getPerceptibleTaskStoppedTimeMillis(); final long ts; if (Flags.pushActivityStateToOomadjuster()) { ts = mPerceptibleTaskStoppedTimeMillis; } else { ts = mApp.getWindowProcessController().getPerceptibleTaskStoppedTimeMillis(); } callback.onOtherActivity(ts); } Loading Loading @@ -1193,6 +1263,10 @@ final class ProcessStateRecord { for (int i = 0; i < mCachedCompatChanges.length; i++) { mCachedCompatChanges[i] = VALUE_INVALID; } mHasActivities = false; mActivityStateFlags = ACTIVITY_STATE_FLAG_MASK_MIN_TASK_LAYER; mPerceptibleTaskStoppedTimeMillis = Long.MIN_VALUE; mHasRecentTask = false; } @GuardedBy("mService") Loading Loading
services/core/java/com/android/server/am/ActivityManagerService.java +13 −3 Original line number Diff line number Diff line Loading @@ -2484,7 +2484,11 @@ public class ActivityManagerService extends IActivityManager.Stub mAppProfiler = new AppProfiler(this, BackgroundThread.getHandler().getLooper(), new LowMemDetector(this)); mPhantomProcessList = new PhantomProcessList(this); final Looper activityTaskLooper = DisplayThread.get().getLooper(); mProcessStateController = new ProcessStateController.Builder(this, mProcessList, activeUids) .setLockObject(this) .setActivityStateLooper(activityTaskLooper) .setTopProcessChangeCallback(this::updateTopAppListeners) .build(); mOomAdjuster = mProcessStateController.getOomAdjuster(); Loading Loading @@ -2527,7 +2531,7 @@ public class ActivityManagerService extends IActivityManager.Stub mActivityTaskManager = atm; mActivityTaskManager.initialize(mIntentFirewall, mPendingIntentController, DisplayThread.get().getLooper()); mProcessStateController, activityTaskLooper); mAtmInternal = LocalServices.getService(ActivityTaskManagerInternal.class); mHiddenApiBlacklist = new HiddenApiSettings(mHandler, mContext); Loading Loading @@ -15526,6 +15530,13 @@ public class ActivityManagerService extends IActivityManager.Stub ProcessRecord getTopApp() { final WindowProcessController wpc = mAtmInternal != null ? mAtmInternal.getTopApp() : null; final ProcessRecord r = wpc != null ? (ProcessRecord) wpc.mOwner : null; if (!Flags.pushActivityStateToOomadjuster()) { updateTopAppListeners(r); } return r; } void updateTopAppListeners(ProcessRecord r) { String pkg; int uid; if (r != null) { Loading Loading @@ -15557,7 +15568,6 @@ public class ActivityManagerService extends IActivityManager.Stub } } } return r; } /**
services/core/java/com/android/server/am/OomAdjuster.java +90 −2 Original line number Diff line number Diff line Loading @@ -470,6 +470,30 @@ public abstract class OomAdjuster { /** Is memory level normal since last evaluation. */ boolean isLastMemoryLevelNormal(); /** The ProcessState to assign to the Top process. */ @ActivityManager.ProcessState int getTopProcessState(); /** Keyguard is in the process of unlocking. */ boolean isUnlocking(); /** The notification shade is expanded. */ boolean hasExpandedNotificationShade(); /** The current Top process. */ @Nullable ProcessRecord getTopProcess(); /** The current Home process. */ @Nullable ProcessRecord getHomeProcess(); /** The current Heavy Weight process. */ @Nullable ProcessRecord getHeavyWeightProcess(); /** The current process showing UI if the device is in doze. */ @Nullable ProcessRecord getShowingUiWhileDozingProcess(); /** The previous process that showed an activity. */ @Nullable ProcessRecord getPreviousProcess(); } boolean isChangeEnabled(@CachedCompatChangeId int cachedCompatChangeId, Loading Loading @@ -661,9 +685,9 @@ public abstract class OomAdjuster { @GuardedBy({"mService", "mProcLock"}) protected int enqueuePendingTopAppIfNecessaryLSP() { final int prevTopProcessState = mService.mAtmInternal.getTopProcessState(); final int prevTopProcessState = getTopProcessState(); mService.enqueuePendingTopAppIfNecessaryLocked(); final int topProcessState = mService.mAtmInternal.getTopProcessState(); final int topProcessState = getTopProcessState(); if (prevTopProcessState != topProcessState) { // Unlikely but possible: WM just updated the top process state, it may have // enqueued the new top app to the pending top UID list. Enqueue that one here too. Loading Loading @@ -1719,6 +1743,70 @@ public abstract class OomAdjuster { } } protected int getTopProcessState() { if (Flags.pushActivityStateToOomadjuster()) { return mGlobalState.getTopProcessState(); } else { return mService.mAtmInternal.getTopProcessState(); } } protected boolean useTopSchedGroupForTopProcess() { if (Flags.pushActivityStateToOomadjuster()) { if (mGlobalState.isUnlocking()) { // Keyguard is unlocking, suppress the top process priority for now. return false; } if (mGlobalState.hasExpandedNotificationShade()) { // The notification shade is occluding the top process, suppress top. return false; } return true; } else { return mService.mAtmInternal.useTopSchedGroupForTopProcess(); } } protected ProcessRecord getTopProcess() { if (Flags.pushActivityStateToOomadjuster()) { return mGlobalState.getTopProcess(); } else { return mService.getTopApp(); } } protected boolean isHomeProcess(ProcessRecord proc) { if (Flags.pushActivityStateToOomadjuster()) { return mGlobalState.getHomeProcess() == proc; } else { return proc.mState.getCachedIsHomeProcess(); } } protected boolean isHeavyWeightProcess(ProcessRecord proc) { if (Flags.pushActivityStateToOomadjuster()) { return mGlobalState.getHeavyWeightProcess() == proc; } else { return proc.mState.getCachedIsHeavyWeight(); } } protected boolean isVisibleDozeUiProcess(ProcessRecord proc) { if (Flags.pushActivityStateToOomadjuster()) { return mGlobalState.getShowingUiWhileDozingProcess() == proc; } else { return proc.getWindowProcessController().isShowingUiWhileDozing(); } } protected boolean isPreviousProcess(ProcessRecord proc) { if (Flags.pushActivityStateToOomadjuster()) { return mGlobalState.getPreviousProcess() == proc; } else { return proc.mState.getCachedIsPreviousProcess(); } } /** * @return The proposed change to the schedGroup. */ Loading
services/core/java/com/android/server/am/OomAdjusterImpl.java +16 −17 Original line number Diff line number Diff line Loading @@ -705,8 +705,7 @@ public class OomAdjusterImpl extends OomAdjuster { @Override protected void performUpdateOomAdjLSP(@OomAdjReason int oomAdjReason) { final ProcessRecord topApp = mService.getTopApp(); mProcessStateCurTop = mService.mAtmInternal.getTopProcessState(); mProcessStateCurTop = getTopProcessState(); // Clear any pending ones because we are doing a full update now. mPendingProcessSet.clear(); Loading Loading @@ -746,7 +745,7 @@ public class OomAdjusterImpl extends OomAdjuster { */ @GuardedBy({"mService", "mProcLock"}) private void fullUpdateLSP(@OomAdjReason int oomAdjReason) { final ProcessRecord topApp = mService.getTopApp(); final ProcessRecord topApp = getTopProcess(); final long now = mInjector.getUptimeMillis(); final long nowElapsed = mInjector.getElapsedRealtimeMillis(); final long oldTime = now - mConstants.mMaxEmptyTimeMillis; Loading Loading @@ -819,7 +818,7 @@ public class OomAdjusterImpl extends OomAdjuster { */ @GuardedBy({"mService", "mProcLock"}) private void partialUpdateLSP(@OomAdjReason int oomAdjReason, ArraySet<ProcessRecord> targets) { final ProcessRecord topApp = mService.getTopApp(); final ProcessRecord topApp = getTopProcess(); final long now = mInjector.getUptimeMillis(); final long nowElapsed = mInjector.getElapsedRealtimeMillis(); final long oldTime = now - mConstants.mMaxEmptyTimeMillis; Loading Loading @@ -1196,7 +1195,7 @@ public class OomAdjusterImpl extends OomAdjuster { // sched group/proc state adjustment is below state.setSystemNoUi(false); state.setAdjType("pers-top-ui"); } else if (state.getCachedHasVisibleActivities()) { } else if (state.getHasVisibleActivities()) { state.setSystemNoUi(false); } if (!state.isSystemNoUi()) { Loading @@ -1204,7 +1203,7 @@ public class OomAdjusterImpl extends OomAdjuster { // screen on or animating, promote UI state.setCurProcState(ActivityManager.PROCESS_STATE_PERSISTENT_UI); state.setCurrentSchedulingGroup(SCHED_GROUP_TOP_APP); } else if (!app.getWindowProcessController().isShowingUiWhileDozing()) { } else if (!isVisibleDozeUiProcess(app)) { // screen off, restrict UI scheduling state.setCurProcState(PROCESS_STATE_BOUND_FOREGROUND_SERVICE); state.setCurrentSchedulingGroup(SCHED_GROUP_RESTRICTED); Loading @@ -1231,7 +1230,7 @@ public class OomAdjusterImpl extends OomAdjuster { if (app == topApp && PROCESS_STATE_CUR_TOP == PROCESS_STATE_TOP) { // The last app on the list is the foreground app. adj = FOREGROUND_APP_ADJ; if (mService.mAtmInternal.useTopSchedGroupForTopProcess()) { if (useTopSchedGroupForTopProcess()) { schedGroup = SCHED_GROUP_TOP_APP; state.setAdjType("top-activity"); } else { Loading Loading @@ -1313,20 +1312,20 @@ public class OomAdjusterImpl extends OomAdjuster { // Examine all non-top activities. boolean foregroundActivities = app == topApp; if (!foregroundActivities && state.getCachedHasActivities()) { if (!foregroundActivities && state.getHasActivities()) { state.computeOomAdjFromActivitiesIfNecessary(mTmpComputeOomAdjWindowCallback, adj, foregroundActivities, hasVisibleActivities, procState, schedGroup, appUid, logUid, PROCESS_STATE_CUR_TOP); adj = state.getCachedAdj(); foregroundActivities = state.getCachedForegroundActivities(); hasVisibleActivities = state.getCachedHasVisibleActivities(); hasVisibleActivities = state.getHasVisibleActivities(); procState = state.getCachedProcState(); schedGroup = state.getCachedSchedGroup(); state.setAdjType(state.getCachedAdjType()); } if (procState > PROCESS_STATE_CACHED_RECENT && state.getCachedHasRecentTasks()) { if (procState > PROCESS_STATE_CACHED_RECENT && state.getHasRecentTasks()) { procState = PROCESS_STATE_CACHED_RECENT; state.setAdjType("cch-rec"); if (DEBUG_OOM_ADJ_REASON || logUid == appUid) { Loading Loading @@ -1452,7 +1451,7 @@ public class OomAdjusterImpl extends OomAdjuster { } } if (state.getCachedIsHeavyWeight()) { if (isHeavyWeightProcess(app)) { if (adj > HEAVY_WEIGHT_APP_ADJ) { // We don't want to kill the current heavy-weight process. adj = HEAVY_WEIGHT_APP_ADJ; Loading @@ -1471,7 +1470,7 @@ public class OomAdjusterImpl extends OomAdjuster { } } if (state.getCachedIsHomeProcess()) { if (isHomeProcess(app)) { if (adj > HOME_APP_ADJ) { // This process is hosting what we currently consider to be the // home app, so we don't want to let it go into the background. Loading @@ -1490,7 +1489,7 @@ public class OomAdjusterImpl extends OomAdjuster { } } } if (state.getCachedIsPreviousProcess() && state.getCachedHasActivities()) { if (isPreviousProcess(app) && state.getHasActivities()) { // This was the previous process that showed UI to the user. We want to // try to keep it around more aggressively, to give a good experience // around switching between two apps. However, we don't want to keep the Loading Loading @@ -1580,7 +1579,7 @@ public class OomAdjusterImpl extends OomAdjuster { "Raise procstate to started service: " + app); } } if (!s.mKeepWarming && state.hasShownUi() && !state.getCachedIsHomeProcess()) { if (!s.mKeepWarming && state.hasShownUi() && !isHomeProcess(app)) { // If this process has shown some UI, let it immediately // go to the LRU list because it may be pretty heavy with // UI stuff. We'll tag it with a label just to help Loading Loading @@ -1922,7 +1921,7 @@ public class OomAdjusterImpl extends OomAdjuster { } // Not doing bind OOM management, so treat // this guy more like a started service. if (state.hasShownUi() && !state.getCachedIsHomeProcess()) { if (state.hasShownUi() && !isHomeProcess(app)) { // If this process has shown some UI, let it immediately // go to the LRU list because it may be pretty heavy with // UI stuff. We'll tag it with a label just to help Loading Loading @@ -1958,7 +1957,7 @@ public class OomAdjusterImpl extends OomAdjuster { // is less important than a state that can be actively running, then we don't // care about the binding as much as we care about letting this process get into // the LRU list to be killed and restarted if needed for memory. if (state.hasShownUi() && !state.getCachedIsHomeProcess() if (state.hasShownUi() && !isHomeProcess(app) && clientAdj > CACHING_UI_SERVICE_CLIENT_ADJ_THRESHOLD) { if (adj >= CACHED_APP_MIN_ADJ) { adjType = "cch-bound-ui-services"; Loading Loading @@ -2322,7 +2321,7 @@ public class OomAdjusterImpl extends OomAdjuster { String adjType = null; if (adj > clientAdj) { if (state.hasShownUi() && !state.getCachedIsHomeProcess() if (state.hasShownUi() && !isHomeProcess(app) && clientAdj > PERCEPTIBLE_APP_ADJ) { adjType = "cch-ui-provider"; } else { Loading
services/core/java/com/android/server/am/ProcessStateController.java +350 −52 File changed.Preview size limit exceeded, changes collapsed. Show changes
services/core/java/com/android/server/am/ProcessStateRecord.java +78 −4 Original line number Diff line number Diff line Loading @@ -385,6 +385,18 @@ final class ProcessStateRecord { @GuardedBy("mService") private @ElapsedRealtimeLong long mLastCachedTime; @GuardedBy("mService") private boolean mHasActivities = false; @GuardedBy("mService") private int mActivityStateFlags = ACTIVITY_STATE_FLAG_MASK_MIN_TASK_LAYER; @GuardedBy("mService") private long mPerceptibleTaskStoppedTimeMillis = Long.MIN_VALUE; @GuardedBy("mService") private boolean mHasRecentTask = false; // Below are the cached task info for OomAdjuster only private static final int VALUE_INVALID = -1; private static final int VALUE_FALSE = 0; Loading Loading @@ -962,6 +974,26 @@ final class ProcessStateRecord { mReachable = reachable; } @GuardedBy("mService") void setHasActivities(boolean hasActivities) { mHasActivities = hasActivities; } @GuardedBy("mService") void setActivityStateFlags(int flags) { mActivityStateFlags = flags; } @GuardedBy("mService") void setPerceptibleTaskStoppedTimeMillis(long uptimeMs) { mPerceptibleTaskStoppedTimeMillis = uptimeMs; } @GuardedBy("mService") void setHasRecentTask(boolean hasRecentTask) { mHasRecentTask = hasRecentTask; } @GuardedBy("mService") void resetCachedInfo() { mCachedHasActivities = VALUE_INVALID; Loading @@ -979,7 +1011,7 @@ final class ProcessStateRecord { } @GuardedBy("mService") boolean getCachedHasActivities() { private boolean getCachedHasActivities() { if (mCachedHasActivities == VALUE_INVALID) { mCachedHasActivities = mApp.getWindowProcessController().hasActivities() ? VALUE_TRUE : VALUE_FALSE; Loading @@ -992,6 +1024,15 @@ final class ProcessStateRecord { return mCachedHasActivities == VALUE_TRUE; } @GuardedBy("mService") boolean getHasActivities() { if (Flags.pushActivityStateToOomadjuster()) { return mHasActivities; } else { return getCachedHasActivities(); } } @GuardedBy("mService") boolean getCachedIsHeavyWeight() { if (mCachedIsHeavyWeight == VALUE_INVALID) { Loading @@ -1002,7 +1043,7 @@ final class ProcessStateRecord { } @GuardedBy("mService") boolean getCachedHasVisibleActivities() { private boolean getCachedHasVisibleActivities() { if (mCachedHasVisibleActivities == VALUE_INVALID) { mCachedHasVisibleActivities = mApp.getWindowProcessController().hasVisibleActivities() ? VALUE_TRUE : VALUE_FALSE; Loading @@ -1010,6 +1051,15 @@ final class ProcessStateRecord { return mCachedHasVisibleActivities == VALUE_TRUE; } @GuardedBy("mService") boolean getHasVisibleActivities() { if (Flags.pushActivityStateToOomadjuster()) { return (mActivityStateFlags & ACTIVITY_STATE_FLAG_IS_VISIBLE) != 0; } else { return getCachedHasVisibleActivities(); } } @GuardedBy("mService") boolean getCachedIsHomeProcess() { if (mCachedIsHomeProcess == VALUE_INVALID) { Loading Loading @@ -1043,6 +1093,15 @@ final class ProcessStateRecord { return mCachedHasRecentTasks == VALUE_TRUE; } @GuardedBy("mService") boolean getHasRecentTasks() { if (Flags.pushActivityStateToOomadjuster()) { return mHasRecentTask; } else { return getCachedHasRecentTasks(); } } @GuardedBy("mService") boolean getCachedIsReceivingBroadcast(int[] outSchedGroup) { if (mCachedIsReceivingBroadcast == VALUE_INVALID) { Loading Loading @@ -1078,7 +1137,12 @@ final class ProcessStateRecord { } callback.initialize(mApp, adj, foregroundActivities, hasVisibleActivities, procState, schedGroup, appUid, logUid, processCurTop); final int flags = mApp.getWindowProcessController().getActivityStateFlags(); final int flags; if (Flags.pushActivityStateToOomadjuster()) { flags = mActivityStateFlags; } else { flags = mApp.getWindowProcessController().getActivityStateFlags(); } if ((flags & ACTIVITY_STATE_FLAG_IS_VISIBLE) != 0) { callback.onVisibleActivity(flags); Loading @@ -1087,7 +1151,13 @@ final class ProcessStateRecord { } else if ((flags & ACTIVITY_STATE_FLAG_IS_STOPPING) != 0) { callback.onStoppingActivity((flags & ACTIVITY_STATE_FLAG_IS_STOPPING_FINISHING) != 0); } else { final long ts = mApp.getWindowProcessController().getPerceptibleTaskStoppedTimeMillis(); final long ts; if (Flags.pushActivityStateToOomadjuster()) { ts = mPerceptibleTaskStoppedTimeMillis; } else { ts = mApp.getWindowProcessController().getPerceptibleTaskStoppedTimeMillis(); } callback.onOtherActivity(ts); } Loading Loading @@ -1193,6 +1263,10 @@ final class ProcessStateRecord { for (int i = 0; i < mCachedCompatChanges.length; i++) { mCachedCompatChanges[i] = VALUE_INVALID; } mHasActivities = false; mActivityStateFlags = ACTIVITY_STATE_FLAG_MASK_MIN_TASK_LAYER; mPerceptibleTaskStoppedTimeMillis = Long.MIN_VALUE; mHasRecentTask = false; } @GuardedBy("mService") Loading