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

Commit 35085f4f authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Grant FGS cpu_time capability by default" into main

parents 395f4a33 a33690a4
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -3433,8 +3433,12 @@ public class OomAdjuster {
            // Process has user visible activities.
            return PROCESS_CAPABILITY_CPU_TIME;
        }
        if (Flags.prototypeAggressiveFreezing()) {
            if (app.mServices.hasUndemotedShortForegroundService(nowUptime)) {
            // It running a short fgs, just give it cpu time.
                // Grant cpu time for short FGS even when aggressively freezing.
                return PROCESS_CAPABILITY_CPU_TIME;
            }
        } else if (app.mServices.hasForegroundServices()) {
            return PROCESS_CAPABILITY_CPU_TIME;
        }
        if (app.mReceivers.numberOfCurReceivers() > 0) {
+41 −1
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import static android.app.ActivityManagerInternal.OOM_ADJ_REASON_ACTIVITY;
import static android.app.ActivityManagerInternal.OOM_ADJ_REASON_NONE;
import static android.app.ActivityManagerInternal.OOM_ADJ_REASON_SHORT_FGS_TIMEOUT;
import static android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_SHORT_SERVICE;
import static android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE;

import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;

@@ -107,6 +108,7 @@ import android.os.PowerManagerInternal;
import android.os.Process;
import android.os.SystemClock;
import android.os.UserHandle;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.annotations.Presubmit;
import android.platform.test.flag.junit.SetFlagsRule;
@@ -698,7 +700,7 @@ public class MockingOomAdjusterTests {

    @SuppressWarnings("GuardedBy")
    @Test
    @EnableFlags(Flags.FLAG_USE_CPU_TIME_CAPABILITY)
    @EnableFlags({Flags.FLAG_USE_CPU_TIME_CAPABILITY, Flags.FLAG_PROTOTYPE_AGGRESSIVE_FREEZING})
    public void testUpdateOomAdjFreezeState_bindingFromShortFgs() {
        // Setting up a started short FGS within app1.
        final ServiceRecord s = ServiceRecord.newEmptyInstanceForTest(mService);
@@ -741,6 +743,44 @@ public class MockingOomAdjusterTests {
        assertNoCpuTime(app2);
    }

    @SuppressWarnings("GuardedBy")
    @Test
    @EnableFlags(Flags.FLAG_USE_CPU_TIME_CAPABILITY)
    @DisableFlags(Flags.FLAG_PROTOTYPE_AGGRESSIVE_FREEZING)
    public void testUpdateOomAdjFreezeState_bindingFromFgs() {
        final ProcessRecord app = spy(makeDefaultProcessRecord(MOCKAPP_PID, MOCKAPP_UID,
                MOCKAPP_PROCESSNAME, MOCKAPP_PACKAGENAME, true));
        mProcessStateController.setHasForegroundServices(app.mServices, true,
                FOREGROUND_SERVICE_TYPE_SPECIAL_USE, false);

        final ProcessRecord app2 = spy(makeDefaultProcessRecord(MOCKAPP2_PID, MOCKAPP2_UID,
                MOCKAPP2_PROCESSNAME, MOCKAPP2_PACKAGENAME, false));
        // App with a foreground service binds to app2
        bindService(app2, app, null, null, 0, mock(IBinder.class));

        setProcessesToLru(app, app2);
        updateOomAdj(app);

        assertCpuTime(app);
        assertCpuTime(app2);
    }

    @SuppressWarnings("GuardedBy")
    @Test
    @EnableFlags(Flags.FLAG_USE_CPU_TIME_CAPABILITY)
    @DisableFlags(Flags.FLAG_PROTOTYPE_AGGRESSIVE_FREEZING)
    public void testUpdateOomAdjFreezeState_soloFgs() {
        final ProcessRecord app = spy(makeDefaultProcessRecord(MOCKAPP_PID, MOCKAPP_UID,
                MOCKAPP_PROCESSNAME, MOCKAPP_PACKAGENAME, true));
        mProcessStateController.setHasForegroundServices(app.mServices, true,
                FOREGROUND_SERVICE_TYPE_SPECIAL_USE, false);

        setProcessesToLru(app);
        updateOomAdj(app);

        assertCpuTime(app);
    }

    @SuppressWarnings("GuardedBy")
    @Test
    @EnableFlags(Flags.FLAG_USE_CPU_TIME_CAPABILITY)