blob: e57a9b5231e3efdd8b0a7936ca5e99f6f612d978 [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;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.content.Context;
22import android.os.Binder;
23import android.os.RemoteException;
24import android.os.IBinder;
25import 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 */
39public class StatusBarManager {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080041 public static final int DISABLE_EXPAND = View.STATUS_BAR_DISABLE_EXPAND;
42 public static final int DISABLE_NOTIFICATION_ICONS = View.STATUS_BAR_DISABLE_NOTIFICATION_ICONS;
43 public static final int DISABLE_NOTIFICATION_ALERTS
44 = View.STATUS_BAR_DISABLE_NOTIFICATION_ALERTS;
Dan Sandlera5e0f412014-01-23 15:11:54 -050045 @Deprecated
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080046 public static final int DISABLE_NOTIFICATION_TICKER
47 = View.STATUS_BAR_DISABLE_NOTIFICATION_TICKER;
48 public static final int DISABLE_SYSTEM_INFO = View.STATUS_BAR_DISABLE_SYSTEM_INFO;
Daniel Sandlerdba93562011-10-06 16:39:58 -040049 public static final int DISABLE_HOME = View.STATUS_BAR_DISABLE_HOME;
50 public static final int DISABLE_RECENT = View.STATUS_BAR_DISABLE_RECENT;
Joe Onorato6478adc2011-01-27 21:15:01 -080051 public static final int DISABLE_BACK = View.STATUS_BAR_DISABLE_BACK;
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080052 public static final int DISABLE_CLOCK = View.STATUS_BAR_DISABLE_CLOCK;
Daniel Sandlerd5483c32012-10-19 16:44:15 -040053 public static final int DISABLE_SEARCH = View.STATUS_BAR_DISABLE_SEARCH;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054
Daniel Sandlerdba93562011-10-06 16:39:58 -040055 @Deprecated
56 public static final int DISABLE_NAVIGATION =
57 View.STATUS_BAR_DISABLE_HOME | View.STATUS_BAR_DISABLE_RECENT;
58
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059 public static final int DISABLE_NONE = 0x00000000;
60
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080061 public static final int DISABLE_MASK = DISABLE_EXPAND | DISABLE_NOTIFICATION_ICONS
62 | DISABLE_NOTIFICATION_ALERTS | DISABLE_NOTIFICATION_TICKER
Daniel Sandlerd5483c32012-10-19 16:44:15 -040063 | DISABLE_SYSTEM_INFO | DISABLE_RECENT | DISABLE_HOME | DISABLE_BACK | DISABLE_CLOCK
64 | DISABLE_SEARCH;
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080065
Benjamin Franz27cf1462015-04-23 19:36:42 +010066 /**
67 * Flag to disable quick settings.
68 *
69 * Setting this flag disables quick settings completely, but does not disable expanding the
70 * notification shade.
71 */
72 public static final int DISABLE2_QUICK_SETTINGS = 0x00000001;
73
Benjamin Franzcde0a2a2015-04-23 17:19:48 +010074 public static final int DISABLE2_NONE = 0x00000000;
75
Benjamin Franz27cf1462015-04-23 19:36:42 +010076 public static final int DISABLE2_MASK = DISABLE2_QUICK_SETTINGS;
Benjamin Franzcde0a2a2015-04-23 17:19:48 +010077
78 @IntDef(flag = true,
Benjamin Franz27cf1462015-04-23 19:36:42 +010079 value = {DISABLE2_NONE, DISABLE2_MASK, DISABLE2_QUICK_SETTINGS})
Benjamin Franzcde0a2a2015-04-23 17:19:48 +010080 @Retention(RetentionPolicy.SOURCE)
81 public @interface Disable2Flags {}
82
John Spurlock56d007b2013-10-28 18:40:56 -040083 public static final int NAVIGATION_HINT_BACK_ALT = 1 << 0;
Jason Monkf1ff2092014-04-29 16:50:53 -040084 public static final int NAVIGATION_HINT_IME_SHOWN = 1 << 1;
Daniel Sandler328310c2011-09-23 15:56:52 -040085
John Spurlock97642182013-07-29 17:58:39 -040086 public static final int WINDOW_STATUS_BAR = 1;
87 public static final int WINDOW_NAVIGATION_BAR = 2;
88
John Spurlock5b9145b2013-08-20 15:13:47 -040089 public static final int WINDOW_STATE_SHOWING = 0;
John Spurlock97642182013-07-29 17:58:39 -040090 public static final int WINDOW_STATE_HIDING = 1;
John Spurlock5b9145b2013-08-20 15:13:47 -040091 public static final int WINDOW_STATE_HIDDEN = 2;
John Spurlock97642182013-07-29 17:58:39 -040092
Jorim Jaggi40aa8812015-09-23 12:59:22 -070093 public static final int CAMERA_LAUNCH_SOURCE_WIGGLE = 0;
94 public static final int CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP = 1;
95
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 private Context mContext;
Joe Onorato25f95f92010-04-08 18:37:10 -050097 private IStatusBarService mService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 private IBinder mToken = new Binder();
99
100 StatusBarManager(Context context) {
101 mContext = context;
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400102 }
103
104 private synchronized IStatusBarService getService() {
105 if (mService == null) {
106 mService = IStatusBarService.Stub.asInterface(
107 ServiceManager.getService(Context.STATUS_BAR_SERVICE));
108 if (mService == null) {
109 Slog.w("StatusBarManager", "warning: no STATUS_BAR_SERVICE");
110 }
111 }
112 return mService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113 }
114
115 /**
116 * Disable some features in the status bar. Pass the bitwise-or of the DISABLE_* flags.
117 * To re-enable everything, pass {@link #DISABLE_NONE}.
118 */
119 public void disable(int what) {
120 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400121 final IStatusBarService svc = getService();
122 if (svc != null) {
123 svc.disable(what, mToken, mContext.getPackageName());
Jim Miller305c78c2011-10-16 14:54:38 -0700124 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700126 throw ex.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127 }
128 }
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100129
130 /**
131 * Disable additional status bar features. Pass the bitwise-or of the DISABLE2_* flags.
132 * To re-enable everything, pass {@link #DISABLE_NONE}.
133 *
134 * Warning: Only pass DISABLE2_* flags into this function, do not use DISABLE_* flags.
135 */
136 public void disable2(@Disable2Flags int what) {
137 try {
138 final IStatusBarService svc = getService();
139 if (svc != null) {
140 svc.disable2(what, mToken, mContext.getPackageName());
141 }
142 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700143 throw ex.rethrowFromSystemServer();
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100144 }
145 }
146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 /**
Daniel Sandler11cf1782012-09-27 14:03:08 -0400148 * Expand the notifications panel.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149 */
Daniel Sandler11cf1782012-09-27 14:03:08 -0400150 public void expandNotificationsPanel() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400152 final IStatusBarService svc = getService();
153 if (svc != null) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400154 svc.expandNotificationsPanel();
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400155 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700157 throw ex.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 }
159 }
160
161 /**
Daniel Sandler11cf1782012-09-27 14:03:08 -0400162 * Collapse the notifications and settings panels.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 */
Daniel Sandler11cf1782012-09-27 14:03:08 -0400164 public void collapsePanels() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400166 final IStatusBarService svc = getService();
167 if (svc != null) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400168 svc.collapsePanels();
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700169 }
170 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700171 throw ex.rethrowFromSystemServer();
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700172 }
173 }
174
175 /**
Daniel Sandler11cf1782012-09-27 14:03:08 -0400176 * Expand the settings panel.
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700177 */
Daniel Sandler11cf1782012-09-27 14:03:08 -0400178 public void expandSettingsPanel() {
Jason Monka9927322015-12-13 16:22:37 -0500179 expandSettingsPanel(null);
180 }
181
182 /**
183 * Expand the settings panel and open a subPanel, pass null to just open the settings panel.
184 */
185 public void expandSettingsPanel(String subPanel) {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700186 try {
187 final IStatusBarService svc = getService();
188 if (svc != null) {
Jason Monka9927322015-12-13 16:22:37 -0500189 svc.expandSettingsPanel(subPanel);
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400190 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700192 throw ex.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193 }
194 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700196 public void setIcon(String slot, int iconId, int iconLevel, String contentDescription) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400198 final IStatusBarService svc = getService();
199 if (svc != null) {
200 svc.setIcon(slot, mContext.getPackageName(), iconId, iconLevel,
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700201 contentDescription);
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 }
207
Joe Onorato0cbda992010-05-02 16:28:15 -0700208 public void removeIcon(String slot) {
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.removeIcon(slot);
213 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700215 throw ex.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 }
217 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400218
219 public void setIconVisibility(String slot, boolean visible) {
220 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400221 final IStatusBarService svc = getService();
222 if (svc != null) {
223 svc.setIconVisibility(slot, visible);
224 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400225 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700226 throw ex.rethrowFromSystemServer();
Joe Onorato798ac4c2010-05-27 16:39:00 -0400227 }
228 }
John Spurlock5b9145b2013-08-20 15:13:47 -0400229
230 /** @hide */
231 public static String windowStateToString(int state) {
232 if (state == WINDOW_STATE_HIDING) return "WINDOW_STATE_HIDING";
233 if (state == WINDOW_STATE_HIDDEN) return "WINDOW_STATE_HIDDEN";
234 if (state == WINDOW_STATE_SHOWING) return "WINDOW_STATE_SHOWING";
235 return "WINDOW_STATE_UNKNOWN";
236 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237}