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

Commit 18325330 authored by Hui Yu's avatar Hui Yu Committed by Automerger Merge Worker
Browse files

Merge "Allow deviceProvisioningPackage to start foreground service from the...

Merge "Allow deviceProvisioningPackage to start foreground service from the background." into udc-dev am: f338ffa8

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23667435



Change-Id: I6cb0696bf37a6fe6130cf0907cf40f1d70587874
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 82ee503a f338ffa8
Loading
Loading
Loading
Loading
+18 −2
Original line number Original line Diff line number Diff line
@@ -406,6 +406,8 @@ public final class ActiveServices {
    // allowlisted packageName.
    // allowlisted packageName.
    ArraySet<String> mAllowListWhileInUsePermissionInFgs = new ArraySet<>();
    ArraySet<String> mAllowListWhileInUsePermissionInFgs = new ArraySet<>();


    String mCachedDeviceProvisioningPackage;

    // TODO: remove this after feature development is done
    // TODO: remove this after feature development is done
    private static final SimpleDateFormat DATE_FORMATTER =
    private static final SimpleDateFormat DATE_FORMATTER =
            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -480,7 +482,8 @@ public final class ActiveServices {
                // (REASON_ALARM_MANAGER_ALARM_CLOCK), allow it to continue and do not stop it,
                // (REASON_ALARM_MANAGER_ALARM_CLOCK), allow it to continue and do not stop it,
                // even the app is background-restricted.
                // even the app is background-restricted.
                if (r.isForeground
                if (r.isForeground
                        && r.mAllowStartForegroundAtEntering != REASON_ALARM_MANAGER_ALARM_CLOCK) {
                        && r.mAllowStartForegroundAtEntering != REASON_ALARM_MANAGER_ALARM_CLOCK
                        && !isDeviceProvisioningPackage(r.packageName)) {
                    toStop.add(r);
                    toStop.add(r);
                }
                }
            }
            }
@@ -880,7 +883,8 @@ public final class ActiveServices {
        boolean forcedStandby = false;
        boolean forcedStandby = false;
        if (bgLaunch
        if (bgLaunch
                && appRestrictedAnyInBackground(appUid, appPackageName)
                && appRestrictedAnyInBackground(appUid, appPackageName)
                && !isTempAllowedByAlarmClock(appUid)) {
                && !isTempAllowedByAlarmClock(appUid)
                && !isDeviceProvisioningPackage(appPackageName)) {
            if (DEBUG_FOREGROUND_SERVICE) {
            if (DEBUG_FOREGROUND_SERVICE) {
                Slog.d(TAG, "Forcing bg-only service start only for " + r.shortInstanceName
                Slog.d(TAG, "Forcing bg-only service start only for " + r.shortInstanceName
                        + " : bgLaunch=" + bgLaunch + " callerFg=" + callerFg);
                        + " : bgLaunch=" + bgLaunch + " callerFg=" + callerFg);
@@ -1926,6 +1930,9 @@ public final class ActiveServices {
     */
     */
    private boolean isForegroundServiceAllowedInBackgroundRestricted(ProcessRecord app) {
    private boolean isForegroundServiceAllowedInBackgroundRestricted(ProcessRecord app) {
        final ProcessStateRecord state = app.mState;
        final ProcessStateRecord state = app.mState;
        if (isDeviceProvisioningPackage(app.info.packageName)) {
            return true;
        }
        if (!state.isBackgroundRestricted()
        if (!state.isBackgroundRestricted()
                || state.getSetProcState() <= ActivityManager.PROCESS_STATE_BOUND_TOP) {
                || state.getSetProcState() <= ActivityManager.PROCESS_STATE_BOUND_TOP) {
            return true;
            return true;
@@ -8404,4 +8411,13 @@ public final class ActiveServices {
        }
        }
        return results;
        return results;
    }
    }

    private boolean isDeviceProvisioningPackage(String packageName) {
        if (mCachedDeviceProvisioningPackage == null) {
            mCachedDeviceProvisioningPackage = mAm.mContext.getResources().getString(
                    com.android.internal.R.string.config_deviceProvisioningPackage);
        }
        return mCachedDeviceProvisioningPackage != null
                && mCachedDeviceProvisioningPackage.equals(packageName);
    }
}
}