From 54fc5e0e52464ec41d115d7ffd44ce7d25c1a6e2 Mon Sep 17 00:00:00 2001 From: Alex Chau Date: Thu, 5 Sep 2024 16:45:44 +0100 Subject: [PATCH] Improve Task launch logging and function naming Fix: 360186814 Test: manual Flag: EXEMPT REFACTOR Change-Id: I22c5a08382800941f0dd8f64f6129438ac04edaa --- .../taskbar/TaskbarActivityContext.java | 2 +- .../uioverrides/QuickstepLauncher.java | 2 +- .../uioverrides/states/OverviewState.java | 2 +- .../android/quickstep/AbsSwipeUpHandler.java | 4 +- .../quickstep/OverviewCommandHelper.kt | 2 +- .../quickstep/TaskShortcutFactory.java | 2 +- .../quickstep/views/DesktopTaskView.kt | 11 +- .../quickstep/views/GroupedTaskView.kt | 18 +- .../android/quickstep/views/RecentsView.java | 2 +- .../com/android/quickstep/views/TaskView.kt | 214 +++++++++--------- 10 files changed, 136 insertions(+), 123 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java index 47ae741908..5f733b066e 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java @@ -1431,7 +1431,7 @@ public class TaskbarActivityContext extends BaseTaskbarContext { && !(foundTaskView instanceof DesktopTaskView)) { TestLogging.recordEvent( TestProtocol.SEQUENCE_MAIN, "start: taskbarAppIcon"); - foundTaskView.launchTasks(); + foundTaskView.launchWithAnimation(); return; } } diff --git a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java index 55c1885793..0b385d9a32 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java +++ b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java @@ -610,7 +610,7 @@ public class QuickstepLauncher extends Launcher implements RecentsViewContainer, .append(" is missing."), QUICK_SWITCH_FROM_HOME_FALLBACK); } - taskToLaunch.launchTask(success -> { + taskToLaunch.launchWithoutAnimation(success -> { if (!success) { getStateManager().goToState(OVERVIEW); } else { diff --git a/quickstep/src/com/android/launcher3/uioverrides/states/OverviewState.java b/quickstep/src/com/android/launcher3/uioverrides/states/OverviewState.java index 6822f1b39c..b165cddfb2 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/states/OverviewState.java +++ b/quickstep/src/com/android/launcher3/uioverrides/states/OverviewState.java @@ -209,7 +209,7 @@ public class OverviewState extends LauncherState { TaskView taskView = recentsView.getRunningTaskView(); if (taskView != null) { if (recentsView.isTaskViewFullyVisible(taskView)) { - taskView.launchTasks(); + taskView.launchWithAnimation(); } else { recentsView.snapToPage(recentsView.indexOfChild(taskView)); } diff --git a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java index 38d08e0d6e..55489bb7d5 100644 --- a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java +++ b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java @@ -2370,7 +2370,7 @@ public abstract class AbsSwipeUpHandler< ActiveGestureLog.INSTANCE.trackEvent(EXPECTING_TASK_APPEARED); } ActiveGestureLog.INSTANCE.addLog(nextTaskLog); - nextTask.launchTask(success -> { + nextTask.launchWithoutAnimation(true, success -> { resultCallback.accept(success); if (success) { if (hasTaskPreviouslyAppeared) { @@ -2383,7 +2383,7 @@ public abstract class AbsSwipeUpHandler< } } return Unit.INSTANCE; - }, true /* freezeTaskList */); + } /* freezeTaskList */); } else { mContainerInterface.onLaunchTaskFailed(); Toast.makeText(mContext, R.string.activity_not_available, LENGTH_SHORT).show(); diff --git a/quickstep/src/com/android/quickstep/OverviewCommandHelper.kt b/quickstep/src/com/android/quickstep/OverviewCommandHelper.kt index 8873275a30..db6fe01601 100644 --- a/quickstep/src/com/android/quickstep/OverviewCommandHelper.kt +++ b/quickstep/src/com/android/quickstep/OverviewCommandHelper.kt @@ -188,7 +188,7 @@ class OverviewCommandHelper( if (taskView != null) { waitForToggleCommandComplete = true taskView.isEndQuickSwitchCuj = true - callbackList = taskView.launchTasks() + callbackList = taskView.launchWithAnimation() } if (callbackList != null) { diff --git a/quickstep/src/com/android/quickstep/TaskShortcutFactory.java b/quickstep/src/com/android/quickstep/TaskShortcutFactory.java index 9e6e2f3f04..785666f77e 100644 --- a/quickstep/src/com/android/quickstep/TaskShortcutFactory.java +++ b/quickstep/src/com/android/quickstep/TaskShortcutFactory.java @@ -431,7 +431,7 @@ public interface TaskShortcutFactory { @Override public void onClick(View view) { - if (mTaskView.launchTaskAnimated() != null) { + if (mTaskView.launchAsStaticTile() != null) { SystemUiProxy.INSTANCE.get(mTarget.asContext()).startScreenPinning( mTaskView.getFirstTask().key.id); } diff --git a/quickstep/src/com/android/quickstep/views/DesktopTaskView.kt b/quickstep/src/com/android/quickstep/views/DesktopTaskView.kt index 41add5414d..6db0923563 100644 --- a/quickstep/src/com/android/quickstep/views/DesktopTaskView.kt +++ b/quickstep/src/com/android/quickstep/views/DesktopTaskView.kt @@ -262,7 +262,7 @@ class DesktopTaskView @JvmOverloads constructor(context: Context, attrs: Attribu } Log.d( TAG, - "launchTaskAnimated - launchTaskWithDesktopController: ${taskIds.contentToString()}, withRemoteTransition: $animated" + "launchTaskWithDesktopController: ${taskIds.contentToString()}, withRemoteTransition: $animated" ) // Callbacks get run from recentsView for case when recents animation already running @@ -270,11 +270,12 @@ class DesktopTaskView @JvmOverloads constructor(context: Context, attrs: Attribu return endCallback } - override fun launchTaskAnimated() = launchTaskWithDesktopController(animated = true) + override fun launchAsStaticTile() = launchTaskWithDesktopController(animated = true) - override fun launchTask(callback: (launched: Boolean) -> Unit, isQuickSwitch: Boolean) { - launchTaskWithDesktopController(animated = false)?.add { callback(true) } ?: callback(false) - } + override fun launchWithoutAnimation( + isQuickSwitch: Boolean, + callback: (launched: Boolean) -> Unit + ) = launchTaskWithDesktopController(animated = false)?.add { callback(true) } ?: callback(false) // Desktop tile can't be in split screen override fun confirmSecondSplitSelectApp(): Boolean = false diff --git a/quickstep/src/com/android/quickstep/views/GroupedTaskView.kt b/quickstep/src/com/android/quickstep/views/GroupedTaskView.kt index 4fae01e021..3fd1a6bb60 100644 --- a/quickstep/src/com/android/quickstep/views/GroupedTaskView.kt +++ b/quickstep/src/com/android/quickstep/views/GroupedTaskView.kt @@ -218,11 +218,7 @@ class GroupedTaskView @JvmOverloads constructor(context: Context, attrs: Attribu invalidate() } - override fun launchTaskAnimated(): RunnableList? { - if (taskContainers.isEmpty()) { - Log.d(TAG, "launchTaskAnimated - task is not bound") - return null - } + override fun launchAsStaticTile(): RunnableList? { val recentsView = recentsView ?: return null val endCallback = RunnableList() // Callbacks run from remote animation when recents animation not currently running @@ -241,8 +237,11 @@ class GroupedTaskView @JvmOverloads constructor(context: Context, attrs: Attribu return endCallback } - override fun launchTask(callback: (launched: Boolean) -> Unit, isQuickSwitch: Boolean) { - launchTaskInternal(isQuickSwitch, false, callback /*launchingExistingTaskview*/) + override fun launchWithoutAnimation( + isQuickSwitch: Boolean, + callback: (launched: Boolean) -> Unit + ) { + launchTaskInternal(isQuickSwitch, launchingExistingTaskView = false, callback) } /** @@ -266,7 +265,10 @@ class GroupedTaskView @JvmOverloads constructor(context: Context, attrs: Attribu isQuickSwitch, snapPosition ) - Log.d(TAG, "launchTaskInternal - launchExistingSplitPair: ${taskIds.contentToString()}") + Log.d( + TAG, + "launchTaskInternal - launchExistingSplitPair: ${taskIds.contentToString()}, launchingExistingTaskView: $launchingExistingTaskView" + ) } } diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index 226ecf5063..e3407a5da0 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -5485,7 +5485,7 @@ public abstract class RecentsView< finishRecentsAnimation(false /* toRecents */, null); onTaskLaunchAnimationEnd(true /* success */); } else { - taskView.launchTask(this::onTaskLaunchAnimationEnd); + taskView.launchWithoutAnimation(this::onTaskLaunchAnimationEnd); } mContainer.getStatsLogManager().logger().withItemInfo(taskView.getFirstItemInfo()) .log(LAUNCHER_TASK_LAUNCH_SWIPE_DOWN); diff --git a/quickstep/src/com/android/quickstep/views/TaskView.kt b/quickstep/src/com/android/quickstep/views/TaskView.kt index 5614af63c7..601dae8b27 100644 --- a/quickstep/src/com/android/quickstep/views/TaskView.kt +++ b/quickstep/src/com/android/quickstep/views/TaskView.kt @@ -1003,7 +1003,7 @@ constructor( return } val callbackList = - launchTasks()?.apply { + launchWithAnimation()?.apply { add { Log.d("b/310064698", "${taskIds.contentToString()} - onClick - launchCompleted") } @@ -1015,12 +1015,106 @@ constructor( .log(LauncherEvent.LAUNCHER_TASK_LAUNCH_TAP) } + /** Launch of the current task (both live and inactive tasks) with an animation. */ + fun launchWithAnimation(): RunnableList? { + return if (isRunningTask && recentsView?.remoteTargetHandles != null) { + launchAsLiveTile() + } else { + launchAsStaticTile() + } + } + + private fun launchAsLiveTile(): RunnableList? { + val recentsView = recentsView ?: return null + val remoteTargetHandles = recentsView.remoteTargetHandles + if (!isClickableAsLiveTile) { + Log.e( + TAG, + "launchAsLiveTile - TaskView is not clickable as a live tile; returning to home: ${taskIds.contentToString()}" + ) + return null + } + isClickableAsLiveTile = false + val targets = + if (remoteTargetHandles.size == 1) { + remoteTargetHandles[0].transformParams.targetSet + } else { + val apps = + remoteTargetHandles.flatMap { it.transformParams.targetSet.apps.asIterable() } + val wallpapers = + remoteTargetHandles.flatMap { + it.transformParams.targetSet.wallpapers.asIterable() + } + RemoteAnimationTargets( + apps.toTypedArray(), + wallpapers.toTypedArray(), + remoteTargetHandles[0].transformParams.targetSet.nonApps, + remoteTargetHandles[0].transformParams.targetSet.targetMode + ) + } + if (targets == null) { + // If the recents animation is cancelled somehow between the parent if block and + // here, try to launch the task as a non live tile task. + val runnableList = launchAsStaticTile() + if (runnableList == null) { + Log.e( + TAG, + "launchAsLiveTile - Recents animation cancelled and cannot launch task as non-live tile; returning to home: ${taskIds.contentToString()}" + ) + } + isClickableAsLiveTile = true + return runnableList + } + TestLogging.recordEvent( + TestProtocol.SEQUENCE_MAIN, + "composeRecentsLaunchAnimator", + taskIds.contentToString() + ) + val runnableList = RunnableList() + with(AnimatorSet()) { + TaskViewUtils.composeRecentsLaunchAnimator( + this, + this@TaskView, + targets.apps, + targets.wallpapers, + targets.nonApps, + true /* launcherClosing */, + recentsView.stateManager, + recentsView, + recentsView.depthController + ) + addListener( + object : AnimatorListenerAdapter() { + override fun onAnimationEnd(animator: Animator) { + if (taskContainers.any { it.task.key.displayId != rootViewDisplayId }) { + launchAsStaticTile() + } + isClickableAsLiveTile = true + runEndCallback() + } + + override fun onAnimationCancel(animation: Animator) { + runEndCallback() + } + + private fun runEndCallback() { + runnableList.executeAllAndDestroy() + } + } + ) + start() + } + Log.d(TAG, "launchAsLiveTile - composeRecentsLaunchAnimator: ${taskIds.contentToString()}") + recentsView.onTaskLaunchedInLiveTileMode() + return runnableList + } + /** * Starts the task associated with this view and animates the startup. * * @return CompletionStage to indicate the animation completion or null if the launch failed. */ - open fun launchTaskAnimated(): RunnableList? { + open fun launchAsStaticTile(): RunnableList? { TestLogging.recordEvent( TestProtocol.SEQUENCE_MAIN, "startActivityFromRecentsAsync", @@ -1036,7 +1130,7 @@ constructor( ) { Log.d( TAG, - "launchTaskAnimated - startActivityFromRecents: ${taskIds.contentToString()}" + "launchAsStaticTile - startActivityFromRecents: ${taskIds.contentToString()}" ) ActiveGestureLog.INSTANCE.trackEvent( ActiveGestureErrorDetector.GestureEvent.EXPECTING_TASK_APPEARED @@ -1060,18 +1154,17 @@ constructor( recentsView.addSideTaskLaunchCallback(opts.onEndCallback) return opts.onEndCallback } else { - notifyTaskLaunchFailed() + notifyTaskLaunchFailed("launchAsStaticTile") return null } } /** Starts the task associated with this view without any animation */ - fun launchTask(callback: (launched: Boolean) -> Unit) { - launchTask(callback, isQuickSwitch = false) - } - - /** Starts the task associated with this view without any animation */ - open fun launchTask(callback: (launched: Boolean) -> Unit, isQuickSwitch: Boolean) { + @JvmOverloads + open fun launchWithoutAnimation( + isQuickSwitch: Boolean = false, + callback: (launched: Boolean) -> Unit + ) { TestLogging.recordEvent( TestProtocol.SEQUENCE_MAIN, "startActivityFromRecentsAsync", @@ -1084,7 +1177,7 @@ constructor( // gesture launcher is in the background state, vs other launches which are in // the actual overview state failureListener.register(container, firstContainer.task.key.id) { - notifyTaskLaunchFailed() + notifyTaskLaunchFailed("launchWithoutAnimation") recentsView?.let { // Disable animations for now, as it is an edge case and the app usually // covers launcher and also any state transition animation also gets @@ -1128,103 +1221,20 @@ constructor( // otherwise, wait for the animation start callback from the activity options // above Executors.MAIN_EXECUTOR.post { - notifyTaskLaunchFailed() + notifyTaskLaunchFailed("launchTask") callback(false) } } - Log.d(TAG, "launchTask - startActivityFromRecents: ${taskIds.contentToString()}") + Log.d( + TAG, + "launchWithoutAnimation - startActivityFromRecents: ${taskIds.contentToString()}" + ) } } - /** Launch of the current task (both live and inactive tasks) with an animation. */ - fun launchTasks(): RunnableList? { - val recentsView = recentsView ?: return null - val remoteTargetHandles = recentsView.mRemoteTargetHandles - if (!isRunningTask || remoteTargetHandles == null) { - return launchTaskAnimated() - } - if (!isClickableAsLiveTile) { - Log.e(TAG, "TaskView is not clickable as a live tile; returning to home.") - return null - } - isClickableAsLiveTile = false - val targets = - if (remoteTargetHandles.size == 1) { - remoteTargetHandles[0].transformParams.targetSet - } else { - val apps = - remoteTargetHandles.flatMap { it.transformParams.targetSet.apps.asIterable() } - val wallpapers = - remoteTargetHandles.flatMap { - it.transformParams.targetSet.wallpapers.asIterable() - } - RemoteAnimationTargets( - apps.toTypedArray(), - wallpapers.toTypedArray(), - remoteTargetHandles[0].transformParams.targetSet.nonApps, - remoteTargetHandles[0].transformParams.targetSet.targetMode - ) - } - if (targets == null) { - // If the recents animation is cancelled somehow between the parent if block and - // here, try to launch the task as a non live tile task. - val runnableList = launchTaskAnimated() - if (runnableList == null) { - Log.e( - TAG, - "Recents animation cancelled and cannot launch task as non-live tile" + - "; returning to home" - ) - } - isClickableAsLiveTile = true - return runnableList - } - TestLogging.recordEvent( - TestProtocol.SEQUENCE_MAIN, - "composeRecentsLaunchAnimator", - taskIds.contentToString() - ) - val runnableList = RunnableList() - with(AnimatorSet()) { - TaskViewUtils.composeRecentsLaunchAnimator( - this, - this@TaskView, - targets.apps, - targets.wallpapers, - targets.nonApps, - true /* launcherClosing */, - recentsView.stateManager, - recentsView, - recentsView.depthController - ) - addListener( - object : AnimatorListenerAdapter() { - override fun onAnimationEnd(animator: Animator) { - if (taskContainers.any { it.task.key.displayId != rootViewDisplayId }) { - launchTaskAnimated() - } - isClickableAsLiveTile = true - runEndCallback() - } - - override fun onAnimationCancel(animation: Animator) { - runEndCallback() - } - - private fun runEndCallback() { - runnableList.executeAllAndDestroy() - } - } - ) - start() - } - Log.d(TAG, "launchTasks - composeRecentsLaunchAnimator: ${taskIds.contentToString()}") - recentsView.onTaskLaunchedInLiveTileMode() - return runnableList - } - - private fun notifyTaskLaunchFailed() { - val sb = StringBuilder("Failed to launch task \n") + private fun notifyTaskLaunchFailed(launchMethod: String) { + val sb = + StringBuilder("$launchMethod - Failed to launch task: ${taskIds.contentToString()}\n") taskContainers.forEach { sb.append("(task=${it.task.key.baseIntent} userId=${it.task.key.userId})\n") }