summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Varun Shah <varunshah@google.com> 2024-04-19 00:49:30 +0000
committer Varun Shah <varunshah@google.com> 2024-04-22 21:44:17 +0000
commit3d7aa89d939f9998ed437b5d218d8007b9d9f30e (patch)
tree795f8e8596fdc413cfbcdf6f3f11a6db928d8770
parente726406a73074c6e2023bcc1dfe711cd2f123d6a (diff)
Update time-limited fgs tracked to use realtime.
Instead of using uptime, use realtime to do all the tracking for time-limited FGS types - this is mainly to ensure the 24hr rolling window is tracked accurately w.r.t. the time limits. Bug: 330399444 Test: atest CtsFgsTimeoutTestCases Change-Id: Ie6b3459cf4882b6a91c0a53fe2bd64901142957f
-rw-r--r--services/core/java/com/android/server/am/ActiveServices.java16
-rw-r--r--services/core/java/com/android/server/am/ServiceRecord.java26
2 files changed, 20 insertions, 22 deletions
diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java
index 2fa0be21a8b0..95c485784af0 100644
--- a/services/core/java/com/android/server/am/ActiveServices.java
+++ b/services/core/java/com/android/server/am/ActiveServices.java
@@ -2422,8 +2422,6 @@ public final class ActiveServices {
getTimeLimitedFgsType(foregroundServiceType);
final TimeLimitedFgsInfo fgsTypeInfo = fgsInfo.get(timeLimitedFgsType);
if (fgsTypeInfo != null) {
- // TODO(b/330399444): check to see if all time book-keeping for
- // time limited types should use elapsedRealtime instead of uptime
final long before24Hr = Math.max(0,
SystemClock.elapsedRealtime() - (24 * 60 * 60 * 1000));
final long lastTimeOutAt = fgsTypeInfo.getTimeLimitExceededAt();
@@ -3757,7 +3755,7 @@ public final class ActiveServices {
}
traceInstant("FGS start: ", sr);
- final long nowUptime = SystemClock.uptimeMillis();
+ final long nowRealtime = SystemClock.elapsedRealtime();
// Fetch/create/update the fgs info for the time-limited type.
SparseArray<TimeLimitedFgsInfo> fgsInfo = mTimeLimitedFgsInfo.get(sr.appInfo.uid);
@@ -3768,10 +3766,10 @@ public final class ActiveServices {
final int timeLimitedFgsType = getTimeLimitedFgsType(sr.foregroundServiceType);
TimeLimitedFgsInfo fgsTypeInfo = fgsInfo.get(timeLimitedFgsType);
if (fgsTypeInfo == null) {
- fgsTypeInfo = sr.createTimeLimitedFgsInfo(nowUptime);
+ fgsTypeInfo = sr.createTimeLimitedFgsInfo(nowRealtime);
fgsInfo.put(timeLimitedFgsType, fgsTypeInfo);
}
- fgsTypeInfo.setLastFgsStartTime(nowUptime);
+ fgsTypeInfo.setLastFgsStartTime(nowRealtime);
// We'll cancel the previous ANR timer and start a fresh one below.
mFGSAnrTimer.cancel(sr);
@@ -3845,14 +3843,14 @@ public final class ActiveServices {
final TimeLimitedFgsInfo fgsTypeInfo = fgsInfo.get(fgsType);
if (fgsTypeInfo != null) {
// Update total runtime for the time-limited fgs type and mark it as timed out.
- final long nowUptime = SystemClock.uptimeMillis();
+ final long nowRealtime = SystemClock.elapsedRealtime();
fgsTypeInfo.updateTotalRuntime();
- fgsTypeInfo.setTimeLimitExceededAt(nowUptime);
+ fgsTypeInfo.setTimeLimitExceededAt(nowRealtime);
logFGSStateChangeLocked(sr,
FOREGROUND_SERVICE_STATE_CHANGED__STATE__TIMED_OUT,
- nowUptime > fgsTypeInfo.getLastFgsStartTime()
- ? (int) (nowUptime - fgsTypeInfo.getLastFgsStartTime()) : 0,
+ nowRealtime > fgsTypeInfo.getLastFgsStartTime()
+ ? (int) (nowRealtime - fgsTypeInfo.getLastFgsStartTime()) : 0,
FGS_STOP_REASON_UNKNOWN,
FGS_TYPE_POLICY_CHECK_UNKNOWN,
FOREGROUND_SERVICE_STATE_CHANGED__FGS_START_API__FGSSTARTAPI_NA,
diff --git a/services/core/java/com/android/server/am/ServiceRecord.java b/services/core/java/com/android/server/am/ServiceRecord.java
index 045d137edf43..065f3bd6b1e6 100644
--- a/services/core/java/com/android/server/am/ServiceRecord.java
+++ b/services/core/java/com/android/server/am/ServiceRecord.java
@@ -30,9 +30,9 @@ 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;
import android.app.BackgroundStartPrivileges;
import android.app.IApplicationThread;
import android.app.Notification;
@@ -677,46 +677,46 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
* Data container class to help track certain fgs info for time-restricted types.
*/
static class TimeLimitedFgsInfo {
- @UptimeMillisLong
+ @ElapsedRealtimeLong
private long mFirstFgsStartTime;
- @UptimeMillisLong
+ @ElapsedRealtimeLong
private long mLastFgsStartTime;
- @UptimeMillisLong
+ @ElapsedRealtimeLong
private long mTimeLimitExceededAt = Long.MIN_VALUE;
private long mTotalRuntime = 0;
- TimeLimitedFgsInfo(@UptimeMillisLong long startTime) {
+ TimeLimitedFgsInfo(@ElapsedRealtimeLong long startTime) {
mFirstFgsStartTime = startTime;
mLastFgsStartTime = startTime;
}
- @UptimeMillisLong
+ @ElapsedRealtimeLong
public long getFirstFgsStartTime() {
return mFirstFgsStartTime;
}
- public void setLastFgsStartTime(@UptimeMillisLong long startTime) {
+ public void setLastFgsStartTime(@ElapsedRealtimeLong long startTime) {
mLastFgsStartTime = startTime;
}
- @UptimeMillisLong
+ @ElapsedRealtimeLong
public long getLastFgsStartTime() {
return mLastFgsStartTime;
}
public void updateTotalRuntime() {
- mTotalRuntime += SystemClock.uptimeMillis() - mLastFgsStartTime;
+ mTotalRuntime += SystemClock.elapsedRealtime() - mLastFgsStartTime;
}
public long getTotalRuntime() {
return mTotalRuntime;
}
- public void setTimeLimitExceededAt(@UptimeMillisLong long timeLimitExceededAt) {
+ public void setTimeLimitExceededAt(@ElapsedRealtimeLong long timeLimitExceededAt) {
mTimeLimitExceededAt = timeLimitExceededAt;
}
- @UptimeMillisLong
+ @ElapsedRealtimeLong
public long getTimeLimitExceededAt() {
return mTimeLimitExceededAt;
}
@@ -1858,8 +1858,8 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
/**
* Called when a time-limited FGS starts.
*/
- public TimeLimitedFgsInfo createTimeLimitedFgsInfo(long nowUptime) {
- return new TimeLimitedFgsInfo(nowUptime);
+ public TimeLimitedFgsInfo createTimeLimitedFgsInfo(@ElapsedRealtimeLong long nowRealtime) {
+ return new TimeLimitedFgsInfo(nowRealtime);
}
/**