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

Commit 64ff8582 authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Enable the new while-in-use / BFSL logic for V+ apps

Note the feature flag (newFgsRestrictionLogic) is still disabled.

Bug: 276963716
Test: Tree hugger
Change-Id: I5a04ecfcf802f6921dddb1e3a2c3ee48d56a16c3
parent 79b8a00c
Loading
Loading
Loading
Loading
+5 −7
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ import android.app.PendingIntent;
import android.app.RemoteServiceException.CannotPostForegroundServiceNotificationException;
import android.app.compat.CompatChanges;
import android.compat.annotation.ChangeId;
import android.compat.annotation.Disabled;
import android.compat.annotation.EnabledAfter;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -49,6 +49,7 @@ import android.content.pm.ServiceInfo;
import android.net.Uri;
import android.os.Binder;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.os.IBinder;
import android.os.PowerExemptionManager;
import android.os.SystemClock;
@@ -94,16 +95,14 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
     * (See also android.app.ForegroundServiceTypePolicy)
     */
    @ChangeId
    // @EnabledAfter(targetSdkVersion = VERSION_CODES.UPSIDE_DOWN_CAKE)
    @Disabled
    @EnabledAfter(targetSdkVersion = VERSION_CODES.UPSIDE_DOWN_CAKE)
    static final long USE_NEW_WIU_LOGIC_FOR_START = 311208629L;

    /**
     * Compat ID to enable the new FGS start logic, for capability calculation.
     */
    @ChangeId
    // Always enabled
    @Disabled
    @EnabledAfter(targetSdkVersion = VERSION_CODES.UPSIDE_DOWN_CAKE)
    static final long USE_NEW_WIU_LOGIC_FOR_CAPABILITIES = 313677553L;

    /**
@@ -111,8 +110,7 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
     * the background.
     */
    @ChangeId
    // @EnabledAfter(targetSdkVersion = VERSION_CODES.UPSIDE_DOWN_CAKE)
    @Disabled
    @EnabledAfter(targetSdkVersion = VERSION_CODES.UPSIDE_DOWN_CAKE)
    static final long USE_NEW_BFSL_LOGIC = 311208749L;

    final ActivityManagerService ams;
+16 −0
Original line number Diff line number Diff line
@@ -97,6 +97,7 @@ import android.os.PowerManagerInternal;
import android.os.SystemClock;
import android.os.UserHandle;
import android.platform.test.annotations.Presubmit;
import android.platform.test.flag.junit.SetFlagsRule;
import android.util.ArrayMap;
import android.util.SparseArray;

@@ -107,7 +108,9 @@ import com.android.server.wm.WindowProcessController;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;

import java.io.File;
@@ -154,6 +157,9 @@ public class MockingOomAdjusterTests {
    private static PackageManagerInternal sPackageManagerInternal;
    private static ActivityManagerService sService;

    @Rule
    public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();

    @SuppressWarnings("GuardedBy")
    @BeforeClass
    public static void setUpOnce() {
@@ -220,6 +226,11 @@ public class MockingOomAdjusterTests {
        }
    }

    @Before
    public void setUp() {
        mSetFlagsRule.enableFlags(Flags.FLAG_NEW_FGS_RESTRICTION_LOGIC);
    }

    @AfterClass
    public static void tearDownOnce() {
        LocalServices.removeServiceForTest(PackageManagerInternal.class);
@@ -519,6 +530,7 @@ public class MockingOomAdjusterTests {
        sService.mConstants.mShortFgsProcStateExtraWaitDuration = 200_000;

        ServiceRecord s = ServiceRecord.newEmptyInstanceForTest(sService);
        s.appInfo = new ApplicationInfo();
        s.startRequested = true;
        s.isForeground = true;
        s.foregroundServiceType = FOREGROUND_SERVICE_TYPE_SHORT_SERVICE;
@@ -561,6 +573,7 @@ public class MockingOomAdjusterTests {

        // SHORT_SERVICE, timed out already.
        s = ServiceRecord.newEmptyInstanceForTest(sService);
        s.appInfo = new ApplicationInfo();
        s.startRequested = true;
        s.isForeground = true;
        s.foregroundServiceType = FOREGROUND_SERVICE_TYPE_SHORT_SERVICE;
@@ -1079,6 +1092,7 @@ public class MockingOomAdjusterTests {

        // In order to trick OomAdjuster to think it has a short-service, we need this logic.
        ServiceRecord s = ServiceRecord.newEmptyInstanceForTest(sService);
        s.appInfo = new ApplicationInfo();
        s.startRequested = true;
        s.isForeground = true;
        s.foregroundServiceType = FOREGROUND_SERVICE_TYPE_SHORT_SERVICE;
@@ -1109,6 +1123,7 @@ public class MockingOomAdjusterTests {

        // In order to trick OomAdjuster to think it has a short-service, we need this logic.
        ServiceRecord s = ServiceRecord.newEmptyInstanceForTest(sService);
        s.appInfo = new ApplicationInfo();
        s.startRequested = true;
        s.isForeground = true;
        s.foregroundServiceType = FOREGROUND_SERVICE_TYPE_SHORT_SERVICE;
@@ -1400,6 +1415,7 @@ public class MockingOomAdjusterTests {

        // In order to trick OomAdjuster to think it has a short-service, we need this logic.
        ServiceRecord s = ServiceRecord.newEmptyInstanceForTest(sService);
        s.appInfo = new ApplicationInfo();
        s.startRequested = true;
        s.isForeground = true;
        s.foregroundServiceType = FOREGROUND_SERVICE_TYPE_SHORT_SERVICE;