From c0f0e1b235828c88ab945ea159d32352ff613c58 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Thu, 14 Jan 2021 18:09:32 +0800 Subject: [PATCH] Do not abort launch logger by invisible drawn activity For a special complex case: A no-display trampoline activity launches main activity in the same task (no starting window), and then the main activity launches trampoline and main again consecutively. If the drawn event of main is reported before the 2nd launch of main, the launch event log will be canceled by seeing the drawn state before transition. Because there will be a transition to commit window visibility, the case can be addressed by allowing invisible drawn activity as a valid launch event. Then the launch time can be reported when notifying transition starting. Bug: 176687862 Test: ActivityMetricsLaunchObserverTests#testActivityDrawnBeforeTransition Change-Id: I81ec1695038216490537bdac6defcd9e6d75e1f8 Merged-In: I81ec1695038216490537bdac6defcd9e6d75e1f8 (cherry picked from commit dc21a33a80fedffe332e1347bde8c1933dd4f4c2) --- .../android/server/wm/ActivityMetricsLogger.java | 4 ++-- .../wm/ActivityMetricsLaunchObserverTests.java | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityMetricsLogger.java b/services/core/java/com/android/server/wm/ActivityMetricsLogger.java index 8f59eef495167..eec2e41eb5db5 100644 --- a/services/core/java/com/android/server/wm/ActivityMetricsLogger.java +++ b/services/core/java/com/android/server/wm/ActivityMetricsLogger.java @@ -264,7 +264,7 @@ class ActivityMetricsLogger { return; } mLastLaunchedActivity = r; - if (!r.noDisplay) { + if (!r.noDisplay && !r.mDrawn) { if (DEBUG_METRICS) Slog.i(TAG, "Add pending draw " + r); mPendingDrawActivities.add(r); } @@ -546,7 +546,7 @@ class ActivityMetricsLogger { + " processSwitch=" + processSwitch + " info=" + info); } - if (launchedActivity.mDrawn) { + if (launchedActivity.mDrawn && launchedActivity.isVisible()) { // Launched activity is already visible. We cannot measure windows drawn delay. abort(info, "launched activity already visible"); return; 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 5b516a9de350d..53a6d3ff599fc 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityMetricsLaunchObserverTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityMetricsLaunchObserverTests.java @@ -311,6 +311,22 @@ public class ActivityMetricsLaunchObserverTests extends ActivityTestsBase { verifyNoMoreInteractions(mLaunchObserver); } + @Test + public void testActivityDrawnBeforeTransition() { + mTopActivity.setVisible(false); + notifyActivityLaunching(mTopActivity.intent); + // Assume the activity is launched the second time consecutively. The drawn event is from + // the first time (omitted in test) launch that is earlier than transition. + mTopActivity.mDrawn = true; + notifyWindowsDrawn(mTopActivity); + notifyActivityLaunched(START_SUCCESS, mTopActivity); + // If the launching activity was drawn when starting transition, the launch event should + // be reported successfully. + notifyTransitionStarting(mTopActivity); + + verifyOnActivityLaunchFinished(mTopActivity); + } + @Test public void testActivityRecordProtoIsNotTooBig() { // The ActivityRecordProto must not be too big, otherwise converting it at runtime