• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 
18 package android.app;
19 
20 import android.annotation.IntDef;
21 import android.annotation.SystemService;
22 import android.content.Context;
23 import android.os.Binder;
24 import android.os.RemoteException;
25 import android.os.IBinder;
26 import android.os.ServiceManager;
27 import android.util.Slog;
28 import android.view.View;
29 
30 import com.android.internal.statusbar.IStatusBarService;
31 
32 import java.lang.annotation.Retention;
33 import java.lang.annotation.RetentionPolicy;
34 
35 /**
36  * Allows an app to control the status bar.
37  *
38  * @hide
39  */
40 @SystemService(Context.STATUS_BAR_SERVICE)
41 public class StatusBarManager {
42 
43     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;
47     @Deprecated
48     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;
51     public static final int DISABLE_HOME = View.STATUS_BAR_DISABLE_HOME;
52     public static final int DISABLE_RECENT = View.STATUS_BAR_DISABLE_RECENT;
53     public static final int DISABLE_BACK = View.STATUS_BAR_DISABLE_BACK;
54     public static final int DISABLE_CLOCK = View.STATUS_BAR_DISABLE_CLOCK;
55     public static final int DISABLE_SEARCH = View.STATUS_BAR_DISABLE_SEARCH;
56 
57     @Deprecated
58     public static final int DISABLE_NAVIGATION =
59             View.STATUS_BAR_DISABLE_HOME | View.STATUS_BAR_DISABLE_RECENT;
60 
61     public static final int DISABLE_NONE = 0x00000000;
62 
63     public static final int DISABLE_MASK = DISABLE_EXPAND | DISABLE_NOTIFICATION_ICONS
64             | DISABLE_NOTIFICATION_ALERTS | DISABLE_NOTIFICATION_TICKER
65             | DISABLE_SYSTEM_INFO | DISABLE_RECENT | DISABLE_HOME | DISABLE_BACK | DISABLE_CLOCK
66             | DISABLE_SEARCH;
67 
68     /**
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 
76     public static final int DISABLE2_NONE = 0x00000000;
77 
78     public static final int DISABLE2_MASK = DISABLE2_QUICK_SETTINGS;
79 
80     @IntDef(flag = true,
81             value = {DISABLE2_NONE, DISABLE2_MASK, DISABLE2_QUICK_SETTINGS})
82     @Retention(RetentionPolicy.SOURCE)
83     public @interface Disable2Flags {}
84 
85     public static final int NAVIGATION_HINT_BACK_ALT      = 1 << 0;
86     public static final int NAVIGATION_HINT_IME_SHOWN     = 1 << 1;
87 
88     public static final int WINDOW_STATUS_BAR = 1;
89     public static final int WINDOW_NAVIGATION_BAR = 2;
90 
91     public static final int WINDOW_STATE_SHOWING = 0;
92     public static final int WINDOW_STATE_HIDING = 1;
93     public static final int WINDOW_STATE_HIDDEN = 2;
94 
95     public static final int CAMERA_LAUNCH_SOURCE_WIGGLE = 0;
96     public static final int CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP = 1;
97     public static final int CAMERA_LAUNCH_SOURCE_LIFT_TRIGGER = 2;
98 
99     private Context mContext;
100     private IStatusBarService mService;
101     private IBinder mToken = new Binder();
102 
StatusBarManager(Context context)103     StatusBarManager(Context context) {
104         mContext = context;
105     }
106 
getService()107     private synchronized IStatusBarService getService() {
108         if (mService == null) {
109             mService = IStatusBarService.Stub.asInterface(
110                     ServiceManager.getService(Context.STATUS_BAR_SERVICE));
111             if (mService == null) {
112                 Slog.w("StatusBarManager", "warning: no STATUS_BAR_SERVICE");
113             }
114         }
115         return mService;
116     }
117 
118     /**
119      * Disable some features in the status bar.  Pass the bitwise-or of the DISABLE_* flags.
120      * To re-enable everything, pass {@link #DISABLE_NONE}.
121      */
disable(int what)122     public void disable(int what) {
123         try {
124             final IStatusBarService svc = getService();
125             if (svc != null) {
126                 svc.disable(what, mToken, mContext.getPackageName());
127             }
128         } catch (RemoteException ex) {
129             throw ex.rethrowFromSystemServer();
130         }
131     }
132 
133     /**
134      * Disable additional status bar features. Pass the bitwise-or of the DISABLE2_* flags.
135      * To re-enable everything, pass {@link #DISABLE_NONE}.
136      *
137      * Warning: Only pass DISABLE2_* flags into this function, do not use DISABLE_* flags.
138      */
disable2(@isable2Flags int what)139     public void disable2(@Disable2Flags int what) {
140         try {
141             final IStatusBarService svc = getService();
142             if (svc != null) {
143                 svc.disable2(what, mToken, mContext.getPackageName());
144             }
145         } catch (RemoteException ex) {
146             throw ex.rethrowFromSystemServer();
147         }
148     }
149 
150     /**
151      * Expand the notifications panel.
152      */
expandNotificationsPanel()153     public void expandNotificationsPanel() {
154         try {
155             final IStatusBarService svc = getService();
156             if (svc != null) {
157                 svc.expandNotificationsPanel();
158             }
159         } catch (RemoteException ex) {
160             throw ex.rethrowFromSystemServer();
161         }
162     }
163 
164     /**
165      * Collapse the notifications and settings panels.
166      */
collapsePanels()167     public void collapsePanels() {
168         try {
169             final IStatusBarService svc = getService();
170             if (svc != null) {
171                 svc.collapsePanels();
172             }
173         } catch (RemoteException ex) {
174             throw ex.rethrowFromSystemServer();
175         }
176     }
177 
178     /**
179      * Expand the settings panel.
180      */
expandSettingsPanel()181     public void expandSettingsPanel() {
182         expandSettingsPanel(null);
183     }
184 
185     /**
186      * Expand the settings panel and open a subPanel, pass null to just open the settings panel.
187      */
expandSettingsPanel(String subPanel)188     public void expandSettingsPanel(String subPanel) {
189         try {
190             final IStatusBarService svc = getService();
191             if (svc != null) {
192                 svc.expandSettingsPanel(subPanel);
193             }
194         } catch (RemoteException ex) {
195             throw ex.rethrowFromSystemServer();
196         }
197     }
198 
setIcon(String slot, int iconId, int iconLevel, String contentDescription)199     public void setIcon(String slot, int iconId, int iconLevel, String contentDescription) {
200         try {
201             final IStatusBarService svc = getService();
202             if (svc != null) {
203                 svc.setIcon(slot, mContext.getPackageName(), iconId, iconLevel,
204                     contentDescription);
205             }
206         } catch (RemoteException ex) {
207             throw ex.rethrowFromSystemServer();
208         }
209     }
210 
removeIcon(String slot)211     public void removeIcon(String slot) {
212         try {
213             final IStatusBarService svc = getService();
214             if (svc != null) {
215                 svc.removeIcon(slot);
216             }
217         } catch (RemoteException ex) {
218             throw ex.rethrowFromSystemServer();
219         }
220     }
221 
setIconVisibility(String slot, boolean visible)222     public void setIconVisibility(String slot, boolean visible) {
223         try {
224             final IStatusBarService svc = getService();
225             if (svc != null) {
226                 svc.setIconVisibility(slot, visible);
227             }
228         } catch (RemoteException ex) {
229             throw ex.rethrowFromSystemServer();
230         }
231     }
232 
233     /** @hide */
windowStateToString(int state)234     public static String windowStateToString(int state) {
235         if (state == WINDOW_STATE_HIDING) return "WINDOW_STATE_HIDING";
236         if (state == WINDOW_STATE_HIDDEN) return "WINDOW_STATE_HIDDEN";
237         if (state == WINDOW_STATE_SHOWING) return "WINDOW_STATE_SHOWING";
238         return "WINDOW_STATE_UNKNOWN";
239     }
240 }
241