Loading services/core/java/com/android/server/am/ProcessServiceRecord.java +4 −2 Original line number Diff line number Diff line Loading @@ -347,8 +347,10 @@ final class ProcessServiceRecord { mHasAboveClient = false; for (int i = mConnections.size() - 1; i >= 0; i--) { ConnectionRecord cr = mConnections.valueAt(i); if (cr.binding.service.app.mServices != this && cr.hasFlag(Context.BIND_ABOVE_CLIENT)) { final boolean isSameProcess = cr.binding.service.app != null && cr.binding.service.app.mServices == this; if (!isSameProcess && cr.hasFlag(Context.BIND_ABOVE_CLIENT)) { mHasAboveClient = true; break; } Loading services/tests/mockingservicestests/src/com/android/server/am/MockingOomAdjusterTests.java +25 −0 Original line number Diff line number Diff line Loading @@ -2617,6 +2617,31 @@ public class MockingOomAdjusterTests { assertTrue(CACHED_APP_MAX_ADJ >= app3.mState.getSetAdj()); } @SuppressWarnings("GuardedBy") @Test public void testUpdateOomAdj_DoOne_AboveClient_NotStarted() { ProcessRecord app = spy(makeDefaultProcessRecord(MOCKAPP_PID, MOCKAPP_UID, MOCKAPP_PROCESSNAME, MOCKAPP_PACKAGENAME, true)); doReturn(PROCESS_STATE_TOP).when(sService.mAtmInternal).getTopProcessState(); doReturn(app).when(sService).getTopApp(); sService.mWakefulness.set(PowerManagerInternal.WAKEFULNESS_AWAKE); sService.mOomAdjuster.updateOomAdjLocked(app, OOM_ADJ_REASON_NONE); assertEquals(FOREGROUND_APP_ADJ, app.mState.getSetAdj()); // Start binding to a service that isn't running yet. ServiceRecord sr = makeServiceRecord(app); sr.app = null; bindService(null, app, sr, Context.BIND_ABOVE_CLIENT, mock(IBinder.class)); // Since sr.app is null, this service cannot be in the same process as the // client so we expect the BIND_ABOVE_CLIENT adjustment to take effect. app.mServices.updateHasAboveClientLocked(); sService.mOomAdjuster.updateOomAdjLocked(app, OOM_ADJ_REASON_NONE); assertTrue(app.mServices.hasAboveClient()); assertNotEquals(FOREGROUND_APP_ADJ, app.mState.getSetAdj()); } private ProcessRecord makeDefaultProcessRecord(int pid, int uid, String processName, String packageName, boolean hasShownUi) { long now = SystemClock.uptimeMillis(); Loading Loading
services/core/java/com/android/server/am/ProcessServiceRecord.java +4 −2 Original line number Diff line number Diff line Loading @@ -347,8 +347,10 @@ final class ProcessServiceRecord { mHasAboveClient = false; for (int i = mConnections.size() - 1; i >= 0; i--) { ConnectionRecord cr = mConnections.valueAt(i); if (cr.binding.service.app.mServices != this && cr.hasFlag(Context.BIND_ABOVE_CLIENT)) { final boolean isSameProcess = cr.binding.service.app != null && cr.binding.service.app.mServices == this; if (!isSameProcess && cr.hasFlag(Context.BIND_ABOVE_CLIENT)) { mHasAboveClient = true; break; } Loading
services/tests/mockingservicestests/src/com/android/server/am/MockingOomAdjusterTests.java +25 −0 Original line number Diff line number Diff line Loading @@ -2617,6 +2617,31 @@ public class MockingOomAdjusterTests { assertTrue(CACHED_APP_MAX_ADJ >= app3.mState.getSetAdj()); } @SuppressWarnings("GuardedBy") @Test public void testUpdateOomAdj_DoOne_AboveClient_NotStarted() { ProcessRecord app = spy(makeDefaultProcessRecord(MOCKAPP_PID, MOCKAPP_UID, MOCKAPP_PROCESSNAME, MOCKAPP_PACKAGENAME, true)); doReturn(PROCESS_STATE_TOP).when(sService.mAtmInternal).getTopProcessState(); doReturn(app).when(sService).getTopApp(); sService.mWakefulness.set(PowerManagerInternal.WAKEFULNESS_AWAKE); sService.mOomAdjuster.updateOomAdjLocked(app, OOM_ADJ_REASON_NONE); assertEquals(FOREGROUND_APP_ADJ, app.mState.getSetAdj()); // Start binding to a service that isn't running yet. ServiceRecord sr = makeServiceRecord(app); sr.app = null; bindService(null, app, sr, Context.BIND_ABOVE_CLIENT, mock(IBinder.class)); // Since sr.app is null, this service cannot be in the same process as the // client so we expect the BIND_ABOVE_CLIENT adjustment to take effect. app.mServices.updateHasAboveClientLocked(); sService.mOomAdjuster.updateOomAdjLocked(app, OOM_ADJ_REASON_NONE); assertTrue(app.mServices.hasAboveClient()); assertNotEquals(FOREGROUND_APP_ADJ, app.mState.getSetAdj()); } private ProcessRecord makeDefaultProcessRecord(int pid, int uid, String processName, String packageName, boolean hasShownUi) { long now = SystemClock.uptimeMillis(); Loading