Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7531c151 authored by Michael Wachenschwanz's avatar Michael Wachenschwanz
Browse files

Fix hasForegroundActivity state for TOP SLEEPING processes

If a process is in the TOP_SLEEPING state it should continue to have the
hasForegroundActivity state while it is running a broadcast receiver

Flag: EXEMPTED bugfix
Fixes: 355162699
Test: atest MockingOomAdjusterTests
Change-Id: I0482d0e345137b089e7d7f61eafb54c2db3e2b4b
parent e2b1ca7b
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -1923,7 +1923,6 @@ public class OomAdjuster {
        int procState;
        int capability = cycleReEval ? getInitialCapability(app) : 0;

        boolean foregroundActivities = false;
        boolean hasVisibleActivities = false;
        if (app == topApp && PROCESS_STATE_CUR_TOP == PROCESS_STATE_TOP) {
            // The last app on the list is the foreground app.
@@ -1937,7 +1936,6 @@ public class OomAdjuster {
                schedGroup = SCHED_GROUP_DEFAULT;
                state.setAdjType("intermediate-top-activity");
            }
            foregroundActivities = true;
            hasVisibleActivities = true;
            procState = PROCESS_STATE_TOP;
            if (DEBUG_OOM_ADJ_REASON || logUid == appUid) {
@@ -1988,7 +1986,6 @@ public class OomAdjuster {
            adj = FOREGROUND_APP_ADJ;
            schedGroup = SCHED_GROUP_BACKGROUND;
            state.setAdjType("top-sleeping");
            foregroundActivities = true;
            procState = PROCESS_STATE_CUR_TOP;
            if (DEBUG_OOM_ADJ_REASON || logUid == appUid) {
                reportOomAdjMessageLocked(TAG_OOM_ADJ, "Making top (sleeping): " + app);
@@ -2008,7 +2005,8 @@ public class OomAdjuster {
            }
        }

        // Examine all activities if not already foreground.
        // Examine all non-top activities.
        boolean foregroundActivities = app == topApp;
        if (!foregroundActivities && state.getCachedHasActivities()) {
            state.computeOomAdjFromActivitiesIfNecessary(mTmpComputeOomAdjWindowCallback,
                    adj, foregroundActivities, hasVisibleActivities, procState, schedGroup,
+22 −0
Original line number Diff line number Diff line
@@ -436,6 +436,28 @@ public class MockingOomAdjusterTests {
        assertProcStates(app, PROCESS_STATE_RECEIVER, FOREGROUND_APP_ADJ, SCHED_GROUP_BACKGROUND);
    }

    @SuppressWarnings("GuardedBy")
    @Test
    public void testUpdateOomAdj_DoOne_TopSleepingReceivingBroadcast() {
        ProcessRecord app = spy(makeDefaultProcessRecord(MOCKAPP_PID, MOCKAPP_UID,
                MOCKAPP_PROCESSNAME, MOCKAPP_PACKAGENAME, true));
        doReturn(PROCESS_STATE_TOP_SLEEPING).when(mService.mAtmInternal).getTopProcessState();
        doReturn(app).when(mService).getTopApp();
        updateOomAdj(app);

        assertProcStates(app, PROCESS_STATE_TOP_SLEEPING, FOREGROUND_APP_ADJ,
                SCHED_GROUP_BACKGROUND);
        assertTrue(app.mState.hasForegroundActivities());

        doReturn(true).when(mService).isReceivingBroadcastLocked(any(ProcessRecord.class),
                any(int[].class));
        updateOomAdj(app);

        assertProcStates(app, PROCESS_STATE_RECEIVER, FOREGROUND_APP_ADJ, SCHED_GROUP_BACKGROUND);
        assertTrue(app.mState.hasForegroundActivities());

    }

    @SuppressWarnings("GuardedBy")
    @Test
    public void testUpdateOomAdj_DoOne_ExecutingService() {