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

Commit 77c06015 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Gate the new FGS time limit logic with a targetSdk check." into main

parents 5786c559 a7250e02
Loading
Loading
Loading
Loading
+23 −7
Original line number Diff line number Diff line
@@ -507,6 +507,18 @@ public final class ActiveServices {
     */
    final SparseArray<SparseArray<TimeLimitedFgsInfo>> mTimeLimitedFgsInfo = new SparseArray<>();

    /**
     * Foreground services of certain types will now have a time limit. If the foreground service
     * of the offending type is not stopped within the allocated time limit, it will receive a
     * callback via {@link Service#onTimeout(int, int)} and it must then be stopped within a few
     * seconds. If an app fails to do so, it will be declared an ANR.
     *
     * @see Service#onTimeout(int, int) onTimeout callback for additional details
     */
    @ChangeId
    @EnabledSince(targetSdkVersion = VERSION_CODES.VANILLA_ICE_CREAM)
    static final long FGS_INTRODUCE_TIME_LIMITS = 317799821L;

    // allowlisted packageName.
    ArraySet<String> mAllowListWhileInUsePermissionInFgs = new ArraySet<>();

@@ -2396,7 +2408,10 @@ public final class ActiveServices {
                                // "if (r.mAllowStartForeground == REASON_DENIED...)" block below.
                            }
                        }
                    } else if (getTimeLimitedFgsType(foregroundServiceType)
                    } else if (CompatChanges.isChangeEnabled(
                                    FGS_INTRODUCE_TIME_LIMITS, r.appInfo.uid)
                                && android.app.Flags.introduceNewServiceOntimeoutCallback()
                                && getTimeLimitedFgsType(foregroundServiceType)
                                        != 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
@@ -2686,7 +2701,10 @@ public final class ActiveServices {
                    mAm.notifyPackageUse(r.serviceInfo.packageName,
                            PackageManager.NOTIFY_PACKAGE_USE_FOREGROUND_SERVICE);

                    if (CompatChanges.isChangeEnabled(FGS_INTRODUCE_TIME_LIMITS, r.appInfo.uid)
                            && android.app.Flags.introduceNewServiceOntimeoutCallback()) {
                        maybeUpdateFgsTrackingLocked(r, previousFgsType);
                    }
                } else {
                    if (DEBUG_FOREGROUND_SERVICE) {
                        Slog.d(TAG, "Suppressing startForeground() for FAS " + r);
@@ -3907,12 +3925,10 @@ public final class ActiveServices {
                Slog.w(TAG_SERVICE, "Exception from scheduleTimeoutServiceForType: " + e);
            }

            if (android.app.Flags.introduceNewServiceOntimeoutCallback()) {
            // ANR the service after giving the service some time to clean up.
            mFGSAnrTimer.start(sr, mAm.mConstants.mFgsAnrExtraWaitDuration);
        }
    }
    }

    void onFgsAnrTimeout(ServiceRecord sr) {
        final int fgsType = getTimeLimitedFgsType(sr.foregroundServiceType);