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

Commit 7def0306 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Allow BG-launch FGS if it is on DeviceIdleController's allowList."

parents 2588dcb3 25e7369a
Loading
Loading
Loading
Loading
+26 −12
Original line number Diff line number Diff line
@@ -558,11 +558,18 @@ public final class ActiveServices {
                }
                if (r.mAllowStartForeground == FGS_FEATURE_DENIED
                        && mAm.mConstants.mFlagFgsStartRestrictionEnabled) {
                    if (mAm.mConstants.mFlagFgsStartTempAllowListEnabled
                            && mAm.isOnDeviceIdleWhitelistLocked(r.appInfo.uid, false)) {
                        // uid is on DeviceIdleController's allowlist.
                        Slog.d(TAG, "startForegroundService() mAllowStartForeground false "
                                + "but allowlist true: service " + r.shortInstanceName);
                    } else {
                        Slog.w(TAG, "startForegroundService() not allowed due to "
                                + "mAllowStartForeground false: service "
                                + r.shortInstanceName);
                        showFgsBgRestrictedNotificationLocked(r);
                    forcedStandby = true;
                        return null;
                    }
                }
            }
        }
@@ -1462,8 +1469,14 @@ public final class ActiveServices {
                        }
                        if (r.mAllowStartForeground == FGS_FEATURE_DENIED
                                && mAm.mConstants.mFlagFgsStartRestrictionEnabled) {
                            Slog.w(TAG,
                                    "Service.startForeground() not allowed due to "
                            if (mAm.mConstants.mFlagFgsStartTempAllowListEnabled
                                    && mAm.isOnDeviceIdleWhitelistLocked(r.appInfo.uid, false)) {
                                // uid is on DeviceIdleController's allowlist.
                                Slog.d(TAG, "Service.startForeground() "
                                        + "mAllowStartForeground false but allowlist true: service "
                                        + r.shortInstanceName);
                            } else {
                                Slog.w(TAG, "Service.startForeground() not allowed due to "
                                                + "mAllowStartForeground false: service "
                                                + r.shortInstanceName);
                                showFgsBgRestrictedNotificationLocked(r);
@@ -1472,6 +1485,7 @@ public final class ActiveServices {
                            }
                        }
                    }
                }

                // Apps under strict background restrictions simply don't get to have foreground
                // services, so now that we've enforced the startForegroundService() contract
+21 −0
Original line number Diff line number Diff line
@@ -161,6 +161,13 @@ final class ActivityManagerConstants extends ContentObserver {
    private static final String KEY_DEFAULT_FGS_STARTS_RESTRICTION_ENABLED =
            "default_fgs_starts_restriction_enabled";

    /**
     * Default value for mFlagFgsStartTempAllowListEnabled if not explicitly set in
     * Settings.Global.
     */
    private static final String KEY_DEFAULT_FGS_STARTS_TEMP_ALLOWLIST_ENABLED =
            "default_fgs_starts_temp_allowlist_enabled";

    // Maximum number of cached processes we will allow.
    public int MAX_CACHED_PROCESSES = DEFAULT_MAX_CACHED_PROCESSES;

@@ -321,6 +328,10 @@ final class ActivityManagerConstants extends ContentObserver {
    // at all.
    volatile boolean mFlagFgsStartRestrictionEnabled = false;

    // When the foreground service background start restriction is enabled, if the app in
    // DeviceIdleController's Temp AllowList is allowed to bypass the restriction.
    volatile boolean mFlagFgsStartTempAllowListEnabled = false;

    private final ActivityManagerService mService;
    private ContentResolver mResolver;
    private final KeyValueListParser mParser = new KeyValueListParser(',');
@@ -472,6 +483,9 @@ final class ActivityManagerConstants extends ContentObserver {
                            case KEY_DEFAULT_FGS_STARTS_RESTRICTION_ENABLED:
                                updateFgsStartsRestriction();
                                break;
                            case KEY_DEFAULT_FGS_STARTS_TEMP_ALLOWLIST_ENABLED:
                                updateFgsStartsTempAllowList();
                                break;
                            case KEY_OOMADJ_UPDATE_POLICY:
                                updateOomAdjUpdatePolicy();
                                break;
@@ -724,6 +738,13 @@ final class ActivityManagerConstants extends ContentObserver {
                /*defaultValue*/ false);
    }

    private void updateFgsStartsTempAllowList() {
        mFlagFgsStartTempAllowListEnabled = DeviceConfig.getBoolean(
                DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
                KEY_DEFAULT_FGS_STARTS_TEMP_ALLOWLIST_ENABLED,
                /*defaultValue*/ false);
    }

    private void updateOomAdjUpdatePolicy() {
        OOMADJ_UPDATE_QUICK = DeviceConfig.getInt(
                DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,