blob: fb8bd3951ed771d1d323577f12c42ae0f8801c72 [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
Jim Miller305c78c2011-10-16 14:54:38 -070017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018package android.app;
19
Benjamin Franzcde0a2a2015-04-23 17:19:48 +010020import android.annotation.IntDef;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060021import android.annotation.SystemService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.content.Context;
23import android.os.Binder;
24import android.os.RemoteException;
25import android.os.IBinder;
26import android.os.ServiceManager;
Daniel Sandler9cbd3602011-10-18 22:59:00 -040027import android.util.Slog;
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080028import android.view.View;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029
Joe Onorato0cbda992010-05-02 16:28:15 -070030import com.android.internal.statusbar.IStatusBarService;
31
Benjamin Franzcde0a2a2015-04-23 17:19:48 +010032import java.lang.annotation.Retention;
33import java.lang.annotation.RetentionPolicy;
34
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035/**
36 * Allows an app to control the status bar.
37 *
38 * @hide
39 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060040@SystemService(Context.STATUS_BAR_SERVICE)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041public class StatusBarManager {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080043 public static final int DISABLE_EXPAND = View.STATUS_BAR_DISABLE_EXPAND;
44 public static final int DISABLE_NOTIFICATION_ICONS = View.STATUS_BAR_DISABLE_NOTIFICATION_ICONS;
45 public static final int DISABLE_NOTIFICATION_ALERTS
46 = View.STATUS_BAR_DISABLE_NOTIFICATION_ALERTS;
Dan Sandlera5e0f412014-01-23 15:11:54 -050047 @Deprecated
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080048 public static final int DISABLE_NOTIFICATION_TICKER
49 = View.STATUS_BAR_DISABLE_NOTIFICATION_TICKER;
50 public static final int DISABLE_SYSTEM_INFO = View.STATUS_BAR_DISABLE_SYSTEM_INFO;
Daniel Sandlerdba93562011-10-06 16:39:58 -040051 public static final int DISABLE_HOME = View.STATUS_BAR_DISABLE_HOME;
52 public static final int DISABLE_RECENT = View.STATUS_BAR_DISABLE_RECENT;
Joe Onorato6478adc2011-01-27 21:15:01 -080053 public static final int DISABLE_BACK = View.STATUS_BAR_DISABLE_BACK;
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080054 public static final int DISABLE_CLOCK = View.STATUS_BAR_DISABLE_CLOCK;
Daniel Sandlerd5483c32012-10-19 16:44:15 -040055 public static final int DISABLE_SEARCH = View.STATUS_BAR_DISABLE_SEARCH;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056
Daniel Sandlerdba93562011-10-06 16:39:58 -040057 @Deprecated
58 public static final int DISABLE_NAVIGATION =
59 View.STATUS_BAR_DISABLE_HOME | View.STATUS_BAR_DISABLE_RECENT;
60
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061 public static final int DISABLE_NONE = 0x00000000;
62
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080063 public static final int DISABLE_MASK = DISABLE_EXPAND | DISABLE_NOTIFICATION_ICONS
64 | DISABLE_NOTIFICATION_ALERTS | DISABLE_NOTIFICATION_TICKER
Daniel Sandlerd5483c32012-10-19 16:44:15 -040065 | DISABLE_SYSTEM_INFO | DISABLE_RECENT | DISABLE_HOME | DISABLE_BACK | DISABLE_CLOCK
66 | DISABLE_SEARCH;
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080067
Benjamin Franz27cf1462015-04-23 19:36:42 +010068 /**
69 * Flag to disable quick settings.
70 *
71 * Setting this flag disables quick settings completely, but does not disable expanding the
72 * notification shade.
73 */
74 public static final int DISABLE2_QUICK_SETTINGS = 0x00000001;
75
Benjamin Franzcde0a2a2015-04-23 17:19:48 +010076 public static final int DISABLE2_NONE = 0x00000000;
77
Benjamin Franz27cf1462015-04-23 19:36:42 +010078 public static final int DISABLE2_MASK = DISABLE2_QUICK_SETTINGS;
Benjamin Franzcde0a2a2015-04-23 17:19:48 +010079
80 @IntDef(flag = true,
Benjamin Franz27cf1462015-04-23 19:36:42 +010081 value = {DISABLE2_NONE, DISABLE2_MASK, DISABLE2_QUICK_SETTINGS})
Benjamin Franzcde0a2a2015-04-23 17:19:48 +010082 @Retention(RetentionPolicy.SOURCE)
83 public @interface Disable2Flags {}
84
John Spurlock56d007b2013-10-28 18:40:56 -040085 public static final int NAVIGATION_HINT_BACK_ALT = 1 << 0;
Jason Monkf1ff2092014-04-29 16:50:53 -040086 public static final int NAVIGATION_HINT_IME_SHOWN = 1 << 1;
Daniel Sandler328310c2011-09-23 15:56:52 -040087
John Spurlock97642182013-07-29 17:58:39 -040088 public static final int WINDOW_STATUS_BAR = 1;
89 public static final int WINDOW_NAVIGATION_BAR = 2;
90
John Spurlock5b9145b2013-08-20 15:13:47 -040091 public static final int WINDOW_STATE_SHOWING = 0;
John Spurlock97642182013-07-29 17:58:39 -040092 public static final int WINDOW_STATE_HIDING = 1;
John Spurlock5b9145b2013-08-20 15:13:47 -040093 public static final int WINDOW_STATE_HIDDEN = 2;
John Spurlock97642182013-07-29 17:58:39 -040094
Jorim Jaggi40aa8812015-09-23 12:59:22 -070095 public static final int CAMERA_LAUNCH_SOURCE_WIGGLE = 0;
96 public static final int CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP = 1;
97
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 private Context mContext;
Joe Onorato25f95f92010-04-08 18:37:10 -050099 private IStatusBarService mService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 private IBinder mToken = new Binder();
101
102 StatusBarManager(Context context) {
103 mContext = context;
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400104 }
105
106 private synchronized IStatusBarService getService() {
107 if (mService == null) {
108 mService = IStatusBarService.Stub.asInterface(
109 ServiceManager.getService(Context.STATUS_BAR_SERVICE));
110 if (mService == null) {
111 Slog.w("StatusBarManager", "warning: no STATUS_BAR_SERVICE");
112 }
113 }
114 return mService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 }
116
117 /**
118 * Disable some features in the status bar. Pass the bitwise-or of the DISABLE_* flags.
119 * To re-enable everything, pass {@link #DISABLE_NONE}.
120 */
121 public void disable(int what) {
122 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400123 final IStatusBarService svc = getService();
124 if (svc != null) {
125 svc.disable(what, mToken, mContext.getPackageName());
Jim Miller305c78c2011-10-16 14:54:38 -0700126 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700128 throw ex.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 }
130 }
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100131
132 /**
133 * Disable additional status bar features. Pass the bitwise-or of the DISABLE2_* flags.
134 * To re-enable everything, pass {@link #DISABLE_NONE}.
135 *
136 * Warning: Only pass DISABLE2_* flags into this function, do not use DISABLE_* flags.
137 */
138 public void disable2(@Disable2Flags int what) {
139 try {
140 final IStatusBarService svc = getService();
141 if (svc != null) {
142 svc.disable2(what, mToken, mContext.getPackageName());
143 }
144 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700145 throw ex.rethrowFromSystemServer();
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100146 }
147 }
148
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149 /**
Daniel Sandler11cf1782012-09-27 14:03:08 -0400150 * Expand the notifications panel.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 */
Daniel Sandler11cf1782012-09-27 14:03:08 -0400152 public void expandNotificationsPanel() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400154 final IStatusBarService svc = getService();
155 if (svc != null) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400156 svc.expandNotificationsPanel();
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400157 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700159 throw ex.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 }
161 }
162
163 /**
Daniel Sandler11cf1782012-09-27 14:03:08 -0400164 * Collapse the notifications and settings panels.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 */
Daniel Sandler11cf1782012-09-27 14:03:08 -0400166 public void collapsePanels() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400168 final IStatusBarService svc = getService();
169 if (svc != null) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400170 svc.collapsePanels();
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700171 }
172 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700173 throw ex.rethrowFromSystemServer();
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700174 }
175 }
176
177 /**
Daniel Sandler11cf1782012-09-27 14:03:08 -0400178 * Expand the settings panel.
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700179 */
Daniel Sandler11cf1782012-09-27 14:03:08 -0400180 public void expandSettingsPanel() {
Jason Monka9927322015-12-13 16:22:37 -0500181 expandSettingsPanel(null);
182 }
183
184 /**
185 * Expand the settings panel and open a subPanel, pass null to just open the settings panel.
186 */
187 public void expandSettingsPanel(String subPanel) {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700188 try {
189 final IStatusBarService svc = getService();
190 if (svc != null) {
Jason Monka9927322015-12-13 16:22:37 -0500191 svc.expandSettingsPanel(subPanel);
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400192 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700194 throw ex.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195 }
196 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700198 public void setIcon(String slot, int iconId, int iconLevel, String contentDescription) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400200 final IStatusBarService svc = getService();
201 if (svc != null) {
202 svc.setIcon(slot, mContext.getPackageName(), iconId, iconLevel,
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700203 contentDescription);
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400204 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700206 throw ex.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207 }
208 }
209
Joe Onorato0cbda992010-05-02 16:28:15 -0700210 public void removeIcon(String slot) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400212 final IStatusBarService svc = getService();
213 if (svc != null) {
214 svc.removeIcon(slot);
215 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700217 throw ex.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218 }
219 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400220
221 public void setIconVisibility(String slot, boolean visible) {
222 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400223 final IStatusBarService svc = getService();
224 if (svc != null) {
225 svc.setIconVisibility(slot, visible);
226 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400227 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700228 throw ex.rethrowFromSystemServer();
Joe Onorato798ac4c2010-05-27 16:39:00 -0400229 }
230 }
John Spurlock5b9145b2013-08-20 15:13:47 -0400231
232 /** @hide */
233 public static String windowStateToString(int state) {
234 if (state == WINDOW_STATE_HIDING) return "WINDOW_STATE_HIDING";
235 if (state == WINDOW_STATE_HIDDEN) return "WINDOW_STATE_HIDDEN";
236 if (state == WINDOW_STATE_SHOWING) return "WINDOW_STATE_SHOWING";
237 return "WINDOW_STATE_UNKNOWN";
238 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239}