blob: dd9f3376d74ef09a0202c4c0258bd423ca109684 [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
Daniel Sandler328310c2011-09-23 15:56:52 -040059 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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064 private Context mContext;
Joe Onorato25f95f92010-04-08 18:37:10 -050065 private IStatusBarService mService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066 private IBinder mToken = new Binder();
67
68 StatusBarManager(Context context) {
69 mContext = context;
Daniel Sandler9cbd3602011-10-18 22:59:00 -040070 }
71
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;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081 }
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 */
87 public void disable(int what) {
88 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -040089 final IStatusBarService svc = getService();
90 if (svc != null) {
91 svc.disable(what, mToken, mContext.getPackageName());
Jim Miller305c78c2011-10-16 14:54:38 -070092 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 } catch (RemoteException ex) {
94 // system process is dead anyway.
95 throw new RuntimeException(ex);
96 }
97 }
98
99 /**
100 * Expand the status bar.
101 */
102 public void expand() {
103 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400104 final IStatusBarService svc = getService();
105 if (svc != null) {
106 svc.expand();
107 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 } catch (RemoteException ex) {
109 // system process is dead anyway.
110 throw new RuntimeException(ex);
111 }
112 }
113
114 /**
115 * Collapse the status bar.
116 */
117 public void collapse() {
118 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400119 final IStatusBarService svc = getService();
120 if (svc != null) {
121 svc.collapse();
122 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123 } catch (RemoteException ex) {
124 // system process is dead anyway.
125 throw new RuntimeException(ex);
126 }
127 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700129 public void setIcon(String slot, int iconId, int iconLevel, String contentDescription) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400131 final IStatusBarService svc = getService();
132 if (svc != null) {
133 svc.setIcon(slot, mContext.getPackageName(), iconId, iconLevel,
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700134 contentDescription);
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400135 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136 } catch (RemoteException ex) {
137 // system process is dead anyway.
138 throw new RuntimeException(ex);
139 }
140 }
141
Joe Onorato0cbda992010-05-02 16:28:15 -0700142 public void removeIcon(String slot) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400144 final IStatusBarService svc = getService();
145 if (svc != null) {
146 svc.removeIcon(slot);
147 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 } catch (RemoteException ex) {
149 // system process is dead anyway.
150 throw new RuntimeException(ex);
151 }
152 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400153
154 public void setIconVisibility(String slot, boolean visible) {
155 try {
Daniel Sandler9cbd3602011-10-18 22:59:00 -0400156 final IStatusBarService svc = getService();
157 if (svc != null) {
158 svc.setIconVisibility(slot, visible);
159 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400160 } catch (RemoteException ex) {
161 // system process is dead anyway.
162 throw new RuntimeException(ex);
163 }
164 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165}