blob: 85a9be35587877b1db6860e56701cf52af40e757 [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;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060020import android.annotation.SystemService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.content.Context;
22import android.os.Binder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.os.IBinder;
Charles Heede39092017-09-18 09:19:28 +010024import android.os.RemoteException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.os.ServiceManager;
Daniel Sandler9cbd3602011-10-18 22:59:00 -040026import android.util.Slog;
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080027import android.view.View;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028
Joe Onorato0cbda992010-05-02 16:28:15 -070029import com.android.internal.statusbar.IStatusBarService;
30
Benjamin Franzcde0a2a2015-04-23 17:19:48 +010031import java.lang.annotation.Retention;
32import java.lang.annotation.RetentionPolicy;
33
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034/**
35 * Allows an app to control the status bar.
36 *
37 * @hide
38 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060039@SystemService(Context.STATUS_BAR_SERVICE)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040public class StatusBarManager {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080042 public static final int DISABLE_EXPAND = View.STATUS_BAR_DISABLE_EXPAND;
43 public static final int DISABLE_NOTIFICATION_ICONS = View.STATUS_BAR_DISABLE_NOTIFICATION_ICONS;
44 public static final int DISABLE_NOTIFICATION_ALERTS
45 = View.STATUS_BAR_DISABLE_NOTIFICATION_ALERTS;
Dan Sandlera5e0f412014-01-23 15:11:54 -050046 @Deprecated
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080047 public static final int DISABLE_NOTIFICATION_TICKER
48 = View.STATUS_BAR_DISABLE_NOTIFICATION_TICKER;
49 public static final int DISABLE_SYSTEM_INFO = View.STATUS_BAR_DISABLE_SYSTEM_INFO;
Daniel Sandlerdba93562011-10-06 16:39:58 -040050 public static final int DISABLE_HOME = View.STATUS_BAR_DISABLE_HOME;
51 public static final int DISABLE_RECENT = View.STATUS_BAR_DISABLE_RECENT;
Joe Onorato6478adc2011-01-27 21:15:01 -080052 public static final int DISABLE_BACK = View.STATUS_BAR_DISABLE_BACK;
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080053 public static final int DISABLE_CLOCK = View.STATUS_BAR_DISABLE_CLOCK;
Daniel Sandlerd5483c32012-10-19 16:44:15 -040054 public static final int DISABLE_SEARCH = View.STATUS_BAR_DISABLE_SEARCH;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055
Daniel Sandlerdba93562011-10-06 16:39:58 -040056 @Deprecated
57 public static final int DISABLE_NAVIGATION =
58 View.STATUS_BAR_DISABLE_HOME | View.STATUS_BAR_DISABLE_RECENT;
59
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060 public static final int DISABLE_NONE = 0x00000000;
61
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080062 public static final int DISABLE_MASK = DISABLE_EXPAND | DISABLE_NOTIFICATION_ICONS
63 | DISABLE_NOTIFICATION_ALERTS | DISABLE_NOTIFICATION_TICKER
Daniel Sandlerd5483c32012-10-19 16:44:15 -040064 | DISABLE_SYSTEM_INFO | DISABLE_RECENT | DISABLE_HOME | DISABLE_BACK | DISABLE_CLOCK
65 | DISABLE_SEARCH;
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080066
Benjamin Franz27cf1462015-04-23 19:36:42 +010067 /**
68 * Flag to disable quick settings.
69 *
70 * Setting this flag disables quick settings completely, but does not disable expanding the
71 * notification shade.
72 */
Charles He6a79b0d2017-09-18 09:50:58 +010073 public static final int DISABLE2_QUICK_SETTINGS = 1;
74 public static final int DISABLE2_SYSTEM_ICONS = 1 << 1;
Charles He2eda2422017-09-24 17:55:21 +010075 public static final int DISABLE2_NOTIFICATION_SHADE = 1 << 2;
Charles He9851a8d2017-10-10 17:31:30 +010076 public static final int DISABLE2_GLOBAL_ACTIONS = 1 << 3;
Benjamin Franz27cf1462015-04-23 19:36:42 +010077
Benjamin Franzcde0a2a2015-04-23 17:19:48 +010078 public static final int DISABLE2_NONE = 0x00000000;
79
Charles He2eda2422017-09-24 17:55:21 +010080 public static final int DISABLE2_MASK = DISABLE2_QUICK_SETTINGS | DISABLE2_SYSTEM_ICONS
Charles He9851a8d2017-10-10 17:31:30 +010081 | DISABLE2_NOTIFICATION_SHADE | DISABLE2_GLOBAL_ACTIONS;
Benjamin Franzcde0a2a2015-04-23 17:19:48 +010082
Jeff Sharkeyce8db992017-12-13 20:05:05 -070083 @IntDef(flag = true, prefix = { "DISABLE2_" }, value = {
84 DISABLE2_NONE,
85 DISABLE2_MASK,
86 DISABLE2_QUICK_SETTINGS,
87 DISABLE2_SYSTEM_ICONS,
88 DISABLE2_NOTIFICATION_SHADE,
89 DISABLE2_GLOBAL_ACTIONS
90 })
Benjamin Franzcde0a2a2015-04-23 17:19:48 +010091 @Retention(RetentionPolicy.SOURCE)
92 public @interface Disable2Flags {}
93
John Spurlock56d007b2013-10-28 18:40:56 -040094 public static final int NAVIGATION_HINT_BACK_ALT = 1 << 0;
Jason Monkf1ff2092014-04-29 16:50:53 -040095 public static final int NAVIGATION_HINT_IME_SHOWN = 1 << 1;
Daniel Sandler328310c2011-09-23 15:56:52 -040096
John Spurlock97642182013-07-29 17:58:39 -040097 public static final int WINDOW_STATUS_BAR = 1;
98 public static final int WINDOW_NAVIGATION_BAR = 2;
99
John Spurlock5b9145b2013-08-20 15:13:47 -0400100 public static final int WINDOW_STATE_SHOWING = 0;
John Spurlock97642182013-07-29 17:58:39 -0400101 public static final int WINDOW_STATE_HIDING = 1;
John Spurlock5b9145b2013-08-20 15:13:47 -0400102 public static final int WINDOW_STATE_HIDDEN = 2;
John Spurlock97642182013-07-29 17:58:39 -0400103
Jorim Jaggi40aa8812015-09-23 12:59:22 -0700104 public static final int CAMERA_LAUNCH_SOURCE_WIGGLE = 0;
105 public static final int CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP = 1;
Jonathan Solnita4138162017-05-10 21:06:04 -0700106 public static final int CAMERA_LAUNCH_SOURCE_LIFT_TRIGGER = 2;
Jorim Jaggi40aa8812015-09-23 12:59:22 -0700107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 private Context mContext;
Joe Onorato25f95f92010-04-08 18:37:10 -0500109 private IStatusBarService mService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110 private IBinder mToken = new Binder();
111
112 StatusBarManager(Context context) {
113 mContext = context;
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400114 }
115
116 private synchronized IStatusBarService getService() {
117 if (mService == null) {
118 mService = IStatusBarService.Stub.asInterface(
119 ServiceManager.getService(Context.STATUS_BAR_SERVICE));
120 if (mService == null) {
121 Slog.w("StatusBarManager", "warning: no STATUS_BAR_SERVICE");
122 }
123 }
124 return mService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125 }
126
127 /**
128 * Disable some features in the status bar. Pass the bitwise-or of the DISABLE_* flags.
129 * To re-enable everything, pass {@link #DISABLE_NONE}.
130 */
131 public void disable(int what) {
132 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400133 final IStatusBarService svc = getService();
134 if (svc != null) {
135 svc.disable(what, mToken, mContext.getPackageName());
Jim Miller305c78c2011-10-16 14:54:38 -0700136 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700138 throw ex.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 }
140 }
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100141
142 /**
143 * Disable additional status bar features. Pass the bitwise-or of the DISABLE2_* flags.
144 * To re-enable everything, pass {@link #DISABLE_NONE}.
145 *
146 * Warning: Only pass DISABLE2_* flags into this function, do not use DISABLE_* flags.
147 */
148 public void disable2(@Disable2Flags int what) {
149 try {
150 final IStatusBarService svc = getService();
151 if (svc != null) {
152 svc.disable2(what, mToken, mContext.getPackageName());
153 }
154 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700155 throw ex.rethrowFromSystemServer();
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100156 }
157 }
158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 /**
Daniel Sandler11cf1782012-09-27 14:03:08 -0400160 * Expand the notifications panel.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 */
Daniel Sandler11cf1782012-09-27 14:03:08 -0400162 public void expandNotificationsPanel() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400164 final IStatusBarService svc = getService();
165 if (svc != null) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400166 svc.expandNotificationsPanel();
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400167 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700169 throw ex.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 }
171 }
172
173 /**
Daniel Sandler11cf1782012-09-27 14:03:08 -0400174 * Collapse the notifications and settings panels.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175 */
Daniel Sandler11cf1782012-09-27 14:03:08 -0400176 public void collapsePanels() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400178 final IStatusBarService svc = getService();
179 if (svc != null) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400180 svc.collapsePanels();
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700181 }
182 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700183 throw ex.rethrowFromSystemServer();
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700184 }
185 }
186
187 /**
Daniel Sandler11cf1782012-09-27 14:03:08 -0400188 * Expand the settings panel.
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700189 */
Daniel Sandler11cf1782012-09-27 14:03:08 -0400190 public void expandSettingsPanel() {
Jason Monka9927322015-12-13 16:22:37 -0500191 expandSettingsPanel(null);
192 }
193
194 /**
195 * Expand the settings panel and open a subPanel, pass null to just open the settings panel.
196 */
197 public void expandSettingsPanel(String subPanel) {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700198 try {
199 final IStatusBarService svc = getService();
200 if (svc != null) {
Jason Monka9927322015-12-13 16:22:37 -0500201 svc.expandSettingsPanel(subPanel);
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400202 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800203 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700204 throw ex.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 }
206 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700208 public void setIcon(String slot, int iconId, int iconLevel, String contentDescription) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400210 final IStatusBarService svc = getService();
211 if (svc != null) {
212 svc.setIcon(slot, mContext.getPackageName(), iconId, iconLevel,
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700213 contentDescription);
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400214 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700216 throw ex.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217 }
218 }
219
Joe Onorato0cbda992010-05-02 16:28:15 -0700220 public void removeIcon(String slot) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400222 final IStatusBarService svc = getService();
223 if (svc != null) {
224 svc.removeIcon(slot);
225 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700227 throw ex.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 }
229 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400230
231 public void setIconVisibility(String slot, boolean visible) {
232 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400233 final IStatusBarService svc = getService();
234 if (svc != null) {
235 svc.setIconVisibility(slot, visible);
236 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400237 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700238 throw ex.rethrowFromSystemServer();
Joe Onorato798ac4c2010-05-27 16:39:00 -0400239 }
240 }
John Spurlock5b9145b2013-08-20 15:13:47 -0400241
242 /** @hide */
243 public static String windowStateToString(int state) {
244 if (state == WINDOW_STATE_HIDING) return "WINDOW_STATE_HIDING";
245 if (state == WINDOW_STATE_HIDDEN) return "WINDOW_STATE_HIDDEN";
246 if (state == WINDOW_STATE_SHOWING) return "WINDOW_STATE_SHOWING";
247 return "WINDOW_STATE_UNKNOWN";
248 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249}