Merge "Fix process capabilities on re-computation for cycles in oomAdjuster" into sc-v2-dev

This commit is contained in:
Jing Ji
2021-12-09 01:10:04 +00:00
committed by Android (Google) Code Review
2 changed files with 36 additions and 5 deletions

View File

@@ -1633,7 +1633,7 @@ public class OomAdjuster {
int schedGroup; int schedGroup;
int procState; int procState;
int cachedAdjSeq; int cachedAdjSeq;
int capability = 0; int capability = cycleReEval ? app.mState.getCurCapability() : 0;
boolean foregroundActivities = false; boolean foregroundActivities = false;
boolean hasVisibleActivities = false; boolean hasVisibleActivities = false;
@@ -2018,10 +2018,6 @@ public class OomAdjuster {
} }
if ((cr.flags & Context.BIND_WAIVE_PRIORITY) == 0) { if ((cr.flags & Context.BIND_WAIVE_PRIORITY) == 0) {
if (shouldSkipDueToCycle(app, cstate, procState, adj, cycleReEval)) {
continue;
}
if (cr.hasFlag(Context.BIND_INCLUDE_CAPABILITIES)) { if (cr.hasFlag(Context.BIND_INCLUDE_CAPABILITIES)) {
capability |= cstate.getCurCapability(); capability |= cstate.getCurCapability();
} }
@@ -2042,6 +2038,10 @@ public class OomAdjuster {
} }
} }
if (shouldSkipDueToCycle(app, cstate, procState, adj, cycleReEval)) {
continue;
}
if (clientProcState >= PROCESS_STATE_CACHED_ACTIVITY) { if (clientProcState >= PROCESS_STATE_CACHED_ACTIVITY) {
// If the other app is cached for any reason, for purposes here // If the other app is cached for any reason, for purposes here
// we are going to consider it empty. The specific cached state // we are going to consider it empty. The specific cached state

View File

@@ -16,6 +16,7 @@
package com.android.server.am; package com.android.server.am;
import static android.app.ActivityManager.PROCESS_CAPABILITY_ALL;
import static android.app.ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE; import static android.app.ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE;
import static android.app.ActivityManager.PROCESS_STATE_BOUND_TOP; import static android.app.ActivityManager.PROCESS_STATE_BOUND_TOP;
import static android.app.ActivityManager.PROCESS_STATE_CACHED_ACTIVITY; import static android.app.ActivityManager.PROCESS_STATE_CACHED_ACTIVITY;
@@ -1852,6 +1853,36 @@ public class MockingOomAdjusterTests {
SCHED_GROUP_DEFAULT); SCHED_GROUP_DEFAULT);
} }
@SuppressWarnings("GuardedBy")
@Test
public void testUpdateOomAdj_DoAll_BoundByPersService_Cycle_Branch_Capability() {
ProcessRecord app = spy(makeDefaultProcessRecord(MOCKAPP_PID, MOCKAPP_UID,
MOCKAPP_PROCESSNAME, MOCKAPP_PACKAGENAME, false));
ProcessRecord client = spy(makeDefaultProcessRecord(MOCKAPP2_PID, MOCKAPP2_UID,
MOCKAPP2_PROCESSNAME, MOCKAPP2_PACKAGENAME, false));
bindService(app, client, null, Context.BIND_INCLUDE_CAPABILITIES, mock(IBinder.class));
ProcessRecord client2 = spy(makeDefaultProcessRecord(MOCKAPP3_PID, MOCKAPP3_UID,
MOCKAPP3_PROCESSNAME, MOCKAPP3_PACKAGENAME, false));
bindService(client, client2, null, Context.BIND_INCLUDE_CAPABILITIES, mock(IBinder.class));
bindService(client2, app, null, Context.BIND_INCLUDE_CAPABILITIES, mock(IBinder.class));
ProcessRecord client3 = spy(makeDefaultProcessRecord(MOCKAPP4_PID, MOCKAPP4_UID,
MOCKAPP4_PROCESSNAME, MOCKAPP4_PACKAGENAME, false));
client3.mState.setMaxAdj(PERSISTENT_PROC_ADJ);
bindService(app, client3, null, Context.BIND_INCLUDE_CAPABILITIES, mock(IBinder.class));
ArrayList<ProcessRecord> lru = sService.mProcessList.getLruProcessesLOSP();
lru.clear();
lru.add(app);
lru.add(client);
lru.add(client2);
lru.add(client3);
sService.mWakefulness.set(PowerManagerInternal.WAKEFULNESS_AWAKE);
sService.mOomAdjuster.updateOomAdjLocked(OomAdjuster.OOM_ADJ_REASON_NONE);
assertEquals(PROCESS_CAPABILITY_ALL, client.mState.getSetCapability());
assertEquals(PROCESS_CAPABILITY_ALL, client2.mState.getSetCapability());
assertEquals(PROCESS_CAPABILITY_ALL, app.mState.getSetCapability());
}
@SuppressWarnings("GuardedBy") @SuppressWarnings("GuardedBy")
@Test @Test
public void testUpdateOomAdj_DoAll_Provider_Cycle_Branch_2() { public void testUpdateOomAdj_DoAll_Provider_Cycle_Branch_2() {