blob: 8df817789af220eedffa53946a5480d9c664207d [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;
Dianne Hackborna924dc0d2011-02-17 14:22:17 -080042import com.android.server.wm.WindowManagerService;
The Android Open Source Project10592532009-03-18 17:39:46 -070043
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import java.io.FileDescriptor;
45import java.io.PrintWriter;
46import java.util.ArrayList;
47import java.util.HashMap;
Joe Onorato75199e32010-05-29 17:22:51 -040048import java.util.List;
49import java.util.Map;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050
51
52/**
Joe Onoratof3f0e052010-05-14 18:49:29 -070053 * A note on locking: We rely on the fact that calls onto mBar are oneway or
54 * if they are local, that they just enqueue messages to not deadlock.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 */
Joe Onorato089de882010-04-12 08:18:45 -070056public class StatusBarManagerService extends IStatusBarService.Stub
Jeff Brown2992ea72011-01-28 22:04:14 -080057 implements WindowManagerService.OnHardKeyboardStatusChangeListener
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058{
Joe Onorato4762c2d2010-05-17 15:42:59 -070059 static final String TAG = "StatusBarManagerService";
Joe Onorato431bb222010-10-18 19:13:23 -040060 static final boolean SPEW = false;
Joe Onoratodf7dbb62009-11-17 10:43:37 -080061
Joe Onoratof3f0e052010-05-14 18:49:29 -070062 final Context mContext;
Jeff Brown2992ea72011-01-28 22:04:14 -080063 final WindowManagerService mWindowManager;
Joe Onoratof3f0e052010-05-14 18:49:29 -070064 Handler mHandler = new Handler();
65 NotificationCallbacks mNotificationCallbacks;
Joe Onorato4762c2d2010-05-17 15:42:59 -070066 volatile IStatusBar mBar;
Joe Onoratof3f0e052010-05-14 18:49:29 -070067 StatusBarIconList mIcons = new StatusBarIconList();
Joe Onorato75199e32010-05-29 17:22:51 -040068 HashMap<IBinder,StatusBarNotification> mNotifications
69 = new HashMap<IBinder,StatusBarNotification>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070
Joe Onoratof3f0e052010-05-14 18:49:29 -070071 // for disabling the status bar
72 ArrayList<DisableRecord> mDisableRecords = new ArrayList<DisableRecord>();
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080073 IBinder mSysUiVisToken = new Binder();
Joe Onoratof3f0e052010-05-14 18:49:29 -070074 int mDisabled = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075
Joe Onorato93056472010-09-10 10:30:46 -040076 Object mLock = new Object();
77 // We usually call it lights out mode, but double negatives are annoying
78 boolean mLightsOn = true;
Daniel Sandlere02d8082010-10-08 15:13:22 -040079 boolean mMenuVisible = false;
Joe Onorato857fd9b2011-01-27 15:08:35 -080080 int mImeWindowVis = 0;
81 int mImeBackDisposition;
82 IBinder mImeToken = null;
satok06487a52010-10-29 11:37:18 +090083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 private class DisableRecord implements IBinder.DeathRecipient {
85 String pkg;
86 int what;
87 IBinder token;
88
89 public void binderDied() {
Joe Onorato8a9b2202010-02-26 18:56:32 -080090 Slog.i(TAG, "binder died for pkg=" + pkg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 disable(0, token, pkg);
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -070092 token.unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 }
94 }
95
96 public interface NotificationCallbacks {
97 void onSetDisabled(int status);
98 void onClearAll();
Fred Quintana6ecaff12009-09-25 14:23:13 -070099 void onNotificationClick(String pkg, String tag, int id);
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400100 void onNotificationClear(String pkg, String tag, int id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101 void onPanelRevealed();
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700102 void onNotificationError(String pkg, String tag, int id,
103 int uid, int initialPid, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104 }
105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 /**
107 * Construct the service, add the status bar view to the window manager
108 */
Jeff Brown2992ea72011-01-28 22:04:14 -0800109 public StatusBarManagerService(Context context, WindowManagerService windowManager) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110 mContext = context;
Jeff Brown2992ea72011-01-28 22:04:14 -0800111 mWindowManager = windowManager;
112 mWindowManager.setOnHardKeyboardStatusChangeListener(this);
Joe Onorato0cbda992010-05-02 16:28:15 -0700113
114 final Resources res = context.getResources();
Joe Onorato75144ea2010-06-07 12:36:25 -0700115 mIcons.defineSlots(res.getStringArray(com.android.internal.R.array.config_statusBarIcons));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116 }
117
118 public void setNotificationCallbacks(NotificationCallbacks listener) {
119 mNotificationCallbacks = listener;
120 }
121
122 // ================================================================================
Joe Onorato25f95f92010-04-08 18:37:10 -0500123 // From IStatusBarService
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 // ================================================================================
Joe Onoratof3f0e052010-05-14 18:49:29 -0700125 public void expand() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126 enforceExpandStatusBar();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700127
128 if (mBar != null) {
129 try {
130 mBar.animateExpand();
131 } catch (RemoteException ex) {
132 }
133 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 }
135
Joe Onoratof3f0e052010-05-14 18:49:29 -0700136 public void collapse() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 enforceExpandStatusBar();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138
Joe Onorato4762c2d2010-05-17 15:42:59 -0700139 if (mBar != null) {
140 try {
141 mBar.animateCollapse();
142 } catch (RemoteException ex) {
143 }
144 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 }
146
147 public void disable(int what, IBinder token, String pkg) {
148 enforceStatusBar();
Joe Onoratof3f0e052010-05-14 18:49:29 -0700149
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800150 synchronized (mLock) {
151 disableLocked(what, token, pkg);
152 }
153 }
154
155 private void disableLocked(int what, IBinder token, String pkg) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700156 // It's important that the the callback and the call to mBar get done
157 // in the same order when multiple threads are calling this function
158 // so they are paired correctly. The messages on the handler will be
159 // handled in the order they were enqueued, but will be outside the lock.
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800160 manageDisableListLocked(what, token, pkg);
161 final int net = gatherDisableActionsLocked();
162 if (net != mDisabled) {
163 mDisabled = net;
164 mHandler.post(new Runnable() {
165 public void run() {
166 mNotificationCallbacks.onSetDisabled(net);
Joe Onoratof3f0e052010-05-14 18:49:29 -0700167 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800168 });
169 if (mBar != null) {
170 try {
171 mBar.disable(net);
172 } catch (RemoteException ex) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700173 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175 }
176 }
177
Joe Onorato0cbda992010-05-02 16:28:15 -0700178 public void setIcon(String slot, String iconPackage, int iconId, int iconLevel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700180
181 synchronized (mIcons) {
182 int index = mIcons.getSlotIndex(slot);
183 if (index < 0) {
184 throw new SecurityException("invalid status bar icon slot: " + slot);
185 }
186
187 StatusBarIcon icon = new StatusBarIcon(iconPackage, iconId, iconLevel);
Joe Onorato66d7d012010-05-14 10:05:10 -0700188 //Slog.d(TAG, "setIcon slot=" + slot + " index=" + index + " icon=" + icon);
Joe Onorato0cbda992010-05-02 16:28:15 -0700189 mIcons.setIcon(index, icon);
190
Joe Onorato0cbda992010-05-02 16:28:15 -0700191 if (mBar != null) {
192 try {
193 mBar.setIcon(index, icon);
194 } catch (RemoteException ex) {
195 }
196 }
197 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198 }
199
Joe Onorato0cbda992010-05-02 16:28:15 -0700200 public void setIconVisibility(String slot, boolean visible) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800201 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700202
Joe Onorato514ad6632010-05-13 18:49:00 -0700203 synchronized (mIcons) {
204 int index = mIcons.getSlotIndex(slot);
205 if (index < 0) {
206 throw new SecurityException("invalid status bar icon slot: " + slot);
207 }
208
209 StatusBarIcon icon = mIcons.getIcon(index);
210 if (icon == null) {
211 return;
212 }
213
214 if (icon.visible != visible) {
215 icon.visible = visible;
216
Joe Onorato514ad6632010-05-13 18:49:00 -0700217 if (mBar != null) {
218 try {
219 mBar.setIcon(index, icon);
220 } catch (RemoteException ex) {
221 }
222 }
223 }
224 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700225 }
226
227 public void removeIcon(String slot) {
228 enforceStatusBar();
229
230 synchronized (mIcons) {
231 int index = mIcons.getSlotIndex(slot);
232 if (index < 0) {
233 throw new SecurityException("invalid status bar icon slot: " + slot);
234 }
235
236 mIcons.removeIcon(index);
237
Joe Onorato0cbda992010-05-02 16:28:15 -0700238 if (mBar != null) {
239 try {
240 mBar.removeIcon(index);
241 } catch (RemoteException ex) {
242 }
243 }
244 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800245 }
246
Daniel Sandlere02d8082010-10-08 15:13:22 -0400247 /**
248 * Hide or show the on-screen Menu key. Only call this from the window manager, typically in
249 * response to a window with FLAG_NEEDS_MENU_KEY set.
250 */
251 public void setMenuKeyVisible(final boolean visible) {
252 enforceStatusBar();
253
254 if (SPEW) Slog.d(TAG, (visible?"showing":"hiding") + " MENU key");
255
256 synchronized(mLock) {
257 if (mMenuVisible != visible) {
258 mMenuVisible = visible;
259 mHandler.post(new Runnable() {
260 public void run() {
261 if (mBar != null) {
262 try {
263 mBar.setMenuKeyVisible(visible);
264 } catch (RemoteException ex) {
265 }
266 }
267 }
268 });
269 }
270 }
271 }
272
Joe Onorato857fd9b2011-01-27 15:08:35 -0800273 public void setImeWindowStatus(final IBinder token, final int vis, final int backDisposition) {
satok06487a52010-10-29 11:37:18 +0900274 enforceStatusBar();
275
Joe Onorato857fd9b2011-01-27 15:08:35 -0800276 if (SPEW) {
277 Slog.d(TAG, "swetImeWindowStatus vis=" + vis + " backDisposition=" + backDisposition);
278 }
satok06487a52010-10-29 11:37:18 +0900279
280 synchronized(mLock) {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800281 // In case of IME change, we need to call up setImeWindowStatus() regardless of
282 // mImeWindowVis because mImeWindowVis may not have been set to false when the
satok06e07442010-11-02 19:46:55 +0900283 // previous IME was destroyed.
Joe Onorato857fd9b2011-01-27 15:08:35 -0800284 mImeWindowVis = vis;
285 mImeBackDisposition = backDisposition;
286 mImeToken = token;
satok06e07442010-11-02 19:46:55 +0900287 mHandler.post(new Runnable() {
288 public void run() {
289 if (mBar != null) {
290 try {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800291 mBar.setImeWindowStatus(token, vis, backDisposition);
satok06e07442010-11-02 19:46:55 +0900292 } catch (RemoteException ex) {
satok06487a52010-10-29 11:37:18 +0900293 }
294 }
satok06e07442010-11-02 19:46:55 +0900295 }
296 });
satok06487a52010-10-29 11:37:18 +0900297 }
298 }
299
Joe Onorato664644d2011-01-23 17:53:23 -0800300 public void setSystemUiVisibility(int vis) {
Joe Onorato55bf3802011-01-25 13:42:10 -0800301 // also allows calls from window manager which is in this process.
Joe Onoratof63b0f42010-09-12 17:03:19 -0400302 enforceStatusBarService();
303
304 synchronized (mLock) {
Joe Onorato664644d2011-01-23 17:53:23 -0800305 final boolean lightsOn = (vis & View.STATUS_BAR_HIDDEN) == 0;
Joe Onoratof63b0f42010-09-12 17:03:19 -0400306 updateLightsOnLocked(lightsOn);
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800307 disableLocked(vis & StatusBarManager.DISABLE_MASK, mSysUiVisToken,
308 "WindowManager.LayoutParams");
Joe Onoratof63b0f42010-09-12 17:03:19 -0400309 }
310 }
311
312 private void updateLightsOnLocked(final boolean lightsOn) {
313 if (mLightsOn != lightsOn) {
314 mLightsOn = lightsOn;
315 mHandler.post(new Runnable() {
316 public void run() {
317 if (mBar != null) {
318 try {
319 mBar.setLightsOn(lightsOn);
320 } catch (RemoteException ex) {
Joe Onorato93056472010-09-10 10:30:46 -0400321 }
322 }
Joe Onoratof63b0f42010-09-12 17:03:19 -0400323 }
324 });
Joe Onorato93056472010-09-10 10:30:46 -0400325 }
326 }
327
Jeff Brown2992ea72011-01-28 22:04:14 -0800328 public void setHardKeyboardEnabled(final boolean enabled) {
329 mHandler.post(new Runnable() {
330 public void run() {
331 mWindowManager.setHardKeyboardEnabled(enabled);
332 }
333 });
334 }
335
336 @Override
337 public void onHardKeyboardStatusChange(final boolean available, final boolean enabled) {
338 mHandler.post(new Runnable() {
339 public void run() {
340 if (mBar != null) {
341 try {
342 mBar.setHardKeyboardStatus(available, enabled);
343 } catch (RemoteException ex) {
344 }
345 }
346 }
347 });
348 }
349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800350 private void enforceStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700351 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700352 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800353 }
354
355 private void enforceExpandStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700356 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.EXPAND_STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700357 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800358 }
359
Joe Onorato8bc6c512010-06-04 16:21:12 -0400360 private void enforceStatusBarService() {
361 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
362 "StatusBarManagerService");
363 }
364
Joe Onorato4762c2d2010-05-17 15:42:59 -0700365 // ================================================================================
366 // Callbacks from the status bar service.
367 // ================================================================================
Joe Onorato75199e32010-05-29 17:22:51 -0400368 public void registerStatusBar(IStatusBar bar, StatusBarIconList iconList,
Joe Onorato93056472010-09-10 10:30:46 -0400369 List<IBinder> notificationKeys, List<StatusBarNotification> notifications,
satokcd7cd292010-11-20 15:46:23 +0900370 int switches[], List<IBinder> binders) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400371 enforceStatusBarService();
372
Joe Onorato0cbda992010-05-02 16:28:15 -0700373 Slog.i(TAG, "registerStatusBar bar=" + bar);
374 mBar = bar;
Joe Onorato75199e32010-05-29 17:22:51 -0400375 synchronized (mIcons) {
376 iconList.copyFrom(mIcons);
377 }
378 synchronized (mNotifications) {
379 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
380 notificationKeys.add(e.getKey());
381 notifications.add(e.getValue());
382 }
383 }
Joe Onorato93056472010-09-10 10:30:46 -0400384 synchronized (mLock) {
Joe Onoratoe4c7b3f2010-10-30 12:15:03 -0700385 switches[0] = gatherDisableActionsLocked();
386 switches[1] = mLightsOn ? 1 : 0;
387 switches[2] = mMenuVisible ? 1 : 0;
Joe Onorato857fd9b2011-01-27 15:08:35 -0800388 switches[3] = mImeWindowVis;
389 switches[4] = mImeBackDisposition;
390 binders.add(mImeToken);
Joe Onorato93056472010-09-10 10:30:46 -0400391 }
Jeff Brown2992ea72011-01-28 22:04:14 -0800392 switches[5] = mWindowManager.isHardKeyboardAvailable() ? 1 : 0;
393 switches[6] = mWindowManager.isHardKeyboardEnabled() ? 1 : 0;
Joe Onorato2314aab2010-04-08 16:41:23 -0500394 }
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400395
Joe Onorato4762c2d2010-05-17 15:42:59 -0700396 /**
Joe Onoratof1f25912010-06-07 11:52:41 -0700397 * The status bar service should call this each time the user brings the panel from
398 * invisible to visible in order to clear the notification light.
Joe Onorato4762c2d2010-05-17 15:42:59 -0700399 */
Joe Onoratof1f25912010-06-07 11:52:41 -0700400 public void onPanelRevealed() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400401 enforceStatusBarService();
402
Joe Onoratof1f25912010-06-07 11:52:41 -0700403 // tell the notification manager to turn off the lights.
404 mNotificationCallbacks.onPanelRevealed();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700405 }
406
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400407 public void onNotificationClick(String pkg, String tag, int id) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400408 enforceStatusBarService();
409
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400410 mNotificationCallbacks.onNotificationClick(pkg, tag, id);
411 }
412
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700413 public void onNotificationError(String pkg, String tag, int id,
414 int uid, int initialPid, String message) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400415 enforceStatusBarService();
416
Joe Onorato005847b2010-06-04 16:08:02 -0400417 // WARNING: this will call back into us to do the remove. Don't hold any locks.
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700418 mNotificationCallbacks.onNotificationError(pkg, tag, id, uid, initialPid, message);
Joe Onorato005847b2010-06-04 16:08:02 -0400419 }
420
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400421 public void onNotificationClear(String pkg, String tag, int id) {
422 enforceStatusBarService();
423
424 mNotificationCallbacks.onNotificationClear(pkg, tag, id);
425 }
426
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400427 public void onClearAllNotifications() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400428 enforceStatusBarService();
429
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400430 mNotificationCallbacks.onClearAll();
431 }
432
Joe Onorato18e69df2010-05-17 22:26:12 -0700433 // ================================================================================
434 // Callbacks for NotificationManagerService.
435 // ================================================================================
436 public IBinder addNotification(StatusBarNotification notification) {
437 synchronized (mNotifications) {
Joe Onoratoa0c56fe2010-05-20 10:21:52 -0700438 IBinder key = new Binder();
Joe Onorato75199e32010-05-29 17:22:51 -0400439 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400440 if (mBar != null) {
441 try {
442 mBar.addNotification(key, notification);
443 } catch (RemoteException ex) {
444 }
445 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700446 return key;
447 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700448 }
449
Joe Onorato18e69df2010-05-17 22:26:12 -0700450 public void updateNotification(IBinder key, StatusBarNotification notification) {
451 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400452 if (!mNotifications.containsKey(key)) {
453 throw new IllegalArgumentException("updateNotification key not found: " + key);
454 }
455 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400456 if (mBar != null) {
457 try {
458 mBar.updateNotification(key, notification);
459 } catch (RemoteException ex) {
460 }
461 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700462 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700463 }
464
465 public void removeNotification(IBinder key) {
Joe Onorato18e69df2010-05-17 22:26:12 -0700466 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400467 final StatusBarNotification n = mNotifications.remove(key);
468 if (n == null) {
469 throw new IllegalArgumentException("removeNotification key not found: " + key);
470 }
Joe Onoratoe345fff2010-05-23 15:18:27 -0400471 if (mBar != null) {
472 try {
473 mBar.removeNotification(key);
474 } catch (RemoteException ex) {
475 }
476 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700477 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700478 }
Joe Onorato2314aab2010-04-08 16:41:23 -0500479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800480 // ================================================================================
481 // Can be called from any thread
482 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800484 // lock on mDisableRecords
485 void manageDisableListLocked(int what, IBinder token, String pkg) {
486 if (SPEW) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700487 Slog.d(TAG, "manageDisableList what=0x" + Integer.toHexString(what) + " pkg=" + pkg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800488 }
489 // update the list
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800490 final int N = mDisableRecords.size();
491 DisableRecord tok = null;
492 int i;
493 for (i=0; i<N; i++) {
494 DisableRecord t = mDisableRecords.get(i);
495 if (t.token == token) {
496 tok = t;
497 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800499 }
500 if (what == 0 || !token.isBinderAlive()) {
501 if (tok != null) {
502 mDisableRecords.remove(i);
503 tok.token.unlinkToDeath(tok, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800505 } else {
506 if (tok == null) {
507 tok = new DisableRecord();
508 try {
509 token.linkToDeath(tok, 0);
510 }
511 catch (RemoteException ex) {
512 return; // give up
513 }
514 mDisableRecords.add(tok);
515 }
516 tok.what = what;
517 tok.token = token;
518 tok.pkg = pkg;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800519 }
520 }
521
522 // lock on mDisableRecords
523 int gatherDisableActionsLocked() {
524 final int N = mDisableRecords.size();
525 // gather the new net flags
526 int net = 0;
527 for (int i=0; i<N; i++) {
528 net |= mDisableRecords.get(i).what;
529 }
530 return net;
531 }
532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800533 // ================================================================================
534 // Always called from UI thread
535 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800537 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
538 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
539 != PackageManager.PERMISSION_GRANTED) {
540 pw.println("Permission Denial: can't dump StatusBar from from pid="
541 + Binder.getCallingPid()
542 + ", uid=" + Binder.getCallingUid());
543 return;
544 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700545
Joe Onorato0cbda992010-05-02 16:28:15 -0700546 synchronized (mIcons) {
547 mIcons.dump(pw);
548 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700549
550 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400551 int i=0;
552 pw.println("Notification list:");
553 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
554 pw.printf(" %2d: %s\n", i, e.getValue().toString());
555 i++;
556 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800557 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700558
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800559 synchronized (mLock) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800560 final int N = mDisableRecords.size();
561 pw.println(" mDisableRecords.size=" + N
562 + " mDisabled=0x" + Integer.toHexString(mDisabled));
563 for (int i=0; i<N; i++) {
564 DisableRecord tok = mDisableRecords.get(i);
565 pw.println(" [" + i + "] what=0x" + Integer.toHexString(tok.what)
566 + " pkg=" + tok.pkg + " token=" + tok.token);
567 }
568 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569 }
570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800571 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
572 public void onReceive(Context context, Intent intent) {
573 String action = intent.getAction();
Joe Onoratof9e0e6b2009-09-08 16:24:36 -0400574 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
575 || Intent.ACTION_SCREEN_OFF.equals(action)) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700576 collapse();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800577 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700578 /*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579 else if (Telephony.Intents.SPN_STRINGS_UPDATED_ACTION.equals(action)) {
580 updateNetworkName(intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_SPN, false),
581 intent.getStringExtra(Telephony.Intents.EXTRA_SPN),
582 intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_PLMN, false),
583 intent.getStringExtra(Telephony.Intents.EXTRA_PLMN));
584 }
585 else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
586 updateResources();
587 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700588 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800589 }
590 };
591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800592}