blob: 5b252e85423819290f389ff5b9a87e922eb05726 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 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
Adam Lesinski182f73f2013-12-05 16:48:06 -080017package com.android.server.statusbar;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018
Adam Lesinskia82b6262017-03-21 16:56:17 -070019import android.app.ActivityThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.app.StatusBarManager;
Jason Monk7e53f202016-01-28 10:40:20 -050021import android.content.ComponentName;
Jason Monk07473ce2016-01-05 14:59:19 -050022import android.content.Context;
23import android.content.pm.PackageManager;
Jorim Jaggi86905582016-02-09 21:36:09 -080024import android.graphics.Rect;
Adam Lesinski182f73f2013-12-05 16:48:06 -080025import android.os.Binder;
Jorim Jaggi165ce062015-07-06 16:18:11 -070026import android.os.Bundle;
Adam Lesinski182f73f2013-12-05 16:48:06 -080027import android.os.Handler;
28import android.os.IBinder;
Jason Monk361915c2017-03-21 20:33:59 -040029import android.os.PowerManager;
Jason Monk7e53f202016-01-28 10:40:20 -050030import android.os.Process;
Adam Lesinski182f73f2013-12-05 16:48:06 -080031import android.os.RemoteException;
Jason Monk7e53f202016-01-28 10:40:20 -050032import android.os.ResultReceiver;
Dianne Hackborn354736e2016-08-22 17:00:05 -070033import android.os.ShellCallback;
Adam Lesinski182f73f2013-12-05 16:48:06 -080034import android.os.UserHandle;
Dan Sandlerf3a1f2c2016-06-26 15:59:13 -040035import android.text.TextUtils;
Jason Monk07473ce2016-01-05 14:59:19 -050036import android.util.ArrayMap;
Joe Onorato8a9b2202010-02-26 18:56:32 -080037import android.util.Slog;
Jim Miller07e03842016-06-22 15:18:13 -070038
Jason Monkb4302182017-08-04 13:39:17 -040039import com.android.internal.R;
Joe Onorato0cbda992010-05-02 16:28:15 -070040import com.android.internal.statusbar.IStatusBar;
41import com.android.internal.statusbar.IStatusBarService;
Chris Wrend1dbc922015-06-19 17:51:16 -040042import com.android.internal.statusbar.NotificationVisibility;
Joe Onorato0cbda992010-05-02 16:28:15 -070043import com.android.internal.statusbar.StatusBarIcon;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060044import com.android.internal.util.DumpUtils;
Adam Lesinski182f73f2013-12-05 16:48:06 -080045import com.android.server.LocalServices;
46import com.android.server.notification.NotificationDelegate;
Jason Monk361915c2017-03-21 20:33:59 -040047import com.android.server.power.ShutdownThread;
48import com.android.server.statusbar.StatusBarManagerInternal.GlobalActionsListener;
Dianne Hackborna924dc0d2011-02-17 14:22:17 -080049import com.android.server.wm.WindowManagerService;
The Android Open Source Project10592532009-03-18 17:39:46 -070050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051import java.io.FileDescriptor;
52import java.io.PrintWriter;
53import java.util.ArrayList;
Joe Onorato75199e32010-05-29 17:22:51 -040054import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055
56
57/**
Joe Onoratof3f0e052010-05-14 18:49:29 -070058 * A note on locking: We rely on the fact that calls onto mBar are oneway or
59 * if they are local, that they just enqueue messages to not deadlock.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060 */
Michael Wright665366a2014-08-07 15:44:40 -070061public class StatusBarManagerService extends IStatusBarService.Stub {
Adam Lesinski182f73f2013-12-05 16:48:06 -080062 private static final String TAG = "StatusBarManagerService";
63 private static final boolean SPEW = false;
Joe Onoratodf7dbb62009-11-17 10:43:37 -080064
Adam Lesinski182f73f2013-12-05 16:48:06 -080065 private final Context mContext;
Adam Lesinskia82b6262017-03-21 16:56:17 -070066
Adam Lesinski182f73f2013-12-05 16:48:06 -080067 private final WindowManagerService mWindowManager;
68 private Handler mHandler = new Handler();
69 private NotificationDelegate mNotificationDelegate;
70 private volatile IStatusBar mBar;
Jason Monk07473ce2016-01-05 14:59:19 -050071 private ArrayMap<String, StatusBarIcon> mIcons = new ArrayMap<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072
Joe Onoratof3f0e052010-05-14 18:49:29 -070073 // for disabling the status bar
Adam Lesinski182f73f2013-12-05 16:48:06 -080074 private final ArrayList<DisableRecord> mDisableRecords = new ArrayList<DisableRecord>();
Jason Monk361915c2017-03-21 20:33:59 -040075 private GlobalActionsListener mGlobalActionListener;
Adam Lesinski182f73f2013-12-05 16:48:06 -080076 private IBinder mSysUiVisToken = new Binder();
Benjamin Franzcde0a2a2015-04-23 17:19:48 +010077 private int mDisabled1 = 0;
78 private int mDisabled2 = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080079
Adrian Roos2a629102016-04-15 16:28:03 -070080 private final Object mLock = new Object();
Daniel Sandler60ee2562011-07-22 12:34:33 -040081 // encompasses lights-out mode and other flags defined on View
Adam Lesinski182f73f2013-12-05 16:48:06 -080082 private int mSystemUiVisibility = 0;
Jorim Jaggi86905582016-02-09 21:36:09 -080083 private int mFullscreenStackSysUiVisibility;
84 private int mDockedStackSysUiVisibility;
85 private final Rect mFullscreenStackBounds = new Rect();
86 private final Rect mDockedStackBounds = new Rect();
Adam Lesinski182f73f2013-12-05 16:48:06 -080087 private boolean mMenuVisible = false;
88 private int mImeWindowVis = 0;
89 private int mImeBackDisposition;
Jason Monkb605fec2014-05-02 17:04:10 -040090 private boolean mShowImeSwitcher;
Adam Lesinski182f73f2013-12-05 16:48:06 -080091 private IBinder mImeToken = null;
92 private int mCurrentUserId;
satok06487a52010-10-29 11:37:18 +090093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 private class DisableRecord implements IBinder.DeathRecipient {
John Spurlock13451a22012-09-28 14:40:41 -040095 int userId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 String pkg;
Benjamin Franzcde0a2a2015-04-23 17:19:48 +010097 int what1;
98 int what2;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 IBinder token;
100
101 public void binderDied() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800102 Slog.i(TAG, "binder died for pkg=" + pkg);
Benjamin Franzea2ec972015-03-16 17:18:09 +0000103 disableForUser(0, token, pkg, userId);
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100104 disable2ForUser(0, token, pkg, userId);
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -0700105 token.unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 }
107 }
108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 /**
110 * Construct the service, add the status bar view to the window manager
111 */
Jeff Brown2992ea72011-01-28 22:04:14 -0800112 public StatusBarManagerService(Context context, WindowManagerService windowManager) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113 mContext = context;
Jeff Brown2992ea72011-01-28 22:04:14 -0800114 mWindowManager = windowManager;
Joe Onorato0cbda992010-05-02 16:28:15 -0700115
Adam Lesinski182f73f2013-12-05 16:48:06 -0800116 LocalServices.addService(StatusBarManagerInternal.class, mInternalService);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 }
118
Adam Lesinski182f73f2013-12-05 16:48:06 -0800119 /**
120 * Private API used by NotificationManagerService.
121 */
122 private final StatusBarManagerInternal mInternalService = new StatusBarManagerInternal() {
John Spurlockcb566aa2014-08-03 22:58:28 -0400123 private boolean mNotificationLightOn;
124
Adam Lesinski182f73f2013-12-05 16:48:06 -0800125 @Override
126 public void setNotificationDelegate(NotificationDelegate delegate) {
Christoph Studere71fefc2014-06-24 16:16:49 +0200127 mNotificationDelegate = delegate;
Adam Lesinski182f73f2013-12-05 16:48:06 -0800128 }
John Spurlockcb566aa2014-08-03 22:58:28 -0400129
John Spurlockcad57682014-07-26 17:09:56 -0400130 @Override
Andrii Kulian0f051f52016-04-14 00:41:51 -0700131 public void showScreenPinningRequest(int taskId) {
Jason Monk5565cb42014-09-12 10:59:21 -0400132 if (mBar != null) {
133 try {
Andrii Kulian0f051f52016-04-14 00:41:51 -0700134 mBar.showScreenPinningRequest(taskId);
Jason Monk5565cb42014-09-12 10:59:21 -0400135 } catch (RemoteException e) {
136 }
137 }
138 }
Adrian Roos4f43dc02015-06-17 16:43:38 -0700139
140 @Override
141 public void showAssistDisclosure() {
142 if (mBar != null) {
143 try {
144 mBar.showAssistDisclosure();
145 } catch (RemoteException e) {
146 }
147 }
148 }
Jorim Jaggi165ce062015-07-06 16:18:11 -0700149
150 @Override
151 public void startAssist(Bundle args) {
152 if (mBar != null) {
153 try {
154 mBar.startAssist(args);
155 } catch (RemoteException e) {
156 }
157 }
158 }
Selim Cinek372d1bd2015-08-14 13:19:37 -0700159
160 @Override
Jorim Jaggi40aa8812015-09-23 12:59:22 -0700161 public void onCameraLaunchGestureDetected(int source) {
Selim Cinek372d1bd2015-08-14 13:19:37 -0700162 if (mBar != null) {
163 try {
Jorim Jaggi40aa8812015-09-23 12:59:22 -0700164 mBar.onCameraLaunchGestureDetected(source);
Selim Cinek372d1bd2015-08-14 13:19:37 -0700165 } catch (RemoteException e) {
166 }
167 }
168 }
Jorim Jaggi86905582016-02-09 21:36:09 -0800169
170 @Override
171 public void topAppWindowChanged(boolean menuVisible) {
172 StatusBarManagerService.this.topAppWindowChanged(menuVisible);
173 }
174
175 @Override
176 public void setSystemUiVisibility(int vis, int fullscreenStackVis, int dockedStackVis,
177 int mask,
178 Rect fullscreenBounds, Rect dockedBounds, String cause) {
179 StatusBarManagerService.this.setSystemUiVisibility(vis, fullscreenStackVis,
180 dockedStackVis, mask, fullscreenBounds, dockedBounds, cause);
181 }
Phil Weaver315c34e2016-02-19 15:12:29 -0800182
183 @Override
184 public void toggleSplitScreen() {
185 enforceStatusBarService();
186 if (mBar != null) {
187 try {
188 mBar.toggleSplitScreen();
189 } catch (RemoteException ex) {}
190 }
191 }
Jorim Jaggi2adba072016-03-03 13:43:39 +0100192
193 public void appTransitionFinished() {
194 enforceStatusBarService();
195 if (mBar != null) {
196 try {
197 mBar.appTransitionFinished();
198 } catch (RemoteException ex) {}
199 }
200 }
Adrian Roosf2efdd82016-04-15 17:43:18 -0700201
202 @Override
203 public void toggleRecentApps() {
204 if (mBar != null) {
205 try {
206 mBar.toggleRecentApps();
207 } catch (RemoteException ex) {}
208 }
209 }
210
211 @Override
212 public void setCurrentUser(int newUserId) {
213 if (SPEW) Slog.d(TAG, "Setting current user to user " + newUserId);
214 mCurrentUserId = newUserId;
215 }
216
217
218 @Override
219 public void preloadRecentApps() {
220 if (mBar != null) {
221 try {
222 mBar.preloadRecentApps();
223 } catch (RemoteException ex) {}
224 }
225 }
226
227 @Override
228 public void cancelPreloadRecentApps() {
229 if (mBar != null) {
230 try {
231 mBar.cancelPreloadRecentApps();
232 } catch (RemoteException ex) {}
233 }
234 }
235
236 @Override
237 public void showRecentApps(boolean triggeredFromAltTab, boolean fromHome) {
238 if (mBar != null) {
239 try {
240 mBar.showRecentApps(triggeredFromAltTab, fromHome);
241 } catch (RemoteException ex) {}
242 }
243 }
244
245 @Override
246 public void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) {
247 if (mBar != null) {
248 try {
249 mBar.hideRecentApps(triggeredFromAltTab, triggeredFromHomeKey);
250 } catch (RemoteException ex) {}
251 }
252 }
253
254 @Override
Andrei Stingaceanu0bf096f2016-04-14 18:11:57 +0100255 public void dismissKeyboardShortcutsMenu() {
256 if (mBar != null) {
257 try {
258 mBar.dismissKeyboardShortcutsMenu();
259 } catch (RemoteException ex) {}
260 }
261 }
262
263 @Override
Adrian Roosf2efdd82016-04-15 17:43:18 -0700264 public void toggleKeyboardShortcutsMenu(int deviceId) {
265 if (mBar != null) {
266 try {
267 mBar.toggleKeyboardShortcutsMenu(deviceId);
268 } catch (RemoteException ex) {}
269 }
270 }
271
272 @Override
Winson Chungac52f282017-03-30 14:44:52 -0700273 public void showPictureInPictureMenu() {
Adrian Roosf2efdd82016-04-15 17:43:18 -0700274 if (mBar != null) {
275 try {
Winson Chungac52f282017-03-30 14:44:52 -0700276 mBar.showPictureInPictureMenu();
Adrian Roosf2efdd82016-04-15 17:43:18 -0700277 } catch (RemoteException ex) {}
278 }
279 }
280
281 @Override
282 public void setWindowState(int window, int state) {
283 if (mBar != null) {
284 try {
285 mBar.setWindowState(window, state);
286 } catch (RemoteException ex) {}
287 }
288 }
289
290 @Override
291 public void appTransitionPending() {
292 if (mBar != null) {
293 try {
294 mBar.appTransitionPending();
295 } catch (RemoteException ex) {}
296 }
297 }
298
299 @Override
300 public void appTransitionCancelled() {
301 if (mBar != null) {
302 try {
303 mBar.appTransitionCancelled();
304 } catch (RemoteException ex) {}
305 }
306 }
307
308 @Override
309 public void appTransitionStarting(long statusBarAnimationsStartTime,
310 long statusBarAnimationsDuration) {
311 if (mBar != null) {
312 try {
313 mBar.appTransitionStarting(
314 statusBarAnimationsStartTime, statusBarAnimationsDuration);
315 } catch (RemoteException ex) {}
316 }
317 }
Jason Monk361915c2017-03-21 20:33:59 -0400318
319 @Override
320 public void setGlobalActionsListener(GlobalActionsListener listener) {
321 mGlobalActionListener = listener;
322 mGlobalActionListener.onStatusBarConnectedChanged(mBar != null);
323 }
324
325 @Override
326 public void showGlobalActions() {
327 if (mBar != null) {
328 try {
329 mBar.showGlobalActionsMenu();
330 } catch (RemoteException ex) {}
331 }
332 }
Jason Monkb4302182017-08-04 13:39:17 -0400333
334 @Override
335 public boolean showShutdownUi(boolean isReboot, String reason) {
336 if (!mContext.getResources().getBoolean(R.bool.config_showSysuiShutdown)) {
337 return false;
338 }
339 if (mBar != null) {
340 try {
341 mBar.showShutdownUi(isReboot, reason);
342 return true;
343 } catch (RemoteException ex) {}
344 }
345 return false;
346 }
Adam Lesinski182f73f2013-12-05 16:48:06 -0800347 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800348
349 // ================================================================================
Joe Onorato25f95f92010-04-08 18:37:10 -0500350 // From IStatusBarService
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800351 // ================================================================================
Adam Lesinski182f73f2013-12-05 16:48:06 -0800352 @Override
Daniel Sandler11cf1782012-09-27 14:03:08 -0400353 public void expandNotificationsPanel() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 enforceExpandStatusBar();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700355
356 if (mBar != null) {
357 try {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400358 mBar.animateExpandNotificationsPanel();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700359 } catch (RemoteException ex) {
360 }
361 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800362 }
363
Adam Lesinski182f73f2013-12-05 16:48:06 -0800364 @Override
Daniel Sandler11cf1782012-09-27 14:03:08 -0400365 public void collapsePanels() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 enforceExpandStatusBar();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367
Joe Onorato4762c2d2010-05-17 15:42:59 -0700368 if (mBar != null) {
369 try {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400370 mBar.animateCollapsePanels();
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700371 } catch (RemoteException ex) {
372 }
373 }
374 }
375
Adam Lesinski182f73f2013-12-05 16:48:06 -0800376 @Override
Jason Monka9927322015-12-13 16:22:37 -0500377 public void expandSettingsPanel(String subPanel) {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700378 enforceExpandStatusBar();
379
380 if (mBar != null) {
381 try {
Jason Monka9927322015-12-13 16:22:37 -0500382 mBar.animateExpandSettingsPanel(subPanel);
Joe Onorato4762c2d2010-05-17 15:42:59 -0700383 } catch (RemoteException ex) {
384 }
385 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 }
387
Jason Monk7e53f202016-01-28 10:40:20 -0500388 public void addTile(ComponentName component) {
389 enforceStatusBarOrShell();
390
391 if (mBar != null) {
392 try {
393 mBar.addQsTile(component);
394 } catch (RemoteException ex) {
395 }
396 }
397 }
398
399 public void remTile(ComponentName component) {
400 enforceStatusBarOrShell();
401
402 if (mBar != null) {
403 try {
404 mBar.remQsTile(component);
405 } catch (RemoteException ex) {
406 }
407 }
408 }
409
410 public void clickTile(ComponentName component) {
411 enforceStatusBarOrShell();
412
413 if (mBar != null) {
414 try {
415 mBar.clickQsTile(component);
416 } catch (RemoteException ex) {
417 }
418 }
419 }
420
Adam Lesinski182f73f2013-12-05 16:48:06 -0800421 @Override
Philip Quinnc3a503d2017-07-18 23:23:41 -0700422 public void handleSystemKey(int key) throws RemoteException {
Jim Miller07e03842016-06-22 15:18:13 -0700423 enforceExpandStatusBar();
424
425 if (mBar != null) {
426 try {
Philip Quinnc3a503d2017-07-18 23:23:41 -0700427 mBar.handleSystemKey(key);
Jim Miller07e03842016-06-22 15:18:13 -0700428 } catch (RemoteException ex) {
429 }
430 }
431 }
432
433 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434 public void disable(int what, IBinder token, String pkg) {
Benjamin Franzea2ec972015-03-16 17:18:09 +0000435 disableForUser(what, token, pkg, mCurrentUserId);
John Spurlock13451a22012-09-28 14:40:41 -0400436 }
437
Benjamin Franzea2ec972015-03-16 17:18:09 +0000438 @Override
439 public void disableForUser(int what, IBinder token, String pkg, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800440 enforceStatusBar();
Joe Onoratof3f0e052010-05-14 18:49:29 -0700441
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800442 synchronized (mLock) {
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100443 disableLocked(userId, what, token, pkg, 1);
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800444 }
445 }
446
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100447 /**
448 * Disable additional status bar features. Pass the bitwise-or of the DISABLE2_* flags.
449 * To re-enable everything, pass {@link #DISABLE_NONE}.
450 *
451 * Warning: Only pass DISABLE2_* flags into this function, do not use DISABLE_* flags.
452 */
453 @Override
454 public void disable2(int what, IBinder token, String pkg) {
Benjamin Franz292a0a92016-03-30 13:41:57 +0100455 disable2ForUser(what, token, pkg, mCurrentUserId);
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100456 }
457
458 /**
459 * Disable additional status bar features for a given user. Pass the bitwise-or of the
460 * DISABLE2_* flags. To re-enable everything, pass {@link #DISABLE_NONE}.
461 *
462 * Warning: Only pass DISABLE2_* flags into this function, do not use DISABLE_* flags.
463 */
464 @Override
465 public void disable2ForUser(int what, IBinder token, String pkg, int userId) {
466 enforceStatusBar();
467
468 synchronized (mLock) {
469 disableLocked(userId, what, token, pkg, 2);
470 }
471 }
472
473 private void disableLocked(int userId, int what, IBinder token, String pkg, int whichFlag) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700474 // It's important that the the callback and the call to mBar get done
475 // in the same order when multiple threads are calling this function
476 // so they are paired correctly. The messages on the handler will be
477 // handled in the order they were enqueued, but will be outside the lock.
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100478 manageDisableListLocked(userId, what, token, pkg, whichFlag);
John Spurlock8f3e6d52012-11-29 13:56:24 -0500479
480 // Ensure state for the current user is applied, even if passed a non-current user.
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100481 final int net1 = gatherDisableActionsLocked(mCurrentUserId, 1);
482 final int net2 = gatherDisableActionsLocked(mCurrentUserId, 2);
483 if (net1 != mDisabled1 || net2 != mDisabled2) {
484 mDisabled1 = net1;
485 mDisabled2 = net2;
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800486 mHandler.post(new Runnable() {
487 public void run() {
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100488 mNotificationDelegate.onSetDisabled(net1);
Joe Onoratof3f0e052010-05-14 18:49:29 -0700489 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800490 });
491 if (mBar != null) {
492 try {
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100493 mBar.disable(net1, net2);
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800494 } catch (RemoteException ex) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700495 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497 }
498 }
499
Adam Lesinski182f73f2013-12-05 16:48:06 -0800500 @Override
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700501 public void setIcon(String slot, String iconPackage, int iconId, int iconLevel,
502 String contentDescription) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700504
505 synchronized (mIcons) {
Xiaohui Chene4de5a02015-09-22 15:33:31 -0700506 StatusBarIcon icon = new StatusBarIcon(iconPackage, UserHandle.SYSTEM, iconId,
507 iconLevel, 0, contentDescription);
Joe Onorato66d7d012010-05-14 10:05:10 -0700508 //Slog.d(TAG, "setIcon slot=" + slot + " index=" + index + " icon=" + icon);
Jason Monk07473ce2016-01-05 14:59:19 -0500509 mIcons.put(slot, icon);
Joe Onorato0cbda992010-05-02 16:28:15 -0700510
Joe Onorato0cbda992010-05-02 16:28:15 -0700511 if (mBar != null) {
512 try {
Jason Monk07473ce2016-01-05 14:59:19 -0500513 mBar.setIcon(slot, icon);
Joe Onorato0cbda992010-05-02 16:28:15 -0700514 } catch (RemoteException ex) {
515 }
516 }
517 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800518 }
519
Adam Lesinski182f73f2013-12-05 16:48:06 -0800520 @Override
Jason Monk07473ce2016-01-05 14:59:19 -0500521 public void setIconVisibility(String slot, boolean visibility) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800522 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700523
Joe Onorato514ad6632010-05-13 18:49:00 -0700524 synchronized (mIcons) {
Jason Monk07473ce2016-01-05 14:59:19 -0500525 StatusBarIcon icon = mIcons.get(slot);
Joe Onorato514ad6632010-05-13 18:49:00 -0700526 if (icon == null) {
527 return;
528 }
Jason Monk07473ce2016-01-05 14:59:19 -0500529 if (icon.visible != visibility) {
530 icon.visible = visibility;
Joe Onorato514ad6632010-05-13 18:49:00 -0700531
Joe Onorato514ad6632010-05-13 18:49:00 -0700532 if (mBar != null) {
533 try {
Jason Monk07473ce2016-01-05 14:59:19 -0500534 mBar.setIcon(slot, icon);
Joe Onorato514ad6632010-05-13 18:49:00 -0700535 } catch (RemoteException ex) {
536 }
537 }
538 }
539 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700540 }
541
Adam Lesinski182f73f2013-12-05 16:48:06 -0800542 @Override
Joe Onorato0cbda992010-05-02 16:28:15 -0700543 public void removeIcon(String slot) {
544 enforceStatusBar();
545
546 synchronized (mIcons) {
Jason Monk07473ce2016-01-05 14:59:19 -0500547 mIcons.remove(slot);
Joe Onorato0cbda992010-05-02 16:28:15 -0700548
Joe Onorato0cbda992010-05-02 16:28:15 -0700549 if (mBar != null) {
550 try {
Jason Monk07473ce2016-01-05 14:59:19 -0500551 mBar.removeIcon(slot);
Joe Onorato0cbda992010-05-02 16:28:15 -0700552 } catch (RemoteException ex) {
553 }
554 }
555 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556 }
557
Wale Ogunwale393b1c12014-10-18 16:22:01 -0700558 /**
Daniel Sandlere02d8082010-10-08 15:13:22 -0400559 * Hide or show the on-screen Menu key. Only call this from the window manager, typically in
Wale Ogunwale393b1c12014-10-18 16:22:01 -0700560 * response to a window with {@link android.view.WindowManager.LayoutParams#needsMenuKey} set
561 * to {@link android.view.WindowManager.LayoutParams#NEEDS_MENU_SET_TRUE}.
Daniel Sandlere02d8082010-10-08 15:13:22 -0400562 */
Jorim Jaggi86905582016-02-09 21:36:09 -0800563 private void topAppWindowChanged(final boolean menuVisible) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400564 enforceStatusBar();
565
Dianne Hackborn7d049322011-06-14 15:00:32 -0700566 if (SPEW) Slog.d(TAG, (menuVisible?"showing":"hiding") + " MENU key");
Daniel Sandlere02d8082010-10-08 15:13:22 -0400567
568 synchronized(mLock) {
Dianne Hackborn7d049322011-06-14 15:00:32 -0700569 mMenuVisible = menuVisible;
570 mHandler.post(new Runnable() {
Jorim Jaggi86905582016-02-09 21:36:09 -0800571 public void run() {
572 if (mBar != null) {
573 try {
574 mBar.topAppWindowChanged(menuVisible);
575 } catch (RemoteException ex) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400576 }
Dianne Hackborn7d049322011-06-14 15:00:32 -0700577 }
Jorim Jaggi86905582016-02-09 21:36:09 -0800578 }
579 });
Daniel Sandlere02d8082010-10-08 15:13:22 -0400580 }
581 }
582
Adam Lesinski182f73f2013-12-05 16:48:06 -0800583 @Override
Jason Monkb605fec2014-05-02 17:04:10 -0400584 public void setImeWindowStatus(final IBinder token, final int vis, final int backDisposition,
585 final boolean showImeSwitcher) {
satok06487a52010-10-29 11:37:18 +0900586 enforceStatusBar();
587
Joe Onorato857fd9b2011-01-27 15:08:35 -0800588 if (SPEW) {
589 Slog.d(TAG, "swetImeWindowStatus vis=" + vis + " backDisposition=" + backDisposition);
590 }
satok06487a52010-10-29 11:37:18 +0900591
592 synchronized(mLock) {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800593 // In case of IME change, we need to call up setImeWindowStatus() regardless of
594 // mImeWindowVis because mImeWindowVis may not have been set to false when the
satok06e07442010-11-02 19:46:55 +0900595 // previous IME was destroyed.
Joe Onorato857fd9b2011-01-27 15:08:35 -0800596 mImeWindowVis = vis;
597 mImeBackDisposition = backDisposition;
598 mImeToken = token;
Jason Monkb605fec2014-05-02 17:04:10 -0400599 mShowImeSwitcher = showImeSwitcher;
satok06e07442010-11-02 19:46:55 +0900600 mHandler.post(new Runnable() {
601 public void run() {
602 if (mBar != null) {
603 try {
Jason Monkb605fec2014-05-02 17:04:10 -0400604 mBar.setImeWindowStatus(token, vis, backDisposition, showImeSwitcher);
satok06e07442010-11-02 19:46:55 +0900605 } catch (RemoteException ex) {
satok06487a52010-10-29 11:37:18 +0900606 }
607 }
satok06e07442010-11-02 19:46:55 +0900608 }
609 });
satok06487a52010-10-29 11:37:18 +0900610 }
611 }
612
Adam Lesinski182f73f2013-12-05 16:48:06 -0800613 @Override
Adrian Roos53f28ec2014-10-29 17:26:12 +0100614 public void setSystemUiVisibility(int vis, int mask, String cause) {
Jorim Jaggi86905582016-02-09 21:36:09 -0800615 setSystemUiVisibility(vis, 0, 0, mask, mFullscreenStackBounds, mDockedStackBounds, cause);
616 }
617
618 private void setSystemUiVisibility(int vis, int fullscreenStackVis, int dockedStackVis, int mask,
619 Rect fullscreenBounds, Rect dockedBounds, String cause) {
Joe Onorato55bf3802011-01-25 13:42:10 -0800620 // also allows calls from window manager which is in this process.
Joe Onoratof63b0f42010-09-12 17:03:19 -0400621 enforceStatusBarService();
622
Jeff Sharkey4519a022011-09-07 23:24:53 -0700623 if (SPEW) Slog.d(TAG, "setSystemUiVisibility(0x" + Integer.toHexString(vis) + ")");
Daniel Sandler60ee2562011-07-22 12:34:33 -0400624
Joe Onoratof63b0f42010-09-12 17:03:19 -0400625 synchronized (mLock) {
Jorim Jaggi86905582016-02-09 21:36:09 -0800626 updateUiVisibilityLocked(vis, fullscreenStackVis, dockedStackVis, mask,
627 fullscreenBounds, dockedBounds);
John Spurlock13451a22012-09-28 14:40:41 -0400628 disableLocked(
629 mCurrentUserId,
630 vis & StatusBarManager.DISABLE_MASK,
631 mSysUiVisToken,
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100632 cause, 1);
Joe Onoratof63b0f42010-09-12 17:03:19 -0400633 }
634 }
635
Jorim Jaggi86905582016-02-09 21:36:09 -0800636 private void updateUiVisibilityLocked(final int vis,
637 final int fullscreenStackVis, final int dockedStackVis, final int mask,
638 final Rect fullscreenBounds, final Rect dockedBounds) {
639 if (mSystemUiVisibility != vis
640 || mFullscreenStackSysUiVisibility != fullscreenStackVis
641 || mDockedStackSysUiVisibility != dockedStackVis
642 || !mFullscreenStackBounds.equals(fullscreenBounds)
643 || !mDockedStackBounds.equals(dockedBounds)) {
Daniel Sandler60ee2562011-07-22 12:34:33 -0400644 mSystemUiVisibility = vis;
Jorim Jaggi86905582016-02-09 21:36:09 -0800645 mFullscreenStackSysUiVisibility = fullscreenStackVis;
646 mDockedStackSysUiVisibility = dockedStackVis;
647 mFullscreenStackBounds.set(fullscreenBounds);
648 mDockedStackBounds.set(dockedBounds);
Joe Onoratof63b0f42010-09-12 17:03:19 -0400649 mHandler.post(new Runnable() {
650 public void run() {
651 if (mBar != null) {
652 try {
Jorim Jaggi86905582016-02-09 21:36:09 -0800653 mBar.setSystemUiVisibility(vis, fullscreenStackVis, dockedStackVis,
654 mask, fullscreenBounds, dockedBounds);
Joe Onoratof63b0f42010-09-12 17:03:19 -0400655 } catch (RemoteException ex) {
Joe Onorato93056472010-09-10 10:30:46 -0400656 }
657 }
Joe Onoratof63b0f42010-09-12 17:03:19 -0400658 }
659 });
Joe Onorato93056472010-09-10 10:30:46 -0400660 }
661 }
662
Jason Monk7e53f202016-01-28 10:40:20 -0500663 private void enforceStatusBarOrShell() {
664 if (Binder.getCallingUid() == Process.SHELL_UID) {
665 return;
666 }
667 enforceStatusBar();
668 }
669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 private void enforceStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700671 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700672 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800673 }
674
675 private void enforceExpandStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700676 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.EXPAND_STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700677 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800678 }
679
Joe Onorato8bc6c512010-06-04 16:21:12 -0400680 private void enforceStatusBarService() {
681 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
682 "StatusBarManagerService");
683 }
684
Joe Onorato4762c2d2010-05-17 15:42:59 -0700685 // ================================================================================
686 // Callbacks from the status bar service.
687 // ================================================================================
Adam Lesinski182f73f2013-12-05 16:48:06 -0800688 @Override
Jason Monk07473ce2016-01-05 14:59:19 -0500689 public void registerStatusBar(IStatusBar bar, List<String> iconSlots,
Jorim Jaggi86905582016-02-09 21:36:09 -0800690 List<StatusBarIcon> iconList, int switches[], List<IBinder> binders,
691 Rect fullscreenStackBounds, Rect dockedStackBounds) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400692 enforceStatusBarService();
693
Joe Onorato0cbda992010-05-02 16:28:15 -0700694 Slog.i(TAG, "registerStatusBar bar=" + bar);
695 mBar = bar;
Jason Monk361915c2017-03-21 20:33:59 -0400696 try {
697 mBar.asBinder().linkToDeath(new DeathRecipient() {
698 @Override
699 public void binderDied() {
700 mBar = null;
701 notifyBarAttachChanged();
702 }
703 }, 0);
704 } catch (RemoteException e) {
705 }
706 notifyBarAttachChanged();
Joe Onorato75199e32010-05-29 17:22:51 -0400707 synchronized (mIcons) {
Jason Monk07473ce2016-01-05 14:59:19 -0500708 for (String slot : mIcons.keySet()) {
709 iconSlots.add(slot);
710 iconList.add(mIcons.get(slot));
711 }
Joe Onorato75199e32010-05-29 17:22:51 -0400712 }
Joe Onorato93056472010-09-10 10:30:46 -0400713 synchronized (mLock) {
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100714 switches[0] = gatherDisableActionsLocked(mCurrentUserId, 1);
Daniel Sandler60ee2562011-07-22 12:34:33 -0400715 switches[1] = mSystemUiVisibility;
Joe Onoratoe4c7b3f2010-10-30 12:15:03 -0700716 switches[2] = mMenuVisible ? 1 : 0;
Joe Onorato857fd9b2011-01-27 15:08:35 -0800717 switches[3] = mImeWindowVis;
718 switches[4] = mImeBackDisposition;
Michael Wright665366a2014-08-07 15:44:40 -0700719 switches[5] = mShowImeSwitcher ? 1 : 0;
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100720 switches[6] = gatherDisableActionsLocked(mCurrentUserId, 2);
Jorim Jaggi86905582016-02-09 21:36:09 -0800721 switches[7] = mFullscreenStackSysUiVisibility;
722 switches[8] = mDockedStackSysUiVisibility;
Joe Onorato857fd9b2011-01-27 15:08:35 -0800723 binders.add(mImeToken);
Jorim Jaggi86905582016-02-09 21:36:09 -0800724 fullscreenStackBounds.set(mFullscreenStackBounds);
725 dockedStackBounds.set(mDockedStackBounds);
Joe Onorato93056472010-09-10 10:30:46 -0400726 }
Joe Onorato2314aab2010-04-08 16:41:23 -0500727 }
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400728
Jason Monk361915c2017-03-21 20:33:59 -0400729 private void notifyBarAttachChanged() {
730 mHandler.post(() -> {
731 if (mGlobalActionListener == null) return;
732 mGlobalActionListener.onStatusBarConnectedChanged(mBar != null);
733 });
734 }
735
Joe Onorato4762c2d2010-05-17 15:42:59 -0700736 /**
Christoph Studer1f32c652014-11-26 15:32:20 +0100737 * @param clearNotificationEffects whether to consider notifications as "shown" and stop
738 * LED, vibration, and ringing
Joe Onorato4762c2d2010-05-17 15:42:59 -0700739 */
Adam Lesinski182f73f2013-12-05 16:48:06 -0800740 @Override
Chris Wrenb659c4f2015-06-25 17:12:27 -0400741 public void onPanelRevealed(boolean clearNotificationEffects, int numItems) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400742 enforceStatusBarService();
Adam Lesinski182f73f2013-12-05 16:48:06 -0800743 long identity = Binder.clearCallingIdentity();
744 try {
Chris Wrenb659c4f2015-06-25 17:12:27 -0400745 mNotificationDelegate.onPanelRevealed(clearNotificationEffects, numItems);
Christoph Studer1f32c652014-11-26 15:32:20 +0100746 } finally {
747 Binder.restoreCallingIdentity(identity);
748 }
749 }
750
751 @Override
752 public void clearNotificationEffects() throws RemoteException {
753 enforceStatusBarService();
754 long identity = Binder.clearCallingIdentity();
755 try {
756 mNotificationDelegate.clearEffects();
Adam Lesinski182f73f2013-12-05 16:48:06 -0800757 } finally {
758 Binder.restoreCallingIdentity(identity);
759 }
Joe Onorato4762c2d2010-05-17 15:42:59 -0700760 }
761
Adam Lesinski182f73f2013-12-05 16:48:06 -0800762 @Override
Christoph Studer760ea552014-03-21 13:10:21 +0100763 public void onPanelHidden() throws RemoteException {
764 enforceStatusBarService();
765 long identity = Binder.clearCallingIdentity();
766 try {
767 mNotificationDelegate.onPanelHidden();
768 } finally {
769 Binder.restoreCallingIdentity(identity);
770 }
771 }
772
Jason Monk361915c2017-03-21 20:33:59 -0400773 /**
774 * Allows the status bar to shutdown the device.
775 */
776 @Override
777 public void shutdown() {
778 enforceStatusBarService();
779 long identity = Binder.clearCallingIdentity();
780 try {
Michael Wright6cd10262017-04-04 17:44:56 +0100781 // ShutdownThread displays UI, so give it a UI context.
Jason Monk361915c2017-03-21 20:33:59 -0400782 mHandler.post(() ->
Michael Wright6cd10262017-04-04 17:44:56 +0100783 ShutdownThread.shutdown(getUiContext(),
784 PowerManager.SHUTDOWN_USER_REQUESTED, false));
Jason Monk361915c2017-03-21 20:33:59 -0400785 } finally {
786 Binder.restoreCallingIdentity(identity);
787 }
788 }
789
790 /**
791 * Allows the status bar to reboot the device.
792 */
793 @Override
794 public void reboot(boolean safeMode) {
795 enforceStatusBarService();
796 long identity = Binder.clearCallingIdentity();
797 try {
798 mHandler.post(() -> {
Adam Lesinskia82b6262017-03-21 16:56:17 -0700799 // ShutdownThread displays UI, so give it a UI context.
Jason Monk361915c2017-03-21 20:33:59 -0400800 if (safeMode) {
Shunta Satobdb0e492017-04-14 16:01:54 +0900801 ShutdownThread.rebootSafeMode(getUiContext(), true);
Jason Monk361915c2017-03-21 20:33:59 -0400802 } else {
Michael Wright6cd10262017-04-04 17:44:56 +0100803 ShutdownThread.reboot(getUiContext(),
804 PowerManager.SHUTDOWN_USER_REQUESTED, false);
Jason Monk361915c2017-03-21 20:33:59 -0400805 }
806 });
807 } finally {
808 Binder.restoreCallingIdentity(identity);
809 }
810 }
811
812 @Override
813 public void onGlobalActionsShown() {
814 enforceStatusBarService();
815 long identity = Binder.clearCallingIdentity();
816 try {
817 if (mGlobalActionListener == null) return;
818 mGlobalActionListener.onGlobalActionsShown();
819 } finally {
820 Binder.restoreCallingIdentity(identity);
821 }
822 }
823
824 @Override
825 public void onGlobalActionsHidden() {
826 enforceStatusBarService();
827 long identity = Binder.clearCallingIdentity();
828 try {
829 if (mGlobalActionListener == null) return;
830 mGlobalActionListener.onGlobalActionsDismissed();
831 } finally {
832 Binder.restoreCallingIdentity(identity);
833 }
834 }
835
Christoph Studer760ea552014-03-21 13:10:21 +0100836 @Override
Christoph Studer03b87a22014-04-30 17:33:27 +0200837 public void onNotificationClick(String key) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400838 enforceStatusBarService();
John Spurlocke6a7d932014-03-13 12:29:00 -0400839 final int callingUid = Binder.getCallingUid();
840 final int callingPid = Binder.getCallingPid();
Adam Lesinski182f73f2013-12-05 16:48:06 -0800841 long identity = Binder.clearCallingIdentity();
842 try {
Christoph Studer03b87a22014-04-30 17:33:27 +0200843 mNotificationDelegate.onNotificationClick(callingUid, callingPid, key);
Adam Lesinski182f73f2013-12-05 16:48:06 -0800844 } finally {
845 Binder.restoreCallingIdentity(identity);
846 }
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400847 }
848
Adam Lesinski182f73f2013-12-05 16:48:06 -0800849 @Override
Christoph Studer4da84cd2014-10-21 17:24:20 +0200850 public void onNotificationActionClick(String key, int actionIndex) {
851 enforceStatusBarService();
852 final int callingUid = Binder.getCallingUid();
853 final int callingPid = Binder.getCallingPid();
854 long identity = Binder.clearCallingIdentity();
855 try {
856 mNotificationDelegate.onNotificationActionClick(callingUid, callingPid, key,
857 actionIndex);
858 } finally {
859 Binder.restoreCallingIdentity(identity);
860 }
861 }
862
863 @Override
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700864 public void onNotificationError(String pkg, String tag, int id,
Kenny Guy3a7c4a52014-03-03 18:24:03 +0000865 int uid, int initialPid, String message, int userId) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400866 enforceStatusBarService();
John Spurlocke6a7d932014-03-13 12:29:00 -0400867 final int callingUid = Binder.getCallingUid();
868 final int callingPid = Binder.getCallingPid();
Adam Lesinski182f73f2013-12-05 16:48:06 -0800869 long identity = Binder.clearCallingIdentity();
870 try {
871 // WARNING: this will call back into us to do the remove. Don't hold any locks.
John Spurlocke6a7d932014-03-13 12:29:00 -0400872 mNotificationDelegate.onNotificationError(callingUid, callingPid,
873 pkg, tag, id, uid, initialPid, message, userId);
Adam Lesinski182f73f2013-12-05 16:48:06 -0800874 } finally {
875 Binder.restoreCallingIdentity(identity);
876 }
Joe Onorato005847b2010-06-04 16:08:02 -0400877 }
878
Adam Lesinski182f73f2013-12-05 16:48:06 -0800879 @Override
Kenny Guy3a7c4a52014-03-03 18:24:03 +0000880 public void onNotificationClear(String pkg, String tag, int id, int userId) {
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400881 enforceStatusBarService();
John Spurlocke6a7d932014-03-13 12:29:00 -0400882 final int callingUid = Binder.getCallingUid();
883 final int callingPid = Binder.getCallingPid();
Adam Lesinski182f73f2013-12-05 16:48:06 -0800884 long identity = Binder.clearCallingIdentity();
885 try {
John Spurlocke6a7d932014-03-13 12:29:00 -0400886 mNotificationDelegate.onNotificationClear(callingUid, callingPid, pkg, tag, id, userId);
Adam Lesinski182f73f2013-12-05 16:48:06 -0800887 } finally {
888 Binder.restoreCallingIdentity(identity);
889 }
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400890 }
891
Adam Lesinski182f73f2013-12-05 16:48:06 -0800892 @Override
Christoph Studer92b389d2014-04-01 18:44:40 +0200893 public void onNotificationVisibilityChanged(
Chris Wrend1dbc922015-06-19 17:51:16 -0400894 NotificationVisibility[] newlyVisibleKeys, NotificationVisibility[] noLongerVisibleKeys)
895 throws RemoteException {
Christoph Studer92b389d2014-04-01 18:44:40 +0200896 enforceStatusBarService();
897 long identity = Binder.clearCallingIdentity();
898 try {
899 mNotificationDelegate.onNotificationVisibilityChanged(
900 newlyVisibleKeys, noLongerVisibleKeys);
901 } finally {
902 Binder.restoreCallingIdentity(identity);
903 }
904 }
905
906 @Override
Chris Wren78403d72014-07-28 10:23:24 +0100907 public void onNotificationExpansionChanged(String key, boolean userAction,
908 boolean expanded) throws RemoteException {
909 enforceStatusBarService();
910 long identity = Binder.clearCallingIdentity();
911 try {
912 mNotificationDelegate.onNotificationExpansionChanged(
913 key, userAction, expanded);
914 } finally {
915 Binder.restoreCallingIdentity(identity);
916 }
917 }
918
919 @Override
Kenny Guy3a7c4a52014-03-03 18:24:03 +0000920 public void onClearAllNotifications(int userId) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400921 enforceStatusBarService();
John Spurlocke6a7d932014-03-13 12:29:00 -0400922 final int callingUid = Binder.getCallingUid();
923 final int callingPid = Binder.getCallingPid();
Adam Lesinski182f73f2013-12-05 16:48:06 -0800924 long identity = Binder.clearCallingIdentity();
925 try {
John Spurlocke6a7d932014-03-13 12:29:00 -0400926 mNotificationDelegate.onClearAll(callingUid, callingPid, userId);
Adam Lesinski182f73f2013-12-05 16:48:06 -0800927 } finally {
928 Binder.restoreCallingIdentity(identity);
Joe Onorato18e69df2010-05-17 22:26:12 -0700929 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700930 }
931
Jason Monk7e53f202016-01-28 10:40:20 -0500932 @Override
933 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
Dianne Hackborn354736e2016-08-22 17:00:05 -0700934 String[] args, ShellCallback callback, ResultReceiver resultReceiver) {
Jason Monk7e53f202016-01-28 10:40:20 -0500935 (new StatusBarShellCommand(this)).exec(
Dianne Hackborn354736e2016-08-22 17:00:05 -0700936 this, in, out, err, args, callback, resultReceiver);
Jason Monk7e53f202016-01-28 10:40:20 -0500937 }
938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800939 // ================================================================================
940 // Can be called from any thread
941 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800943 // lock on mDisableRecords
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100944 void manageDisableListLocked(int userId, int what, IBinder token, String pkg, int which) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800945 if (SPEW) {
John Spurlock13451a22012-09-28 14:40:41 -0400946 Slog.d(TAG, "manageDisableList userId=" + userId
947 + " what=0x" + Integer.toHexString(what) + " pkg=" + pkg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800948 }
949 // update the list
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800950 final int N = mDisableRecords.size();
951 DisableRecord tok = null;
952 int i;
953 for (i=0; i<N; i++) {
954 DisableRecord t = mDisableRecords.get(i);
John Spurlock4e6922d2012-10-04 14:51:51 -0400955 if (t.token == token && t.userId == userId) {
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800956 tok = t;
957 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800958 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800959 }
960 if (what == 0 || !token.isBinderAlive()) {
961 if (tok != null) {
962 mDisableRecords.remove(i);
963 tok.token.unlinkToDeath(tok, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800964 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800965 } else {
966 if (tok == null) {
967 tok = new DisableRecord();
John Spurlock13451a22012-09-28 14:40:41 -0400968 tok.userId = userId;
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800969 try {
970 token.linkToDeath(tok, 0);
971 }
972 catch (RemoteException ex) {
973 return; // give up
974 }
975 mDisableRecords.add(tok);
976 }
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100977 if (which == 1) {
978 tok.what1 = what;
979 } else {
980 tok.what2 = what;
981 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800982 tok.token = token;
983 tok.pkg = pkg;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800984 }
985 }
986
987 // lock on mDisableRecords
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100988 int gatherDisableActionsLocked(int userId, int which) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800989 final int N = mDisableRecords.size();
990 // gather the new net flags
991 int net = 0;
992 for (int i=0; i<N; i++) {
John Spurlock13451a22012-09-28 14:40:41 -0400993 final DisableRecord rec = mDisableRecords.get(i);
994 if (rec.userId == userId) {
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100995 net |= (which == 1) ? rec.what1 : rec.what2;
John Spurlock13451a22012-09-28 14:40:41 -0400996 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800997 }
998 return net;
999 }
1000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001001 // ================================================================================
1002 // Always called from UI thread
1003 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001005 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001006 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Joe Onorato0cbda992010-05-02 16:28:15 -07001007
Joe Onorato7bb8eeb2011-01-27 16:00:58 -08001008 synchronized (mLock) {
Benjamin Franzcde0a2a2015-04-23 17:19:48 +01001009 pw.println(" mDisabled1=0x" + Integer.toHexString(mDisabled1));
1010 pw.println(" mDisabled2=0x" + Integer.toHexString(mDisabled2));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001011 final int N = mDisableRecords.size();
John Spurlock13451a22012-09-28 14:40:41 -04001012 pw.println(" mDisableRecords.size=" + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001013 for (int i=0; i<N; i++) {
1014 DisableRecord tok = mDisableRecords.get(i);
John Spurlock13451a22012-09-28 14:40:41 -04001015 pw.println(" [" + i + "] userId=" + tok.userId
Benjamin Franzcde0a2a2015-04-23 17:19:48 +01001016 + " what1=0x" + Integer.toHexString(tok.what1)
1017 + " what2=0x" + Integer.toHexString(tok.what2)
John Spurlock13451a22012-09-28 14:40:41 -04001018 + " pkg=" + tok.pkg
1019 + " token=" + tok.token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001020 }
Adrian Roos2a629102016-04-15 16:28:03 -07001021 pw.println(" mCurrentUserId=" + mCurrentUserId);
Dan Sandlerf3a1f2c2016-06-26 15:59:13 -04001022 pw.println(" mIcons=");
1023 for (String slot : mIcons.keySet()) {
1024 pw.println(" ");
1025 pw.print(slot);
1026 pw.print(" -> ");
1027 final StatusBarIcon icon = mIcons.get(slot);
1028 pw.print(icon);
1029 if (!TextUtils.isEmpty(icon.contentDescription)) {
1030 pw.print(" \"");
1031 pw.print(icon.contentDescription);
1032 pw.print("\"");
1033 }
1034 pw.println();
1035 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001036 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001037 }
Michael Wright6cd10262017-04-04 17:44:56 +01001038
1039 private static final Context getUiContext() {
1040 return ActivityThread.currentActivityThread().getSystemUiContext();
1041 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001042}