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

Commit 528d0277 authored by Varun Shah's avatar Varun Shah Committed by Android Build Coastguard Worker
Browse files

Make sure last top time is valid.

In some cases, the app can start an FGS due to certain launch
exemptions without the app being in the TOP state. If this is the
case, the app's last TOP time will always be Long.MIN_VALUE, causing
the handler to repeatedly send messages and leading to a deadlock.

Fixes: 337740958
Fixes: 337701437
Test: atest CtsFgsTimeoutTestCases
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:24dad64b89fcb4c5fbb553b7523c527309dc30fc)
Merged-In: Idf303b7acfd73f46481309029816686a5161ada7
Change-Id: Idf303b7acfd73f46481309029816686a5161ada7
parent bd69b27b
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -3864,10 +3864,12 @@ public final class ActiveServices {
            final long lastTopTime = sr.app.mState.getLastTopTime();
            final long constantTimeLimit = getTimeLimitForFgsType(fgsType);
            final long nowUptime = SystemClock.uptimeMillis();
            if (constantTimeLimit > (nowUptime - lastTopTime)) {
            if (lastTopTime != Long.MIN_VALUE && constantTimeLimit > (nowUptime - lastTopTime)) {
                // Discard any other messages for this service
                mFGSAnrTimer.discard(sr);
                mAm.mHandler.removeMessages(ActivityManagerService.SERVICE_FGS_TIMEOUT_MSG, sr);
                // The app was in the TOP state after the FGS was started so its time allowance
                // should be counted from that time since this is considered a user interaction
                mFGSAnrTimer.discard(sr);
                final Message msg = mAm.mHandler.obtainMessage(
                                        ActivityManagerService.SERVICE_FGS_TIMEOUT_MSG, sr);
                mAm.mHandler.sendMessageAtTime(msg, lastTopTime + constantTimeLimit);