blob: 57a6776ebc6cb1ed904e5117d2fa3b00d66f2952 [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;
Charles Chen24e7a9f2018-11-21 11:59:07 +080020import static android.view.Display.DEFAULT_DISPLAY;
Charles He9851a8d2017-10-10 17:31:30 +010021
Evan Lairdedd016f2019-01-23 18:36:29 -050022import android.annotation.Nullable;
Adam Lesinskia82b6262017-03-21 16:56:17 -070023import android.app.ActivityThread;
Bernardo Rufinoab338ac2019-12-20 18:35:30 +000024import android.app.ITransientNotificationCallback;
Tony Mak7d4b3a52018-11-27 17:29:36 +000025import android.app.Notification;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.app.StatusBarManager;
Jason Monk7e53f202016-01-28 10:40:20 -050027import android.content.ComponentName;
Jason Monk07473ce2016-01-05 14:59:19 -050028import android.content.Context;
Kevin Chyn23289ef2018-11-28 16:32:36 -080029import android.hardware.biometrics.IBiometricServiceReceiverInternal;
Charles Chen24e7a9f2018-11-21 11:59:07 +080030import android.hardware.display.DisplayManager;
31import android.hardware.display.DisplayManager.DisplayListener;
Aran Inkfd2bfd32019-10-04 16:30:01 -040032import android.net.Uri;
Adam Lesinski182f73f2013-12-05 16:48:06 -080033import android.os.Binder;
Jorim Jaggi165ce062015-07-06 16:18:11 -070034import android.os.Bundle;
Adam Lesinski182f73f2013-12-05 16:48:06 -080035import android.os.Handler;
36import android.os.IBinder;
Jason Monk361915c2017-03-21 20:33:59 -040037import android.os.PowerManager;
Jason Monk7e53f202016-01-28 10:40:20 -050038import android.os.Process;
Adam Lesinski182f73f2013-12-05 16:48:06 -080039import android.os.RemoteException;
Jason Monk7e53f202016-01-28 10:40:20 -050040import android.os.ResultReceiver;
Dianne Hackborn354736e2016-08-22 17:00:05 -070041import android.os.ShellCallback;
Adam Lesinski182f73f2013-12-05 16:48:06 -080042import android.os.UserHandle;
Julia Reynolds503ed942017-10-04 16:04:56 -040043import android.service.notification.NotificationStats;
Dan Sandlerf3a1f2c2016-06-26 15:59:13 -040044import android.text.TextUtils;
Jason Monk07473ce2016-01-05 14:59:19 -050045import android.util.ArrayMap;
Tiger Huang0dbd5372019-10-26 00:24:22 +080046import android.util.ArraySet;
Evan Lairdedd016f2019-01-23 18:36:29 -050047import android.util.Pair;
Joe Onorato8a9b2202010-02-26 18:56:32 -080048import android.util.Slog;
Charles Chen24e7a9f2018-11-21 11:59:07 +080049import android.util.SparseArray;
Tiger Huang332793b2019-10-29 23:21:27 +080050import android.view.InsetsState.InternalInsetsType;
Jorim Jaggi956ca412019-01-07 14:49:14 +010051import android.view.WindowInsetsController.Appearance;
Jim Miller07e03842016-06-22 15:18:13 -070052
Jason Monkb4302182017-08-04 13:39:17 -040053import com.android.internal.R;
Evan Lairdedd016f2019-01-23 18:36:29 -050054import com.android.internal.annotations.GuardedBy;
Joe Onorato0cbda992010-05-02 16:28:15 -070055import com.android.internal.statusbar.IStatusBar;
56import com.android.internal.statusbar.IStatusBarService;
Chris Wrend1dbc922015-06-19 17:51:16 -040057import com.android.internal.statusbar.NotificationVisibility;
Yohei Yukawa49efa712019-04-04 11:49:02 -070058import com.android.internal.statusbar.RegisterStatusBarResult;
Joe Onorato0cbda992010-05-02 16:28:15 -070059import com.android.internal.statusbar.StatusBarIcon;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060060import com.android.internal.util.DumpUtils;
Jorim Jaggi956ca412019-01-07 14:49:14 +010061import com.android.internal.view.AppearanceRegion;
Adam Lesinski182f73f2013-12-05 16:48:06 -080062import com.android.server.LocalServices;
63import com.android.server.notification.NotificationDelegate;
Michael Kwan2decbf72018-02-22 07:40:11 -080064import com.android.server.policy.GlobalActionsProvider;
Jason Monk361915c2017-03-21 20:33:59 -040065import com.android.server.power.ShutdownThread;
Dianne Hackborna924dc0d2011-02-17 14:22:17 -080066import com.android.server.wm.WindowManagerService;
The Android Open Source Project10592532009-03-18 17:39:46 -070067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068import java.io.FileDescriptor;
69import java.io.PrintWriter;
70import java.util.ArrayList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072/**
Joe Onoratof3f0e052010-05-14 18:49:29 -070073 * A note on locking: We rely on the fact that calls onto mBar are oneway or
74 * if they are local, that they just enqueue messages to not deadlock.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075 */
Charles Chen24e7a9f2018-11-21 11:59:07 +080076public class StatusBarManagerService extends IStatusBarService.Stub implements DisplayListener {
Adam Lesinski182f73f2013-12-05 16:48:06 -080077 private static final String TAG = "StatusBarManagerService";
78 private static final boolean SPEW = false;
Joe Onoratodf7dbb62009-11-17 10:43:37 -080079
Adam Lesinski182f73f2013-12-05 16:48:06 -080080 private final Context mContext;
Adam Lesinskia82b6262017-03-21 16:56:17 -070081
Adam Lesinski182f73f2013-12-05 16:48:06 -080082 private final WindowManagerService mWindowManager;
83 private Handler mHandler = new Handler();
84 private NotificationDelegate mNotificationDelegate;
85 private volatile IStatusBar mBar;
Jason Monk07473ce2016-01-05 14:59:19 -050086 private ArrayMap<String, StatusBarIcon> mIcons = new ArrayMap<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087
Joe Onoratof3f0e052010-05-14 18:49:29 -070088 // for disabling the status bar
Adam Lesinski182f73f2013-12-05 16:48:06 -080089 private final ArrayList<DisableRecord> mDisableRecords = new ArrayList<DisableRecord>();
Michael Kwan2decbf72018-02-22 07:40:11 -080090 private GlobalActionsProvider.GlobalActionsListener mGlobalActionListener;
Adam Lesinski182f73f2013-12-05 16:48:06 -080091 private IBinder mSysUiVisToken = new Binder();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092
Adrian Roos2a629102016-04-15 16:28:03 -070093 private final Object mLock = new Object();
Gopal Krishna Shuklae5c83792018-06-29 18:20:36 +053094 private final DeathRecipient mDeathRecipient = new DeathRecipient();
Adam Lesinski182f73f2013-12-05 16:48:06 -080095 private int mCurrentUserId;
satok06487a52010-10-29 11:37:18 +090096
Charles Chen24e7a9f2018-11-21 11:59:07 +080097 private SparseArray<UiState> mDisplayUiState = new SparseArray<>();
98
Gopal Krishna Shuklae5c83792018-06-29 18:20:36 +053099 private class DeathRecipient implements IBinder.DeathRecipient {
100 public void binderDied() {
101 mBar.asBinder().unlinkToDeath(this,0);
102 mBar = null;
103 notifyBarAttachChanged();
104 }
105
106 public void linkToDeath() {
107 try {
108 mBar.asBinder().linkToDeath(mDeathRecipient,0);
109 } catch (RemoteException e) {
110 Slog.e(TAG,"Unable to register Death Recipient for status bar", e);
111 }
112 }
113
114 }
115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116 private class DisableRecord implements IBinder.DeathRecipient {
John Spurlock13451a22012-09-28 14:40:41 -0400117 int userId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118 String pkg;
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100119 int what1;
120 int what2;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121 IBinder token;
122
Charles Heede39092017-09-18 09:19:28 +0100123 public DisableRecord(int userId, IBinder token) {
124 this.userId = userId;
125 this.token = token;
126 try {
127 token.linkToDeath(this, 0);
128 } catch (RemoteException re) {
129 // Give up
130 }
131 }
132
133 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 public void binderDied() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800135 Slog.i(TAG, "binder died for pkg=" + pkg);
Benjamin Franzea2ec972015-03-16 17:18:09 +0000136 disableForUser(0, token, pkg, userId);
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100137 disable2ForUser(0, token, pkg, userId);
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -0700138 token.unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 }
Charles Heede39092017-09-18 09:19:28 +0100140
141 public void setFlags(int what, int which, String pkg) {
142 switch (which) {
143 case 1:
144 what1 = what;
JiangDongyab1352cd2018-11-09 18:23:54 +0800145 break;
Charles Heede39092017-09-18 09:19:28 +0100146 case 2:
147 what2 = what;
JiangDongyab1352cd2018-11-09 18:23:54 +0800148 break;
Charles Heede39092017-09-18 09:19:28 +0100149 default:
150 Slog.w(TAG, "Can't set unsupported disable flag " + which
151 + ": 0x" + Integer.toHexString(what));
JiangDongyab1352cd2018-11-09 18:23:54 +0800152 break;
Charles Heede39092017-09-18 09:19:28 +0100153 }
154 this.pkg = pkg;
155 }
156
157 public int getFlags(int which) {
158 switch (which) {
159 case 1: return what1;
160 case 2: return what2;
161 default:
162 Slog.w(TAG, "Can't get unsupported disable flag " + which);
163 return 0;
164 }
165 }
166
167 public boolean isEmpty() {
168 return what1 == 0 && what2 == 0;
169 }
170
171 @Override
172 public String toString() {
173 return String.format("userId=%d what1=0x%08X what2=0x%08X pkg=%s token=%s",
174 userId, what1, what2, pkg, token);
175 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 }
177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 /**
179 * Construct the service, add the status bar view to the window manager
180 */
Jeff Brown2992ea72011-01-28 22:04:14 -0800181 public StatusBarManagerService(Context context, WindowManagerService windowManager) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 mContext = context;
Jeff Brown2992ea72011-01-28 22:04:14 -0800183 mWindowManager = windowManager;
Joe Onorato0cbda992010-05-02 16:28:15 -0700184
Adam Lesinski182f73f2013-12-05 16:48:06 -0800185 LocalServices.addService(StatusBarManagerInternal.class, mInternalService);
Michael Kwan2decbf72018-02-22 07:40:11 -0800186 LocalServices.addService(GlobalActionsProvider.class, mGlobalActionsProvider);
Charles Chen24e7a9f2018-11-21 11:59:07 +0800187
188 // We always have a default display.
189 final UiState state = new UiState();
190 mDisplayUiState.put(DEFAULT_DISPLAY, state);
191
192 final DisplayManager displayManager =
193 (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
194 displayManager.registerDisplayListener(this, mHandler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195 }
196
Charles Chen24e7a9f2018-11-21 11:59:07 +0800197 @Override
198 public void onDisplayAdded(int displayId) {}
199
200 @Override
201 public void onDisplayRemoved(int displayId) {
202 synchronized (mLock) {
203 mDisplayUiState.remove(displayId);
204 }
205 }
206
207 @Override
208 public void onDisplayChanged(int displayId) {}
209
Adam Lesinski182f73f2013-12-05 16:48:06 -0800210 /**
211 * Private API used by NotificationManagerService.
212 */
213 private final StatusBarManagerInternal mInternalService = new StatusBarManagerInternal() {
John Spurlockcb566aa2014-08-03 22:58:28 -0400214 private boolean mNotificationLightOn;
215
Adam Lesinski182f73f2013-12-05 16:48:06 -0800216 @Override
217 public void setNotificationDelegate(NotificationDelegate delegate) {
Christoph Studere71fefc2014-06-24 16:16:49 +0200218 mNotificationDelegate = delegate;
Adam Lesinski182f73f2013-12-05 16:48:06 -0800219 }
John Spurlockcb566aa2014-08-03 22:58:28 -0400220
John Spurlockcad57682014-07-26 17:09:56 -0400221 @Override
Andrii Kulian0f051f52016-04-14 00:41:51 -0700222 public void showScreenPinningRequest(int taskId) {
Jason Monk5565cb42014-09-12 10:59:21 -0400223 if (mBar != null) {
224 try {
Andrii Kulian0f051f52016-04-14 00:41:51 -0700225 mBar.showScreenPinningRequest(taskId);
Jason Monk5565cb42014-09-12 10:59:21 -0400226 } catch (RemoteException e) {
227 }
228 }
229 }
Adrian Roos4f43dc02015-06-17 16:43:38 -0700230
231 @Override
232 public void showAssistDisclosure() {
233 if (mBar != null) {
234 try {
235 mBar.showAssistDisclosure();
236 } catch (RemoteException e) {
237 }
238 }
239 }
Jorim Jaggi165ce062015-07-06 16:18:11 -0700240
241 @Override
242 public void startAssist(Bundle args) {
243 if (mBar != null) {
244 try {
245 mBar.startAssist(args);
246 } catch (RemoteException e) {
247 }
248 }
249 }
Selim Cinek372d1bd2015-08-14 13:19:37 -0700250
251 @Override
Jorim Jaggi40aa8812015-09-23 12:59:22 -0700252 public void onCameraLaunchGestureDetected(int source) {
Selim Cinek372d1bd2015-08-14 13:19:37 -0700253 if (mBar != null) {
254 try {
Jorim Jaggi40aa8812015-09-23 12:59:22 -0700255 mBar.onCameraLaunchGestureDetected(source);
Selim Cinek372d1bd2015-08-14 13:19:37 -0700256 } catch (RemoteException e) {
257 }
258 }
259 }
Jorim Jaggi86905582016-02-09 21:36:09 -0800260
261 @Override
Jorim Jaggi956ca412019-01-07 14:49:14 +0100262 public void topAppWindowChanged(int displayId, boolean isFullscreen, boolean isImmersive) {
263 StatusBarManagerService.this.topAppWindowChanged(displayId, isFullscreen, isImmersive);
Jorim Jaggi86905582016-02-09 21:36:09 -0800264 }
265
266 @Override
Tiger Huang0dbd5372019-10-26 00:24:22 +0800267 public void setDisableFlags(int displayId, int flags, String cause) {
268 StatusBarManagerService.this.setDisableFlags(displayId, flags, cause);
Jorim Jaggi86905582016-02-09 21:36:09 -0800269 }
Phil Weaver315c34e2016-02-19 15:12:29 -0800270
271 @Override
272 public void toggleSplitScreen() {
273 enforceStatusBarService();
274 if (mBar != null) {
275 try {
276 mBar.toggleSplitScreen();
277 } catch (RemoteException ex) {}
278 }
279 }
Jorim Jaggi2adba072016-03-03 13:43:39 +0100280
Tiger Huang7c610aa2018-10-27 00:01:01 +0800281 @Override
282 public void appTransitionFinished(int displayId) {
Jorim Jaggi2adba072016-03-03 13:43:39 +0100283 enforceStatusBarService();
284 if (mBar != null) {
285 try {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800286 mBar.appTransitionFinished(displayId);
Jorim Jaggi2adba072016-03-03 13:43:39 +0100287 } catch (RemoteException ex) {}
288 }
289 }
Adrian Roosf2efdd82016-04-15 17:43:18 -0700290
291 @Override
292 public void toggleRecentApps() {
293 if (mBar != null) {
294 try {
295 mBar.toggleRecentApps();
296 } catch (RemoteException ex) {}
297 }
298 }
299
300 @Override
301 public void setCurrentUser(int newUserId) {
302 if (SPEW) Slog.d(TAG, "Setting current user to user " + newUserId);
303 mCurrentUserId = newUserId;
304 }
305
306
307 @Override
308 public void preloadRecentApps() {
309 if (mBar != null) {
310 try {
311 mBar.preloadRecentApps();
312 } catch (RemoteException ex) {}
313 }
314 }
315
316 @Override
317 public void cancelPreloadRecentApps() {
318 if (mBar != null) {
319 try {
320 mBar.cancelPreloadRecentApps();
321 } catch (RemoteException ex) {}
322 }
323 }
324
325 @Override
Winson Chungdff7a732017-12-11 12:17:06 -0800326 public void showRecentApps(boolean triggeredFromAltTab) {
Adrian Roosf2efdd82016-04-15 17:43:18 -0700327 if (mBar != null) {
328 try {
Winson Chungdff7a732017-12-11 12:17:06 -0800329 mBar.showRecentApps(triggeredFromAltTab);
Adrian Roosf2efdd82016-04-15 17:43:18 -0700330 } catch (RemoteException ex) {}
331 }
332 }
333
334 @Override
335 public void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) {
336 if (mBar != null) {
337 try {
338 mBar.hideRecentApps(triggeredFromAltTab, triggeredFromHomeKey);
339 } catch (RemoteException ex) {}
340 }
341 }
342
343 @Override
Andrei Stingaceanu0bf096f2016-04-14 18:11:57 +0100344 public void dismissKeyboardShortcutsMenu() {
345 if (mBar != null) {
346 try {
347 mBar.dismissKeyboardShortcutsMenu();
348 } catch (RemoteException ex) {}
349 }
350 }
351
352 @Override
Adrian Roosf2efdd82016-04-15 17:43:18 -0700353 public void toggleKeyboardShortcutsMenu(int deviceId) {
354 if (mBar != null) {
355 try {
356 mBar.toggleKeyboardShortcutsMenu(deviceId);
357 } catch (RemoteException ex) {}
358 }
359 }
360
361 @Override
Beverlyae79ab92017-12-11 09:20:02 -0500362 public void showChargingAnimation(int batteryLevel) {
363 if (mBar != null) {
364 try {
Beverlyac32c9a2018-01-31 16:10:41 -0500365 mBar.showWirelessChargingAnimation(batteryLevel);
Beverlyae79ab92017-12-11 09:20:02 -0500366 } catch (RemoteException ex){
367 }
368 }
369 }
370
371 @Override
Winson Chungac52f282017-03-30 14:44:52 -0700372 public void showPictureInPictureMenu() {
Adrian Roosf2efdd82016-04-15 17:43:18 -0700373 if (mBar != null) {
374 try {
Winson Chungac52f282017-03-30 14:44:52 -0700375 mBar.showPictureInPictureMenu();
Adrian Roosf2efdd82016-04-15 17:43:18 -0700376 } catch (RemoteException ex) {}
377 }
378 }
379
380 @Override
Tiger Huang7c610aa2018-10-27 00:01:01 +0800381 public void setWindowState(int displayId, int window, int state) {
Adrian Roosf2efdd82016-04-15 17:43:18 -0700382 if (mBar != null) {
383 try {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800384 mBar.setWindowState(displayId, window, state);
Adrian Roosf2efdd82016-04-15 17:43:18 -0700385 } catch (RemoteException ex) {}
386 }
387 }
388
389 @Override
Tiger Huang7c610aa2018-10-27 00:01:01 +0800390 public void appTransitionPending(int displayId) {
Adrian Roosf2efdd82016-04-15 17:43:18 -0700391 if (mBar != null) {
392 try {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800393 mBar.appTransitionPending(displayId);
Adrian Roosf2efdd82016-04-15 17:43:18 -0700394 } catch (RemoteException ex) {}
395 }
396 }
397
398 @Override
Tiger Huang7c610aa2018-10-27 00:01:01 +0800399 public void appTransitionCancelled(int displayId) {
Adrian Roosf2efdd82016-04-15 17:43:18 -0700400 if (mBar != null) {
401 try {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800402 mBar.appTransitionCancelled(displayId);
Adrian Roosf2efdd82016-04-15 17:43:18 -0700403 } catch (RemoteException ex) {}
404 }
405 }
406
407 @Override
Tiger Huang7c610aa2018-10-27 00:01:01 +0800408 public void appTransitionStarting(int displayId, long statusBarAnimationsStartTime,
Adrian Roosf2efdd82016-04-15 17:43:18 -0700409 long statusBarAnimationsDuration) {
410 if (mBar != null) {
411 try {
412 mBar.appTransitionStarting(
Charles Chen24e7a9f2018-11-21 11:59:07 +0800413 displayId, statusBarAnimationsStartTime, statusBarAnimationsDuration);
Adrian Roosf2efdd82016-04-15 17:43:18 -0700414 } catch (RemoteException ex) {}
415 }
416 }
Jason Monk361915c2017-03-21 20:33:59 -0400417
418 @Override
Selim Cinek3a49ba22017-08-10 11:17:39 -0700419 public void setTopAppHidesStatusBar(boolean hidesStatusBar) {
420 if (mBar != null) {
421 try {
422 mBar.setTopAppHidesStatusBar(hidesStatusBar);
423 } catch (RemoteException ex) {}
424 }
425 }
426
427 @Override
Jason Monkb4302182017-08-04 13:39:17 -0400428 public boolean showShutdownUi(boolean isReboot, String reason) {
429 if (!mContext.getResources().getBoolean(R.bool.config_showSysuiShutdown)) {
430 return false;
431 }
432 if (mBar != null) {
433 try {
434 mBar.showShutdownUi(isReboot, reason);
435 return true;
436 } catch (RemoteException ex) {}
437 }
438 return false;
439 }
Mike Digman93f08342017-11-24 21:46:53 -0800440
Charles Chen24e7a9f2018-11-21 11:59:07 +0800441 // TODO(b/118592525): support it per display if necessary.
Mike Digman93f08342017-11-24 21:46:53 -0800442 @Override
Mike Digmane0777312018-01-19 12:41:51 -0800443 public void onProposedRotationChanged(int rotation, boolean isValid) {
Mike Digman93f08342017-11-24 21:46:53 -0800444 if (mBar != null){
445 try {
Mike Digmane0777312018-01-19 12:41:51 -0800446 mBar.onProposedRotationChanged(rotation, isValid);
Mike Digman93f08342017-11-24 21:46:53 -0800447 } catch (RemoteException ex) {}
448 }
449 }
Charles Chen3dedec32019-01-24 22:19:37 +0800450
451 @Override
452 public void onDisplayReady(int displayId) {
453 if (mBar != null) {
454 try {
455 mBar.onDisplayReady(displayId);
Winson Chung67e49362019-05-17 16:40:38 -0700456 } catch (RemoteException ex) {}
Charles Chen3dedec32019-01-24 22:19:37 +0800457 }
458 }
Winson Chung67e49362019-05-17 16:40:38 -0700459
460 @Override
461 public void onRecentsAnimationStateChanged(boolean running) {
462 if (mBar != null) {
463 try {
464 mBar.onRecentsAnimationStateChanged(running);
465 } catch (RemoteException ex) {}
466 }
467
468 }
Jorim Jaggi956ca412019-01-07 14:49:14 +0100469
470 @Override
471 public void onSystemBarAppearanceChanged(int displayId, @Appearance int appearance,
472 AppearanceRegion[] appearanceRegions, boolean navbarColorManagedByIme) {
Tiger Huang0dbd5372019-10-26 00:24:22 +0800473 final UiState state = getUiState(displayId);
474 if (!state.appearanceEquals(appearance, appearanceRegions, navbarColorManagedByIme)) {
475 state.setAppearance(appearance, appearanceRegions, navbarColorManagedByIme);
476 }
Jorim Jaggi956ca412019-01-07 14:49:14 +0100477 if (mBar != null) {
478 try {
479 mBar.onSystemBarAppearanceChanged(displayId, appearance, appearanceRegions,
480 navbarColorManagedByIme);
481 } catch (RemoteException ex) { }
482 }
483 }
484
485 @Override
Tiger Huang332793b2019-10-29 23:21:27 +0800486 public void showTransient(int displayId, @InternalInsetsType int[] types) {
Tiger Huang0dbd5372019-10-26 00:24:22 +0800487 getUiState(displayId).showTransient(types);
Jorim Jaggi956ca412019-01-07 14:49:14 +0100488 if (mBar != null) {
489 try {
490 mBar.showTransient(displayId, types);
491 } catch (RemoteException ex) { }
492 }
493 }
494
495 @Override
Tiger Huang332793b2019-10-29 23:21:27 +0800496 public void abortTransient(int displayId, @InternalInsetsType int[] types) {
Tiger Huang0dbd5372019-10-26 00:24:22 +0800497 getUiState(displayId).clearTransient(types);
Jorim Jaggi956ca412019-01-07 14:49:14 +0100498 if (mBar != null) {
499 try {
500 mBar.abortTransient(displayId, types);
501 } catch (RemoteException ex) { }
502 }
503 }
Bernardo Rufinoab338ac2019-12-20 18:35:30 +0000504
505 @Override
506 public void showToast(String packageName, IBinder token, CharSequence text,
507 IBinder windowToken, int duration,
508 @Nullable ITransientNotificationCallback callback) {
509 if (mBar != null) {
510 try {
511 mBar.showToast(packageName, token, text, windowToken, duration, callback);
512 } catch (RemoteException ex) { }
513 }
514 }
515
516 @Override
517 public void hideToast(String packageName, IBinder token) {
518 if (mBar != null) {
519 try {
520 mBar.hideToast(packageName, token);
521 } catch (RemoteException ex) { }
522 }
523 }
Adam Lesinski182f73f2013-12-05 16:48:06 -0800524 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800525
Michael Kwan2decbf72018-02-22 07:40:11 -0800526 private final GlobalActionsProvider mGlobalActionsProvider = new GlobalActionsProvider() {
527 @Override
528 public boolean isGlobalActionsDisabled() {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800529 // TODO(b/118592525): support global actions for multi-display.
530 final int disabled2 = mDisplayUiState.get(DEFAULT_DISPLAY).getDisabled2();
531 return (disabled2 & DISABLE2_GLOBAL_ACTIONS) != 0;
Michael Kwan2decbf72018-02-22 07:40:11 -0800532 }
533
534 @Override
535 public void setGlobalActionsListener(GlobalActionsProvider.GlobalActionsListener listener) {
536 mGlobalActionListener = listener;
537 mGlobalActionListener.onGlobalActionsAvailableChanged(mBar != null);
538 }
539
540 @Override
541 public void showGlobalActions() {
542 if (mBar != null) {
543 try {
544 mBar.showGlobalActionsMenu();
545 } catch (RemoteException ex) {}
546 }
547 }
548 };
549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800550 // ================================================================================
Joe Onorato25f95f92010-04-08 18:37:10 -0500551 // From IStatusBarService
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800552 // ================================================================================
Adam Lesinski182f73f2013-12-05 16:48:06 -0800553 @Override
Daniel Sandler11cf1782012-09-27 14:03:08 -0400554 public void expandNotificationsPanel() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800555 enforceExpandStatusBar();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700556
557 if (mBar != null) {
558 try {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400559 mBar.animateExpandNotificationsPanel();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700560 } catch (RemoteException ex) {
561 }
562 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 }
564
Adam Lesinski182f73f2013-12-05 16:48:06 -0800565 @Override
Daniel Sandler11cf1782012-09-27 14:03:08 -0400566 public void collapsePanels() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567 enforceExpandStatusBar();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800568
Joe Onorato4762c2d2010-05-17 15:42:59 -0700569 if (mBar != null) {
570 try {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400571 mBar.animateCollapsePanels();
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700572 } catch (RemoteException ex) {
573 }
574 }
575 }
576
Adam Lesinski182f73f2013-12-05 16:48:06 -0800577 @Override
Anthony Chen9ad00e02017-05-12 15:53:36 -0700578 public void togglePanel() {
579 enforceExpandStatusBar();
580
581 if (mBar != null) {
582 try {
583 mBar.togglePanel();
584 } catch (RemoteException ex) {
585 }
586 }
587 }
588
589 @Override
Jason Monka9927322015-12-13 16:22:37 -0500590 public void expandSettingsPanel(String subPanel) {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700591 enforceExpandStatusBar();
592
593 if (mBar != null) {
594 try {
Jason Monka9927322015-12-13 16:22:37 -0500595 mBar.animateExpandSettingsPanel(subPanel);
Joe Onorato4762c2d2010-05-17 15:42:59 -0700596 } catch (RemoteException ex) {
597 }
598 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800599 }
600
Jason Monk7e53f202016-01-28 10:40:20 -0500601 public void addTile(ComponentName component) {
602 enforceStatusBarOrShell();
603
604 if (mBar != null) {
605 try {
606 mBar.addQsTile(component);
607 } catch (RemoteException ex) {
608 }
609 }
610 }
611
612 public void remTile(ComponentName component) {
613 enforceStatusBarOrShell();
614
615 if (mBar != null) {
616 try {
617 mBar.remQsTile(component);
618 } catch (RemoteException ex) {
619 }
620 }
621 }
622
623 public void clickTile(ComponentName component) {
624 enforceStatusBarOrShell();
625
626 if (mBar != null) {
627 try {
628 mBar.clickQsTile(component);
629 } catch (RemoteException ex) {
630 }
631 }
632 }
633
Adam Lesinski182f73f2013-12-05 16:48:06 -0800634 @Override
Philip Quinnc3a503d2017-07-18 23:23:41 -0700635 public void handleSystemKey(int key) throws RemoteException {
Jim Miller07e03842016-06-22 15:18:13 -0700636 enforceExpandStatusBar();
637
638 if (mBar != null) {
639 try {
Philip Quinnc3a503d2017-07-18 23:23:41 -0700640 mBar.handleSystemKey(key);
Jim Miller07e03842016-06-22 15:18:13 -0700641 } catch (RemoteException ex) {
642 }
643 }
644 }
645
646 @Override
Matthew Ng9c3bce52018-02-01 22:00:31 +0000647 public void showPinningEnterExitToast(boolean entering) throws RemoteException {
648 if (mBar != null) {
649 try {
650 mBar.showPinningEnterExitToast(entering);
651 } catch (RemoteException ex) {
652 }
653 }
654 }
655
656 @Override
657 public void showPinningEscapeToast() throws RemoteException {
658 if (mBar != null) {
659 try {
660 mBar.showPinningEscapeToast();
661 } catch (RemoteException ex) {
662 }
663 }
664 }
665
666 @Override
Kevin Chyn86f1b8e2019-09-24 19:00:49 -0700667 public void showAuthenticationDialog(Bundle bundle, IBiometricServiceReceiverInternal receiver,
668 int biometricModality, boolean requireConfirmation, int userId, String opPackageName) {
Kevin Chyn95c27e02018-09-12 01:46:16 -0700669 enforceBiometricDialog();
Kevin Chynaae4a152018-01-18 11:48:09 -0800670 if (mBar != null) {
671 try {
Kevin Chyn86f1b8e2019-09-24 19:00:49 -0700672 mBar.showAuthenticationDialog(bundle, receiver, biometricModality,
673 requireConfirmation, userId, opPackageName);
Kevin Chynaae4a152018-01-18 11:48:09 -0800674 } catch (RemoteException ex) {
675 }
676 }
677 }
678
679 @Override
Ilya Matyukhin0f9da352019-10-03 14:10:01 -0700680 public void onBiometricAuthenticated() {
Kevin Chyn95c27e02018-09-12 01:46:16 -0700681 enforceBiometricDialog();
Kevin Chynaae4a152018-01-18 11:48:09 -0800682 if (mBar != null) {
683 try {
Ilya Matyukhin0f9da352019-10-03 14:10:01 -0700684 mBar.onBiometricAuthenticated();
Kevin Chynaae4a152018-01-18 11:48:09 -0800685 } catch (RemoteException ex) {
686 }
687 }
688 }
689
690 @Override
Kevin Chyne9275662018-07-23 16:42:06 -0700691 public void onBiometricHelp(String message) {
Kevin Chyn95c27e02018-09-12 01:46:16 -0700692 enforceBiometricDialog();
Kevin Chynaae4a152018-01-18 11:48:09 -0800693 if (mBar != null) {
694 try {
Kevin Chyne9275662018-07-23 16:42:06 -0700695 mBar.onBiometricHelp(message);
Kevin Chynaae4a152018-01-18 11:48:09 -0800696 } catch (RemoteException ex) {
697 }
698 }
699 }
700
701 @Override
Ilya Matyukhin0f9da352019-10-03 14:10:01 -0700702 public void onBiometricError(int modality, int error, int vendorCode) {
Kevin Chyn95c27e02018-09-12 01:46:16 -0700703 enforceBiometricDialog();
Kevin Chynaae4a152018-01-18 11:48:09 -0800704 if (mBar != null) {
705 try {
Ilya Matyukhin0f9da352019-10-03 14:10:01 -0700706 mBar.onBiometricError(modality, error, vendorCode);
Kevin Chynaae4a152018-01-18 11:48:09 -0800707 } catch (RemoteException ex) {
708 }
709 }
710 }
711
712 @Override
Kevin Chyn86f1b8e2019-09-24 19:00:49 -0700713 public void hideAuthenticationDialog() {
Kevin Chyn95c27e02018-09-12 01:46:16 -0700714 enforceBiometricDialog();
Kevin Chynaae4a152018-01-18 11:48:09 -0800715 if (mBar != null) {
716 try {
Kevin Chyn86f1b8e2019-09-24 19:00:49 -0700717 mBar.hideAuthenticationDialog();
Kevin Chynaae4a152018-01-18 11:48:09 -0800718 } catch (RemoteException ex) {
719 }
720 }
721 }
722
Charles Chen24e7a9f2018-11-21 11:59:07 +0800723 // TODO(b/117478341): make it aware of multi-display if needed.
Kevin Chyn23289ef2018-11-28 16:32:36 -0800724 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 public void disable(int what, IBinder token, String pkg) {
Benjamin Franzea2ec972015-03-16 17:18:09 +0000726 disableForUser(what, token, pkg, mCurrentUserId);
John Spurlock13451a22012-09-28 14:40:41 -0400727 }
728
Charles Chen24e7a9f2018-11-21 11:59:07 +0800729 // TODO(b/117478341): make it aware of multi-display if needed.
Benjamin Franzea2ec972015-03-16 17:18:09 +0000730 @Override
731 public void disableForUser(int what, IBinder token, String pkg, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800732 enforceStatusBar();
Joe Onoratof3f0e052010-05-14 18:49:29 -0700733
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800734 synchronized (mLock) {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800735 disableLocked(DEFAULT_DISPLAY, userId, what, token, pkg, 1);
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800736 }
737 }
738
Charles Chen24e7a9f2018-11-21 11:59:07 +0800739 // TODO(b/117478341): make it aware of multi-display if needed.
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100740 /**
741 * Disable additional status bar features. Pass the bitwise-or of the DISABLE2_* flags.
Evan Lairdedd016f2019-01-23 18:36:29 -0500742 * To re-enable everything, pass {@link #DISABLE2_NONE}.
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100743 *
744 * Warning: Only pass DISABLE2_* flags into this function, do not use DISABLE_* flags.
745 */
746 @Override
747 public void disable2(int what, IBinder token, String pkg) {
Benjamin Franz292a0a92016-03-30 13:41:57 +0100748 disable2ForUser(what, token, pkg, mCurrentUserId);
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100749 }
750
Charles Chen24e7a9f2018-11-21 11:59:07 +0800751 // TODO(b/117478341): make it aware of multi-display if needed.
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100752 /**
753 * Disable additional status bar features for a given user. Pass the bitwise-or of the
754 * DISABLE2_* flags. To re-enable everything, pass {@link #DISABLE_NONE}.
755 *
756 * Warning: Only pass DISABLE2_* flags into this function, do not use DISABLE_* flags.
757 */
758 @Override
759 public void disable2ForUser(int what, IBinder token, String pkg, int userId) {
Mike Digmandd2f49e2018-03-16 10:54:22 -0700760 enforceStatusBar();
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100761
762 synchronized (mLock) {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800763 disableLocked(DEFAULT_DISPLAY, userId, what, token, pkg, 2);
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100764 }
765 }
766
Charles Chen24e7a9f2018-11-21 11:59:07 +0800767 private void disableLocked(int displayId, int userId, int what, IBinder token, String pkg,
768 int whichFlag) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700769 // It's important that the the callback and the call to mBar get done
770 // in the same order when multiple threads are calling this function
771 // so they are paired correctly. The messages on the handler will be
772 // handled in the order they were enqueued, but will be outside the lock.
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100773 manageDisableListLocked(userId, what, token, pkg, whichFlag);
John Spurlock8f3e6d52012-11-29 13:56:24 -0500774
775 // Ensure state for the current user is applied, even if passed a non-current user.
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100776 final int net1 = gatherDisableActionsLocked(mCurrentUserId, 1);
777 final int net2 = gatherDisableActionsLocked(mCurrentUserId, 2);
Charles Chen24e7a9f2018-11-21 11:59:07 +0800778 final UiState state = getUiState(displayId);
Charles Chen1313fee2018-12-12 23:36:21 +0800779 if (!state.disableEquals(net1, net2)) {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800780 state.setDisabled(net1, net2);
781 mHandler.post(() -> mNotificationDelegate.onSetDisabled(net1));
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800782 if (mBar != null) {
783 try {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800784 mBar.disable(displayId, net1, net2);
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800785 } catch (RemoteException ex) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700786 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800787 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800788 }
789 }
790
Evan Lairdedd016f2019-01-23 18:36:29 -0500791 /**
792 * Get the currently applied disable flags, in the form of one Pair<Integer, Integer>.
793 *
794 * @return pair of disable flags in the form of (disabled1, disabled2), where (0, 0) indicates
795 * no flags are set for this token.
796 */
797 @Override
798 public int[] getDisableFlags(IBinder token, int userId) {
799 enforceStatusBar();
800
801 int disable1 = 0;
802 int disable2 = 0;
803 synchronized (mLock) {
804 // Find a matching record if it exists
805 DisableRecord record = findMatchingRecordLocked(token, userId).second;
806 if (record != null) {
807 disable1 = record.what1;
808 disable2 = record.what2;
809 }
810 }
811
812 return new int[] {disable1, disable2};
813 }
814
Adam Lesinski182f73f2013-12-05 16:48:06 -0800815 @Override
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700816 public void setIcon(String slot, String iconPackage, int iconId, int iconLevel,
817 String contentDescription) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800818 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700819
820 synchronized (mIcons) {
Xiaohui Chene4de5a02015-09-22 15:33:31 -0700821 StatusBarIcon icon = new StatusBarIcon(iconPackage, UserHandle.SYSTEM, iconId,
822 iconLevel, 0, contentDescription);
Joe Onorato66d7d012010-05-14 10:05:10 -0700823 //Slog.d(TAG, "setIcon slot=" + slot + " index=" + index + " icon=" + icon);
Jason Monk07473ce2016-01-05 14:59:19 -0500824 mIcons.put(slot, icon);
Joe Onorato0cbda992010-05-02 16:28:15 -0700825
Joe Onorato0cbda992010-05-02 16:28:15 -0700826 if (mBar != null) {
827 try {
Jason Monk07473ce2016-01-05 14:59:19 -0500828 mBar.setIcon(slot, icon);
Joe Onorato0cbda992010-05-02 16:28:15 -0700829 } catch (RemoteException ex) {
830 }
831 }
832 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800833 }
834
Adam Lesinski182f73f2013-12-05 16:48:06 -0800835 @Override
Jason Monk07473ce2016-01-05 14:59:19 -0500836 public void setIconVisibility(String slot, boolean visibility) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800837 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700838
Joe Onorato514ad6632010-05-13 18:49:00 -0700839 synchronized (mIcons) {
Jason Monk07473ce2016-01-05 14:59:19 -0500840 StatusBarIcon icon = mIcons.get(slot);
Joe Onorato514ad6632010-05-13 18:49:00 -0700841 if (icon == null) {
842 return;
843 }
Jason Monk07473ce2016-01-05 14:59:19 -0500844 if (icon.visible != visibility) {
845 icon.visible = visibility;
Joe Onorato514ad6632010-05-13 18:49:00 -0700846
Joe Onorato514ad6632010-05-13 18:49:00 -0700847 if (mBar != null) {
848 try {
Jason Monk07473ce2016-01-05 14:59:19 -0500849 mBar.setIcon(slot, icon);
Joe Onorato514ad6632010-05-13 18:49:00 -0700850 } catch (RemoteException ex) {
851 }
852 }
853 }
854 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700855 }
856
Adam Lesinski182f73f2013-12-05 16:48:06 -0800857 @Override
Joe Onorato0cbda992010-05-02 16:28:15 -0700858 public void removeIcon(String slot) {
859 enforceStatusBar();
860
861 synchronized (mIcons) {
Jason Monk07473ce2016-01-05 14:59:19 -0500862 mIcons.remove(slot);
Joe Onorato0cbda992010-05-02 16:28:15 -0700863
Joe Onorato0cbda992010-05-02 16:28:15 -0700864 if (mBar != null) {
865 try {
Jason Monk07473ce2016-01-05 14:59:19 -0500866 mBar.removeIcon(slot);
Joe Onorato0cbda992010-05-02 16:28:15 -0700867 } catch (RemoteException ex) {
868 }
869 }
870 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800871 }
872
Wale Ogunwale393b1c12014-10-18 16:22:01 -0700873 /**
Jorim Jaggi956ca412019-01-07 14:49:14 +0100874 * Enables System UI to know whether the top app is fullscreen or not, and whether this app is
875 * in immersive mode or not.
Daniel Sandlere02d8082010-10-08 15:13:22 -0400876 */
Jorim Jaggi956ca412019-01-07 14:49:14 +0100877 private void topAppWindowChanged(int displayId, boolean isFullscreen, boolean isImmersive) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400878 enforceStatusBar();
879
Daniel Sandlere02d8082010-10-08 15:13:22 -0400880 synchronized(mLock) {
Jorim Jaggi956ca412019-01-07 14:49:14 +0100881 getUiState(displayId).setFullscreen(isFullscreen);
882 getUiState(displayId).setImmersive(isImmersive);
Charles Chen24e7a9f2018-11-21 11:59:07 +0800883 mHandler.post(() -> {
884 if (mBar != null) {
885 try {
Jorim Jaggi956ca412019-01-07 14:49:14 +0100886 mBar.topAppWindowChanged(displayId, isFullscreen, isImmersive);
Charles Chen24e7a9f2018-11-21 11:59:07 +0800887 } catch (RemoteException ex) {
Dianne Hackborn7d049322011-06-14 15:00:32 -0700888 }
Jorim Jaggi86905582016-02-09 21:36:09 -0800889 }
890 });
Daniel Sandlere02d8082010-10-08 15:13:22 -0400891 }
892 }
893
Adam Lesinski182f73f2013-12-05 16:48:06 -0800894 @Override
lumark7570cac2019-03-07 22:14:38 +0800895 public void setImeWindowStatus(int displayId, final IBinder token, final int vis,
Tarandeep Singh07b318b2019-07-17 11:12:04 -0700896 final int backDisposition, final boolean showImeSwitcher,
897 boolean isMultiClientImeEnabled) {
satok06487a52010-10-29 11:37:18 +0900898 enforceStatusBar();
899
Joe Onorato857fd9b2011-01-27 15:08:35 -0800900 if (SPEW) {
901 Slog.d(TAG, "swetImeWindowStatus vis=" + vis + " backDisposition=" + backDisposition);
902 }
satok06487a52010-10-29 11:37:18 +0900903
904 synchronized(mLock) {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800905 // In case of IME change, we need to call up setImeWindowStatus() regardless of
906 // mImeWindowVis because mImeWindowVis may not have been set to false when the
satok06e07442010-11-02 19:46:55 +0900907 // previous IME was destroyed.
lumark7570cac2019-03-07 22:14:38 +0800908 getUiState(displayId).setImeWindowState(vis, backDisposition, showImeSwitcher, token);
Charles Chen24e7a9f2018-11-21 11:59:07 +0800909
910 mHandler.post(() -> {
911 if (mBar == null) return;
912 try {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800913 mBar.setImeWindowStatus(
Tarandeep Singh07b318b2019-07-17 11:12:04 -0700914 displayId, token, vis, backDisposition, showImeSwitcher,
915 isMultiClientImeEnabled);
Charles Chen24e7a9f2018-11-21 11:59:07 +0800916 } catch (RemoteException ex) { }
satok06e07442010-11-02 19:46:55 +0900917 });
satok06487a52010-10-29 11:37:18 +0900918 }
919 }
920
Tiger Huang0dbd5372019-10-26 00:24:22 +0800921 private void setDisableFlags(int displayId, int flags, String cause) {
Joe Onorato55bf3802011-01-25 13:42:10 -0800922 // also allows calls from window manager which is in this process.
Joe Onoratof63b0f42010-09-12 17:03:19 -0400923 enforceStatusBarService();
924
Tiger Huang0dbd5372019-10-26 00:24:22 +0800925 final int unknownFlags = flags & ~StatusBarManager.DISABLE_MASK;
926 if (unknownFlags != 0) {
927 Slog.e(TAG, "Unknown disable flags: 0x" + Integer.toHexString(unknownFlags),
928 new RuntimeException());
929 }
930
931 if (SPEW) Slog.d(TAG, "setDisableFlags(0x" + Integer.toHexString(flags) + ")");
Daniel Sandler60ee2562011-07-22 12:34:33 -0400932
Joe Onoratof63b0f42010-09-12 17:03:19 -0400933 synchronized (mLock) {
Tiger Huang0dbd5372019-10-26 00:24:22 +0800934 disableLocked(displayId, mCurrentUserId, flags, mSysUiVisToken, cause, 1);
Charles Chen24e7a9f2018-11-21 11:59:07 +0800935 }
936 }
937
938 /**
939 * @return {@link UiState} specified by {@code displayId}.
940 *
941 * <p>
942 * Note: If {@link UiState} specified by {@code displayId} does not exist, {@link UiState}
943 * will be allocated and {@code mDisplayUiState} will be updated accordingly.
944 * <p/>
945 */
946 private UiState getUiState(int displayId) {
947 UiState state = mDisplayUiState.get(displayId);
948 if (state == null) {
949 state = new UiState();
950 mDisplayUiState.put(displayId, state);
951 }
952 return state;
953 }
954
955 private class UiState {
Tiger Huang0dbd5372019-10-26 00:24:22 +0800956 private @Appearance int mAppearance = 0;
957 private AppearanceRegion[] mAppearanceRegions = new AppearanceRegion[0];
958 private ArraySet<Integer> mTransientBarTypes = new ArraySet<>();
959 private boolean mNavbarColorManagedByIme = false;
Jorim Jaggi956ca412019-01-07 14:49:14 +0100960 private boolean mFullscreen = false;
961 private boolean mImmersive = false;
Charles Chen24e7a9f2018-11-21 11:59:07 +0800962 private int mDisabled1 = 0;
963 private int mDisabled2 = 0;
964 private int mImeWindowVis = 0;
965 private int mImeBackDisposition = 0;
966 private boolean mShowImeSwitcher = false;
967 private IBinder mImeToken = null;
Tiger Huang0dbd5372019-10-26 00:24:22 +0800968
969 private void setAppearance(@Appearance int appearance,
970 AppearanceRegion[] appearanceRegions, boolean navbarColorManagedByIme) {
971 mAppearance = appearance;
972 mAppearanceRegions = appearanceRegions;
973 mNavbarColorManagedByIme = navbarColorManagedByIme;
974 }
975
976 private boolean appearanceEquals(@Appearance int appearance,
977 AppearanceRegion[] appearanceRegions, boolean navbarColorManagedByIme) {
978 if (mAppearance != appearance || mAppearanceRegions.length != appearanceRegions.length
979 || mNavbarColorManagedByIme != navbarColorManagedByIme) {
980 return false;
981 }
982 for (int i = appearanceRegions.length - 1; i >= 0; i--) {
983 if (!mAppearanceRegions[i].equals(appearanceRegions[i])) {
984 return false;
985 }
986 }
987 return true;
988 }
989
Tiger Huang332793b2019-10-29 23:21:27 +0800990 private void showTransient(@InternalInsetsType int[] types) {
Tiger Huang0dbd5372019-10-26 00:24:22 +0800991 for (int type : types) {
992 mTransientBarTypes.add(type);
993 }
994 }
995
Tiger Huang332793b2019-10-29 23:21:27 +0800996 private void clearTransient(@InternalInsetsType int[] types) {
Tiger Huang0dbd5372019-10-26 00:24:22 +0800997 for (int type : types) {
998 mTransientBarTypes.remove(type);
999 }
1000 }
1001
1002 private void setFullscreen(boolean isFullscreen) {
1003 mFullscreen = isFullscreen;
1004 }
1005
1006 private void setImmersive(boolean isImmersive) {
1007 mImmersive = isImmersive;
1008 }
Charles Chen24e7a9f2018-11-21 11:59:07 +08001009
1010 private int getDisabled1() {
1011 return mDisabled1;
1012 }
1013
1014 private int getDisabled2() {
1015 return mDisabled2;
1016 }
1017
1018 private void setDisabled(int disabled1, int disabled2) {
1019 mDisabled1 = disabled1;
1020 mDisabled2 = disabled2;
1021 }
1022
Charles Chen24e7a9f2018-11-21 11:59:07 +08001023 private boolean disableEquals(int disabled1, int disabled2) {
1024 return mDisabled1 == disabled1 && mDisabled2 == disabled2;
1025 }
1026
Charles Chen24e7a9f2018-11-21 11:59:07 +08001027 private void setImeWindowState(final int vis, final int backDisposition,
1028 final boolean showImeSwitcher, final IBinder token) {
1029 mImeWindowVis = vis;
1030 mImeBackDisposition = backDisposition;
1031 mShowImeSwitcher = showImeSwitcher;
1032 mImeToken = token;
Joe Onorato93056472010-09-10 10:30:46 -04001033 }
1034 }
1035
Jason Monk7e53f202016-01-28 10:40:20 -05001036 private void enforceStatusBarOrShell() {
1037 if (Binder.getCallingUid() == Process.SHELL_UID) {
1038 return;
1039 }
1040 enforceStatusBar();
1041 }
1042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001043 private void enforceStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -07001044 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -07001045 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001046 }
1047
1048 private void enforceExpandStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -07001049 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.EXPAND_STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -07001050 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001051 }
1052
Joe Onorato8bc6c512010-06-04 16:21:12 -04001053 private void enforceStatusBarService() {
1054 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
1055 "StatusBarManagerService");
1056 }
1057
Kevin Chyn95c27e02018-09-12 01:46:16 -07001058 private void enforceBiometricDialog() {
1059 mContext.enforceCallingOrSelfPermission(
1060 android.Manifest.permission.MANAGE_BIOMETRIC_DIALOG,
1061 "StatusBarManagerService");
1062 }
1063
Joe Onorato4762c2d2010-05-17 15:42:59 -07001064 // ================================================================================
1065 // Callbacks from the status bar service.
1066 // ================================================================================
Charles Chen24e7a9f2018-11-21 11:59:07 +08001067 // TODO(b/118592525): refactor it as an IStatusBar API.
Adam Lesinski182f73f2013-12-05 16:48:06 -08001068 @Override
Yohei Yukawa49efa712019-04-04 11:49:02 -07001069 public RegisterStatusBarResult registerStatusBar(IStatusBar bar) {
Joe Onorato8bc6c512010-06-04 16:21:12 -04001070 enforceStatusBarService();
1071
Joe Onorato0cbda992010-05-02 16:28:15 -07001072 Slog.i(TAG, "registerStatusBar bar=" + bar);
1073 mBar = bar;
Gopal Krishna Shuklae5c83792018-06-29 18:20:36 +05301074 mDeathRecipient.linkToDeath();
Jason Monk361915c2017-03-21 20:33:59 -04001075 notifyBarAttachChanged();
Yohei Yukawa49efa712019-04-04 11:49:02 -07001076 final ArrayMap<String, StatusBarIcon> icons;
Joe Onorato75199e32010-05-29 17:22:51 -04001077 synchronized (mIcons) {
Yohei Yukawa49efa712019-04-04 11:49:02 -07001078 icons = new ArrayMap<>(mIcons);
Joe Onorato75199e32010-05-29 17:22:51 -04001079 }
Joe Onorato93056472010-09-10 10:30:46 -04001080 synchronized (mLock) {
Charles Chen24e7a9f2018-11-21 11:59:07 +08001081 // TODO(b/118592525): Currently, status bar only works on the default display.
1082 // Make it aware of multi-display if needed.
1083 final UiState state = mDisplayUiState.get(DEFAULT_DISPLAY);
Tiger Huang0dbd5372019-10-26 00:24:22 +08001084 final int[] transientBarTypes = new int[state.mTransientBarTypes.size()];
1085 for (int i = 0; i < transientBarTypes.length; i++) {
1086 transientBarTypes[i] = state.mTransientBarTypes.valueAt(i);
1087 }
Yohei Yukawa49efa712019-04-04 11:49:02 -07001088 return new RegisterStatusBarResult(icons, gatherDisableActionsLocked(mCurrentUserId, 1),
Tiger Huang0dbd5372019-10-26 00:24:22 +08001089 state.mAppearance, state.mAppearanceRegions, state.mImeWindowVis,
Yohei Yukawa49efa712019-04-04 11:49:02 -07001090 state.mImeBackDisposition, state.mShowImeSwitcher,
Tiger Huang0dbd5372019-10-26 00:24:22 +08001091 gatherDisableActionsLocked(mCurrentUserId, 2), state.mImeToken,
1092 state.mNavbarColorManagedByIme, state.mFullscreen, state.mImmersive,
1093 transientBarTypes);
Joe Onorato93056472010-09-10 10:30:46 -04001094 }
Joe Onorato2314aab2010-04-08 16:41:23 -05001095 }
Joe Onoratoaaba60b2010-05-23 15:18:41 -04001096
Jason Monk361915c2017-03-21 20:33:59 -04001097 private void notifyBarAttachChanged() {
1098 mHandler.post(() -> {
1099 if (mGlobalActionListener == null) return;
Michael Kwan2decbf72018-02-22 07:40:11 -08001100 mGlobalActionListener.onGlobalActionsAvailableChanged(mBar != null);
Jason Monk361915c2017-03-21 20:33:59 -04001101 });
1102 }
1103
Joe Onorato4762c2d2010-05-17 15:42:59 -07001104 /**
Christoph Studer1f32c652014-11-26 15:32:20 +01001105 * @param clearNotificationEffects whether to consider notifications as "shown" and stop
1106 * LED, vibration, and ringing
Joe Onorato4762c2d2010-05-17 15:42:59 -07001107 */
Adam Lesinski182f73f2013-12-05 16:48:06 -08001108 @Override
Chris Wrenb659c4f2015-06-25 17:12:27 -04001109 public void onPanelRevealed(boolean clearNotificationEffects, int numItems) {
Joe Onorato8bc6c512010-06-04 16:21:12 -04001110 enforceStatusBarService();
Adam Lesinski182f73f2013-12-05 16:48:06 -08001111 long identity = Binder.clearCallingIdentity();
1112 try {
Chris Wrenb659c4f2015-06-25 17:12:27 -04001113 mNotificationDelegate.onPanelRevealed(clearNotificationEffects, numItems);
Christoph Studer1f32c652014-11-26 15:32:20 +01001114 } finally {
1115 Binder.restoreCallingIdentity(identity);
1116 }
1117 }
1118
1119 @Override
1120 public void clearNotificationEffects() throws RemoteException {
1121 enforceStatusBarService();
1122 long identity = Binder.clearCallingIdentity();
1123 try {
1124 mNotificationDelegate.clearEffects();
Adam Lesinski182f73f2013-12-05 16:48:06 -08001125 } finally {
1126 Binder.restoreCallingIdentity(identity);
1127 }
Joe Onorato4762c2d2010-05-17 15:42:59 -07001128 }
1129
Adam Lesinski182f73f2013-12-05 16:48:06 -08001130 @Override
Christoph Studer760ea552014-03-21 13:10:21 +01001131 public void onPanelHidden() throws RemoteException {
1132 enforceStatusBarService();
1133 long identity = Binder.clearCallingIdentity();
1134 try {
1135 mNotificationDelegate.onPanelHidden();
1136 } finally {
1137 Binder.restoreCallingIdentity(identity);
1138 }
1139 }
1140
Jason Monk361915c2017-03-21 20:33:59 -04001141 /**
1142 * Allows the status bar to shutdown the device.
1143 */
1144 @Override
1145 public void shutdown() {
1146 enforceStatusBarService();
1147 long identity = Binder.clearCallingIdentity();
1148 try {
Michael Wright6cd10262017-04-04 17:44:56 +01001149 // ShutdownThread displays UI, so give it a UI context.
Jason Monk361915c2017-03-21 20:33:59 -04001150 mHandler.post(() ->
Michael Wright6cd10262017-04-04 17:44:56 +01001151 ShutdownThread.shutdown(getUiContext(),
1152 PowerManager.SHUTDOWN_USER_REQUESTED, false));
Jason Monk361915c2017-03-21 20:33:59 -04001153 } finally {
1154 Binder.restoreCallingIdentity(identity);
1155 }
1156 }
1157
1158 /**
1159 * Allows the status bar to reboot the device.
1160 */
1161 @Override
1162 public void reboot(boolean safeMode) {
1163 enforceStatusBarService();
1164 long identity = Binder.clearCallingIdentity();
1165 try {
1166 mHandler.post(() -> {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001167 // ShutdownThread displays UI, so give it a UI context.
Jason Monk361915c2017-03-21 20:33:59 -04001168 if (safeMode) {
Shunta Satobdb0e492017-04-14 16:01:54 +09001169 ShutdownThread.rebootSafeMode(getUiContext(), true);
Jason Monk361915c2017-03-21 20:33:59 -04001170 } else {
Michael Wright6cd10262017-04-04 17:44:56 +01001171 ShutdownThread.reboot(getUiContext(),
1172 PowerManager.SHUTDOWN_USER_REQUESTED, false);
Jason Monk361915c2017-03-21 20:33:59 -04001173 }
1174 });
1175 } finally {
1176 Binder.restoreCallingIdentity(identity);
1177 }
1178 }
1179
1180 @Override
1181 public void onGlobalActionsShown() {
1182 enforceStatusBarService();
1183 long identity = Binder.clearCallingIdentity();
1184 try {
1185 if (mGlobalActionListener == null) return;
1186 mGlobalActionListener.onGlobalActionsShown();
1187 } finally {
1188 Binder.restoreCallingIdentity(identity);
1189 }
1190 }
1191
1192 @Override
1193 public void onGlobalActionsHidden() {
1194 enforceStatusBarService();
1195 long identity = Binder.clearCallingIdentity();
1196 try {
1197 if (mGlobalActionListener == null) return;
1198 mGlobalActionListener.onGlobalActionsDismissed();
1199 } finally {
1200 Binder.restoreCallingIdentity(identity);
1201 }
1202 }
1203
Christoph Studer760ea552014-03-21 13:10:21 +01001204 @Override
Dieter Hsud39f0d52018-04-14 02:08:30 +08001205 public void onNotificationClick(String key, NotificationVisibility nv) {
Joe Onorato8bc6c512010-06-04 16:21:12 -04001206 enforceStatusBarService();
John Spurlocke6a7d932014-03-13 12:29:00 -04001207 final int callingUid = Binder.getCallingUid();
1208 final int callingPid = Binder.getCallingPid();
Adam Lesinski182f73f2013-12-05 16:48:06 -08001209 long identity = Binder.clearCallingIdentity();
1210 try {
Dieter Hsud39f0d52018-04-14 02:08:30 +08001211 mNotificationDelegate.onNotificationClick(callingUid, callingPid, key, nv);
Adam Lesinski182f73f2013-12-05 16:48:06 -08001212 } finally {
1213 Binder.restoreCallingIdentity(identity);
1214 }
Joe Onoratoaaba60b2010-05-23 15:18:41 -04001215 }
1216
Adam Lesinski182f73f2013-12-05 16:48:06 -08001217 @Override
Tony Mak7d4b3a52018-11-27 17:29:36 +00001218 public void onNotificationActionClick(
1219 String key, int actionIndex, Notification.Action action, NotificationVisibility nv,
1220 boolean generatedByAssistant) {
Christoph Studer4da84cd2014-10-21 17:24:20 +02001221 enforceStatusBarService();
1222 final int callingUid = Binder.getCallingUid();
1223 final int callingPid = Binder.getCallingPid();
1224 long identity = Binder.clearCallingIdentity();
1225 try {
1226 mNotificationDelegate.onNotificationActionClick(callingUid, callingPid, key,
Tony Mak7d4b3a52018-11-27 17:29:36 +00001227 actionIndex, action, nv, generatedByAssistant);
Christoph Studer4da84cd2014-10-21 17:24:20 +02001228 } finally {
1229 Binder.restoreCallingIdentity(identity);
1230 }
1231 }
1232
1233 @Override
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -07001234 public void onNotificationError(String pkg, String tag, int id,
Kenny Guy3a7c4a52014-03-03 18:24:03 +00001235 int uid, int initialPid, String message, int userId) {
Joe Onorato8bc6c512010-06-04 16:21:12 -04001236 enforceStatusBarService();
John Spurlocke6a7d932014-03-13 12:29:00 -04001237 final int callingUid = Binder.getCallingUid();
1238 final int callingPid = Binder.getCallingPid();
Adam Lesinski182f73f2013-12-05 16:48:06 -08001239 long identity = Binder.clearCallingIdentity();
1240 try {
1241 // WARNING: this will call back into us to do the remove. Don't hold any locks.
John Spurlocke6a7d932014-03-13 12:29:00 -04001242 mNotificationDelegate.onNotificationError(callingUid, callingPid,
1243 pkg, tag, id, uid, initialPid, message, userId);
Adam Lesinski182f73f2013-12-05 16:48:06 -08001244 } finally {
1245 Binder.restoreCallingIdentity(identity);
1246 }
Joe Onorato005847b2010-06-04 16:08:02 -04001247 }
1248
Adam Lesinski182f73f2013-12-05 16:48:06 -08001249 @Override
Julia Reynolds503ed942017-10-04 16:04:56 -04001250 public void onNotificationClear(String pkg, String tag, int id, int userId, String key,
Julia Reynoldsfd4099d2018-08-21 11:06:06 -04001251 @NotificationStats.DismissalSurface int dismissalSurface,
1252 @NotificationStats.DismissalSentiment int dismissalSentiment,
1253 NotificationVisibility nv) {
Daniel Sandler0f0b11c2010-08-04 15:54:58 -04001254 enforceStatusBarService();
John Spurlocke6a7d932014-03-13 12:29:00 -04001255 final int callingUid = Binder.getCallingUid();
1256 final int callingPid = Binder.getCallingPid();
Adam Lesinski182f73f2013-12-05 16:48:06 -08001257 long identity = Binder.clearCallingIdentity();
1258 try {
Dieter Hsud39f0d52018-04-14 02:08:30 +08001259 mNotificationDelegate.onNotificationClear(callingUid, callingPid, pkg, tag, id, userId,
Julia Reynoldsfd4099d2018-08-21 11:06:06 -04001260 key, dismissalSurface, dismissalSentiment, nv);
Adam Lesinski182f73f2013-12-05 16:48:06 -08001261 } finally {
1262 Binder.restoreCallingIdentity(identity);
1263 }
Daniel Sandler0f0b11c2010-08-04 15:54:58 -04001264 }
1265
Adam Lesinski182f73f2013-12-05 16:48:06 -08001266 @Override
Christoph Studer92b389d2014-04-01 18:44:40 +02001267 public void onNotificationVisibilityChanged(
Chris Wrend1dbc922015-06-19 17:51:16 -04001268 NotificationVisibility[] newlyVisibleKeys, NotificationVisibility[] noLongerVisibleKeys)
1269 throws RemoteException {
Christoph Studer92b389d2014-04-01 18:44:40 +02001270 enforceStatusBarService();
1271 long identity = Binder.clearCallingIdentity();
1272 try {
1273 mNotificationDelegate.onNotificationVisibilityChanged(
1274 newlyVisibleKeys, noLongerVisibleKeys);
1275 } finally {
1276 Binder.restoreCallingIdentity(identity);
1277 }
1278 }
1279
1280 @Override
Gustav Senntona8e38aa2019-01-22 14:55:39 +00001281 public void onNotificationExpansionChanged(String key, boolean userAction, boolean expanded,
1282 int location) throws RemoteException {
Chris Wren78403d72014-07-28 10:23:24 +01001283 enforceStatusBarService();
1284 long identity = Binder.clearCallingIdentity();
1285 try {
1286 mNotificationDelegate.onNotificationExpansionChanged(
Gustav Senntona8e38aa2019-01-22 14:55:39 +00001287 key, userAction, expanded, location);
Chris Wren78403d72014-07-28 10:23:24 +01001288 } finally {
1289 Binder.restoreCallingIdentity(identity);
1290 }
1291 }
1292
1293 @Override
Julia Reynolds503ed942017-10-04 16:04:56 -04001294 public void onNotificationDirectReplied(String key) throws RemoteException {
1295 enforceStatusBarService();
1296 long identity = Binder.clearCallingIdentity();
1297 try {
1298 mNotificationDelegate.onNotificationDirectReplied(key);
1299 } finally {
1300 Binder.restoreCallingIdentity(identity);
1301 }
1302 }
1303
1304 @Override
Gustav Senntond25a64d2018-12-07 10:58:39 +00001305 public void onNotificationSmartSuggestionsAdded(String key, int smartReplyCount,
Milo Sredkov13d88112019-02-01 12:23:24 +00001306 int smartActionCount, boolean generatedByAssistant, boolean editBeforeSending) {
Kenny Guy23991102018-04-05 21:18:38 +01001307 enforceStatusBarService();
1308 long identity = Binder.clearCallingIdentity();
1309 try {
Gustav Senntond25a64d2018-12-07 10:58:39 +00001310 mNotificationDelegate.onNotificationSmartSuggestionsAdded(key, smartReplyCount,
Milo Sredkov13d88112019-02-01 12:23:24 +00001311 smartActionCount, generatedByAssistant, editBeforeSending);
Kenny Guy23991102018-04-05 21:18:38 +01001312 } finally {
1313 Binder.restoreCallingIdentity(identity);
1314 }
1315 }
1316
1317 @Override
Tony Mak29996702018-11-26 16:23:34 +00001318 public void onNotificationSmartReplySent(
Milo Sredkov13d88112019-02-01 12:23:24 +00001319 String key, int replyIndex, CharSequence reply, int notificationLocation,
1320 boolean modifiedBeforeSending) throws RemoteException {
Kenny Guy23991102018-04-05 21:18:38 +01001321 enforceStatusBarService();
1322 long identity = Binder.clearCallingIdentity();
1323 try {
Tony Mak29996702018-11-26 16:23:34 +00001324 mNotificationDelegate.onNotificationSmartReplySent(key, replyIndex, reply,
Milo Sredkov13d88112019-02-01 12:23:24 +00001325 notificationLocation, modifiedBeforeSending);
Kenny Guy23991102018-04-05 21:18:38 +01001326 } finally {
1327 Binder.restoreCallingIdentity(identity);
1328 }
1329 }
1330
1331 @Override
Julia Reynolds503ed942017-10-04 16:04:56 -04001332 public void onNotificationSettingsViewed(String key) throws RemoteException {
1333 enforceStatusBarService();
1334 long identity = Binder.clearCallingIdentity();
1335 try {
1336 mNotificationDelegate.onNotificationSettingsViewed(key);
1337 } finally {
1338 Binder.restoreCallingIdentity(identity);
1339 }
1340 }
1341
1342 @Override
Kenny Guy3a7c4a52014-03-03 18:24:03 +00001343 public void onClearAllNotifications(int userId) {
Joe Onorato8bc6c512010-06-04 16:21:12 -04001344 enforceStatusBarService();
John Spurlocke6a7d932014-03-13 12:29:00 -04001345 final int callingUid = Binder.getCallingUid();
1346 final int callingPid = Binder.getCallingPid();
Adam Lesinski182f73f2013-12-05 16:48:06 -08001347 long identity = Binder.clearCallingIdentity();
1348 try {
John Spurlocke6a7d932014-03-13 12:29:00 -04001349 mNotificationDelegate.onClearAll(callingUid, callingPid, userId);
Adam Lesinski182f73f2013-12-05 16:48:06 -08001350 } finally {
1351 Binder.restoreCallingIdentity(identity);
Joe Onorato18e69df2010-05-17 22:26:12 -07001352 }
Joe Onorato0cbda992010-05-02 16:28:15 -07001353 }
1354
Jason Monk7e53f202016-01-28 10:40:20 -05001355 @Override
Mady Mellora54e9fa2019-04-18 13:26:18 -07001356 public void onNotificationBubbleChanged(String key, boolean isBubble) {
1357 enforceStatusBarService();
1358 long identity = Binder.clearCallingIdentity();
1359 try {
1360 mNotificationDelegate.onNotificationBubbleChanged(key, isBubble);
1361 } finally {
1362 Binder.restoreCallingIdentity(identity);
1363 }
1364 }
1365
1366 @Override
Mady Mellorf44b6832020-01-14 13:26:14 -08001367 public void onBubbleNotificationSuppressionChanged(String key, boolean isNotifSuppressed) {
1368 enforceStatusBarService();
1369 long identity = Binder.clearCallingIdentity();
1370 try {
1371 mNotificationDelegate.onBubbleNotificationSuppressionChanged(key, isNotifSuppressed);
1372 } finally {
1373 Binder.restoreCallingIdentity(identity);
1374 }
1375 }
1376
1377 @Override
Aran Ink979c9762019-10-24 16:09:45 -04001378 public void grantInlineReplyUriPermission(String key, Uri uri, UserHandle user,
1379 String packageName) {
Aran Inkfd2bfd32019-10-04 16:30:01 -04001380 enforceStatusBarService();
1381 int callingUid = Binder.getCallingUid();
1382 long identity = Binder.clearCallingIdentity();
1383 try {
Aran Ink979c9762019-10-24 16:09:45 -04001384 mNotificationDelegate.grantInlineReplyUriPermission(key, uri, user, packageName,
1385 callingUid);
1386 } finally {
1387 Binder.restoreCallingIdentity(identity);
1388 }
1389 }
1390
1391 @Override
1392 public void clearInlineReplyUriPermissions(String key) {
1393 enforceStatusBarService();
1394 int callingUid = Binder.getCallingUid();
1395 long identity = Binder.clearCallingIdentity();
1396 try {
1397 mNotificationDelegate.clearInlineReplyUriPermissions(key, callingUid);
Aran Inkfd2bfd32019-10-04 16:30:01 -04001398 } finally {
1399 Binder.restoreCallingIdentity(identity);
1400 }
1401 }
1402
1403 @Override
Jason Monk7e53f202016-01-28 10:40:20 -05001404 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
Dianne Hackborn354736e2016-08-22 17:00:05 -07001405 String[] args, ShellCallback callback, ResultReceiver resultReceiver) {
Evan Lairdedd016f2019-01-23 18:36:29 -05001406 (new StatusBarShellCommand(this, mContext)).exec(
Dianne Hackborn354736e2016-08-22 17:00:05 -07001407 this, in, out, err, args, callback, resultReceiver);
Jason Monk7e53f202016-01-28 10:40:20 -05001408 }
1409
Robert Horvath5560f382019-07-10 10:46:38 +02001410 @Override
1411 public void showInattentiveSleepWarning() {
1412 enforceStatusBarService();
1413 if (mBar != null) {
1414 try {
1415 mBar.showInattentiveSleepWarning();
1416 } catch (RemoteException ex) {
1417 }
1418 }
1419 }
1420
1421 @Override
Robert Horvath60e51fe2019-08-20 13:10:34 +02001422 public void dismissInattentiveSleepWarning(boolean animated) {
Robert Horvath5560f382019-07-10 10:46:38 +02001423 enforceStatusBarService();
1424 if (mBar != null) {
1425 try {
Robert Horvath60e51fe2019-08-20 13:10:34 +02001426 mBar.dismissInattentiveSleepWarning(animated);
Robert Horvath5560f382019-07-10 10:46:38 +02001427 } catch (RemoteException ex) {
1428 }
1429 }
1430 }
1431
Jason Monkf8c2f7b2017-09-06 09:22:29 -04001432 public String[] getStatusBarIcons() {
1433 return mContext.getResources().getStringArray(R.array.config_statusBarIcons);
1434 }
1435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001436 // ================================================================================
1437 // Can be called from any thread
1438 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001439
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001440 // lock on mDisableRecords
Benjamin Franzcde0a2a2015-04-23 17:19:48 +01001441 void manageDisableListLocked(int userId, int what, IBinder token, String pkg, int which) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001442 if (SPEW) {
John Spurlock13451a22012-09-28 14:40:41 -04001443 Slog.d(TAG, "manageDisableList userId=" + userId
1444 + " what=0x" + Integer.toHexString(what) + " pkg=" + pkg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001445 }
Charles Heede39092017-09-18 09:19:28 +01001446
1447 // Find matching record, if any
Evan Lairdedd016f2019-01-23 18:36:29 -05001448 Pair<Integer, DisableRecord> match = findMatchingRecordLocked(token, userId);
1449 int i = match.first;
1450 DisableRecord record = match.second;
Charles Heede39092017-09-18 09:19:28 +01001451
1452 // Remove record if binder is already dead
1453 if (!token.isBinderAlive()) {
1454 if (record != null) {
Joe Onorato7bb8eeb2011-01-27 16:00:58 -08001455 mDisableRecords.remove(i);
Charles Heede39092017-09-18 09:19:28 +01001456 record.token.unlinkToDeath(record, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001457 }
Charles Heede39092017-09-18 09:19:28 +01001458 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001459 }
Charles Heede39092017-09-18 09:19:28 +01001460
1461 // Update existing record
1462 if (record != null) {
1463 record.setFlags(what, which, pkg);
1464 if (record.isEmpty()) {
1465 mDisableRecords.remove(i);
1466 record.token.unlinkToDeath(record, 0);
1467 }
1468 return;
1469 }
1470
1471 // Record doesn't exist, so we create a new one
1472 record = new DisableRecord(userId, token);
1473 record.setFlags(what, which, pkg);
1474 mDisableRecords.add(record);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001475 }
1476
Evan Lairdedd016f2019-01-23 18:36:29 -05001477 @Nullable
1478 @GuardedBy("mLock")
1479 private Pair<Integer, DisableRecord> findMatchingRecordLocked(IBinder token, int userId) {
1480 final int numRecords = mDisableRecords.size();
1481 DisableRecord record = null;
1482 int i;
1483 for (i = 0; i < numRecords; i++) {
1484 DisableRecord r = mDisableRecords.get(i);
1485 if (r.token == token && r.userId == userId) {
1486 record = r;
1487 break;
1488 }
1489 }
1490
1491 return new Pair<Integer, DisableRecord>(i, record);
1492 }
1493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001494 // lock on mDisableRecords
Benjamin Franzcde0a2a2015-04-23 17:19:48 +01001495 int gatherDisableActionsLocked(int userId, int which) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001496 final int N = mDisableRecords.size();
1497 // gather the new net flags
1498 int net = 0;
1499 for (int i=0; i<N; i++) {
John Spurlock13451a22012-09-28 14:40:41 -04001500 final DisableRecord rec = mDisableRecords.get(i);
1501 if (rec.userId == userId) {
Charles Heede39092017-09-18 09:19:28 +01001502 net |= rec.getFlags(which);
John Spurlock13451a22012-09-28 14:40:41 -04001503 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001504 }
1505 return net;
1506 }
1507
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001508 // ================================================================================
1509 // Always called from UI thread
1510 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001512 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001513 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Joe Onorato0cbda992010-05-02 16:28:15 -07001514
Joe Onorato7bb8eeb2011-01-27 16:00:58 -08001515 synchronized (mLock) {
Charles Chen24e7a9f2018-11-21 11:59:07 +08001516 for (int i = 0; i < mDisplayUiState.size(); i++) {
1517 final int key = mDisplayUiState.keyAt(i);
1518 final UiState state = mDisplayUiState.get(key);
1519 pw.println(" displayId=" + key);
1520 pw.println(" mDisabled1=0x" + Integer.toHexString(state.getDisabled1()));
1521 pw.println(" mDisabled2=0x" + Integer.toHexString(state.getDisabled2()));
1522 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001523 final int N = mDisableRecords.size();
John Spurlock13451a22012-09-28 14:40:41 -04001524 pw.println(" mDisableRecords.size=" + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001525 for (int i=0; i<N; i++) {
1526 DisableRecord tok = mDisableRecords.get(i);
Charles Heede39092017-09-18 09:19:28 +01001527 pw.println(" [" + i + "] " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001528 }
Adrian Roos2a629102016-04-15 16:28:03 -07001529 pw.println(" mCurrentUserId=" + mCurrentUserId);
Dan Sandlerf3a1f2c2016-06-26 15:59:13 -04001530 pw.println(" mIcons=");
1531 for (String slot : mIcons.keySet()) {
1532 pw.println(" ");
1533 pw.print(slot);
1534 pw.print(" -> ");
1535 final StatusBarIcon icon = mIcons.get(slot);
1536 pw.print(icon);
1537 if (!TextUtils.isEmpty(icon.contentDescription)) {
1538 pw.print(" \"");
1539 pw.print(icon.contentDescription);
1540 pw.print("\"");
1541 }
1542 pw.println();
1543 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001544 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001545 }
Michael Wright6cd10262017-04-04 17:44:56 +01001546
1547 private static final Context getUiContext() {
1548 return ActivityThread.currentActivityThread().getSystemUiContext();
1549 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001550}