From 54cff64ec6ef818e270eb39a74d6a58068553d66 Mon Sep 17 00:00:00 2001 From: Jorim Jaggi Date: Thu, 15 Mar 2018 15:51:32 +0100 Subject: [PATCH] Insert correct app transition events for recents anim The transition delay will be the latency until all the leashes were created etc. Thus, the actual latency is going to be in WINDOWS_DRAWN_DELAY. Also fix an issue where we inadvertently started a transition, and then the transition logger was hanging. Bug: 72967764 Test: Swipe up from home button, observe eventlog Change-Id: I2b1fb7d9d694a629a33653c1fa3d5ed47f53de6b --- core/java/android/app/ActivityManagerInternal.java | 7 +++++++ core/proto/android/app/enums.proto | 3 +++ .../com/android/server/am/ActivityMetricsLogger.java | 10 +++++++++- .../java/com/android/server/am/RecentsAnimation.java | 6 ++++++ .../android/server/wm/RecentsAnimationController.java | 8 ++++++++ 5 files changed, 33 insertions(+), 1 deletion(-) diff --git a/core/java/android/app/ActivityManagerInternal.java b/core/java/android/app/ActivityManagerInternal.java index cab6744e3c818..2752fa9f1eb30 100644 --- a/core/java/android/app/ActivityManagerInternal.java +++ b/core/java/android/app/ActivityManagerInternal.java @@ -68,6 +68,13 @@ public abstract class ActivityManagerInternal { public static final int APP_TRANSITION_SNAPSHOT = AppProtoEnums.APP_TRANSITION_SNAPSHOT; // 4 + /** + * Type for {@link #notifyAppTransitionStarting}: The transition was started because it was a + * recents animation and we only needed to wait on the wallpaper. + */ + public static final int APP_TRANSITION_RECENTS_ANIM = + AppProtoEnums.APP_TRANSITION_RECENTS_ANIM; // 5 + /** * The bundle key to extract the assist data. */ diff --git a/core/proto/android/app/enums.proto b/core/proto/android/app/enums.proto index 5eb05be1a1d1e..1754e426fe93f 100644 --- a/core/proto/android/app/enums.proto +++ b/core/proto/android/app/enums.proto @@ -32,6 +32,9 @@ enum AppTransitionReasonEnum { APP_TRANSITION_TIMEOUT = 3; // The transition was started because of a we drew a task snapshot. APP_TRANSITION_SNAPSHOT = 4; + // The transition was started because it was a recents animation and we only needed to wait on + // the wallpaper. + APP_TRANSITION_RECENTS_ANIM = 5; } // ActivityManager.java PROCESS_STATEs diff --git a/services/core/java/com/android/server/am/ActivityMetricsLogger.java b/services/core/java/com/android/server/am/ActivityMetricsLogger.java index 352b75704d6e3..724dd3fd98475 100644 --- a/services/core/java/com/android/server/am/ActivityMetricsLogger.java +++ b/services/core/java/com/android/server/am/ActivityMetricsLogger.java @@ -299,7 +299,7 @@ class ActivityMetricsLogger { final boolean otherWindowModesLaunching = mWindowingModeTransitionInfo.size() > 0 && info == null; - if ((resultCode < 0 || launchedActivity == null || !processSwitch + if ((!isLoggableResultCode(resultCode) || launchedActivity == null || !processSwitch || windowingMode == WINDOWING_MODE_UNDEFINED) && !otherWindowModesLaunching) { // Failed to launch or it was not a process switch, so we don't care about the timing. @@ -321,6 +321,14 @@ class ActivityMetricsLogger { mCurrentTransitionDeviceUptime = (int) (SystemClock.uptimeMillis() / 1000); } + /** + * @return True if we should start logging an event for an activity start that returned + * {@code resultCode} and that we'll indeed get a windows drawn event. + */ + private boolean isLoggableResultCode(int resultCode) { + return resultCode == START_SUCCESS || resultCode == START_TASK_TO_FRONT; + } + /** * Notifies the tracker that all windows of the app have been drawn. */ diff --git a/services/core/java/com/android/server/am/RecentsAnimation.java b/services/core/java/com/android/server/am/RecentsAnimation.java index 91215685f35f3..da56ffd57bf3b 100644 --- a/services/core/java/com/android/server/am/RecentsAnimation.java +++ b/services/core/java/com/android/server/am/RecentsAnimation.java @@ -16,6 +16,7 @@ package com.android.server.am; +import static android.app.ActivityManager.START_TASK_TO_FRONT; import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; import static android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION; @@ -95,6 +96,8 @@ class RecentsAnimation implements RecentsAnimationCallbacks { } } + mStackSupervisor.getActivityMetricsLogger().notifyActivityLaunching(); + mService.setRunningRemoteAnimation(mCallingPid, true); mWindowManager.deferSurfaceLayout(); @@ -143,6 +146,9 @@ class RecentsAnimation implements RecentsAnimationCallbacks { // If we updated the launch-behind state, update the visibility of the activities after // we fetch the visible tasks to be controlled by the animation mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, PRESERVE_WINDOWS); + + mStackSupervisor.getActivityMetricsLogger().notifyActivityLaunched(START_TASK_TO_FRONT, + homeActivity); } finally { mWindowManager.continueSurfaceLayout(); Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); diff --git a/services/core/java/com/android/server/wm/RecentsAnimationController.java b/services/core/java/com/android/server/wm/RecentsAnimationController.java index 0b0df6ff588d5..3e72a713272ad 100644 --- a/services/core/java/com/android/server/wm/RecentsAnimationController.java +++ b/services/core/java/com/android/server/wm/RecentsAnimationController.java @@ -16,13 +16,16 @@ package com.android.server.wm; +import static android.app.ActivityManagerInternal.APP_TRANSITION_RECENTS_ANIM; import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; +import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; import static android.view.RemoteAnimationTarget.MODE_CLOSING; import static android.view.WindowManager.INPUT_CONSUMER_RECENTS_ANIMATION; import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; +import static com.android.server.wm.WindowManagerService.H.NOTIFY_APP_TRANSITION_STARTING; import static com.android.server.wm.proto.RemoteAnimationAdapterWrapperProto.TARGET; import static com.android.server.wm.proto.AnimationAdapterProto.REMOTE; @@ -37,6 +40,7 @@ import android.util.ArraySet; import android.util.Log; import android.util.Slog;import android.util.proto.ProtoOutputStream; import android.util.SparseBooleanArray; +import android.util.SparseIntArray; import android.util.proto.ProtoOutputStream; import android.view.IRecentsAnimationController; import android.view.IRecentsAnimationRunner; @@ -279,6 +283,10 @@ public class RecentsAnimationController { } catch (RemoteException e) { Slog.e(TAG, "Failed to start recents animation", e); } + final SparseIntArray reasons = new SparseIntArray(); + reasons.put(WINDOWING_MODE_FULLSCREEN, APP_TRANSITION_RECENTS_ANIM); + mService.mH.obtainMessage(NOTIFY_APP_TRANSITION_STARTING, + reasons).sendToTarget(); } void cancelAnimation() {