From 292ae8c060b23750422af0f822c0ca297addbfb7 Mon Sep 17 00:00:00 2001 From: Calvin Huang Date: Tue, 8 Oct 2024 09:53:32 -0700 Subject: Update PAUSE usage state when activity move from RESUMED to STOPPING In some multitasking scenarios, an activity can be scheduled to move directly from the RESUMED state to the STOPPED state, bypassing the PAUSED state. But the activity will cycled through to PAUSED state anyway. Need to update the PAUSED usage state in this case. Test: atest com.google.android.gts.playstore.UsageStatsHostTest Test: atest ActivityRecordTests Bug: 368228446 Flag: EXEMPT bugfix Change-Id: Ib66e9627d4c7ed857df9d6ae614e2001ad2d97b6 --- services/core/java/com/android/server/wm/ActivityRecord.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 12d733fc8c1a..8d0639b1e73b 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -5863,6 +5863,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A return; } + final State prevState = mState; mState = state; if (getTaskFragment() != null) { @@ -5903,6 +5904,14 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A mAtmService.updateBatteryStats(this, false); mAtmService.updateActivityUsageStats(this, Event.ACTIVITY_PAUSED); break; + case STOPPING: + // It is possible that an Activity is scheduled to be STOPPED directly from RESUMED + // state. Updating the PAUSED usage state in that case, since the Activity will be + // STOPPED while cycled through the PAUSED state. + if (prevState == RESUMED) { + mAtmService.updateActivityUsageStats(this, Event.ACTIVITY_PAUSED); + } + break; case STOPPED: mAtmService.updateActivityUsageStats(this, Event.ACTIVITY_STOPPED); if (mDisplayContent != null) { -- cgit v1.2.3-59-g8ed1b