blob: 2045ed8411a30a3e7673b7edbe9c6ec48fc36d0e [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
20import android.content.Context;
21import android.os.Binder;
22import android.os.RemoteException;
23import android.os.IBinder;
24import android.os.ServiceManager;
Daniel Sandler9cbd3602011-10-18 22:59:00 -040025import android.util.Slog;
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080026import android.view.View;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027
Joe Onorato0cbda992010-05-02 16:28:15 -070028import com.android.internal.statusbar.IStatusBarService;
29
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030/**
31 * Allows an app to control the status bar.
32 *
33 * @hide
34 */
35public class StatusBarManager {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080037 public static final int DISABLE_EXPAND = View.STATUS_BAR_DISABLE_EXPAND;
38 public static final int DISABLE_NOTIFICATION_ICONS = View.STATUS_BAR_DISABLE_NOTIFICATION_ICONS;
39 public static final int DISABLE_NOTIFICATION_ALERTS
40 = View.STATUS_BAR_DISABLE_NOTIFICATION_ALERTS;
41 public static final int DISABLE_NOTIFICATION_TICKER
42 = View.STATUS_BAR_DISABLE_NOTIFICATION_TICKER;
43 public static final int DISABLE_SYSTEM_INFO = View.STATUS_BAR_DISABLE_SYSTEM_INFO;
Daniel Sandlerdba93562011-10-06 16:39:58 -040044 public static final int DISABLE_HOME = View.STATUS_BAR_DISABLE_HOME;
45 public static final int DISABLE_RECENT = View.STATUS_BAR_DISABLE_RECENT;
Joe Onorato6478adc2011-01-27 21:15:01 -080046 public static final int DISABLE_BACK = View.STATUS_BAR_DISABLE_BACK;
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080047 public static final int DISABLE_CLOCK = View.STATUS_BAR_DISABLE_CLOCK;
Daniel Sandlerd5483c32012-10-19 16:44:15 -040048 public static final int DISABLE_SEARCH = View.STATUS_BAR_DISABLE_SEARCH;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049
Daniel Sandlerdba93562011-10-06 16:39:58 -040050 @Deprecated
51 public static final int DISABLE_NAVIGATION =
52 View.STATUS_BAR_DISABLE_HOME | View.STATUS_BAR_DISABLE_RECENT;
53
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054 public static final int DISABLE_NONE = 0x00000000;
55
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080056 public static final int DISABLE_MASK = DISABLE_EXPAND | DISABLE_NOTIFICATION_ICONS
57 | DISABLE_NOTIFICATION_ALERTS | DISABLE_NOTIFICATION_TICKER
Daniel Sandlerd5483c32012-10-19 16:44:15 -040058 | DISABLE_SYSTEM_INFO | DISABLE_RECENT | DISABLE_HOME | DISABLE_BACK | DISABLE_CLOCK
59 | DISABLE_SEARCH;
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080060
John Spurlock56d007b2013-10-28 18:40:56 -040061 public static final int NAVIGATION_HINT_BACK_ALT = 1 << 0;
Daniel Sandler328310c2011-09-23 15:56:52 -040062
John Spurlock97642182013-07-29 17:58:39 -040063 public static final int WINDOW_STATUS_BAR = 1;
64 public static final int WINDOW_NAVIGATION_BAR = 2;
65
John Spurlock5b9145b2013-08-20 15:13:47 -040066 public static final int WINDOW_STATE_SHOWING = 0;
John Spurlock97642182013-07-29 17:58:39 -040067 public static final int WINDOW_STATE_HIDING = 1;
John Spurlock5b9145b2013-08-20 15:13:47 -040068 public static final int WINDOW_STATE_HIDDEN = 2;
John Spurlock97642182013-07-29 17:58:39 -040069
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070 private Context mContext;
Joe Onorato25f95f92010-04-08 18:37:10 -050071 private IStatusBarService mService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072 private IBinder mToken = new Binder();
73
74 StatusBarManager(Context context) {
75 mContext = context;
Daniel Sandler9cbd3602011-10-18 22:59:00 -040076 }
77
78 private synchronized IStatusBarService getService() {
79 if (mService == null) {
80 mService = IStatusBarService.Stub.asInterface(
81 ServiceManager.getService(Context.STATUS_BAR_SERVICE));
82 if (mService == null) {
83 Slog.w("StatusBarManager", "warning: no STATUS_BAR_SERVICE");
84 }
85 }
86 return mService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087 }
88
89 /**
90 * Disable some features in the status bar. Pass the bitwise-or of the DISABLE_* flags.
91 * To re-enable everything, pass {@link #DISABLE_NONE}.
92 */
93 public void disable(int what) {
94 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -040095 final IStatusBarService svc = getService();
96 if (svc != null) {
97 svc.disable(what, mToken, mContext.getPackageName());
Jim Miller305c78c2011-10-16 14:54:38 -070098 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 } catch (RemoteException ex) {
100 // system process is dead anyway.
101 throw new RuntimeException(ex);
102 }
103 }
104
105 /**
Daniel Sandler11cf1782012-09-27 14:03:08 -0400106 * Expand the notifications panel.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 */
Daniel Sandler11cf1782012-09-27 14:03:08 -0400108 public void expandNotificationsPanel() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400110 final IStatusBarService svc = getService();
111 if (svc != null) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400112 svc.expandNotificationsPanel();
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400113 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114 } catch (RemoteException ex) {
115 // system process is dead anyway.
116 throw new RuntimeException(ex);
117 }
118 }
119
120 /**
Daniel Sandler11cf1782012-09-27 14:03:08 -0400121 * Collapse the notifications and settings panels.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122 */
Daniel Sandler11cf1782012-09-27 14:03:08 -0400123 public void collapsePanels() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400125 final IStatusBarService svc = getService();
126 if (svc != null) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400127 svc.collapsePanels();
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700128 }
129 } catch (RemoteException ex) {
130 // system process is dead anyway.
131 throw new RuntimeException(ex);
132 }
133 }
134
135 /**
Daniel Sandler11cf1782012-09-27 14:03:08 -0400136 * Expand the settings panel.
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700137 */
Daniel Sandler11cf1782012-09-27 14:03:08 -0400138 public void expandSettingsPanel() {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700139 try {
140 final IStatusBarService svc = getService();
141 if (svc != null) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400142 svc.expandSettingsPanel();
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400143 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 } catch (RemoteException ex) {
145 // system process is dead anyway.
146 throw new RuntimeException(ex);
147 }
148 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700150 public void setIcon(String slot, int iconId, int iconLevel, String contentDescription) {
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) {
154 svc.setIcon(slot, mContext.getPackageName(), iconId, iconLevel,
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700155 contentDescription);
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400156 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 } catch (RemoteException ex) {
158 // system process is dead anyway.
159 throw new RuntimeException(ex);
160 }
161 }
162
Joe Onorato0cbda992010-05-02 16:28:15 -0700163 public void removeIcon(String slot) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400165 final IStatusBarService svc = getService();
166 if (svc != null) {
167 svc.removeIcon(slot);
168 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 } catch (RemoteException ex) {
170 // system process is dead anyway.
171 throw new RuntimeException(ex);
172 }
173 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400174
175 public void setIconVisibility(String slot, boolean visible) {
176 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400177 final IStatusBarService svc = getService();
178 if (svc != null) {
179 svc.setIconVisibility(slot, visible);
180 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400181 } catch (RemoteException ex) {
182 // system process is dead anyway.
183 throw new RuntimeException(ex);
184 }
185 }
John Spurlock5b9145b2013-08-20 15:13:47 -0400186
187 /** @hide */
188 public static String windowStateToString(int state) {
189 if (state == WINDOW_STATE_HIDING) return "WINDOW_STATE_HIDING";
190 if (state == WINDOW_STATE_HIDDEN) return "WINDOW_STATE_HIDDEN";
191 if (state == WINDOW_STATE_SHOWING) return "WINDOW_STATE_SHOWING";
192 return "WINDOW_STATE_UNKNOWN";
193 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194}