blob: cdbf237c59e53a69b282c83ed149df84445aec1b [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>();
70 int mDisabled = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071
Joe Onorato93056472010-09-10 10:30:46 -040072 Object mLock = new Object();
73 // We usually call it lights out mode, but double negatives are annoying
74 boolean mLightsOn = true;
Daniel Sandlere02d8082010-10-08 15:13:22 -040075 boolean mMenuVisible = false;
Joe Onorato857fd9b2011-01-27 15:08:35 -080076 int mImeWindowVis = 0;
77 int mImeBackDisposition;
78 IBinder mImeToken = null;
satok06487a52010-10-29 11:37:18 +090079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080 private class DisableRecord implements IBinder.DeathRecipient {
81 String pkg;
82 int what;
83 IBinder token;
84
85 public void binderDied() {
Joe Onorato8a9b2202010-02-26 18:56:32 -080086 Slog.i(TAG, "binder died for pkg=" + pkg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087 disable(0, token, pkg);
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -070088 token.unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 }
90 }
91
92 public interface NotificationCallbacks {
93 void onSetDisabled(int status);
94 void onClearAll();
Fred Quintana6ecaff12009-09-25 14:23:13 -070095 void onNotificationClick(String pkg, String tag, int id);
Daniel Sandler0f0b11c2010-08-04 15:54:58 -040096 void onNotificationClear(String pkg, String tag, int id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 void onPanelRevealed();
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -070098 void onNotificationError(String pkg, String tag, int id,
99 int uid, int initialPid, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 }
101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102 /**
103 * Construct the service, add the status bar view to the window manager
104 */
Joe Onorato089de882010-04-12 08:18:45 -0700105 public StatusBarManagerService(Context context) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 mContext = context;
Joe Onorato0cbda992010-05-02 16:28:15 -0700107
108 final Resources res = context.getResources();
Joe Onorato75144ea2010-06-07 12:36:25 -0700109 mIcons.defineSlots(res.getStringArray(com.android.internal.R.array.config_statusBarIcons));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110 }
111
112 public void setNotificationCallbacks(NotificationCallbacks listener) {
113 mNotificationCallbacks = listener;
114 }
115
116 // ================================================================================
Joe Onorato25f95f92010-04-08 18:37:10 -0500117 // From IStatusBarService
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118 // ================================================================================
Joe Onoratof3f0e052010-05-14 18:49:29 -0700119 public void expand() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120 enforceExpandStatusBar();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700121
122 if (mBar != null) {
123 try {
124 mBar.animateExpand();
125 } catch (RemoteException ex) {
126 }
127 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 }
129
Joe Onoratof3f0e052010-05-14 18:49:29 -0700130 public void collapse() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131 enforceExpandStatusBar();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132
Joe Onorato4762c2d2010-05-17 15:42:59 -0700133 if (mBar != null) {
134 try {
135 mBar.animateCollapse();
136 } catch (RemoteException ex) {
137 }
138 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 }
140
141 public void disable(int what, IBinder token, String pkg) {
142 enforceStatusBar();
Joe Onoratof3f0e052010-05-14 18:49:29 -0700143
144 // It's important that the the callback and the call to mBar get done
145 // in the same order when multiple threads are calling this function
146 // so they are paired correctly. The messages on the handler will be
147 // handled in the order they were enqueued, but will be outside the lock.
148 synchronized (mDisableRecords) {
149 manageDisableListLocked(what, token, pkg);
150 final int net = gatherDisableActionsLocked();
Joe Onoratof3f0e052010-05-14 18:49:29 -0700151 if (net != mDisabled) {
152 mDisabled = net;
153 mHandler.post(new Runnable() {
154 public void run() {
155 mNotificationCallbacks.onSetDisabled(net);
156 }
157 });
158 if (mBar != null) {
159 try {
160 mBar.disable(net);
161 } catch (RemoteException ex) {
162 }
163 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 }
166 }
167
Joe Onorato0cbda992010-05-02 16:28:15 -0700168 public void setIcon(String slot, String iconPackage, int iconId, int iconLevel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700170
171 synchronized (mIcons) {
172 int index = mIcons.getSlotIndex(slot);
173 if (index < 0) {
174 throw new SecurityException("invalid status bar icon slot: " + slot);
175 }
176
177 StatusBarIcon icon = new StatusBarIcon(iconPackage, iconId, iconLevel);
Joe Onorato66d7d012010-05-14 10:05:10 -0700178 //Slog.d(TAG, "setIcon slot=" + slot + " index=" + index + " icon=" + icon);
Joe Onorato0cbda992010-05-02 16:28:15 -0700179 mIcons.setIcon(index, icon);
180
Joe Onorato0cbda992010-05-02 16:28:15 -0700181 if (mBar != null) {
182 try {
183 mBar.setIcon(index, icon);
184 } catch (RemoteException ex) {
185 }
186 }
187 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188 }
189
Joe Onorato0cbda992010-05-02 16:28:15 -0700190 public void setIconVisibility(String slot, boolean visible) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700192
Joe Onorato514ad6632010-05-13 18:49:00 -0700193 synchronized (mIcons) {
194 int index = mIcons.getSlotIndex(slot);
195 if (index < 0) {
196 throw new SecurityException("invalid status bar icon slot: " + slot);
197 }
198
199 StatusBarIcon icon = mIcons.getIcon(index);
200 if (icon == null) {
201 return;
202 }
203
204 if (icon.visible != visible) {
205 icon.visible = visible;
206
Joe Onorato514ad6632010-05-13 18:49:00 -0700207 if (mBar != null) {
208 try {
209 mBar.setIcon(index, icon);
210 } catch (RemoteException ex) {
211 }
212 }
213 }
214 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700215 }
216
217 public void removeIcon(String slot) {
218 enforceStatusBar();
219
220 synchronized (mIcons) {
221 int index = mIcons.getSlotIndex(slot);
222 if (index < 0) {
223 throw new SecurityException("invalid status bar icon slot: " + slot);
224 }
225
226 mIcons.removeIcon(index);
227
Joe Onorato0cbda992010-05-02 16:28:15 -0700228 if (mBar != null) {
229 try {
230 mBar.removeIcon(index);
231 } catch (RemoteException ex) {
232 }
233 }
234 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800235 }
236
Daniel Sandlere02d8082010-10-08 15:13:22 -0400237 /**
238 * Hide or show the on-screen Menu key. Only call this from the window manager, typically in
239 * response to a window with FLAG_NEEDS_MENU_KEY set.
240 */
241 public void setMenuKeyVisible(final boolean visible) {
242 enforceStatusBar();
243
244 if (SPEW) Slog.d(TAG, (visible?"showing":"hiding") + " MENU key");
245
246 synchronized(mLock) {
247 if (mMenuVisible != visible) {
248 mMenuVisible = visible;
249 mHandler.post(new Runnable() {
250 public void run() {
251 if (mBar != null) {
252 try {
253 mBar.setMenuKeyVisible(visible);
254 } catch (RemoteException ex) {
255 }
256 }
257 }
258 });
259 }
260 }
261 }
262
Joe Onorato857fd9b2011-01-27 15:08:35 -0800263 public void setImeWindowStatus(final IBinder token, final int vis, final int backDisposition) {
satok06487a52010-10-29 11:37:18 +0900264 enforceStatusBar();
265
Joe Onorato857fd9b2011-01-27 15:08:35 -0800266 if (SPEW) {
267 Slog.d(TAG, "swetImeWindowStatus vis=" + vis + " backDisposition=" + backDisposition);
268 }
satok06487a52010-10-29 11:37:18 +0900269
270 synchronized(mLock) {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800271 // In case of IME change, we need to call up setImeWindowStatus() regardless of
272 // mImeWindowVis because mImeWindowVis may not have been set to false when the
satok06e07442010-11-02 19:46:55 +0900273 // previous IME was destroyed.
Joe Onorato857fd9b2011-01-27 15:08:35 -0800274 mImeWindowVis = vis;
275 mImeBackDisposition = backDisposition;
276 mImeToken = token;
satok06e07442010-11-02 19:46:55 +0900277 mHandler.post(new Runnable() {
278 public void run() {
279 if (mBar != null) {
280 try {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800281 mBar.setImeWindowStatus(token, vis, backDisposition);
satok06e07442010-11-02 19:46:55 +0900282 } catch (RemoteException ex) {
satok06487a52010-10-29 11:37:18 +0900283 }
284 }
satok06e07442010-11-02 19:46:55 +0900285 }
286 });
satok06487a52010-10-29 11:37:18 +0900287 }
288 }
289
Joe Onorato664644d2011-01-23 17:53:23 -0800290 public void setSystemUiVisibility(int vis) {
Joe Onorato55bf3802011-01-25 13:42:10 -0800291 // also allows calls from window manager which is in this process.
Joe Onoratof63b0f42010-09-12 17:03:19 -0400292 enforceStatusBarService();
293
294 synchronized (mLock) {
Joe Onorato664644d2011-01-23 17:53:23 -0800295 final boolean lightsOn = (vis & View.STATUS_BAR_HIDDEN) == 0;
Joe Onoratof63b0f42010-09-12 17:03:19 -0400296 updateLightsOnLocked(lightsOn);
297 }
298 }
299
300 private void updateLightsOnLocked(final boolean lightsOn) {
301 if (mLightsOn != lightsOn) {
302 mLightsOn = lightsOn;
303 mHandler.post(new Runnable() {
304 public void run() {
305 if (mBar != null) {
306 try {
307 mBar.setLightsOn(lightsOn);
308 } catch (RemoteException ex) {
Joe Onorato93056472010-09-10 10:30:46 -0400309 }
310 }
Joe Onoratof63b0f42010-09-12 17:03:19 -0400311 }
312 });
Joe Onorato93056472010-09-10 10:30:46 -0400313 }
314 }
315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316 private void enforceStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700317 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700318 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319 }
320
321 private void enforceExpandStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700322 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.EXPAND_STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700323 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800324 }
325
Joe Onorato8bc6c512010-06-04 16:21:12 -0400326 private void enforceStatusBarService() {
327 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
328 "StatusBarManagerService");
329 }
330
Joe Onorato4762c2d2010-05-17 15:42:59 -0700331
332 // ================================================================================
333 // Callbacks from the status bar service.
334 // ================================================================================
Joe Onorato75199e32010-05-29 17:22:51 -0400335 public void registerStatusBar(IStatusBar bar, StatusBarIconList iconList,
Joe Onorato93056472010-09-10 10:30:46 -0400336 List<IBinder> notificationKeys, List<StatusBarNotification> notifications,
satokcd7cd292010-11-20 15:46:23 +0900337 int switches[], List<IBinder> binders) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400338 enforceStatusBarService();
339
Joe Onorato0cbda992010-05-02 16:28:15 -0700340 Slog.i(TAG, "registerStatusBar bar=" + bar);
341 mBar = bar;
Joe Onorato75199e32010-05-29 17:22:51 -0400342 synchronized (mIcons) {
343 iconList.copyFrom(mIcons);
344 }
345 synchronized (mNotifications) {
346 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
347 notificationKeys.add(e.getKey());
348 notifications.add(e.getValue());
349 }
350 }
Joe Onorato93056472010-09-10 10:30:46 -0400351 synchronized (mLock) {
Joe Onoratoe4c7b3f2010-10-30 12:15:03 -0700352 switches[0] = gatherDisableActionsLocked();
353 switches[1] = mLightsOn ? 1 : 0;
354 switches[2] = mMenuVisible ? 1 : 0;
Joe Onorato857fd9b2011-01-27 15:08:35 -0800355 switches[3] = mImeWindowVis;
356 switches[4] = mImeBackDisposition;
357 binders.add(mImeToken);
Joe Onorato93056472010-09-10 10:30:46 -0400358 }
Joe Onorato2314aab2010-04-08 16:41:23 -0500359 }
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400360
Joe Onorato4762c2d2010-05-17 15:42:59 -0700361 /**
Joe Onoratof1f25912010-06-07 11:52:41 -0700362 * The status bar service should call this each time the user brings the panel from
363 * invisible to visible in order to clear the notification light.
Joe Onorato4762c2d2010-05-17 15:42:59 -0700364 */
Joe Onoratof1f25912010-06-07 11:52:41 -0700365 public void onPanelRevealed() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400366 enforceStatusBarService();
367
Joe Onoratof1f25912010-06-07 11:52:41 -0700368 // tell the notification manager to turn off the lights.
369 mNotificationCallbacks.onPanelRevealed();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700370 }
371
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400372 public void onNotificationClick(String pkg, String tag, int id) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400373 enforceStatusBarService();
374
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400375 mNotificationCallbacks.onNotificationClick(pkg, tag, id);
376 }
377
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700378 public void onNotificationError(String pkg, String tag, int id,
379 int uid, int initialPid, String message) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400380 enforceStatusBarService();
381
Joe Onorato005847b2010-06-04 16:08:02 -0400382 // WARNING: this will call back into us to do the remove. Don't hold any locks.
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700383 mNotificationCallbacks.onNotificationError(pkg, tag, id, uid, initialPid, message);
Joe Onorato005847b2010-06-04 16:08:02 -0400384 }
385
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400386 public void onNotificationClear(String pkg, String tag, int id) {
387 enforceStatusBarService();
388
389 mNotificationCallbacks.onNotificationClear(pkg, tag, id);
390 }
391
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400392 public void onClearAllNotifications() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400393 enforceStatusBarService();
394
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400395 mNotificationCallbacks.onClearAll();
396 }
397
Joe Onorato18e69df2010-05-17 22:26:12 -0700398 // ================================================================================
399 // Callbacks for NotificationManagerService.
400 // ================================================================================
401 public IBinder addNotification(StatusBarNotification notification) {
402 synchronized (mNotifications) {
Joe Onoratoa0c56fe2010-05-20 10:21:52 -0700403 IBinder key = new Binder();
Joe Onorato75199e32010-05-29 17:22:51 -0400404 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400405 if (mBar != null) {
406 try {
407 mBar.addNotification(key, notification);
408 } catch (RemoteException ex) {
409 }
410 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700411 return key;
412 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700413 }
414
Joe Onorato18e69df2010-05-17 22:26:12 -0700415 public void updateNotification(IBinder key, StatusBarNotification notification) {
416 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400417 if (!mNotifications.containsKey(key)) {
418 throw new IllegalArgumentException("updateNotification key not found: " + key);
419 }
420 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400421 if (mBar != null) {
422 try {
423 mBar.updateNotification(key, notification);
424 } catch (RemoteException ex) {
425 }
426 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700427 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700428 }
429
430 public void removeNotification(IBinder key) {
Joe Onorato18e69df2010-05-17 22:26:12 -0700431 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400432 final StatusBarNotification n = mNotifications.remove(key);
433 if (n == null) {
434 throw new IllegalArgumentException("removeNotification key not found: " + key);
435 }
Joe Onoratoe345fff2010-05-23 15:18:27 -0400436 if (mBar != null) {
437 try {
438 mBar.removeNotification(key);
439 } catch (RemoteException ex) {
440 }
441 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700442 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700443 }
Joe Onorato2314aab2010-04-08 16:41:23 -0500444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800445 // ================================================================================
446 // Can be called from any thread
447 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800449 // lock on mDisableRecords
450 void manageDisableListLocked(int what, IBinder token, String pkg) {
451 if (SPEW) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700452 Slog.d(TAG, "manageDisableList what=0x" + Integer.toHexString(what) + " pkg=" + pkg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800453 }
454 // update the list
455 synchronized (mDisableRecords) {
456 final int N = mDisableRecords.size();
457 DisableRecord tok = null;
458 int i;
459 for (i=0; i<N; i++) {
460 DisableRecord t = mDisableRecords.get(i);
461 if (t.token == token) {
462 tok = t;
463 break;
464 }
465 }
466 if (what == 0 || !token.isBinderAlive()) {
467 if (tok != null) {
468 mDisableRecords.remove(i);
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -0700469 tok.token.unlinkToDeath(tok, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800470 }
471 } else {
472 if (tok == null) {
473 tok = new DisableRecord();
474 try {
475 token.linkToDeath(tok, 0);
476 }
477 catch (RemoteException ex) {
478 return; // give up
479 }
480 mDisableRecords.add(tok);
481 }
482 tok.what = what;
483 tok.token = token;
484 tok.pkg = pkg;
485 }
486 }
487 }
488
489 // lock on mDisableRecords
490 int gatherDisableActionsLocked() {
491 final int N = mDisableRecords.size();
492 // gather the new net flags
493 int net = 0;
494 for (int i=0; i<N; i++) {
495 net |= mDisableRecords.get(i).what;
496 }
497 return net;
498 }
499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500 // ================================================================================
501 // Always called from UI thread
502 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
505 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
506 != PackageManager.PERMISSION_GRANTED) {
507 pw.println("Permission Denial: can't dump StatusBar from from pid="
508 + Binder.getCallingPid()
509 + ", uid=" + Binder.getCallingUid());
510 return;
511 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700512
Joe Onorato0cbda992010-05-02 16:28:15 -0700513 synchronized (mIcons) {
514 mIcons.dump(pw);
515 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700516
517 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400518 int i=0;
519 pw.println("Notification list:");
520 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
521 pw.printf(" %2d: %s\n", i, e.getValue().toString());
522 i++;
523 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800524 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800526 synchronized (mDisableRecords) {
527 final int N = mDisableRecords.size();
528 pw.println(" mDisableRecords.size=" + N
529 + " mDisabled=0x" + Integer.toHexString(mDisabled));
530 for (int i=0; i<N; i++) {
531 DisableRecord tok = mDisableRecords.get(i);
532 pw.println(" [" + i + "] what=0x" + Integer.toHexString(tok.what)
533 + " pkg=" + tok.pkg + " token=" + tok.token);
534 }
535 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 }
537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800538 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
539 public void onReceive(Context context, Intent intent) {
540 String action = intent.getAction();
Joe Onoratof9e0e6b2009-09-08 16:24:36 -0400541 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
542 || Intent.ACTION_SCREEN_OFF.equals(action)) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700543 collapse();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700545 /*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800546 else if (Telephony.Intents.SPN_STRINGS_UPDATED_ACTION.equals(action)) {
547 updateNetworkName(intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_SPN, false),
548 intent.getStringExtra(Telephony.Intents.EXTRA_SPN),
549 intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_PLMN, false),
550 intent.getStringExtra(Telephony.Intents.EXTRA_PLMN));
551 }
552 else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
553 updateResources();
554 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700555 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556 }
557 };
558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800559}