Jason Monk | 7e53f20 | 2016-01-28 10:40:20 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file |
| 5 | * except in compliance with the License. You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the |
| 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 11 | * KIND, either express or implied. See the License for the specific language governing |
| 12 | * permissions and limitations under the License. |
| 13 | */ |
| 14 | |
| 15 | package com.android.server.statusbar; |
| 16 | |
Evan Laird | edd016f | 2019-01-23 18:36:29 -0500 | [diff] [blame] | 17 | import static android.app.StatusBarManager.DEFAULT_SETUP_DISABLE2_FLAGS; |
| 18 | import static android.app.StatusBarManager.DEFAULT_SETUP_DISABLE_FLAGS; |
| 19 | import static android.app.StatusBarManager.DISABLE2_NONE; |
| 20 | import static android.app.StatusBarManager.DISABLE_NONE; |
| 21 | |
Evan Laird | ced4aeb | 2019-01-28 16:52:41 -0500 | [diff] [blame] | 22 | import android.app.StatusBarManager.DisableInfo; |
Jason Monk | 7e53f20 | 2016-01-28 10:40:20 -0500 | [diff] [blame] | 23 | import android.content.ComponentName; |
Evan Laird | edd016f | 2019-01-23 18:36:29 -0500 | [diff] [blame] | 24 | import android.content.Context; |
| 25 | import android.os.Binder; |
| 26 | import android.os.IBinder; |
Jason Monk | 7e53f20 | 2016-01-28 10:40:20 -0500 | [diff] [blame] | 27 | import android.os.RemoteException; |
| 28 | import android.os.ShellCommand; |
Jason Monk | 213eb4f | 2017-03-31 09:26:27 -0400 | [diff] [blame] | 29 | import android.service.quicksettings.TileService; |
Evan Laird | ced4aeb | 2019-01-28 16:52:41 -0500 | [diff] [blame] | 30 | import android.util.Pair; |
Jason Monk | 213eb4f | 2017-03-31 09:26:27 -0400 | [diff] [blame] | 31 | |
Jason Monk | 7e53f20 | 2016-01-28 10:40:20 -0500 | [diff] [blame] | 32 | import java.io.PrintWriter; |
| 33 | |
| 34 | public class StatusBarShellCommand extends ShellCommand { |
| 35 | |
Evan Laird | edd016f | 2019-01-23 18:36:29 -0500 | [diff] [blame] | 36 | private static final IBinder sToken = new StatusBarShellCommandToken(); |
Jason Monk | 7e53f20 | 2016-01-28 10:40:20 -0500 | [diff] [blame] | 37 | |
Evan Laird | edd016f | 2019-01-23 18:36:29 -0500 | [diff] [blame] | 38 | private final StatusBarManagerService mInterface; |
| 39 | private final Context mContext; |
| 40 | |
| 41 | public StatusBarShellCommand(StatusBarManagerService service, Context context) { |
Jason Monk | 7e53f20 | 2016-01-28 10:40:20 -0500 | [diff] [blame] | 42 | mInterface = service; |
Evan Laird | edd016f | 2019-01-23 18:36:29 -0500 | [diff] [blame] | 43 | mContext = context; |
Jason Monk | 7e53f20 | 2016-01-28 10:40:20 -0500 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public int onCommand(String cmd) { |
| 48 | if (cmd == null) { |
| 49 | return handleDefaultCommands(cmd); |
| 50 | } |
| 51 | try { |
| 52 | switch (cmd) { |
| 53 | case "expand-notifications": |
| 54 | return runExpandNotifications(); |
| 55 | case "expand-settings": |
| 56 | return runExpandSettings(); |
| 57 | case "collapse": |
| 58 | return runCollapse(); |
| 59 | case "add-tile": |
| 60 | return runAddTile(); |
| 61 | case "remove-tile": |
| 62 | return runRemoveTile(); |
| 63 | case "click-tile": |
| 64 | return runClickTile(); |
Jason Monk | 213eb4f | 2017-03-31 09:26:27 -0400 | [diff] [blame] | 65 | case "check-support": |
| 66 | final PrintWriter pw = getOutPrintWriter(); |
| 67 | pw.println(String.valueOf(TileService.isQuickSettingsSupported())); |
| 68 | return 0; |
Jason Monk | f8c2f7b | 2017-09-06 09:22:29 -0400 | [diff] [blame] | 69 | case "get-status-icons": |
| 70 | return runGetStatusIcons(); |
Evan Laird | edd016f | 2019-01-23 18:36:29 -0500 | [diff] [blame] | 71 | case "disable-for-setup": |
| 72 | return runDisableForSetup(); |
Evan Laird | ced4aeb | 2019-01-28 16:52:41 -0500 | [diff] [blame] | 73 | case "send-disable-flag": |
| 74 | return runSendDisableFlag(); |
Jason Monk | 7e53f20 | 2016-01-28 10:40:20 -0500 | [diff] [blame] | 75 | default: |
| 76 | return handleDefaultCommands(cmd); |
| 77 | } |
| 78 | } catch (RemoteException e) { |
| 79 | final PrintWriter pw = getOutPrintWriter(); |
| 80 | pw.println("Remote exception: " + e); |
| 81 | } |
| 82 | return -1; |
| 83 | } |
| 84 | |
| 85 | private int runAddTile() throws RemoteException { |
| 86 | mInterface.addTile(ComponentName.unflattenFromString(getNextArgRequired())); |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | private int runRemoveTile() throws RemoteException { |
| 91 | mInterface.remTile(ComponentName.unflattenFromString(getNextArgRequired())); |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | private int runClickTile() throws RemoteException { |
| 96 | mInterface.clickTile(ComponentName.unflattenFromString(getNextArgRequired())); |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | private int runCollapse() throws RemoteException { |
| 101 | mInterface.collapsePanels(); |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | private int runExpandSettings() throws RemoteException { |
| 106 | mInterface.expandSettingsPanel(null); |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | private int runExpandNotifications() throws RemoteException { |
| 111 | mInterface.expandNotificationsPanel(); |
| 112 | return 0; |
| 113 | } |
| 114 | |
Jason Monk | f8c2f7b | 2017-09-06 09:22:29 -0400 | [diff] [blame] | 115 | private int runGetStatusIcons() { |
| 116 | final PrintWriter pw = getOutPrintWriter(); |
| 117 | for (String icon : mInterface.getStatusBarIcons()) { |
| 118 | pw.println(icon); |
| 119 | } |
| 120 | return 0; |
| 121 | } |
| 122 | |
Evan Laird | edd016f | 2019-01-23 18:36:29 -0500 | [diff] [blame] | 123 | private int runDisableForSetup() { |
| 124 | String arg = getNextArgRequired(); |
| 125 | String pkg = mContext.getPackageName(); |
| 126 | boolean disable = Boolean.parseBoolean(arg); |
| 127 | |
| 128 | if (disable) { |
| 129 | mInterface.disable(DEFAULT_SETUP_DISABLE_FLAGS, sToken, pkg); |
| 130 | mInterface.disable2(DEFAULT_SETUP_DISABLE2_FLAGS, sToken, pkg); |
| 131 | } else { |
| 132 | mInterface.disable(DISABLE_NONE, sToken, pkg); |
| 133 | mInterface.disable2(DISABLE2_NONE, sToken, pkg); |
| 134 | } |
| 135 | |
| 136 | return 0; |
| 137 | } |
| 138 | |
Evan Laird | ced4aeb | 2019-01-28 16:52:41 -0500 | [diff] [blame] | 139 | private int runSendDisableFlag() { |
| 140 | String pkg = mContext.getPackageName(); |
| 141 | int disable1 = DISABLE_NONE; |
| 142 | int disable2 = DISABLE2_NONE; |
| 143 | |
| 144 | DisableInfo info = new DisableInfo(); |
| 145 | |
| 146 | String arg = getNextArg(); |
| 147 | while (arg != null) { |
| 148 | switch (arg) { |
| 149 | case "search": |
| 150 | info.setSearchDisabled(true); |
| 151 | break; |
| 152 | case "home": |
| 153 | info.setNagivationHomeDisabled(true); |
| 154 | break; |
| 155 | case "recents": |
| 156 | info.setRecentsDisabled(true); |
| 157 | break; |
| 158 | case "notification-alerts": |
| 159 | info.setNotificationPeekingDisabled(true); |
| 160 | break; |
| 161 | case "statusbar-expansion": |
| 162 | info.setStatusBarExpansionDisabled(true); |
| 163 | break; |
Beverly | 54fead8 | 2019-05-22 17:57:39 -0400 | [diff] [blame] | 164 | case "system-icons": |
| 165 | info.setSystemIconsDisabled(true); |
| 166 | break; |
| 167 | case "clock": |
| 168 | info.setClockDisabled(true); |
| 169 | break; |
| 170 | case "notification-icons": |
| 171 | info.setNotificationIconsDisabled(true); |
| 172 | break; |
Evan Laird | ced4aeb | 2019-01-28 16:52:41 -0500 | [diff] [blame] | 173 | default: |
| 174 | break; |
| 175 | } |
| 176 | |
| 177 | arg = getNextArg(); |
| 178 | } |
| 179 | |
| 180 | Pair<Integer, Integer> flagPair = info.toFlags(); |
| 181 | |
| 182 | mInterface.disable(flagPair.first, sToken, pkg); |
| 183 | mInterface.disable2(flagPair.second, sToken, pkg); |
| 184 | |
| 185 | return 0; |
| 186 | } |
| 187 | |
Jason Monk | 7e53f20 | 2016-01-28 10:40:20 -0500 | [diff] [blame] | 188 | @Override |
| 189 | public void onHelp() { |
| 190 | final PrintWriter pw = getOutPrintWriter(); |
| 191 | pw.println("Status bar commands:"); |
| 192 | pw.println(" help"); |
| 193 | pw.println(" Print this help text."); |
| 194 | pw.println(""); |
| 195 | pw.println(" expand-notifications"); |
| 196 | pw.println(" Open the notifications panel."); |
| 197 | pw.println(""); |
| 198 | pw.println(" expand-settings"); |
| 199 | pw.println(" Open the notifications panel and expand quick settings if present."); |
| 200 | pw.println(""); |
| 201 | pw.println(" collapse"); |
| 202 | pw.println(" Collapse the notifications and settings panel."); |
| 203 | pw.println(""); |
| 204 | pw.println(" add-tile COMPONENT"); |
| 205 | pw.println(" Add a TileService of the specified component"); |
| 206 | pw.println(""); |
| 207 | pw.println(" remove-tile COMPONENT"); |
| 208 | pw.println(" Remove a TileService of the specified component"); |
| 209 | pw.println(""); |
| 210 | pw.println(" click-tile COMPONENT"); |
| 211 | pw.println(" Click on a TileService of the specified component"); |
| 212 | pw.println(""); |
Jason Monk | 213eb4f | 2017-03-31 09:26:27 -0400 | [diff] [blame] | 213 | pw.println(" check-support"); |
| 214 | pw.println(" Check if this device supports QS + APIs"); |
| 215 | pw.println(""); |
Jason Monk | f8c2f7b | 2017-09-06 09:22:29 -0400 | [diff] [blame] | 216 | pw.println(" get-status-icons"); |
| 217 | pw.println(" Print the list of status bar icons and the order they appear in"); |
| 218 | pw.println(""); |
Evan Laird | edd016f | 2019-01-23 18:36:29 -0500 | [diff] [blame] | 219 | pw.println(" disable-for-setup DISABLE"); |
| 220 | pw.println(" If true, disable status bar components unsuitable for device setup"); |
| 221 | pw.println(""); |
Evan Laird | ced4aeb | 2019-01-28 16:52:41 -0500 | [diff] [blame] | 222 | pw.println(" send-disable-flag FLAG..."); |
| 223 | pw.println(" Send zero or more disable flags (parsed individually) to StatusBarManager"); |
| 224 | pw.println(" Valid options:"); |
| 225 | pw.println(" <blank> - equivalent to \"none\""); |
| 226 | pw.println(" none - re-enables all components"); |
| 227 | pw.println(" search - disable search"); |
| 228 | pw.println(" home - disable naviagation home"); |
| 229 | pw.println(" recents - disable recents/overview"); |
| 230 | pw.println(" notification-peek - disable notification peeking"); |
| 231 | pw.println(" statusbar-expansion - disable status bar expansion"); |
Beverly | 54fead8 | 2019-05-22 17:57:39 -0400 | [diff] [blame] | 232 | pw.println(" system-icons - disable system icons appearing in status bar"); |
| 233 | pw.println(" clock - disable clock appearing in status bar"); |
| 234 | pw.println(" notification-icons - disable notification icons from status bar"); |
Evan Laird | ced4aeb | 2019-01-28 16:52:41 -0500 | [diff] [blame] | 235 | pw.println(""); |
Evan Laird | edd016f | 2019-01-23 18:36:29 -0500 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | /** |
| 239 | * Token to send to StatusBarManagerService for disable* commands |
| 240 | */ |
| 241 | private static final class StatusBarShellCommandToken extends Binder { |
Jason Monk | 7e53f20 | 2016-01-28 10:40:20 -0500 | [diff] [blame] | 242 | } |
| 243 | } |