• 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 import android.util.Slog;
26 import android.view.View;
27 
28 import com.android.internal.statusbar.IStatusBarService;
29 
30 /**
31  * Allows an app to control the status bar.
32  *
33  * @hide
34  */
35 public class StatusBarManager {
36 
37     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;
44     public static final int DISABLE_HOME = View.STATUS_BAR_DISABLE_HOME;
45     public static final int DISABLE_RECENT = View.STATUS_BAR_DISABLE_RECENT;
46     public static final int DISABLE_BACK = View.STATUS_BAR_DISABLE_BACK;
47     public static final int DISABLE_CLOCK = View.STATUS_BAR_DISABLE_CLOCK;
48 
49     @Deprecated
50     public static final int DISABLE_NAVIGATION =
51             View.STATUS_BAR_DISABLE_HOME | View.STATUS_BAR_DISABLE_RECENT;
52 
53     public static final int DISABLE_NONE = 0x00000000;
54 
55     public static final int DISABLE_MASK = DISABLE_EXPAND | DISABLE_NOTIFICATION_ICONS
56             | DISABLE_NOTIFICATION_ALERTS | DISABLE_NOTIFICATION_TICKER
57             | DISABLE_SYSTEM_INFO | DISABLE_RECENT | DISABLE_HOME | DISABLE_BACK | DISABLE_CLOCK;
58 
59     public static final int NAVIGATION_HINT_BACK_NOP      = 1 << 0;
60     public static final int NAVIGATION_HINT_HOME_NOP      = 1 << 1;
61     public static final int NAVIGATION_HINT_RECENT_NOP    = 1 << 2;
62     public static final int NAVIGATION_HINT_BACK_ALT      = 1 << 3;
63 
64     private Context mContext;
65     private IStatusBarService mService;
66     private IBinder mToken = new Binder();
67 
StatusBarManager(Context context)68     StatusBarManager(Context context) {
69         mContext = context;
70     }
71 
getService()72     private synchronized IStatusBarService getService() {
73         if (mService == null) {
74             mService = IStatusBarService.Stub.asInterface(
75                     ServiceManager.getService(Context.STATUS_BAR_SERVICE));
76             if (mService == null) {
77                 Slog.w("StatusBarManager", "warning: no STATUS_BAR_SERVICE");
78             }
79         }
80         return mService;
81     }
82 
83     /**
84      * Disable some features in the status bar.  Pass the bitwise-or of the DISABLE_* flags.
85      * To re-enable everything, pass {@link #DISABLE_NONE}.
86      */
disable(int what)87     public void disable(int what) {
88         try {
89             final IStatusBarService svc = getService();
90             if (svc != null) {
91                 svc.disable(what, mToken, mContext.getPackageName());
92             }
93         } catch (RemoteException ex) {
94             // system process is dead anyway.
95             throw new RuntimeException(ex);
96         }
97     }
98 
99     /**
100      * Expand the status bar.
101      */
expand()102     public void expand() {
103         try {
104             final IStatusBarService svc = getService();
105             if (svc != null) {
106                 svc.expand();
107             }
108         } catch (RemoteException ex) {
109             // system process is dead anyway.
110             throw new RuntimeException(ex);
111         }
112     }
113 
114     /**
115      * Collapse the status bar.
116      */
collapse()117     public void collapse() {
118         try {
119             final IStatusBarService svc = getService();
120             if (svc != null) {
121                 svc.collapse();
122             }
123         } catch (RemoteException ex) {
124             // system process is dead anyway.
125             throw new RuntimeException(ex);
126         }
127     }
128 
setIcon(String slot, int iconId, int iconLevel, String contentDescription)129     public void setIcon(String slot, int iconId, int iconLevel, String contentDescription) {
130         try {
131             final IStatusBarService svc = getService();
132             if (svc != null) {
133                 svc.setIcon(slot, mContext.getPackageName(), iconId, iconLevel,
134                     contentDescription);
135             }
136         } catch (RemoteException ex) {
137             // system process is dead anyway.
138             throw new RuntimeException(ex);
139         }
140     }
141 
removeIcon(String slot)142     public void removeIcon(String slot) {
143         try {
144             final IStatusBarService svc = getService();
145             if (svc != null) {
146                 svc.removeIcon(slot);
147             }
148         } catch (RemoteException ex) {
149             // system process is dead anyway.
150             throw new RuntimeException(ex);
151         }
152     }
153 
setIconVisibility(String slot, boolean visible)154     public void setIconVisibility(String slot, boolean visible) {
155         try {
156             final IStatusBarService svc = getService();
157             if (svc != null) {
158                 svc.setIconVisibility(slot, visible);
159             }
160         } catch (RemoteException ex) {
161             // system process is dead anyway.
162             throw new RuntimeException(ex);
163         }
164     }
165 }
166