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

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

Merge "Gate the FGS timeout ANR behavior." into main

parents a3b8dba9 b524e253
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -50,3 +50,13 @@ flag {
         purpose: PURPOSE_BUGFIX
     }
}

flag {
     namespace: "backstage_power"
     name: "gate_fgs_timeout_anr_behavior"
     description: "Gate the new behavior where an ANR is thrown once an FGS times out."
     bug: "339315145"
     metadata {
         purpose: PURPOSE_BUGFIX
     }
}
+18 −3
Original line number Diff line number Diff line
@@ -2454,10 +2454,19 @@ public final class ActiveServices {
                                } else if (lastTimeOutAt > 0) {
                                    // Time limit was exhausted within the past 24 hours and the app
                                    // has not been in the TOP state since then, throw an exception.
                                    throw new ForegroundServiceStartNotAllowedException("Time limit"
                                            + " already exhausted for foreground service type "
                                    final String exceptionMsg = "Time limit already exhausted for"
                                            + " foreground service type "
                                            + ServiceInfo.foregroundServiceTypeToLabel(
                                                            foregroundServiceType));
                                                    foregroundServiceType);
                                    if (!android.app.Flags.gateFgsTimeoutAnrBehavior()) {
                                        throw new ForegroundServiceStartNotAllowedException(
                                                    exceptionMsg);
                                    } else {
                                        // Only throw an exception above while the new ANR behavior
                                        // is not gated, otherwise, reset the limit temporarily.
                                        Slog.wtf(TAG, exceptionMsg);
                                        fgsTypeInfo.reset();
                                    }
                                }
                            }
                        } else {
@@ -3943,6 +3952,12 @@ public final class ActiveServices {
                + ServiceInfo.foregroundServiceTypeToLabel(fgsType)
                + " did not stop within its timeout: " + sr.getComponentName();

        if (android.app.Flags.gateFgsTimeoutAnrBehavior()) {
            // Log a WTF instead of throwing an ANR while the new behavior is gated.
            Slog.wtf(TAG, reason);
            return;
        }

        final TimeoutRecord tr = TimeoutRecord.forFgsTimeout(reason);
        tr.mLatencyTracker.waitingOnAMSLockStarted();
        synchronized (mAm) {