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

Commit 8504828e authored by Christopher Tate's avatar Christopher Tate
Browse files

Correct bg service start policy re bg-restricted state

Apps under strict bg restrictions shouldn't have that policy
applied when they're showing foreground UI.

Bug: 77345409
Test: ApiDemos
Test: maps navigation
Change-Id: I16b72c26d3e29b547442c1501a7e1761b182a25f
parent a57290a4
Loading
Loading
Loading
Loading
+15 −4
Original line number Original line Diff line number Diff line
@@ -415,12 +415,23 @@ public final class ActiveServices {
            return null;
            return null;
        }
        }


        // If the app has strict background restrictions, we treat any service
        // If we're starting indirectly (e.g. from PendingIntent), figure out whether
        // start analogously to the legacy-app forced-restrictions case.
        // we're launching into an app in a background state.
        final int uidState = mAm.getUidStateLocked(r.appInfo.uid);
        if (DEBUG_SERVICE) {
            Slog.v(TAG_SERVICE, "Uid state " + uidState + " indirect starting " + r.shortName);
        }
        final boolean bgLaunch = (uidState >
                ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND);

        // If the app has strict background restrictions, we treat any bg service
        // start analogously to the legacy-app forced-restrictions case, regardless
        // of its target SDK version.
        boolean forcedStandby = false;
        boolean forcedStandby = false;
        if (appRestrictedAnyInBackground(r.appInfo.uid, r.packageName)) {
        if (bgLaunch && appRestrictedAnyInBackground(r.appInfo.uid, r.packageName)) {
            if (DEBUG_FOREGROUND_SERVICE) {
            if (DEBUG_FOREGROUND_SERVICE) {
                Slog.d(TAG, "Forcing bg-only service start only for " + r.shortName);
                Slog.d(TAG, "Forcing bg-only service start only for " + r.shortName
                        + " : bgLaunch=" + bgLaunch + " callerFg=" + callerFg);
            }
            }
            forcedStandby = true;
            forcedStandby = true;
        }
        }