blob: 6ea08fe1a19d1083b7e95c702f1b9b71ab3697d9 [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;
Tony Mak7d4b3a52018-11-27 17:29:36 +000024import android.app.Notification;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.app.StatusBarManager;
Jason Monk7e53f202016-01-28 10:40:20 -050026import android.content.ComponentName;
Jason Monk07473ce2016-01-05 14:59:19 -050027import android.content.Context;
Kevin Chyn23289ef2018-11-28 16:32:36 -080028import android.hardware.biometrics.IBiometricServiceReceiverInternal;
Charles Chen24e7a9f2018-11-21 11:59:07 +080029import android.hardware.display.DisplayManager;
30import android.hardware.display.DisplayManager.DisplayListener;
Aran Inkfd2bfd32019-10-04 16:30:01 -040031import android.net.Uri;
Adam Lesinski182f73f2013-12-05 16:48:06 -080032import android.os.Binder;
Jorim Jaggi165ce062015-07-06 16:18:11 -070033import android.os.Bundle;
Adam Lesinski182f73f2013-12-05 16:48:06 -080034import android.os.Handler;
35import android.os.IBinder;
Jason Monk361915c2017-03-21 20:33:59 -040036import android.os.PowerManager;
Jason Monk7e53f202016-01-28 10:40:20 -050037import android.os.Process;
Adam Lesinski182f73f2013-12-05 16:48:06 -080038import android.os.RemoteException;
Jason Monk7e53f202016-01-28 10:40:20 -050039import android.os.ResultReceiver;
Dianne Hackborn354736e2016-08-22 17:00:05 -070040import android.os.ShellCallback;
Adam Lesinski182f73f2013-12-05 16:48:06 -080041import android.os.UserHandle;
Julia Reynolds503ed942017-10-04 16:04:56 -040042import android.service.notification.NotificationStats;
Dan Sandlerf3a1f2c2016-06-26 15:59:13 -040043import android.text.TextUtils;
Jason Monk07473ce2016-01-05 14:59:19 -050044import android.util.ArrayMap;
Tiger Huang0dbd5372019-10-26 00:24:22 +080045import android.util.ArraySet;
Evan Lairdedd016f2019-01-23 18:36:29 -050046import android.util.Pair;
Joe Onorato8a9b2202010-02-26 18:56:32 -080047import android.util.Slog;
Charles Chen24e7a9f2018-11-21 11:59:07 +080048import android.util.SparseArray;
Tiger Huang0dbd5372019-10-26 00:24:22 +080049import android.view.InsetsState.InternalInsetType;
Jorim Jaggi956ca412019-01-07 14:49:14 +010050import android.view.WindowInsetsController.Appearance;
Jim Miller07e03842016-06-22 15:18:13 -070051
Jason Monkb4302182017-08-04 13:39:17 -040052import com.android.internal.R;
Evan Lairdedd016f2019-01-23 18:36:29 -050053import com.android.internal.annotations.GuardedBy;
Joe Onorato0cbda992010-05-02 16:28:15 -070054import com.android.internal.statusbar.IStatusBar;
55import com.android.internal.statusbar.IStatusBarService;
Chris Wrend1dbc922015-06-19 17:51:16 -040056import com.android.internal.statusbar.NotificationVisibility;
Yohei Yukawa49efa712019-04-04 11:49:02 -070057import com.android.internal.statusbar.RegisterStatusBarResult;
Joe Onorato0cbda992010-05-02 16:28:15 -070058import com.android.internal.statusbar.StatusBarIcon;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060059import com.android.internal.util.DumpUtils;
Jorim Jaggi956ca412019-01-07 14:49:14 +010060import com.android.internal.view.AppearanceRegion;
Adam Lesinski182f73f2013-12-05 16:48:06 -080061import com.android.server.LocalServices;
62import com.android.server.notification.NotificationDelegate;
Michael Kwan2decbf72018-02-22 07:40:11 -080063import com.android.server.policy.GlobalActionsProvider;
Jason Monk361915c2017-03-21 20:33:59 -040064import com.android.server.power.ShutdownThread;
Dianne Hackborna924dc0d2011-02-17 14:22:17 -080065import com.android.server.wm.WindowManagerService;
The Android Open Source Project10592532009-03-18 17:39:46 -070066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067import java.io.FileDescriptor;
68import java.io.PrintWriter;
69import java.util.ArrayList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071/**
Joe Onoratof3f0e052010-05-14 18:49:29 -070072 * A note on locking: We rely on the fact that calls onto mBar are oneway or
73 * if they are local, that they just enqueue messages to not deadlock.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074 */
Charles Chen24e7a9f2018-11-21 11:59:07 +080075public class StatusBarManagerService extends IStatusBarService.Stub implements DisplayListener {
Adam Lesinski182f73f2013-12-05 16:48:06 -080076 private static final String TAG = "StatusBarManagerService";
77 private static final boolean SPEW = false;
Joe Onoratodf7dbb62009-11-17 10:43:37 -080078
Adam Lesinski182f73f2013-12-05 16:48:06 -080079 private final Context mContext;
Adam Lesinskia82b6262017-03-21 16:56:17 -070080
Adam Lesinski182f73f2013-12-05 16:48:06 -080081 private final WindowManagerService mWindowManager;
82 private Handler mHandler = new Handler();
83 private NotificationDelegate mNotificationDelegate;
84 private volatile IStatusBar mBar;
Jason Monk07473ce2016-01-05 14:59:19 -050085 private ArrayMap<String, StatusBarIcon> mIcons = new ArrayMap<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086
Joe Onoratof3f0e052010-05-14 18:49:29 -070087 // for disabling the status bar
Adam Lesinski182f73f2013-12-05 16:48:06 -080088 private final ArrayList<DisableRecord> mDisableRecords = new ArrayList<DisableRecord>();
Michael Kwan2decbf72018-02-22 07:40:11 -080089 private GlobalActionsProvider.GlobalActionsListener mGlobalActionListener;
Adam Lesinski182f73f2013-12-05 16:48:06 -080090 private IBinder mSysUiVisToken = new Binder();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091
Adrian Roos2a629102016-04-15 16:28:03 -070092 private final Object mLock = new Object();
Gopal Krishna Shuklae5c83792018-06-29 18:20:36 +053093 private final DeathRecipient mDeathRecipient = new DeathRecipient();
Adam Lesinski182f73f2013-12-05 16:48:06 -080094 private int mCurrentUserId;
satok06487a52010-10-29 11:37:18 +090095
Charles Chen24e7a9f2018-11-21 11:59:07 +080096 private SparseArray<UiState> mDisplayUiState = new SparseArray<>();
97
Gopal Krishna Shuklae5c83792018-06-29 18:20:36 +053098 private class DeathRecipient implements IBinder.DeathRecipient {
99 public void binderDied() {
100 mBar.asBinder().unlinkToDeath(this,0);
101 mBar = null;
102 notifyBarAttachChanged();
103 }
104
105 public void linkToDeath() {
106 try {
107 mBar.asBinder().linkToDeath(mDeathRecipient,0);
108 } catch (RemoteException e) {
109 Slog.e(TAG,"Unable to register Death Recipient for status bar", e);
110 }
111 }
112
113 }
114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 private class DisableRecord implements IBinder.DeathRecipient {
John Spurlock13451a22012-09-28 14:40:41 -0400116 int userId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 String pkg;
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100118 int what1;
119 int what2;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120 IBinder token;
121
Charles Heede39092017-09-18 09:19:28 +0100122 public DisableRecord(int userId, IBinder token) {
123 this.userId = userId;
124 this.token = token;
125 try {
126 token.linkToDeath(this, 0);
127 } catch (RemoteException re) {
128 // Give up
129 }
130 }
131
132 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 public void binderDied() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800134 Slog.i(TAG, "binder died for pkg=" + pkg);
Benjamin Franzea2ec972015-03-16 17:18:09 +0000135 disableForUser(0, token, pkg, userId);
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100136 disable2ForUser(0, token, pkg, userId);
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -0700137 token.unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 }
Charles Heede39092017-09-18 09:19:28 +0100139
140 public void setFlags(int what, int which, String pkg) {
141 switch (which) {
142 case 1:
143 what1 = what;
JiangDongyab1352cd2018-11-09 18:23:54 +0800144 break;
Charles Heede39092017-09-18 09:19:28 +0100145 case 2:
146 what2 = what;
JiangDongyab1352cd2018-11-09 18:23:54 +0800147 break;
Charles Heede39092017-09-18 09:19:28 +0100148 default:
149 Slog.w(TAG, "Can't set unsupported disable flag " + which
150 + ": 0x" + Integer.toHexString(what));
JiangDongyab1352cd2018-11-09 18:23:54 +0800151 break;
Charles Heede39092017-09-18 09:19:28 +0100152 }
153 this.pkg = pkg;
154 }
155
156 public int getFlags(int which) {
157 switch (which) {
158 case 1: return what1;
159 case 2: return what2;
160 default:
161 Slog.w(TAG, "Can't get unsupported disable flag " + which);
162 return 0;
163 }
164 }
165
166 public boolean isEmpty() {
167 return what1 == 0 && what2 == 0;
168 }
169
170 @Override
171 public String toString() {
172 return String.format("userId=%d what1=0x%08X what2=0x%08X pkg=%s token=%s",
173 userId, what1, what2, pkg, token);
174 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175 }
176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 /**
178 * Construct the service, add the status bar view to the window manager
179 */
Jeff Brown2992ea72011-01-28 22:04:14 -0800180 public StatusBarManagerService(Context context, WindowManagerService windowManager) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 mContext = context;
Jeff Brown2992ea72011-01-28 22:04:14 -0800182 mWindowManager = windowManager;
Joe Onorato0cbda992010-05-02 16:28:15 -0700183
Adam Lesinski182f73f2013-12-05 16:48:06 -0800184 LocalServices.addService(StatusBarManagerInternal.class, mInternalService);
Michael Kwan2decbf72018-02-22 07:40:11 -0800185 LocalServices.addService(GlobalActionsProvider.class, mGlobalActionsProvider);
Charles Chen24e7a9f2018-11-21 11:59:07 +0800186
187 // We always have a default display.
188 final UiState state = new UiState();
189 mDisplayUiState.put(DEFAULT_DISPLAY, state);
190
191 final DisplayManager displayManager =
192 (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
193 displayManager.registerDisplayListener(this, mHandler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194 }
195
Charles Chen24e7a9f2018-11-21 11:59:07 +0800196 @Override
197 public void onDisplayAdded(int displayId) {}
198
199 @Override
200 public void onDisplayRemoved(int displayId) {
201 synchronized (mLock) {
202 mDisplayUiState.remove(displayId);
203 }
204 }
205
206 @Override
207 public void onDisplayChanged(int displayId) {}
208
Adam Lesinski182f73f2013-12-05 16:48:06 -0800209 /**
210 * Private API used by NotificationManagerService.
211 */
212 private final StatusBarManagerInternal mInternalService = new StatusBarManagerInternal() {
John Spurlockcb566aa2014-08-03 22:58:28 -0400213 private boolean mNotificationLightOn;
214
Adam Lesinski182f73f2013-12-05 16:48:06 -0800215 @Override
216 public void setNotificationDelegate(NotificationDelegate delegate) {
Christoph Studere71fefc2014-06-24 16:16:49 +0200217 mNotificationDelegate = delegate;
Adam Lesinski182f73f2013-12-05 16:48:06 -0800218 }
John Spurlockcb566aa2014-08-03 22:58:28 -0400219
John Spurlockcad57682014-07-26 17:09:56 -0400220 @Override
Andrii Kulian0f051f52016-04-14 00:41:51 -0700221 public void showScreenPinningRequest(int taskId) {
Jason Monk5565cb42014-09-12 10:59:21 -0400222 if (mBar != null) {
223 try {
Andrii Kulian0f051f52016-04-14 00:41:51 -0700224 mBar.showScreenPinningRequest(taskId);
Jason Monk5565cb42014-09-12 10:59:21 -0400225 } catch (RemoteException e) {
226 }
227 }
228 }
Adrian Roos4f43dc02015-06-17 16:43:38 -0700229
230 @Override
231 public void showAssistDisclosure() {
232 if (mBar != null) {
233 try {
234 mBar.showAssistDisclosure();
235 } catch (RemoteException e) {
236 }
237 }
238 }
Jorim Jaggi165ce062015-07-06 16:18:11 -0700239
240 @Override
241 public void startAssist(Bundle args) {
242 if (mBar != null) {
243 try {
244 mBar.startAssist(args);
245 } catch (RemoteException e) {
246 }
247 }
248 }
Selim Cinek372d1bd2015-08-14 13:19:37 -0700249
250 @Override
Jorim Jaggi40aa8812015-09-23 12:59:22 -0700251 public void onCameraLaunchGestureDetected(int source) {
Selim Cinek372d1bd2015-08-14 13:19:37 -0700252 if (mBar != null) {
253 try {
Jorim Jaggi40aa8812015-09-23 12:59:22 -0700254 mBar.onCameraLaunchGestureDetected(source);
Selim Cinek372d1bd2015-08-14 13:19:37 -0700255 } catch (RemoteException e) {
256 }
257 }
258 }
Jorim Jaggi86905582016-02-09 21:36:09 -0800259
260 @Override
Jorim Jaggi956ca412019-01-07 14:49:14 +0100261 public void topAppWindowChanged(int displayId, boolean isFullscreen, boolean isImmersive) {
262 StatusBarManagerService.this.topAppWindowChanged(displayId, isFullscreen, isImmersive);
Jorim Jaggi86905582016-02-09 21:36:09 -0800263 }
264
265 @Override
Tiger Huang0dbd5372019-10-26 00:24:22 +0800266 public void setDisableFlags(int displayId, int flags, String cause) {
267 StatusBarManagerService.this.setDisableFlags(displayId, flags, cause);
Jorim Jaggi86905582016-02-09 21:36:09 -0800268 }
Phil Weaver315c34e2016-02-19 15:12:29 -0800269
270 @Override
271 public void toggleSplitScreen() {
272 enforceStatusBarService();
273 if (mBar != null) {
274 try {
275 mBar.toggleSplitScreen();
276 } catch (RemoteException ex) {}
277 }
278 }
Jorim Jaggi2adba072016-03-03 13:43:39 +0100279
Tiger Huang7c610aa2018-10-27 00:01:01 +0800280 @Override
281 public void appTransitionFinished(int displayId) {
Jorim Jaggi2adba072016-03-03 13:43:39 +0100282 enforceStatusBarService();
283 if (mBar != null) {
284 try {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800285 mBar.appTransitionFinished(displayId);
Jorim Jaggi2adba072016-03-03 13:43:39 +0100286 } catch (RemoteException ex) {}
287 }
288 }
Adrian Roosf2efdd82016-04-15 17:43:18 -0700289
290 @Override
291 public void toggleRecentApps() {
292 if (mBar != null) {
293 try {
294 mBar.toggleRecentApps();
295 } catch (RemoteException ex) {}
296 }
297 }
298
299 @Override
300 public void setCurrentUser(int newUserId) {
301 if (SPEW) Slog.d(TAG, "Setting current user to user " + newUserId);
302 mCurrentUserId = newUserId;
303 }
304
305
306 @Override
307 public void preloadRecentApps() {
308 if (mBar != null) {
309 try {
310 mBar.preloadRecentApps();
311 } catch (RemoteException ex) {}
312 }
313 }
314
315 @Override
316 public void cancelPreloadRecentApps() {
317 if (mBar != null) {
318 try {
319 mBar.cancelPreloadRecentApps();
320 } catch (RemoteException ex) {}
321 }
322 }
323
324 @Override
Winson Chungdff7a732017-12-11 12:17:06 -0800325 public void showRecentApps(boolean triggeredFromAltTab) {
Adrian Roosf2efdd82016-04-15 17:43:18 -0700326 if (mBar != null) {
327 try {
Winson Chungdff7a732017-12-11 12:17:06 -0800328 mBar.showRecentApps(triggeredFromAltTab);
Adrian Roosf2efdd82016-04-15 17:43:18 -0700329 } catch (RemoteException ex) {}
330 }
331 }
332
333 @Override
334 public void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) {
335 if (mBar != null) {
336 try {
337 mBar.hideRecentApps(triggeredFromAltTab, triggeredFromHomeKey);
338 } catch (RemoteException ex) {}
339 }
340 }
341
342 @Override
Andrei Stingaceanu0bf096f2016-04-14 18:11:57 +0100343 public void dismissKeyboardShortcutsMenu() {
344 if (mBar != null) {
345 try {
346 mBar.dismissKeyboardShortcutsMenu();
347 } catch (RemoteException ex) {}
348 }
349 }
350
351 @Override
Adrian Roosf2efdd82016-04-15 17:43:18 -0700352 public void toggleKeyboardShortcutsMenu(int deviceId) {
353 if (mBar != null) {
354 try {
355 mBar.toggleKeyboardShortcutsMenu(deviceId);
356 } catch (RemoteException ex) {}
357 }
358 }
359
360 @Override
Beverlyae79ab92017-12-11 09:20:02 -0500361 public void showChargingAnimation(int batteryLevel) {
362 if (mBar != null) {
363 try {
Beverlyac32c9a2018-01-31 16:10:41 -0500364 mBar.showWirelessChargingAnimation(batteryLevel);
Beverlyae79ab92017-12-11 09:20:02 -0500365 } catch (RemoteException ex){
366 }
367 }
368 }
369
370 @Override
Winson Chungac52f282017-03-30 14:44:52 -0700371 public void showPictureInPictureMenu() {
Adrian Roosf2efdd82016-04-15 17:43:18 -0700372 if (mBar != null) {
373 try {
Winson Chungac52f282017-03-30 14:44:52 -0700374 mBar.showPictureInPictureMenu();
Adrian Roosf2efdd82016-04-15 17:43:18 -0700375 } catch (RemoteException ex) {}
376 }
377 }
378
379 @Override
Tiger Huang7c610aa2018-10-27 00:01:01 +0800380 public void setWindowState(int displayId, int window, int state) {
Adrian Roosf2efdd82016-04-15 17:43:18 -0700381 if (mBar != null) {
382 try {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800383 mBar.setWindowState(displayId, window, state);
Adrian Roosf2efdd82016-04-15 17:43:18 -0700384 } catch (RemoteException ex) {}
385 }
386 }
387
388 @Override
Tiger Huang7c610aa2018-10-27 00:01:01 +0800389 public void appTransitionPending(int displayId) {
Adrian Roosf2efdd82016-04-15 17:43:18 -0700390 if (mBar != null) {
391 try {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800392 mBar.appTransitionPending(displayId);
Adrian Roosf2efdd82016-04-15 17:43:18 -0700393 } catch (RemoteException ex) {}
394 }
395 }
396
397 @Override
Tiger Huang7c610aa2018-10-27 00:01:01 +0800398 public void appTransitionCancelled(int displayId) {
Adrian Roosf2efdd82016-04-15 17:43:18 -0700399 if (mBar != null) {
400 try {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800401 mBar.appTransitionCancelled(displayId);
Adrian Roosf2efdd82016-04-15 17:43:18 -0700402 } catch (RemoteException ex) {}
403 }
404 }
405
406 @Override
Tiger Huang7c610aa2018-10-27 00:01:01 +0800407 public void appTransitionStarting(int displayId, long statusBarAnimationsStartTime,
Adrian Roosf2efdd82016-04-15 17:43:18 -0700408 long statusBarAnimationsDuration) {
409 if (mBar != null) {
410 try {
411 mBar.appTransitionStarting(
Charles Chen24e7a9f2018-11-21 11:59:07 +0800412 displayId, statusBarAnimationsStartTime, statusBarAnimationsDuration);
Adrian Roosf2efdd82016-04-15 17:43:18 -0700413 } catch (RemoteException ex) {}
414 }
415 }
Jason Monk361915c2017-03-21 20:33:59 -0400416
417 @Override
Selim Cinek3a49ba22017-08-10 11:17:39 -0700418 public void setTopAppHidesStatusBar(boolean hidesStatusBar) {
419 if (mBar != null) {
420 try {
421 mBar.setTopAppHidesStatusBar(hidesStatusBar);
422 } catch (RemoteException ex) {}
423 }
424 }
425
426 @Override
Jason Monkb4302182017-08-04 13:39:17 -0400427 public boolean showShutdownUi(boolean isReboot, String reason) {
428 if (!mContext.getResources().getBoolean(R.bool.config_showSysuiShutdown)) {
429 return false;
430 }
431 if (mBar != null) {
432 try {
433 mBar.showShutdownUi(isReboot, reason);
434 return true;
435 } catch (RemoteException ex) {}
436 }
437 return false;
438 }
Mike Digman93f08342017-11-24 21:46:53 -0800439
Charles Chen24e7a9f2018-11-21 11:59:07 +0800440 // TODO(b/118592525): support it per display if necessary.
Mike Digman93f08342017-11-24 21:46:53 -0800441 @Override
Mike Digmane0777312018-01-19 12:41:51 -0800442 public void onProposedRotationChanged(int rotation, boolean isValid) {
Mike Digman93f08342017-11-24 21:46:53 -0800443 if (mBar != null){
444 try {
Mike Digmane0777312018-01-19 12:41:51 -0800445 mBar.onProposedRotationChanged(rotation, isValid);
Mike Digman93f08342017-11-24 21:46:53 -0800446 } catch (RemoteException ex) {}
447 }
448 }
Charles Chen3dedec32019-01-24 22:19:37 +0800449
450 @Override
451 public void onDisplayReady(int displayId) {
452 if (mBar != null) {
453 try {
454 mBar.onDisplayReady(displayId);
Winson Chung67e49362019-05-17 16:40:38 -0700455 } catch (RemoteException ex) {}
Charles Chen3dedec32019-01-24 22:19:37 +0800456 }
457 }
Winson Chung67e49362019-05-17 16:40:38 -0700458
459 @Override
460 public void onRecentsAnimationStateChanged(boolean running) {
461 if (mBar != null) {
462 try {
463 mBar.onRecentsAnimationStateChanged(running);
464 } catch (RemoteException ex) {}
465 }
466
467 }
Jorim Jaggi956ca412019-01-07 14:49:14 +0100468
469 @Override
470 public void onSystemBarAppearanceChanged(int displayId, @Appearance int appearance,
471 AppearanceRegion[] appearanceRegions, boolean navbarColorManagedByIme) {
Tiger Huang0dbd5372019-10-26 00:24:22 +0800472 final UiState state = getUiState(displayId);
473 if (!state.appearanceEquals(appearance, appearanceRegions, navbarColorManagedByIme)) {
474 state.setAppearance(appearance, appearanceRegions, navbarColorManagedByIme);
475 }
Jorim Jaggi956ca412019-01-07 14:49:14 +0100476 if (mBar != null) {
477 try {
478 mBar.onSystemBarAppearanceChanged(displayId, appearance, appearanceRegions,
479 navbarColorManagedByIme);
480 } catch (RemoteException ex) { }
481 }
482 }
483
484 @Override
Tiger Huang0dbd5372019-10-26 00:24:22 +0800485 public void showTransient(int displayId, @InternalInsetType int[] types) {
486 getUiState(displayId).showTransient(types);
Jorim Jaggi956ca412019-01-07 14:49:14 +0100487 if (mBar != null) {
488 try {
489 mBar.showTransient(displayId, types);
490 } catch (RemoteException ex) { }
491 }
492 }
493
494 @Override
Tiger Huang0dbd5372019-10-26 00:24:22 +0800495 public void abortTransient(int displayId, @InternalInsetType int[] types) {
496 getUiState(displayId).clearTransient(types);
Jorim Jaggi956ca412019-01-07 14:49:14 +0100497 if (mBar != null) {
498 try {
499 mBar.abortTransient(displayId, types);
500 } catch (RemoteException ex) { }
501 }
502 }
Adam Lesinski182f73f2013-12-05 16:48:06 -0800503 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504
Michael Kwan2decbf72018-02-22 07:40:11 -0800505 private final GlobalActionsProvider mGlobalActionsProvider = new GlobalActionsProvider() {
506 @Override
507 public boolean isGlobalActionsDisabled() {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800508 // TODO(b/118592525): support global actions for multi-display.
509 final int disabled2 = mDisplayUiState.get(DEFAULT_DISPLAY).getDisabled2();
510 return (disabled2 & DISABLE2_GLOBAL_ACTIONS) != 0;
Michael Kwan2decbf72018-02-22 07:40:11 -0800511 }
512
513 @Override
514 public void setGlobalActionsListener(GlobalActionsProvider.GlobalActionsListener listener) {
515 mGlobalActionListener = listener;
516 mGlobalActionListener.onGlobalActionsAvailableChanged(mBar != null);
517 }
518
519 @Override
520 public void showGlobalActions() {
521 if (mBar != null) {
522 try {
523 mBar.showGlobalActionsMenu();
524 } catch (RemoteException ex) {}
525 }
526 }
527 };
528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800529 // ================================================================================
Joe Onorato25f95f92010-04-08 18:37:10 -0500530 // From IStatusBarService
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800531 // ================================================================================
Adam Lesinski182f73f2013-12-05 16:48:06 -0800532 @Override
Daniel Sandler11cf1782012-09-27 14:03:08 -0400533 public void expandNotificationsPanel() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800534 enforceExpandStatusBar();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700535
536 if (mBar != null) {
537 try {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400538 mBar.animateExpandNotificationsPanel();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700539 } catch (RemoteException ex) {
540 }
541 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800542 }
543
Adam Lesinski182f73f2013-12-05 16:48:06 -0800544 @Override
Daniel Sandler11cf1782012-09-27 14:03:08 -0400545 public void collapsePanels() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800546 enforceExpandStatusBar();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800547
Joe Onorato4762c2d2010-05-17 15:42:59 -0700548 if (mBar != null) {
549 try {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400550 mBar.animateCollapsePanels();
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700551 } catch (RemoteException ex) {
552 }
553 }
554 }
555
Adam Lesinski182f73f2013-12-05 16:48:06 -0800556 @Override
Anthony Chen9ad00e02017-05-12 15:53:36 -0700557 public void togglePanel() {
558 enforceExpandStatusBar();
559
560 if (mBar != null) {
561 try {
562 mBar.togglePanel();
563 } catch (RemoteException ex) {
564 }
565 }
566 }
567
568 @Override
Jason Monka9927322015-12-13 16:22:37 -0500569 public void expandSettingsPanel(String subPanel) {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700570 enforceExpandStatusBar();
571
572 if (mBar != null) {
573 try {
Jason Monka9927322015-12-13 16:22:37 -0500574 mBar.animateExpandSettingsPanel(subPanel);
Joe Onorato4762c2d2010-05-17 15:42:59 -0700575 } catch (RemoteException ex) {
576 }
577 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 }
579
Jason Monk7e53f202016-01-28 10:40:20 -0500580 public void addTile(ComponentName component) {
581 enforceStatusBarOrShell();
582
583 if (mBar != null) {
584 try {
585 mBar.addQsTile(component);
586 } catch (RemoteException ex) {
587 }
588 }
589 }
590
591 public void remTile(ComponentName component) {
592 enforceStatusBarOrShell();
593
594 if (mBar != null) {
595 try {
596 mBar.remQsTile(component);
597 } catch (RemoteException ex) {
598 }
599 }
600 }
601
602 public void clickTile(ComponentName component) {
603 enforceStatusBarOrShell();
604
605 if (mBar != null) {
606 try {
607 mBar.clickQsTile(component);
608 } catch (RemoteException ex) {
609 }
610 }
611 }
612
Adam Lesinski182f73f2013-12-05 16:48:06 -0800613 @Override
Philip Quinnc3a503d2017-07-18 23:23:41 -0700614 public void handleSystemKey(int key) throws RemoteException {
Jim Miller07e03842016-06-22 15:18:13 -0700615 enforceExpandStatusBar();
616
617 if (mBar != null) {
618 try {
Philip Quinnc3a503d2017-07-18 23:23:41 -0700619 mBar.handleSystemKey(key);
Jim Miller07e03842016-06-22 15:18:13 -0700620 } catch (RemoteException ex) {
621 }
622 }
623 }
624
625 @Override
Matthew Ng9c3bce52018-02-01 22:00:31 +0000626 public void showPinningEnterExitToast(boolean entering) throws RemoteException {
627 if (mBar != null) {
628 try {
629 mBar.showPinningEnterExitToast(entering);
630 } catch (RemoteException ex) {
631 }
632 }
633 }
634
635 @Override
636 public void showPinningEscapeToast() throws RemoteException {
637 if (mBar != null) {
638 try {
639 mBar.showPinningEscapeToast();
640 } catch (RemoteException ex) {
641 }
642 }
643 }
644
645 @Override
Kevin Chyn86f1b8e2019-09-24 19:00:49 -0700646 public void showAuthenticationDialog(Bundle bundle, IBiometricServiceReceiverInternal receiver,
647 int biometricModality, boolean requireConfirmation, int userId, String opPackageName) {
Kevin Chyn95c27e02018-09-12 01:46:16 -0700648 enforceBiometricDialog();
Kevin Chynaae4a152018-01-18 11:48:09 -0800649 if (mBar != null) {
650 try {
Kevin Chyn86f1b8e2019-09-24 19:00:49 -0700651 mBar.showAuthenticationDialog(bundle, receiver, biometricModality,
652 requireConfirmation, userId, opPackageName);
Kevin Chynaae4a152018-01-18 11:48:09 -0800653 } catch (RemoteException ex) {
654 }
655 }
656 }
657
658 @Override
Ilya Matyukhin0f9da352019-10-03 14:10:01 -0700659 public void onBiometricAuthenticated() {
Kevin Chyn95c27e02018-09-12 01:46:16 -0700660 enforceBiometricDialog();
Kevin Chynaae4a152018-01-18 11:48:09 -0800661 if (mBar != null) {
662 try {
Ilya Matyukhin0f9da352019-10-03 14:10:01 -0700663 mBar.onBiometricAuthenticated();
Kevin Chynaae4a152018-01-18 11:48:09 -0800664 } catch (RemoteException ex) {
665 }
666 }
667 }
668
669 @Override
Kevin Chyne9275662018-07-23 16:42:06 -0700670 public void onBiometricHelp(String message) {
Kevin Chyn95c27e02018-09-12 01:46:16 -0700671 enforceBiometricDialog();
Kevin Chynaae4a152018-01-18 11:48:09 -0800672 if (mBar != null) {
673 try {
Kevin Chyne9275662018-07-23 16:42:06 -0700674 mBar.onBiometricHelp(message);
Kevin Chynaae4a152018-01-18 11:48:09 -0800675 } catch (RemoteException ex) {
676 }
677 }
678 }
679
680 @Override
Ilya Matyukhin0f9da352019-10-03 14:10:01 -0700681 public void onBiometricError(int modality, int error, int vendorCode) {
Kevin Chyn95c27e02018-09-12 01:46:16 -0700682 enforceBiometricDialog();
Kevin Chynaae4a152018-01-18 11:48:09 -0800683 if (mBar != null) {
684 try {
Ilya Matyukhin0f9da352019-10-03 14:10:01 -0700685 mBar.onBiometricError(modality, error, vendorCode);
Kevin Chynaae4a152018-01-18 11:48:09 -0800686 } catch (RemoteException ex) {
687 }
688 }
689 }
690
691 @Override
Kevin Chyn86f1b8e2019-09-24 19:00:49 -0700692 public void hideAuthenticationDialog() {
Kevin Chyn95c27e02018-09-12 01:46:16 -0700693 enforceBiometricDialog();
Kevin Chynaae4a152018-01-18 11:48:09 -0800694 if (mBar != null) {
695 try {
Kevin Chyn86f1b8e2019-09-24 19:00:49 -0700696 mBar.hideAuthenticationDialog();
Kevin Chynaae4a152018-01-18 11:48:09 -0800697 } catch (RemoteException ex) {
698 }
699 }
700 }
701
Charles Chen24e7a9f2018-11-21 11:59:07 +0800702 // TODO(b/117478341): make it aware of multi-display if needed.
Kevin Chyn23289ef2018-11-28 16:32:36 -0800703 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800704 public void disable(int what, IBinder token, String pkg) {
Benjamin Franzea2ec972015-03-16 17:18:09 +0000705 disableForUser(what, token, pkg, mCurrentUserId);
John Spurlock13451a22012-09-28 14:40:41 -0400706 }
707
Charles Chen24e7a9f2018-11-21 11:59:07 +0800708 // TODO(b/117478341): make it aware of multi-display if needed.
Benjamin Franzea2ec972015-03-16 17:18:09 +0000709 @Override
710 public void disableForUser(int what, IBinder token, String pkg, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800711 enforceStatusBar();
Joe Onoratof3f0e052010-05-14 18:49:29 -0700712
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800713 synchronized (mLock) {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800714 disableLocked(DEFAULT_DISPLAY, userId, what, token, pkg, 1);
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800715 }
716 }
717
Charles Chen24e7a9f2018-11-21 11:59:07 +0800718 // TODO(b/117478341): make it aware of multi-display if needed.
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100719 /**
720 * Disable additional status bar features. Pass the bitwise-or of the DISABLE2_* flags.
Evan Lairdedd016f2019-01-23 18:36:29 -0500721 * To re-enable everything, pass {@link #DISABLE2_NONE}.
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100722 *
723 * Warning: Only pass DISABLE2_* flags into this function, do not use DISABLE_* flags.
724 */
725 @Override
726 public void disable2(int what, IBinder token, String pkg) {
Benjamin Franz292a0a92016-03-30 13:41:57 +0100727 disable2ForUser(what, token, pkg, mCurrentUserId);
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100728 }
729
Charles Chen24e7a9f2018-11-21 11:59:07 +0800730 // TODO(b/117478341): make it aware of multi-display if needed.
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100731 /**
732 * Disable additional status bar features for a given user. Pass the bitwise-or of the
733 * DISABLE2_* flags. To re-enable everything, pass {@link #DISABLE_NONE}.
734 *
735 * Warning: Only pass DISABLE2_* flags into this function, do not use DISABLE_* flags.
736 */
737 @Override
738 public void disable2ForUser(int what, IBinder token, String pkg, int userId) {
Mike Digmandd2f49e2018-03-16 10:54:22 -0700739 enforceStatusBar();
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100740
741 synchronized (mLock) {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800742 disableLocked(DEFAULT_DISPLAY, userId, what, token, pkg, 2);
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100743 }
744 }
745
Charles Chen24e7a9f2018-11-21 11:59:07 +0800746 private void disableLocked(int displayId, int userId, int what, IBinder token, String pkg,
747 int whichFlag) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700748 // It's important that the the callback and the call to mBar get done
749 // in the same order when multiple threads are calling this function
750 // so they are paired correctly. The messages on the handler will be
751 // handled in the order they were enqueued, but will be outside the lock.
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100752 manageDisableListLocked(userId, what, token, pkg, whichFlag);
John Spurlock8f3e6d52012-11-29 13:56:24 -0500753
754 // Ensure state for the current user is applied, even if passed a non-current user.
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100755 final int net1 = gatherDisableActionsLocked(mCurrentUserId, 1);
756 final int net2 = gatherDisableActionsLocked(mCurrentUserId, 2);
Charles Chen24e7a9f2018-11-21 11:59:07 +0800757 final UiState state = getUiState(displayId);
Charles Chen1313fee2018-12-12 23:36:21 +0800758 if (!state.disableEquals(net1, net2)) {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800759 state.setDisabled(net1, net2);
760 mHandler.post(() -> mNotificationDelegate.onSetDisabled(net1));
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800761 if (mBar != null) {
762 try {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800763 mBar.disable(displayId, net1, net2);
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800764 } catch (RemoteException ex) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700765 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800766 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800767 }
768 }
769
Evan Lairdedd016f2019-01-23 18:36:29 -0500770 /**
771 * Get the currently applied disable flags, in the form of one Pair<Integer, Integer>.
772 *
773 * @return pair of disable flags in the form of (disabled1, disabled2), where (0, 0) indicates
774 * no flags are set for this token.
775 */
776 @Override
777 public int[] getDisableFlags(IBinder token, int userId) {
778 enforceStatusBar();
779
780 int disable1 = 0;
781 int disable2 = 0;
782 synchronized (mLock) {
783 // Find a matching record if it exists
784 DisableRecord record = findMatchingRecordLocked(token, userId).second;
785 if (record != null) {
786 disable1 = record.what1;
787 disable2 = record.what2;
788 }
789 }
790
791 return new int[] {disable1, disable2};
792 }
793
Adam Lesinski182f73f2013-12-05 16:48:06 -0800794 @Override
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700795 public void setIcon(String slot, String iconPackage, int iconId, int iconLevel,
796 String contentDescription) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800797 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700798
799 synchronized (mIcons) {
Xiaohui Chene4de5a02015-09-22 15:33:31 -0700800 StatusBarIcon icon = new StatusBarIcon(iconPackage, UserHandle.SYSTEM, iconId,
801 iconLevel, 0, contentDescription);
Joe Onorato66d7d012010-05-14 10:05:10 -0700802 //Slog.d(TAG, "setIcon slot=" + slot + " index=" + index + " icon=" + icon);
Jason Monk07473ce2016-01-05 14:59:19 -0500803 mIcons.put(slot, icon);
Joe Onorato0cbda992010-05-02 16:28:15 -0700804
Joe Onorato0cbda992010-05-02 16:28:15 -0700805 if (mBar != null) {
806 try {
Jason Monk07473ce2016-01-05 14:59:19 -0500807 mBar.setIcon(slot, icon);
Joe Onorato0cbda992010-05-02 16:28:15 -0700808 } catch (RemoteException ex) {
809 }
810 }
811 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800812 }
813
Adam Lesinski182f73f2013-12-05 16:48:06 -0800814 @Override
Jason Monk07473ce2016-01-05 14:59:19 -0500815 public void setIconVisibility(String slot, boolean visibility) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800816 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700817
Joe Onorato514ad6632010-05-13 18:49:00 -0700818 synchronized (mIcons) {
Jason Monk07473ce2016-01-05 14:59:19 -0500819 StatusBarIcon icon = mIcons.get(slot);
Joe Onorato514ad6632010-05-13 18:49:00 -0700820 if (icon == null) {
821 return;
822 }
Jason Monk07473ce2016-01-05 14:59:19 -0500823 if (icon.visible != visibility) {
824 icon.visible = visibility;
Joe Onorato514ad6632010-05-13 18:49:00 -0700825
Joe Onorato514ad6632010-05-13 18:49:00 -0700826 if (mBar != null) {
827 try {
Jason Monk07473ce2016-01-05 14:59:19 -0500828 mBar.setIcon(slot, icon);
Joe Onorato514ad6632010-05-13 18:49:00 -0700829 } catch (RemoteException ex) {
830 }
831 }
832 }
833 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700834 }
835
Adam Lesinski182f73f2013-12-05 16:48:06 -0800836 @Override
Joe Onorato0cbda992010-05-02 16:28:15 -0700837 public void removeIcon(String slot) {
838 enforceStatusBar();
839
840 synchronized (mIcons) {
Jason Monk07473ce2016-01-05 14:59:19 -0500841 mIcons.remove(slot);
Joe Onorato0cbda992010-05-02 16:28:15 -0700842
Joe Onorato0cbda992010-05-02 16:28:15 -0700843 if (mBar != null) {
844 try {
Jason Monk07473ce2016-01-05 14:59:19 -0500845 mBar.removeIcon(slot);
Joe Onorato0cbda992010-05-02 16:28:15 -0700846 } catch (RemoteException ex) {
847 }
848 }
849 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800850 }
851
Wale Ogunwale393b1c12014-10-18 16:22:01 -0700852 /**
Jorim Jaggi956ca412019-01-07 14:49:14 +0100853 * Enables System UI to know whether the top app is fullscreen or not, and whether this app is
854 * in immersive mode or not.
Daniel Sandlere02d8082010-10-08 15:13:22 -0400855 */
Jorim Jaggi956ca412019-01-07 14:49:14 +0100856 private void topAppWindowChanged(int displayId, boolean isFullscreen, boolean isImmersive) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400857 enforceStatusBar();
858
Daniel Sandlere02d8082010-10-08 15:13:22 -0400859 synchronized(mLock) {
Jorim Jaggi956ca412019-01-07 14:49:14 +0100860 getUiState(displayId).setFullscreen(isFullscreen);
861 getUiState(displayId).setImmersive(isImmersive);
Charles Chen24e7a9f2018-11-21 11:59:07 +0800862 mHandler.post(() -> {
863 if (mBar != null) {
864 try {
Jorim Jaggi956ca412019-01-07 14:49:14 +0100865 mBar.topAppWindowChanged(displayId, isFullscreen, isImmersive);
Charles Chen24e7a9f2018-11-21 11:59:07 +0800866 } catch (RemoteException ex) {
Dianne Hackborn7d049322011-06-14 15:00:32 -0700867 }
Jorim Jaggi86905582016-02-09 21:36:09 -0800868 }
869 });
Daniel Sandlere02d8082010-10-08 15:13:22 -0400870 }
871 }
872
Adam Lesinski182f73f2013-12-05 16:48:06 -0800873 @Override
lumark7570cac2019-03-07 22:14:38 +0800874 public void setImeWindowStatus(int displayId, final IBinder token, final int vis,
Tarandeep Singh07b318b2019-07-17 11:12:04 -0700875 final int backDisposition, final boolean showImeSwitcher,
876 boolean isMultiClientImeEnabled) {
satok06487a52010-10-29 11:37:18 +0900877 enforceStatusBar();
878
Joe Onorato857fd9b2011-01-27 15:08:35 -0800879 if (SPEW) {
880 Slog.d(TAG, "swetImeWindowStatus vis=" + vis + " backDisposition=" + backDisposition);
881 }
satok06487a52010-10-29 11:37:18 +0900882
883 synchronized(mLock) {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800884 // In case of IME change, we need to call up setImeWindowStatus() regardless of
885 // mImeWindowVis because mImeWindowVis may not have been set to false when the
satok06e07442010-11-02 19:46:55 +0900886 // previous IME was destroyed.
lumark7570cac2019-03-07 22:14:38 +0800887 getUiState(displayId).setImeWindowState(vis, backDisposition, showImeSwitcher, token);
Charles Chen24e7a9f2018-11-21 11:59:07 +0800888
889 mHandler.post(() -> {
890 if (mBar == null) return;
891 try {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800892 mBar.setImeWindowStatus(
Tarandeep Singh07b318b2019-07-17 11:12:04 -0700893 displayId, token, vis, backDisposition, showImeSwitcher,
894 isMultiClientImeEnabled);
Charles Chen24e7a9f2018-11-21 11:59:07 +0800895 } catch (RemoteException ex) { }
satok06e07442010-11-02 19:46:55 +0900896 });
satok06487a52010-10-29 11:37:18 +0900897 }
898 }
899
Tiger Huang0dbd5372019-10-26 00:24:22 +0800900 private void setDisableFlags(int displayId, int flags, String cause) {
Joe Onorato55bf3802011-01-25 13:42:10 -0800901 // also allows calls from window manager which is in this process.
Joe Onoratof63b0f42010-09-12 17:03:19 -0400902 enforceStatusBarService();
903
Tiger Huang0dbd5372019-10-26 00:24:22 +0800904 final int unknownFlags = flags & ~StatusBarManager.DISABLE_MASK;
905 if (unknownFlags != 0) {
906 Slog.e(TAG, "Unknown disable flags: 0x" + Integer.toHexString(unknownFlags),
907 new RuntimeException());
908 }
909
910 if (SPEW) Slog.d(TAG, "setDisableFlags(0x" + Integer.toHexString(flags) + ")");
Daniel Sandler60ee2562011-07-22 12:34:33 -0400911
Joe Onoratof63b0f42010-09-12 17:03:19 -0400912 synchronized (mLock) {
Tiger Huang0dbd5372019-10-26 00:24:22 +0800913 disableLocked(displayId, mCurrentUserId, flags, mSysUiVisToken, cause, 1);
Charles Chen24e7a9f2018-11-21 11:59:07 +0800914 }
915 }
916
917 /**
918 * @return {@link UiState} specified by {@code displayId}.
919 *
920 * <p>
921 * Note: If {@link UiState} specified by {@code displayId} does not exist, {@link UiState}
922 * will be allocated and {@code mDisplayUiState} will be updated accordingly.
923 * <p/>
924 */
925 private UiState getUiState(int displayId) {
926 UiState state = mDisplayUiState.get(displayId);
927 if (state == null) {
928 state = new UiState();
929 mDisplayUiState.put(displayId, state);
930 }
931 return state;
932 }
933
934 private class UiState {
Tiger Huang0dbd5372019-10-26 00:24:22 +0800935 private @Appearance int mAppearance = 0;
936 private AppearanceRegion[] mAppearanceRegions = new AppearanceRegion[0];
937 private ArraySet<Integer> mTransientBarTypes = new ArraySet<>();
938 private boolean mNavbarColorManagedByIme = false;
Jorim Jaggi956ca412019-01-07 14:49:14 +0100939 private boolean mFullscreen = false;
940 private boolean mImmersive = false;
Charles Chen24e7a9f2018-11-21 11:59:07 +0800941 private int mDisabled1 = 0;
942 private int mDisabled2 = 0;
943 private int mImeWindowVis = 0;
944 private int mImeBackDisposition = 0;
945 private boolean mShowImeSwitcher = false;
946 private IBinder mImeToken = null;
Tiger Huang0dbd5372019-10-26 00:24:22 +0800947
948 private void setAppearance(@Appearance int appearance,
949 AppearanceRegion[] appearanceRegions, boolean navbarColorManagedByIme) {
950 mAppearance = appearance;
951 mAppearanceRegions = appearanceRegions;
952 mNavbarColorManagedByIme = navbarColorManagedByIme;
953 }
954
955 private boolean appearanceEquals(@Appearance int appearance,
956 AppearanceRegion[] appearanceRegions, boolean navbarColorManagedByIme) {
957 if (mAppearance != appearance || mAppearanceRegions.length != appearanceRegions.length
958 || mNavbarColorManagedByIme != navbarColorManagedByIme) {
959 return false;
960 }
961 for (int i = appearanceRegions.length - 1; i >= 0; i--) {
962 if (!mAppearanceRegions[i].equals(appearanceRegions[i])) {
963 return false;
964 }
965 }
966 return true;
967 }
968
969 private void showTransient(@InternalInsetType int[] types) {
970 for (int type : types) {
971 mTransientBarTypes.add(type);
972 }
973 }
974
975 private void clearTransient(@InternalInsetType int[] types) {
976 for (int type : types) {
977 mTransientBarTypes.remove(type);
978 }
979 }
980
981 private void setFullscreen(boolean isFullscreen) {
982 mFullscreen = isFullscreen;
983 }
984
985 private void setImmersive(boolean isImmersive) {
986 mImmersive = isImmersive;
987 }
Charles Chen24e7a9f2018-11-21 11:59:07 +0800988
989 private int getDisabled1() {
990 return mDisabled1;
991 }
992
993 private int getDisabled2() {
994 return mDisabled2;
995 }
996
997 private void setDisabled(int disabled1, int disabled2) {
998 mDisabled1 = disabled1;
999 mDisabled2 = disabled2;
1000 }
1001
Charles Chen24e7a9f2018-11-21 11:59:07 +08001002 private boolean disableEquals(int disabled1, int disabled2) {
1003 return mDisabled1 == disabled1 && mDisabled2 == disabled2;
1004 }
1005
Charles Chen24e7a9f2018-11-21 11:59:07 +08001006 private void setImeWindowState(final int vis, final int backDisposition,
1007 final boolean showImeSwitcher, final IBinder token) {
1008 mImeWindowVis = vis;
1009 mImeBackDisposition = backDisposition;
1010 mShowImeSwitcher = showImeSwitcher;
1011 mImeToken = token;
Joe Onorato93056472010-09-10 10:30:46 -04001012 }
1013 }
1014
Jason Monk7e53f202016-01-28 10:40:20 -05001015 private void enforceStatusBarOrShell() {
1016 if (Binder.getCallingUid() == Process.SHELL_UID) {
1017 return;
1018 }
1019 enforceStatusBar();
1020 }
1021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001022 private void enforceStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -07001023 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -07001024 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001025 }
1026
1027 private void enforceExpandStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -07001028 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.EXPAND_STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -07001029 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001030 }
1031
Joe Onorato8bc6c512010-06-04 16:21:12 -04001032 private void enforceStatusBarService() {
1033 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
1034 "StatusBarManagerService");
1035 }
1036
Kevin Chyn95c27e02018-09-12 01:46:16 -07001037 private void enforceBiometricDialog() {
1038 mContext.enforceCallingOrSelfPermission(
1039 android.Manifest.permission.MANAGE_BIOMETRIC_DIALOG,
1040 "StatusBarManagerService");
1041 }
1042
Joe Onorato4762c2d2010-05-17 15:42:59 -07001043 // ================================================================================
1044 // Callbacks from the status bar service.
1045 // ================================================================================
Charles Chen24e7a9f2018-11-21 11:59:07 +08001046 // TODO(b/118592525): refactor it as an IStatusBar API.
Adam Lesinski182f73f2013-12-05 16:48:06 -08001047 @Override
Yohei Yukawa49efa712019-04-04 11:49:02 -07001048 public RegisterStatusBarResult registerStatusBar(IStatusBar bar) {
Joe Onorato8bc6c512010-06-04 16:21:12 -04001049 enforceStatusBarService();
1050
Joe Onorato0cbda992010-05-02 16:28:15 -07001051 Slog.i(TAG, "registerStatusBar bar=" + bar);
1052 mBar = bar;
Gopal Krishna Shuklae5c83792018-06-29 18:20:36 +05301053 mDeathRecipient.linkToDeath();
Jason Monk361915c2017-03-21 20:33:59 -04001054 notifyBarAttachChanged();
Yohei Yukawa49efa712019-04-04 11:49:02 -07001055 final ArrayMap<String, StatusBarIcon> icons;
Joe Onorato75199e32010-05-29 17:22:51 -04001056 synchronized (mIcons) {
Yohei Yukawa49efa712019-04-04 11:49:02 -07001057 icons = new ArrayMap<>(mIcons);
Joe Onorato75199e32010-05-29 17:22:51 -04001058 }
Joe Onorato93056472010-09-10 10:30:46 -04001059 synchronized (mLock) {
Charles Chen24e7a9f2018-11-21 11:59:07 +08001060 // TODO(b/118592525): Currently, status bar only works on the default display.
1061 // Make it aware of multi-display if needed.
1062 final UiState state = mDisplayUiState.get(DEFAULT_DISPLAY);
Tiger Huang0dbd5372019-10-26 00:24:22 +08001063 final int[] transientBarTypes = new int[state.mTransientBarTypes.size()];
1064 for (int i = 0; i < transientBarTypes.length; i++) {
1065 transientBarTypes[i] = state.mTransientBarTypes.valueAt(i);
1066 }
Yohei Yukawa49efa712019-04-04 11:49:02 -07001067 return new RegisterStatusBarResult(icons, gatherDisableActionsLocked(mCurrentUserId, 1),
Tiger Huang0dbd5372019-10-26 00:24:22 +08001068 state.mAppearance, state.mAppearanceRegions, state.mImeWindowVis,
Yohei Yukawa49efa712019-04-04 11:49:02 -07001069 state.mImeBackDisposition, state.mShowImeSwitcher,
Tiger Huang0dbd5372019-10-26 00:24:22 +08001070 gatherDisableActionsLocked(mCurrentUserId, 2), state.mImeToken,
1071 state.mNavbarColorManagedByIme, state.mFullscreen, state.mImmersive,
1072 transientBarTypes);
Joe Onorato93056472010-09-10 10:30:46 -04001073 }
Joe Onorato2314aab2010-04-08 16:41:23 -05001074 }
Joe Onoratoaaba60b2010-05-23 15:18:41 -04001075
Jason Monk361915c2017-03-21 20:33:59 -04001076 private void notifyBarAttachChanged() {
1077 mHandler.post(() -> {
1078 if (mGlobalActionListener == null) return;
Michael Kwan2decbf72018-02-22 07:40:11 -08001079 mGlobalActionListener.onGlobalActionsAvailableChanged(mBar != null);
Jason Monk361915c2017-03-21 20:33:59 -04001080 });
1081 }
1082
Joe Onorato4762c2d2010-05-17 15:42:59 -07001083 /**
Christoph Studer1f32c652014-11-26 15:32:20 +01001084 * @param clearNotificationEffects whether to consider notifications as "shown" and stop
1085 * LED, vibration, and ringing
Joe Onorato4762c2d2010-05-17 15:42:59 -07001086 */
Adam Lesinski182f73f2013-12-05 16:48:06 -08001087 @Override
Chris Wrenb659c4f2015-06-25 17:12:27 -04001088 public void onPanelRevealed(boolean clearNotificationEffects, int numItems) {
Joe Onorato8bc6c512010-06-04 16:21:12 -04001089 enforceStatusBarService();
Adam Lesinski182f73f2013-12-05 16:48:06 -08001090 long identity = Binder.clearCallingIdentity();
1091 try {
Chris Wrenb659c4f2015-06-25 17:12:27 -04001092 mNotificationDelegate.onPanelRevealed(clearNotificationEffects, numItems);
Christoph Studer1f32c652014-11-26 15:32:20 +01001093 } finally {
1094 Binder.restoreCallingIdentity(identity);
1095 }
1096 }
1097
1098 @Override
1099 public void clearNotificationEffects() throws RemoteException {
1100 enforceStatusBarService();
1101 long identity = Binder.clearCallingIdentity();
1102 try {
1103 mNotificationDelegate.clearEffects();
Adam Lesinski182f73f2013-12-05 16:48:06 -08001104 } finally {
1105 Binder.restoreCallingIdentity(identity);
1106 }
Joe Onorato4762c2d2010-05-17 15:42:59 -07001107 }
1108
Adam Lesinski182f73f2013-12-05 16:48:06 -08001109 @Override
Christoph Studer760ea552014-03-21 13:10:21 +01001110 public void onPanelHidden() throws RemoteException {
1111 enforceStatusBarService();
1112 long identity = Binder.clearCallingIdentity();
1113 try {
1114 mNotificationDelegate.onPanelHidden();
1115 } finally {
1116 Binder.restoreCallingIdentity(identity);
1117 }
1118 }
1119
Jason Monk361915c2017-03-21 20:33:59 -04001120 /**
1121 * Allows the status bar to shutdown the device.
1122 */
1123 @Override
1124 public void shutdown() {
1125 enforceStatusBarService();
1126 long identity = Binder.clearCallingIdentity();
1127 try {
Michael Wright6cd10262017-04-04 17:44:56 +01001128 // ShutdownThread displays UI, so give it a UI context.
Jason Monk361915c2017-03-21 20:33:59 -04001129 mHandler.post(() ->
Michael Wright6cd10262017-04-04 17:44:56 +01001130 ShutdownThread.shutdown(getUiContext(),
1131 PowerManager.SHUTDOWN_USER_REQUESTED, false));
Jason Monk361915c2017-03-21 20:33:59 -04001132 } finally {
1133 Binder.restoreCallingIdentity(identity);
1134 }
1135 }
1136
1137 /**
1138 * Allows the status bar to reboot the device.
1139 */
1140 @Override
1141 public void reboot(boolean safeMode) {
1142 enforceStatusBarService();
1143 long identity = Binder.clearCallingIdentity();
1144 try {
1145 mHandler.post(() -> {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001146 // ShutdownThread displays UI, so give it a UI context.
Jason Monk361915c2017-03-21 20:33:59 -04001147 if (safeMode) {
Shunta Satobdb0e492017-04-14 16:01:54 +09001148 ShutdownThread.rebootSafeMode(getUiContext(), true);
Jason Monk361915c2017-03-21 20:33:59 -04001149 } else {
Michael Wright6cd10262017-04-04 17:44:56 +01001150 ShutdownThread.reboot(getUiContext(),
1151 PowerManager.SHUTDOWN_USER_REQUESTED, false);
Jason Monk361915c2017-03-21 20:33:59 -04001152 }
1153 });
1154 } finally {
1155 Binder.restoreCallingIdentity(identity);
1156 }
1157 }
1158
1159 @Override
1160 public void onGlobalActionsShown() {
1161 enforceStatusBarService();
1162 long identity = Binder.clearCallingIdentity();
1163 try {
1164 if (mGlobalActionListener == null) return;
1165 mGlobalActionListener.onGlobalActionsShown();
1166 } finally {
1167 Binder.restoreCallingIdentity(identity);
1168 }
1169 }
1170
1171 @Override
1172 public void onGlobalActionsHidden() {
1173 enforceStatusBarService();
1174 long identity = Binder.clearCallingIdentity();
1175 try {
1176 if (mGlobalActionListener == null) return;
1177 mGlobalActionListener.onGlobalActionsDismissed();
1178 } finally {
1179 Binder.restoreCallingIdentity(identity);
1180 }
1181 }
1182
Christoph Studer760ea552014-03-21 13:10:21 +01001183 @Override
Dieter Hsud39f0d52018-04-14 02:08:30 +08001184 public void onNotificationClick(String key, NotificationVisibility nv) {
Joe Onorato8bc6c512010-06-04 16:21:12 -04001185 enforceStatusBarService();
John Spurlocke6a7d932014-03-13 12:29:00 -04001186 final int callingUid = Binder.getCallingUid();
1187 final int callingPid = Binder.getCallingPid();
Adam Lesinski182f73f2013-12-05 16:48:06 -08001188 long identity = Binder.clearCallingIdentity();
1189 try {
Dieter Hsud39f0d52018-04-14 02:08:30 +08001190 mNotificationDelegate.onNotificationClick(callingUid, callingPid, key, nv);
Adam Lesinski182f73f2013-12-05 16:48:06 -08001191 } finally {
1192 Binder.restoreCallingIdentity(identity);
1193 }
Joe Onoratoaaba60b2010-05-23 15:18:41 -04001194 }
1195
Adam Lesinski182f73f2013-12-05 16:48:06 -08001196 @Override
Tony Mak7d4b3a52018-11-27 17:29:36 +00001197 public void onNotificationActionClick(
1198 String key, int actionIndex, Notification.Action action, NotificationVisibility nv,
1199 boolean generatedByAssistant) {
Christoph Studer4da84cd2014-10-21 17:24:20 +02001200 enforceStatusBarService();
1201 final int callingUid = Binder.getCallingUid();
1202 final int callingPid = Binder.getCallingPid();
1203 long identity = Binder.clearCallingIdentity();
1204 try {
1205 mNotificationDelegate.onNotificationActionClick(callingUid, callingPid, key,
Tony Mak7d4b3a52018-11-27 17:29:36 +00001206 actionIndex, action, nv, generatedByAssistant);
Christoph Studer4da84cd2014-10-21 17:24:20 +02001207 } finally {
1208 Binder.restoreCallingIdentity(identity);
1209 }
1210 }
1211
1212 @Override
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -07001213 public void onNotificationError(String pkg, String tag, int id,
Kenny Guy3a7c4a52014-03-03 18:24:03 +00001214 int uid, int initialPid, String message, int userId) {
Joe Onorato8bc6c512010-06-04 16:21:12 -04001215 enforceStatusBarService();
John Spurlocke6a7d932014-03-13 12:29:00 -04001216 final int callingUid = Binder.getCallingUid();
1217 final int callingPid = Binder.getCallingPid();
Adam Lesinski182f73f2013-12-05 16:48:06 -08001218 long identity = Binder.clearCallingIdentity();
1219 try {
1220 // WARNING: this will call back into us to do the remove. Don't hold any locks.
John Spurlocke6a7d932014-03-13 12:29:00 -04001221 mNotificationDelegate.onNotificationError(callingUid, callingPid,
1222 pkg, tag, id, uid, initialPid, message, userId);
Adam Lesinski182f73f2013-12-05 16:48:06 -08001223 } finally {
1224 Binder.restoreCallingIdentity(identity);
1225 }
Joe Onorato005847b2010-06-04 16:08:02 -04001226 }
1227
Adam Lesinski182f73f2013-12-05 16:48:06 -08001228 @Override
Julia Reynolds503ed942017-10-04 16:04:56 -04001229 public void onNotificationClear(String pkg, String tag, int id, int userId, String key,
Julia Reynoldsfd4099d2018-08-21 11:06:06 -04001230 @NotificationStats.DismissalSurface int dismissalSurface,
1231 @NotificationStats.DismissalSentiment int dismissalSentiment,
1232 NotificationVisibility nv) {
Daniel Sandler0f0b11c2010-08-04 15:54:58 -04001233 enforceStatusBarService();
John Spurlocke6a7d932014-03-13 12:29:00 -04001234 final int callingUid = Binder.getCallingUid();
1235 final int callingPid = Binder.getCallingPid();
Adam Lesinski182f73f2013-12-05 16:48:06 -08001236 long identity = Binder.clearCallingIdentity();
1237 try {
Dieter Hsud39f0d52018-04-14 02:08:30 +08001238 mNotificationDelegate.onNotificationClear(callingUid, callingPid, pkg, tag, id, userId,
Julia Reynoldsfd4099d2018-08-21 11:06:06 -04001239 key, dismissalSurface, dismissalSentiment, nv);
Adam Lesinski182f73f2013-12-05 16:48:06 -08001240 } finally {
1241 Binder.restoreCallingIdentity(identity);
1242 }
Daniel Sandler0f0b11c2010-08-04 15:54:58 -04001243 }
1244
Adam Lesinski182f73f2013-12-05 16:48:06 -08001245 @Override
Christoph Studer92b389d2014-04-01 18:44:40 +02001246 public void onNotificationVisibilityChanged(
Chris Wrend1dbc922015-06-19 17:51:16 -04001247 NotificationVisibility[] newlyVisibleKeys, NotificationVisibility[] noLongerVisibleKeys)
1248 throws RemoteException {
Christoph Studer92b389d2014-04-01 18:44:40 +02001249 enforceStatusBarService();
1250 long identity = Binder.clearCallingIdentity();
1251 try {
1252 mNotificationDelegate.onNotificationVisibilityChanged(
1253 newlyVisibleKeys, noLongerVisibleKeys);
1254 } finally {
1255 Binder.restoreCallingIdentity(identity);
1256 }
1257 }
1258
1259 @Override
Gustav Senntona8e38aa2019-01-22 14:55:39 +00001260 public void onNotificationExpansionChanged(String key, boolean userAction, boolean expanded,
1261 int location) throws RemoteException {
Chris Wren78403d72014-07-28 10:23:24 +01001262 enforceStatusBarService();
1263 long identity = Binder.clearCallingIdentity();
1264 try {
1265 mNotificationDelegate.onNotificationExpansionChanged(
Gustav Senntona8e38aa2019-01-22 14:55:39 +00001266 key, userAction, expanded, location);
Chris Wren78403d72014-07-28 10:23:24 +01001267 } finally {
1268 Binder.restoreCallingIdentity(identity);
1269 }
1270 }
1271
1272 @Override
Julia Reynolds503ed942017-10-04 16:04:56 -04001273 public void onNotificationDirectReplied(String key) throws RemoteException {
1274 enforceStatusBarService();
1275 long identity = Binder.clearCallingIdentity();
1276 try {
1277 mNotificationDelegate.onNotificationDirectReplied(key);
1278 } finally {
1279 Binder.restoreCallingIdentity(identity);
1280 }
1281 }
1282
1283 @Override
Gustav Senntond25a64d2018-12-07 10:58:39 +00001284 public void onNotificationSmartSuggestionsAdded(String key, int smartReplyCount,
Milo Sredkov13d88112019-02-01 12:23:24 +00001285 int smartActionCount, boolean generatedByAssistant, boolean editBeforeSending) {
Kenny Guy23991102018-04-05 21:18:38 +01001286 enforceStatusBarService();
1287 long identity = Binder.clearCallingIdentity();
1288 try {
Gustav Senntond25a64d2018-12-07 10:58:39 +00001289 mNotificationDelegate.onNotificationSmartSuggestionsAdded(key, smartReplyCount,
Milo Sredkov13d88112019-02-01 12:23:24 +00001290 smartActionCount, generatedByAssistant, editBeforeSending);
Kenny Guy23991102018-04-05 21:18:38 +01001291 } finally {
1292 Binder.restoreCallingIdentity(identity);
1293 }
1294 }
1295
1296 @Override
Tony Mak29996702018-11-26 16:23:34 +00001297 public void onNotificationSmartReplySent(
Milo Sredkov13d88112019-02-01 12:23:24 +00001298 String key, int replyIndex, CharSequence reply, int notificationLocation,
1299 boolean modifiedBeforeSending) throws RemoteException {
Kenny Guy23991102018-04-05 21:18:38 +01001300 enforceStatusBarService();
1301 long identity = Binder.clearCallingIdentity();
1302 try {
Tony Mak29996702018-11-26 16:23:34 +00001303 mNotificationDelegate.onNotificationSmartReplySent(key, replyIndex, reply,
Milo Sredkov13d88112019-02-01 12:23:24 +00001304 notificationLocation, modifiedBeforeSending);
Kenny Guy23991102018-04-05 21:18:38 +01001305 } finally {
1306 Binder.restoreCallingIdentity(identity);
1307 }
1308 }
1309
1310 @Override
Julia Reynolds503ed942017-10-04 16:04:56 -04001311 public void onNotificationSettingsViewed(String key) throws RemoteException {
1312 enforceStatusBarService();
1313 long identity = Binder.clearCallingIdentity();
1314 try {
1315 mNotificationDelegate.onNotificationSettingsViewed(key);
1316 } finally {
1317 Binder.restoreCallingIdentity(identity);
1318 }
1319 }
1320
1321 @Override
Kenny Guy3a7c4a52014-03-03 18:24:03 +00001322 public void onClearAllNotifications(int userId) {
Joe Onorato8bc6c512010-06-04 16:21:12 -04001323 enforceStatusBarService();
John Spurlocke6a7d932014-03-13 12:29:00 -04001324 final int callingUid = Binder.getCallingUid();
1325 final int callingPid = Binder.getCallingPid();
Adam Lesinski182f73f2013-12-05 16:48:06 -08001326 long identity = Binder.clearCallingIdentity();
1327 try {
John Spurlocke6a7d932014-03-13 12:29:00 -04001328 mNotificationDelegate.onClearAll(callingUid, callingPid, userId);
Adam Lesinski182f73f2013-12-05 16:48:06 -08001329 } finally {
1330 Binder.restoreCallingIdentity(identity);
Joe Onorato18e69df2010-05-17 22:26:12 -07001331 }
Joe Onorato0cbda992010-05-02 16:28:15 -07001332 }
1333
Jason Monk7e53f202016-01-28 10:40:20 -05001334 @Override
Mady Mellora54e9fa2019-04-18 13:26:18 -07001335 public void onNotificationBubbleChanged(String key, boolean isBubble) {
1336 enforceStatusBarService();
1337 long identity = Binder.clearCallingIdentity();
1338 try {
1339 mNotificationDelegate.onNotificationBubbleChanged(key, isBubble);
1340 } finally {
1341 Binder.restoreCallingIdentity(identity);
1342 }
1343 }
1344
1345 @Override
Aran Ink979c9762019-10-24 16:09:45 -04001346 public void grantInlineReplyUriPermission(String key, Uri uri, UserHandle user,
1347 String packageName) {
Aran Inkfd2bfd32019-10-04 16:30:01 -04001348 enforceStatusBarService();
1349 int callingUid = Binder.getCallingUid();
1350 long identity = Binder.clearCallingIdentity();
1351 try {
Aran Ink979c9762019-10-24 16:09:45 -04001352 mNotificationDelegate.grantInlineReplyUriPermission(key, uri, user, packageName,
1353 callingUid);
1354 } finally {
1355 Binder.restoreCallingIdentity(identity);
1356 }
1357 }
1358
1359 @Override
1360 public void clearInlineReplyUriPermissions(String key) {
1361 enforceStatusBarService();
1362 int callingUid = Binder.getCallingUid();
1363 long identity = Binder.clearCallingIdentity();
1364 try {
1365 mNotificationDelegate.clearInlineReplyUriPermissions(key, callingUid);
Aran Inkfd2bfd32019-10-04 16:30:01 -04001366 } finally {
1367 Binder.restoreCallingIdentity(identity);
1368 }
1369 }
1370
1371 @Override
Jason Monk7e53f202016-01-28 10:40:20 -05001372 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
Dianne Hackborn354736e2016-08-22 17:00:05 -07001373 String[] args, ShellCallback callback, ResultReceiver resultReceiver) {
Evan Lairdedd016f2019-01-23 18:36:29 -05001374 (new StatusBarShellCommand(this, mContext)).exec(
Dianne Hackborn354736e2016-08-22 17:00:05 -07001375 this, in, out, err, args, callback, resultReceiver);
Jason Monk7e53f202016-01-28 10:40:20 -05001376 }
1377
Robert Horvath5560f382019-07-10 10:46:38 +02001378 @Override
1379 public void showInattentiveSleepWarning() {
1380 enforceStatusBarService();
1381 if (mBar != null) {
1382 try {
1383 mBar.showInattentiveSleepWarning();
1384 } catch (RemoteException ex) {
1385 }
1386 }
1387 }
1388
1389 @Override
Robert Horvath60e51fe2019-08-20 13:10:34 +02001390 public void dismissInattentiveSleepWarning(boolean animated) {
Robert Horvath5560f382019-07-10 10:46:38 +02001391 enforceStatusBarService();
1392 if (mBar != null) {
1393 try {
Robert Horvath60e51fe2019-08-20 13:10:34 +02001394 mBar.dismissInattentiveSleepWarning(animated);
Robert Horvath5560f382019-07-10 10:46:38 +02001395 } catch (RemoteException ex) {
1396 }
1397 }
1398 }
1399
Jason Monkf8c2f7b2017-09-06 09:22:29 -04001400 public String[] getStatusBarIcons() {
1401 return mContext.getResources().getStringArray(R.array.config_statusBarIcons);
1402 }
1403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001404 // ================================================================================
1405 // Can be called from any thread
1406 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001407
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001408 // lock on mDisableRecords
Benjamin Franzcde0a2a2015-04-23 17:19:48 +01001409 void manageDisableListLocked(int userId, int what, IBinder token, String pkg, int which) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001410 if (SPEW) {
John Spurlock13451a22012-09-28 14:40:41 -04001411 Slog.d(TAG, "manageDisableList userId=" + userId
1412 + " what=0x" + Integer.toHexString(what) + " pkg=" + pkg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001413 }
Charles Heede39092017-09-18 09:19:28 +01001414
1415 // Find matching record, if any
Evan Lairdedd016f2019-01-23 18:36:29 -05001416 Pair<Integer, DisableRecord> match = findMatchingRecordLocked(token, userId);
1417 int i = match.first;
1418 DisableRecord record = match.second;
Charles Heede39092017-09-18 09:19:28 +01001419
1420 // Remove record if binder is already dead
1421 if (!token.isBinderAlive()) {
1422 if (record != null) {
Joe Onorato7bb8eeb2011-01-27 16:00:58 -08001423 mDisableRecords.remove(i);
Charles Heede39092017-09-18 09:19:28 +01001424 record.token.unlinkToDeath(record, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001425 }
Charles Heede39092017-09-18 09:19:28 +01001426 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001427 }
Charles Heede39092017-09-18 09:19:28 +01001428
1429 // Update existing record
1430 if (record != null) {
1431 record.setFlags(what, which, pkg);
1432 if (record.isEmpty()) {
1433 mDisableRecords.remove(i);
1434 record.token.unlinkToDeath(record, 0);
1435 }
1436 return;
1437 }
1438
1439 // Record doesn't exist, so we create a new one
1440 record = new DisableRecord(userId, token);
1441 record.setFlags(what, which, pkg);
1442 mDisableRecords.add(record);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001443 }
1444
Evan Lairdedd016f2019-01-23 18:36:29 -05001445 @Nullable
1446 @GuardedBy("mLock")
1447 private Pair<Integer, DisableRecord> findMatchingRecordLocked(IBinder token, int userId) {
1448 final int numRecords = mDisableRecords.size();
1449 DisableRecord record = null;
1450 int i;
1451 for (i = 0; i < numRecords; i++) {
1452 DisableRecord r = mDisableRecords.get(i);
1453 if (r.token == token && r.userId == userId) {
1454 record = r;
1455 break;
1456 }
1457 }
1458
1459 return new Pair<Integer, DisableRecord>(i, record);
1460 }
1461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001462 // lock on mDisableRecords
Benjamin Franzcde0a2a2015-04-23 17:19:48 +01001463 int gatherDisableActionsLocked(int userId, int which) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001464 final int N = mDisableRecords.size();
1465 // gather the new net flags
1466 int net = 0;
1467 for (int i=0; i<N; i++) {
John Spurlock13451a22012-09-28 14:40:41 -04001468 final DisableRecord rec = mDisableRecords.get(i);
1469 if (rec.userId == userId) {
Charles Heede39092017-09-18 09:19:28 +01001470 net |= rec.getFlags(which);
John Spurlock13451a22012-09-28 14:40:41 -04001471 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001472 }
1473 return net;
1474 }
1475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001476 // ================================================================================
1477 // Always called from UI thread
1478 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001480 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001481 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Joe Onorato0cbda992010-05-02 16:28:15 -07001482
Joe Onorato7bb8eeb2011-01-27 16:00:58 -08001483 synchronized (mLock) {
Charles Chen24e7a9f2018-11-21 11:59:07 +08001484 for (int i = 0; i < mDisplayUiState.size(); i++) {
1485 final int key = mDisplayUiState.keyAt(i);
1486 final UiState state = mDisplayUiState.get(key);
1487 pw.println(" displayId=" + key);
1488 pw.println(" mDisabled1=0x" + Integer.toHexString(state.getDisabled1()));
1489 pw.println(" mDisabled2=0x" + Integer.toHexString(state.getDisabled2()));
1490 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001491 final int N = mDisableRecords.size();
John Spurlock13451a22012-09-28 14:40:41 -04001492 pw.println(" mDisableRecords.size=" + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001493 for (int i=0; i<N; i++) {
1494 DisableRecord tok = mDisableRecords.get(i);
Charles Heede39092017-09-18 09:19:28 +01001495 pw.println(" [" + i + "] " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001496 }
Adrian Roos2a629102016-04-15 16:28:03 -07001497 pw.println(" mCurrentUserId=" + mCurrentUserId);
Dan Sandlerf3a1f2c2016-06-26 15:59:13 -04001498 pw.println(" mIcons=");
1499 for (String slot : mIcons.keySet()) {
1500 pw.println(" ");
1501 pw.print(slot);
1502 pw.print(" -> ");
1503 final StatusBarIcon icon = mIcons.get(slot);
1504 pw.print(icon);
1505 if (!TextUtils.isEmpty(icon.contentDescription)) {
1506 pw.print(" \"");
1507 pw.print(icon.contentDescription);
1508 pw.print("\"");
1509 }
1510 pw.println();
1511 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001512 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001513 }
Michael Wright6cd10262017-04-04 17:44:56 +01001514
1515 private static final Context getUiContext() {
1516 return ActivityThread.currentActivityThread().getSystemUiContext();
1517 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001518}