Loading services/core/java/com/android/server/wm/ActivityMetricsLogger.java +8 −12 Original line number Diff line number Diff line Loading @@ -129,7 +129,6 @@ class ActivityMetricsLogger { */ private static final int IGNORE_CALLER = -1; private static final int INVALID_DELAY = -1; private static final int INVALID_TRANSITION_TYPE = -1; // Preallocated strings we are sending to tron, so we don't have to allocate a new one every // time we log. Loading Loading @@ -224,22 +223,19 @@ class ActivityMetricsLogger { static TransitionInfo create(@NonNull ActivityRecord r, @NonNull LaunchingState launchingState, boolean processRunning, boolean processSwitch, int startResult) { int transitionType = INVALID_TRANSITION_TYPE; if (processRunning) { if (startResult == START_SUCCESS) { transitionType = TYPE_TRANSITION_WARM_LAUNCH; } else if (startResult == START_TASK_TO_FRONT) { transitionType = TYPE_TRANSITION_HOT_LAUNCH; if (startResult != START_SUCCESS && startResult != START_TASK_TO_FRONT) { return null; } } else if (startResult == START_SUCCESS || startResult == START_TASK_TO_FRONT) { final int transitionType; if (processRunning) { transitionType = r.attachedToProcess() ? TYPE_TRANSITION_HOT_LAUNCH : TYPE_TRANSITION_WARM_LAUNCH; } else { // Task may still exist when cold launching an activity and the start result will be // set to START_TASK_TO_FRONT. Treat this as a COLD launch. transitionType = TYPE_TRANSITION_COLD_LAUNCH; } if (transitionType == INVALID_TRANSITION_TYPE) { // That means the startResult is neither START_SUCCESS nor START_TASK_TO_FRONT. return null; } return new TransitionInfo(r, launchingState, transitionType, processRunning, processSwitch); } Loading services/tests/wmtests/src/com/android/server/wm/ActivityMetricsLaunchObserverTests.java +13 −4 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.timeout; import android.app.WaitResult; import android.content.Intent; import android.os.SystemClock; import android.platform.test.annotations.Presubmit; Loading Loading @@ -163,10 +164,15 @@ public class ActivityMetricsLaunchObserverTests extends ActivityTestsBase { @Test public void testOnActivityLaunchFinished() { // Assume that the process is started (ActivityBuilder has mocked the returned value of // ATMS#getProcessController) but the activity has not attached process. mTopActivity.app = null; onActivityLaunched(mTopActivity); notifyTransitionStarting(mTopActivity); notifyWindowsDrawn(mTopActivity); final ActivityMetricsLogger.TransitionInfoSnapshot info = notifyWindowsDrawn(mTopActivity); assertWithMessage("Warm launch").that(info.getLaunchState()) .isEqualTo(WaitResult.LAUNCH_STATE_WARM); verifyOnActivityLaunchFinished(mTopActivity); verifyNoMoreInteractions(mLaunchObserver); Loading Loading @@ -201,7 +207,7 @@ public class ActivityMetricsLaunchObserverTests extends ActivityTestsBase { notifyActivityLaunching(noDrawnActivity.intent); notifyActivityLaunched(START_SUCCESS, noDrawnActivity); noDrawnActivity.destroyIfPossible("test"); noDrawnActivity.mVisibleRequested = false; mActivityMetricsLogger.notifyVisibilityChanged(noDrawnActivity); verifyAsync(mLaunchObserver).onActivityLaunchCancelled(eqProto(noDrawnActivity)); Loading @@ -217,6 +223,9 @@ public class ActivityMetricsLaunchObserverTests extends ActivityTestsBase { notifyTransitionStarting(mTopActivity); // The pending fully drawn event should send when the actual windows drawn event occurs. notifyWindowsDrawn(mTopActivity); final ActivityMetricsLogger.TransitionInfoSnapshot info = notifyWindowsDrawn(mTopActivity); assertWithMessage("Hot launch").that(info.getLaunchState()) .isEqualTo(WaitResult.LAUNCH_STATE_HOT); verifyAsync(mLaunchObserver).onReportFullyDrawn(eqProto(mTopActivity), anyLong()); verifyOnActivityLaunchFinished(mTopActivity); Loading Loading @@ -260,8 +269,8 @@ public class ActivityMetricsLaunchObserverTests extends ActivityTestsBase { mActivityMetricsLogger.notifyTransitionStarting(reasons); } private void notifyWindowsDrawn(ActivityRecord r) { mActivityMetricsLogger.notifyWindowsDrawn(r, SystemClock.elapsedRealtimeNanos()); private ActivityMetricsLogger.TransitionInfoSnapshot notifyWindowsDrawn(ActivityRecord r) { return mActivityMetricsLogger.notifyWindowsDrawn(r, SystemClock.elapsedRealtimeNanos()); } @Test Loading Loading
services/core/java/com/android/server/wm/ActivityMetricsLogger.java +8 −12 Original line number Diff line number Diff line Loading @@ -129,7 +129,6 @@ class ActivityMetricsLogger { */ private static final int IGNORE_CALLER = -1; private static final int INVALID_DELAY = -1; private static final int INVALID_TRANSITION_TYPE = -1; // Preallocated strings we are sending to tron, so we don't have to allocate a new one every // time we log. Loading Loading @@ -224,22 +223,19 @@ class ActivityMetricsLogger { static TransitionInfo create(@NonNull ActivityRecord r, @NonNull LaunchingState launchingState, boolean processRunning, boolean processSwitch, int startResult) { int transitionType = INVALID_TRANSITION_TYPE; if (processRunning) { if (startResult == START_SUCCESS) { transitionType = TYPE_TRANSITION_WARM_LAUNCH; } else if (startResult == START_TASK_TO_FRONT) { transitionType = TYPE_TRANSITION_HOT_LAUNCH; if (startResult != START_SUCCESS && startResult != START_TASK_TO_FRONT) { return null; } } else if (startResult == START_SUCCESS || startResult == START_TASK_TO_FRONT) { final int transitionType; if (processRunning) { transitionType = r.attachedToProcess() ? TYPE_TRANSITION_HOT_LAUNCH : TYPE_TRANSITION_WARM_LAUNCH; } else { // Task may still exist when cold launching an activity and the start result will be // set to START_TASK_TO_FRONT. Treat this as a COLD launch. transitionType = TYPE_TRANSITION_COLD_LAUNCH; } if (transitionType == INVALID_TRANSITION_TYPE) { // That means the startResult is neither START_SUCCESS nor START_TASK_TO_FRONT. return null; } return new TransitionInfo(r, launchingState, transitionType, processRunning, processSwitch); } Loading
services/tests/wmtests/src/com/android/server/wm/ActivityMetricsLaunchObserverTests.java +13 −4 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.timeout; import android.app.WaitResult; import android.content.Intent; import android.os.SystemClock; import android.platform.test.annotations.Presubmit; Loading Loading @@ -163,10 +164,15 @@ public class ActivityMetricsLaunchObserverTests extends ActivityTestsBase { @Test public void testOnActivityLaunchFinished() { // Assume that the process is started (ActivityBuilder has mocked the returned value of // ATMS#getProcessController) but the activity has not attached process. mTopActivity.app = null; onActivityLaunched(mTopActivity); notifyTransitionStarting(mTopActivity); notifyWindowsDrawn(mTopActivity); final ActivityMetricsLogger.TransitionInfoSnapshot info = notifyWindowsDrawn(mTopActivity); assertWithMessage("Warm launch").that(info.getLaunchState()) .isEqualTo(WaitResult.LAUNCH_STATE_WARM); verifyOnActivityLaunchFinished(mTopActivity); verifyNoMoreInteractions(mLaunchObserver); Loading Loading @@ -201,7 +207,7 @@ public class ActivityMetricsLaunchObserverTests extends ActivityTestsBase { notifyActivityLaunching(noDrawnActivity.intent); notifyActivityLaunched(START_SUCCESS, noDrawnActivity); noDrawnActivity.destroyIfPossible("test"); noDrawnActivity.mVisibleRequested = false; mActivityMetricsLogger.notifyVisibilityChanged(noDrawnActivity); verifyAsync(mLaunchObserver).onActivityLaunchCancelled(eqProto(noDrawnActivity)); Loading @@ -217,6 +223,9 @@ public class ActivityMetricsLaunchObserverTests extends ActivityTestsBase { notifyTransitionStarting(mTopActivity); // The pending fully drawn event should send when the actual windows drawn event occurs. notifyWindowsDrawn(mTopActivity); final ActivityMetricsLogger.TransitionInfoSnapshot info = notifyWindowsDrawn(mTopActivity); assertWithMessage("Hot launch").that(info.getLaunchState()) .isEqualTo(WaitResult.LAUNCH_STATE_HOT); verifyAsync(mLaunchObserver).onReportFullyDrawn(eqProto(mTopActivity), anyLong()); verifyOnActivityLaunchFinished(mTopActivity); Loading Loading @@ -260,8 +269,8 @@ public class ActivityMetricsLaunchObserverTests extends ActivityTestsBase { mActivityMetricsLogger.notifyTransitionStarting(reasons); } private void notifyWindowsDrawn(ActivityRecord r) { mActivityMetricsLogger.notifyWindowsDrawn(r, SystemClock.elapsedRealtimeNanos()); private ActivityMetricsLogger.TransitionInfoSnapshot notifyWindowsDrawn(ActivityRecord r) { return mActivityMetricsLogger.notifyWindowsDrawn(r, SystemClock.elapsedRealtimeNanos()); } @Test Loading