blob: 5b8addf2a7c2bca934034ed79a10c4efb29d0ceb [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;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048
Daniel Sandlerdba93562011-10-06 16:39:58 -040049 @Deprecated
50 public static final int DISABLE_NAVIGATION =
51 View.STATUS_BAR_DISABLE_HOME | View.STATUS_BAR_DISABLE_RECENT;
52
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053 public static final int DISABLE_NONE = 0x00000000;
54
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080055 public static final int DISABLE_MASK = DISABLE_EXPAND | DISABLE_NOTIFICATION_ICONS
56 | DISABLE_NOTIFICATION_ALERTS | DISABLE_NOTIFICATION_TICKER
Daniel Sandlerdba93562011-10-06 16:39:58 -040057 | DISABLE_SYSTEM_INFO | DISABLE_RECENT | DISABLE_HOME | DISABLE_BACK | DISABLE_CLOCK;
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080058
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059 private Context mContext;
Joe Onorato25f95f92010-04-08 18:37:10 -050060 private IStatusBarService mService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061 private IBinder mToken = new Binder();
62
63 StatusBarManager(Context context) {
64 mContext = context;
Daniel Sandler9cbd3602011-10-18 22:59:00 -040065 }
66
67 private synchronized IStatusBarService getService() {
68 if (mService == null) {
69 mService = IStatusBarService.Stub.asInterface(
70 ServiceManager.getService(Context.STATUS_BAR_SERVICE));
71 if (mService == null) {
72 Slog.w("StatusBarManager", "warning: no STATUS_BAR_SERVICE");
73 }
74 }
75 return mService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076 }
77
78 /**
79 * Disable some features in the status bar. Pass the bitwise-or of the DISABLE_* flags.
80 * To re-enable everything, pass {@link #DISABLE_NONE}.
81 */
82 public void disable(int what) {
83 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -040084 final IStatusBarService svc = getService();
85 if (svc != null) {
86 svc.disable(what, mToken, mContext.getPackageName());
Jim Miller305c78c2011-10-16 14:54:38 -070087 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088 } catch (RemoteException ex) {
89 // system process is dead anyway.
90 throw new RuntimeException(ex);
91 }
92 }
93
94 /**
95 * Expand the status bar.
96 */
97 public void expand() {
98 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -040099 final IStatusBarService svc = getService();
100 if (svc != null) {
101 svc.expand();
102 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 } catch (RemoteException ex) {
104 // system process is dead anyway.
105 throw new RuntimeException(ex);
106 }
107 }
108
109 /**
110 * Collapse the status bar.
111 */
112 public void collapse() {
113 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400114 final IStatusBarService svc = getService();
115 if (svc != null) {
116 svc.collapse();
117 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118 } catch (RemoteException ex) {
119 // system process is dead anyway.
120 throw new RuntimeException(ex);
121 }
122 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700124 public void setIcon(String slot, int iconId, int iconLevel, String contentDescription) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400126 final IStatusBarService svc = getService();
127 if (svc != null) {
128 svc.setIcon(slot, mContext.getPackageName(), iconId, iconLevel,
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700129 contentDescription);
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400130 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131 } catch (RemoteException ex) {
132 // system process is dead anyway.
133 throw new RuntimeException(ex);
134 }
135 }
136
Joe Onorato0cbda992010-05-02 16:28:15 -0700137 public void removeIcon(String slot) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400139 final IStatusBarService svc = getService();
140 if (svc != null) {
141 svc.removeIcon(slot);
142 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143 } catch (RemoteException ex) {
144 // system process is dead anyway.
145 throw new RuntimeException(ex);
146 }
147 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400148
149 public void setIconVisibility(String slot, boolean visible) {
150 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400151 final IStatusBarService svc = getService();
152 if (svc != null) {
153 svc.setIconVisibility(slot, visible);
154 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400155 } catch (RemoteException ex) {
156 // system process is dead anyway.
157 throw new RuntimeException(ex);
158 }
159 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160}