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

Commit 8a3b17f0 authored by Jing Ji's avatar Jing Ji
Browse files

Add exemption cases for app background restrictions

For the high background current drains and long-running FGS, exempt
idle allowlisted apps, companion device apps, device owner apps, etc.
Additionally, we're also exempting/setting a higher threshold for
the apps with long-running media sessions, media/location FGS,
bg location permissions.

Meanwhile, the durations that apps spent on TOP state will be excluded
from all these accounting.

BYPASS_INCLUSIVE_LANGUAGE_REASON=Legacy API name

Bug: 200326767
Test: atest FrameworksMockingServicesTests:BackgroundRestrictionTest
Change-Id: Ie22cd011679dcb70612cf740fa3e6dec9f1299d0
parent 64ac1a92
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
@@ -169,6 +169,15 @@ public class ServiceInfo extends ComponentInfo
     */
    public static final int FOREGROUND_SERVICE_TYPE_MICROPHONE = 1 << 7;

    /**
     * The number of foreground service types, this doesn't include
     * the {@link #FOREGROUND_SERVICE_TYPE_MANIFEST} and {@link #FOREGROUND_SERVICE_TYPE_NONE}
     * as they're not real service types.
     *
     * @hide
     */
    public static final int NUM_OF_FOREGROUND_SERVICE_TYPES = 8;

    /**
     * A special value indicates to use all types set in manifest file.
     */
@@ -239,6 +248,38 @@ public class ServiceInfo extends ComponentInfo
            + " " + name + "}";
    }

    /**
     * @return The label for the given foreground service type.
     *
     * @hide
     */
    public static String foregroundServiceTypeToLabel(@ForegroundServiceType int type) {
        switch (type) {
            case FOREGROUND_SERVICE_TYPE_MANIFEST:
                return "manifest";
            case FOREGROUND_SERVICE_TYPE_NONE:
                return "none";
            case FOREGROUND_SERVICE_TYPE_DATA_SYNC:
                return "dataSync";
            case FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK:
                return "mediaPlayback";
            case FOREGROUND_SERVICE_TYPE_PHONE_CALL:
                return "phoneCall";
            case FOREGROUND_SERVICE_TYPE_LOCATION:
                return "location";
            case FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE:
                return "connectedDevice";
            case FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION:
                return "mediaProjection";
            case FOREGROUND_SERVICE_TYPE_CAMERA:
                return "camera";
            case FOREGROUND_SERVICE_TYPE_MICROPHONE:
                return "microphone";
            default:
                return "unknown";
        }
    }

    public int describeContents() {
        return 0;
    }
+3 −2
Original line number Diff line number Diff line
@@ -2279,7 +2279,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        mPendingIntentController = hasHandlerThread
                ? new PendingIntentController(handlerThread.getLooper(), mUserController,
                        mConstants) : null;
        mAppRestrictionController = new AppRestrictionController(mContext);
        mAppRestrictionController = new AppRestrictionController(mContext, this);
        mProcStartHandlerThread = null;
        mProcStartHandler = null;
        mHiddenApiBlacklist = null;
@@ -2389,7 +2389,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        mPendingIntentController = new PendingIntentController(
                mHandlerThread.getLooper(), mUserController, mConstants);
        mAppRestrictionController = new AppRestrictionController(mContext);
        mAppRestrictionController = new AppRestrictionController(mContext, this);
        mUseFifoUiScheduling = SystemProperties.getInt("sys.use_fifo_ui", 0) != 0;
@@ -15857,6 +15857,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                synchronized (mProcLock) {
                    mDeviceIdleAllowlist = allAppids;
                    mDeviceIdleExceptIdleAllowlist = exceptIdleAppids;
                    mAppRestrictionController.setDeviceIdleAllowlist(allAppids, exceptIdleAppids);
                }
            }
        }
Loading