blob: bf3d885cd9c9d8ac7f0bd7f7a59d8e66f4d8b9a9 [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;
Fabian Kozynskie3137e32018-09-28 11:20:04 -040020import android.annotation.Nullable;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060021import android.annotation.SystemService;
Mathew Inwood61e8ae62018-08-14 14:17:44 +010022import android.annotation.UnsupportedAppUsage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.content.Context;
24import android.os.Binder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.os.IBinder;
Charles Heede39092017-09-18 09:19:28 +010026import android.os.RemoteException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.os.ServiceManager;
Daniel Sandler9cbd3602011-10-18 22:59:00 -040028import android.util.Slog;
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080029import android.view.View;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030
Joe Onorato0cbda992010-05-02 16:28:15 -070031import com.android.internal.statusbar.IStatusBarService;
32
Benjamin Franzcde0a2a2015-04-23 17:19:48 +010033import java.lang.annotation.Retention;
34import java.lang.annotation.RetentionPolicy;
35
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036/**
37 * Allows an app to control the status bar.
38 *
39 * @hide
40 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060041@SystemService(Context.STATUS_BAR_SERVICE)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042public class StatusBarManager {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043
Mathew Inwood61e8ae62018-08-14 14:17:44 +010044 @UnsupportedAppUsage
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080045 public static final int DISABLE_EXPAND = View.STATUS_BAR_DISABLE_EXPAND;
46 public static final int DISABLE_NOTIFICATION_ICONS = View.STATUS_BAR_DISABLE_NOTIFICATION_ICONS;
47 public static final int DISABLE_NOTIFICATION_ALERTS
48 = View.STATUS_BAR_DISABLE_NOTIFICATION_ALERTS;
Dan Sandlera5e0f412014-01-23 15:11:54 -050049 @Deprecated
Mathew Inwood61e8ae62018-08-14 14:17:44 +010050 @UnsupportedAppUsage
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080051 public static final int DISABLE_NOTIFICATION_TICKER
52 = View.STATUS_BAR_DISABLE_NOTIFICATION_TICKER;
53 public static final int DISABLE_SYSTEM_INFO = View.STATUS_BAR_DISABLE_SYSTEM_INFO;
Daniel Sandlerdba93562011-10-06 16:39:58 -040054 public static final int DISABLE_HOME = View.STATUS_BAR_DISABLE_HOME;
55 public static final int DISABLE_RECENT = View.STATUS_BAR_DISABLE_RECENT;
Joe Onorato6478adc2011-01-27 21:15:01 -080056 public static final int DISABLE_BACK = View.STATUS_BAR_DISABLE_BACK;
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080057 public static final int DISABLE_CLOCK = View.STATUS_BAR_DISABLE_CLOCK;
Daniel Sandlerd5483c32012-10-19 16:44:15 -040058 public static final int DISABLE_SEARCH = View.STATUS_BAR_DISABLE_SEARCH;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059
Daniel Sandlerdba93562011-10-06 16:39:58 -040060 @Deprecated
61 public static final int DISABLE_NAVIGATION =
62 View.STATUS_BAR_DISABLE_HOME | View.STATUS_BAR_DISABLE_RECENT;
63
Mathew Inwood61e8ae62018-08-14 14:17:44 +010064 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065 public static final int DISABLE_NONE = 0x00000000;
66
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080067 public static final int DISABLE_MASK = DISABLE_EXPAND | DISABLE_NOTIFICATION_ICONS
68 | DISABLE_NOTIFICATION_ALERTS | DISABLE_NOTIFICATION_TICKER
Daniel Sandlerd5483c32012-10-19 16:44:15 -040069 | DISABLE_SYSTEM_INFO | DISABLE_RECENT | DISABLE_HOME | DISABLE_BACK | DISABLE_CLOCK
70 | DISABLE_SEARCH;
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080071
Benjamin Franz27cf1462015-04-23 19:36:42 +010072 /**
73 * Flag to disable quick settings.
74 *
75 * Setting this flag disables quick settings completely, but does not disable expanding the
76 * notification shade.
77 */
Charles He6a79b0d2017-09-18 09:50:58 +010078 public static final int DISABLE2_QUICK_SETTINGS = 1;
79 public static final int DISABLE2_SYSTEM_ICONS = 1 << 1;
Charles He2eda2422017-09-24 17:55:21 +010080 public static final int DISABLE2_NOTIFICATION_SHADE = 1 << 2;
Charles He9851a8d2017-10-10 17:31:30 +010081 public static final int DISABLE2_GLOBAL_ACTIONS = 1 << 3;
Mike Digmandd2f49e2018-03-16 10:54:22 -070082 public static final int DISABLE2_ROTATE_SUGGESTIONS = 1 << 4;
Benjamin Franz27cf1462015-04-23 19:36:42 +010083
Benjamin Franzcde0a2a2015-04-23 17:19:48 +010084 public static final int DISABLE2_NONE = 0x00000000;
85
Charles He2eda2422017-09-24 17:55:21 +010086 public static final int DISABLE2_MASK = DISABLE2_QUICK_SETTINGS | DISABLE2_SYSTEM_ICONS
Mike Digmandd2f49e2018-03-16 10:54:22 -070087 | DISABLE2_NOTIFICATION_SHADE | DISABLE2_GLOBAL_ACTIONS | DISABLE2_ROTATE_SUGGESTIONS;
Benjamin Franzcde0a2a2015-04-23 17:19:48 +010088
Jeff Sharkeyce8db992017-12-13 20:05:05 -070089 @IntDef(flag = true, prefix = { "DISABLE2_" }, value = {
90 DISABLE2_NONE,
91 DISABLE2_MASK,
92 DISABLE2_QUICK_SETTINGS,
93 DISABLE2_SYSTEM_ICONS,
94 DISABLE2_NOTIFICATION_SHADE,
Mike Digmandd2f49e2018-03-16 10:54:22 -070095 DISABLE2_GLOBAL_ACTIONS,
96 DISABLE2_ROTATE_SUGGESTIONS
Jeff Sharkeyce8db992017-12-13 20:05:05 -070097 })
Benjamin Franzcde0a2a2015-04-23 17:19:48 +010098 @Retention(RetentionPolicy.SOURCE)
99 public @interface Disable2Flags {}
100
John Spurlock56d007b2013-10-28 18:40:56 -0400101 public static final int NAVIGATION_HINT_BACK_ALT = 1 << 0;
Jason Monkf1ff2092014-04-29 16:50:53 -0400102 public static final int NAVIGATION_HINT_IME_SHOWN = 1 << 1;
Daniel Sandler328310c2011-09-23 15:56:52 -0400103
John Spurlock97642182013-07-29 17:58:39 -0400104 public static final int WINDOW_STATUS_BAR = 1;
105 public static final int WINDOW_NAVIGATION_BAR = 2;
106
John Spurlock5b9145b2013-08-20 15:13:47 -0400107 public static final int WINDOW_STATE_SHOWING = 0;
John Spurlock97642182013-07-29 17:58:39 -0400108 public static final int WINDOW_STATE_HIDING = 1;
John Spurlock5b9145b2013-08-20 15:13:47 -0400109 public static final int WINDOW_STATE_HIDDEN = 2;
John Spurlock97642182013-07-29 17:58:39 -0400110
Jorim Jaggi40aa8812015-09-23 12:59:22 -0700111 public static final int CAMERA_LAUNCH_SOURCE_WIGGLE = 0;
112 public static final int CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP = 1;
Jonathan Solnita4138162017-05-10 21:06:04 -0700113 public static final int CAMERA_LAUNCH_SOURCE_LIFT_TRIGGER = 2;
Jorim Jaggi40aa8812015-09-23 12:59:22 -0700114
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100115 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116 private Context mContext;
Joe Onorato25f95f92010-04-08 18:37:10 -0500117 private IStatusBarService mService;
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100118 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 private IBinder mToken = new Binder();
120
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100121 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122 StatusBarManager(Context context) {
123 mContext = context;
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400124 }
125
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100126 @UnsupportedAppUsage
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400127 private synchronized IStatusBarService getService() {
128 if (mService == null) {
129 mService = IStatusBarService.Stub.asInterface(
130 ServiceManager.getService(Context.STATUS_BAR_SERVICE));
131 if (mService == null) {
132 Slog.w("StatusBarManager", "warning: no STATUS_BAR_SERVICE");
133 }
134 }
135 return mService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136 }
137
138 /**
139 * Disable some features in the status bar. Pass the bitwise-or of the DISABLE_* flags.
140 * To re-enable everything, pass {@link #DISABLE_NONE}.
141 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100142 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143 public void disable(int what) {
144 try {
Evan Lairda6917e12018-05-29 17:28:58 -0400145 final int userId = Binder.getCallingUserHandle().getIdentifier();
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400146 final IStatusBarService svc = getService();
147 if (svc != null) {
Evan Lairda6917e12018-05-29 17:28:58 -0400148 svc.disableForUser(what, mToken, mContext.getPackageName(), userId);
Jim Miller305c78c2011-10-16 14:54:38 -0700149 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700151 throw ex.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 }
153 }
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100154
155 /**
156 * Disable additional status bar features. Pass the bitwise-or of the DISABLE2_* flags.
157 * To re-enable everything, pass {@link #DISABLE_NONE}.
158 *
159 * Warning: Only pass DISABLE2_* flags into this function, do not use DISABLE_* flags.
160 */
161 public void disable2(@Disable2Flags int what) {
162 try {
Evan Lairda6917e12018-05-29 17:28:58 -0400163 final int userId = Binder.getCallingUserHandle().getIdentifier();
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100164 final IStatusBarService svc = getService();
165 if (svc != null) {
Evan Lairda6917e12018-05-29 17:28:58 -0400166 svc.disable2ForUser(what, mToken, mContext.getPackageName(), userId);
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100167 }
168 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700169 throw ex.rethrowFromSystemServer();
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100170 }
171 }
172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 /**
Daniel Sandler11cf1782012-09-27 14:03:08 -0400174 * Expand the notifications panel.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100176 @UnsupportedAppUsage
Daniel Sandler11cf1782012-09-27 14:03:08 -0400177 public void expandNotificationsPanel() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400179 final IStatusBarService svc = getService();
180 if (svc != null) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400181 svc.expandNotificationsPanel();
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400182 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700184 throw ex.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 }
186 }
187
188 /**
Daniel Sandler11cf1782012-09-27 14:03:08 -0400189 * Collapse the notifications and settings panels.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100191 @UnsupportedAppUsage
Daniel Sandler11cf1782012-09-27 14:03:08 -0400192 public void collapsePanels() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400194 final IStatusBarService svc = getService();
195 if (svc != null) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400196 svc.collapsePanels();
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700197 }
198 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700199 throw ex.rethrowFromSystemServer();
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700200 }
201 }
202
203 /**
Daniel Sandler11cf1782012-09-27 14:03:08 -0400204 * Expand the settings panel.
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700205 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100206 @UnsupportedAppUsage
Daniel Sandler11cf1782012-09-27 14:03:08 -0400207 public void expandSettingsPanel() {
Jason Monka9927322015-12-13 16:22:37 -0500208 expandSettingsPanel(null);
209 }
210
211 /**
Fabian Kozynskie3137e32018-09-28 11:20:04 -0400212 * Expand the settings panel and open a subPanel. If the subpanel is null or does not have a
213 * corresponding tile, the QS panel is simply expanded
Jason Monka9927322015-12-13 16:22:37 -0500214 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100215 @UnsupportedAppUsage
Fabian Kozynskie3137e32018-09-28 11:20:04 -0400216 public void expandSettingsPanel(@Nullable String subPanel) {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700217 try {
218 final IStatusBarService svc = getService();
219 if (svc != null) {
Jason Monka9927322015-12-13 16:22:37 -0500220 svc.expandSettingsPanel(subPanel);
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400221 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700223 throw ex.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 }
225 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100227 @UnsupportedAppUsage
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700228 public void setIcon(String slot, int iconId, int iconLevel, String contentDescription) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400230 final IStatusBarService svc = getService();
231 if (svc != null) {
232 svc.setIcon(slot, mContext.getPackageName(), iconId, iconLevel,
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700233 contentDescription);
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400234 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800235 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700236 throw ex.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237 }
238 }
239
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100240 @UnsupportedAppUsage
Joe Onorato0cbda992010-05-02 16:28:15 -0700241 public void removeIcon(String slot) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400243 final IStatusBarService svc = getService();
244 if (svc != null) {
245 svc.removeIcon(slot);
246 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700248 throw ex.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249 }
250 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400251
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100252 @UnsupportedAppUsage
Joe Onorato798ac4c2010-05-27 16:39:00 -0400253 public void setIconVisibility(String slot, boolean visible) {
254 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400255 final IStatusBarService svc = getService();
256 if (svc != null) {
257 svc.setIconVisibility(slot, visible);
258 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400259 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700260 throw ex.rethrowFromSystemServer();
Joe Onorato798ac4c2010-05-27 16:39:00 -0400261 }
262 }
John Spurlock5b9145b2013-08-20 15:13:47 -0400263
264 /** @hide */
265 public static String windowStateToString(int state) {
266 if (state == WINDOW_STATE_HIDING) return "WINDOW_STATE_HIDING";
267 if (state == WINDOW_STATE_HIDDEN) return "WINDOW_STATE_HIDDEN";
268 if (state == WINDOW_STATE_SHOWING) return "WINDOW_STATE_SHOWING";
269 return "WINDOW_STATE_UNKNOWN";
270 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271}