Loading services/core/java/com/android/server/am/ActivityManagerService.java +3 −3 Original line number Diff line number Diff line Loading @@ -14600,7 +14600,7 @@ public class ActivityManagerService extends IActivityManager.Stub app.mProfile.addHostingComponentType(HOSTING_COMPONENT_TYPE_INSTRUMENTATION); } app.setActiveInstrumentation(activeInstr); mProcessStateController.setActiveInstrumentation(app, activeInstr); activeInstr.mFinished = false; activeInstr.mSourceUid = callingUid; activeInstr.mRunningProcesses.add(app); Loading Loading @@ -14746,7 +14746,7 @@ public class ActivityManagerService extends IActivityManager.Stub abiOverride, ZYGOTE_POLICY_FLAG_EMPTY); app.setActiveInstrumentation(activeInstr); mProcessStateController.setActiveInstrumentation(app, activeInstr); activeInstr.mFinished = false; activeInstr.mSourceUid = callingUid; activeInstr.mRunningProcesses.add(app); Loading Loading @@ -14883,7 +14883,7 @@ public class ActivityManagerService extends IActivityManager.Stub } instr.removeProcess(app); app.setActiveInstrumentation(null); mProcessStateController.setActiveInstrumentation(app, null); } app.mProfile.clearHostingComponentType(HOSTING_COMPONENT_TYPE_INSTRUMENTATION); services/core/java/com/android/server/am/AppProfiler.java +4 −2 Original line number Diff line number Diff line Loading @@ -2477,13 +2477,15 @@ public class AppProfiler { // This is the wildcard mode, where every process brought up for // the target instrumentation should be included. if (aInstr.mTargetInfo.packageName.equals(app.info.packageName)) { app.setActiveInstrumentation(aInstr); mService.mProcessStateController.setActiveInstrumentation(app, aInstr); aInstr.mRunningProcesses.add(app); } } else { for (String proc : aInstr.mTargetProcesses) { if (proc.equals(app.processName)) { app.setActiveInstrumentation(aInstr); mService.mProcessStateController.setActiveInstrumentation(app, aInstr); aInstr.mRunningProcesses.add(app); break; } Loading services/core/java/com/android/server/am/OomAdjuster.java +7 −1 Original line number Diff line number Diff line Loading @@ -3403,7 +3403,7 @@ public class OomAdjuster { private static int getCpuCapability(ProcessRecord app, long nowUptime) { final UidRecord uidRec = app.getUidRecord(); if (uidRec != null && uidRec.isCurAllowListed()) { // Process has user visible activities. // Process is in the power allowlist. return PROCESS_CAPABILITY_CPU_TIME; } if (UserHandle.isCore(app.uid)) { Loading @@ -3418,6 +3418,12 @@ public class OomAdjuster { // It running a short fgs, just give it cpu time. return PROCESS_CAPABILITY_CPU_TIME; } if (app.mReceivers.numberOfCurReceivers() > 0) { return PROCESS_CAPABILITY_CPU_TIME; } if (app.hasActiveInstrumentation()) { return PROCESS_CAPABILITY_CPU_TIME; } // TODO(b/370817323): Populate this method with all of the reasons to keep a process // unfrozen. return 0; Loading services/core/java/com/android/server/am/ProcessStateController.java +32 −5 Original line number Diff line number Diff line Loading @@ -246,12 +246,11 @@ public class ProcessStateController { } /** * Set what sched group to grant a process due to running a broadcast. * {@link ProcessList.SCHED_GROUP_UNDEFINED} means the process is not running a broadcast. * Sets an active instrumentation running within the given process. */ public void setBroadcastSchedGroup(@NonNull ProcessRecord proc, int schedGroup) { // TODO(b/302575389): Migrate state pulled from BroadcastQueue to a pushed model throw new UnsupportedOperationException("Not implemented yet"); public void setActiveInstrumentation(@NonNull ProcessRecord proc, ActiveInstrumentation activeInstrumentation) { proc.setActiveInstrumentation(activeInstrumentation); } /********************* Process Visibility State Events *********************/ Loading Loading @@ -587,6 +586,34 @@ public class ProcessStateController { psr.updateHasTopStartedAlmostPerceptibleServices(); } /************************ Broadcast Receiver State Events **************************/ /** * Set what sched group to grant a process due to running a broadcast. * {@link ProcessList.SCHED_GROUP_UNDEFINED} means the process is not running a broadcast. */ public void setBroadcastSchedGroup(@NonNull ProcessRecord proc, int schedGroup) { // TODO(b/302575389): Migrate state pulled from BroadcastQueue to a pushed model throw new UnsupportedOperationException("Not implemented yet"); } /** * Note that the process has started processing a broadcast receiver. */ public boolean incrementCurReceivers(@NonNull ProcessRecord app) { // TODO(b/302575389): Migrate state pulled from ATMS to a pushed model // maybe used ActivityStateFlags instead. throw new UnsupportedOperationException("Not implemented yet"); } /** * Note that the process has finished processing a broadcast receiver. */ public boolean decrementCurReceivers(@NonNull ProcessRecord app) { // TODO(b/302575389): Migrate state pulled from ATMS to a pushed model // maybe used ActivityStateFlags instead. throw new UnsupportedOperationException("Not implemented yet"); } /** * Builder for ProcessStateController. */ Loading services/tests/mockingservicestests/src/com/android/server/am/MockingOomAdjusterTests.java +37 −0 Original line number Diff line number Diff line Loading @@ -741,6 +741,43 @@ public class MockingOomAdjusterTests { assertNoCpuTime(app2); } @SuppressWarnings("GuardedBy") @Test @EnableFlags(Flags.FLAG_USE_CPU_TIME_CAPABILITY) public void testUpdateOomAdjFreezeState_receivers() { final ProcessRecord app = makeDefaultProcessRecord(MOCKAPP_PID, MOCKAPP_UID, MOCKAPP_PROCESSNAME, MOCKAPP_PACKAGENAME, true); updateOomAdj(app); assertNoCpuTime(app); app.mReceivers.incrementCurReceivers(); updateOomAdj(app); assertCpuTime(app); app.mReceivers.decrementCurReceivers(); updateOomAdj(app); assertNoCpuTime(app); } @SuppressWarnings("GuardedBy") @Test @EnableFlags(Flags.FLAG_USE_CPU_TIME_CAPABILITY) public void testUpdateOomAdjFreezeState_activeInstrumentation() { ProcessRecord app = makeDefaultProcessRecord(MOCKAPP_PID, MOCKAPP_UID, MOCKAPP_PROCESSNAME, MOCKAPP_PACKAGENAME, true); updateOomAdj(app); assertNoCpuTime(app); mProcessStateController.setActiveInstrumentation(app, mock(ActiveInstrumentation.class)); updateOomAdj(app); assertCpuTime(app); mProcessStateController.setActiveInstrumentation(app, null); updateOomAdj(app); assertNoCpuTime(app); } @SuppressWarnings("GuardedBy") @Test public void testUpdateOomAdj_DoOne_OverlayUi() { Loading Loading
services/core/java/com/android/server/am/ActivityManagerService.java +3 −3 Original line number Diff line number Diff line Loading @@ -14600,7 +14600,7 @@ public class ActivityManagerService extends IActivityManager.Stub app.mProfile.addHostingComponentType(HOSTING_COMPONENT_TYPE_INSTRUMENTATION); } app.setActiveInstrumentation(activeInstr); mProcessStateController.setActiveInstrumentation(app, activeInstr); activeInstr.mFinished = false; activeInstr.mSourceUid = callingUid; activeInstr.mRunningProcesses.add(app); Loading Loading @@ -14746,7 +14746,7 @@ public class ActivityManagerService extends IActivityManager.Stub abiOverride, ZYGOTE_POLICY_FLAG_EMPTY); app.setActiveInstrumentation(activeInstr); mProcessStateController.setActiveInstrumentation(app, activeInstr); activeInstr.mFinished = false; activeInstr.mSourceUid = callingUid; activeInstr.mRunningProcesses.add(app); Loading Loading @@ -14883,7 +14883,7 @@ public class ActivityManagerService extends IActivityManager.Stub } instr.removeProcess(app); app.setActiveInstrumentation(null); mProcessStateController.setActiveInstrumentation(app, null); } app.mProfile.clearHostingComponentType(HOSTING_COMPONENT_TYPE_INSTRUMENTATION);
services/core/java/com/android/server/am/AppProfiler.java +4 −2 Original line number Diff line number Diff line Loading @@ -2477,13 +2477,15 @@ public class AppProfiler { // This is the wildcard mode, where every process brought up for // the target instrumentation should be included. if (aInstr.mTargetInfo.packageName.equals(app.info.packageName)) { app.setActiveInstrumentation(aInstr); mService.mProcessStateController.setActiveInstrumentation(app, aInstr); aInstr.mRunningProcesses.add(app); } } else { for (String proc : aInstr.mTargetProcesses) { if (proc.equals(app.processName)) { app.setActiveInstrumentation(aInstr); mService.mProcessStateController.setActiveInstrumentation(app, aInstr); aInstr.mRunningProcesses.add(app); break; } Loading
services/core/java/com/android/server/am/OomAdjuster.java +7 −1 Original line number Diff line number Diff line Loading @@ -3403,7 +3403,7 @@ public class OomAdjuster { private static int getCpuCapability(ProcessRecord app, long nowUptime) { final UidRecord uidRec = app.getUidRecord(); if (uidRec != null && uidRec.isCurAllowListed()) { // Process has user visible activities. // Process is in the power allowlist. return PROCESS_CAPABILITY_CPU_TIME; } if (UserHandle.isCore(app.uid)) { Loading @@ -3418,6 +3418,12 @@ public class OomAdjuster { // It running a short fgs, just give it cpu time. return PROCESS_CAPABILITY_CPU_TIME; } if (app.mReceivers.numberOfCurReceivers() > 0) { return PROCESS_CAPABILITY_CPU_TIME; } if (app.hasActiveInstrumentation()) { return PROCESS_CAPABILITY_CPU_TIME; } // TODO(b/370817323): Populate this method with all of the reasons to keep a process // unfrozen. return 0; Loading
services/core/java/com/android/server/am/ProcessStateController.java +32 −5 Original line number Diff line number Diff line Loading @@ -246,12 +246,11 @@ public class ProcessStateController { } /** * Set what sched group to grant a process due to running a broadcast. * {@link ProcessList.SCHED_GROUP_UNDEFINED} means the process is not running a broadcast. * Sets an active instrumentation running within the given process. */ public void setBroadcastSchedGroup(@NonNull ProcessRecord proc, int schedGroup) { // TODO(b/302575389): Migrate state pulled from BroadcastQueue to a pushed model throw new UnsupportedOperationException("Not implemented yet"); public void setActiveInstrumentation(@NonNull ProcessRecord proc, ActiveInstrumentation activeInstrumentation) { proc.setActiveInstrumentation(activeInstrumentation); } /********************* Process Visibility State Events *********************/ Loading Loading @@ -587,6 +586,34 @@ public class ProcessStateController { psr.updateHasTopStartedAlmostPerceptibleServices(); } /************************ Broadcast Receiver State Events **************************/ /** * Set what sched group to grant a process due to running a broadcast. * {@link ProcessList.SCHED_GROUP_UNDEFINED} means the process is not running a broadcast. */ public void setBroadcastSchedGroup(@NonNull ProcessRecord proc, int schedGroup) { // TODO(b/302575389): Migrate state pulled from BroadcastQueue to a pushed model throw new UnsupportedOperationException("Not implemented yet"); } /** * Note that the process has started processing a broadcast receiver. */ public boolean incrementCurReceivers(@NonNull ProcessRecord app) { // TODO(b/302575389): Migrate state pulled from ATMS to a pushed model // maybe used ActivityStateFlags instead. throw new UnsupportedOperationException("Not implemented yet"); } /** * Note that the process has finished processing a broadcast receiver. */ public boolean decrementCurReceivers(@NonNull ProcessRecord app) { // TODO(b/302575389): Migrate state pulled from ATMS to a pushed model // maybe used ActivityStateFlags instead. throw new UnsupportedOperationException("Not implemented yet"); } /** * Builder for ProcessStateController. */ Loading
services/tests/mockingservicestests/src/com/android/server/am/MockingOomAdjusterTests.java +37 −0 Original line number Diff line number Diff line Loading @@ -741,6 +741,43 @@ public class MockingOomAdjusterTests { assertNoCpuTime(app2); } @SuppressWarnings("GuardedBy") @Test @EnableFlags(Flags.FLAG_USE_CPU_TIME_CAPABILITY) public void testUpdateOomAdjFreezeState_receivers() { final ProcessRecord app = makeDefaultProcessRecord(MOCKAPP_PID, MOCKAPP_UID, MOCKAPP_PROCESSNAME, MOCKAPP_PACKAGENAME, true); updateOomAdj(app); assertNoCpuTime(app); app.mReceivers.incrementCurReceivers(); updateOomAdj(app); assertCpuTime(app); app.mReceivers.decrementCurReceivers(); updateOomAdj(app); assertNoCpuTime(app); } @SuppressWarnings("GuardedBy") @Test @EnableFlags(Flags.FLAG_USE_CPU_TIME_CAPABILITY) public void testUpdateOomAdjFreezeState_activeInstrumentation() { ProcessRecord app = makeDefaultProcessRecord(MOCKAPP_PID, MOCKAPP_UID, MOCKAPP_PROCESSNAME, MOCKAPP_PACKAGENAME, true); updateOomAdj(app); assertNoCpuTime(app); mProcessStateController.setActiveInstrumentation(app, mock(ActiveInstrumentation.class)); updateOomAdj(app); assertCpuTime(app); mProcessStateController.setActiveInstrumentation(app, null); updateOomAdj(app); assertNoCpuTime(app); } @SuppressWarnings("GuardedBy") @Test public void testUpdateOomAdj_DoOne_OverlayUi() { Loading