blob: 738b0ca4a74f24092ce556c191112d8888e3e600 [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;
Vishwath Mohanecf00ce2018-04-05 10:28:24 -070026import android.hardware.biometrics.IBiometricPromptReceiver;
Adam Lesinski182f73f2013-12-05 16:48:06 -080027import android.os.Binder;
Jorim Jaggi165ce062015-07-06 16:18:11 -070028import android.os.Bundle;
Adam Lesinski182f73f2013-12-05 16:48:06 -080029import android.os.Handler;
30import android.os.IBinder;
Jason Monk361915c2017-03-21 20:33:59 -040031import android.os.PowerManager;
Jason Monk7e53f202016-01-28 10:40:20 -050032import android.os.Process;
Adam Lesinski182f73f2013-12-05 16:48:06 -080033import android.os.RemoteException;
Jason Monk7e53f202016-01-28 10:40:20 -050034import android.os.ResultReceiver;
Dianne Hackborn354736e2016-08-22 17:00:05 -070035import android.os.ShellCallback;
Adam Lesinski182f73f2013-12-05 16:48:06 -080036import android.os.UserHandle;
Julia Reynolds503ed942017-10-04 16:04:56 -040037import android.service.notification.NotificationStats;
Dan Sandlerf3a1f2c2016-06-26 15:59:13 -040038import android.text.TextUtils;
Jason Monk07473ce2016-01-05 14:59:19 -050039import android.util.ArrayMap;
Joe Onorato8a9b2202010-02-26 18:56:32 -080040import android.util.Slog;
Jim Miller07e03842016-06-22 15:18:13 -070041
Jason Monkb4302182017-08-04 13:39:17 -040042import com.android.internal.R;
Joe Onorato0cbda992010-05-02 16:28:15 -070043import com.android.internal.statusbar.IStatusBar;
44import com.android.internal.statusbar.IStatusBarService;
Chris Wrend1dbc922015-06-19 17:51:16 -040045import com.android.internal.statusbar.NotificationVisibility;
Joe Onorato0cbda992010-05-02 16:28:15 -070046import com.android.internal.statusbar.StatusBarIcon;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060047import com.android.internal.util.DumpUtils;
Adam Lesinski182f73f2013-12-05 16:48:06 -080048import com.android.server.LocalServices;
49import com.android.server.notification.NotificationDelegate;
Michael Kwan2decbf72018-02-22 07:40:11 -080050import com.android.server.policy.GlobalActionsProvider;
Jason Monk361915c2017-03-21 20:33:59 -040051import com.android.server.power.ShutdownThread;
Dianne Hackborna924dc0d2011-02-17 14:22:17 -080052import com.android.server.wm.WindowManagerService;
The Android Open Source Project10592532009-03-18 17:39:46 -070053
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import java.io.FileDescriptor;
55import java.io.PrintWriter;
56import java.util.ArrayList;
Joe Onorato75199e32010-05-29 17:22:51 -040057import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059/**
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>();
Michael Kwan2decbf72018-02-22 07:40:11 -080077 private GlobalActionsProvider.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);
Michael Kwan2decbf72018-02-22 07:40:11 -0800165 LocalServices.addService(GlobalActionsProvider.class, mGlobalActionsProvider);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 }
167
Adam Lesinski182f73f2013-12-05 16:48:06 -0800168 /**
169 * Private API used by NotificationManagerService.
170 */
171 private final StatusBarManagerInternal mInternalService = new StatusBarManagerInternal() {
John Spurlockcb566aa2014-08-03 22:58:28 -0400172 private boolean mNotificationLightOn;
173
Adam Lesinski182f73f2013-12-05 16:48:06 -0800174 @Override
175 public void setNotificationDelegate(NotificationDelegate delegate) {
Christoph Studere71fefc2014-06-24 16:16:49 +0200176 mNotificationDelegate = delegate;
Adam Lesinski182f73f2013-12-05 16:48:06 -0800177 }
John Spurlockcb566aa2014-08-03 22:58:28 -0400178
John Spurlockcad57682014-07-26 17:09:56 -0400179 @Override
Andrii Kulian0f051f52016-04-14 00:41:51 -0700180 public void showScreenPinningRequest(int taskId) {
Jason Monk5565cb42014-09-12 10:59:21 -0400181 if (mBar != null) {
182 try {
Andrii Kulian0f051f52016-04-14 00:41:51 -0700183 mBar.showScreenPinningRequest(taskId);
Jason Monk5565cb42014-09-12 10:59:21 -0400184 } catch (RemoteException e) {
185 }
186 }
187 }
Adrian Roos4f43dc02015-06-17 16:43:38 -0700188
189 @Override
190 public void showAssistDisclosure() {
191 if (mBar != null) {
192 try {
193 mBar.showAssistDisclosure();
194 } catch (RemoteException e) {
195 }
196 }
197 }
Jorim Jaggi165ce062015-07-06 16:18:11 -0700198
199 @Override
200 public void startAssist(Bundle args) {
201 if (mBar != null) {
202 try {
203 mBar.startAssist(args);
204 } catch (RemoteException e) {
205 }
206 }
207 }
Selim Cinek372d1bd2015-08-14 13:19:37 -0700208
209 @Override
Jorim Jaggi40aa8812015-09-23 12:59:22 -0700210 public void onCameraLaunchGestureDetected(int source) {
Selim Cinek372d1bd2015-08-14 13:19:37 -0700211 if (mBar != null) {
212 try {
Jorim Jaggi40aa8812015-09-23 12:59:22 -0700213 mBar.onCameraLaunchGestureDetected(source);
Selim Cinek372d1bd2015-08-14 13:19:37 -0700214 } catch (RemoteException e) {
215 }
216 }
217 }
Jorim Jaggi86905582016-02-09 21:36:09 -0800218
219 @Override
220 public void topAppWindowChanged(boolean menuVisible) {
221 StatusBarManagerService.this.topAppWindowChanged(menuVisible);
222 }
223
224 @Override
225 public void setSystemUiVisibility(int vis, int fullscreenStackVis, int dockedStackVis,
226 int mask,
227 Rect fullscreenBounds, Rect dockedBounds, String cause) {
228 StatusBarManagerService.this.setSystemUiVisibility(vis, fullscreenStackVis,
229 dockedStackVis, mask, fullscreenBounds, dockedBounds, cause);
230 }
Phil Weaver315c34e2016-02-19 15:12:29 -0800231
232 @Override
233 public void toggleSplitScreen() {
234 enforceStatusBarService();
235 if (mBar != null) {
236 try {
237 mBar.toggleSplitScreen();
238 } catch (RemoteException ex) {}
239 }
240 }
Jorim Jaggi2adba072016-03-03 13:43:39 +0100241
242 public void appTransitionFinished() {
243 enforceStatusBarService();
244 if (mBar != null) {
245 try {
246 mBar.appTransitionFinished();
247 } catch (RemoteException ex) {}
248 }
249 }
Adrian Roosf2efdd82016-04-15 17:43:18 -0700250
251 @Override
252 public void toggleRecentApps() {
253 if (mBar != null) {
254 try {
255 mBar.toggleRecentApps();
256 } catch (RemoteException ex) {}
257 }
258 }
259
260 @Override
261 public void setCurrentUser(int newUserId) {
262 if (SPEW) Slog.d(TAG, "Setting current user to user " + newUserId);
263 mCurrentUserId = newUserId;
264 }
265
266
267 @Override
268 public void preloadRecentApps() {
269 if (mBar != null) {
270 try {
271 mBar.preloadRecentApps();
272 } catch (RemoteException ex) {}
273 }
274 }
275
276 @Override
277 public void cancelPreloadRecentApps() {
278 if (mBar != null) {
279 try {
280 mBar.cancelPreloadRecentApps();
281 } catch (RemoteException ex) {}
282 }
283 }
284
285 @Override
Winson Chungdff7a732017-12-11 12:17:06 -0800286 public void showRecentApps(boolean triggeredFromAltTab) {
Adrian Roosf2efdd82016-04-15 17:43:18 -0700287 if (mBar != null) {
288 try {
Winson Chungdff7a732017-12-11 12:17:06 -0800289 mBar.showRecentApps(triggeredFromAltTab);
Adrian Roosf2efdd82016-04-15 17:43:18 -0700290 } catch (RemoteException ex) {}
291 }
292 }
293
294 @Override
295 public void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) {
296 if (mBar != null) {
297 try {
298 mBar.hideRecentApps(triggeredFromAltTab, triggeredFromHomeKey);
299 } catch (RemoteException ex) {}
300 }
301 }
302
303 @Override
Andrei Stingaceanu0bf096f2016-04-14 18:11:57 +0100304 public void dismissKeyboardShortcutsMenu() {
305 if (mBar != null) {
306 try {
307 mBar.dismissKeyboardShortcutsMenu();
308 } catch (RemoteException ex) {}
309 }
310 }
311
312 @Override
Adrian Roosf2efdd82016-04-15 17:43:18 -0700313 public void toggleKeyboardShortcutsMenu(int deviceId) {
314 if (mBar != null) {
315 try {
316 mBar.toggleKeyboardShortcutsMenu(deviceId);
317 } catch (RemoteException ex) {}
318 }
319 }
320
321 @Override
Beverlyae79ab92017-12-11 09:20:02 -0500322 public void showChargingAnimation(int batteryLevel) {
323 if (mBar != null) {
324 try {
Beverlyac32c9a2018-01-31 16:10:41 -0500325 mBar.showWirelessChargingAnimation(batteryLevel);
Beverlyae79ab92017-12-11 09:20:02 -0500326 } catch (RemoteException ex){
327 }
328 }
329 }
330
331 @Override
Winson Chungac52f282017-03-30 14:44:52 -0700332 public void showPictureInPictureMenu() {
Adrian Roosf2efdd82016-04-15 17:43:18 -0700333 if (mBar != null) {
334 try {
Winson Chungac52f282017-03-30 14:44:52 -0700335 mBar.showPictureInPictureMenu();
Adrian Roosf2efdd82016-04-15 17:43:18 -0700336 } catch (RemoteException ex) {}
337 }
338 }
339
340 @Override
341 public void setWindowState(int window, int state) {
342 if (mBar != null) {
343 try {
344 mBar.setWindowState(window, state);
345 } catch (RemoteException ex) {}
346 }
347 }
348
349 @Override
350 public void appTransitionPending() {
351 if (mBar != null) {
352 try {
353 mBar.appTransitionPending();
354 } catch (RemoteException ex) {}
355 }
356 }
357
358 @Override
359 public void appTransitionCancelled() {
360 if (mBar != null) {
361 try {
362 mBar.appTransitionCancelled();
363 } catch (RemoteException ex) {}
364 }
365 }
366
367 @Override
368 public void appTransitionStarting(long statusBarAnimationsStartTime,
369 long statusBarAnimationsDuration) {
370 if (mBar != null) {
371 try {
372 mBar.appTransitionStarting(
373 statusBarAnimationsStartTime, statusBarAnimationsDuration);
374 } catch (RemoteException ex) {}
375 }
376 }
Jason Monk361915c2017-03-21 20:33:59 -0400377
378 @Override
Selim Cinek3a49ba22017-08-10 11:17:39 -0700379 public void setTopAppHidesStatusBar(boolean hidesStatusBar) {
380 if (mBar != null) {
381 try {
382 mBar.setTopAppHidesStatusBar(hidesStatusBar);
383 } catch (RemoteException ex) {}
384 }
385 }
386
387 @Override
Jason Monkb4302182017-08-04 13:39:17 -0400388 public boolean showShutdownUi(boolean isReboot, String reason) {
389 if (!mContext.getResources().getBoolean(R.bool.config_showSysuiShutdown)) {
390 return false;
391 }
392 if (mBar != null) {
393 try {
394 mBar.showShutdownUi(isReboot, reason);
395 return true;
396 } catch (RemoteException ex) {}
397 }
398 return false;
399 }
Mike Digman93f08342017-11-24 21:46:53 -0800400
401 @Override
Mike Digmane0777312018-01-19 12:41:51 -0800402 public void onProposedRotationChanged(int rotation, boolean isValid) {
Mike Digman93f08342017-11-24 21:46:53 -0800403 if (mBar != null){
404 try {
Mike Digmane0777312018-01-19 12:41:51 -0800405 mBar.onProposedRotationChanged(rotation, isValid);
Mike Digman93f08342017-11-24 21:46:53 -0800406 } catch (RemoteException ex) {}
407 }
408 }
Adam Lesinski182f73f2013-12-05 16:48:06 -0800409 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800410
Michael Kwan2decbf72018-02-22 07:40:11 -0800411 private final GlobalActionsProvider mGlobalActionsProvider = new GlobalActionsProvider() {
412 @Override
413 public boolean isGlobalActionsDisabled() {
414 return (mDisabled2 & DISABLE2_GLOBAL_ACTIONS) != 0;
415 }
416
417 @Override
418 public void setGlobalActionsListener(GlobalActionsProvider.GlobalActionsListener listener) {
419 mGlobalActionListener = listener;
420 mGlobalActionListener.onGlobalActionsAvailableChanged(mBar != null);
421 }
422
423 @Override
424 public void showGlobalActions() {
425 if (mBar != null) {
426 try {
427 mBar.showGlobalActionsMenu();
428 } catch (RemoteException ex) {}
429 }
430 }
431 };
432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800433 // ================================================================================
Joe Onorato25f95f92010-04-08 18:37:10 -0500434 // From IStatusBarService
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 // ================================================================================
Adam Lesinski182f73f2013-12-05 16:48:06 -0800436 @Override
Daniel Sandler11cf1782012-09-27 14:03:08 -0400437 public void expandNotificationsPanel() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800438 enforceExpandStatusBar();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700439
440 if (mBar != null) {
441 try {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400442 mBar.animateExpandNotificationsPanel();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700443 } catch (RemoteException ex) {
444 }
445 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800446 }
447
Adam Lesinski182f73f2013-12-05 16:48:06 -0800448 @Override
Daniel Sandler11cf1782012-09-27 14:03:08 -0400449 public void collapsePanels() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800450 enforceExpandStatusBar();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451
Joe Onorato4762c2d2010-05-17 15:42:59 -0700452 if (mBar != null) {
453 try {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400454 mBar.animateCollapsePanels();
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700455 } catch (RemoteException ex) {
456 }
457 }
458 }
459
Adam Lesinski182f73f2013-12-05 16:48:06 -0800460 @Override
Anthony Chen9ad00e02017-05-12 15:53:36 -0700461 public void togglePanel() {
462 enforceExpandStatusBar();
463
464 if (mBar != null) {
465 try {
466 mBar.togglePanel();
467 } catch (RemoteException ex) {
468 }
469 }
470 }
471
472 @Override
Jason Monka9927322015-12-13 16:22:37 -0500473 public void expandSettingsPanel(String subPanel) {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700474 enforceExpandStatusBar();
475
476 if (mBar != null) {
477 try {
Jason Monka9927322015-12-13 16:22:37 -0500478 mBar.animateExpandSettingsPanel(subPanel);
Joe Onorato4762c2d2010-05-17 15:42:59 -0700479 } catch (RemoteException ex) {
480 }
481 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800482 }
483
Jason Monk7e53f202016-01-28 10:40:20 -0500484 public void addTile(ComponentName component) {
485 enforceStatusBarOrShell();
486
487 if (mBar != null) {
488 try {
489 mBar.addQsTile(component);
490 } catch (RemoteException ex) {
491 }
492 }
493 }
494
495 public void remTile(ComponentName component) {
496 enforceStatusBarOrShell();
497
498 if (mBar != null) {
499 try {
500 mBar.remQsTile(component);
501 } catch (RemoteException ex) {
502 }
503 }
504 }
505
506 public void clickTile(ComponentName component) {
507 enforceStatusBarOrShell();
508
509 if (mBar != null) {
510 try {
511 mBar.clickQsTile(component);
512 } catch (RemoteException ex) {
513 }
514 }
515 }
516
Adam Lesinski182f73f2013-12-05 16:48:06 -0800517 @Override
Philip Quinnc3a503d2017-07-18 23:23:41 -0700518 public void handleSystemKey(int key) throws RemoteException {
Jim Miller07e03842016-06-22 15:18:13 -0700519 enforceExpandStatusBar();
520
521 if (mBar != null) {
522 try {
Philip Quinnc3a503d2017-07-18 23:23:41 -0700523 mBar.handleSystemKey(key);
Jim Miller07e03842016-06-22 15:18:13 -0700524 } catch (RemoteException ex) {
525 }
526 }
527 }
528
529 @Override
Matthew Ng9c3bce52018-02-01 22:00:31 +0000530 public void showPinningEnterExitToast(boolean entering) throws RemoteException {
531 if (mBar != null) {
532 try {
533 mBar.showPinningEnterExitToast(entering);
534 } catch (RemoteException ex) {
535 }
536 }
537 }
538
539 @Override
540 public void showPinningEscapeToast() throws RemoteException {
541 if (mBar != null) {
542 try {
543 mBar.showPinningEscapeToast();
544 } catch (RemoteException ex) {
545 }
546 }
547 }
548
549 @Override
Vishwath Mohanecf00ce2018-04-05 10:28:24 -0700550 public void showFingerprintDialog(Bundle bundle, IBiometricPromptReceiver receiver) {
Kevin Chynaae4a152018-01-18 11:48:09 -0800551 if (mBar != null) {
552 try {
553 mBar.showFingerprintDialog(bundle, receiver);
554 } catch (RemoteException ex) {
555 }
556 }
557 }
558
559 @Override
560 public void onFingerprintAuthenticated() {
561 if (mBar != null) {
562 try {
563 mBar.onFingerprintAuthenticated();
564 } catch (RemoteException ex) {
565 }
566 }
567 }
568
569 @Override
570 public void onFingerprintHelp(String message) {
571 if (mBar != null) {
572 try {
573 mBar.onFingerprintHelp(message);
574 } catch (RemoteException ex) {
575 }
576 }
577 }
578
579 @Override
580 public void onFingerprintError(String error) {
581 if (mBar != null) {
582 try {
583 mBar.onFingerprintError(error);
584 } catch (RemoteException ex) {
585 }
586 }
587 }
588
589 @Override
590 public void hideFingerprintDialog() {
591 if (mBar != null) {
592 try {
593 mBar.hideFingerprintDialog();
594 } catch (RemoteException ex) {
595 }
596 }
597 }
598
599 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800600 public void disable(int what, IBinder token, String pkg) {
Benjamin Franzea2ec972015-03-16 17:18:09 +0000601 disableForUser(what, token, pkg, mCurrentUserId);
John Spurlock13451a22012-09-28 14:40:41 -0400602 }
603
Benjamin Franzea2ec972015-03-16 17:18:09 +0000604 @Override
605 public void disableForUser(int what, IBinder token, String pkg, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800606 enforceStatusBar();
Joe Onoratof3f0e052010-05-14 18:49:29 -0700607
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800608 synchronized (mLock) {
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100609 disableLocked(userId, what, token, pkg, 1);
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800610 }
611 }
612
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100613 /**
614 * Disable additional status bar features. Pass the bitwise-or of the DISABLE2_* flags.
615 * To re-enable everything, pass {@link #DISABLE_NONE}.
616 *
617 * Warning: Only pass DISABLE2_* flags into this function, do not use DISABLE_* flags.
618 */
619 @Override
620 public void disable2(int what, IBinder token, String pkg) {
Benjamin Franz292a0a92016-03-30 13:41:57 +0100621 disable2ForUser(what, token, pkg, mCurrentUserId);
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100622 }
623
624 /**
625 * Disable additional status bar features for a given user. Pass the bitwise-or of the
626 * DISABLE2_* flags. To re-enable everything, pass {@link #DISABLE_NONE}.
627 *
628 * Warning: Only pass DISABLE2_* flags into this function, do not use DISABLE_* flags.
629 */
630 @Override
631 public void disable2ForUser(int what, IBinder token, String pkg, int userId) {
Mike Digmandd2f49e2018-03-16 10:54:22 -0700632 enforceStatusBar();
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100633
634 synchronized (mLock) {
635 disableLocked(userId, what, token, pkg, 2);
636 }
637 }
638
639 private void disableLocked(int userId, int what, IBinder token, String pkg, int whichFlag) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700640 // It's important that the the callback and the call to mBar get done
641 // in the same order when multiple threads are calling this function
642 // so they are paired correctly. The messages on the handler will be
643 // handled in the order they were enqueued, but will be outside the lock.
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100644 manageDisableListLocked(userId, what, token, pkg, whichFlag);
John Spurlock8f3e6d52012-11-29 13:56:24 -0500645
646 // Ensure state for the current user is applied, even if passed a non-current user.
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100647 final int net1 = gatherDisableActionsLocked(mCurrentUserId, 1);
648 final int net2 = gatherDisableActionsLocked(mCurrentUserId, 2);
649 if (net1 != mDisabled1 || net2 != mDisabled2) {
650 mDisabled1 = net1;
651 mDisabled2 = net2;
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800652 mHandler.post(new Runnable() {
653 public void run() {
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100654 mNotificationDelegate.onSetDisabled(net1);
Joe Onoratof3f0e052010-05-14 18:49:29 -0700655 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800656 });
657 if (mBar != null) {
658 try {
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100659 mBar.disable(net1, net2);
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800660 } catch (RemoteException ex) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700661 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800663 }
664 }
665
Adam Lesinski182f73f2013-12-05 16:48:06 -0800666 @Override
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700667 public void setIcon(String slot, String iconPackage, int iconId, int iconLevel,
668 String contentDescription) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800669 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700670
671 synchronized (mIcons) {
Xiaohui Chene4de5a02015-09-22 15:33:31 -0700672 StatusBarIcon icon = new StatusBarIcon(iconPackage, UserHandle.SYSTEM, iconId,
673 iconLevel, 0, contentDescription);
Joe Onorato66d7d012010-05-14 10:05:10 -0700674 //Slog.d(TAG, "setIcon slot=" + slot + " index=" + index + " icon=" + icon);
Jason Monk07473ce2016-01-05 14:59:19 -0500675 mIcons.put(slot, icon);
Joe Onorato0cbda992010-05-02 16:28:15 -0700676
Joe Onorato0cbda992010-05-02 16:28:15 -0700677 if (mBar != null) {
678 try {
Jason Monk07473ce2016-01-05 14:59:19 -0500679 mBar.setIcon(slot, icon);
Joe Onorato0cbda992010-05-02 16:28:15 -0700680 } catch (RemoteException ex) {
681 }
682 }
683 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684 }
685
Adam Lesinski182f73f2013-12-05 16:48:06 -0800686 @Override
Jason Monk07473ce2016-01-05 14:59:19 -0500687 public void setIconVisibility(String slot, boolean visibility) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800688 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700689
Joe Onorato514ad6632010-05-13 18:49:00 -0700690 synchronized (mIcons) {
Jason Monk07473ce2016-01-05 14:59:19 -0500691 StatusBarIcon icon = mIcons.get(slot);
Joe Onorato514ad6632010-05-13 18:49:00 -0700692 if (icon == null) {
693 return;
694 }
Jason Monk07473ce2016-01-05 14:59:19 -0500695 if (icon.visible != visibility) {
696 icon.visible = visibility;
Joe Onorato514ad6632010-05-13 18:49:00 -0700697
Joe Onorato514ad6632010-05-13 18:49:00 -0700698 if (mBar != null) {
699 try {
Jason Monk07473ce2016-01-05 14:59:19 -0500700 mBar.setIcon(slot, icon);
Joe Onorato514ad6632010-05-13 18:49:00 -0700701 } catch (RemoteException ex) {
702 }
703 }
704 }
705 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700706 }
707
Adam Lesinski182f73f2013-12-05 16:48:06 -0800708 @Override
Joe Onorato0cbda992010-05-02 16:28:15 -0700709 public void removeIcon(String slot) {
710 enforceStatusBar();
711
712 synchronized (mIcons) {
Jason Monk07473ce2016-01-05 14:59:19 -0500713 mIcons.remove(slot);
Joe Onorato0cbda992010-05-02 16:28:15 -0700714
Joe Onorato0cbda992010-05-02 16:28:15 -0700715 if (mBar != null) {
716 try {
Jason Monk07473ce2016-01-05 14:59:19 -0500717 mBar.removeIcon(slot);
Joe Onorato0cbda992010-05-02 16:28:15 -0700718 } catch (RemoteException ex) {
719 }
720 }
721 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722 }
723
Wale Ogunwale393b1c12014-10-18 16:22:01 -0700724 /**
Daniel Sandlere02d8082010-10-08 15:13:22 -0400725 * Hide or show the on-screen Menu key. Only call this from the window manager, typically in
Wale Ogunwale393b1c12014-10-18 16:22:01 -0700726 * response to a window with {@link android.view.WindowManager.LayoutParams#needsMenuKey} set
727 * to {@link android.view.WindowManager.LayoutParams#NEEDS_MENU_SET_TRUE}.
Daniel Sandlere02d8082010-10-08 15:13:22 -0400728 */
Jorim Jaggi86905582016-02-09 21:36:09 -0800729 private void topAppWindowChanged(final boolean menuVisible) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400730 enforceStatusBar();
731
Dianne Hackborn7d049322011-06-14 15:00:32 -0700732 if (SPEW) Slog.d(TAG, (menuVisible?"showing":"hiding") + " MENU key");
Daniel Sandlere02d8082010-10-08 15:13:22 -0400733
734 synchronized(mLock) {
Dianne Hackborn7d049322011-06-14 15:00:32 -0700735 mMenuVisible = menuVisible;
736 mHandler.post(new Runnable() {
Jorim Jaggi86905582016-02-09 21:36:09 -0800737 public void run() {
738 if (mBar != null) {
739 try {
740 mBar.topAppWindowChanged(menuVisible);
741 } catch (RemoteException ex) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400742 }
Dianne Hackborn7d049322011-06-14 15:00:32 -0700743 }
Jorim Jaggi86905582016-02-09 21:36:09 -0800744 }
745 });
Daniel Sandlere02d8082010-10-08 15:13:22 -0400746 }
747 }
748
Adam Lesinski182f73f2013-12-05 16:48:06 -0800749 @Override
Jason Monkb605fec2014-05-02 17:04:10 -0400750 public void setImeWindowStatus(final IBinder token, final int vis, final int backDisposition,
751 final boolean showImeSwitcher) {
satok06487a52010-10-29 11:37:18 +0900752 enforceStatusBar();
753
Joe Onorato857fd9b2011-01-27 15:08:35 -0800754 if (SPEW) {
755 Slog.d(TAG, "swetImeWindowStatus vis=" + vis + " backDisposition=" + backDisposition);
756 }
satok06487a52010-10-29 11:37:18 +0900757
758 synchronized(mLock) {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800759 // In case of IME change, we need to call up setImeWindowStatus() regardless of
760 // mImeWindowVis because mImeWindowVis may not have been set to false when the
satok06e07442010-11-02 19:46:55 +0900761 // previous IME was destroyed.
Joe Onorato857fd9b2011-01-27 15:08:35 -0800762 mImeWindowVis = vis;
763 mImeBackDisposition = backDisposition;
764 mImeToken = token;
Jason Monkb605fec2014-05-02 17:04:10 -0400765 mShowImeSwitcher = showImeSwitcher;
satok06e07442010-11-02 19:46:55 +0900766 mHandler.post(new Runnable() {
767 public void run() {
768 if (mBar != null) {
769 try {
Jason Monkb605fec2014-05-02 17:04:10 -0400770 mBar.setImeWindowStatus(token, vis, backDisposition, showImeSwitcher);
satok06e07442010-11-02 19:46:55 +0900771 } catch (RemoteException ex) {
satok06487a52010-10-29 11:37:18 +0900772 }
773 }
satok06e07442010-11-02 19:46:55 +0900774 }
775 });
satok06487a52010-10-29 11:37:18 +0900776 }
777 }
778
Adam Lesinski182f73f2013-12-05 16:48:06 -0800779 @Override
Adrian Roos53f28ec2014-10-29 17:26:12 +0100780 public void setSystemUiVisibility(int vis, int mask, String cause) {
Jorim Jaggi86905582016-02-09 21:36:09 -0800781 setSystemUiVisibility(vis, 0, 0, mask, mFullscreenStackBounds, mDockedStackBounds, cause);
782 }
783
784 private void setSystemUiVisibility(int vis, int fullscreenStackVis, int dockedStackVis, int mask,
785 Rect fullscreenBounds, Rect dockedBounds, String cause) {
Joe Onorato55bf3802011-01-25 13:42:10 -0800786 // also allows calls from window manager which is in this process.
Joe Onoratof63b0f42010-09-12 17:03:19 -0400787 enforceStatusBarService();
788
Jeff Sharkey4519a022011-09-07 23:24:53 -0700789 if (SPEW) Slog.d(TAG, "setSystemUiVisibility(0x" + Integer.toHexString(vis) + ")");
Daniel Sandler60ee2562011-07-22 12:34:33 -0400790
Joe Onoratof63b0f42010-09-12 17:03:19 -0400791 synchronized (mLock) {
Jorim Jaggi86905582016-02-09 21:36:09 -0800792 updateUiVisibilityLocked(vis, fullscreenStackVis, dockedStackVis, mask,
793 fullscreenBounds, dockedBounds);
John Spurlock13451a22012-09-28 14:40:41 -0400794 disableLocked(
795 mCurrentUserId,
796 vis & StatusBarManager.DISABLE_MASK,
797 mSysUiVisToken,
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100798 cause, 1);
Joe Onoratof63b0f42010-09-12 17:03:19 -0400799 }
800 }
801
Jorim Jaggi86905582016-02-09 21:36:09 -0800802 private void updateUiVisibilityLocked(final int vis,
803 final int fullscreenStackVis, final int dockedStackVis, final int mask,
804 final Rect fullscreenBounds, final Rect dockedBounds) {
805 if (mSystemUiVisibility != vis
806 || mFullscreenStackSysUiVisibility != fullscreenStackVis
807 || mDockedStackSysUiVisibility != dockedStackVis
808 || !mFullscreenStackBounds.equals(fullscreenBounds)
809 || !mDockedStackBounds.equals(dockedBounds)) {
Daniel Sandler60ee2562011-07-22 12:34:33 -0400810 mSystemUiVisibility = vis;
Jorim Jaggi86905582016-02-09 21:36:09 -0800811 mFullscreenStackSysUiVisibility = fullscreenStackVis;
812 mDockedStackSysUiVisibility = dockedStackVis;
813 mFullscreenStackBounds.set(fullscreenBounds);
814 mDockedStackBounds.set(dockedBounds);
Joe Onoratof63b0f42010-09-12 17:03:19 -0400815 mHandler.post(new Runnable() {
816 public void run() {
817 if (mBar != null) {
818 try {
Jorim Jaggi86905582016-02-09 21:36:09 -0800819 mBar.setSystemUiVisibility(vis, fullscreenStackVis, dockedStackVis,
820 mask, fullscreenBounds, dockedBounds);
Joe Onoratof63b0f42010-09-12 17:03:19 -0400821 } catch (RemoteException ex) {
Joe Onorato93056472010-09-10 10:30:46 -0400822 }
823 }
Joe Onoratof63b0f42010-09-12 17:03:19 -0400824 }
825 });
Joe Onorato93056472010-09-10 10:30:46 -0400826 }
827 }
828
Jason Monk7e53f202016-01-28 10:40:20 -0500829 private void enforceStatusBarOrShell() {
830 if (Binder.getCallingUid() == Process.SHELL_UID) {
831 return;
832 }
833 enforceStatusBar();
834 }
835
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800836 private void enforceStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700837 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700838 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800839 }
840
841 private void enforceExpandStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700842 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.EXPAND_STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700843 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800844 }
845
Joe Onorato8bc6c512010-06-04 16:21:12 -0400846 private void enforceStatusBarService() {
847 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
848 "StatusBarManagerService");
849 }
850
Joe Onorato4762c2d2010-05-17 15:42:59 -0700851 // ================================================================================
852 // Callbacks from the status bar service.
853 // ================================================================================
Adam Lesinski182f73f2013-12-05 16:48:06 -0800854 @Override
Jason Monk07473ce2016-01-05 14:59:19 -0500855 public void registerStatusBar(IStatusBar bar, List<String> iconSlots,
Jorim Jaggi86905582016-02-09 21:36:09 -0800856 List<StatusBarIcon> iconList, int switches[], List<IBinder> binders,
857 Rect fullscreenStackBounds, Rect dockedStackBounds) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400858 enforceStatusBarService();
859
Joe Onorato0cbda992010-05-02 16:28:15 -0700860 Slog.i(TAG, "registerStatusBar bar=" + bar);
861 mBar = bar;
Jason Monk361915c2017-03-21 20:33:59 -0400862 try {
863 mBar.asBinder().linkToDeath(new DeathRecipient() {
864 @Override
865 public void binderDied() {
866 mBar = null;
867 notifyBarAttachChanged();
868 }
869 }, 0);
870 } catch (RemoteException e) {
871 }
872 notifyBarAttachChanged();
Joe Onorato75199e32010-05-29 17:22:51 -0400873 synchronized (mIcons) {
Jason Monk07473ce2016-01-05 14:59:19 -0500874 for (String slot : mIcons.keySet()) {
875 iconSlots.add(slot);
876 iconList.add(mIcons.get(slot));
877 }
Joe Onorato75199e32010-05-29 17:22:51 -0400878 }
Joe Onorato93056472010-09-10 10:30:46 -0400879 synchronized (mLock) {
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100880 switches[0] = gatherDisableActionsLocked(mCurrentUserId, 1);
Daniel Sandler60ee2562011-07-22 12:34:33 -0400881 switches[1] = mSystemUiVisibility;
Joe Onoratoe4c7b3f2010-10-30 12:15:03 -0700882 switches[2] = mMenuVisible ? 1 : 0;
Joe Onorato857fd9b2011-01-27 15:08:35 -0800883 switches[3] = mImeWindowVis;
884 switches[4] = mImeBackDisposition;
Michael Wright665366a2014-08-07 15:44:40 -0700885 switches[5] = mShowImeSwitcher ? 1 : 0;
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100886 switches[6] = gatherDisableActionsLocked(mCurrentUserId, 2);
Jorim Jaggi86905582016-02-09 21:36:09 -0800887 switches[7] = mFullscreenStackSysUiVisibility;
888 switches[8] = mDockedStackSysUiVisibility;
Joe Onorato857fd9b2011-01-27 15:08:35 -0800889 binders.add(mImeToken);
Jorim Jaggi86905582016-02-09 21:36:09 -0800890 fullscreenStackBounds.set(mFullscreenStackBounds);
891 dockedStackBounds.set(mDockedStackBounds);
Joe Onorato93056472010-09-10 10:30:46 -0400892 }
Joe Onorato2314aab2010-04-08 16:41:23 -0500893 }
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400894
Jason Monk361915c2017-03-21 20:33:59 -0400895 private void notifyBarAttachChanged() {
896 mHandler.post(() -> {
897 if (mGlobalActionListener == null) return;
Michael Kwan2decbf72018-02-22 07:40:11 -0800898 mGlobalActionListener.onGlobalActionsAvailableChanged(mBar != null);
Jason Monk361915c2017-03-21 20:33:59 -0400899 });
900 }
901
Joe Onorato4762c2d2010-05-17 15:42:59 -0700902 /**
Christoph Studer1f32c652014-11-26 15:32:20 +0100903 * @param clearNotificationEffects whether to consider notifications as "shown" and stop
904 * LED, vibration, and ringing
Joe Onorato4762c2d2010-05-17 15:42:59 -0700905 */
Adam Lesinski182f73f2013-12-05 16:48:06 -0800906 @Override
Chris Wrenb659c4f2015-06-25 17:12:27 -0400907 public void onPanelRevealed(boolean clearNotificationEffects, int numItems) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400908 enforceStatusBarService();
Adam Lesinski182f73f2013-12-05 16:48:06 -0800909 long identity = Binder.clearCallingIdentity();
910 try {
Chris Wrenb659c4f2015-06-25 17:12:27 -0400911 mNotificationDelegate.onPanelRevealed(clearNotificationEffects, numItems);
Christoph Studer1f32c652014-11-26 15:32:20 +0100912 } finally {
913 Binder.restoreCallingIdentity(identity);
914 }
915 }
916
917 @Override
918 public void clearNotificationEffects() throws RemoteException {
919 enforceStatusBarService();
920 long identity = Binder.clearCallingIdentity();
921 try {
922 mNotificationDelegate.clearEffects();
Adam Lesinski182f73f2013-12-05 16:48:06 -0800923 } finally {
924 Binder.restoreCallingIdentity(identity);
925 }
Joe Onorato4762c2d2010-05-17 15:42:59 -0700926 }
927
Adam Lesinski182f73f2013-12-05 16:48:06 -0800928 @Override
Christoph Studer760ea552014-03-21 13:10:21 +0100929 public void onPanelHidden() throws RemoteException {
930 enforceStatusBarService();
931 long identity = Binder.clearCallingIdentity();
932 try {
933 mNotificationDelegate.onPanelHidden();
934 } finally {
935 Binder.restoreCallingIdentity(identity);
936 }
937 }
938
Jason Monk361915c2017-03-21 20:33:59 -0400939 /**
940 * Allows the status bar to shutdown the device.
941 */
942 @Override
943 public void shutdown() {
944 enforceStatusBarService();
945 long identity = Binder.clearCallingIdentity();
946 try {
Michael Wright6cd10262017-04-04 17:44:56 +0100947 // ShutdownThread displays UI, so give it a UI context.
Jason Monk361915c2017-03-21 20:33:59 -0400948 mHandler.post(() ->
Michael Wright6cd10262017-04-04 17:44:56 +0100949 ShutdownThread.shutdown(getUiContext(),
950 PowerManager.SHUTDOWN_USER_REQUESTED, false));
Jason Monk361915c2017-03-21 20:33:59 -0400951 } finally {
952 Binder.restoreCallingIdentity(identity);
953 }
954 }
955
956 /**
957 * Allows the status bar to reboot the device.
958 */
959 @Override
960 public void reboot(boolean safeMode) {
961 enforceStatusBarService();
962 long identity = Binder.clearCallingIdentity();
963 try {
964 mHandler.post(() -> {
Adam Lesinskia82b6262017-03-21 16:56:17 -0700965 // ShutdownThread displays UI, so give it a UI context.
Jason Monk361915c2017-03-21 20:33:59 -0400966 if (safeMode) {
Shunta Satobdb0e492017-04-14 16:01:54 +0900967 ShutdownThread.rebootSafeMode(getUiContext(), true);
Jason Monk361915c2017-03-21 20:33:59 -0400968 } else {
Michael Wright6cd10262017-04-04 17:44:56 +0100969 ShutdownThread.reboot(getUiContext(),
970 PowerManager.SHUTDOWN_USER_REQUESTED, false);
Jason Monk361915c2017-03-21 20:33:59 -0400971 }
972 });
973 } finally {
974 Binder.restoreCallingIdentity(identity);
975 }
976 }
977
978 @Override
979 public void onGlobalActionsShown() {
980 enforceStatusBarService();
981 long identity = Binder.clearCallingIdentity();
982 try {
983 if (mGlobalActionListener == null) return;
984 mGlobalActionListener.onGlobalActionsShown();
985 } finally {
986 Binder.restoreCallingIdentity(identity);
987 }
988 }
989
990 @Override
991 public void onGlobalActionsHidden() {
992 enforceStatusBarService();
993 long identity = Binder.clearCallingIdentity();
994 try {
995 if (mGlobalActionListener == null) return;
996 mGlobalActionListener.onGlobalActionsDismissed();
997 } finally {
998 Binder.restoreCallingIdentity(identity);
999 }
1000 }
1001
Christoph Studer760ea552014-03-21 13:10:21 +01001002 @Override
Dieter Hsud39f0d52018-04-14 02:08:30 +08001003 public void onNotificationClick(String key, NotificationVisibility nv) {
Joe Onorato8bc6c512010-06-04 16:21:12 -04001004 enforceStatusBarService();
John Spurlocke6a7d932014-03-13 12:29:00 -04001005 final int callingUid = Binder.getCallingUid();
1006 final int callingPid = Binder.getCallingPid();
Adam Lesinski182f73f2013-12-05 16:48:06 -08001007 long identity = Binder.clearCallingIdentity();
1008 try {
Dieter Hsud39f0d52018-04-14 02:08:30 +08001009 mNotificationDelegate.onNotificationClick(callingUid, callingPid, key, nv);
Adam Lesinski182f73f2013-12-05 16:48:06 -08001010 } finally {
1011 Binder.restoreCallingIdentity(identity);
1012 }
Joe Onoratoaaba60b2010-05-23 15:18:41 -04001013 }
1014
Adam Lesinski182f73f2013-12-05 16:48:06 -08001015 @Override
Dieter Hsud39f0d52018-04-14 02:08:30 +08001016 public void onNotificationActionClick(String key, int actionIndex, NotificationVisibility nv) {
Christoph Studer4da84cd2014-10-21 17:24:20 +02001017 enforceStatusBarService();
1018 final int callingUid = Binder.getCallingUid();
1019 final int callingPid = Binder.getCallingPid();
1020 long identity = Binder.clearCallingIdentity();
1021 try {
1022 mNotificationDelegate.onNotificationActionClick(callingUid, callingPid, key,
Dieter Hsud39f0d52018-04-14 02:08:30 +08001023 actionIndex, nv);
Christoph Studer4da84cd2014-10-21 17:24:20 +02001024 } finally {
1025 Binder.restoreCallingIdentity(identity);
1026 }
1027 }
1028
1029 @Override
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -07001030 public void onNotificationError(String pkg, String tag, int id,
Kenny Guy3a7c4a52014-03-03 18:24:03 +00001031 int uid, int initialPid, String message, int userId) {
Joe Onorato8bc6c512010-06-04 16:21:12 -04001032 enforceStatusBarService();
John Spurlocke6a7d932014-03-13 12:29:00 -04001033 final int callingUid = Binder.getCallingUid();
1034 final int callingPid = Binder.getCallingPid();
Adam Lesinski182f73f2013-12-05 16:48:06 -08001035 long identity = Binder.clearCallingIdentity();
1036 try {
1037 // WARNING: this will call back into us to do the remove. Don't hold any locks.
John Spurlocke6a7d932014-03-13 12:29:00 -04001038 mNotificationDelegate.onNotificationError(callingUid, callingPid,
1039 pkg, tag, id, uid, initialPid, message, userId);
Adam Lesinski182f73f2013-12-05 16:48:06 -08001040 } finally {
1041 Binder.restoreCallingIdentity(identity);
1042 }
Joe Onorato005847b2010-06-04 16:08:02 -04001043 }
1044
Adam Lesinski182f73f2013-12-05 16:48:06 -08001045 @Override
Julia Reynolds503ed942017-10-04 16:04:56 -04001046 public void onNotificationClear(String pkg, String tag, int id, int userId, String key,
Dieter Hsud39f0d52018-04-14 02:08:30 +08001047 @NotificationStats.DismissalSurface int dismissalSurface, NotificationVisibility nv) {
Daniel Sandler0f0b11c2010-08-04 15:54:58 -04001048 enforceStatusBarService();
John Spurlocke6a7d932014-03-13 12:29:00 -04001049 final int callingUid = Binder.getCallingUid();
1050 final int callingPid = Binder.getCallingPid();
Adam Lesinski182f73f2013-12-05 16:48:06 -08001051 long identity = Binder.clearCallingIdentity();
1052 try {
Dieter Hsud39f0d52018-04-14 02:08:30 +08001053 mNotificationDelegate.onNotificationClear(callingUid, callingPid, pkg, tag, id, userId,
1054 key, dismissalSurface, nv);
Adam Lesinski182f73f2013-12-05 16:48:06 -08001055 } finally {
1056 Binder.restoreCallingIdentity(identity);
1057 }
Daniel Sandler0f0b11c2010-08-04 15:54:58 -04001058 }
1059
Adam Lesinski182f73f2013-12-05 16:48:06 -08001060 @Override
Christoph Studer92b389d2014-04-01 18:44:40 +02001061 public void onNotificationVisibilityChanged(
Chris Wrend1dbc922015-06-19 17:51:16 -04001062 NotificationVisibility[] newlyVisibleKeys, NotificationVisibility[] noLongerVisibleKeys)
1063 throws RemoteException {
Christoph Studer92b389d2014-04-01 18:44:40 +02001064 enforceStatusBarService();
1065 long identity = Binder.clearCallingIdentity();
1066 try {
1067 mNotificationDelegate.onNotificationVisibilityChanged(
1068 newlyVisibleKeys, noLongerVisibleKeys);
1069 } finally {
1070 Binder.restoreCallingIdentity(identity);
1071 }
1072 }
1073
1074 @Override
Chris Wren78403d72014-07-28 10:23:24 +01001075 public void onNotificationExpansionChanged(String key, boolean userAction,
1076 boolean expanded) throws RemoteException {
1077 enforceStatusBarService();
1078 long identity = Binder.clearCallingIdentity();
1079 try {
1080 mNotificationDelegate.onNotificationExpansionChanged(
1081 key, userAction, expanded);
1082 } finally {
1083 Binder.restoreCallingIdentity(identity);
1084 }
1085 }
1086
1087 @Override
Julia Reynolds503ed942017-10-04 16:04:56 -04001088 public void onNotificationDirectReplied(String key) throws RemoteException {
1089 enforceStatusBarService();
1090 long identity = Binder.clearCallingIdentity();
1091 try {
1092 mNotificationDelegate.onNotificationDirectReplied(key);
1093 } finally {
1094 Binder.restoreCallingIdentity(identity);
1095 }
1096 }
1097
1098 @Override
Kenny Guy23991102018-04-05 21:18:38 +01001099 public void onNotificationSmartRepliesAdded(String key, int replyCount)
1100 throws RemoteException {
1101 enforceStatusBarService();
1102 long identity = Binder.clearCallingIdentity();
1103 try {
1104 mNotificationDelegate.onNotificationSmartRepliesAdded(key, replyCount);
1105 } finally {
1106 Binder.restoreCallingIdentity(identity);
1107 }
1108 }
1109
1110 @Override
1111 public void onNotificationSmartReplySent(String key, int replyIndex)
1112 throws RemoteException {
1113 enforceStatusBarService();
1114 long identity = Binder.clearCallingIdentity();
1115 try {
1116 mNotificationDelegate.onNotificationSmartReplySent(key, replyIndex);
1117 } finally {
1118 Binder.restoreCallingIdentity(identity);
1119 }
1120 }
1121
1122 @Override
Julia Reynolds503ed942017-10-04 16:04:56 -04001123 public void onNotificationSettingsViewed(String key) throws RemoteException {
1124 enforceStatusBarService();
1125 long identity = Binder.clearCallingIdentity();
1126 try {
1127 mNotificationDelegate.onNotificationSettingsViewed(key);
1128 } finally {
1129 Binder.restoreCallingIdentity(identity);
1130 }
1131 }
1132
1133 @Override
Kenny Guy3a7c4a52014-03-03 18:24:03 +00001134 public void onClearAllNotifications(int userId) {
Joe Onorato8bc6c512010-06-04 16:21:12 -04001135 enforceStatusBarService();
John Spurlocke6a7d932014-03-13 12:29:00 -04001136 final int callingUid = Binder.getCallingUid();
1137 final int callingPid = Binder.getCallingPid();
Adam Lesinski182f73f2013-12-05 16:48:06 -08001138 long identity = Binder.clearCallingIdentity();
1139 try {
John Spurlocke6a7d932014-03-13 12:29:00 -04001140 mNotificationDelegate.onClearAll(callingUid, callingPid, userId);
Adam Lesinski182f73f2013-12-05 16:48:06 -08001141 } finally {
1142 Binder.restoreCallingIdentity(identity);
Joe Onorato18e69df2010-05-17 22:26:12 -07001143 }
Joe Onorato0cbda992010-05-02 16:28:15 -07001144 }
1145
Jason Monk7e53f202016-01-28 10:40:20 -05001146 @Override
1147 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
Dianne Hackborn354736e2016-08-22 17:00:05 -07001148 String[] args, ShellCallback callback, ResultReceiver resultReceiver) {
Jason Monk7e53f202016-01-28 10:40:20 -05001149 (new StatusBarShellCommand(this)).exec(
Dianne Hackborn354736e2016-08-22 17:00:05 -07001150 this, in, out, err, args, callback, resultReceiver);
Jason Monk7e53f202016-01-28 10:40:20 -05001151 }
1152
Jason Monkf8c2f7b2017-09-06 09:22:29 -04001153 public String[] getStatusBarIcons() {
1154 return mContext.getResources().getStringArray(R.array.config_statusBarIcons);
1155 }
1156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001157 // ================================================================================
1158 // Can be called from any thread
1159 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001161 // lock on mDisableRecords
Benjamin Franzcde0a2a2015-04-23 17:19:48 +01001162 void manageDisableListLocked(int userId, int what, IBinder token, String pkg, int which) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001163 if (SPEW) {
John Spurlock13451a22012-09-28 14:40:41 -04001164 Slog.d(TAG, "manageDisableList userId=" + userId
1165 + " what=0x" + Integer.toHexString(what) + " pkg=" + pkg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001166 }
Charles Heede39092017-09-18 09:19:28 +01001167
1168 // Find matching record, if any
Joe Onorato7bb8eeb2011-01-27 16:00:58 -08001169 final int N = mDisableRecords.size();
Charles Heede39092017-09-18 09:19:28 +01001170 DisableRecord record = null;
Joe Onorato7bb8eeb2011-01-27 16:00:58 -08001171 int i;
Charles Heede39092017-09-18 09:19:28 +01001172 for (i = 0; i < N; i++) {
1173 DisableRecord r = mDisableRecords.get(i);
1174 if (r.token == token && r.userId == userId) {
1175 record = r;
Joe Onorato7bb8eeb2011-01-27 16:00:58 -08001176 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001177 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -08001178 }
Charles Heede39092017-09-18 09:19:28 +01001179
1180 // Remove record if binder is already dead
1181 if (!token.isBinderAlive()) {
1182 if (record != null) {
Joe Onorato7bb8eeb2011-01-27 16:00:58 -08001183 mDisableRecords.remove(i);
Charles Heede39092017-09-18 09:19:28 +01001184 record.token.unlinkToDeath(record, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001185 }
Charles Heede39092017-09-18 09:19:28 +01001186 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001187 }
Charles Heede39092017-09-18 09:19:28 +01001188
1189 // Update existing record
1190 if (record != null) {
1191 record.setFlags(what, which, pkg);
1192 if (record.isEmpty()) {
1193 mDisableRecords.remove(i);
1194 record.token.unlinkToDeath(record, 0);
1195 }
1196 return;
1197 }
1198
1199 // Record doesn't exist, so we create a new one
1200 record = new DisableRecord(userId, token);
1201 record.setFlags(what, which, pkg);
1202 mDisableRecords.add(record);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001203 }
1204
1205 // lock on mDisableRecords
Benjamin Franzcde0a2a2015-04-23 17:19:48 +01001206 int gatherDisableActionsLocked(int userId, int which) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001207 final int N = mDisableRecords.size();
1208 // gather the new net flags
1209 int net = 0;
1210 for (int i=0; i<N; i++) {
John Spurlock13451a22012-09-28 14:40:41 -04001211 final DisableRecord rec = mDisableRecords.get(i);
1212 if (rec.userId == userId) {
Charles Heede39092017-09-18 09:19:28 +01001213 net |= rec.getFlags(which);
John Spurlock13451a22012-09-28 14:40:41 -04001214 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001215 }
1216 return net;
1217 }
1218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001219 // ================================================================================
1220 // Always called from UI thread
1221 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001223 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001224 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Joe Onorato0cbda992010-05-02 16:28:15 -07001225
Joe Onorato7bb8eeb2011-01-27 16:00:58 -08001226 synchronized (mLock) {
Benjamin Franzcde0a2a2015-04-23 17:19:48 +01001227 pw.println(" mDisabled1=0x" + Integer.toHexString(mDisabled1));
1228 pw.println(" mDisabled2=0x" + Integer.toHexString(mDisabled2));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001229 final int N = mDisableRecords.size();
John Spurlock13451a22012-09-28 14:40:41 -04001230 pw.println(" mDisableRecords.size=" + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001231 for (int i=0; i<N; i++) {
1232 DisableRecord tok = mDisableRecords.get(i);
Charles Heede39092017-09-18 09:19:28 +01001233 pw.println(" [" + i + "] " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001234 }
Adrian Roos2a629102016-04-15 16:28:03 -07001235 pw.println(" mCurrentUserId=" + mCurrentUserId);
Dan Sandlerf3a1f2c2016-06-26 15:59:13 -04001236 pw.println(" mIcons=");
1237 for (String slot : mIcons.keySet()) {
1238 pw.println(" ");
1239 pw.print(slot);
1240 pw.print(" -> ");
1241 final StatusBarIcon icon = mIcons.get(slot);
1242 pw.print(icon);
1243 if (!TextUtils.isEmpty(icon.contentDescription)) {
1244 pw.print(" \"");
1245 pw.print(icon.contentDescription);
1246 pw.print("\"");
1247 }
1248 pw.println();
1249 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001250 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001251 }
Michael Wright6cd10262017-04-04 17:44:56 +01001252
1253 private static final Context getUiContext() {
1254 return ActivityThread.currentActivityThread().getSystemUiContext();
1255 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001256}