blob: c7c03b48a77804c6872bf6b1e45d35324206546f [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
Charles He9851a8d2017-10-10 17:31:30 +010019import static android.app.StatusBarManager.DISABLE2_GLOBAL_ACTIONS;
20
Adam Lesinskia82b6262017-03-21 16:56:17 -070021import android.app.ActivityThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.app.StatusBarManager;
Jason Monk7e53f202016-01-28 10:40:20 -050023import android.content.ComponentName;
Jason Monk07473ce2016-01-05 14:59:19 -050024import android.content.Context;
Jorim Jaggi86905582016-02-09 21:36:09 -080025import android.graphics.Rect;
Adam Lesinski182f73f2013-12-05 16:48:06 -080026import android.os.Binder;
Jorim Jaggi165ce062015-07-06 16:18:11 -070027import android.os.Bundle;
Adam Lesinski182f73f2013-12-05 16:48:06 -080028import android.os.Handler;
29import android.os.IBinder;
Jason Monk361915c2017-03-21 20:33:59 -040030import android.os.PowerManager;
Jason Monk7e53f202016-01-28 10:40:20 -050031import android.os.Process;
Adam Lesinski182f73f2013-12-05 16:48:06 -080032import android.os.RemoteException;
Jason Monk7e53f202016-01-28 10:40:20 -050033import android.os.ResultReceiver;
Dianne Hackborn354736e2016-08-22 17:00:05 -070034import android.os.ShellCallback;
Adam Lesinski182f73f2013-12-05 16:48:06 -080035import android.os.UserHandle;
Julia Reynolds503ed942017-10-04 16:04:56 -040036import android.service.notification.NotificationStats;
Dan Sandlerf3a1f2c2016-06-26 15:59:13 -040037import android.text.TextUtils;
Jason Monk07473ce2016-01-05 14:59:19 -050038import android.util.ArrayMap;
Joe Onorato8a9b2202010-02-26 18:56:32 -080039import android.util.Slog;
Jim Miller07e03842016-06-22 15:18:13 -070040
Jason Monkb4302182017-08-04 13:39:17 -040041import com.android.internal.R;
Joe Onorato0cbda992010-05-02 16:28:15 -070042import com.android.internal.statusbar.IStatusBar;
43import com.android.internal.statusbar.IStatusBarService;
Chris Wrend1dbc922015-06-19 17:51:16 -040044import com.android.internal.statusbar.NotificationVisibility;
Joe Onorato0cbda992010-05-02 16:28:15 -070045import com.android.internal.statusbar.StatusBarIcon;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060046import com.android.internal.util.DumpUtils;
Adam Lesinski182f73f2013-12-05 16:48:06 -080047import com.android.server.LocalServices;
48import com.android.server.notification.NotificationDelegate;
Jason Monk361915c2017-03-21 20:33:59 -040049import com.android.server.power.ShutdownThread;
50import com.android.server.statusbar.StatusBarManagerInternal.GlobalActionsListener;
Dianne Hackborna924dc0d2011-02-17 14:22:17 -080051import com.android.server.wm.WindowManagerService;
The Android Open Source Project10592532009-03-18 17:39:46 -070052
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053import java.io.FileDescriptor;
54import java.io.PrintWriter;
55import java.util.ArrayList;
Joe Onorato75199e32010-05-29 17:22:51 -040056import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057
58
59/**
Joe Onoratof3f0e052010-05-14 18:49:29 -070060 * A note on locking: We rely on the fact that calls onto mBar are oneway or
61 * if they are local, that they just enqueue messages to not deadlock.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062 */
Michael Wright665366a2014-08-07 15:44:40 -070063public class StatusBarManagerService extends IStatusBarService.Stub {
Adam Lesinski182f73f2013-12-05 16:48:06 -080064 private static final String TAG = "StatusBarManagerService";
65 private static final boolean SPEW = false;
Joe Onoratodf7dbb62009-11-17 10:43:37 -080066
Adam Lesinski182f73f2013-12-05 16:48:06 -080067 private final Context mContext;
Adam Lesinskia82b6262017-03-21 16:56:17 -070068
Adam Lesinski182f73f2013-12-05 16:48:06 -080069 private final WindowManagerService mWindowManager;
70 private Handler mHandler = new Handler();
71 private NotificationDelegate mNotificationDelegate;
72 private volatile IStatusBar mBar;
Jason Monk07473ce2016-01-05 14:59:19 -050073 private ArrayMap<String, StatusBarIcon> mIcons = new ArrayMap<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074
Joe Onoratof3f0e052010-05-14 18:49:29 -070075 // for disabling the status bar
Adam Lesinski182f73f2013-12-05 16:48:06 -080076 private final ArrayList<DisableRecord> mDisableRecords = new ArrayList<DisableRecord>();
Jason Monk361915c2017-03-21 20:33:59 -040077 private GlobalActionsListener mGlobalActionListener;
Adam Lesinski182f73f2013-12-05 16:48:06 -080078 private IBinder mSysUiVisToken = new Binder();
Benjamin Franzcde0a2a2015-04-23 17:19:48 +010079 private int mDisabled1 = 0;
80 private int mDisabled2 = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081
Adrian Roos2a629102016-04-15 16:28:03 -070082 private final Object mLock = new Object();
Daniel Sandler60ee2562011-07-22 12:34:33 -040083 // encompasses lights-out mode and other flags defined on View
Adam Lesinski182f73f2013-12-05 16:48:06 -080084 private int mSystemUiVisibility = 0;
Jorim Jaggi86905582016-02-09 21:36:09 -080085 private int mFullscreenStackSysUiVisibility;
86 private int mDockedStackSysUiVisibility;
87 private final Rect mFullscreenStackBounds = new Rect();
88 private final Rect mDockedStackBounds = new Rect();
Adam Lesinski182f73f2013-12-05 16:48:06 -080089 private boolean mMenuVisible = false;
90 private int mImeWindowVis = 0;
91 private int mImeBackDisposition;
Jason Monkb605fec2014-05-02 17:04:10 -040092 private boolean mShowImeSwitcher;
Adam Lesinski182f73f2013-12-05 16:48:06 -080093 private IBinder mImeToken = null;
94 private int mCurrentUserId;
satok06487a52010-10-29 11:37:18 +090095
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 private class DisableRecord implements IBinder.DeathRecipient {
John Spurlock13451a22012-09-28 14:40:41 -040097 int userId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 String pkg;
Benjamin Franzcde0a2a2015-04-23 17:19:48 +010099 int what1;
100 int what2;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101 IBinder token;
102
Charles Heede39092017-09-18 09:19:28 +0100103 public DisableRecord(int userId, IBinder token) {
104 this.userId = userId;
105 this.token = token;
106 try {
107 token.linkToDeath(this, 0);
108 } catch (RemoteException re) {
109 // Give up
110 }
111 }
112
113 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114 public void binderDied() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800115 Slog.i(TAG, "binder died for pkg=" + pkg);
Benjamin Franzea2ec972015-03-16 17:18:09 +0000116 disableForUser(0, token, pkg, userId);
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100117 disable2ForUser(0, token, pkg, userId);
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -0700118 token.unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 }
Charles Heede39092017-09-18 09:19:28 +0100120
121 public void setFlags(int what, int which, String pkg) {
122 switch (which) {
123 case 1:
124 what1 = what;
125 return;
126 case 2:
127 what2 = what;
128 return;
129 default:
130 Slog.w(TAG, "Can't set unsupported disable flag " + which
131 + ": 0x" + Integer.toHexString(what));
132 }
133 this.pkg = pkg;
134 }
135
136 public int getFlags(int which) {
137 switch (which) {
138 case 1: return what1;
139 case 2: return what2;
140 default:
141 Slog.w(TAG, "Can't get unsupported disable flag " + which);
142 return 0;
143 }
144 }
145
146 public boolean isEmpty() {
147 return what1 == 0 && what2 == 0;
148 }
149
150 @Override
151 public String toString() {
152 return String.format("userId=%d what1=0x%08X what2=0x%08X pkg=%s token=%s",
153 userId, what1, what2, pkg, token);
154 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 }
156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 /**
158 * Construct the service, add the status bar view to the window manager
159 */
Jeff Brown2992ea72011-01-28 22:04:14 -0800160 public StatusBarManagerService(Context context, WindowManagerService windowManager) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 mContext = context;
Jeff Brown2992ea72011-01-28 22:04:14 -0800162 mWindowManager = windowManager;
Joe Onorato0cbda992010-05-02 16:28:15 -0700163
Adam Lesinski182f73f2013-12-05 16:48:06 -0800164 LocalServices.addService(StatusBarManagerInternal.class, mInternalService);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 }
166
Adam Lesinski182f73f2013-12-05 16:48:06 -0800167 /**
168 * Private API used by NotificationManagerService.
169 */
170 private final StatusBarManagerInternal mInternalService = new StatusBarManagerInternal() {
John Spurlockcb566aa2014-08-03 22:58:28 -0400171 private boolean mNotificationLightOn;
172
Adam Lesinski182f73f2013-12-05 16:48:06 -0800173 @Override
174 public void setNotificationDelegate(NotificationDelegate delegate) {
Christoph Studere71fefc2014-06-24 16:16:49 +0200175 mNotificationDelegate = delegate;
Adam Lesinski182f73f2013-12-05 16:48:06 -0800176 }
John Spurlockcb566aa2014-08-03 22:58:28 -0400177
John Spurlockcad57682014-07-26 17:09:56 -0400178 @Override
Andrii Kulian0f051f52016-04-14 00:41:51 -0700179 public void showScreenPinningRequest(int taskId) {
Jason Monk5565cb42014-09-12 10:59:21 -0400180 if (mBar != null) {
181 try {
Andrii Kulian0f051f52016-04-14 00:41:51 -0700182 mBar.showScreenPinningRequest(taskId);
Jason Monk5565cb42014-09-12 10:59:21 -0400183 } catch (RemoteException e) {
184 }
185 }
186 }
Adrian Roos4f43dc02015-06-17 16:43:38 -0700187
188 @Override
189 public void showAssistDisclosure() {
190 if (mBar != null) {
191 try {
192 mBar.showAssistDisclosure();
193 } catch (RemoteException e) {
194 }
195 }
196 }
Jorim Jaggi165ce062015-07-06 16:18:11 -0700197
198 @Override
199 public void startAssist(Bundle args) {
200 if (mBar != null) {
201 try {
202 mBar.startAssist(args);
203 } catch (RemoteException e) {
204 }
205 }
206 }
Selim Cinek372d1bd2015-08-14 13:19:37 -0700207
208 @Override
Jorim Jaggi40aa8812015-09-23 12:59:22 -0700209 public void onCameraLaunchGestureDetected(int source) {
Selim Cinek372d1bd2015-08-14 13:19:37 -0700210 if (mBar != null) {
211 try {
Jorim Jaggi40aa8812015-09-23 12:59:22 -0700212 mBar.onCameraLaunchGestureDetected(source);
Selim Cinek372d1bd2015-08-14 13:19:37 -0700213 } catch (RemoteException e) {
214 }
215 }
216 }
Jorim Jaggi86905582016-02-09 21:36:09 -0800217
218 @Override
219 public void topAppWindowChanged(boolean menuVisible) {
220 StatusBarManagerService.this.topAppWindowChanged(menuVisible);
221 }
222
223 @Override
224 public void setSystemUiVisibility(int vis, int fullscreenStackVis, int dockedStackVis,
225 int mask,
226 Rect fullscreenBounds, Rect dockedBounds, String cause) {
227 StatusBarManagerService.this.setSystemUiVisibility(vis, fullscreenStackVis,
228 dockedStackVis, mask, fullscreenBounds, dockedBounds, cause);
229 }
Phil Weaver315c34e2016-02-19 15:12:29 -0800230
231 @Override
232 public void toggleSplitScreen() {
233 enforceStatusBarService();
234 if (mBar != null) {
235 try {
236 mBar.toggleSplitScreen();
237 } catch (RemoteException ex) {}
238 }
239 }
Jorim Jaggi2adba072016-03-03 13:43:39 +0100240
241 public void appTransitionFinished() {
242 enforceStatusBarService();
243 if (mBar != null) {
244 try {
245 mBar.appTransitionFinished();
246 } catch (RemoteException ex) {}
247 }
248 }
Adrian Roosf2efdd82016-04-15 17:43:18 -0700249
250 @Override
251 public void toggleRecentApps() {
252 if (mBar != null) {
253 try {
254 mBar.toggleRecentApps();
255 } catch (RemoteException ex) {}
256 }
257 }
258
259 @Override
260 public void setCurrentUser(int newUserId) {
261 if (SPEW) Slog.d(TAG, "Setting current user to user " + newUserId);
262 mCurrentUserId = newUserId;
263 }
264
265
266 @Override
267 public void preloadRecentApps() {
268 if (mBar != null) {
269 try {
270 mBar.preloadRecentApps();
271 } catch (RemoteException ex) {}
272 }
273 }
274
275 @Override
276 public void cancelPreloadRecentApps() {
277 if (mBar != null) {
278 try {
279 mBar.cancelPreloadRecentApps();
280 } catch (RemoteException ex) {}
281 }
282 }
283
284 @Override
285 public void showRecentApps(boolean triggeredFromAltTab, boolean fromHome) {
286 if (mBar != null) {
287 try {
288 mBar.showRecentApps(triggeredFromAltTab, fromHome);
289 } catch (RemoteException ex) {}
290 }
291 }
292
293 @Override
294 public void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) {
295 if (mBar != null) {
296 try {
297 mBar.hideRecentApps(triggeredFromAltTab, triggeredFromHomeKey);
298 } catch (RemoteException ex) {}
299 }
300 }
301
302 @Override
Andrei Stingaceanu0bf096f2016-04-14 18:11:57 +0100303 public void dismissKeyboardShortcutsMenu() {
304 if (mBar != null) {
305 try {
306 mBar.dismissKeyboardShortcutsMenu();
307 } catch (RemoteException ex) {}
308 }
309 }
310
311 @Override
Adrian Roosf2efdd82016-04-15 17:43:18 -0700312 public void toggleKeyboardShortcutsMenu(int deviceId) {
313 if (mBar != null) {
314 try {
315 mBar.toggleKeyboardShortcutsMenu(deviceId);
316 } catch (RemoteException ex) {}
317 }
318 }
319
320 @Override
Winson Chungac52f282017-03-30 14:44:52 -0700321 public void showPictureInPictureMenu() {
Adrian Roosf2efdd82016-04-15 17:43:18 -0700322 if (mBar != null) {
323 try {
Winson Chungac52f282017-03-30 14:44:52 -0700324 mBar.showPictureInPictureMenu();
Adrian Roosf2efdd82016-04-15 17:43:18 -0700325 } catch (RemoteException ex) {}
326 }
327 }
328
329 @Override
330 public void setWindowState(int window, int state) {
331 if (mBar != null) {
332 try {
333 mBar.setWindowState(window, state);
334 } catch (RemoteException ex) {}
335 }
336 }
337
338 @Override
339 public void appTransitionPending() {
340 if (mBar != null) {
341 try {
342 mBar.appTransitionPending();
343 } catch (RemoteException ex) {}
344 }
345 }
346
347 @Override
348 public void appTransitionCancelled() {
349 if (mBar != null) {
350 try {
351 mBar.appTransitionCancelled();
352 } catch (RemoteException ex) {}
353 }
354 }
355
356 @Override
357 public void appTransitionStarting(long statusBarAnimationsStartTime,
358 long statusBarAnimationsDuration) {
359 if (mBar != null) {
360 try {
361 mBar.appTransitionStarting(
362 statusBarAnimationsStartTime, statusBarAnimationsDuration);
363 } catch (RemoteException ex) {}
364 }
365 }
Jason Monk361915c2017-03-21 20:33:59 -0400366
367 @Override
Charles He9851a8d2017-10-10 17:31:30 +0100368 public boolean isGlobalActionsDisabled() {
369 return (mDisabled2 & DISABLE2_GLOBAL_ACTIONS) != 0;
370 }
371
372 @Override
Jason Monk361915c2017-03-21 20:33:59 -0400373 public void setGlobalActionsListener(GlobalActionsListener listener) {
374 mGlobalActionListener = listener;
375 mGlobalActionListener.onStatusBarConnectedChanged(mBar != null);
376 }
377
378 @Override
379 public void showGlobalActions() {
380 if (mBar != null) {
381 try {
382 mBar.showGlobalActionsMenu();
383 } catch (RemoteException ex) {}
384 }
385 }
Jason Monkb4302182017-08-04 13:39:17 -0400386
387 @Override
Selim Cinek3a49ba22017-08-10 11:17:39 -0700388 public void setTopAppHidesStatusBar(boolean hidesStatusBar) {
389 if (mBar != null) {
390 try {
391 mBar.setTopAppHidesStatusBar(hidesStatusBar);
392 } catch (RemoteException ex) {}
393 }
394 }
395
396 @Override
Jason Monkb4302182017-08-04 13:39:17 -0400397 public boolean showShutdownUi(boolean isReboot, String reason) {
398 if (!mContext.getResources().getBoolean(R.bool.config_showSysuiShutdown)) {
399 return false;
400 }
401 if (mBar != null) {
402 try {
403 mBar.showShutdownUi(isReboot, reason);
404 return true;
405 } catch (RemoteException ex) {}
406 }
407 return false;
408 }
Mike Digman93f08342017-11-24 21:46:53 -0800409
410 @Override
411 public void onProposedRotationChanged(int rotation) {
412 if (mBar != null){
413 try {
414 mBar.onProposedRotationChanged(rotation);
415 } catch (RemoteException ex) {}
416 }
417 }
Adam Lesinski182f73f2013-12-05 16:48:06 -0800418 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419
420 // ================================================================================
Joe Onorato25f95f92010-04-08 18:37:10 -0500421 // From IStatusBarService
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 // ================================================================================
Adam Lesinski182f73f2013-12-05 16:48:06 -0800423 @Override
Daniel Sandler11cf1782012-09-27 14:03:08 -0400424 public void expandNotificationsPanel() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800425 enforceExpandStatusBar();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700426
427 if (mBar != null) {
428 try {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400429 mBar.animateExpandNotificationsPanel();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700430 } catch (RemoteException ex) {
431 }
432 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800433 }
434
Adam Lesinski182f73f2013-12-05 16:48:06 -0800435 @Override
Daniel Sandler11cf1782012-09-27 14:03:08 -0400436 public void collapsePanels() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437 enforceExpandStatusBar();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800438
Joe Onorato4762c2d2010-05-17 15:42:59 -0700439 if (mBar != null) {
440 try {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400441 mBar.animateCollapsePanels();
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700442 } catch (RemoteException ex) {
443 }
444 }
445 }
446
Adam Lesinski182f73f2013-12-05 16:48:06 -0800447 @Override
Anthony Chen9ad00e02017-05-12 15:53:36 -0700448 public void togglePanel() {
449 enforceExpandStatusBar();
450
451 if (mBar != null) {
452 try {
453 mBar.togglePanel();
454 } catch (RemoteException ex) {
455 }
456 }
457 }
458
459 @Override
Jason Monka9927322015-12-13 16:22:37 -0500460 public void expandSettingsPanel(String subPanel) {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700461 enforceExpandStatusBar();
462
463 if (mBar != null) {
464 try {
Jason Monka9927322015-12-13 16:22:37 -0500465 mBar.animateExpandSettingsPanel(subPanel);
Joe Onorato4762c2d2010-05-17 15:42:59 -0700466 } catch (RemoteException ex) {
467 }
468 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800469 }
470
Jason Monk7e53f202016-01-28 10:40:20 -0500471 public void addTile(ComponentName component) {
472 enforceStatusBarOrShell();
473
474 if (mBar != null) {
475 try {
476 mBar.addQsTile(component);
477 } catch (RemoteException ex) {
478 }
479 }
480 }
481
482 public void remTile(ComponentName component) {
483 enforceStatusBarOrShell();
484
485 if (mBar != null) {
486 try {
487 mBar.remQsTile(component);
488 } catch (RemoteException ex) {
489 }
490 }
491 }
492
493 public void clickTile(ComponentName component) {
494 enforceStatusBarOrShell();
495
496 if (mBar != null) {
497 try {
498 mBar.clickQsTile(component);
499 } catch (RemoteException ex) {
500 }
501 }
502 }
503
Adam Lesinski182f73f2013-12-05 16:48:06 -0800504 @Override
Philip Quinnc3a503d2017-07-18 23:23:41 -0700505 public void handleSystemKey(int key) throws RemoteException {
Jim Miller07e03842016-06-22 15:18:13 -0700506 enforceExpandStatusBar();
507
508 if (mBar != null) {
509 try {
Philip Quinnc3a503d2017-07-18 23:23:41 -0700510 mBar.handleSystemKey(key);
Jim Miller07e03842016-06-22 15:18:13 -0700511 } catch (RemoteException ex) {
512 }
513 }
514 }
515
516 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 public void disable(int what, IBinder token, String pkg) {
Benjamin Franzea2ec972015-03-16 17:18:09 +0000518 disableForUser(what, token, pkg, mCurrentUserId);
John Spurlock13451a22012-09-28 14:40:41 -0400519 }
520
Benjamin Franzea2ec972015-03-16 17:18:09 +0000521 @Override
522 public void disableForUser(int what, IBinder token, String pkg, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800523 enforceStatusBar();
Joe Onoratof3f0e052010-05-14 18:49:29 -0700524
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800525 synchronized (mLock) {
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100526 disableLocked(userId, what, token, pkg, 1);
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800527 }
528 }
529
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100530 /**
531 * Disable additional status bar features. Pass the bitwise-or of the DISABLE2_* flags.
532 * To re-enable everything, pass {@link #DISABLE_NONE}.
533 *
534 * Warning: Only pass DISABLE2_* flags into this function, do not use DISABLE_* flags.
535 */
536 @Override
537 public void disable2(int what, IBinder token, String pkg) {
Benjamin Franz292a0a92016-03-30 13:41:57 +0100538 disable2ForUser(what, token, pkg, mCurrentUserId);
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100539 }
540
541 /**
542 * Disable additional status bar features for a given user. Pass the bitwise-or of the
543 * DISABLE2_* flags. To re-enable everything, pass {@link #DISABLE_NONE}.
544 *
545 * Warning: Only pass DISABLE2_* flags into this function, do not use DISABLE_* flags.
546 */
547 @Override
548 public void disable2ForUser(int what, IBinder token, String pkg, int userId) {
Charles He2eda2422017-09-24 17:55:21 +0100549 enforceStatusBarService();
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100550
551 synchronized (mLock) {
552 disableLocked(userId, what, token, pkg, 2);
553 }
554 }
555
556 private void disableLocked(int userId, int what, IBinder token, String pkg, int whichFlag) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700557 // It's important that the the callback and the call to mBar get done
558 // in the same order when multiple threads are calling this function
559 // so they are paired correctly. The messages on the handler will be
560 // handled in the order they were enqueued, but will be outside the lock.
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100561 manageDisableListLocked(userId, what, token, pkg, whichFlag);
John Spurlock8f3e6d52012-11-29 13:56:24 -0500562
563 // Ensure state for the current user is applied, even if passed a non-current user.
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100564 final int net1 = gatherDisableActionsLocked(mCurrentUserId, 1);
565 final int net2 = gatherDisableActionsLocked(mCurrentUserId, 2);
566 if (net1 != mDisabled1 || net2 != mDisabled2) {
567 mDisabled1 = net1;
568 mDisabled2 = net2;
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800569 mHandler.post(new Runnable() {
570 public void run() {
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100571 mNotificationDelegate.onSetDisabled(net1);
Joe Onoratof3f0e052010-05-14 18:49:29 -0700572 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800573 });
574 if (mBar != null) {
575 try {
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100576 mBar.disable(net1, net2);
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800577 } catch (RemoteException ex) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700578 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800580 }
581 }
582
Adam Lesinski182f73f2013-12-05 16:48:06 -0800583 @Override
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700584 public void setIcon(String slot, String iconPackage, int iconId, int iconLevel,
585 String contentDescription) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700587
588 synchronized (mIcons) {
Xiaohui Chene4de5a02015-09-22 15:33:31 -0700589 StatusBarIcon icon = new StatusBarIcon(iconPackage, UserHandle.SYSTEM, iconId,
590 iconLevel, 0, contentDescription);
Joe Onorato66d7d012010-05-14 10:05:10 -0700591 //Slog.d(TAG, "setIcon slot=" + slot + " index=" + index + " icon=" + icon);
Jason Monk07473ce2016-01-05 14:59:19 -0500592 mIcons.put(slot, icon);
Joe Onorato0cbda992010-05-02 16:28:15 -0700593
Joe Onorato0cbda992010-05-02 16:28:15 -0700594 if (mBar != null) {
595 try {
Jason Monk07473ce2016-01-05 14:59:19 -0500596 mBar.setIcon(slot, icon);
Joe Onorato0cbda992010-05-02 16:28:15 -0700597 } catch (RemoteException ex) {
598 }
599 }
600 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800601 }
602
Adam Lesinski182f73f2013-12-05 16:48:06 -0800603 @Override
Jason Monk07473ce2016-01-05 14:59:19 -0500604 public void setIconVisibility(String slot, boolean visibility) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700606
Joe Onorato514ad6632010-05-13 18:49:00 -0700607 synchronized (mIcons) {
Jason Monk07473ce2016-01-05 14:59:19 -0500608 StatusBarIcon icon = mIcons.get(slot);
Joe Onorato514ad6632010-05-13 18:49:00 -0700609 if (icon == null) {
610 return;
611 }
Jason Monk07473ce2016-01-05 14:59:19 -0500612 if (icon.visible != visibility) {
613 icon.visible = visibility;
Joe Onorato514ad6632010-05-13 18:49:00 -0700614
Joe Onorato514ad6632010-05-13 18:49:00 -0700615 if (mBar != null) {
616 try {
Jason Monk07473ce2016-01-05 14:59:19 -0500617 mBar.setIcon(slot, icon);
Joe Onorato514ad6632010-05-13 18:49:00 -0700618 } catch (RemoteException ex) {
619 }
620 }
621 }
622 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700623 }
624
Adam Lesinski182f73f2013-12-05 16:48:06 -0800625 @Override
Joe Onorato0cbda992010-05-02 16:28:15 -0700626 public void removeIcon(String slot) {
627 enforceStatusBar();
628
629 synchronized (mIcons) {
Jason Monk07473ce2016-01-05 14:59:19 -0500630 mIcons.remove(slot);
Joe Onorato0cbda992010-05-02 16:28:15 -0700631
Joe Onorato0cbda992010-05-02 16:28:15 -0700632 if (mBar != null) {
633 try {
Jason Monk07473ce2016-01-05 14:59:19 -0500634 mBar.removeIcon(slot);
Joe Onorato0cbda992010-05-02 16:28:15 -0700635 } catch (RemoteException ex) {
636 }
637 }
638 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800639 }
640
Wale Ogunwale393b1c12014-10-18 16:22:01 -0700641 /**
Daniel Sandlere02d8082010-10-08 15:13:22 -0400642 * Hide or show the on-screen Menu key. Only call this from the window manager, typically in
Wale Ogunwale393b1c12014-10-18 16:22:01 -0700643 * response to a window with {@link android.view.WindowManager.LayoutParams#needsMenuKey} set
644 * to {@link android.view.WindowManager.LayoutParams#NEEDS_MENU_SET_TRUE}.
Daniel Sandlere02d8082010-10-08 15:13:22 -0400645 */
Jorim Jaggi86905582016-02-09 21:36:09 -0800646 private void topAppWindowChanged(final boolean menuVisible) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400647 enforceStatusBar();
648
Dianne Hackborn7d049322011-06-14 15:00:32 -0700649 if (SPEW) Slog.d(TAG, (menuVisible?"showing":"hiding") + " MENU key");
Daniel Sandlere02d8082010-10-08 15:13:22 -0400650
651 synchronized(mLock) {
Dianne Hackborn7d049322011-06-14 15:00:32 -0700652 mMenuVisible = menuVisible;
653 mHandler.post(new Runnable() {
Jorim Jaggi86905582016-02-09 21:36:09 -0800654 public void run() {
655 if (mBar != null) {
656 try {
657 mBar.topAppWindowChanged(menuVisible);
658 } catch (RemoteException ex) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400659 }
Dianne Hackborn7d049322011-06-14 15:00:32 -0700660 }
Jorim Jaggi86905582016-02-09 21:36:09 -0800661 }
662 });
Daniel Sandlere02d8082010-10-08 15:13:22 -0400663 }
664 }
665
Adam Lesinski182f73f2013-12-05 16:48:06 -0800666 @Override
Jason Monkb605fec2014-05-02 17:04:10 -0400667 public void setImeWindowStatus(final IBinder token, final int vis, final int backDisposition,
668 final boolean showImeSwitcher) {
satok06487a52010-10-29 11:37:18 +0900669 enforceStatusBar();
670
Joe Onorato857fd9b2011-01-27 15:08:35 -0800671 if (SPEW) {
672 Slog.d(TAG, "swetImeWindowStatus vis=" + vis + " backDisposition=" + backDisposition);
673 }
satok06487a52010-10-29 11:37:18 +0900674
675 synchronized(mLock) {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800676 // In case of IME change, we need to call up setImeWindowStatus() regardless of
677 // mImeWindowVis because mImeWindowVis may not have been set to false when the
satok06e07442010-11-02 19:46:55 +0900678 // previous IME was destroyed.
Joe Onorato857fd9b2011-01-27 15:08:35 -0800679 mImeWindowVis = vis;
680 mImeBackDisposition = backDisposition;
681 mImeToken = token;
Jason Monkb605fec2014-05-02 17:04:10 -0400682 mShowImeSwitcher = showImeSwitcher;
satok06e07442010-11-02 19:46:55 +0900683 mHandler.post(new Runnable() {
684 public void run() {
685 if (mBar != null) {
686 try {
Jason Monkb605fec2014-05-02 17:04:10 -0400687 mBar.setImeWindowStatus(token, vis, backDisposition, showImeSwitcher);
satok06e07442010-11-02 19:46:55 +0900688 } catch (RemoteException ex) {
satok06487a52010-10-29 11:37:18 +0900689 }
690 }
satok06e07442010-11-02 19:46:55 +0900691 }
692 });
satok06487a52010-10-29 11:37:18 +0900693 }
694 }
695
Adam Lesinski182f73f2013-12-05 16:48:06 -0800696 @Override
Adrian Roos53f28ec2014-10-29 17:26:12 +0100697 public void setSystemUiVisibility(int vis, int mask, String cause) {
Jorim Jaggi86905582016-02-09 21:36:09 -0800698 setSystemUiVisibility(vis, 0, 0, mask, mFullscreenStackBounds, mDockedStackBounds, cause);
699 }
700
701 private void setSystemUiVisibility(int vis, int fullscreenStackVis, int dockedStackVis, int mask,
702 Rect fullscreenBounds, Rect dockedBounds, String cause) {
Joe Onorato55bf3802011-01-25 13:42:10 -0800703 // also allows calls from window manager which is in this process.
Joe Onoratof63b0f42010-09-12 17:03:19 -0400704 enforceStatusBarService();
705
Jeff Sharkey4519a022011-09-07 23:24:53 -0700706 if (SPEW) Slog.d(TAG, "setSystemUiVisibility(0x" + Integer.toHexString(vis) + ")");
Daniel Sandler60ee2562011-07-22 12:34:33 -0400707
Joe Onoratof63b0f42010-09-12 17:03:19 -0400708 synchronized (mLock) {
Jorim Jaggi86905582016-02-09 21:36:09 -0800709 updateUiVisibilityLocked(vis, fullscreenStackVis, dockedStackVis, mask,
710 fullscreenBounds, dockedBounds);
John Spurlock13451a22012-09-28 14:40:41 -0400711 disableLocked(
712 mCurrentUserId,
713 vis & StatusBarManager.DISABLE_MASK,
714 mSysUiVisToken,
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100715 cause, 1);
Joe Onoratof63b0f42010-09-12 17:03:19 -0400716 }
717 }
718
Jorim Jaggi86905582016-02-09 21:36:09 -0800719 private void updateUiVisibilityLocked(final int vis,
720 final int fullscreenStackVis, final int dockedStackVis, final int mask,
721 final Rect fullscreenBounds, final Rect dockedBounds) {
722 if (mSystemUiVisibility != vis
723 || mFullscreenStackSysUiVisibility != fullscreenStackVis
724 || mDockedStackSysUiVisibility != dockedStackVis
725 || !mFullscreenStackBounds.equals(fullscreenBounds)
726 || !mDockedStackBounds.equals(dockedBounds)) {
Daniel Sandler60ee2562011-07-22 12:34:33 -0400727 mSystemUiVisibility = vis;
Jorim Jaggi86905582016-02-09 21:36:09 -0800728 mFullscreenStackSysUiVisibility = fullscreenStackVis;
729 mDockedStackSysUiVisibility = dockedStackVis;
730 mFullscreenStackBounds.set(fullscreenBounds);
731 mDockedStackBounds.set(dockedBounds);
Joe Onoratof63b0f42010-09-12 17:03:19 -0400732 mHandler.post(new Runnable() {
733 public void run() {
734 if (mBar != null) {
735 try {
Jorim Jaggi86905582016-02-09 21:36:09 -0800736 mBar.setSystemUiVisibility(vis, fullscreenStackVis, dockedStackVis,
737 mask, fullscreenBounds, dockedBounds);
Joe Onoratof63b0f42010-09-12 17:03:19 -0400738 } catch (RemoteException ex) {
Joe Onorato93056472010-09-10 10:30:46 -0400739 }
740 }
Joe Onoratof63b0f42010-09-12 17:03:19 -0400741 }
742 });
Joe Onorato93056472010-09-10 10:30:46 -0400743 }
744 }
745
Jason Monk7e53f202016-01-28 10:40:20 -0500746 private void enforceStatusBarOrShell() {
747 if (Binder.getCallingUid() == Process.SHELL_UID) {
748 return;
749 }
750 enforceStatusBar();
751 }
752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800753 private void enforceStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700754 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700755 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800756 }
757
758 private void enforceExpandStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700759 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.EXPAND_STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700760 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 }
762
Joe Onorato8bc6c512010-06-04 16:21:12 -0400763 private void enforceStatusBarService() {
764 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
765 "StatusBarManagerService");
766 }
767
Joe Onorato4762c2d2010-05-17 15:42:59 -0700768 // ================================================================================
769 // Callbacks from the status bar service.
770 // ================================================================================
Adam Lesinski182f73f2013-12-05 16:48:06 -0800771 @Override
Jason Monk07473ce2016-01-05 14:59:19 -0500772 public void registerStatusBar(IStatusBar bar, List<String> iconSlots,
Jorim Jaggi86905582016-02-09 21:36:09 -0800773 List<StatusBarIcon> iconList, int switches[], List<IBinder> binders,
774 Rect fullscreenStackBounds, Rect dockedStackBounds) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400775 enforceStatusBarService();
776
Joe Onorato0cbda992010-05-02 16:28:15 -0700777 Slog.i(TAG, "registerStatusBar bar=" + bar);
778 mBar = bar;
Jason Monk361915c2017-03-21 20:33:59 -0400779 try {
780 mBar.asBinder().linkToDeath(new DeathRecipient() {
781 @Override
782 public void binderDied() {
783 mBar = null;
784 notifyBarAttachChanged();
785 }
786 }, 0);
787 } catch (RemoteException e) {
788 }
789 notifyBarAttachChanged();
Joe Onorato75199e32010-05-29 17:22:51 -0400790 synchronized (mIcons) {
Jason Monk07473ce2016-01-05 14:59:19 -0500791 for (String slot : mIcons.keySet()) {
792 iconSlots.add(slot);
793 iconList.add(mIcons.get(slot));
794 }
Joe Onorato75199e32010-05-29 17:22:51 -0400795 }
Joe Onorato93056472010-09-10 10:30:46 -0400796 synchronized (mLock) {
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100797 switches[0] = gatherDisableActionsLocked(mCurrentUserId, 1);
Daniel Sandler60ee2562011-07-22 12:34:33 -0400798 switches[1] = mSystemUiVisibility;
Joe Onoratoe4c7b3f2010-10-30 12:15:03 -0700799 switches[2] = mMenuVisible ? 1 : 0;
Joe Onorato857fd9b2011-01-27 15:08:35 -0800800 switches[3] = mImeWindowVis;
801 switches[4] = mImeBackDisposition;
Michael Wright665366a2014-08-07 15:44:40 -0700802 switches[5] = mShowImeSwitcher ? 1 : 0;
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100803 switches[6] = gatherDisableActionsLocked(mCurrentUserId, 2);
Jorim Jaggi86905582016-02-09 21:36:09 -0800804 switches[7] = mFullscreenStackSysUiVisibility;
805 switches[8] = mDockedStackSysUiVisibility;
Joe Onorato857fd9b2011-01-27 15:08:35 -0800806 binders.add(mImeToken);
Jorim Jaggi86905582016-02-09 21:36:09 -0800807 fullscreenStackBounds.set(mFullscreenStackBounds);
808 dockedStackBounds.set(mDockedStackBounds);
Joe Onorato93056472010-09-10 10:30:46 -0400809 }
Joe Onorato2314aab2010-04-08 16:41:23 -0500810 }
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400811
Jason Monk361915c2017-03-21 20:33:59 -0400812 private void notifyBarAttachChanged() {
813 mHandler.post(() -> {
814 if (mGlobalActionListener == null) return;
815 mGlobalActionListener.onStatusBarConnectedChanged(mBar != null);
816 });
817 }
818
Joe Onorato4762c2d2010-05-17 15:42:59 -0700819 /**
Christoph Studer1f32c652014-11-26 15:32:20 +0100820 * @param clearNotificationEffects whether to consider notifications as "shown" and stop
821 * LED, vibration, and ringing
Joe Onorato4762c2d2010-05-17 15:42:59 -0700822 */
Adam Lesinski182f73f2013-12-05 16:48:06 -0800823 @Override
Chris Wrenb659c4f2015-06-25 17:12:27 -0400824 public void onPanelRevealed(boolean clearNotificationEffects, int numItems) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400825 enforceStatusBarService();
Adam Lesinski182f73f2013-12-05 16:48:06 -0800826 long identity = Binder.clearCallingIdentity();
827 try {
Chris Wrenb659c4f2015-06-25 17:12:27 -0400828 mNotificationDelegate.onPanelRevealed(clearNotificationEffects, numItems);
Christoph Studer1f32c652014-11-26 15:32:20 +0100829 } finally {
830 Binder.restoreCallingIdentity(identity);
831 }
832 }
833
834 @Override
835 public void clearNotificationEffects() throws RemoteException {
836 enforceStatusBarService();
837 long identity = Binder.clearCallingIdentity();
838 try {
839 mNotificationDelegate.clearEffects();
Adam Lesinski182f73f2013-12-05 16:48:06 -0800840 } finally {
841 Binder.restoreCallingIdentity(identity);
842 }
Joe Onorato4762c2d2010-05-17 15:42:59 -0700843 }
844
Adam Lesinski182f73f2013-12-05 16:48:06 -0800845 @Override
Christoph Studer760ea552014-03-21 13:10:21 +0100846 public void onPanelHidden() throws RemoteException {
847 enforceStatusBarService();
848 long identity = Binder.clearCallingIdentity();
849 try {
850 mNotificationDelegate.onPanelHidden();
851 } finally {
852 Binder.restoreCallingIdentity(identity);
853 }
854 }
855
Jason Monk361915c2017-03-21 20:33:59 -0400856 /**
857 * Allows the status bar to shutdown the device.
858 */
859 @Override
860 public void shutdown() {
861 enforceStatusBarService();
862 long identity = Binder.clearCallingIdentity();
863 try {
Michael Wright6cd10262017-04-04 17:44:56 +0100864 // ShutdownThread displays UI, so give it a UI context.
Jason Monk361915c2017-03-21 20:33:59 -0400865 mHandler.post(() ->
Michael Wright6cd10262017-04-04 17:44:56 +0100866 ShutdownThread.shutdown(getUiContext(),
867 PowerManager.SHUTDOWN_USER_REQUESTED, false));
Jason Monk361915c2017-03-21 20:33:59 -0400868 } finally {
869 Binder.restoreCallingIdentity(identity);
870 }
871 }
872
873 /**
874 * Allows the status bar to reboot the device.
875 */
876 @Override
877 public void reboot(boolean safeMode) {
878 enforceStatusBarService();
879 long identity = Binder.clearCallingIdentity();
880 try {
881 mHandler.post(() -> {
Adam Lesinskia82b6262017-03-21 16:56:17 -0700882 // ShutdownThread displays UI, so give it a UI context.
Jason Monk361915c2017-03-21 20:33:59 -0400883 if (safeMode) {
Shunta Satobdb0e492017-04-14 16:01:54 +0900884 ShutdownThread.rebootSafeMode(getUiContext(), true);
Jason Monk361915c2017-03-21 20:33:59 -0400885 } else {
Michael Wright6cd10262017-04-04 17:44:56 +0100886 ShutdownThread.reboot(getUiContext(),
887 PowerManager.SHUTDOWN_USER_REQUESTED, false);
Jason Monk361915c2017-03-21 20:33:59 -0400888 }
889 });
890 } finally {
891 Binder.restoreCallingIdentity(identity);
892 }
893 }
894
895 @Override
896 public void onGlobalActionsShown() {
897 enforceStatusBarService();
898 long identity = Binder.clearCallingIdentity();
899 try {
900 if (mGlobalActionListener == null) return;
901 mGlobalActionListener.onGlobalActionsShown();
902 } finally {
903 Binder.restoreCallingIdentity(identity);
904 }
905 }
906
907 @Override
908 public void onGlobalActionsHidden() {
909 enforceStatusBarService();
910 long identity = Binder.clearCallingIdentity();
911 try {
912 if (mGlobalActionListener == null) return;
913 mGlobalActionListener.onGlobalActionsDismissed();
914 } finally {
915 Binder.restoreCallingIdentity(identity);
916 }
917 }
918
Christoph Studer760ea552014-03-21 13:10:21 +0100919 @Override
Christoph Studer03b87a22014-04-30 17:33:27 +0200920 public void onNotificationClick(String key) {
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 {
Christoph Studer03b87a22014-04-30 17:33:27 +0200926 mNotificationDelegate.onNotificationClick(callingUid, callingPid, key);
Adam Lesinski182f73f2013-12-05 16:48:06 -0800927 } finally {
928 Binder.restoreCallingIdentity(identity);
929 }
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400930 }
931
Adam Lesinski182f73f2013-12-05 16:48:06 -0800932 @Override
Christoph Studer4da84cd2014-10-21 17:24:20 +0200933 public void onNotificationActionClick(String key, int actionIndex) {
934 enforceStatusBarService();
935 final int callingUid = Binder.getCallingUid();
936 final int callingPid = Binder.getCallingPid();
937 long identity = Binder.clearCallingIdentity();
938 try {
939 mNotificationDelegate.onNotificationActionClick(callingUid, callingPid, key,
940 actionIndex);
941 } finally {
942 Binder.restoreCallingIdentity(identity);
943 }
944 }
945
946 @Override
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700947 public void onNotificationError(String pkg, String tag, int id,
Kenny Guy3a7c4a52014-03-03 18:24:03 +0000948 int uid, int initialPid, String message, int userId) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400949 enforceStatusBarService();
John Spurlocke6a7d932014-03-13 12:29:00 -0400950 final int callingUid = Binder.getCallingUid();
951 final int callingPid = Binder.getCallingPid();
Adam Lesinski182f73f2013-12-05 16:48:06 -0800952 long identity = Binder.clearCallingIdentity();
953 try {
954 // WARNING: this will call back into us to do the remove. Don't hold any locks.
John Spurlocke6a7d932014-03-13 12:29:00 -0400955 mNotificationDelegate.onNotificationError(callingUid, callingPid,
956 pkg, tag, id, uid, initialPid, message, userId);
Adam Lesinski182f73f2013-12-05 16:48:06 -0800957 } finally {
958 Binder.restoreCallingIdentity(identity);
959 }
Joe Onorato005847b2010-06-04 16:08:02 -0400960 }
961
Adam Lesinski182f73f2013-12-05 16:48:06 -0800962 @Override
Julia Reynolds503ed942017-10-04 16:04:56 -0400963 public void onNotificationClear(String pkg, String tag, int id, int userId, String key,
964 @NotificationStats.DismissalSurface int dismissalSurface) {
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400965 enforceStatusBarService();
John Spurlocke6a7d932014-03-13 12:29:00 -0400966 final int callingUid = Binder.getCallingUid();
967 final int callingPid = Binder.getCallingPid();
Adam Lesinski182f73f2013-12-05 16:48:06 -0800968 long identity = Binder.clearCallingIdentity();
969 try {
Julia Reynolds503ed942017-10-04 16:04:56 -0400970 mNotificationDelegate.onNotificationClear(
971 callingUid, callingPid, pkg, tag, id, userId, key, dismissalSurface);
Adam Lesinski182f73f2013-12-05 16:48:06 -0800972 } finally {
973 Binder.restoreCallingIdentity(identity);
974 }
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400975 }
976
Adam Lesinski182f73f2013-12-05 16:48:06 -0800977 @Override
Christoph Studer92b389d2014-04-01 18:44:40 +0200978 public void onNotificationVisibilityChanged(
Chris Wrend1dbc922015-06-19 17:51:16 -0400979 NotificationVisibility[] newlyVisibleKeys, NotificationVisibility[] noLongerVisibleKeys)
980 throws RemoteException {
Christoph Studer92b389d2014-04-01 18:44:40 +0200981 enforceStatusBarService();
982 long identity = Binder.clearCallingIdentity();
983 try {
984 mNotificationDelegate.onNotificationVisibilityChanged(
985 newlyVisibleKeys, noLongerVisibleKeys);
986 } finally {
987 Binder.restoreCallingIdentity(identity);
988 }
989 }
990
991 @Override
Chris Wren78403d72014-07-28 10:23:24 +0100992 public void onNotificationExpansionChanged(String key, boolean userAction,
993 boolean expanded) throws RemoteException {
994 enforceStatusBarService();
995 long identity = Binder.clearCallingIdentity();
996 try {
997 mNotificationDelegate.onNotificationExpansionChanged(
998 key, userAction, expanded);
999 } finally {
1000 Binder.restoreCallingIdentity(identity);
1001 }
1002 }
1003
1004 @Override
Julia Reynolds503ed942017-10-04 16:04:56 -04001005 public void onNotificationDirectReplied(String key) throws RemoteException {
1006 enforceStatusBarService();
1007 long identity = Binder.clearCallingIdentity();
1008 try {
1009 mNotificationDelegate.onNotificationDirectReplied(key);
1010 } finally {
1011 Binder.restoreCallingIdentity(identity);
1012 }
1013 }
1014
1015 @Override
1016 public void onNotificationSettingsViewed(String key) throws RemoteException {
1017 enforceStatusBarService();
1018 long identity = Binder.clearCallingIdentity();
1019 try {
1020 mNotificationDelegate.onNotificationSettingsViewed(key);
1021 } finally {
1022 Binder.restoreCallingIdentity(identity);
1023 }
1024 }
1025
1026 @Override
Kenny Guy3a7c4a52014-03-03 18:24:03 +00001027 public void onClearAllNotifications(int userId) {
Joe Onorato8bc6c512010-06-04 16:21:12 -04001028 enforceStatusBarService();
John Spurlocke6a7d932014-03-13 12:29:00 -04001029 final int callingUid = Binder.getCallingUid();
1030 final int callingPid = Binder.getCallingPid();
Adam Lesinski182f73f2013-12-05 16:48:06 -08001031 long identity = Binder.clearCallingIdentity();
1032 try {
John Spurlocke6a7d932014-03-13 12:29:00 -04001033 mNotificationDelegate.onClearAll(callingUid, callingPid, userId);
Adam Lesinski182f73f2013-12-05 16:48:06 -08001034 } finally {
1035 Binder.restoreCallingIdentity(identity);
Joe Onorato18e69df2010-05-17 22:26:12 -07001036 }
Joe Onorato0cbda992010-05-02 16:28:15 -07001037 }
1038
Jason Monk7e53f202016-01-28 10:40:20 -05001039 @Override
1040 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
Dianne Hackborn354736e2016-08-22 17:00:05 -07001041 String[] args, ShellCallback callback, ResultReceiver resultReceiver) {
Jason Monk7e53f202016-01-28 10:40:20 -05001042 (new StatusBarShellCommand(this)).exec(
Dianne Hackborn354736e2016-08-22 17:00:05 -07001043 this, in, out, err, args, callback, resultReceiver);
Jason Monk7e53f202016-01-28 10:40:20 -05001044 }
1045
Jason Monkf8c2f7b2017-09-06 09:22:29 -04001046 public String[] getStatusBarIcons() {
1047 return mContext.getResources().getStringArray(R.array.config_statusBarIcons);
1048 }
1049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001050 // ================================================================================
1051 // Can be called from any thread
1052 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001053
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001054 // lock on mDisableRecords
Benjamin Franzcde0a2a2015-04-23 17:19:48 +01001055 void manageDisableListLocked(int userId, int what, IBinder token, String pkg, int which) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001056 if (SPEW) {
John Spurlock13451a22012-09-28 14:40:41 -04001057 Slog.d(TAG, "manageDisableList userId=" + userId
1058 + " what=0x" + Integer.toHexString(what) + " pkg=" + pkg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001059 }
Charles Heede39092017-09-18 09:19:28 +01001060
1061 // Find matching record, if any
Joe Onorato7bb8eeb2011-01-27 16:00:58 -08001062 final int N = mDisableRecords.size();
Charles Heede39092017-09-18 09:19:28 +01001063 DisableRecord record = null;
Joe Onorato7bb8eeb2011-01-27 16:00:58 -08001064 int i;
Charles Heede39092017-09-18 09:19:28 +01001065 for (i = 0; i < N; i++) {
1066 DisableRecord r = mDisableRecords.get(i);
1067 if (r.token == token && r.userId == userId) {
1068 record = r;
Joe Onorato7bb8eeb2011-01-27 16:00:58 -08001069 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001070 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -08001071 }
Charles Heede39092017-09-18 09:19:28 +01001072
1073 // Remove record if binder is already dead
1074 if (!token.isBinderAlive()) {
1075 if (record != null) {
Joe Onorato7bb8eeb2011-01-27 16:00:58 -08001076 mDisableRecords.remove(i);
Charles Heede39092017-09-18 09:19:28 +01001077 record.token.unlinkToDeath(record, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 }
Charles Heede39092017-09-18 09:19:28 +01001079 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001080 }
Charles Heede39092017-09-18 09:19:28 +01001081
1082 // Update existing record
1083 if (record != null) {
1084 record.setFlags(what, which, pkg);
1085 if (record.isEmpty()) {
1086 mDisableRecords.remove(i);
1087 record.token.unlinkToDeath(record, 0);
1088 }
1089 return;
1090 }
1091
1092 // Record doesn't exist, so we create a new one
1093 record = new DisableRecord(userId, token);
1094 record.setFlags(what, which, pkg);
1095 mDisableRecords.add(record);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001096 }
1097
1098 // lock on mDisableRecords
Benjamin Franzcde0a2a2015-04-23 17:19:48 +01001099 int gatherDisableActionsLocked(int userId, int which) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001100 final int N = mDisableRecords.size();
1101 // gather the new net flags
1102 int net = 0;
1103 for (int i=0; i<N; i++) {
John Spurlock13451a22012-09-28 14:40:41 -04001104 final DisableRecord rec = mDisableRecords.get(i);
1105 if (rec.userId == userId) {
Charles Heede39092017-09-18 09:19:28 +01001106 net |= rec.getFlags(which);
John Spurlock13451a22012-09-28 14:40:41 -04001107 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001108 }
1109 return net;
1110 }
1111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001112 // ================================================================================
1113 // Always called from UI thread
1114 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001116 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001117 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Joe Onorato0cbda992010-05-02 16:28:15 -07001118
Joe Onorato7bb8eeb2011-01-27 16:00:58 -08001119 synchronized (mLock) {
Benjamin Franzcde0a2a2015-04-23 17:19:48 +01001120 pw.println(" mDisabled1=0x" + Integer.toHexString(mDisabled1));
1121 pw.println(" mDisabled2=0x" + Integer.toHexString(mDisabled2));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001122 final int N = mDisableRecords.size();
John Spurlock13451a22012-09-28 14:40:41 -04001123 pw.println(" mDisableRecords.size=" + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001124 for (int i=0; i<N; i++) {
1125 DisableRecord tok = mDisableRecords.get(i);
Charles Heede39092017-09-18 09:19:28 +01001126 pw.println(" [" + i + "] " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001127 }
Adrian Roos2a629102016-04-15 16:28:03 -07001128 pw.println(" mCurrentUserId=" + mCurrentUserId);
Dan Sandlerf3a1f2c2016-06-26 15:59:13 -04001129 pw.println(" mIcons=");
1130 for (String slot : mIcons.keySet()) {
1131 pw.println(" ");
1132 pw.print(slot);
1133 pw.print(" -> ");
1134 final StatusBarIcon icon = mIcons.get(slot);
1135 pw.print(icon);
1136 if (!TextUtils.isEmpty(icon.contentDescription)) {
1137 pw.print(" \"");
1138 pw.print(icon.contentDescription);
1139 pw.print("\"");
1140 }
1141 pw.println();
1142 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001143 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001144 }
Michael Wright6cd10262017-04-04 17:44:56 +01001145
1146 private static final Context getUiContext() {
1147 return ActivityThread.currentActivityThread().getSystemUiContext();
1148 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001149}