blob: 1a2f86763dc2c2d93f30ed00ff9b980c03f0ae6c [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
Joe Onorato7a0f36b2010-06-07 10:24:36 -070017package com.android.server;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import android.app.PendingIntent;
20import android.app.StatusBarManager;
21import android.content.BroadcastReceiver;
Joe Onorato9e875fc2010-06-07 11:12:11 -070022import android.content.ComponentName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.content.Context;
24import android.content.Intent;
25import android.content.IntentFilter;
26import android.content.pm.PackageManager;
27import android.content.res.Resources;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.net.Uri;
29import android.os.IBinder;
30import android.os.RemoteException;
31import android.os.Binder;
Joe Onoratof3f0e052010-05-14 18:49:29 -070032import android.os.Handler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.os.SystemClock;
Joe Onorato8a9b2202010-02-26 18:56:32 -080034import android.util.Slog;
Joe Onorato664644d2011-01-23 17:53:23 -080035import android.view.View;
Joe Onorato0cbda992010-05-02 16:28:15 -070036
37import com.android.internal.statusbar.IStatusBar;
38import com.android.internal.statusbar.IStatusBarService;
39import com.android.internal.statusbar.StatusBarIcon;
40import com.android.internal.statusbar.StatusBarIconList;
Joe Onorato18e69df2010-05-17 22:26:12 -070041import com.android.internal.statusbar.StatusBarNotification;
The Android Open Source Project10592532009-03-18 17:39:46 -070042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043import java.io.FileDescriptor;
44import java.io.PrintWriter;
45import java.util.ArrayList;
46import java.util.HashMap;
Joe Onorato75199e32010-05-29 17:22:51 -040047import java.util.List;
48import java.util.Map;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049
50
51/**
Joe Onoratof3f0e052010-05-14 18:49:29 -070052 * A note on locking: We rely on the fact that calls onto mBar are oneway or
53 * if they are local, that they just enqueue messages to not deadlock.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054 */
Joe Onorato089de882010-04-12 08:18:45 -070055public class StatusBarManagerService extends IStatusBarService.Stub
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056{
Joe Onorato4762c2d2010-05-17 15:42:59 -070057 static final String TAG = "StatusBarManagerService";
Joe Onorato431bb222010-10-18 19:13:23 -040058 static final boolean SPEW = false;
Joe Onoratodf7dbb62009-11-17 10:43:37 -080059
Joe Onoratof3f0e052010-05-14 18:49:29 -070060 final Context mContext;
61 Handler mHandler = new Handler();
62 NotificationCallbacks mNotificationCallbacks;
Joe Onorato4762c2d2010-05-17 15:42:59 -070063 volatile IStatusBar mBar;
Joe Onoratof3f0e052010-05-14 18:49:29 -070064 StatusBarIconList mIcons = new StatusBarIconList();
Joe Onorato75199e32010-05-29 17:22:51 -040065 HashMap<IBinder,StatusBarNotification> mNotifications
66 = new HashMap<IBinder,StatusBarNotification>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067
Joe Onoratof3f0e052010-05-14 18:49:29 -070068 // for disabling the status bar
69 ArrayList<DisableRecord> mDisableRecords = new ArrayList<DisableRecord>();
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080070 IBinder mSysUiVisToken = new Binder();
Joe Onoratof3f0e052010-05-14 18:49:29 -070071 int mDisabled = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072
Joe Onorato93056472010-09-10 10:30:46 -040073 Object mLock = new Object();
74 // We usually call it lights out mode, but double negatives are annoying
75 boolean mLightsOn = true;
Daniel Sandlere02d8082010-10-08 15:13:22 -040076 boolean mMenuVisible = false;
Joe Onorato857fd9b2011-01-27 15:08:35 -080077 int mImeWindowVis = 0;
78 int mImeBackDisposition;
79 IBinder mImeToken = null;
satok06487a52010-10-29 11:37:18 +090080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081 private class DisableRecord implements IBinder.DeathRecipient {
82 String pkg;
83 int what;
84 IBinder token;
85
86 public void binderDied() {
Joe Onorato8a9b2202010-02-26 18:56:32 -080087 Slog.i(TAG, "binder died for pkg=" + pkg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088 disable(0, token, pkg);
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -070089 token.unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 }
91 }
92
93 public interface NotificationCallbacks {
94 void onSetDisabled(int status);
95 void onClearAll();
Fred Quintana6ecaff12009-09-25 14:23:13 -070096 void onNotificationClick(String pkg, String tag, int id);
Daniel Sandler0f0b11c2010-08-04 15:54:58 -040097 void onNotificationClear(String pkg, String tag, int id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 void onPanelRevealed();
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -070099 void onNotificationError(String pkg, String tag, int id,
100 int uid, int initialPid, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101 }
102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 /**
104 * Construct the service, add the status bar view to the window manager
105 */
Joe Onorato089de882010-04-12 08:18:45 -0700106 public StatusBarManagerService(Context context) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 mContext = context;
Joe Onorato0cbda992010-05-02 16:28:15 -0700108
109 final Resources res = context.getResources();
Joe Onorato75144ea2010-06-07 12:36:25 -0700110 mIcons.defineSlots(res.getStringArray(com.android.internal.R.array.config_statusBarIcons));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111 }
112
113 public void setNotificationCallbacks(NotificationCallbacks listener) {
114 mNotificationCallbacks = listener;
115 }
116
117 // ================================================================================
Joe Onorato25f95f92010-04-08 18:37:10 -0500118 // From IStatusBarService
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 // ================================================================================
Joe Onoratof3f0e052010-05-14 18:49:29 -0700120 public void expand() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121 enforceExpandStatusBar();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700122
123 if (mBar != null) {
124 try {
125 mBar.animateExpand();
126 } catch (RemoteException ex) {
127 }
128 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 }
130
Joe Onoratof3f0e052010-05-14 18:49:29 -0700131 public void collapse() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 enforceExpandStatusBar();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133
Joe Onorato4762c2d2010-05-17 15:42:59 -0700134 if (mBar != null) {
135 try {
136 mBar.animateCollapse();
137 } catch (RemoteException ex) {
138 }
139 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 }
141
142 public void disable(int what, IBinder token, String pkg) {
143 enforceStatusBar();
Joe Onoratof3f0e052010-05-14 18:49:29 -0700144
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800145 synchronized (mLock) {
146 disableLocked(what, token, pkg);
147 }
148 }
149
150 private void disableLocked(int what, IBinder token, String pkg) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700151 // It's important that the the callback and the call to mBar get done
152 // in the same order when multiple threads are calling this function
153 // so they are paired correctly. The messages on the handler will be
154 // handled in the order they were enqueued, but will be outside the lock.
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800155 manageDisableListLocked(what, token, pkg);
156 final int net = gatherDisableActionsLocked();
157 if (net != mDisabled) {
158 mDisabled = net;
159 mHandler.post(new Runnable() {
160 public void run() {
161 mNotificationCallbacks.onSetDisabled(net);
Joe Onoratof3f0e052010-05-14 18:49:29 -0700162 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800163 });
164 if (mBar != null) {
165 try {
166 mBar.disable(net);
167 } catch (RemoteException ex) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700168 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 }
171 }
172
Joe Onorato0cbda992010-05-02 16:28:15 -0700173 public void setIcon(String slot, String iconPackage, int iconId, int iconLevel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700175
176 synchronized (mIcons) {
177 int index = mIcons.getSlotIndex(slot);
178 if (index < 0) {
179 throw new SecurityException("invalid status bar icon slot: " + slot);
180 }
181
182 StatusBarIcon icon = new StatusBarIcon(iconPackage, iconId, iconLevel);
Joe Onorato66d7d012010-05-14 10:05:10 -0700183 //Slog.d(TAG, "setIcon slot=" + slot + " index=" + index + " icon=" + icon);
Joe Onorato0cbda992010-05-02 16:28:15 -0700184 mIcons.setIcon(index, icon);
185
Joe Onorato0cbda992010-05-02 16:28:15 -0700186 if (mBar != null) {
187 try {
188 mBar.setIcon(index, icon);
189 } catch (RemoteException ex) {
190 }
191 }
192 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193 }
194
Joe Onorato0cbda992010-05-02 16:28:15 -0700195 public void setIconVisibility(String slot, boolean visible) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800196 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700197
Joe Onorato514ad6632010-05-13 18:49:00 -0700198 synchronized (mIcons) {
199 int index = mIcons.getSlotIndex(slot);
200 if (index < 0) {
201 throw new SecurityException("invalid status bar icon slot: " + slot);
202 }
203
204 StatusBarIcon icon = mIcons.getIcon(index);
205 if (icon == null) {
206 return;
207 }
208
209 if (icon.visible != visible) {
210 icon.visible = visible;
211
Joe Onorato514ad6632010-05-13 18:49:00 -0700212 if (mBar != null) {
213 try {
214 mBar.setIcon(index, icon);
215 } catch (RemoteException ex) {
216 }
217 }
218 }
219 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700220 }
221
222 public void removeIcon(String slot) {
223 enforceStatusBar();
224
225 synchronized (mIcons) {
226 int index = mIcons.getSlotIndex(slot);
227 if (index < 0) {
228 throw new SecurityException("invalid status bar icon slot: " + slot);
229 }
230
231 mIcons.removeIcon(index);
232
Joe Onorato0cbda992010-05-02 16:28:15 -0700233 if (mBar != null) {
234 try {
235 mBar.removeIcon(index);
236 } catch (RemoteException ex) {
237 }
238 }
239 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800240 }
241
Daniel Sandlere02d8082010-10-08 15:13:22 -0400242 /**
243 * Hide or show the on-screen Menu key. Only call this from the window manager, typically in
244 * response to a window with FLAG_NEEDS_MENU_KEY set.
245 */
246 public void setMenuKeyVisible(final boolean visible) {
247 enforceStatusBar();
248
249 if (SPEW) Slog.d(TAG, (visible?"showing":"hiding") + " MENU key");
250
251 synchronized(mLock) {
252 if (mMenuVisible != visible) {
253 mMenuVisible = visible;
254 mHandler.post(new Runnable() {
255 public void run() {
256 if (mBar != null) {
257 try {
258 mBar.setMenuKeyVisible(visible);
259 } catch (RemoteException ex) {
260 }
261 }
262 }
263 });
264 }
265 }
266 }
267
Joe Onorato857fd9b2011-01-27 15:08:35 -0800268 public void setImeWindowStatus(final IBinder token, final int vis, final int backDisposition) {
satok06487a52010-10-29 11:37:18 +0900269 enforceStatusBar();
270
Joe Onorato857fd9b2011-01-27 15:08:35 -0800271 if (SPEW) {
272 Slog.d(TAG, "swetImeWindowStatus vis=" + vis + " backDisposition=" + backDisposition);
273 }
satok06487a52010-10-29 11:37:18 +0900274
275 synchronized(mLock) {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800276 // In case of IME change, we need to call up setImeWindowStatus() regardless of
277 // mImeWindowVis because mImeWindowVis may not have been set to false when the
satok06e07442010-11-02 19:46:55 +0900278 // previous IME was destroyed.
Joe Onorato857fd9b2011-01-27 15:08:35 -0800279 mImeWindowVis = vis;
280 mImeBackDisposition = backDisposition;
281 mImeToken = token;
satok06e07442010-11-02 19:46:55 +0900282 mHandler.post(new Runnable() {
283 public void run() {
284 if (mBar != null) {
285 try {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800286 mBar.setImeWindowStatus(token, vis, backDisposition);
satok06e07442010-11-02 19:46:55 +0900287 } catch (RemoteException ex) {
satok06487a52010-10-29 11:37:18 +0900288 }
289 }
satok06e07442010-11-02 19:46:55 +0900290 }
291 });
satok06487a52010-10-29 11:37:18 +0900292 }
293 }
294
Joe Onorato664644d2011-01-23 17:53:23 -0800295 public void setSystemUiVisibility(int vis) {
Joe Onorato55bf3802011-01-25 13:42:10 -0800296 // also allows calls from window manager which is in this process.
Joe Onoratof63b0f42010-09-12 17:03:19 -0400297 enforceStatusBarService();
298
299 synchronized (mLock) {
Joe Onorato664644d2011-01-23 17:53:23 -0800300 final boolean lightsOn = (vis & View.STATUS_BAR_HIDDEN) == 0;
Joe Onoratof63b0f42010-09-12 17:03:19 -0400301 updateLightsOnLocked(lightsOn);
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800302 disableLocked(vis & StatusBarManager.DISABLE_MASK, mSysUiVisToken,
303 "WindowManager.LayoutParams");
Joe Onoratof63b0f42010-09-12 17:03:19 -0400304 }
305 }
306
307 private void updateLightsOnLocked(final boolean lightsOn) {
308 if (mLightsOn != lightsOn) {
309 mLightsOn = lightsOn;
310 mHandler.post(new Runnable() {
311 public void run() {
312 if (mBar != null) {
313 try {
314 mBar.setLightsOn(lightsOn);
315 } catch (RemoteException ex) {
Joe Onorato93056472010-09-10 10:30:46 -0400316 }
317 }
Joe Onoratof63b0f42010-09-12 17:03:19 -0400318 }
319 });
Joe Onorato93056472010-09-10 10:30:46 -0400320 }
321 }
322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800323 private void enforceStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700324 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700325 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800326 }
327
328 private void enforceExpandStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700329 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.EXPAND_STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700330 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331 }
332
Joe Onorato8bc6c512010-06-04 16:21:12 -0400333 private void enforceStatusBarService() {
334 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
335 "StatusBarManagerService");
336 }
337
Joe Onorato4762c2d2010-05-17 15:42:59 -0700338
339 // ================================================================================
340 // Callbacks from the status bar service.
341 // ================================================================================
Joe Onorato75199e32010-05-29 17:22:51 -0400342 public void registerStatusBar(IStatusBar bar, StatusBarIconList iconList,
Joe Onorato93056472010-09-10 10:30:46 -0400343 List<IBinder> notificationKeys, List<StatusBarNotification> notifications,
satokcd7cd292010-11-20 15:46:23 +0900344 int switches[], List<IBinder> binders) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400345 enforceStatusBarService();
346
Joe Onorato0cbda992010-05-02 16:28:15 -0700347 Slog.i(TAG, "registerStatusBar bar=" + bar);
348 mBar = bar;
Joe Onorato75199e32010-05-29 17:22:51 -0400349 synchronized (mIcons) {
350 iconList.copyFrom(mIcons);
351 }
352 synchronized (mNotifications) {
353 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
354 notificationKeys.add(e.getKey());
355 notifications.add(e.getValue());
356 }
357 }
Joe Onorato93056472010-09-10 10:30:46 -0400358 synchronized (mLock) {
Joe Onoratoe4c7b3f2010-10-30 12:15:03 -0700359 switches[0] = gatherDisableActionsLocked();
360 switches[1] = mLightsOn ? 1 : 0;
361 switches[2] = mMenuVisible ? 1 : 0;
Joe Onorato857fd9b2011-01-27 15:08:35 -0800362 switches[3] = mImeWindowVis;
363 switches[4] = mImeBackDisposition;
364 binders.add(mImeToken);
Joe Onorato93056472010-09-10 10:30:46 -0400365 }
Joe Onorato2314aab2010-04-08 16:41:23 -0500366 }
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400367
Joe Onorato4762c2d2010-05-17 15:42:59 -0700368 /**
Joe Onoratof1f25912010-06-07 11:52:41 -0700369 * The status bar service should call this each time the user brings the panel from
370 * invisible to visible in order to clear the notification light.
Joe Onorato4762c2d2010-05-17 15:42:59 -0700371 */
Joe Onoratof1f25912010-06-07 11:52:41 -0700372 public void onPanelRevealed() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400373 enforceStatusBarService();
374
Joe Onoratof1f25912010-06-07 11:52:41 -0700375 // tell the notification manager to turn off the lights.
376 mNotificationCallbacks.onPanelRevealed();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700377 }
378
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400379 public void onNotificationClick(String pkg, String tag, int id) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400380 enforceStatusBarService();
381
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400382 mNotificationCallbacks.onNotificationClick(pkg, tag, id);
383 }
384
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700385 public void onNotificationError(String pkg, String tag, int id,
386 int uid, int initialPid, String message) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400387 enforceStatusBarService();
388
Joe Onorato005847b2010-06-04 16:08:02 -0400389 // WARNING: this will call back into us to do the remove. Don't hold any locks.
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700390 mNotificationCallbacks.onNotificationError(pkg, tag, id, uid, initialPid, message);
Joe Onorato005847b2010-06-04 16:08:02 -0400391 }
392
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400393 public void onNotificationClear(String pkg, String tag, int id) {
394 enforceStatusBarService();
395
396 mNotificationCallbacks.onNotificationClear(pkg, tag, id);
397 }
398
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400399 public void onClearAllNotifications() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400400 enforceStatusBarService();
401
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400402 mNotificationCallbacks.onClearAll();
403 }
404
Joe Onorato18e69df2010-05-17 22:26:12 -0700405 // ================================================================================
406 // Callbacks for NotificationManagerService.
407 // ================================================================================
408 public IBinder addNotification(StatusBarNotification notification) {
409 synchronized (mNotifications) {
Joe Onoratoa0c56fe2010-05-20 10:21:52 -0700410 IBinder key = new Binder();
Joe Onorato75199e32010-05-29 17:22:51 -0400411 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400412 if (mBar != null) {
413 try {
414 mBar.addNotification(key, notification);
415 } catch (RemoteException ex) {
416 }
417 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700418 return key;
419 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700420 }
421
Joe Onorato18e69df2010-05-17 22:26:12 -0700422 public void updateNotification(IBinder key, StatusBarNotification notification) {
423 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400424 if (!mNotifications.containsKey(key)) {
425 throw new IllegalArgumentException("updateNotification key not found: " + key);
426 }
427 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400428 if (mBar != null) {
429 try {
430 mBar.updateNotification(key, notification);
431 } catch (RemoteException ex) {
432 }
433 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700434 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700435 }
436
437 public void removeNotification(IBinder key) {
Joe Onorato18e69df2010-05-17 22:26:12 -0700438 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400439 final StatusBarNotification n = mNotifications.remove(key);
440 if (n == null) {
441 throw new IllegalArgumentException("removeNotification key not found: " + key);
442 }
Joe Onoratoe345fff2010-05-23 15:18:27 -0400443 if (mBar != null) {
444 try {
445 mBar.removeNotification(key);
446 } catch (RemoteException ex) {
447 }
448 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700449 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700450 }
Joe Onorato2314aab2010-04-08 16:41:23 -0500451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800452 // ================================================================================
453 // Can be called from any thread
454 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800456 // lock on mDisableRecords
457 void manageDisableListLocked(int what, IBinder token, String pkg) {
458 if (SPEW) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700459 Slog.d(TAG, "manageDisableList what=0x" + Integer.toHexString(what) + " pkg=" + pkg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800460 }
461 // update the list
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800462 final int N = mDisableRecords.size();
463 DisableRecord tok = null;
464 int i;
465 for (i=0; i<N; i++) {
466 DisableRecord t = mDisableRecords.get(i);
467 if (t.token == token) {
468 tok = t;
469 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800470 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800471 }
472 if (what == 0 || !token.isBinderAlive()) {
473 if (tok != null) {
474 mDisableRecords.remove(i);
475 tok.token.unlinkToDeath(tok, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800476 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800477 } else {
478 if (tok == null) {
479 tok = new DisableRecord();
480 try {
481 token.linkToDeath(tok, 0);
482 }
483 catch (RemoteException ex) {
484 return; // give up
485 }
486 mDisableRecords.add(tok);
487 }
488 tok.what = what;
489 tok.token = token;
490 tok.pkg = pkg;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800491 }
492 }
493
494 // lock on mDisableRecords
495 int gatherDisableActionsLocked() {
496 final int N = mDisableRecords.size();
497 // gather the new net flags
498 int net = 0;
499 for (int i=0; i<N; i++) {
500 net |= mDisableRecords.get(i).what;
501 }
502 return net;
503 }
504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800505 // ================================================================================
506 // Always called from UI thread
507 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800509 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
510 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
511 != PackageManager.PERMISSION_GRANTED) {
512 pw.println("Permission Denial: can't dump StatusBar from from pid="
513 + Binder.getCallingPid()
514 + ", uid=" + Binder.getCallingUid());
515 return;
516 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700517
Joe Onorato0cbda992010-05-02 16:28:15 -0700518 synchronized (mIcons) {
519 mIcons.dump(pw);
520 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700521
522 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400523 int i=0;
524 pw.println("Notification list:");
525 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
526 pw.printf(" %2d: %s\n", i, e.getValue().toString());
527 i++;
528 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800529 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700530
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800531 synchronized (mLock) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 final int N = mDisableRecords.size();
533 pw.println(" mDisableRecords.size=" + N
534 + " mDisabled=0x" + Integer.toHexString(mDisabled));
535 for (int i=0; i<N; i++) {
536 DisableRecord tok = mDisableRecords.get(i);
537 pw.println(" [" + i + "] what=0x" + Integer.toHexString(tok.what)
538 + " pkg=" + tok.pkg + " token=" + tok.token);
539 }
540 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541 }
542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800543 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
544 public void onReceive(Context context, Intent intent) {
545 String action = intent.getAction();
Joe Onoratof9e0e6b2009-09-08 16:24:36 -0400546 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
547 || Intent.ACTION_SCREEN_OFF.equals(action)) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700548 collapse();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800549 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700550 /*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800551 else if (Telephony.Intents.SPN_STRINGS_UPDATED_ACTION.equals(action)) {
552 updateNetworkName(intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_SPN, false),
553 intent.getStringExtra(Telephony.Intents.EXTRA_SPN),
554 intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_PLMN, false),
555 intent.getStringExtra(Telephony.Intents.EXTRA_PLMN));
556 }
557 else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
558 updateResources();
559 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700560 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800561 }
562 };
563
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564}