diff options
2 files changed, 107 insertions, 0 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeShellCommandHandler.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeShellCommandHandler.kt new file mode 100644 index 000000000000..fd91ac0affc5 --- /dev/null +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeShellCommandHandler.kt @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.wm.shell.desktopmode + +import android.window.WindowContainerTransaction +import com.android.wm.shell.sysui.ShellCommandHandler +import java.io.PrintWriter + +/** + * Handles the shell commands for the DesktopTasksController. + */ +class DesktopModeShellCommandHandler(private val controller: DesktopTasksController) : + ShellCommandHandler.ShellCommandActionHandler { + + override fun onShellCommand(args: Array<String>, pw: PrintWriter): Boolean { + return when (args[0]) { + "moveToDesktop" -> { + if (!runMoveToDesktop(args, pw)) { + pw.println("Task not found. Please enter a valid taskId.") + false + } else { + true + } + } + + else -> { + pw.println("Invalid command: ${args[0]}") + false + } + } + } + + private fun runMoveToDesktop(args: Array<String>, pw: PrintWriter): Boolean { + if (args.size < 2) { + // First argument is the action name. + pw.println("Error: task id should be provided as arguments") + return false + } + + val taskId = try { + args[1].toInt() + } catch (e: NumberFormatException) { + pw.println("Error: task id should be an integer") + return false + } + + return controller.moveToDesktopWithoutDecor(taskId, WindowContainerTransaction()) + } + + override fun printShellCommandHelp(pw: PrintWriter, prefix: String) { + pw.println("$prefix moveToDesktop <taskId> ") + pw.println("$prefix Move a task with given id to desktop mode.") + } +}
\ No newline at end of file diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt index a089e81ff6dd..e8728498ad64 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt @@ -100,6 +100,9 @@ class DesktopTasksController( private val desktopMode: DesktopModeImpl private var visualIndicator: DesktopModeVisualIndicator? = null + private val desktopModeShellCommandHandler: DesktopModeShellCommandHandler = + DesktopModeShellCommandHandler(this) + private val mOnAnimationFinishedCallback = Consumer<SurfaceControl.Transaction> { t: SurfaceControl.Transaction -> visualIndicator?.releaseVisualIndicator(t) @@ -148,6 +151,8 @@ class DesktopTasksController( private fun onInit() { KtProtoLog.d(WM_SHELL_DESKTOP_MODE, "Initialize DesktopTasksController") shellCommandHandler.addDumpCallback(this::dump, this) + shellCommandHandler.addCommandCallback("desktopmode", desktopModeShellCommandHandler, + this) shellController.addExternalInterface( ShellSharedConstants.KEY_EXTRA_SHELL_DESKTOP_MODE, { createExternalInterface() }, @@ -240,6 +245,40 @@ class DesktopTasksController( } } + /** Move a task with given `taskId` to desktop without decor */ + fun moveToDesktopWithoutDecor( + taskId: Int, + wct: WindowContainerTransaction + ): Boolean { + val task = shellTaskOrganizer.getRunningTaskInfo(taskId) ?: return false + moveToDesktopWithoutDecor(task, wct) + return true + } + + /** + * Move a task to desktop without decor + */ + private fun moveToDesktopWithoutDecor( + task: RunningTaskInfo, + wct: WindowContainerTransaction + ) { + KtProtoLog.v( + WM_SHELL_DESKTOP_MODE, + "DesktopTasksController: moveToDesktopWithoutDecor taskId=%d", + task.taskId + ) + exitSplitIfApplicable(wct, task) + // Bring other apps to front first + bringDesktopAppsToFront(task.displayId, wct) + addMoveToDesktopChanges(wct, task) + + if (Transitions.ENABLE_SHELL_TRANSITIONS) { + transitions.startTransition(TRANSIT_CHANGE, wct, null /* handler */) + } else { + shellTaskOrganizer.applyTransaction(wct) + } + } + /** * Move a task to desktop */ |