Loading services/core/java/com/android/server/am/ActivityManagerConstants.java +1 −1 Original line number Diff line number Diff line Loading @@ -1347,7 +1347,7 @@ final class ActivityManagerConstants extends ContentObserver { updateForegroundServiceStartsLoggingEnabled(); } private void loadDeviceConfigConstants() { void loadDeviceConfigConstants() { mOnDeviceConfigChangedListener.onPropertiesChanged( DeviceConfig.getProperties(DeviceConfig.NAMESPACE_ACTIVITY_MANAGER)); mOnDeviceConfigChangedForComponentAliasListener.onPropertiesChanged( Loading services/core/java/com/android/server/am/ActivityManagerService.java +7 −9 Original line number Diff line number Diff line Loading @@ -4579,14 +4579,8 @@ public class ActivityManagerService extends IActivityManager.Stub EventLogTags.writeAmProcBound(app.userId, pid, app.processName); synchronized (mProcLock) { app.mState.setCurAdj(ProcessList.INVALID_ADJ); app.mState.setSetAdj(ProcessList.INVALID_ADJ); app.mState.setVerifiedAdj(ProcessList.INVALID_ADJ); mOomAdjuster.setAttachingSchedGroupLSP(app); app.mState.setForcingToImportant(null); mOomAdjuster.setAttachingProcessStatesLSP(app); clearProcessForegroundLocked(app); app.mState.setHasShownUi(false); app.mState.setCached(false); app.setDebugging(false); app.setKilledByAm(false); app.setKilled(false); Loading Loading @@ -4753,8 +4747,14 @@ public class ActivityManagerService extends IActivityManager.Stub app.makeActive(thread, mProcessStats); checkTime(startTime, "attachApplicationLocked: immediately after bindApplication"); } app.setPendingFinishAttach(true); updateLruProcessLocked(app, false, null); checkTime(startTime, "attachApplicationLocked: after updateLruProcessLocked"); updateOomAdjLocked(app, OOM_ADJ_REASON_PROCESS_BEGIN); checkTime(startTime, "attachApplicationLocked: after updateOomAdjLocked"); final long now = SystemClock.uptimeMillis(); synchronized (mAppProfiler.mProfilerLock) { app.mProfile.setLastRequestedGc(now); Loading @@ -4770,8 +4770,6 @@ public class ActivityManagerService extends IActivityManager.Stub if (!mConstants.mEnableWaitForFinishAttachApplication) { finishAttachApplicationInner(startSeq, callingUid, pid); } else { app.setPendingFinishAttach(true); } } catch (Exception e) { // We need kill the process group here. (b/148588589) Loading services/core/java/com/android/server/am/ActivityManagerShellCommand.java +4 −7 Original line number Diff line number Diff line Loading @@ -3699,14 +3699,11 @@ final class ActivityManagerShellCommand extends ShellCommand { if (foregroundActivities) { try { int prcState = mIam.getUidProcessState(uid, "android"); ProcessRecord topApp = mInternal.getTopApp(); if (topApp == null) { mPw.println("No top app found"); } else { int topPid = topApp.getPid(); if (prcState == ProcessStateEnum.TOP && topPid == pid) { if (prcState == ProcessStateEnum.TOP) { mPw.println("New foreground process: " + pid); } } else { mPw.println("No top app found"); } mPw.flush(); } catch (RemoteException e) { Loading services/core/java/com/android/server/am/OomAdjuster.java +36 −3 Original line number Diff line number Diff line Loading @@ -1293,12 +1293,19 @@ public class OomAdjuster { for (int i = numLru - 1; i >= 0; i--) { ProcessRecord app = lruList.get(i); final ProcessStateRecord state = app.mState; if (!app.isKilledByAm() && app.getThread() != null && !app.isPendingFinishAttach()) { if (!app.isKilledByAm() && app.getThread() != null) { // We don't need to apply the update for the process which didn't get computed if (state.getCompletedAdjSeq() == mAdjSeq) { applyOomAdjLSP(app, true, now, nowElapsed, oomAdjReason); } if (app.isPendingFinishAttach()) { // Avoid trimming processes that are still initializing. If they aren't // hosting any components yet because they may be unfairly killed. // We however apply the oom scores set at #setAttachingProcessStatesLSP. continue; } final ProcessServiceRecord psr = app.mServices; // Count the number of process types. switch (state.getCurProcState()) { Loading Loading @@ -2806,6 +2813,18 @@ public class OomAdjuster { capability &= ~PROCESS_CAPABILITY_BFSL; } if (app.isPendingFinishAttach()) { // If the app is still starting up. We reset the computations to the // hardcoded values in setAttachingProcessStatesLSP. This ensures that the app keeps // hard-coded default 'startup' oom scores while starting up. When it finishes startup, // we'll recompute oom scores based on it's actual hosted compoenents. setAttachingProcessStatesLSP(app); state.setAdjSeq(mAdjSeq); state.setCompletedAdjSeq(state.getAdjSeq()); return false; } // Do final modification to adj. Everything we do between here and applying // the final setAdj must be done in this function, because we will also use // it when computing the final cached adj later. Note that we don't need to Loading Loading @@ -3243,8 +3262,11 @@ public class OomAdjuster { } @GuardedBy({"mService", "mProcLock"}) void setAttachingSchedGroupLSP(ProcessRecord app) { void setAttachingProcessStatesLSP(ProcessRecord app) { int initialSchedGroup = SCHED_GROUP_DEFAULT; int initialProcState = PROCESS_STATE_CACHED_EMPTY; int initialCapability = PROCESS_CAPABILITY_NONE; boolean initialCached = true; final ProcessStateRecord state = app.mState; // If the process has been marked as foreground, it is starting as the top app (with // Zygote#START_AS_TOP_APP_ARG), so boost the thread priority of its default UI thread. Loading @@ -3260,13 +3282,24 @@ public class OomAdjuster { setThreadPriority(app.getPid(), THREAD_PRIORITY_TOP_APP_BOOST); } initialSchedGroup = SCHED_GROUP_TOP_APP; initialProcState = PROCESS_STATE_TOP; initialCapability = PROCESS_CAPABILITY_ALL; initialCached = false; } catch (Exception e) { Slog.w(TAG, "Failed to pre-set top priority to " + app + " " + e); } } state.setSetSchedGroup(initialSchedGroup); state.setCurrentSchedulingGroup(initialSchedGroup); state.setCurProcState(initialProcState); state.setCurRawProcState(initialProcState); state.setCurCapability(initialCapability); state.setCached(initialCached); state.setCurAdj(ProcessList.FOREGROUND_APP_ADJ); state.setCurRawAdj(ProcessList.FOREGROUND_APP_ADJ); state.setForcingToImportant(null); state.setHasShownUi(false); } // ONLY used for unit testing in OomAdjusterTests.java Loading services/tests/mockingservicestests/src/com/android/server/am/AsyncProcessStartTest.java +8 −4 Original line number Diff line number Diff line Loading @@ -131,6 +131,7 @@ public class AsyncProcessStartTest { mRealAms = new ActivityManagerService( new TestInjector(mContext), mServiceThreadRule.getThread()); mRealAms.mConstants.loadDeviceConfigConstants(); mRealAms.mActivityTaskManager = new ActivityTaskManagerService(mContext); mRealAms.mActivityTaskManager.initialize(null, null, mContext.getMainLooper()); mRealAms.mAtmInternal = mActivityTaskManagerInt; Loading Loading @@ -195,8 +196,10 @@ public class AsyncProcessStartTest { Log.v(TAG, "Intercepting bindApplication() for " + Arrays.toString(invocation.getArguments())); if (!wedge) { if (mRealAms.mConstants.mEnableWaitForFinishAttachApplication) { mRealAms.finishAttachApplication(0); } } return null; }).when(thread).bindApplication( any(), any(), Loading Loading @@ -237,10 +240,11 @@ public class AsyncProcessStartTest { */ @Test public void testNormal() throws Exception { if (mRealAms.mConstants.mEnableWaitForFinishAttachApplication) { ProcessRecord app = startProcessAndWait(false); verify(app, never()).killLocked(any(), anyInt(), anyBoolean()); } } /** * Verify that we kill a wedged process after the process start timeout Loading Loading
services/core/java/com/android/server/am/ActivityManagerConstants.java +1 −1 Original line number Diff line number Diff line Loading @@ -1347,7 +1347,7 @@ final class ActivityManagerConstants extends ContentObserver { updateForegroundServiceStartsLoggingEnabled(); } private void loadDeviceConfigConstants() { void loadDeviceConfigConstants() { mOnDeviceConfigChangedListener.onPropertiesChanged( DeviceConfig.getProperties(DeviceConfig.NAMESPACE_ACTIVITY_MANAGER)); mOnDeviceConfigChangedForComponentAliasListener.onPropertiesChanged( Loading
services/core/java/com/android/server/am/ActivityManagerService.java +7 −9 Original line number Diff line number Diff line Loading @@ -4579,14 +4579,8 @@ public class ActivityManagerService extends IActivityManager.Stub EventLogTags.writeAmProcBound(app.userId, pid, app.processName); synchronized (mProcLock) { app.mState.setCurAdj(ProcessList.INVALID_ADJ); app.mState.setSetAdj(ProcessList.INVALID_ADJ); app.mState.setVerifiedAdj(ProcessList.INVALID_ADJ); mOomAdjuster.setAttachingSchedGroupLSP(app); app.mState.setForcingToImportant(null); mOomAdjuster.setAttachingProcessStatesLSP(app); clearProcessForegroundLocked(app); app.mState.setHasShownUi(false); app.mState.setCached(false); app.setDebugging(false); app.setKilledByAm(false); app.setKilled(false); Loading Loading @@ -4753,8 +4747,14 @@ public class ActivityManagerService extends IActivityManager.Stub app.makeActive(thread, mProcessStats); checkTime(startTime, "attachApplicationLocked: immediately after bindApplication"); } app.setPendingFinishAttach(true); updateLruProcessLocked(app, false, null); checkTime(startTime, "attachApplicationLocked: after updateLruProcessLocked"); updateOomAdjLocked(app, OOM_ADJ_REASON_PROCESS_BEGIN); checkTime(startTime, "attachApplicationLocked: after updateOomAdjLocked"); final long now = SystemClock.uptimeMillis(); synchronized (mAppProfiler.mProfilerLock) { app.mProfile.setLastRequestedGc(now); Loading @@ -4770,8 +4770,6 @@ public class ActivityManagerService extends IActivityManager.Stub if (!mConstants.mEnableWaitForFinishAttachApplication) { finishAttachApplicationInner(startSeq, callingUid, pid); } else { app.setPendingFinishAttach(true); } } catch (Exception e) { // We need kill the process group here. (b/148588589) Loading
services/core/java/com/android/server/am/ActivityManagerShellCommand.java +4 −7 Original line number Diff line number Diff line Loading @@ -3699,14 +3699,11 @@ final class ActivityManagerShellCommand extends ShellCommand { if (foregroundActivities) { try { int prcState = mIam.getUidProcessState(uid, "android"); ProcessRecord topApp = mInternal.getTopApp(); if (topApp == null) { mPw.println("No top app found"); } else { int topPid = topApp.getPid(); if (prcState == ProcessStateEnum.TOP && topPid == pid) { if (prcState == ProcessStateEnum.TOP) { mPw.println("New foreground process: " + pid); } } else { mPw.println("No top app found"); } mPw.flush(); } catch (RemoteException e) { Loading
services/core/java/com/android/server/am/OomAdjuster.java +36 −3 Original line number Diff line number Diff line Loading @@ -1293,12 +1293,19 @@ public class OomAdjuster { for (int i = numLru - 1; i >= 0; i--) { ProcessRecord app = lruList.get(i); final ProcessStateRecord state = app.mState; if (!app.isKilledByAm() && app.getThread() != null && !app.isPendingFinishAttach()) { if (!app.isKilledByAm() && app.getThread() != null) { // We don't need to apply the update for the process which didn't get computed if (state.getCompletedAdjSeq() == mAdjSeq) { applyOomAdjLSP(app, true, now, nowElapsed, oomAdjReason); } if (app.isPendingFinishAttach()) { // Avoid trimming processes that are still initializing. If they aren't // hosting any components yet because they may be unfairly killed. // We however apply the oom scores set at #setAttachingProcessStatesLSP. continue; } final ProcessServiceRecord psr = app.mServices; // Count the number of process types. switch (state.getCurProcState()) { Loading Loading @@ -2806,6 +2813,18 @@ public class OomAdjuster { capability &= ~PROCESS_CAPABILITY_BFSL; } if (app.isPendingFinishAttach()) { // If the app is still starting up. We reset the computations to the // hardcoded values in setAttachingProcessStatesLSP. This ensures that the app keeps // hard-coded default 'startup' oom scores while starting up. When it finishes startup, // we'll recompute oom scores based on it's actual hosted compoenents. setAttachingProcessStatesLSP(app); state.setAdjSeq(mAdjSeq); state.setCompletedAdjSeq(state.getAdjSeq()); return false; } // Do final modification to adj. Everything we do between here and applying // the final setAdj must be done in this function, because we will also use // it when computing the final cached adj later. Note that we don't need to Loading Loading @@ -3243,8 +3262,11 @@ public class OomAdjuster { } @GuardedBy({"mService", "mProcLock"}) void setAttachingSchedGroupLSP(ProcessRecord app) { void setAttachingProcessStatesLSP(ProcessRecord app) { int initialSchedGroup = SCHED_GROUP_DEFAULT; int initialProcState = PROCESS_STATE_CACHED_EMPTY; int initialCapability = PROCESS_CAPABILITY_NONE; boolean initialCached = true; final ProcessStateRecord state = app.mState; // If the process has been marked as foreground, it is starting as the top app (with // Zygote#START_AS_TOP_APP_ARG), so boost the thread priority of its default UI thread. Loading @@ -3260,13 +3282,24 @@ public class OomAdjuster { setThreadPriority(app.getPid(), THREAD_PRIORITY_TOP_APP_BOOST); } initialSchedGroup = SCHED_GROUP_TOP_APP; initialProcState = PROCESS_STATE_TOP; initialCapability = PROCESS_CAPABILITY_ALL; initialCached = false; } catch (Exception e) { Slog.w(TAG, "Failed to pre-set top priority to " + app + " " + e); } } state.setSetSchedGroup(initialSchedGroup); state.setCurrentSchedulingGroup(initialSchedGroup); state.setCurProcState(initialProcState); state.setCurRawProcState(initialProcState); state.setCurCapability(initialCapability); state.setCached(initialCached); state.setCurAdj(ProcessList.FOREGROUND_APP_ADJ); state.setCurRawAdj(ProcessList.FOREGROUND_APP_ADJ); state.setForcingToImportant(null); state.setHasShownUi(false); } // ONLY used for unit testing in OomAdjusterTests.java Loading
services/tests/mockingservicestests/src/com/android/server/am/AsyncProcessStartTest.java +8 −4 Original line number Diff line number Diff line Loading @@ -131,6 +131,7 @@ public class AsyncProcessStartTest { mRealAms = new ActivityManagerService( new TestInjector(mContext), mServiceThreadRule.getThread()); mRealAms.mConstants.loadDeviceConfigConstants(); mRealAms.mActivityTaskManager = new ActivityTaskManagerService(mContext); mRealAms.mActivityTaskManager.initialize(null, null, mContext.getMainLooper()); mRealAms.mAtmInternal = mActivityTaskManagerInt; Loading Loading @@ -195,8 +196,10 @@ public class AsyncProcessStartTest { Log.v(TAG, "Intercepting bindApplication() for " + Arrays.toString(invocation.getArguments())); if (!wedge) { if (mRealAms.mConstants.mEnableWaitForFinishAttachApplication) { mRealAms.finishAttachApplication(0); } } return null; }).when(thread).bindApplication( any(), any(), Loading Loading @@ -237,10 +240,11 @@ public class AsyncProcessStartTest { */ @Test public void testNormal() throws Exception { if (mRealAms.mConstants.mEnableWaitForFinishAttachApplication) { ProcessRecord app = startProcessAndWait(false); verify(app, never()).killLocked(any(), anyInt(), anyBoolean()); } } /** * Verify that we kill a wedged process after the process start timeout Loading