diff --git a/services/core/java/com/android/server/wm/ActivityMetricsLogger.java b/services/core/java/com/android/server/wm/ActivityMetricsLogger.java index 891654979965c..a21919cdb9609 100644 --- a/services/core/java/com/android/server/wm/ActivityMetricsLogger.java +++ b/services/core/java/com/android/server/wm/ActivityMetricsLogger.java @@ -741,7 +741,8 @@ class ActivityMetricsLogger { info.mWindowsDrawnDelayMs = info.calculateDelay(timestampNs); info.mIsDrawn = true; final TransitionInfoSnapshot infoSnapshot = new TransitionInfoSnapshot(info); - if (info.mLoggedTransitionStarting) { + if (info.mLoggedTransitionStarting || (!r.mDisplayContent.mOpeningApps.contains(r) + && !r.mTransitionController.isCollecting(r))) { done(false /* abort */, info, "notifyWindowsDrawn", timestampNs); } return infoSnapshot; 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 5b909a343a59a..1d52b7f540a17 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityMetricsLaunchObserverTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityMetricsLaunchObserverTests.java @@ -19,6 +19,7 @@ package com.android.server.wm; import static android.app.ActivityManager.START_SUCCESS; import static android.app.ActivityManager.START_TASK_TO_FRONT; import static android.content.ComponentName.createRelative; +import static android.view.WindowManager.TRANSIT_OPEN; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; @@ -75,6 +76,7 @@ public class ActivityMetricsLaunchObserverTests extends WindowTestsBase { private ActivityRecord mTrampolineActivity; private ActivityRecord mTopActivity; private ActivityOptions mActivityOptions; + private Transition mTransition; private boolean mLaunchTopByTrampoline; private boolean mNewActivityCreated = true; private long mExpectedStartedId; @@ -98,6 +100,11 @@ public class ActivityMetricsLaunchObserverTests extends WindowTestsBase { .setTask(mTrampolineActivity.getTask()) .setComponent(createRelative(DEFAULT_COMPONENT_PACKAGE_NAME, "TopActivity")) .build(); + mTopActivity.mDisplayContent.mOpeningApps.add(mTopActivity); + mTransition = new Transition(TRANSIT_OPEN, 0 /* flags */, + mTopActivity.mTransitionController, createTestBLASTSyncEngine()); + mTransition.mParticipants.add(mTopActivity); + mTopActivity.mTransitionController.moveToCollecting(mTransition); // becomes invisible when covered by mTopActivity mTrampolineActivity.mVisibleRequested = false; } @@ -437,11 +444,13 @@ public class ActivityMetricsLaunchObserverTests extends WindowTestsBase { @Test public void testActivityDrawnBeforeTransition() { mTopActivity.setVisible(false); - notifyActivityLaunching(mTopActivity.intent); + onIntentStarted(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. doReturn(true).when(mTopActivity).isReportedDrawn(); notifyWindowsDrawn(mTopActivity); + verifyNoMoreInteractions(mLaunchObserver); + notifyActivityLaunched(START_SUCCESS, mTopActivity); // If the launching activity was drawn when starting transition, the launch event should // be reported successfully. @@ -451,6 +460,18 @@ public class ActivityMetricsLaunchObserverTests extends WindowTestsBase { verifyOnActivityLaunchFinished(mTopActivity); } + @Test + public void testActivityDrawnWithoutTransition() { + mTopActivity.mDisplayContent.mOpeningApps.remove(mTopActivity); + mTransition.mParticipants.remove(mTopActivity); + onIntentStarted(mTopActivity.intent); + notifyAndVerifyActivityLaunched(mTopActivity); + notifyWindowsDrawn(mTopActivity); + // Even if there is no notifyTransitionStarting, the launch event can still be reported + // because the drawn activity is not involved in transition. + verifyOnActivityLaunchFinished(mTopActivity); + } + @Test public void testConcurrentLaunches() { onActivityLaunched(mTopActivity);