diff options
7 files changed, 94 insertions, 8 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentTasksController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentTasksController.java index d6f9183a4281..975b65023f20 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentTasksController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentTasksController.java @@ -103,6 +103,7 @@ public class RecentTasksController implements TaskStackListenerCallback, private final RecentTasksImpl mImpl = new RecentTasksImpl(); private final ActivityTaskManager mActivityTaskManager; private final TaskStackTransitionObserver mTaskStackTransitionObserver; + private final RecentsShellCommandHandler mRecentsShellCommandHandler; private RecentsTransitionHandler mTransitionHandler = null; private IRecentTasksListener mListener; private final boolean mPcFeatureEnabled; @@ -167,6 +168,7 @@ public class RecentTasksController implements TaskStackListenerCallback, mDesktopUserRepositories = desktopUserRepositories; mTaskStackTransitionObserver = taskStackTransitionObserver; mMainExecutor = mainExecutor; + mRecentsShellCommandHandler = new RecentsShellCommandHandler(this); shellInit.addInitCallback(this::onInit, this); } @@ -183,6 +185,7 @@ public class RecentTasksController implements TaskStackListenerCallback, mShellController.addExternalInterface(IRecentTasks.DESCRIPTOR, this::createExternalInterface, this); mShellCommandHandler.addDumpCallback(this::dump, this); + mShellCommandHandler.addCommandCallback("recents", mRecentsShellCommandHandler, this); mUserId = ActivityManager.getCurrentUser(); mDesktopUserRepositories.ifPresent( desktopUserRepositories -> @@ -656,6 +659,11 @@ public class RecentTasksController implements TaskStackListenerCallback, return mActivityTaskManager.removeTask(taskId); } + /** Removes all recent tasks that are visible. */ + public void removeAllVisibleRecentTasks() throws RemoteException { + ActivityTaskManager.getService().removeAllVisibleRecentTasks(); + } + public void dump(@NonNull PrintWriter pw, String prefix) { final String innerPrefix = prefix + " "; pw.println(prefix + TAG); diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentsShellCommandHandler.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentsShellCommandHandler.kt new file mode 100644 index 000000000000..f786e079ed93 --- /dev/null +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentsShellCommandHandler.kt @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2025 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.recents + +import android.os.RemoteException +import com.android.wm.shell.sysui.ShellCommandHandler.ShellCommandActionHandler +import java.io.PrintWriter + +class RecentsShellCommandHandler( + private val recentTasksController: RecentTasksController +) : ShellCommandActionHandler { + override fun onShellCommand(args: Array<out String>, pw: PrintWriter): Boolean { + when (args[0]) { + "clearAll" -> return runClearAll(pw) + else -> { + pw.println("Invalid command: " + args[0]) + return false + } + } + } + + override fun printShellCommandHelp(pw: PrintWriter, prefix: String) { + pw.println("${prefix}clearAll") + pw.println("$prefix Clears all visible recent tasks.") + } + + private fun runClearAll(pw: PrintWriter): Boolean { + try { + recentTasksController.removeAllVisibleRecentTasks() + } catch (e: RemoteException) { + pw.println("Exception while removing visible recent tasks:") + e.printStackTrace(pw) + return false + } + return true + } +}
\ No newline at end of file diff --git a/libs/WindowManager/Shell/tests/e2e/splitscreen/scenarios/src/com/android/wm/shell/scenarios/CopyContentInSplit.kt b/libs/WindowManager/Shell/tests/e2e/splitscreen/scenarios/src/com/android/wm/shell/scenarios/CopyContentInSplit.kt index ba4654260864..31d89f92f744 100644 --- a/libs/WindowManager/Shell/tests/e2e/splitscreen/scenarios/src/com/android/wm/shell/scenarios/CopyContentInSplit.kt +++ b/libs/WindowManager/Shell/tests/e2e/splitscreen/scenarios/src/com/android/wm/shell/scenarios/CopyContentInSplit.kt @@ -24,6 +24,7 @@ import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.UiDevice import com.android.launcher3.tapl.LauncherInstrumentation import com.android.wm.shell.Utils +import com.android.wm.shell.flicker.utils.RecentTasksUtils import com.android.wm.shell.flicker.utils.SplitScreenUtils import org.junit.After import org.junit.Before @@ -61,7 +62,6 @@ constructor(val rotation: Rotation = Rotation.ROTATION_0) { @After fun teardown() { - primaryApp.exit(wmHelper) - secondaryApp.exit(wmHelper) + RecentTasksUtils.clearAllVisibleRecentTasks(instrumentation) } } diff --git a/libs/WindowManager/Shell/tests/e2e/splitscreen/scenarios/src/com/android/wm/shell/scenarios/DismissSplitScreenByDivider.kt b/libs/WindowManager/Shell/tests/e2e/splitscreen/scenarios/src/com/android/wm/shell/scenarios/DismissSplitScreenByDivider.kt index d774a31220da..1af6cac39085 100644 --- a/libs/WindowManager/Shell/tests/e2e/splitscreen/scenarios/src/com/android/wm/shell/scenarios/DismissSplitScreenByDivider.kt +++ b/libs/WindowManager/Shell/tests/e2e/splitscreen/scenarios/src/com/android/wm/shell/scenarios/DismissSplitScreenByDivider.kt @@ -24,6 +24,7 @@ import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.UiDevice import com.android.launcher3.tapl.LauncherInstrumentation import com.android.wm.shell.Utils +import com.android.wm.shell.flicker.utils.RecentTasksUtils import com.android.wm.shell.flicker.utils.SplitScreenUtils import org.junit.After import org.junit.Before @@ -74,7 +75,6 @@ constructor(val rotation: Rotation = Rotation.ROTATION_0) { @After fun teardown() { - primaryApp.exit(wmHelper) - secondaryApp.exit(wmHelper) + RecentTasksUtils.clearAllVisibleRecentTasks(instrumentation) } } diff --git a/libs/WindowManager/Shell/tests/e2e/splitscreen/scenarios/src/com/android/wm/shell/scenarios/DismissSplitScreenByGoHome.kt b/libs/WindowManager/Shell/tests/e2e/splitscreen/scenarios/src/com/android/wm/shell/scenarios/DismissSplitScreenByGoHome.kt index 5aa161911a9a..8ad8c7bd7a7f 100644 --- a/libs/WindowManager/Shell/tests/e2e/splitscreen/scenarios/src/com/android/wm/shell/scenarios/DismissSplitScreenByGoHome.kt +++ b/libs/WindowManager/Shell/tests/e2e/splitscreen/scenarios/src/com/android/wm/shell/scenarios/DismissSplitScreenByGoHome.kt @@ -24,6 +24,7 @@ import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.UiDevice import com.android.launcher3.tapl.LauncherInstrumentation import com.android.wm.shell.Utils +import com.android.wm.shell.flicker.utils.RecentTasksUtils import com.android.wm.shell.flicker.utils.SplitScreenUtils import org.junit.After import org.junit.Before @@ -60,7 +61,6 @@ constructor(val rotation: Rotation = Rotation.ROTATION_0) { @After fun teardown() { - primaryApp.exit(wmHelper) - secondaryApp.exit(wmHelper) + RecentTasksUtils.clearAllVisibleRecentTasks(instrumentation) } } diff --git a/libs/WindowManager/Shell/tests/e2e/splitscreen/scenarios/src/com/android/wm/shell/scenarios/DragDividerToResize.kt b/libs/WindowManager/Shell/tests/e2e/splitscreen/scenarios/src/com/android/wm/shell/scenarios/DragDividerToResize.kt index 668f3678bb38..da0ace472153 100644 --- a/libs/WindowManager/Shell/tests/e2e/splitscreen/scenarios/src/com/android/wm/shell/scenarios/DragDividerToResize.kt +++ b/libs/WindowManager/Shell/tests/e2e/splitscreen/scenarios/src/com/android/wm/shell/scenarios/DragDividerToResize.kt @@ -24,6 +24,7 @@ import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.UiDevice import com.android.launcher3.tapl.LauncherInstrumentation import com.android.wm.shell.Utils +import com.android.wm.shell.flicker.utils.RecentTasksUtils import com.android.wm.shell.flicker.utils.SplitScreenUtils import org.junit.After import org.junit.Before @@ -61,7 +62,6 @@ constructor(val rotation: Rotation = Rotation.ROTATION_0) { @After fun teardown() { - primaryApp.exit(wmHelper) - secondaryApp.exit(wmHelper) + RecentTasksUtils.clearAllVisibleRecentTasks(instrumentation) } } diff --git a/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/utils/RecentTasksUtils.kt b/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/utils/RecentTasksUtils.kt new file mode 100644 index 000000000000..aa262f9dfd6a --- /dev/null +++ b/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/utils/RecentTasksUtils.kt @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2025 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.flicker.utils + +import android.app.Instrumentation + +object RecentTasksUtils { + fun clearAllVisibleRecentTasks(instrumentation: Instrumentation) { + instrumentation.uiAutomation.executeShellCommand( + "dumpsys activity service SystemUIService WMShell recents clearAll" + ) + } +}
\ No newline at end of file |