blob: d7f86cd65ae993db2468a5bcc7629a53b9a066f0 [file] [log] [blame]
Jason Monk7e53f202016-01-28 10:40:20 -05001/*
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
15package com.android.server.statusbar;
16
Evan Lairdedd016f2019-01-23 18:36:29 -050017import static android.app.StatusBarManager.DEFAULT_SETUP_DISABLE2_FLAGS;
18import static android.app.StatusBarManager.DEFAULT_SETUP_DISABLE_FLAGS;
19import static android.app.StatusBarManager.DISABLE2_NONE;
20import static android.app.StatusBarManager.DISABLE_NONE;
21
Evan Lairdced4aeb2019-01-28 16:52:41 -050022import android.app.StatusBarManager.DisableInfo;
Jason Monk7e53f202016-01-28 10:40:20 -050023import android.content.ComponentName;
Evan Lairdedd016f2019-01-23 18:36:29 -050024import android.content.Context;
25import android.os.Binder;
26import android.os.IBinder;
Jason Monk7e53f202016-01-28 10:40:20 -050027import android.os.RemoteException;
28import android.os.ShellCommand;
Jason Monk213eb4f2017-03-31 09:26:27 -040029import android.service.quicksettings.TileService;
Evan Lairdced4aeb2019-01-28 16:52:41 -050030import android.util.Pair;
Jason Monk213eb4f2017-03-31 09:26:27 -040031
Jason Monk7e53f202016-01-28 10:40:20 -050032import java.io.PrintWriter;
33
34public class StatusBarShellCommand extends ShellCommand {
35
Evan Lairdedd016f2019-01-23 18:36:29 -050036 private static final IBinder sToken = new StatusBarShellCommandToken();
Jason Monk7e53f202016-01-28 10:40:20 -050037
Evan Lairdedd016f2019-01-23 18:36:29 -050038 private final StatusBarManagerService mInterface;
39 private final Context mContext;
40
41 public StatusBarShellCommand(StatusBarManagerService service, Context context) {
Jason Monk7e53f202016-01-28 10:40:20 -050042 mInterface = service;
Evan Lairdedd016f2019-01-23 18:36:29 -050043 mContext = context;
Jason Monk7e53f202016-01-28 10:40:20 -050044 }
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 Monk213eb4f2017-03-31 09:26:27 -040065 case "check-support":
66 final PrintWriter pw = getOutPrintWriter();
67 pw.println(String.valueOf(TileService.isQuickSettingsSupported()));
68 return 0;
Jason Monkf8c2f7b2017-09-06 09:22:29 -040069 case "get-status-icons":
70 return runGetStatusIcons();
Evan Lairdedd016f2019-01-23 18:36:29 -050071 case "disable-for-setup":
72 return runDisableForSetup();
Evan Lairdced4aeb2019-01-28 16:52:41 -050073 case "send-disable-flag":
74 return runSendDisableFlag();
Jason Monk7e53f202016-01-28 10:40:20 -050075 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 Monkf8c2f7b2017-09-06 09:22:29 -0400115 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 Lairdedd016f2019-01-23 18:36:29 -0500123 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 Lairdced4aeb2019-01-28 16:52:41 -0500139 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;
Beverly54fead82019-05-22 17:57:39 -0400164 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 Lairdced4aeb2019-01-28 16:52:41 -0500173 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 Monk7e53f202016-01-28 10:40:20 -0500188 @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 Monk213eb4f2017-03-31 09:26:27 -0400213 pw.println(" check-support");
214 pw.println(" Check if this device supports QS + APIs");
215 pw.println("");
Jason Monkf8c2f7b2017-09-06 09:22:29 -0400216 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 Lairdedd016f2019-01-23 18:36:29 -0500219 pw.println(" disable-for-setup DISABLE");
220 pw.println(" If true, disable status bar components unsuitable for device setup");
221 pw.println("");
Evan Lairdced4aeb2019-01-28 16:52:41 -0500222 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");
Beverly54fead82019-05-22 17:57:39 -0400232 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 Lairdced4aeb2019-01-28 16:52:41 -0500235 pw.println("");
Evan Lairdedd016f2019-01-23 18:36:29 -0500236 }
237
238 /**
239 * Token to send to StatusBarManagerService for disable* commands
240 */
241 private static final class StatusBarShellCommandToken extends Binder {
Jason Monk7e53f202016-01-28 10:40:20 -0500242 }
243}