blob: 9ff363dddc3c323306670c97be631b62cbe7e5b4 [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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080017package android.app;
18
Benjamin Franzcde0a2a2015-04-23 17:19:48 +010019import android.annotation.IntDef;
Evan Laird2c4d0cf2019-02-28 12:10:29 -050020import android.annotation.NonNull;
Fabian Kozynskie3137e32018-09-28 11:20:04 -040021import android.annotation.Nullable;
Evan Lairdab196592019-02-26 17:21:32 -050022import android.annotation.RequiresPermission;
Evan Lairdedd016f2019-01-23 18:36:29 -050023import android.annotation.SystemApi;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060024import android.annotation.SystemService;
Mathew Inwood61e8ae62018-08-14 14:17:44 +010025import android.annotation.UnsupportedAppUsage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.content.Context;
27import android.os.Binder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.os.IBinder;
Charles Heede39092017-09-18 09:19:28 +010029import android.os.RemoteException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.os.ServiceManager;
Evan Lairdedd016f2019-01-23 18:36:29 -050031import android.util.Pair;
Daniel Sandler9cbd3602011-10-18 22:59:00 -040032import android.util.Slog;
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080033import android.view.View;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034
Joe Onorato0cbda992010-05-02 16:28:15 -070035import com.android.internal.statusbar.IStatusBarService;
36
Benjamin Franzcde0a2a2015-04-23 17:19:48 +010037import java.lang.annotation.Retention;
38import java.lang.annotation.RetentionPolicy;
39
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040/**
41 * Allows an app to control the status bar.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060043@SystemService(Context.STATUS_BAR_SERVICE)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044public class StatusBarManager {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045
Evan Laird27323242019-01-11 16:08:07 -050046 /** @hide */
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080047 public static final int DISABLE_EXPAND = View.STATUS_BAR_DISABLE_EXPAND;
Evan Laird27323242019-01-11 16:08:07 -050048 /** @hide */
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080049 public static final int DISABLE_NOTIFICATION_ICONS = View.STATUS_BAR_DISABLE_NOTIFICATION_ICONS;
Evan Laird27323242019-01-11 16:08:07 -050050 /** @hide */
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080051 public static final int DISABLE_NOTIFICATION_ALERTS
52 = View.STATUS_BAR_DISABLE_NOTIFICATION_ALERTS;
Evan Laird27323242019-01-11 16:08:07 -050053
54 /** @hide */
Dan Sandlera5e0f412014-01-23 15:11:54 -050055 @Deprecated
Mathew Inwood61e8ae62018-08-14 14:17:44 +010056 @UnsupportedAppUsage
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080057 public static final int DISABLE_NOTIFICATION_TICKER
58 = View.STATUS_BAR_DISABLE_NOTIFICATION_TICKER;
Evan Laird27323242019-01-11 16:08:07 -050059 /** @hide */
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080060 public static final int DISABLE_SYSTEM_INFO = View.STATUS_BAR_DISABLE_SYSTEM_INFO;
Evan Laird27323242019-01-11 16:08:07 -050061 /** @hide */
Daniel Sandlerdba93562011-10-06 16:39:58 -040062 public static final int DISABLE_HOME = View.STATUS_BAR_DISABLE_HOME;
Evan Laird27323242019-01-11 16:08:07 -050063 /** @hide */
Daniel Sandlerdba93562011-10-06 16:39:58 -040064 public static final int DISABLE_RECENT = View.STATUS_BAR_DISABLE_RECENT;
Evan Laird27323242019-01-11 16:08:07 -050065 /** @hide */
Joe Onorato6478adc2011-01-27 21:15:01 -080066 public static final int DISABLE_BACK = View.STATUS_BAR_DISABLE_BACK;
Evan Laird27323242019-01-11 16:08:07 -050067 /** @hide */
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080068 public static final int DISABLE_CLOCK = View.STATUS_BAR_DISABLE_CLOCK;
Evan Laird27323242019-01-11 16:08:07 -050069 /** @hide */
Daniel Sandlerd5483c32012-10-19 16:44:15 -040070 public static final int DISABLE_SEARCH = View.STATUS_BAR_DISABLE_SEARCH;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071
Evan Laird27323242019-01-11 16:08:07 -050072 /** @hide */
Daniel Sandlerdba93562011-10-06 16:39:58 -040073 @Deprecated
Evan Laird27323242019-01-11 16:08:07 -050074 public static final int DISABLE_NAVIGATION =
Daniel Sandlerdba93562011-10-06 16:39:58 -040075 View.STATUS_BAR_DISABLE_HOME | View.STATUS_BAR_DISABLE_RECENT;
76
Evan Laird27323242019-01-11 16:08:07 -050077 /** @hide */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078 public static final int DISABLE_NONE = 0x00000000;
79
Evan Laird27323242019-01-11 16:08:07 -050080 /** @hide */
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080081 public static final int DISABLE_MASK = DISABLE_EXPAND | DISABLE_NOTIFICATION_ICONS
82 | DISABLE_NOTIFICATION_ALERTS | DISABLE_NOTIFICATION_TICKER
Daniel Sandlerd5483c32012-10-19 16:44:15 -040083 | DISABLE_SYSTEM_INFO | DISABLE_RECENT | DISABLE_HOME | DISABLE_BACK | DISABLE_CLOCK
84 | DISABLE_SEARCH;
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080085
Evan Laird27323242019-01-11 16:08:07 -050086 /** @hide */
Charles Chenf3d295c2018-11-30 18:15:21 +080087 @IntDef(flag = true, prefix = {"DISABLE_"}, value = {
88 DISABLE_NONE,
89 DISABLE_EXPAND,
90 DISABLE_NOTIFICATION_ICONS,
91 DISABLE_NOTIFICATION_ALERTS,
92 DISABLE_NOTIFICATION_TICKER,
93 DISABLE_SYSTEM_INFO,
94 DISABLE_HOME,
95 DISABLE_RECENT,
96 DISABLE_BACK,
97 DISABLE_CLOCK,
98 DISABLE_SEARCH
99 })
100 @Retention(RetentionPolicy.SOURCE)
101 public @interface DisableFlags {}
102
Benjamin Franz27cf1462015-04-23 19:36:42 +0100103 /**
104 * Flag to disable quick settings.
105 *
106 * Setting this flag disables quick settings completely, but does not disable expanding the
107 * notification shade.
108 */
Evan Laird27323242019-01-11 16:08:07 -0500109 /** @hide */
Charles He6a79b0d2017-09-18 09:50:58 +0100110 public static final int DISABLE2_QUICK_SETTINGS = 1;
Evan Laird27323242019-01-11 16:08:07 -0500111 /** @hide */
Charles He6a79b0d2017-09-18 09:50:58 +0100112 public static final int DISABLE2_SYSTEM_ICONS = 1 << 1;
Evan Laird27323242019-01-11 16:08:07 -0500113 /** @hide */
Charles He2eda2422017-09-24 17:55:21 +0100114 public static final int DISABLE2_NOTIFICATION_SHADE = 1 << 2;
Evan Laird27323242019-01-11 16:08:07 -0500115 /** @hide */
Charles He9851a8d2017-10-10 17:31:30 +0100116 public static final int DISABLE2_GLOBAL_ACTIONS = 1 << 3;
Evan Laird27323242019-01-11 16:08:07 -0500117 /** @hide */
Mike Digmandd2f49e2018-03-16 10:54:22 -0700118 public static final int DISABLE2_ROTATE_SUGGESTIONS = 1 << 4;
Benjamin Franz27cf1462015-04-23 19:36:42 +0100119
Evan Laird27323242019-01-11 16:08:07 -0500120 /** @hide */
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100121 public static final int DISABLE2_NONE = 0x00000000;
122
Evan Laird27323242019-01-11 16:08:07 -0500123 /** @hide */
Charles He2eda2422017-09-24 17:55:21 +0100124 public static final int DISABLE2_MASK = DISABLE2_QUICK_SETTINGS | DISABLE2_SYSTEM_ICONS
Mike Digmandd2f49e2018-03-16 10:54:22 -0700125 | DISABLE2_NOTIFICATION_SHADE | DISABLE2_GLOBAL_ACTIONS | DISABLE2_ROTATE_SUGGESTIONS;
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100126
Evan Laird27323242019-01-11 16:08:07 -0500127 /** @hide */
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700128 @IntDef(flag = true, prefix = { "DISABLE2_" }, value = {
129 DISABLE2_NONE,
130 DISABLE2_MASK,
131 DISABLE2_QUICK_SETTINGS,
132 DISABLE2_SYSTEM_ICONS,
133 DISABLE2_NOTIFICATION_SHADE,
Mike Digmandd2f49e2018-03-16 10:54:22 -0700134 DISABLE2_GLOBAL_ACTIONS,
135 DISABLE2_ROTATE_SUGGESTIONS
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700136 })
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100137 @Retention(RetentionPolicy.SOURCE)
138 public @interface Disable2Flags {}
139
Evan Lairdedd016f2019-01-23 18:36:29 -0500140 /**
141 * Default disable flags for setup
142 *
143 * @hide
144 */
145 public static final int DEFAULT_SETUP_DISABLE_FLAGS = DISABLE_NOTIFICATION_ALERTS
146 | DISABLE_HOME | DISABLE_EXPAND | DISABLE_RECENT | DISABLE_CLOCK | DISABLE_SEARCH;
147
148 /**
149 * Default disable2 flags for setup
150 *
151 * @hide
152 */
153 public static final int DEFAULT_SETUP_DISABLE2_FLAGS = DISABLE2_ROTATE_SUGGESTIONS;
154
Evan Laird27323242019-01-11 16:08:07 -0500155 /** @hide */
John Spurlock56d007b2013-10-28 18:40:56 -0400156 public static final int NAVIGATION_HINT_BACK_ALT = 1 << 0;
Evan Laird27323242019-01-11 16:08:07 -0500157 /** @hide */
Jason Monkf1ff2092014-04-29 16:50:53 -0400158 public static final int NAVIGATION_HINT_IME_SHOWN = 1 << 1;
Daniel Sandler328310c2011-09-23 15:56:52 -0400159
Evan Laird27323242019-01-11 16:08:07 -0500160 /** @hide */
John Spurlock97642182013-07-29 17:58:39 -0400161 public static final int WINDOW_STATUS_BAR = 1;
Evan Laird27323242019-01-11 16:08:07 -0500162 /** @hide */
John Spurlock97642182013-07-29 17:58:39 -0400163 public static final int WINDOW_NAVIGATION_BAR = 2;
164
Evan Laird27323242019-01-11 16:08:07 -0500165 /** @hide */
Charles Chenf3d295c2018-11-30 18:15:21 +0800166 @IntDef(flag = true, prefix = { "WINDOW_" }, value = {
167 WINDOW_STATUS_BAR,
168 WINDOW_NAVIGATION_BAR
169 })
170 @Retention(RetentionPolicy.SOURCE)
171 public @interface WindowType {}
172
Evan Laird27323242019-01-11 16:08:07 -0500173 /** @hide */
John Spurlock5b9145b2013-08-20 15:13:47 -0400174 public static final int WINDOW_STATE_SHOWING = 0;
Evan Laird27323242019-01-11 16:08:07 -0500175 /** @hide */
John Spurlock97642182013-07-29 17:58:39 -0400176 public static final int WINDOW_STATE_HIDING = 1;
Evan Laird27323242019-01-11 16:08:07 -0500177 /** @hide */
John Spurlock5b9145b2013-08-20 15:13:47 -0400178 public static final int WINDOW_STATE_HIDDEN = 2;
John Spurlock97642182013-07-29 17:58:39 -0400179
Evan Laird27323242019-01-11 16:08:07 -0500180 /** @hide */
Charles Chenf3d295c2018-11-30 18:15:21 +0800181 @IntDef(flag = true, prefix = { "WINDOW_STATE_" }, value = {
182 WINDOW_STATE_SHOWING,
183 WINDOW_STATE_HIDING,
184 WINDOW_STATE_HIDDEN
185 })
186 @Retention(RetentionPolicy.SOURCE)
187 public @interface WindowVisibleState {}
188
Evan Laird27323242019-01-11 16:08:07 -0500189 /** @hide */
Jorim Jaggi40aa8812015-09-23 12:59:22 -0700190 public static final int CAMERA_LAUNCH_SOURCE_WIGGLE = 0;
Evan Laird27323242019-01-11 16:08:07 -0500191 /** @hide */
Jorim Jaggi40aa8812015-09-23 12:59:22 -0700192 public static final int CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP = 1;
Evan Laird27323242019-01-11 16:08:07 -0500193 /** @hide */
Jonathan Solnita4138162017-05-10 21:06:04 -0700194 public static final int CAMERA_LAUNCH_SOURCE_LIFT_TRIGGER = 2;
Jorim Jaggi40aa8812015-09-23 12:59:22 -0700195
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100196 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197 private Context mContext;
Joe Onorato25f95f92010-04-08 18:37:10 -0500198 private IStatusBarService mService;
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100199 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200 private IBinder mToken = new Binder();
201
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100202 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800203 StatusBarManager(Context context) {
204 mContext = context;
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400205 }
206
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100207 @UnsupportedAppUsage
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400208 private synchronized IStatusBarService getService() {
209 if (mService == null) {
210 mService = IStatusBarService.Stub.asInterface(
211 ServiceManager.getService(Context.STATUS_BAR_SERVICE));
212 if (mService == null) {
213 Slog.w("StatusBarManager", "warning: no STATUS_BAR_SERVICE");
214 }
215 }
216 return mService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217 }
218
219 /**
220 * Disable some features in the status bar. Pass the bitwise-or of the DISABLE_* flags.
221 * To re-enable everything, pass {@link #DISABLE_NONE}.
Evan Laird27323242019-01-11 16:08:07 -0500222 *
223 * @hide
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100225 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226 public void disable(int what) {
227 try {
Evan Lairda6917e12018-05-29 17:28:58 -0400228 final int userId = Binder.getCallingUserHandle().getIdentifier();
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400229 final IStatusBarService svc = getService();
230 if (svc != null) {
Evan Lairda6917e12018-05-29 17:28:58 -0400231 svc.disableForUser(what, mToken, mContext.getPackageName(), userId);
Jim Miller305c78c2011-10-16 14:54:38 -0700232 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700234 throw ex.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800235 }
236 }
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100237
238 /**
239 * Disable additional status bar features. Pass the bitwise-or of the DISABLE2_* flags.
240 * To re-enable everything, pass {@link #DISABLE_NONE}.
241 *
242 * Warning: Only pass DISABLE2_* flags into this function, do not use DISABLE_* flags.
Evan Laird27323242019-01-11 16:08:07 -0500243 *
244 * @hide
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100245 */
246 public void disable2(@Disable2Flags int what) {
247 try {
Evan Lairda6917e12018-05-29 17:28:58 -0400248 final int userId = Binder.getCallingUserHandle().getIdentifier();
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100249 final IStatusBarService svc = getService();
250 if (svc != null) {
Evan Lairda6917e12018-05-29 17:28:58 -0400251 svc.disable2ForUser(what, mToken, mContext.getPackageName(), userId);
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100252 }
253 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700254 throw ex.rethrowFromSystemServer();
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100255 }
256 }
257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800258 /**
Daniel Sandler11cf1782012-09-27 14:03:08 -0400259 * Expand the notifications panel.
Evan Laird27323242019-01-11 16:08:07 -0500260 *
261 * @hide
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800262 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100263 @UnsupportedAppUsage
Daniel Sandler11cf1782012-09-27 14:03:08 -0400264 public void expandNotificationsPanel() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400266 final IStatusBarService svc = getService();
267 if (svc != null) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400268 svc.expandNotificationsPanel();
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400269 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700271 throw ex.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 }
273 }
Evan Laird27323242019-01-11 16:08:07 -0500274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 /**
Daniel Sandler11cf1782012-09-27 14:03:08 -0400276 * Collapse the notifications and settings panels.
Evan Laird27323242019-01-11 16:08:07 -0500277 *
278 * @hide
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100280 @UnsupportedAppUsage
Daniel Sandler11cf1782012-09-27 14:03:08 -0400281 public void collapsePanels() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800282 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400283 final IStatusBarService svc = getService();
284 if (svc != null) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400285 svc.collapsePanels();
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700286 }
287 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700288 throw ex.rethrowFromSystemServer();
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700289 }
290 }
291
292 /**
Daniel Sandler11cf1782012-09-27 14:03:08 -0400293 * Expand the settings panel.
Evan Laird27323242019-01-11 16:08:07 -0500294 *
295 * @hide
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700296 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100297 @UnsupportedAppUsage
Daniel Sandler11cf1782012-09-27 14:03:08 -0400298 public void expandSettingsPanel() {
Jason Monka9927322015-12-13 16:22:37 -0500299 expandSettingsPanel(null);
300 }
301
302 /**
Fabian Kozynskie3137e32018-09-28 11:20:04 -0400303 * Expand the settings panel and open a subPanel. If the subpanel is null or does not have a
304 * corresponding tile, the QS panel is simply expanded
Evan Laird27323242019-01-11 16:08:07 -0500305 *
306 * @hide
Jason Monka9927322015-12-13 16:22:37 -0500307 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100308 @UnsupportedAppUsage
Fabian Kozynskie3137e32018-09-28 11:20:04 -0400309 public void expandSettingsPanel(@Nullable String subPanel) {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700310 try {
311 final IStatusBarService svc = getService();
312 if (svc != null) {
Jason Monka9927322015-12-13 16:22:37 -0500313 svc.expandSettingsPanel(subPanel);
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400314 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700316 throw ex.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317 }
318 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319
Evan Laird27323242019-01-11 16:08:07 -0500320 /** @hide */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100321 @UnsupportedAppUsage
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700322 public void setIcon(String slot, int iconId, int iconLevel, String contentDescription) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800323 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400324 final IStatusBarService svc = getService();
325 if (svc != null) {
326 svc.setIcon(slot, mContext.getPackageName(), iconId, iconLevel,
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700327 contentDescription);
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400328 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700330 throw ex.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331 }
332 }
333
Evan Laird27323242019-01-11 16:08:07 -0500334 /** @hide */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100335 @UnsupportedAppUsage
Joe Onorato0cbda992010-05-02 16:28:15 -0700336 public void removeIcon(String slot) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800337 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400338 final IStatusBarService svc = getService();
339 if (svc != null) {
340 svc.removeIcon(slot);
341 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700343 throw ex.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344 }
345 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400346
Evan Laird27323242019-01-11 16:08:07 -0500347 /** @hide */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100348 @UnsupportedAppUsage
Joe Onorato798ac4c2010-05-27 16:39:00 -0400349 public void setIconVisibility(String slot, boolean visible) {
350 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400351 final IStatusBarService svc = getService();
352 if (svc != null) {
353 svc.setIconVisibility(slot, visible);
354 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400355 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700356 throw ex.rethrowFromSystemServer();
Joe Onorato798ac4c2010-05-27 16:39:00 -0400357 }
358 }
John Spurlock5b9145b2013-08-20 15:13:47 -0400359
Evan Lairdedd016f2019-01-23 18:36:29 -0500360 /**
361 * Enable or disable status bar elements (notifications, clock) which are inappropriate during
362 * device setup.
363 *
364 * @param disabled whether to apply or remove the disabled flags
365 *
366 * @hide
367 */
368 @SystemApi
Evan Lairdab196592019-02-26 17:21:32 -0500369 @RequiresPermission(android.Manifest.permission.STATUS_BAR)
Evan Lairdedd016f2019-01-23 18:36:29 -0500370 public void setDisabledForSetup(boolean disabled) {
371 try {
372 final int userId = Binder.getCallingUserHandle().getIdentifier();
373 final IStatusBarService svc = getService();
374 if (svc != null) {
375 svc.disableForUser(disabled ? DEFAULT_SETUP_DISABLE_FLAGS : DISABLE_NONE,
376 mToken, mContext.getPackageName(), userId);
377 svc.disable2ForUser(disabled ? DEFAULT_SETUP_DISABLE2_FLAGS : DISABLE2_NONE,
378 mToken, mContext.getPackageName(), userId);
379 }
380 } catch (RemoteException ex) {
381 throw ex.rethrowFromSystemServer();
382 }
383 }
384
385 /**
Evan Lairdced4aeb2019-01-28 16:52:41 -0500386 * Get this app's currently requested disabled components
Evan Lairdedd016f2019-01-23 18:36:29 -0500387 *
Evan Lairdced4aeb2019-01-28 16:52:41 -0500388 * @return a new DisableInfo
Evan Lairdedd016f2019-01-23 18:36:29 -0500389 *
390 * @hide
391 */
392 @SystemApi
Evan Lairdab196592019-02-26 17:21:32 -0500393 @RequiresPermission(android.Manifest.permission.STATUS_BAR)
Evan Laird2c4d0cf2019-02-28 12:10:29 -0500394 @NonNull
Evan Lairdced4aeb2019-01-28 16:52:41 -0500395 public DisableInfo getDisableInfo() {
Evan Lairdedd016f2019-01-23 18:36:29 -0500396 try {
397 final int userId = Binder.getCallingUserHandle().getIdentifier();
398 final IStatusBarService svc = getService();
399 int[] flags = new int[] {0, 0};
400 if (svc != null) {
401 flags = svc.getDisableFlags(mToken, userId);
402 }
403
Evan Lairdced4aeb2019-01-28 16:52:41 -0500404 return new DisableInfo(flags[0], flags[1]);
Evan Lairdedd016f2019-01-23 18:36:29 -0500405 } catch (RemoteException ex) {
406 throw ex.rethrowFromSystemServer();
407 }
408 }
409
John Spurlock5b9145b2013-08-20 15:13:47 -0400410 /** @hide */
411 public static String windowStateToString(int state) {
412 if (state == WINDOW_STATE_HIDING) return "WINDOW_STATE_HIDING";
413 if (state == WINDOW_STATE_HIDDEN) return "WINDOW_STATE_HIDDEN";
414 if (state == WINDOW_STATE_SHOWING) return "WINDOW_STATE_SHOWING";
415 return "WINDOW_STATE_UNKNOWN";
416 }
Evan Lairdced4aeb2019-01-28 16:52:41 -0500417
418 /**
419 * DisableInfo describes this app's requested state of the StatusBar with regards to which
420 * components are enabled/disabled
421 *
422 * @hide
423 */
424 @SystemApi
425 public static final class DisableInfo {
426
427 private boolean mStatusBarExpansion;
428 private boolean mNavigateHome;
429 private boolean mNotificationPeeking;
430 private boolean mRecents;
431 private boolean mSearch;
432
433 /** @hide */
434 public DisableInfo(int flags1, int flags2) {
435 mStatusBarExpansion = (flags1 & DISABLE_EXPAND) != 0;
436 mNavigateHome = (flags1 & DISABLE_HOME) != 0;
437 mNotificationPeeking = (flags1 & DISABLE_NOTIFICATION_ALERTS) != 0;
438 mRecents = (flags1 & DISABLE_RECENT) != 0;
439 mSearch = (flags1 & DISABLE_SEARCH) != 0;
440 }
441
442 /** @hide */
443 public DisableInfo() {}
444
445 /**
446 * @return {@code true} if expanding the notification shade is disabled
447 *
448 * @hide
449 */
450 @SystemApi
451 public boolean isStatusBarExpansionDisabled() {
452 return mStatusBarExpansion;
453 }
454
455 /** * @hide */
456 public void setStatusBarExpansionDisabled(boolean disabled) {
457 mStatusBarExpansion = disabled;
458 }
459
460 /**
461 * @return {@code true} if navigation home is disabled
462 *
463 * @hide
464 */
465 @SystemApi
466 public boolean isNavigateToHomeDisabled() {
467 return mNavigateHome;
468 }
469
470 /** * @hide */
471 public void setNagivationHomeDisabled(boolean disabled) {
472 mNavigateHome = disabled;
473 }
474
475 /**
476 * @return {@code true} if notification peeking (heads-up notification) is disabled
477 *
478 * @hide
479 */
480 @SystemApi
481 public boolean isNotificationPeekingDisabled() {
482 return mNotificationPeeking;
483 }
484
485 /** @hide */
486 public void setNotificationPeekingDisabled(boolean disabled) {
487 mNotificationPeeking = disabled;
488 }
489
490 /**
491 * @return {@code true} if mRecents/overview is disabled
492 *
493 * @hide
494 */
495 @SystemApi
496 public boolean isRecentsDisabled() {
497 return mRecents;
498 }
499
500 /** @hide */
501 public void setRecentsDisabled(boolean disabled) {
502 mRecents = disabled;
503 }
504
505 /**
506 * @return {@code true} if mSearch is disabled
507 *
508 * @hide
509 */
510 @SystemApi
511 public boolean isSearchDisabled() {
512 return mSearch;
513 }
514
515 /** @hide */
516 public void setSearchDisabled(boolean disabled) {
517 mSearch = disabled;
518 }
519
520 /**
521 * @return {@code true} if no components are disabled (default state)
522 *
523 * @hide
524 */
525 @SystemApi
Evan Lairdab196592019-02-26 17:21:32 -0500526 public boolean areAllComponentsEnabled() {
Evan Lairdced4aeb2019-01-28 16:52:41 -0500527 return !mStatusBarExpansion && !mNavigateHome && !mNotificationPeeking && !mRecents
528 && !mSearch;
529 }
530
531 /** @hide */
532 public void setEnableAll() {
533 mStatusBarExpansion = false;
534 mNavigateHome = false;
535 mNotificationPeeking = false;
536 mRecents = false;
537 mSearch = false;
538 }
539
540 /**
541 * @return {@code true} if all status bar components are disabled
542 *
543 * @hide
544 */
545 public boolean areAllComponentsDisabled() {
546 return mStatusBarExpansion && mNavigateHome && mNotificationPeeking
547 && mRecents && mSearch;
548 }
549
550 /** @hide */
551 public void setDisableAll() {
552 mStatusBarExpansion = true;
553 mNavigateHome = true;
554 mNotificationPeeking = true;
555 mRecents = true;
556 mSearch = true;
557 }
558
559 @Override
560 public String toString() {
561 StringBuilder sb = new StringBuilder();
562 sb.append("DisableInfo: ");
563 sb.append(" mStatusBarExpansion=").append(mStatusBarExpansion ? "disabled" : "enabled");
564 sb.append(" mNavigateHome=").append(mNavigateHome ? "disabled" : "enabled");
565 sb.append(" mNotificationPeeking=")
566 .append(mNotificationPeeking ? "disabled" : "enabled");
567 sb.append(" mRecents=").append(mRecents ? "disabled" : "enabled");
568 sb.append(" mSearch=").append(mSearch ? "disabled" : "enabled");
569
570 return sb.toString();
571
572 }
573
574 /**
575 * Convert a DisableInfo to equivalent flags
576 * @return a pair of equivalent disable flags
577 *
578 * @hide
579 */
580 public Pair<Integer, Integer> toFlags() {
581 int disable1 = DISABLE_NONE;
582 int disable2 = DISABLE2_NONE;
583
584 if (mStatusBarExpansion) disable1 |= DISABLE_EXPAND;
585 if (mNavigateHome) disable1 |= DISABLE_HOME;
586 if (mNotificationPeeking) disable1 |= DISABLE_NOTIFICATION_ALERTS;
587 if (mRecents) disable1 |= DISABLE_RECENT;
588 if (mSearch) disable1 |= DISABLE_SEARCH;
589
590 return new Pair<Integer, Integer>(disable1, disable2);
591 }
592 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593}