From a3beedb37e519b238c96de83186a9d5a37314b52 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Mon, 23 Aug 2021 21:54:44 +0800 Subject: [PATCH] Clear invisible undrawn activities when reporting drawn There may have initializing activities put in the same launch stack without state and visibility change. The case happens when using startActivities to start multiple activities at once. Without clearing the invisible pending draw activities, the launch event cannot end to report launch time and stop trace. Bug: 196917563 Bug: 192043869 Test: ActivityMetricsLaunchObserverTests#testConsecutiveLaunch Change-Id: If511a1526b803455a967f6bc1358a23e15a4234d --- .../com/android/server/wm/ActivityMetricsLogger.java | 1 + .../server/wm/ActivityMetricsLaunchObserverTests.java | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/services/core/java/com/android/server/wm/ActivityMetricsLogger.java b/services/core/java/com/android/server/wm/ActivityMetricsLogger.java index ce1592d87fcda..73ef385618dc9 100644 --- a/services/core/java/com/android/server/wm/ActivityMetricsLogger.java +++ b/services/core/java/com/android/server/wm/ActivityMetricsLogger.java @@ -703,6 +703,7 @@ class ActivityMetricsLogger { // Always calculate the delay because the caller may need to know the individual drawn time. info.mWindowsDrawnDelayMs = info.calculateDelay(timestampNs); info.removePendingDrawActivity(r); + info.updatePendingDraw(false /* keepInitializing */); final TransitionInfoSnapshot infoSnapshot = new TransitionInfoSnapshot(info); if (info.mLoggedTransitionStarting && info.allDrawn()) { done(false /* abort */, info, "notifyWindowsDrawn - all windows drawn", timestampNs); diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityMetricsLaunchObserverTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityMetricsLaunchObserverTests.java index 89a126b92bfa7..0b918025bb50b 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityMetricsLaunchObserverTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityMetricsLaunchObserverTests.java @@ -475,6 +475,16 @@ public class ActivityMetricsLaunchObserverTests extends WindowTestsBase { transitToDrawnAndVerifyOnLaunchFinished(mTopActivity); } + @Test + public void testConsecutiveLaunch() { + mTrampolineActivity.setState(ActivityRecord.State.INITIALIZING, "test"); + onActivityLaunched(mTrampolineActivity); + mActivityMetricsLogger.notifyActivityLaunching(mTopActivity.intent, + mTrampolineActivity /* caller */, mTrampolineActivity.getUid()); + notifyActivityLaunched(START_SUCCESS, mTopActivity); + transitToDrawnAndVerifyOnLaunchFinished(mTopActivity); + } + @Test public void testConsecutiveLaunchNewTask() { final IBinder launchCookie = mock(IBinder.class);