blob: b899116142c85b434bab30e0e2967b533b0fe98d [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) {
126 // system process is dead anyway.
127 throw new RuntimeException(ex);
128 }
129 }
Benjamin Franzcde0a2a2015-04-23 17:19:48 +0100130
131 /**
132 * Disable additional status bar features. Pass the bitwise-or of the DISABLE2_* flags.
133 * To re-enable everything, pass {@link #DISABLE_NONE}.
134 *
135 * Warning: Only pass DISABLE2_* flags into this function, do not use DISABLE_* flags.
136 */
137 public void disable2(@Disable2Flags int what) {
138 try {
139 final IStatusBarService svc = getService();
140 if (svc != null) {
141 svc.disable2(what, mToken, mContext.getPackageName());
142 }
143 } catch (RemoteException ex) {
144 // system process is dead anyway.
145 throw new RuntimeException(ex);
146 }
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) {
159 // system process is dead anyway.
160 throw new RuntimeException(ex);
161 }
162 }
163
164 /**
Daniel Sandler11cf1782012-09-27 14:03:08 -0400165 * Collapse the notifications and settings panels.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 */
Daniel Sandler11cf1782012-09-27 14:03:08 -0400167 public void collapsePanels() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400169 final IStatusBarService svc = getService();
170 if (svc != null) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400171 svc.collapsePanels();
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700172 }
173 } catch (RemoteException ex) {
174 // system process is dead anyway.
175 throw new RuntimeException(ex);
176 }
177 }
178
179 /**
Daniel Sandler11cf1782012-09-27 14:03:08 -0400180 * Expand the settings panel.
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700181 */
Daniel Sandler11cf1782012-09-27 14:03:08 -0400182 public void expandSettingsPanel() {
Jason Monka9927322015-12-13 16:22:37 -0500183 expandSettingsPanel(null);
184 }
185
186 /**
187 * Expand the settings panel and open a subPanel, pass null to just open the settings panel.
188 */
189 public void expandSettingsPanel(String subPanel) {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700190 try {
191 final IStatusBarService svc = getService();
192 if (svc != null) {
Jason Monka9927322015-12-13 16:22:37 -0500193 svc.expandSettingsPanel(subPanel);
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400194 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195 } catch (RemoteException ex) {
196 // system process is dead anyway.
197 throw new RuntimeException(ex);
198 }
199 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700201 public void setIcon(String slot, int iconId, int iconLevel, String contentDescription) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400203 final IStatusBarService svc = getService();
204 if (svc != null) {
205 svc.setIcon(slot, mContext.getPackageName(), iconId, iconLevel,
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700206 contentDescription);
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400207 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800208 } catch (RemoteException ex) {
209 // system process is dead anyway.
210 throw new RuntimeException(ex);
211 }
212 }
213
Joe Onorato0cbda992010-05-02 16:28:15 -0700214 public void removeIcon(String slot) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400216 final IStatusBarService svc = getService();
217 if (svc != null) {
218 svc.removeIcon(slot);
219 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800220 } catch (RemoteException ex) {
221 // system process is dead anyway.
222 throw new RuntimeException(ex);
223 }
224 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400225
226 public void setIconVisibility(String slot, boolean visible) {
227 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400228 final IStatusBarService svc = getService();
229 if (svc != null) {
230 svc.setIconVisibility(slot, visible);
231 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400232 } catch (RemoteException ex) {
233 // system process is dead anyway.
234 throw new RuntimeException(ex);
235 }
236 }
John Spurlock5b9145b2013-08-20 15:13:47 -0400237
238 /** @hide */
239 public static String windowStateToString(int state) {
240 if (state == WINDOW_STATE_HIDING) return "WINDOW_STATE_HIDING";
241 if (state == WINDOW_STATE_HIDDEN) return "WINDOW_STATE_HIDDEN";
242 if (state == WINDOW_STATE_SHOWING) return "WINDOW_STATE_SHOWING";
243 return "WINDOW_STATE_UNKNOWN";
244 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800245}