diff --git a/services/core/java/com/android/server/wm/ActivityMetricsLogger.java b/services/core/java/com/android/server/wm/ActivityMetricsLogger.java index d1374362505f6..f87856255b3e6 100644 --- a/services/core/java/com/android/server/wm/ActivityMetricsLogger.java +++ b/services/core/java/com/android/server/wm/ActivityMetricsLogger.java @@ -770,10 +770,6 @@ class ActivityMetricsLogger { if (compatStateInfo.mLastLoggedActivity == r) { compatStateInfo.mLastLoggedActivity = null; } - if (compatStateInfo.mVisibleActivities.isEmpty()) { - // No need to keep the entry if there are no visible activities. - mPackageUidToCompatStateInfo.remove(packageUid); - } } /** @@ -1269,13 +1265,14 @@ class ActivityMetricsLogger { * activity. *
If the current state is NOT_VISIBLE and the previous state which was logged by {@code - * activity} wasn't, looks for the first visible activity with the same package UID that has - * a letterboxed state, or a non-letterboxed state if there isn't one, and logs that state. + * activity} (or an activity that has been removed) wasn't, looks for the first visible activity + * with the same package UID that has a letterboxed state, or a non-letterboxed state if + * there isn't one, and logs that state. * *
This method assumes that the caller is wrapping the call with a synchronized block so * that there won't be a race condition between two activities with the same package. @@ -1311,14 +1308,14 @@ class ActivityMetricsLogger { if (!isVisible && !visibleActivities.isEmpty()) { // There is another visible activity for this package UID. - if (activity == lastLoggedActivity) { + if (lastLoggedActivity == null || activity == lastLoggedActivity) { // Make sure a new visible state is logged if needed. findAppCompatStateToLog(compatStateInfo, packageUid); } return; } - if (activity != lastLoggedActivity + if (lastLoggedActivity != null && activity != lastLoggedActivity && lastLoggedState != APP_COMPAT_STATE_CHANGED__STATE__NOT_VISIBLE && lastLoggedState != APP_COMPAT_STATE_CHANGED__STATE__NOT_LETTERBOXED) { // Another visible activity for this package UID has logged a letterboxed state. @@ -1332,15 +1329,25 @@ class ActivityMetricsLogger { * Looks for the first visible activity in {@code compatStateInfo} that has a letterboxed * state, or a non-letterboxed state if there isn't one, and logs that state for the given * {@code packageUid}. + * + *
If there is a visible activity in {@code compatStateInfo} with the same state as the
+ * last logged state for the given {@code packageUid}, changes the last logged activity to
+ * reference the first such activity without actually logging the same state twice.
*/
private void findAppCompatStateToLog(PackageCompatStateInfo compatStateInfo, int packageUid) {
final ArrayList