• 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.content.Context;
21 import android.os.Binder;
22 import android.os.RemoteException;
23 import android.os.IBinder;
24 import android.os.ServiceManager;
25 
26 /**
27  * Allows an app to control the status bar.
28  *
29  * @hide
30  */
31 public class StatusBarManager {
32     /**
33      * Flag for {@link #disable} to make the status bar not expandable.  Unless you also
34      * set {@link #DISABLE_NOTIFICATIONS}, new notifications will continue to show.
35      */
36     public static final int DISABLE_EXPAND = 0x00000001;
37 
38     /**
39      * Flag for {@link #disable} to hide notification icons and ticker text.
40      */
41     public static final int DISABLE_NOTIFICATION_ICONS = 0x00000002;
42 
43     /**
44      * Flag for {@link #disable} to disable incoming notification alerts.  This will not block
45      * icons, but it will block sound, vibrating and other visual or aural notifications.
46      */
47     public static final int DISABLE_NOTIFICATION_ALERTS = 0x00000004;
48 
49     /**
50      * Re-enable all of the status bar features that you've disabled.
51      */
52     public static final int DISABLE_NONE = 0x00000000;
53 
54     private Context mContext;
55     private IStatusBar mService;
56     private IBinder mToken = new Binder();
57 
StatusBarManager(Context context)58     StatusBarManager(Context context) {
59         mContext = context;
60         mService = IStatusBar.Stub.asInterface(
61                 ServiceManager.getService(Context.STATUS_BAR_SERVICE));
62     }
63 
64     /**
65      * Disable some features in the status bar.  Pass the bitwise-or of the DISABLE_* flags.
66      * To re-enable everything, pass {@link #DISABLE_NONE}.
67      */
disable(int what)68     public void disable(int what) {
69         try {
70             mService.disable(what, mToken, mContext.getPackageName());
71         } catch (RemoteException ex) {
72             // system process is dead anyway.
73             throw new RuntimeException(ex);
74         }
75     }
76 
77     /**
78      * Expand the status bar.
79      */
expand()80     public void expand() {
81         try {
82             mService.activate();
83         } catch (RemoteException ex) {
84             // system process is dead anyway.
85             throw new RuntimeException(ex);
86         }
87     }
88 
89     /**
90      * Collapse the status bar.
91      */
collapse()92     public void collapse() {
93         try {
94             mService.deactivate();
95         } catch (RemoteException ex) {
96             // system process is dead anyway.
97             throw new RuntimeException(ex);
98         }
99     }
100 
101     /**
102      * Toggle the status bar.
103      */
toggle()104     public void toggle() {
105         try {
106             mService.toggle();
107         } catch (RemoteException ex) {
108             // system process is dead anyway.
109             throw new RuntimeException(ex);
110         }
111     }
112 
addIcon(String slot, int iconId, int iconLevel)113     public IBinder addIcon(String slot, int iconId, int iconLevel) {
114         try {
115             return mService.addIcon(slot, mContext.getPackageName(), iconId, iconLevel);
116         } catch (RemoteException ex) {
117             // system process is dead anyway.
118             throw new RuntimeException(ex);
119         }
120     }
121 
updateIcon(IBinder key, String slot, int iconId, int iconLevel)122     public void updateIcon(IBinder key, String slot, int iconId, int iconLevel) {
123         try {
124             mService.updateIcon(key, slot, mContext.getPackageName(), iconId, iconLevel);
125         } catch (RemoteException ex) {
126             // system process is dead anyway.
127             throw new RuntimeException(ex);
128         }
129     }
130 
removeIcon(IBinder key)131     public void removeIcon(IBinder key) {
132         try {
133             mService.removeIcon(key);
134         } catch (RemoteException ex) {
135             // system process is dead anyway.
136             throw new RuntimeException(ex);
137         }
138     }
139 }
140