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

Commit ce5f8eb5 authored by Kunal's avatar Kunal
Browse files

Disabling FGS start from System Alert Window

Bug: 296558535
Test: atest coming soon
Change-Id: I70c02e8285413eb7f7a97a54e2d2247588fa1e36
parent b80207f6
Loading
Loading
Loading
Loading
+33 −3
Original line number Diff line number Diff line
@@ -372,6 +372,15 @@ public final class ActiveServices {
    @Overridable
    public static final long FGS_BOOT_COMPLETED_RESTRICTIONS = 296558535L;

    /**
     * Disables foreground service background starts in System Alert Window for all types
     * unless it already has a System Overlay Window.
     */
    @ChangeId
    @EnabledSince(targetSdkVersion = VERSION_CODES.VANILLA_ICE_CREAM)
    @Overridable
    public static final long FGS_SAW_RESTRICTIONS = 319471980L;

    final ActivityManagerService mAm;

    // Maximum number of services that we allow to start in the background
@@ -8525,12 +8534,33 @@ public final class ActiveServices {
            }
        }

        // The flag being enabled isn't enough to deny background start: we need to also check
        // if there is a system alert UI present.
        if (ret == REASON_DENIED) {
            // Flag check: are we disabling SAW FGS background starts?
            final boolean shouldDisableSaw = Flags.fgsDisableSaw()
                    && CompatChanges.isChangeEnabled(FGS_BOOT_COMPLETED_RESTRICTIONS, callingUid);
            if (shouldDisableSaw) {
                final ProcessRecord processRecord = mAm
                        .getProcessRecordLocked(targetService.processName,
                        targetService.appInfo.uid);
                if (processRecord != null) {
                    if (processRecord.mState.hasOverlayUi()) {
                        if (mAm.mAtmInternal.hasSystemAlertWindowPermission(callingUid, callingPid,
                                callingPackage)) {
                            ret = REASON_SYSTEM_ALERT_WINDOW_PERMISSION;
                        }
                    }
                } else {
                    Slog.e(TAG, "Could not find process record for SAW check");
                }
            } else {
                if (mAm.mAtmInternal.hasSystemAlertWindowPermission(callingUid, callingPid,
                        callingPackage)) {
                    ret = REASON_SYSTEM_ALERT_WINDOW_PERMISSION;
                }
            }
        }

        // Check for CDM apps with either REQUEST_COMPANION_RUN_IN_BACKGROUND or
        // REQUEST_COMPANION_START_FOREGROUND_SERVICES_FROM_BACKGROUND.
+7 −0
Original line number Diff line number Diff line
@@ -22,6 +22,13 @@ flag {
    bug: "296558535"
}

flag {
    name: "fgs_disable_saw"
    namespace: "backstage_power"
    description: "Disable System Alert Window FGS start"
    bug: "296558535"
}

flag {
    name: "bfgs_managed_network_access"
    namespace: "backstage_power"