Merge "Improve Task launch logging and function naming" into main

This commit is contained in:
Treehugger Robot authored and Android (Google) Code Review committed 2024-09-06 15:15:50 +00:00
commit 255bb6a80c
10 files changed
+136 -123

No files matched your search

@@ -1431,7 +1431,7 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
&& !(foundTaskView instanceof DesktopTaskView)) {
TestLogging.recordEvent(
TestProtocol.SEQUENCE_MAIN, "start: taskbarAppIcon");
foundTaskView.launchTasks();
foundTaskView.launchWithAnimation();
return;
}
}
@@ -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 {
@@ -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));
}
@@ -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();
@@ -254,7 +254,7 @@ constructor(
if (taskView != null) {
waitForToggleCommandComplete = true
taskView.isEndQuickSwitchCuj = true
callbackList = taskView.launchTasks()
callbackList = taskView.launchWithAnimation()
}
if (callbackList != null) {
@@ -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);
}
@@ -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
@@ -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"
)
}
}
@@ -5494,7 +5494,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);
@@ -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")
}