• 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.content.Context;
22 import android.os.Binder;
23 import android.os.RemoteException;
24 import android.os.IBinder;
25 import android.os.ServiceManager;
26 import android.util.Slog;
27 import android.view.View;
28 
29 import com.android.internal.statusbar.IStatusBarService;
30 
31 import java.lang.annotation.Retention;
32 import java.lang.annotation.RetentionPolicy;
33 
34 /**
35  * Allows an app to control the status bar.
36  *
37  * @hide
38  */
39 public class StatusBarManager {
40 
41     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;
45     @Deprecated
46     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;
49     public static final int DISABLE_HOME = View.STATUS_BAR_DISABLE_HOME;
50     public static final int DISABLE_RECENT = View.STATUS_BAR_DISABLE_RECENT;
51     public static final int DISABLE_BACK = View.STATUS_BAR_DISABLE_BACK;
52     public static final int DISABLE_CLOCK = View.STATUS_BAR_DISABLE_CLOCK;
53     public static final int DISABLE_SEARCH = View.STATUS_BAR_DISABLE_SEARCH;
54 
55     @Deprecated
56     public static final int DISABLE_NAVIGATION =
57             View.STATUS_BAR_DISABLE_HOME | View.STATUS_BAR_DISABLE_RECENT;
58 
59     public static final int DISABLE_NONE = 0x00000000;
60 
61     public static final int DISABLE_MASK = DISABLE_EXPAND | DISABLE_NOTIFICATION_ICONS
62             | DISABLE_NOTIFICATION_ALERTS | DISABLE_NOTIFICATION_TICKER
63             | DISABLE_SYSTEM_INFO | DISABLE_RECENT | DISABLE_HOME | DISABLE_BACK | DISABLE_CLOCK
64             | DISABLE_SEARCH;
65 
66     /**
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 
74     public static final int DISABLE2_NONE = 0x00000000;
75 
76     public static final int DISABLE2_MASK = DISABLE2_QUICK_SETTINGS;
77 
78     @IntDef(flag = true,
79             value = {DISABLE2_NONE, DISABLE2_MASK, DISABLE2_QUICK_SETTINGS})
80     @Retention(RetentionPolicy.SOURCE)
81     public @interface Disable2Flags {}
82 
83     public static final int NAVIGATION_HINT_BACK_ALT      = 1 << 0;
84     public static final int NAVIGATION_HINT_IME_SHOWN     = 1 << 1;
85 
86     public static final int WINDOW_STATUS_BAR = 1;
87     public static final int WINDOW_NAVIGATION_BAR = 2;
88 
89     public static final int WINDOW_STATE_SHOWING = 0;
90     public static final int WINDOW_STATE_HIDING = 1;
91     public static final int WINDOW_STATE_HIDDEN = 2;
92 
93     public static final int CAMERA_LAUNCH_SOURCE_WIGGLE = 0;
94     public static final int CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP = 1;
95 
96     private Context mContext;
97     private IStatusBarService mService;
98     private IBinder mToken = new Binder();
99 
StatusBarManager(Context context)100     StatusBarManager(Context context) {
101         mContext = context;
102     }
103 
getService()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;
113     }
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      */
disable(int what)119     public void disable(int what) {
120         try {
121             final IStatusBarService svc = getService();
122             if (svc != null) {
123                 svc.disable(what, mToken, mContext.getPackageName());
124             }
125         } catch (RemoteException ex) {
126             // system process is dead anyway.
127             throw new RuntimeException(ex);
128         }
129     }
130 
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      */
disable2(@isable2Flags int what)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 
149     /**
150      * Expand the notifications panel.
151      */
expandNotificationsPanel()152     public void expandNotificationsPanel() {
153         try {
154             final IStatusBarService svc = getService();
155             if (svc != null) {
156                 svc.expandNotificationsPanel();
157             }
158         } catch (RemoteException ex) {
159             // system process is dead anyway.
160             throw new RuntimeException(ex);
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             // system process is dead anyway.
175             throw new RuntimeException(ex);
176         }
177     }
178 
179     /**
180      * Expand the settings panel.
181      */
expandSettingsPanel()182     public void expandSettingsPanel() {
183         try {
184             final IStatusBarService svc = getService();
185             if (svc != null) {
186                 svc.expandSettingsPanel();
187             }
188         } catch (RemoteException ex) {
189             // system process is dead anyway.
190             throw new RuntimeException(ex);
191         }
192     }
193 
setIcon(String slot, int iconId, int iconLevel, String contentDescription)194     public void setIcon(String slot, int iconId, int iconLevel, String contentDescription) {
195         try {
196             final IStatusBarService svc = getService();
197             if (svc != null) {
198                 svc.setIcon(slot, mContext.getPackageName(), iconId, iconLevel,
199                     contentDescription);
200             }
201         } catch (RemoteException ex) {
202             // system process is dead anyway.
203             throw new RuntimeException(ex);
204         }
205     }
206 
removeIcon(String slot)207     public void removeIcon(String slot) {
208         try {
209             final IStatusBarService svc = getService();
210             if (svc != null) {
211                 svc.removeIcon(slot);
212             }
213         } catch (RemoteException ex) {
214             // system process is dead anyway.
215             throw new RuntimeException(ex);
216         }
217     }
218 
setIconVisibility(String slot, boolean visible)219     public void setIconVisibility(String slot, boolean visible) {
220         try {
221             final IStatusBarService svc = getService();
222             if (svc != null) {
223                 svc.setIconVisibility(slot, visible);
224             }
225         } catch (RemoteException ex) {
226             // system process is dead anyway.
227             throw new RuntimeException(ex);
228         }
229     }
230 
231     /** @hide */
windowStateToString(int state)232     public static String windowStateToString(int state) {
233         if (state == WINDOW_STATE_HIDING) return "WINDOW_STATE_HIDING";
234         if (state == WINDOW_STATE_HIDDEN) return "WINDOW_STATE_HIDDEN";
235         if (state == WINDOW_STATE_SHOWING) return "WINDOW_STATE_SHOWING";
236         return "WINDOW_STATE_UNKNOWN";
237     }
238 }
239