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

Commit 28d9534c authored by Varun Shah's avatar Varun Shah
Browse files

Use realtime to maintain 24-hour fgs tracking.

All FGS tracking currently is in the uptime base, however, the 24-hour
time limit reset window for time-limited fgs types is based in realtime.
Maintain a separate first-start-time bit in the tracking info which will
be used to determine if the time limits should be reset.

Bug: 330399444
Test: atest CtsFgsTimeoutTestCases
Change-Id: Iae008c74d598f4dce4cef8ae1a7cc7af7f2f63be
parent ffeed61e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2425,7 +2425,7 @@ public final class ActiveServices {
                                final long before24Hr = Math.max(0,
                                            SystemClock.elapsedRealtime() - (24 * 60 * 60 * 1000));
                                final long lastTimeOutAt = fgsTypeInfo.getTimeLimitExceededAt();
                                if (fgsTypeInfo.getFirstFgsStartTime() < before24Hr
                                if (fgsTypeInfo.getFirstFgsStartRealtime() < before24Hr
                                        || (lastTimeOutAt != Long.MIN_VALUE
                                            && r.app.mState.getLastTopTime() > lastTimeOutAt)) {
                                    // Reset the time limit info for this fgs type if it has been
+17 −5
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_FOREGROUND_
import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;

import android.annotation.ElapsedRealtimeLong;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UptimeMillisLong;
@@ -678,7 +679,11 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
     */
    static class TimeLimitedFgsInfo {
        @UptimeMillisLong
        private long mFirstFgsStartTime;
        private long mFirstFgsStartUptime;
        // The first fgs start time is maintained here separately in realtime-base
        // for the 24-hour window reset logic.
        @ElapsedRealtimeLong
        private long mFirstFgsStartRealtime;
        @UptimeMillisLong
        private long mLastFgsStartTime;
        @UptimeMillisLong
@@ -687,13 +692,19 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
        private long mTotalRuntime = 0;

        TimeLimitedFgsInfo(@UptimeMillisLong long startTime) {
            mFirstFgsStartTime = startTime;
            mFirstFgsStartUptime = startTime;
            mFirstFgsStartRealtime = SystemClock.elapsedRealtime();
            mLastFgsStartTime = startTime;
        }

        @UptimeMillisLong
        public long getFirstFgsStartTime() {
            return mFirstFgsStartTime;
        public long getFirstFgsStartUptime() {
            return mFirstFgsStartUptime;
        }

        @ElapsedRealtimeLong
        public long getFirstFgsStartRealtime() {
            return mFirstFgsStartRealtime;
        }

        public void setLastFgsStartTime(@UptimeMillisLong long startTime) {
@@ -724,7 +735,8 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
        }

        public void reset() {
            mFirstFgsStartTime = 0;
            mFirstFgsStartUptime = 0;
            mFirstFgsStartRealtime = 0;
            mLastFgsStartTime = 0;
            mTotalRuntime = 0;
            mTimeLimitExceededAt = Long.MIN_VALUE;