• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.wm.shell.recents
18 
19 import android.os.RemoteException
20 import com.android.wm.shell.sysui.ShellCommandHandler.ShellCommandActionHandler
21 import java.io.PrintWriter
22 
23 class RecentsShellCommandHandler(
24     private val recentTasksController: RecentTasksController
25 ) : ShellCommandActionHandler {
onShellCommandnull26     override fun onShellCommand(args: Array<out String>, pw: PrintWriter): Boolean {
27         when (args[0]) {
28             "clearAll" -> return runClearAll(pw)
29             else -> {
30                 pw.println("Invalid command: " + args[0])
31                 return false
32             }
33         }
34     }
35 
printShellCommandHelpnull36     override fun printShellCommandHelp(pw: PrintWriter, prefix: String) {
37         pw.println("${prefix}clearAll")
38         pw.println("$prefix  Clears all visible recent tasks.")
39     }
40 
runClearAllnull41     private fun runClearAll(pw: PrintWriter): Boolean {
42         try {
43             recentTasksController.removeAllVisibleRecentTasks()
44         } catch (e: RemoteException) {
45             pw.println("Exception while removing visible recent tasks:")
46             e.printStackTrace(pw)
47             return false
48         }
49         return true
50     }
51 }