blob: 9a30f1de70f0d76a27fa31232de9ad3e5a49940c [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 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;
Winson Chungb53b30c2019-11-18 21:03:09 -080095 private boolean mTracingEnabled;
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 /**
Winson Chungb53b30c2019-11-18 21:03:09 -0800179 * Construct the service
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800180 */
Winson Chungb53b30c2019-11-18 21:03:09 -0800181 public StatusBarManagerService(Context context) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 mContext = context;
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 Huang332793b2019-10-29 23:21:27 +0800485 public void showTransient(int displayId, @InternalInsetsType int[] types) {
Tiger Huang0dbd5372019-10-26 00:24:22 +0800486 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 Huang332793b2019-10-29 23:21:27 +0800495 public void abortTransient(int displayId, @InternalInsetsType int[] types) {
Tiger Huang0dbd5372019-10-26 00:24:22 +0800496 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 }
Bernardo Rufinoab338ac2019-12-20 18:35:30 +0000503
504 @Override
505 public void showToast(String packageName, IBinder token, CharSequence text,
506 IBinder windowToken, int duration,
507 @Nullable ITransientNotificationCallback callback) {
508 if (mBar != null) {
509 try {
510 mBar.showToast(packageName, token, text, windowToken, duration, callback);
511 } catch (RemoteException ex) { }
512 }
513 }
514
515 @Override
516 public void hideToast(String packageName, IBinder token) {
517 if (mBar != null) {
518 try {
519 mBar.hideToast(packageName, token);
520 } catch (RemoteException ex) { }
521 }
522 }
Adam Lesinski182f73f2013-12-05 16:48:06 -0800523 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800524
Michael Kwan2decbf72018-02-22 07:40:11 -0800525 private final GlobalActionsProvider mGlobalActionsProvider = new GlobalActionsProvider() {
526 @Override
527 public boolean isGlobalActionsDisabled() {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800528 // TODO(b/118592525): support global actions for multi-display.
529 final int disabled2 = mDisplayUiState.get(DEFAULT_DISPLAY).getDisabled2();
530 return (disabled2 & DISABLE2_GLOBAL_ACTIONS) != 0;
Michael Kwan2decbf72018-02-22 07:40:11 -0800531 }
532
533 @Override
534 public void setGlobalActionsListener(GlobalActionsProvider.GlobalActionsListener listener) {
535 mGlobalActionListener = listener;
536 mGlobalActionListener.onGlobalActionsAvailableChanged(mBar != null);
537 }
538
539 @Override
540 public void showGlobalActions() {
541 if (mBar != null) {
542 try {
543 mBar.showGlobalActionsMenu();
544 } catch (RemoteException ex) {}
545 }
546 }
547 };
548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800549 // ================================================================================
Joe Onorato25f95f92010-04-08 18:37:10 -0500550 // From IStatusBarService
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800551 // ================================================================================
Adam Lesinski182f73f2013-12-05 16:48:06 -0800552 @Override
Daniel Sandler11cf1782012-09-27 14:03:08 -0400553 public void expandNotificationsPanel() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800554 enforceExpandStatusBar();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700555
556 if (mBar != null) {
557 try {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400558 mBar.animateExpandNotificationsPanel();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700559 } catch (RemoteException ex) {
560 }
561 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800562 }
563
Adam Lesinski182f73f2013-12-05 16:48:06 -0800564 @Override
Daniel Sandler11cf1782012-09-27 14:03:08 -0400565 public void collapsePanels() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566 enforceExpandStatusBar();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567
Joe Onorato4762c2d2010-05-17 15:42:59 -0700568 if (mBar != null) {
569 try {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400570 mBar.animateCollapsePanels();
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700571 } catch (RemoteException ex) {
572 }
573 }
574 }
575
Adam Lesinski182f73f2013-12-05 16:48:06 -0800576 @Override
Anthony Chen9ad00e02017-05-12 15:53:36 -0700577 public void togglePanel() {
578 enforceExpandStatusBar();
579
580 if (mBar != null) {
581 try {
582 mBar.togglePanel();
583 } catch (RemoteException ex) {
584 }
585 }
586 }
587
588 @Override
Jason Monka9927322015-12-13 16:22:37 -0500589 public void expandSettingsPanel(String subPanel) {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700590 enforceExpandStatusBar();
591
592 if (mBar != null) {
593 try {
Jason Monka9927322015-12-13 16:22:37 -0500594 mBar.animateExpandSettingsPanel(subPanel);
Joe Onorato4762c2d2010-05-17 15:42:59 -0700595 } catch (RemoteException ex) {
596 }
597 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598 }
599
Jason Monk7e53f202016-01-28 10:40:20 -0500600 public void addTile(ComponentName component) {
601 enforceStatusBarOrShell();
602
603 if (mBar != null) {
604 try {
605 mBar.addQsTile(component);
606 } catch (RemoteException ex) {
607 }
608 }
609 }
610
611 public void remTile(ComponentName component) {
612 enforceStatusBarOrShell();
613
614 if (mBar != null) {
615 try {
616 mBar.remQsTile(component);
617 } catch (RemoteException ex) {
618 }
619 }
620 }
621
622 public void clickTile(ComponentName component) {
623 enforceStatusBarOrShell();
624
625 if (mBar != null) {
626 try {
627 mBar.clickQsTile(component);
628 } catch (RemoteException ex) {
629 }
630 }
631 }
632
Adam Lesinski182f73f2013-12-05 16:48:06 -0800633 @Override
Philip Quinnc3a503d2017-07-18 23:23:41 -0700634 public void handleSystemKey(int key) throws RemoteException {
Jim Miller07e03842016-06-22 15:18:13 -0700635 enforceExpandStatusBar();
636
637 if (mBar != null) {
638 try {
Philip Quinnc3a503d2017-07-18 23:23:41 -0700639 mBar.handleSystemKey(key);
Jim Miller07e03842016-06-22 15:18:13 -0700640 } catch (RemoteException ex) {
641 }
642 }
643 }
644
645 @Override
Matthew Ng9c3bce52018-02-01 22:00:31 +0000646 public void showPinningEnterExitToast(boolean entering) throws RemoteException {
647 if (mBar != null) {
648 try {
649 mBar.showPinningEnterExitToast(entering);
650 } catch (RemoteException ex) {
651 }
652 }
653 }
654
655 @Override
656 public void showPinningEscapeToast() throws RemoteException {
657 if (mBar != null) {
658 try {
659 mBar.showPinningEscapeToast();
660 } catch (RemoteException ex) {
661 }
662 }
663 }
664
665 @Override
Kevin Chyn86f1b8e2019-09-24 19:00:49 -0700666 public void showAuthenticationDialog(Bundle bundle, IBiometricServiceReceiverInternal receiver,
667 int biometricModality, boolean requireConfirmation, int userId, String opPackageName) {
Kevin Chyn95c27e02018-09-12 01:46:16 -0700668 enforceBiometricDialog();
Kevin Chynaae4a152018-01-18 11:48:09 -0800669 if (mBar != null) {
670 try {
Kevin Chyn86f1b8e2019-09-24 19:00:49 -0700671 mBar.showAuthenticationDialog(bundle, receiver, biometricModality,
672 requireConfirmation, userId, opPackageName);
Kevin Chynaae4a152018-01-18 11:48:09 -0800673 } catch (RemoteException ex) {
674 }
675 }
676 }
677
678 @Override
Ilya Matyukhin0f9da352019-10-03 14:10:01 -0700679 public void onBiometricAuthenticated() {
Kevin Chyn95c27e02018-09-12 01:46:16 -0700680 enforceBiometricDialog();
Kevin Chynaae4a152018-01-18 11:48:09 -0800681 if (mBar != null) {
682 try {
Ilya Matyukhin0f9da352019-10-03 14:10:01 -0700683 mBar.onBiometricAuthenticated();
Kevin Chynaae4a152018-01-18 11:48:09 -0800684 } catch (RemoteException ex) {
685 }
686 }
687 }
688
689 @Override
Kevin Chyne9275662018-07-23 16:42:06 -0700690 public void onBiometricHelp(String message) {
Kevin Chyn95c27e02018-09-12 01:46:16 -0700691 enforceBiometricDialog();
Kevin Chynaae4a152018-01-18 11:48:09 -0800692 if (mBar != null) {
693 try {
Kevin Chyne9275662018-07-23 16:42:06 -0700694 mBar.onBiometricHelp(message);
Kevin Chynaae4a152018-01-18 11:48:09 -0800695 } catch (RemoteException ex) {
696 }
697 }
698 }
699
700 @Override
Ilya Matyukhin0f9da352019-10-03 14:10:01 -0700701 public void onBiometricError(int modality, int error, int vendorCode) {
Kevin Chyn95c27e02018-09-12 01:46:16 -0700702 enforceBiometricDialog();
Kevin Chynaae4a152018-01-18 11:48:09 -0800703 if (mBar != null) {
704 try {
Ilya Matyukhin0f9da352019-10-03 14:10:01 -0700705 mBar.onBiometricError(modality, error, vendorCode);
Kevin Chynaae4a152018-01-18 11:48:09 -0800706 } catch (RemoteException ex) {
707 }
708 }
709 }
710
711 @Override
Kevin Chyn86f1b8e2019-09-24 19:00:49 -0700712 public void hideAuthenticationDialog() {
Kevin Chyn95c27e02018-09-12 01:46:16 -0700713 enforceBiometricDialog();
Kevin Chynaae4a152018-01-18 11:48:09 -0800714 if (mBar != null) {
715 try {
Kevin Chyn86f1b8e2019-09-24 19:00:49 -0700716 mBar.hideAuthenticationDialog();
Kevin Chynaae4a152018-01-18 11:48:09 -0800717 } catch (RemoteException ex) {
718 }
719 }
720 }
721
Winson Chungb53b30c2019-11-18 21:03:09 -0800722 @Override
723 public void startTracing() {
724 if (mBar != null) {
725 try {
726 mBar.startTracing();
727 mTracingEnabled = true;
728 } catch (RemoteException ex) {}
729 }
730 }
731
732 @Override
733 public void stopTracing() {
734 if (mBar != null) {
735 try {
736 mTracingEnabled = false;
737 mBar.stopTracing();
738 } catch (RemoteException ex) {}
739 }
740 }
741
742 @Override
743 public boolean isTracing() {
744 return mTracingEnabled;
745 }
746
Charles Chen24e7a9f2018-11-21 11:59:07 +0800747 // TODO(b/117478341): make it aware of multi-display if needed.
Kevin Chyn23289ef2018-11-28 16:32:36 -0800748 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800749 public void disable(int what, IBinder token, String pkg) {
Benjamin Franzea2ec972015-03-16 17:18:09 +0000750 disableForUser(what, token, pkg, mCurrentUserId);
John Spurlock13451a22012-09-28 14:40:41 -0400751 }
752
Charles Chen24e7a9f2018-11-21 11:59:07 +0800753 // TODO(b/117478341): make it aware of multi-display if needed.
Benjamin Franzea2ec972015-03-16 17:18:09 +0000754 @Override
755 public void disableForUser(int what, IBinder token, String pkg, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800756 enforceStatusBar();
Joe Onoratof3f0e052010-05-14 18:49:29 -0700757
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800758 synchronized (mLock) {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800759 disableLocked(DEFAULT_DISPLAY, userId, what, token, pkg, 1);
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800760 }
761 }
762
Charles Chen24e7a9f2018-11-21 11:59:07 +0800763 // TODO(b/117478341): make it aware of multi-display if needed.
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100764 /**
765 * Disable additional status bar features. Pass the bitwise-or of the DISABLE2_* flags.
Evan Lairdedd016f2019-01-23 18:36:29 -0500766 * To re-enable everything, pass {@link #DISABLE2_NONE}.
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100767 *
768 * Warning: Only pass DISABLE2_* flags into this function, do not use DISABLE_* flags.
769 */
770 @Override
771 public void disable2(int what, IBinder token, String pkg) {
Benjamin Franz292a0a92016-03-30 13:41:57 +0100772 disable2ForUser(what, token, pkg, mCurrentUserId);
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100773 }
774
Charles Chen24e7a9f2018-11-21 11:59:07 +0800775 // TODO(b/117478341): make it aware of multi-display if needed.
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100776 /**
777 * Disable additional status bar features for a given user. Pass the bitwise-or of the
778 * DISABLE2_* flags. To re-enable everything, pass {@link #DISABLE_NONE}.
779 *
780 * Warning: Only pass DISABLE2_* flags into this function, do not use DISABLE_* flags.
781 */
782 @Override
783 public void disable2ForUser(int what, IBinder token, String pkg, int userId) {
Mike Digmandd2f49e2018-03-16 10:54:22 -0700784 enforceStatusBar();
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100785
786 synchronized (mLock) {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800787 disableLocked(DEFAULT_DISPLAY, userId, what, token, pkg, 2);
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100788 }
789 }
790
Charles Chen24e7a9f2018-11-21 11:59:07 +0800791 private void disableLocked(int displayId, int userId, int what, IBinder token, String pkg,
792 int whichFlag) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700793 // It's important that the the callback and the call to mBar get done
794 // in the same order when multiple threads are calling this function
795 // so they are paired correctly. The messages on the handler will be
796 // handled in the order they were enqueued, but will be outside the lock.
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100797 manageDisableListLocked(userId, what, token, pkg, whichFlag);
John Spurlock8f3e6d52012-11-29 13:56:24 -0500798
799 // Ensure state for the current user is applied, even if passed a non-current user.
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100800 final int net1 = gatherDisableActionsLocked(mCurrentUserId, 1);
801 final int net2 = gatherDisableActionsLocked(mCurrentUserId, 2);
Charles Chen24e7a9f2018-11-21 11:59:07 +0800802 final UiState state = getUiState(displayId);
Charles Chen1313fee2018-12-12 23:36:21 +0800803 if (!state.disableEquals(net1, net2)) {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800804 state.setDisabled(net1, net2);
805 mHandler.post(() -> mNotificationDelegate.onSetDisabled(net1));
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800806 if (mBar != null) {
807 try {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800808 mBar.disable(displayId, net1, net2);
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800809 } catch (RemoteException ex) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700810 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800811 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800812 }
813 }
814
Evan Lairdedd016f2019-01-23 18:36:29 -0500815 /**
816 * Get the currently applied disable flags, in the form of one Pair<Integer, Integer>.
817 *
818 * @return pair of disable flags in the form of (disabled1, disabled2), where (0, 0) indicates
819 * no flags are set for this token.
820 */
821 @Override
822 public int[] getDisableFlags(IBinder token, int userId) {
823 enforceStatusBar();
824
825 int disable1 = 0;
826 int disable2 = 0;
827 synchronized (mLock) {
828 // Find a matching record if it exists
829 DisableRecord record = findMatchingRecordLocked(token, userId).second;
830 if (record != null) {
831 disable1 = record.what1;
832 disable2 = record.what2;
833 }
834 }
835
836 return new int[] {disable1, disable2};
837 }
838
Adam Lesinski182f73f2013-12-05 16:48:06 -0800839 @Override
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700840 public void setIcon(String slot, String iconPackage, int iconId, int iconLevel,
841 String contentDescription) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800842 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700843
844 synchronized (mIcons) {
Xiaohui Chene4de5a02015-09-22 15:33:31 -0700845 StatusBarIcon icon = new StatusBarIcon(iconPackage, UserHandle.SYSTEM, iconId,
846 iconLevel, 0, contentDescription);
Joe Onorato66d7d012010-05-14 10:05:10 -0700847 //Slog.d(TAG, "setIcon slot=" + slot + " index=" + index + " icon=" + icon);
Jason Monk07473ce2016-01-05 14:59:19 -0500848 mIcons.put(slot, icon);
Joe Onorato0cbda992010-05-02 16:28:15 -0700849
Joe Onorato0cbda992010-05-02 16:28:15 -0700850 if (mBar != null) {
851 try {
Jason Monk07473ce2016-01-05 14:59:19 -0500852 mBar.setIcon(slot, icon);
Joe Onorato0cbda992010-05-02 16:28:15 -0700853 } catch (RemoteException ex) {
854 }
855 }
856 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800857 }
858
Adam Lesinski182f73f2013-12-05 16:48:06 -0800859 @Override
Jason Monk07473ce2016-01-05 14:59:19 -0500860 public void setIconVisibility(String slot, boolean visibility) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800861 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700862
Joe Onorato514ad6632010-05-13 18:49:00 -0700863 synchronized (mIcons) {
Jason Monk07473ce2016-01-05 14:59:19 -0500864 StatusBarIcon icon = mIcons.get(slot);
Joe Onorato514ad6632010-05-13 18:49:00 -0700865 if (icon == null) {
866 return;
867 }
Jason Monk07473ce2016-01-05 14:59:19 -0500868 if (icon.visible != visibility) {
869 icon.visible = visibility;
Joe Onorato514ad6632010-05-13 18:49:00 -0700870
Joe Onorato514ad6632010-05-13 18:49:00 -0700871 if (mBar != null) {
872 try {
Jason Monk07473ce2016-01-05 14:59:19 -0500873 mBar.setIcon(slot, icon);
Joe Onorato514ad6632010-05-13 18:49:00 -0700874 } catch (RemoteException ex) {
875 }
876 }
877 }
878 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700879 }
880
Adam Lesinski182f73f2013-12-05 16:48:06 -0800881 @Override
Joe Onorato0cbda992010-05-02 16:28:15 -0700882 public void removeIcon(String slot) {
883 enforceStatusBar();
884
885 synchronized (mIcons) {
Jason Monk07473ce2016-01-05 14:59:19 -0500886 mIcons.remove(slot);
Joe Onorato0cbda992010-05-02 16:28:15 -0700887
Joe Onorato0cbda992010-05-02 16:28:15 -0700888 if (mBar != null) {
889 try {
Jason Monk07473ce2016-01-05 14:59:19 -0500890 mBar.removeIcon(slot);
Joe Onorato0cbda992010-05-02 16:28:15 -0700891 } catch (RemoteException ex) {
892 }
893 }
894 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800895 }
896
Wale Ogunwale393b1c12014-10-18 16:22:01 -0700897 /**
Jorim Jaggi956ca412019-01-07 14:49:14 +0100898 * Enables System UI to know whether the top app is fullscreen or not, and whether this app is
899 * in immersive mode or not.
Daniel Sandlere02d8082010-10-08 15:13:22 -0400900 */
Jorim Jaggi956ca412019-01-07 14:49:14 +0100901 private void topAppWindowChanged(int displayId, boolean isFullscreen, boolean isImmersive) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400902 enforceStatusBar();
903
Daniel Sandlere02d8082010-10-08 15:13:22 -0400904 synchronized(mLock) {
Jorim Jaggi956ca412019-01-07 14:49:14 +0100905 getUiState(displayId).setFullscreen(isFullscreen);
906 getUiState(displayId).setImmersive(isImmersive);
Charles Chen24e7a9f2018-11-21 11:59:07 +0800907 mHandler.post(() -> {
908 if (mBar != null) {
909 try {
Jorim Jaggi956ca412019-01-07 14:49:14 +0100910 mBar.topAppWindowChanged(displayId, isFullscreen, isImmersive);
Charles Chen24e7a9f2018-11-21 11:59:07 +0800911 } catch (RemoteException ex) {
Dianne Hackborn7d049322011-06-14 15:00:32 -0700912 }
Jorim Jaggi86905582016-02-09 21:36:09 -0800913 }
914 });
Daniel Sandlere02d8082010-10-08 15:13:22 -0400915 }
916 }
917
Adam Lesinski182f73f2013-12-05 16:48:06 -0800918 @Override
lumark7570cac2019-03-07 22:14:38 +0800919 public void setImeWindowStatus(int displayId, final IBinder token, final int vis,
Tarandeep Singh07b318b2019-07-17 11:12:04 -0700920 final int backDisposition, final boolean showImeSwitcher,
921 boolean isMultiClientImeEnabled) {
satok06487a52010-10-29 11:37:18 +0900922 enforceStatusBar();
923
Joe Onorato857fd9b2011-01-27 15:08:35 -0800924 if (SPEW) {
925 Slog.d(TAG, "swetImeWindowStatus vis=" + vis + " backDisposition=" + backDisposition);
926 }
satok06487a52010-10-29 11:37:18 +0900927
928 synchronized(mLock) {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800929 // In case of IME change, we need to call up setImeWindowStatus() regardless of
930 // mImeWindowVis because mImeWindowVis may not have been set to false when the
satok06e07442010-11-02 19:46:55 +0900931 // previous IME was destroyed.
lumark7570cac2019-03-07 22:14:38 +0800932 getUiState(displayId).setImeWindowState(vis, backDisposition, showImeSwitcher, token);
Charles Chen24e7a9f2018-11-21 11:59:07 +0800933
934 mHandler.post(() -> {
935 if (mBar == null) return;
936 try {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800937 mBar.setImeWindowStatus(
Tarandeep Singh07b318b2019-07-17 11:12:04 -0700938 displayId, token, vis, backDisposition, showImeSwitcher,
939 isMultiClientImeEnabled);
Charles Chen24e7a9f2018-11-21 11:59:07 +0800940 } catch (RemoteException ex) { }
satok06e07442010-11-02 19:46:55 +0900941 });
satok06487a52010-10-29 11:37:18 +0900942 }
943 }
944
Tiger Huang0dbd5372019-10-26 00:24:22 +0800945 private void setDisableFlags(int displayId, int flags, String cause) {
Joe Onorato55bf3802011-01-25 13:42:10 -0800946 // also allows calls from window manager which is in this process.
Joe Onoratof63b0f42010-09-12 17:03:19 -0400947 enforceStatusBarService();
948
Tiger Huang0dbd5372019-10-26 00:24:22 +0800949 final int unknownFlags = flags & ~StatusBarManager.DISABLE_MASK;
950 if (unknownFlags != 0) {
951 Slog.e(TAG, "Unknown disable flags: 0x" + Integer.toHexString(unknownFlags),
952 new RuntimeException());
953 }
954
955 if (SPEW) Slog.d(TAG, "setDisableFlags(0x" + Integer.toHexString(flags) + ")");
Daniel Sandler60ee2562011-07-22 12:34:33 -0400956
Joe Onoratof63b0f42010-09-12 17:03:19 -0400957 synchronized (mLock) {
Tiger Huang0dbd5372019-10-26 00:24:22 +0800958 disableLocked(displayId, mCurrentUserId, flags, mSysUiVisToken, cause, 1);
Charles Chen24e7a9f2018-11-21 11:59:07 +0800959 }
960 }
961
962 /**
963 * @return {@link UiState} specified by {@code displayId}.
964 *
965 * <p>
966 * Note: If {@link UiState} specified by {@code displayId} does not exist, {@link UiState}
967 * will be allocated and {@code mDisplayUiState} will be updated accordingly.
968 * <p/>
969 */
970 private UiState getUiState(int displayId) {
971 UiState state = mDisplayUiState.get(displayId);
972 if (state == null) {
973 state = new UiState();
974 mDisplayUiState.put(displayId, state);
975 }
976 return state;
977 }
978
979 private class UiState {
Tiger Huang0dbd5372019-10-26 00:24:22 +0800980 private @Appearance int mAppearance = 0;
981 private AppearanceRegion[] mAppearanceRegions = new AppearanceRegion[0];
982 private ArraySet<Integer> mTransientBarTypes = new ArraySet<>();
983 private boolean mNavbarColorManagedByIme = false;
Jorim Jaggi956ca412019-01-07 14:49:14 +0100984 private boolean mFullscreen = false;
985 private boolean mImmersive = false;
Charles Chen24e7a9f2018-11-21 11:59:07 +0800986 private int mDisabled1 = 0;
987 private int mDisabled2 = 0;
988 private int mImeWindowVis = 0;
989 private int mImeBackDisposition = 0;
990 private boolean mShowImeSwitcher = false;
991 private IBinder mImeToken = null;
Tiger Huang0dbd5372019-10-26 00:24:22 +0800992
993 private void setAppearance(@Appearance int appearance,
994 AppearanceRegion[] appearanceRegions, boolean navbarColorManagedByIme) {
995 mAppearance = appearance;
996 mAppearanceRegions = appearanceRegions;
997 mNavbarColorManagedByIme = navbarColorManagedByIme;
998 }
999
1000 private boolean appearanceEquals(@Appearance int appearance,
1001 AppearanceRegion[] appearanceRegions, boolean navbarColorManagedByIme) {
1002 if (mAppearance != appearance || mAppearanceRegions.length != appearanceRegions.length
1003 || mNavbarColorManagedByIme != navbarColorManagedByIme) {
1004 return false;
1005 }
1006 for (int i = appearanceRegions.length - 1; i >= 0; i--) {
1007 if (!mAppearanceRegions[i].equals(appearanceRegions[i])) {
1008 return false;
1009 }
1010 }
1011 return true;
1012 }
1013
Tiger Huang332793b2019-10-29 23:21:27 +08001014 private void showTransient(@InternalInsetsType int[] types) {
Tiger Huang0dbd5372019-10-26 00:24:22 +08001015 for (int type : types) {
1016 mTransientBarTypes.add(type);
1017 }
1018 }
1019
Tiger Huang332793b2019-10-29 23:21:27 +08001020 private void clearTransient(@InternalInsetsType int[] types) {
Tiger Huang0dbd5372019-10-26 00:24:22 +08001021 for (int type : types) {
1022 mTransientBarTypes.remove(type);
1023 }
1024 }
1025
1026 private void setFullscreen(boolean isFullscreen) {
1027 mFullscreen = isFullscreen;
1028 }
1029
1030 private void setImmersive(boolean isImmersive) {
1031 mImmersive = isImmersive;
1032 }
Charles Chen24e7a9f2018-11-21 11:59:07 +08001033
1034 private int getDisabled1() {
1035 return mDisabled1;
1036 }
1037
1038 private int getDisabled2() {
1039 return mDisabled2;
1040 }
1041
1042 private void setDisabled(int disabled1, int disabled2) {
1043 mDisabled1 = disabled1;
1044 mDisabled2 = disabled2;
1045 }
1046
Charles Chen24e7a9f2018-11-21 11:59:07 +08001047 private boolean disableEquals(int disabled1, int disabled2) {
1048 return mDisabled1 == disabled1 && mDisabled2 == disabled2;
1049 }
1050
Charles Chen24e7a9f2018-11-21 11:59:07 +08001051 private void setImeWindowState(final int vis, final int backDisposition,
1052 final boolean showImeSwitcher, final IBinder token) {
1053 mImeWindowVis = vis;
1054 mImeBackDisposition = backDisposition;
1055 mShowImeSwitcher = showImeSwitcher;
1056 mImeToken = token;
Joe Onorato93056472010-09-10 10:30:46 -04001057 }
1058 }
1059
Jason Monk7e53f202016-01-28 10:40:20 -05001060 private void enforceStatusBarOrShell() {
1061 if (Binder.getCallingUid() == Process.SHELL_UID) {
1062 return;
1063 }
1064 enforceStatusBar();
1065 }
1066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067 private void enforceStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -07001068 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -07001069 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001070 }
1071
1072 private void enforceExpandStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -07001073 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.EXPAND_STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -07001074 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001075 }
1076
Joe Onorato8bc6c512010-06-04 16:21:12 -04001077 private void enforceStatusBarService() {
1078 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
1079 "StatusBarManagerService");
1080 }
1081
Kevin Chyn95c27e02018-09-12 01:46:16 -07001082 private void enforceBiometricDialog() {
1083 mContext.enforceCallingOrSelfPermission(
1084 android.Manifest.permission.MANAGE_BIOMETRIC_DIALOG,
1085 "StatusBarManagerService");
1086 }
1087
Joe Onorato4762c2d2010-05-17 15:42:59 -07001088 // ================================================================================
1089 // Callbacks from the status bar service.
1090 // ================================================================================
Charles Chen24e7a9f2018-11-21 11:59:07 +08001091 // TODO(b/118592525): refactor it as an IStatusBar API.
Adam Lesinski182f73f2013-12-05 16:48:06 -08001092 @Override
Yohei Yukawa49efa712019-04-04 11:49:02 -07001093 public RegisterStatusBarResult registerStatusBar(IStatusBar bar) {
Joe Onorato8bc6c512010-06-04 16:21:12 -04001094 enforceStatusBarService();
1095
Joe Onorato0cbda992010-05-02 16:28:15 -07001096 Slog.i(TAG, "registerStatusBar bar=" + bar);
1097 mBar = bar;
Gopal Krishna Shuklae5c83792018-06-29 18:20:36 +05301098 mDeathRecipient.linkToDeath();
Jason Monk361915c2017-03-21 20:33:59 -04001099 notifyBarAttachChanged();
Yohei Yukawa49efa712019-04-04 11:49:02 -07001100 final ArrayMap<String, StatusBarIcon> icons;
Joe Onorato75199e32010-05-29 17:22:51 -04001101 synchronized (mIcons) {
Yohei Yukawa49efa712019-04-04 11:49:02 -07001102 icons = new ArrayMap<>(mIcons);
Joe Onorato75199e32010-05-29 17:22:51 -04001103 }
Joe Onorato93056472010-09-10 10:30:46 -04001104 synchronized (mLock) {
Charles Chen24e7a9f2018-11-21 11:59:07 +08001105 // TODO(b/118592525): Currently, status bar only works on the default display.
1106 // Make it aware of multi-display if needed.
1107 final UiState state = mDisplayUiState.get(DEFAULT_DISPLAY);
Tiger Huang0dbd5372019-10-26 00:24:22 +08001108 final int[] transientBarTypes = new int[state.mTransientBarTypes.size()];
1109 for (int i = 0; i < transientBarTypes.length; i++) {
1110 transientBarTypes[i] = state.mTransientBarTypes.valueAt(i);
1111 }
Yohei Yukawa49efa712019-04-04 11:49:02 -07001112 return new RegisterStatusBarResult(icons, gatherDisableActionsLocked(mCurrentUserId, 1),
Tiger Huang0dbd5372019-10-26 00:24:22 +08001113 state.mAppearance, state.mAppearanceRegions, state.mImeWindowVis,
Yohei Yukawa49efa712019-04-04 11:49:02 -07001114 state.mImeBackDisposition, state.mShowImeSwitcher,
Tiger Huang0dbd5372019-10-26 00:24:22 +08001115 gatherDisableActionsLocked(mCurrentUserId, 2), state.mImeToken,
1116 state.mNavbarColorManagedByIme, state.mFullscreen, state.mImmersive,
1117 transientBarTypes);
Joe Onorato93056472010-09-10 10:30:46 -04001118 }
Joe Onorato2314aab2010-04-08 16:41:23 -05001119 }
Joe Onoratoaaba60b2010-05-23 15:18:41 -04001120
Jason Monk361915c2017-03-21 20:33:59 -04001121 private void notifyBarAttachChanged() {
1122 mHandler.post(() -> {
1123 if (mGlobalActionListener == null) return;
Michael Kwan2decbf72018-02-22 07:40:11 -08001124 mGlobalActionListener.onGlobalActionsAvailableChanged(mBar != null);
Jason Monk361915c2017-03-21 20:33:59 -04001125 });
1126 }
1127
Joe Onorato4762c2d2010-05-17 15:42:59 -07001128 /**
Christoph Studer1f32c652014-11-26 15:32:20 +01001129 * @param clearNotificationEffects whether to consider notifications as "shown" and stop
1130 * LED, vibration, and ringing
Joe Onorato4762c2d2010-05-17 15:42:59 -07001131 */
Adam Lesinski182f73f2013-12-05 16:48:06 -08001132 @Override
Chris Wrenb659c4f2015-06-25 17:12:27 -04001133 public void onPanelRevealed(boolean clearNotificationEffects, int numItems) {
Joe Onorato8bc6c512010-06-04 16:21:12 -04001134 enforceStatusBarService();
Adam Lesinski182f73f2013-12-05 16:48:06 -08001135 long identity = Binder.clearCallingIdentity();
1136 try {
Chris Wrenb659c4f2015-06-25 17:12:27 -04001137 mNotificationDelegate.onPanelRevealed(clearNotificationEffects, numItems);
Christoph Studer1f32c652014-11-26 15:32:20 +01001138 } finally {
1139 Binder.restoreCallingIdentity(identity);
1140 }
1141 }
1142
1143 @Override
1144 public void clearNotificationEffects() throws RemoteException {
1145 enforceStatusBarService();
1146 long identity = Binder.clearCallingIdentity();
1147 try {
1148 mNotificationDelegate.clearEffects();
Adam Lesinski182f73f2013-12-05 16:48:06 -08001149 } finally {
1150 Binder.restoreCallingIdentity(identity);
1151 }
Joe Onorato4762c2d2010-05-17 15:42:59 -07001152 }
1153
Adam Lesinski182f73f2013-12-05 16:48:06 -08001154 @Override
Christoph Studer760ea552014-03-21 13:10:21 +01001155 public void onPanelHidden() throws RemoteException {
1156 enforceStatusBarService();
1157 long identity = Binder.clearCallingIdentity();
1158 try {
1159 mNotificationDelegate.onPanelHidden();
1160 } finally {
1161 Binder.restoreCallingIdentity(identity);
1162 }
1163 }
1164
Jason Monk361915c2017-03-21 20:33:59 -04001165 /**
1166 * Allows the status bar to shutdown the device.
1167 */
1168 @Override
1169 public void shutdown() {
1170 enforceStatusBarService();
1171 long identity = Binder.clearCallingIdentity();
1172 try {
Michael Wright6cd10262017-04-04 17:44:56 +01001173 // ShutdownThread displays UI, so give it a UI context.
Jason Monk361915c2017-03-21 20:33:59 -04001174 mHandler.post(() ->
Michael Wright6cd10262017-04-04 17:44:56 +01001175 ShutdownThread.shutdown(getUiContext(),
1176 PowerManager.SHUTDOWN_USER_REQUESTED, false));
Jason Monk361915c2017-03-21 20:33:59 -04001177 } finally {
1178 Binder.restoreCallingIdentity(identity);
1179 }
1180 }
1181
1182 /**
1183 * Allows the status bar to reboot the device.
1184 */
1185 @Override
1186 public void reboot(boolean safeMode) {
1187 enforceStatusBarService();
1188 long identity = Binder.clearCallingIdentity();
1189 try {
1190 mHandler.post(() -> {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001191 // ShutdownThread displays UI, so give it a UI context.
Jason Monk361915c2017-03-21 20:33:59 -04001192 if (safeMode) {
Shunta Satobdb0e492017-04-14 16:01:54 +09001193 ShutdownThread.rebootSafeMode(getUiContext(), true);
Jason Monk361915c2017-03-21 20:33:59 -04001194 } else {
Michael Wright6cd10262017-04-04 17:44:56 +01001195 ShutdownThread.reboot(getUiContext(),
1196 PowerManager.SHUTDOWN_USER_REQUESTED, false);
Jason Monk361915c2017-03-21 20:33:59 -04001197 }
1198 });
1199 } finally {
1200 Binder.restoreCallingIdentity(identity);
1201 }
1202 }
1203
1204 @Override
1205 public void onGlobalActionsShown() {
1206 enforceStatusBarService();
1207 long identity = Binder.clearCallingIdentity();
1208 try {
1209 if (mGlobalActionListener == null) return;
1210 mGlobalActionListener.onGlobalActionsShown();
1211 } finally {
1212 Binder.restoreCallingIdentity(identity);
1213 }
1214 }
1215
1216 @Override
1217 public void onGlobalActionsHidden() {
1218 enforceStatusBarService();
1219 long identity = Binder.clearCallingIdentity();
1220 try {
1221 if (mGlobalActionListener == null) return;
1222 mGlobalActionListener.onGlobalActionsDismissed();
1223 } finally {
1224 Binder.restoreCallingIdentity(identity);
1225 }
1226 }
1227
Christoph Studer760ea552014-03-21 13:10:21 +01001228 @Override
Dieter Hsud39f0d52018-04-14 02:08:30 +08001229 public void onNotificationClick(String key, NotificationVisibility nv) {
Joe Onorato8bc6c512010-06-04 16:21:12 -04001230 enforceStatusBarService();
John Spurlocke6a7d932014-03-13 12:29:00 -04001231 final int callingUid = Binder.getCallingUid();
1232 final int callingPid = Binder.getCallingPid();
Adam Lesinski182f73f2013-12-05 16:48:06 -08001233 long identity = Binder.clearCallingIdentity();
1234 try {
Dieter Hsud39f0d52018-04-14 02:08:30 +08001235 mNotificationDelegate.onNotificationClick(callingUid, callingPid, key, nv);
Adam Lesinski182f73f2013-12-05 16:48:06 -08001236 } finally {
1237 Binder.restoreCallingIdentity(identity);
1238 }
Joe Onoratoaaba60b2010-05-23 15:18:41 -04001239 }
1240
Adam Lesinski182f73f2013-12-05 16:48:06 -08001241 @Override
Tony Mak7d4b3a52018-11-27 17:29:36 +00001242 public void onNotificationActionClick(
1243 String key, int actionIndex, Notification.Action action, NotificationVisibility nv,
1244 boolean generatedByAssistant) {
Christoph Studer4da84cd2014-10-21 17:24:20 +02001245 enforceStatusBarService();
1246 final int callingUid = Binder.getCallingUid();
1247 final int callingPid = Binder.getCallingPid();
1248 long identity = Binder.clearCallingIdentity();
1249 try {
1250 mNotificationDelegate.onNotificationActionClick(callingUid, callingPid, key,
Tony Mak7d4b3a52018-11-27 17:29:36 +00001251 actionIndex, action, nv, generatedByAssistant);
Christoph Studer4da84cd2014-10-21 17:24:20 +02001252 } finally {
1253 Binder.restoreCallingIdentity(identity);
1254 }
1255 }
1256
1257 @Override
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -07001258 public void onNotificationError(String pkg, String tag, int id,
Kenny Guy3a7c4a52014-03-03 18:24:03 +00001259 int uid, int initialPid, String message, int userId) {
Joe Onorato8bc6c512010-06-04 16:21:12 -04001260 enforceStatusBarService();
John Spurlocke6a7d932014-03-13 12:29:00 -04001261 final int callingUid = Binder.getCallingUid();
1262 final int callingPid = Binder.getCallingPid();
Adam Lesinski182f73f2013-12-05 16:48:06 -08001263 long identity = Binder.clearCallingIdentity();
1264 try {
1265 // WARNING: this will call back into us to do the remove. Don't hold any locks.
John Spurlocke6a7d932014-03-13 12:29:00 -04001266 mNotificationDelegate.onNotificationError(callingUid, callingPid,
1267 pkg, tag, id, uid, initialPid, message, userId);
Adam Lesinski182f73f2013-12-05 16:48:06 -08001268 } finally {
1269 Binder.restoreCallingIdentity(identity);
1270 }
Joe Onorato005847b2010-06-04 16:08:02 -04001271 }
1272
Adam Lesinski182f73f2013-12-05 16:48:06 -08001273 @Override
Julia Reynolds503ed942017-10-04 16:04:56 -04001274 public void onNotificationClear(String pkg, String tag, int id, int userId, String key,
Julia Reynoldsfd4099d2018-08-21 11:06:06 -04001275 @NotificationStats.DismissalSurface int dismissalSurface,
1276 @NotificationStats.DismissalSentiment int dismissalSentiment,
1277 NotificationVisibility nv) {
Daniel Sandler0f0b11c2010-08-04 15:54:58 -04001278 enforceStatusBarService();
John Spurlocke6a7d932014-03-13 12:29:00 -04001279 final int callingUid = Binder.getCallingUid();
1280 final int callingPid = Binder.getCallingPid();
Adam Lesinski182f73f2013-12-05 16:48:06 -08001281 long identity = Binder.clearCallingIdentity();
1282 try {
Dieter Hsud39f0d52018-04-14 02:08:30 +08001283 mNotificationDelegate.onNotificationClear(callingUid, callingPid, pkg, tag, id, userId,
Julia Reynoldsfd4099d2018-08-21 11:06:06 -04001284 key, dismissalSurface, dismissalSentiment, nv);
Adam Lesinski182f73f2013-12-05 16:48:06 -08001285 } finally {
1286 Binder.restoreCallingIdentity(identity);
1287 }
Daniel Sandler0f0b11c2010-08-04 15:54:58 -04001288 }
1289
Adam Lesinski182f73f2013-12-05 16:48:06 -08001290 @Override
Christoph Studer92b389d2014-04-01 18:44:40 +02001291 public void onNotificationVisibilityChanged(
Chris Wrend1dbc922015-06-19 17:51:16 -04001292 NotificationVisibility[] newlyVisibleKeys, NotificationVisibility[] noLongerVisibleKeys)
1293 throws RemoteException {
Christoph Studer92b389d2014-04-01 18:44:40 +02001294 enforceStatusBarService();
1295 long identity = Binder.clearCallingIdentity();
1296 try {
1297 mNotificationDelegate.onNotificationVisibilityChanged(
1298 newlyVisibleKeys, noLongerVisibleKeys);
1299 } finally {
1300 Binder.restoreCallingIdentity(identity);
1301 }
1302 }
1303
1304 @Override
Gustav Senntona8e38aa2019-01-22 14:55:39 +00001305 public void onNotificationExpansionChanged(String key, boolean userAction, boolean expanded,
1306 int location) throws RemoteException {
Chris Wren78403d72014-07-28 10:23:24 +01001307 enforceStatusBarService();
1308 long identity = Binder.clearCallingIdentity();
1309 try {
1310 mNotificationDelegate.onNotificationExpansionChanged(
Gustav Senntona8e38aa2019-01-22 14:55:39 +00001311 key, userAction, expanded, location);
Chris Wren78403d72014-07-28 10:23:24 +01001312 } finally {
1313 Binder.restoreCallingIdentity(identity);
1314 }
1315 }
1316
1317 @Override
Julia Reynolds503ed942017-10-04 16:04:56 -04001318 public void onNotificationDirectReplied(String key) throws RemoteException {
1319 enforceStatusBarService();
1320 long identity = Binder.clearCallingIdentity();
1321 try {
1322 mNotificationDelegate.onNotificationDirectReplied(key);
1323 } finally {
1324 Binder.restoreCallingIdentity(identity);
1325 }
1326 }
1327
1328 @Override
Gustav Senntond25a64d2018-12-07 10:58:39 +00001329 public void onNotificationSmartSuggestionsAdded(String key, int smartReplyCount,
Milo Sredkov13d88112019-02-01 12:23:24 +00001330 int smartActionCount, boolean generatedByAssistant, boolean editBeforeSending) {
Kenny Guy23991102018-04-05 21:18:38 +01001331 enforceStatusBarService();
1332 long identity = Binder.clearCallingIdentity();
1333 try {
Gustav Senntond25a64d2018-12-07 10:58:39 +00001334 mNotificationDelegate.onNotificationSmartSuggestionsAdded(key, smartReplyCount,
Milo Sredkov13d88112019-02-01 12:23:24 +00001335 smartActionCount, generatedByAssistant, editBeforeSending);
Kenny Guy23991102018-04-05 21:18:38 +01001336 } finally {
1337 Binder.restoreCallingIdentity(identity);
1338 }
1339 }
1340
1341 @Override
Tony Mak29996702018-11-26 16:23:34 +00001342 public void onNotificationSmartReplySent(
Milo Sredkov13d88112019-02-01 12:23:24 +00001343 String key, int replyIndex, CharSequence reply, int notificationLocation,
1344 boolean modifiedBeforeSending) throws RemoteException {
Kenny Guy23991102018-04-05 21:18:38 +01001345 enforceStatusBarService();
1346 long identity = Binder.clearCallingIdentity();
1347 try {
Tony Mak29996702018-11-26 16:23:34 +00001348 mNotificationDelegate.onNotificationSmartReplySent(key, replyIndex, reply,
Milo Sredkov13d88112019-02-01 12:23:24 +00001349 notificationLocation, modifiedBeforeSending);
Kenny Guy23991102018-04-05 21:18:38 +01001350 } finally {
1351 Binder.restoreCallingIdentity(identity);
1352 }
1353 }
1354
1355 @Override
Julia Reynolds503ed942017-10-04 16:04:56 -04001356 public void onNotificationSettingsViewed(String key) throws RemoteException {
1357 enforceStatusBarService();
1358 long identity = Binder.clearCallingIdentity();
1359 try {
1360 mNotificationDelegate.onNotificationSettingsViewed(key);
1361 } finally {
1362 Binder.restoreCallingIdentity(identity);
1363 }
1364 }
1365
1366 @Override
Kenny Guy3a7c4a52014-03-03 18:24:03 +00001367 public void onClearAllNotifications(int userId) {
Joe Onorato8bc6c512010-06-04 16:21:12 -04001368 enforceStatusBarService();
John Spurlocke6a7d932014-03-13 12:29:00 -04001369 final int callingUid = Binder.getCallingUid();
1370 final int callingPid = Binder.getCallingPid();
Adam Lesinski182f73f2013-12-05 16:48:06 -08001371 long identity = Binder.clearCallingIdentity();
1372 try {
John Spurlocke6a7d932014-03-13 12:29:00 -04001373 mNotificationDelegate.onClearAll(callingUid, callingPid, userId);
Adam Lesinski182f73f2013-12-05 16:48:06 -08001374 } finally {
1375 Binder.restoreCallingIdentity(identity);
Joe Onorato18e69df2010-05-17 22:26:12 -07001376 }
Joe Onorato0cbda992010-05-02 16:28:15 -07001377 }
1378
Jason Monk7e53f202016-01-28 10:40:20 -05001379 @Override
Mady Mellora54e9fa2019-04-18 13:26:18 -07001380 public void onNotificationBubbleChanged(String key, boolean isBubble) {
1381 enforceStatusBarService();
1382 long identity = Binder.clearCallingIdentity();
1383 try {
1384 mNotificationDelegate.onNotificationBubbleChanged(key, isBubble);
1385 } finally {
1386 Binder.restoreCallingIdentity(identity);
1387 }
1388 }
1389
1390 @Override
Mady Mellorf44b6832020-01-14 13:26:14 -08001391 public void onBubbleNotificationSuppressionChanged(String key, boolean isNotifSuppressed) {
1392 enforceStatusBarService();
1393 long identity = Binder.clearCallingIdentity();
1394 try {
1395 mNotificationDelegate.onBubbleNotificationSuppressionChanged(key, isNotifSuppressed);
1396 } finally {
1397 Binder.restoreCallingIdentity(identity);
1398 }
1399 }
1400
1401 @Override
Aran Ink979c9762019-10-24 16:09:45 -04001402 public void grantInlineReplyUriPermission(String key, Uri uri, UserHandle user,
1403 String packageName) {
Aran Inkfd2bfd32019-10-04 16:30:01 -04001404 enforceStatusBarService();
1405 int callingUid = Binder.getCallingUid();
1406 long identity = Binder.clearCallingIdentity();
1407 try {
Aran Ink979c9762019-10-24 16:09:45 -04001408 mNotificationDelegate.grantInlineReplyUriPermission(key, uri, user, packageName,
1409 callingUid);
1410 } finally {
1411 Binder.restoreCallingIdentity(identity);
1412 }
1413 }
1414
1415 @Override
1416 public void clearInlineReplyUriPermissions(String key) {
1417 enforceStatusBarService();
1418 int callingUid = Binder.getCallingUid();
1419 long identity = Binder.clearCallingIdentity();
1420 try {
1421 mNotificationDelegate.clearInlineReplyUriPermissions(key, callingUid);
Aran Inkfd2bfd32019-10-04 16:30:01 -04001422 } finally {
1423 Binder.restoreCallingIdentity(identity);
1424 }
1425 }
1426
1427 @Override
Jason Monk7e53f202016-01-28 10:40:20 -05001428 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
Dianne Hackborn354736e2016-08-22 17:00:05 -07001429 String[] args, ShellCallback callback, ResultReceiver resultReceiver) {
Evan Lairdedd016f2019-01-23 18:36:29 -05001430 (new StatusBarShellCommand(this, mContext)).exec(
Dianne Hackborn354736e2016-08-22 17:00:05 -07001431 this, in, out, err, args, callback, resultReceiver);
Jason Monk7e53f202016-01-28 10:40:20 -05001432 }
1433
Robert Horvath5560f382019-07-10 10:46:38 +02001434 @Override
1435 public void showInattentiveSleepWarning() {
1436 enforceStatusBarService();
1437 if (mBar != null) {
1438 try {
1439 mBar.showInattentiveSleepWarning();
1440 } catch (RemoteException ex) {
1441 }
1442 }
1443 }
1444
1445 @Override
Robert Horvath60e51fe2019-08-20 13:10:34 +02001446 public void dismissInattentiveSleepWarning(boolean animated) {
Robert Horvath5560f382019-07-10 10:46:38 +02001447 enforceStatusBarService();
1448 if (mBar != null) {
1449 try {
Robert Horvath60e51fe2019-08-20 13:10:34 +02001450 mBar.dismissInattentiveSleepWarning(animated);
Robert Horvath5560f382019-07-10 10:46:38 +02001451 } catch (RemoteException ex) {
1452 }
1453 }
1454 }
1455
Jason Monkf8c2f7b2017-09-06 09:22:29 -04001456 public String[] getStatusBarIcons() {
1457 return mContext.getResources().getStringArray(R.array.config_statusBarIcons);
1458 }
1459
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001460 // ================================================================================
1461 // Can be called from any thread
1462 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001464 // lock on mDisableRecords
Benjamin Franzcde0a2a2015-04-23 17:19:48 +01001465 void manageDisableListLocked(int userId, int what, IBinder token, String pkg, int which) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001466 if (SPEW) {
John Spurlock13451a22012-09-28 14:40:41 -04001467 Slog.d(TAG, "manageDisableList userId=" + userId
1468 + " what=0x" + Integer.toHexString(what) + " pkg=" + pkg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001469 }
Charles Heede39092017-09-18 09:19:28 +01001470
1471 // Find matching record, if any
Evan Lairdedd016f2019-01-23 18:36:29 -05001472 Pair<Integer, DisableRecord> match = findMatchingRecordLocked(token, userId);
1473 int i = match.first;
1474 DisableRecord record = match.second;
Charles Heede39092017-09-18 09:19:28 +01001475
1476 // Remove record if binder is already dead
1477 if (!token.isBinderAlive()) {
1478 if (record != null) {
Joe Onorato7bb8eeb2011-01-27 16:00:58 -08001479 mDisableRecords.remove(i);
Charles Heede39092017-09-18 09:19:28 +01001480 record.token.unlinkToDeath(record, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001481 }
Charles Heede39092017-09-18 09:19:28 +01001482 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001483 }
Charles Heede39092017-09-18 09:19:28 +01001484
1485 // Update existing record
1486 if (record != null) {
1487 record.setFlags(what, which, pkg);
1488 if (record.isEmpty()) {
1489 mDisableRecords.remove(i);
1490 record.token.unlinkToDeath(record, 0);
1491 }
1492 return;
1493 }
1494
1495 // Record doesn't exist, so we create a new one
1496 record = new DisableRecord(userId, token);
1497 record.setFlags(what, which, pkg);
1498 mDisableRecords.add(record);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001499 }
1500
Evan Lairdedd016f2019-01-23 18:36:29 -05001501 @Nullable
1502 @GuardedBy("mLock")
1503 private Pair<Integer, DisableRecord> findMatchingRecordLocked(IBinder token, int userId) {
1504 final int numRecords = mDisableRecords.size();
1505 DisableRecord record = null;
1506 int i;
1507 for (i = 0; i < numRecords; i++) {
1508 DisableRecord r = mDisableRecords.get(i);
1509 if (r.token == token && r.userId == userId) {
1510 record = r;
1511 break;
1512 }
1513 }
1514
1515 return new Pair<Integer, DisableRecord>(i, record);
1516 }
1517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001518 // lock on mDisableRecords
Benjamin Franzcde0a2a2015-04-23 17:19:48 +01001519 int gatherDisableActionsLocked(int userId, int which) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001520 final int N = mDisableRecords.size();
1521 // gather the new net flags
1522 int net = 0;
1523 for (int i=0; i<N; i++) {
John Spurlock13451a22012-09-28 14:40:41 -04001524 final DisableRecord rec = mDisableRecords.get(i);
1525 if (rec.userId == userId) {
Charles Heede39092017-09-18 09:19:28 +01001526 net |= rec.getFlags(which);
John Spurlock13451a22012-09-28 14:40:41 -04001527 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001528 }
1529 return net;
1530 }
1531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001532 // ================================================================================
1533 // Always called from UI thread
1534 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001536 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001537 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Joe Onorato0cbda992010-05-02 16:28:15 -07001538
Joe Onorato7bb8eeb2011-01-27 16:00:58 -08001539 synchronized (mLock) {
Charles Chen24e7a9f2018-11-21 11:59:07 +08001540 for (int i = 0; i < mDisplayUiState.size(); i++) {
1541 final int key = mDisplayUiState.keyAt(i);
1542 final UiState state = mDisplayUiState.get(key);
1543 pw.println(" displayId=" + key);
1544 pw.println(" mDisabled1=0x" + Integer.toHexString(state.getDisabled1()));
1545 pw.println(" mDisabled2=0x" + Integer.toHexString(state.getDisabled2()));
1546 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001547 final int N = mDisableRecords.size();
John Spurlock13451a22012-09-28 14:40:41 -04001548 pw.println(" mDisableRecords.size=" + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001549 for (int i=0; i<N; i++) {
1550 DisableRecord tok = mDisableRecords.get(i);
Charles Heede39092017-09-18 09:19:28 +01001551 pw.println(" [" + i + "] " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001552 }
Adrian Roos2a629102016-04-15 16:28:03 -07001553 pw.println(" mCurrentUserId=" + mCurrentUserId);
Dan Sandlerf3a1f2c2016-06-26 15:59:13 -04001554 pw.println(" mIcons=");
1555 for (String slot : mIcons.keySet()) {
1556 pw.println(" ");
1557 pw.print(slot);
1558 pw.print(" -> ");
1559 final StatusBarIcon icon = mIcons.get(slot);
1560 pw.print(icon);
1561 if (!TextUtils.isEmpty(icon.contentDescription)) {
1562 pw.print(" \"");
1563 pw.print(icon.contentDescription);
1564 pw.print("\"");
1565 }
1566 pw.println();
1567 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001568 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001569 }
Michael Wright6cd10262017-04-04 17:44:56 +01001570
1571 private static final Context getUiContext() {
1572 return ActivityThread.currentActivityThread().getSystemUiContext();
1573 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001574}