blob: 568a5e3b6c6af9585f15faf9617f9896a788c6a5 [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.StatusBarManager;
20import android.content.BroadcastReceiver;
21import android.content.Context;
22import android.content.Intent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.content.pm.PackageManager;
24import android.content.res.Resources;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.os.IBinder;
26import android.os.RemoteException;
27import android.os.Binder;
Joe Onoratof3f0e052010-05-14 18:49:29 -070028import android.os.Handler;
Joe Onorato8a9b2202010-02-26 18:56:32 -080029import android.util.Slog;
Joe Onorato664644d2011-01-23 17:53:23 -080030import android.view.View;
Joe Onorato0cbda992010-05-02 16:28:15 -070031
32import com.android.internal.statusbar.IStatusBar;
33import com.android.internal.statusbar.IStatusBarService;
34import com.android.internal.statusbar.StatusBarIcon;
35import com.android.internal.statusbar.StatusBarIconList;
Joe Onorato18e69df2010-05-17 22:26:12 -070036import com.android.internal.statusbar.StatusBarNotification;
Dianne Hackborna924dc0d2011-02-17 14:22:17 -080037import com.android.server.wm.WindowManagerService;
The Android Open Source Project10592532009-03-18 17:39:46 -070038
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import java.io.FileDescriptor;
40import java.io.PrintWriter;
41import java.util.ArrayList;
42import java.util.HashMap;
Joe Onorato75199e32010-05-29 17:22:51 -040043import java.util.List;
44import java.util.Map;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045
46
47/**
Joe Onoratof3f0e052010-05-14 18:49:29 -070048 * A note on locking: We rely on the fact that calls onto mBar are oneway or
49 * if they are local, that they just enqueue messages to not deadlock.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050 */
Joe Onorato089de882010-04-12 08:18:45 -070051public class StatusBarManagerService extends IStatusBarService.Stub
Jeff Brown2992ea72011-01-28 22:04:14 -080052 implements WindowManagerService.OnHardKeyboardStatusChangeListener
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053{
Joe Onorato4762c2d2010-05-17 15:42:59 -070054 static final String TAG = "StatusBarManagerService";
Joe Onorato431bb222010-10-18 19:13:23 -040055 static final boolean SPEW = false;
Joe Onoratodf7dbb62009-11-17 10:43:37 -080056
Joe Onoratof3f0e052010-05-14 18:49:29 -070057 final Context mContext;
Jeff Brown2992ea72011-01-28 22:04:14 -080058 final WindowManagerService mWindowManager;
Joe Onoratof3f0e052010-05-14 18:49:29 -070059 Handler mHandler = new Handler();
60 NotificationCallbacks mNotificationCallbacks;
Joe Onorato4762c2d2010-05-17 15:42:59 -070061 volatile IStatusBar mBar;
Joe Onoratof3f0e052010-05-14 18:49:29 -070062 StatusBarIconList mIcons = new StatusBarIconList();
Joe Onorato75199e32010-05-29 17:22:51 -040063 HashMap<IBinder,StatusBarNotification> mNotifications
64 = new HashMap<IBinder,StatusBarNotification>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065
Joe Onoratof3f0e052010-05-14 18:49:29 -070066 // for disabling the status bar
67 ArrayList<DisableRecord> mDisableRecords = new ArrayList<DisableRecord>();
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080068 IBinder mSysUiVisToken = new Binder();
Joe Onoratof3f0e052010-05-14 18:49:29 -070069 int mDisabled = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070
Joe Onorato93056472010-09-10 10:30:46 -040071 Object mLock = new Object();
72 // We usually call it lights out mode, but double negatives are annoying
73 boolean mLightsOn = true;
Daniel Sandlere02d8082010-10-08 15:13:22 -040074 boolean mMenuVisible = false;
Joe Onorato857fd9b2011-01-27 15:08:35 -080075 int mImeWindowVis = 0;
76 int mImeBackDisposition;
77 IBinder mImeToken = null;
satok06487a52010-10-29 11:37:18 +090078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080079 private class DisableRecord implements IBinder.DeathRecipient {
80 String pkg;
81 int what;
82 IBinder token;
83
84 public void binderDied() {
Joe Onorato8a9b2202010-02-26 18:56:32 -080085 Slog.i(TAG, "binder died for pkg=" + pkg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 disable(0, token, pkg);
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -070087 token.unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088 }
89 }
90
91 public interface NotificationCallbacks {
92 void onSetDisabled(int status);
93 void onClearAll();
Fred Quintana6ecaff12009-09-25 14:23:13 -070094 void onNotificationClick(String pkg, String tag, int id);
Daniel Sandler0f0b11c2010-08-04 15:54:58 -040095 void onNotificationClear(String pkg, String tag, int id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 void onPanelRevealed();
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -070097 void onNotificationError(String pkg, String tag, int id,
98 int uid, int initialPid, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 }
100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101 /**
102 * Construct the service, add the status bar view to the window manager
103 */
Jeff Brown2992ea72011-01-28 22:04:14 -0800104 public StatusBarManagerService(Context context, WindowManagerService windowManager) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 mContext = context;
Jeff Brown2992ea72011-01-28 22:04:14 -0800106 mWindowManager = windowManager;
107 mWindowManager.setOnHardKeyboardStatusChangeListener(this);
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 */
Dianne Hackborn7d049322011-06-14 15:00:32 -0700246 public void topAppWindowChanged(final boolean menuVisible) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400247 enforceStatusBar();
248
Dianne Hackborn7d049322011-06-14 15:00:32 -0700249 if (SPEW) Slog.d(TAG, (menuVisible?"showing":"hiding") + " MENU key");
Daniel Sandlere02d8082010-10-08 15:13:22 -0400250
251 synchronized(mLock) {
Dianne Hackborn7d049322011-06-14 15:00:32 -0700252 mMenuVisible = menuVisible;
253 mHandler.post(new Runnable() {
254 public void run() {
255 if (mBar != null) {
256 try {
257 mBar.topAppWindowChanged(menuVisible);
258 } catch (RemoteException ex) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400259 }
260 }
Dianne Hackborn7d049322011-06-14 15:00:32 -0700261 }
262 });
Daniel Sandlere02d8082010-10-08 15:13:22 -0400263 }
264 }
265
Joe Onorato857fd9b2011-01-27 15:08:35 -0800266 public void setImeWindowStatus(final IBinder token, final int vis, final int backDisposition) {
satok06487a52010-10-29 11:37:18 +0900267 enforceStatusBar();
268
Joe Onorato857fd9b2011-01-27 15:08:35 -0800269 if (SPEW) {
270 Slog.d(TAG, "swetImeWindowStatus vis=" + vis + " backDisposition=" + backDisposition);
271 }
satok06487a52010-10-29 11:37:18 +0900272
273 synchronized(mLock) {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800274 // In case of IME change, we need to call up setImeWindowStatus() regardless of
275 // mImeWindowVis because mImeWindowVis may not have been set to false when the
satok06e07442010-11-02 19:46:55 +0900276 // previous IME was destroyed.
Joe Onorato857fd9b2011-01-27 15:08:35 -0800277 mImeWindowVis = vis;
278 mImeBackDisposition = backDisposition;
279 mImeToken = token;
satok06e07442010-11-02 19:46:55 +0900280 mHandler.post(new Runnable() {
281 public void run() {
282 if (mBar != null) {
283 try {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800284 mBar.setImeWindowStatus(token, vis, backDisposition);
satok06e07442010-11-02 19:46:55 +0900285 } catch (RemoteException ex) {
satok06487a52010-10-29 11:37:18 +0900286 }
287 }
satok06e07442010-11-02 19:46:55 +0900288 }
289 });
satok06487a52010-10-29 11:37:18 +0900290 }
291 }
292
Joe Onorato664644d2011-01-23 17:53:23 -0800293 public void setSystemUiVisibility(int vis) {
Joe Onorato55bf3802011-01-25 13:42:10 -0800294 // also allows calls from window manager which is in this process.
Joe Onoratof63b0f42010-09-12 17:03:19 -0400295 enforceStatusBarService();
296
297 synchronized (mLock) {
Joe Onorato664644d2011-01-23 17:53:23 -0800298 final boolean lightsOn = (vis & View.STATUS_BAR_HIDDEN) == 0;
Joe Onoratof63b0f42010-09-12 17:03:19 -0400299 updateLightsOnLocked(lightsOn);
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800300 disableLocked(vis & StatusBarManager.DISABLE_MASK, mSysUiVisToken,
301 "WindowManager.LayoutParams");
Joe Onoratof63b0f42010-09-12 17:03:19 -0400302 }
303 }
304
305 private void updateLightsOnLocked(final boolean lightsOn) {
306 if (mLightsOn != lightsOn) {
307 mLightsOn = lightsOn;
308 mHandler.post(new Runnable() {
309 public void run() {
310 if (mBar != null) {
311 try {
312 mBar.setLightsOn(lightsOn);
313 } catch (RemoteException ex) {
Joe Onorato93056472010-09-10 10:30:46 -0400314 }
315 }
Joe Onoratof63b0f42010-09-12 17:03:19 -0400316 }
317 });
Joe Onorato93056472010-09-10 10:30:46 -0400318 }
319 }
320
Jeff Brown2992ea72011-01-28 22:04:14 -0800321 public void setHardKeyboardEnabled(final boolean enabled) {
322 mHandler.post(new Runnable() {
323 public void run() {
324 mWindowManager.setHardKeyboardEnabled(enabled);
325 }
326 });
327 }
328
329 @Override
330 public void onHardKeyboardStatusChange(final boolean available, final boolean enabled) {
331 mHandler.post(new Runnable() {
332 public void run() {
333 if (mBar != null) {
334 try {
335 mBar.setHardKeyboardStatus(available, enabled);
336 } catch (RemoteException ex) {
337 }
338 }
339 }
340 });
341 }
342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800343 private void enforceStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700344 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700345 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346 }
347
348 private void enforceExpandStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700349 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.EXPAND_STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700350 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800351 }
352
Joe Onorato8bc6c512010-06-04 16:21:12 -0400353 private void enforceStatusBarService() {
354 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
355 "StatusBarManagerService");
356 }
357
Joe Onorato4762c2d2010-05-17 15:42:59 -0700358 // ================================================================================
359 // Callbacks from the status bar service.
360 // ================================================================================
Joe Onorato75199e32010-05-29 17:22:51 -0400361 public void registerStatusBar(IStatusBar bar, StatusBarIconList iconList,
Joe Onorato93056472010-09-10 10:30:46 -0400362 List<IBinder> notificationKeys, List<StatusBarNotification> notifications,
satokcd7cd292010-11-20 15:46:23 +0900363 int switches[], List<IBinder> binders) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400364 enforceStatusBarService();
365
Joe Onorato0cbda992010-05-02 16:28:15 -0700366 Slog.i(TAG, "registerStatusBar bar=" + bar);
367 mBar = bar;
Joe Onorato75199e32010-05-29 17:22:51 -0400368 synchronized (mIcons) {
369 iconList.copyFrom(mIcons);
370 }
371 synchronized (mNotifications) {
372 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
373 notificationKeys.add(e.getKey());
374 notifications.add(e.getValue());
375 }
376 }
Joe Onorato93056472010-09-10 10:30:46 -0400377 synchronized (mLock) {
Joe Onoratoe4c7b3f2010-10-30 12:15:03 -0700378 switches[0] = gatherDisableActionsLocked();
379 switches[1] = mLightsOn ? 1 : 0;
380 switches[2] = mMenuVisible ? 1 : 0;
Joe Onorato857fd9b2011-01-27 15:08:35 -0800381 switches[3] = mImeWindowVis;
382 switches[4] = mImeBackDisposition;
383 binders.add(mImeToken);
Joe Onorato93056472010-09-10 10:30:46 -0400384 }
Jeff Brown2992ea72011-01-28 22:04:14 -0800385 switches[5] = mWindowManager.isHardKeyboardAvailable() ? 1 : 0;
386 switches[6] = mWindowManager.isHardKeyboardEnabled() ? 1 : 0;
Joe Onorato2314aab2010-04-08 16:41:23 -0500387 }
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400388
Joe Onorato4762c2d2010-05-17 15:42:59 -0700389 /**
Joe Onoratof1f25912010-06-07 11:52:41 -0700390 * The status bar service should call this each time the user brings the panel from
391 * invisible to visible in order to clear the notification light.
Joe Onorato4762c2d2010-05-17 15:42:59 -0700392 */
Joe Onoratof1f25912010-06-07 11:52:41 -0700393 public void onPanelRevealed() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400394 enforceStatusBarService();
395
Joe Onoratof1f25912010-06-07 11:52:41 -0700396 // tell the notification manager to turn off the lights.
397 mNotificationCallbacks.onPanelRevealed();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700398 }
399
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400400 public void onNotificationClick(String pkg, String tag, int id) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400401 enforceStatusBarService();
402
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400403 mNotificationCallbacks.onNotificationClick(pkg, tag, id);
404 }
405
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700406 public void onNotificationError(String pkg, String tag, int id,
407 int uid, int initialPid, String message) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400408 enforceStatusBarService();
409
Joe Onorato005847b2010-06-04 16:08:02 -0400410 // WARNING: this will call back into us to do the remove. Don't hold any locks.
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700411 mNotificationCallbacks.onNotificationError(pkg, tag, id, uid, initialPid, message);
Joe Onorato005847b2010-06-04 16:08:02 -0400412 }
413
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400414 public void onNotificationClear(String pkg, String tag, int id) {
415 enforceStatusBarService();
416
417 mNotificationCallbacks.onNotificationClear(pkg, tag, id);
418 }
419
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400420 public void onClearAllNotifications() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400421 enforceStatusBarService();
422
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400423 mNotificationCallbacks.onClearAll();
424 }
425
Joe Onorato18e69df2010-05-17 22:26:12 -0700426 // ================================================================================
427 // Callbacks for NotificationManagerService.
428 // ================================================================================
429 public IBinder addNotification(StatusBarNotification notification) {
430 synchronized (mNotifications) {
Joe Onoratoa0c56fe2010-05-20 10:21:52 -0700431 IBinder key = new Binder();
Joe Onorato75199e32010-05-29 17:22:51 -0400432 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400433 if (mBar != null) {
434 try {
435 mBar.addNotification(key, notification);
436 } catch (RemoteException ex) {
437 }
438 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700439 return key;
440 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700441 }
442
Joe Onorato18e69df2010-05-17 22:26:12 -0700443 public void updateNotification(IBinder key, StatusBarNotification notification) {
444 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400445 if (!mNotifications.containsKey(key)) {
446 throw new IllegalArgumentException("updateNotification key not found: " + key);
447 }
448 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400449 if (mBar != null) {
450 try {
451 mBar.updateNotification(key, notification);
452 } catch (RemoteException ex) {
453 }
454 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700455 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700456 }
457
458 public void removeNotification(IBinder key) {
Joe Onorato18e69df2010-05-17 22:26:12 -0700459 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400460 final StatusBarNotification n = mNotifications.remove(key);
461 if (n == null) {
462 throw new IllegalArgumentException("removeNotification key not found: " + key);
463 }
Joe Onoratoe345fff2010-05-23 15:18:27 -0400464 if (mBar != null) {
465 try {
466 mBar.removeNotification(key);
467 } catch (RemoteException ex) {
468 }
469 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700470 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700471 }
Joe Onorato2314aab2010-04-08 16:41:23 -0500472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800473 // ================================================================================
474 // Can be called from any thread
475 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800477 // lock on mDisableRecords
478 void manageDisableListLocked(int what, IBinder token, String pkg) {
479 if (SPEW) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700480 Slog.d(TAG, "manageDisableList what=0x" + Integer.toHexString(what) + " pkg=" + pkg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800481 }
482 // update the list
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800483 final int N = mDisableRecords.size();
484 DisableRecord tok = null;
485 int i;
486 for (i=0; i<N; i++) {
487 DisableRecord t = mDisableRecords.get(i);
488 if (t.token == token) {
489 tok = t;
490 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800491 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800492 }
493 if (what == 0 || !token.isBinderAlive()) {
494 if (tok != null) {
495 mDisableRecords.remove(i);
496 tok.token.unlinkToDeath(tok, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800498 } else {
499 if (tok == null) {
500 tok = new DisableRecord();
501 try {
502 token.linkToDeath(tok, 0);
503 }
504 catch (RemoteException ex) {
505 return; // give up
506 }
507 mDisableRecords.add(tok);
508 }
509 tok.what = what;
510 tok.token = token;
511 tok.pkg = pkg;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800512 }
513 }
514
515 // lock on mDisableRecords
516 int gatherDisableActionsLocked() {
517 final int N = mDisableRecords.size();
518 // gather the new net flags
519 int net = 0;
520 for (int i=0; i<N; i++) {
521 net |= mDisableRecords.get(i).what;
522 }
523 return net;
524 }
525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800526 // ================================================================================
527 // Always called from UI thread
528 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800530 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
531 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
532 != PackageManager.PERMISSION_GRANTED) {
533 pw.println("Permission Denial: can't dump StatusBar from from pid="
534 + Binder.getCallingPid()
535 + ", uid=" + Binder.getCallingUid());
536 return;
537 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700538
Joe Onorato0cbda992010-05-02 16:28:15 -0700539 synchronized (mIcons) {
540 mIcons.dump(pw);
541 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700542
543 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400544 int i=0;
545 pw.println("Notification list:");
546 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
547 pw.printf(" %2d: %s\n", i, e.getValue().toString());
548 i++;
549 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800550 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700551
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800552 synchronized (mLock) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800553 final int N = mDisableRecords.size();
554 pw.println(" mDisableRecords.size=" + N
555 + " mDisabled=0x" + Integer.toHexString(mDisabled));
556 for (int i=0; i<N; i++) {
557 DisableRecord tok = mDisableRecords.get(i);
558 pw.println(" [" + i + "] what=0x" + Integer.toHexString(tok.what)
559 + " pkg=" + tok.pkg + " token=" + tok.token);
560 }
561 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800562 }
563
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
565 public void onReceive(Context context, Intent intent) {
566 String action = intent.getAction();
Joe Onoratof9e0e6b2009-09-08 16:24:36 -0400567 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
568 || Intent.ACTION_SCREEN_OFF.equals(action)) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700569 collapse();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800570 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700571 /*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572 else if (Telephony.Intents.SPN_STRINGS_UPDATED_ACTION.equals(action)) {
573 updateNetworkName(intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_SPN, false),
574 intent.getStringExtra(Telephony.Intents.EXTRA_SPN),
575 intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_PLMN, false),
576 intent.getStringExtra(Telephony.Intents.EXTRA_PLMN));
577 }
578 else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
579 updateResources();
580 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700581 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800582 }
583 };
584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585}