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

Commit 888daa96 authored by Varun Shah's avatar Varun Shah Committed by Android Build Coastguard Worker
Browse files

Update reset logic for time limited foreground services.

- When the app is force-stopped, reset its limits to handle cases
  where the user force stops an app when it continously crashes.

- When the app is currently in the TOP state (or better), also
  reset its limits even if the time limit has been exhausted
  since this could be a user requested FGS start.

Bug: 330399444
Test: atest CtsFgsTimeoutTestCases
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:8e1b1be29aa99acf1b3e650a1fd87ecf85002329)
Merged-In: I80687713591cf146b70f196a4ffaeb0f3c26a1e5
Change-Id: I80687713591cf146b70f196a4ffaeb0f3c26a1e5
parent 295ebddd
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -2415,7 +2415,9 @@ public final class ActiveServices {
                                        != ServiceInfo.FOREGROUND_SERVICE_TYPE_NONE) {
                        // Calling startForeground on a FGS type which has a time limit will only be
                        // allowed if the app is in a state where it can normally start another FGS
                        // and it hasn't hit the time limit for that type in the past 24hrs.
                        // and it hasn't hit its time limit in the past 24hrs, or it has been in the
                        // foreground after it hit its time limit, or it is currently in the
                        // TOP (or better) proc state.

                        // See if the app could start an FGS or not.
                        r.clearFgsAllowStart();
@@ -2441,11 +2443,13 @@ public final class ActiveServices {
                                            SystemClock.elapsedRealtime() - (24 * 60 * 60 * 1000));
                                final long lastTimeOutAt = fgsTypeInfo.getTimeLimitExceededAt();
                                if (fgsTypeInfo.getFirstFgsStartRealtime() < before24Hr
                                        || r.app.mState.getCurProcState() <= PROCESS_STATE_TOP
                                        || (lastTimeOutAt != Long.MIN_VALUE
                                            && r.app.mState.getLastTopTime() > lastTimeOutAt)) {
                                    // Reset the time limit info for this fgs type if it has been
                                    // more than 24hrs since the first fgs start or if the app was
                                    // in the TOP state after time limit was exhausted.
                                    // more than 24hrs since the first fgs start or if the app is
                                    // currently in the TOP state or was in the TOP state after
                                    // the time limit was exhausted previously.
                                    fgsTypeInfo.reset();
                                } else if (lastTimeOutAt > 0) {
                                    // Time limit was exhausted within the past 24 hours and the app
+5 −2
Original line number Diff line number Diff line
@@ -4342,6 +4342,7 @@ public class ActivityManagerService extends IActivityManager.Stub
            mServices.bringDownDisabledPackageServicesLocked(
                    packageName, null, userId, false, true, true);
            mServices.onUidRemovedLocked(uid);
            if (mBooted) {
                mAtmInternal.resumeTopActivities(true);
@@ -4372,9 +4373,10 @@ public class ActivityManagerService extends IActivityManager.Stub
            Slog.w(TAG, "Can't force stop all processes of all users, that is insane!");
        }
        final int uid = getPackageManagerInternal().getPackageUid(packageName,
                            MATCH_DEBUG_TRIAGED_MISSING | MATCH_ANY_USER, UserHandle.USER_SYSTEM);
        if (appId < 0 && packageName != null) {
            appId = UserHandle.getAppId(getPackageManagerInternal().getPackageUid(packageName,
                    MATCH_DEBUG_TRIAGED_MISSING | MATCH_ANY_USER, UserHandle.USER_SYSTEM));
            appId = UserHandle.getAppId(uid);
        }
        boolean didSomething;
@@ -4418,6 +4420,7 @@ public class ActivityManagerService extends IActivityManager.Stub
            }
            didSomething = true;
        }
        mServices.onUidRemovedLocked(uid);
        if (packageName == null) {
            // Remove all sticky broadcasts from this user.