From d15063bb64b993e4553990ea56dd8d8e90a90deb Mon Sep 17 00:00:00 2001 From: Vishnu Nair Date: Tue, 11 Jun 2019 08:08:25 -0700 Subject: [PATCH] [AML] Check if launched activity has changed when handling visibility changes The trampoline activity launches a new activity and becomes invisible. AML receives a visibility changed notification for the trampoline activity and activity launching notification. If the intent is not resolved, and the activity is not launched before the visibility change is processed, AML will incorrectly cancel the app transition since it does not know if the app will ever draw on screen. This change checks if the launched activity has changed when handling the visibility change notification. Bug: 134694123 Test: atest ActivityMetricsLoggerTests Test: repro steps in bug Change-Id: I10744323b971ba709afa506e804d458de22c44e5 --- .../server/wm/ActivityMetricsLogger.java | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityMetricsLogger.java b/services/core/java/com/android/server/wm/ActivityMetricsLogger.java index feef5e27d26a1..bc0f74715240a 100644 --- a/services/core/java/com/android/server/wm/ActivityMetricsLogger.java +++ b/services/core/java/com/android/server/wm/ActivityMetricsLogger.java @@ -544,14 +544,30 @@ class ActivityMetricsLogger { // If we have an active transition that's waiting on a certain activity that will be // invisible now, we'll never get onWindowsDrawn, so abort the transition if necessary. - if (info != null && !hasVisibleNonFinishingActivity(t)) { - if (DEBUG_METRICS) Slog.i(TAG, "notifyVisibilityChanged to invisible" - + " activity=" + r); - logAppTransitionCancel(info); - mWindowingModeTransitionInfo.remove(r.getWindowingMode()); - if (mWindowingModeTransitionInfo.size() == 0) { - reset(true /* abort */, info, "notifyVisibilityChanged to invisible"); - } + + // We have no active transitions. + if (info == null) { + return; + } + + // The notified activity whose visibility changed is no longer the launched activity. + // We can still wait to get onWindowsDrawn. + if (info.launchedActivity != r) { + return; + } + + // Check if there is any activity in the task that is visible and not finishing. If the + // launched activity finished before it is drawn and if there is another activity in + // the task then that activity will be draw on screen. + if (hasVisibleNonFinishingActivity(t)) { + return; + } + + if (DEBUG_METRICS) Slog.i(TAG, "notifyVisibilityChanged to invisible activity=" + r); + logAppTransitionCancel(info); + mWindowingModeTransitionInfo.remove(r.getWindowingMode()); + if (mWindowingModeTransitionInfo.size() == 0) { + reset(true /* abort */, info, "notifyVisibilityChanged to invisible"); } } }