blob: 286a9376981dbaf17d0e0bfbcf66c4e3e3c5f5a7 [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 // ================================================================================
Daniel Sandler1d4d30a2011-04-28 12:35:29 -0400120 public void userActivity() {
121 if (mBar != null) try {
122 mBar.userActivity();
123 } catch (RemoteException ex) {}
124 }
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 */
Dianne Hackborn7d049322011-06-14 15:00:32 -0700251 public void topAppWindowChanged(final boolean menuVisible) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400252 enforceStatusBar();
253
Dianne Hackborn7d049322011-06-14 15:00:32 -0700254 if (SPEW) Slog.d(TAG, (menuVisible?"showing":"hiding") + " MENU key");
Daniel Sandlere02d8082010-10-08 15:13:22 -0400255
256 synchronized(mLock) {
Dianne Hackborn7d049322011-06-14 15:00:32 -0700257 mMenuVisible = menuVisible;
258 mHandler.post(new Runnable() {
259 public void run() {
260 if (mBar != null) {
261 try {
262 mBar.topAppWindowChanged(menuVisible);
263 } catch (RemoteException ex) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400264 }
265 }
Dianne Hackborn7d049322011-06-14 15:00:32 -0700266 }
267 });
Daniel Sandlere02d8082010-10-08 15:13:22 -0400268 }
269 }
270
Joe Onorato857fd9b2011-01-27 15:08:35 -0800271 public void setImeWindowStatus(final IBinder token, final int vis, final int backDisposition) {
satok06487a52010-10-29 11:37:18 +0900272 enforceStatusBar();
273
Joe Onorato857fd9b2011-01-27 15:08:35 -0800274 if (SPEW) {
275 Slog.d(TAG, "swetImeWindowStatus vis=" + vis + " backDisposition=" + backDisposition);
276 }
satok06487a52010-10-29 11:37:18 +0900277
278 synchronized(mLock) {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800279 // In case of IME change, we need to call up setImeWindowStatus() regardless of
280 // mImeWindowVis because mImeWindowVis may not have been set to false when the
satok06e07442010-11-02 19:46:55 +0900281 // previous IME was destroyed.
Joe Onorato857fd9b2011-01-27 15:08:35 -0800282 mImeWindowVis = vis;
283 mImeBackDisposition = backDisposition;
284 mImeToken = token;
satok06e07442010-11-02 19:46:55 +0900285 mHandler.post(new Runnable() {
286 public void run() {
287 if (mBar != null) {
288 try {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800289 mBar.setImeWindowStatus(token, vis, backDisposition);
satok06e07442010-11-02 19:46:55 +0900290 } catch (RemoteException ex) {
satok06487a52010-10-29 11:37:18 +0900291 }
292 }
satok06e07442010-11-02 19:46:55 +0900293 }
294 });
satok06487a52010-10-29 11:37:18 +0900295 }
296 }
297
Joe Onorato664644d2011-01-23 17:53:23 -0800298 public void setSystemUiVisibility(int vis) {
Joe Onorato55bf3802011-01-25 13:42:10 -0800299 // also allows calls from window manager which is in this process.
Joe Onoratof63b0f42010-09-12 17:03:19 -0400300 enforceStatusBarService();
301
302 synchronized (mLock) {
Joe Onorato664644d2011-01-23 17:53:23 -0800303 final boolean lightsOn = (vis & View.STATUS_BAR_HIDDEN) == 0;
Joe Onoratof63b0f42010-09-12 17:03:19 -0400304 updateLightsOnLocked(lightsOn);
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800305 disableLocked(vis & StatusBarManager.DISABLE_MASK, mSysUiVisToken,
306 "WindowManager.LayoutParams");
Joe Onoratof63b0f42010-09-12 17:03:19 -0400307 }
308 }
309
310 private void updateLightsOnLocked(final boolean lightsOn) {
311 if (mLightsOn != lightsOn) {
312 mLightsOn = lightsOn;
313 mHandler.post(new Runnable() {
314 public void run() {
315 if (mBar != null) {
316 try {
317 mBar.setLightsOn(lightsOn);
318 } catch (RemoteException ex) {
Joe Onorato93056472010-09-10 10:30:46 -0400319 }
320 }
Joe Onoratof63b0f42010-09-12 17:03:19 -0400321 }
322 });
Joe Onorato93056472010-09-10 10:30:46 -0400323 }
324 }
325
Jeff Brown2992ea72011-01-28 22:04:14 -0800326 public void setHardKeyboardEnabled(final boolean enabled) {
327 mHandler.post(new Runnable() {
328 public void run() {
329 mWindowManager.setHardKeyboardEnabled(enabled);
330 }
331 });
332 }
333
334 @Override
335 public void onHardKeyboardStatusChange(final boolean available, final boolean enabled) {
336 mHandler.post(new Runnable() {
337 public void run() {
338 if (mBar != null) {
339 try {
340 mBar.setHardKeyboardStatus(available, enabled);
341 } catch (RemoteException ex) {
342 }
343 }
344 }
345 });
346 }
347
Michael Jurka3b1fc472011-06-13 10:54:40 -0700348 @Override
349 public void toggleRecentApps() {
350 if (mBar != null) {
351 try {
352 mBar.toggleRecentApps();
353 } catch (RemoteException ex) {}
354 }
355 }
356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357 private void enforceStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700358 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700359 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800360 }
361
362 private void enforceExpandStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700363 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.EXPAND_STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700364 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800365 }
366
Joe Onorato8bc6c512010-06-04 16:21:12 -0400367 private void enforceStatusBarService() {
368 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
369 "StatusBarManagerService");
370 }
371
Joe Onorato4762c2d2010-05-17 15:42:59 -0700372 // ================================================================================
373 // Callbacks from the status bar service.
374 // ================================================================================
Joe Onorato75199e32010-05-29 17:22:51 -0400375 public void registerStatusBar(IStatusBar bar, StatusBarIconList iconList,
Joe Onorato93056472010-09-10 10:30:46 -0400376 List<IBinder> notificationKeys, List<StatusBarNotification> notifications,
satokcd7cd292010-11-20 15:46:23 +0900377 int switches[], List<IBinder> binders) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400378 enforceStatusBarService();
379
Joe Onorato0cbda992010-05-02 16:28:15 -0700380 Slog.i(TAG, "registerStatusBar bar=" + bar);
381 mBar = bar;
Joe Onorato75199e32010-05-29 17:22:51 -0400382 synchronized (mIcons) {
383 iconList.copyFrom(mIcons);
384 }
385 synchronized (mNotifications) {
386 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
387 notificationKeys.add(e.getKey());
388 notifications.add(e.getValue());
389 }
390 }
Joe Onorato93056472010-09-10 10:30:46 -0400391 synchronized (mLock) {
Joe Onoratoe4c7b3f2010-10-30 12:15:03 -0700392 switches[0] = gatherDisableActionsLocked();
393 switches[1] = mLightsOn ? 1 : 0;
394 switches[2] = mMenuVisible ? 1 : 0;
Joe Onorato857fd9b2011-01-27 15:08:35 -0800395 switches[3] = mImeWindowVis;
396 switches[4] = mImeBackDisposition;
397 binders.add(mImeToken);
Joe Onorato93056472010-09-10 10:30:46 -0400398 }
Jeff Brown2992ea72011-01-28 22:04:14 -0800399 switches[5] = mWindowManager.isHardKeyboardAvailable() ? 1 : 0;
400 switches[6] = mWindowManager.isHardKeyboardEnabled() ? 1 : 0;
Joe Onorato2314aab2010-04-08 16:41:23 -0500401 }
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400402
Joe Onorato4762c2d2010-05-17 15:42:59 -0700403 /**
Joe Onoratof1f25912010-06-07 11:52:41 -0700404 * The status bar service should call this each time the user brings the panel from
405 * invisible to visible in order to clear the notification light.
Joe Onorato4762c2d2010-05-17 15:42:59 -0700406 */
Joe Onoratof1f25912010-06-07 11:52:41 -0700407 public void onPanelRevealed() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400408 enforceStatusBarService();
409
Joe Onoratof1f25912010-06-07 11:52:41 -0700410 // tell the notification manager to turn off the lights.
411 mNotificationCallbacks.onPanelRevealed();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700412 }
413
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400414 public void onNotificationClick(String pkg, String tag, int id) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400415 enforceStatusBarService();
416
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400417 mNotificationCallbacks.onNotificationClick(pkg, tag, id);
418 }
419
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700420 public void onNotificationError(String pkg, String tag, int id,
421 int uid, int initialPid, String message) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400422 enforceStatusBarService();
423
Joe Onorato005847b2010-06-04 16:08:02 -0400424 // WARNING: this will call back into us to do the remove. Don't hold any locks.
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700425 mNotificationCallbacks.onNotificationError(pkg, tag, id, uid, initialPid, message);
Joe Onorato005847b2010-06-04 16:08:02 -0400426 }
427
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400428 public void onNotificationClear(String pkg, String tag, int id) {
429 enforceStatusBarService();
430
431 mNotificationCallbacks.onNotificationClear(pkg, tag, id);
432 }
433
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400434 public void onClearAllNotifications() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400435 enforceStatusBarService();
436
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400437 mNotificationCallbacks.onClearAll();
438 }
439
Joe Onorato18e69df2010-05-17 22:26:12 -0700440 // ================================================================================
441 // Callbacks for NotificationManagerService.
442 // ================================================================================
443 public IBinder addNotification(StatusBarNotification notification) {
444 synchronized (mNotifications) {
Joe Onoratoa0c56fe2010-05-20 10:21:52 -0700445 IBinder key = new Binder();
Joe Onorato75199e32010-05-29 17:22:51 -0400446 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400447 if (mBar != null) {
448 try {
449 mBar.addNotification(key, notification);
450 } catch (RemoteException ex) {
451 }
452 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700453 return key;
454 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700455 }
456
Joe Onorato18e69df2010-05-17 22:26:12 -0700457 public void updateNotification(IBinder key, StatusBarNotification notification) {
458 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400459 if (!mNotifications.containsKey(key)) {
460 throw new IllegalArgumentException("updateNotification key not found: " + key);
461 }
462 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400463 if (mBar != null) {
464 try {
465 mBar.updateNotification(key, notification);
466 } catch (RemoteException ex) {
467 }
468 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700469 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700470 }
471
472 public void removeNotification(IBinder key) {
Joe Onorato18e69df2010-05-17 22:26:12 -0700473 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400474 final StatusBarNotification n = mNotifications.remove(key);
475 if (n == null) {
476 throw new IllegalArgumentException("removeNotification key not found: " + key);
477 }
Joe Onoratoe345fff2010-05-23 15:18:27 -0400478 if (mBar != null) {
479 try {
480 mBar.removeNotification(key);
481 } catch (RemoteException ex) {
482 }
483 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700484 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700485 }
Joe Onorato2314aab2010-04-08 16:41:23 -0500486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800487 // ================================================================================
488 // Can be called from any thread
489 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800491 // lock on mDisableRecords
492 void manageDisableListLocked(int what, IBinder token, String pkg) {
493 if (SPEW) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700494 Slog.d(TAG, "manageDisableList what=0x" + Integer.toHexString(what) + " pkg=" + pkg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 }
496 // update the list
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800497 final int N = mDisableRecords.size();
498 DisableRecord tok = null;
499 int i;
500 for (i=0; i<N; i++) {
501 DisableRecord t = mDisableRecords.get(i);
502 if (t.token == token) {
503 tok = t;
504 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800505 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800506 }
507 if (what == 0 || !token.isBinderAlive()) {
508 if (tok != null) {
509 mDisableRecords.remove(i);
510 tok.token.unlinkToDeath(tok, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800512 } else {
513 if (tok == null) {
514 tok = new DisableRecord();
515 try {
516 token.linkToDeath(tok, 0);
517 }
518 catch (RemoteException ex) {
519 return; // give up
520 }
521 mDisableRecords.add(tok);
522 }
523 tok.what = what;
524 tok.token = token;
525 tok.pkg = pkg;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800526 }
527 }
528
529 // lock on mDisableRecords
530 int gatherDisableActionsLocked() {
531 final int N = mDisableRecords.size();
532 // gather the new net flags
533 int net = 0;
534 for (int i=0; i<N; i++) {
535 net |= mDisableRecords.get(i).what;
536 }
537 return net;
538 }
539
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540 // ================================================================================
541 // Always called from UI thread
542 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
545 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
546 != PackageManager.PERMISSION_GRANTED) {
547 pw.println("Permission Denial: can't dump StatusBar from from pid="
548 + Binder.getCallingPid()
549 + ", uid=" + Binder.getCallingUid());
550 return;
551 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700552
Joe Onorato0cbda992010-05-02 16:28:15 -0700553 synchronized (mIcons) {
554 mIcons.dump(pw);
555 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700556
557 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400558 int i=0;
559 pw.println("Notification list:");
560 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
561 pw.printf(" %2d: %s\n", i, e.getValue().toString());
562 i++;
563 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700565
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800566 synchronized (mLock) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567 final int N = mDisableRecords.size();
568 pw.println(" mDisableRecords.size=" + N
569 + " mDisabled=0x" + Integer.toHexString(mDisabled));
570 for (int i=0; i<N; i++) {
571 DisableRecord tok = mDisableRecords.get(i);
572 pw.println(" [" + i + "] what=0x" + Integer.toHexString(tok.what)
573 + " pkg=" + tok.pkg + " token=" + tok.token);
574 }
575 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 }
577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
579 public void onReceive(Context context, Intent intent) {
580 String action = intent.getAction();
Joe Onoratof9e0e6b2009-09-08 16:24:36 -0400581 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
582 || Intent.ACTION_SCREEN_OFF.equals(action)) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700583 collapse();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700585 /*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586 else if (Telephony.Intents.SPN_STRINGS_UPDATED_ACTION.equals(action)) {
587 updateNetworkName(intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_SPN, false),
588 intent.getStringExtra(Telephony.Intents.EXTRA_SPN),
589 intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_PLMN, false),
590 intent.getStringExtra(Telephony.Intents.EXTRA_PLMN));
591 }
592 else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
593 updateResources();
594 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700595 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596 }
597 };
598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800599}