blob: b1bce50bac97a0770194ef220efb1e423c0901df [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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800348 private void enforceStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700349 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700350 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800351 }
352
353 private void enforceExpandStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700354 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.EXPAND_STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700355 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356 }
357
Joe Onorato8bc6c512010-06-04 16:21:12 -0400358 private void enforceStatusBarService() {
359 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
360 "StatusBarManagerService");
361 }
362
Joe Onorato4762c2d2010-05-17 15:42:59 -0700363 // ================================================================================
364 // Callbacks from the status bar service.
365 // ================================================================================
Joe Onorato75199e32010-05-29 17:22:51 -0400366 public void registerStatusBar(IStatusBar bar, StatusBarIconList iconList,
Joe Onorato93056472010-09-10 10:30:46 -0400367 List<IBinder> notificationKeys, List<StatusBarNotification> notifications,
satokcd7cd292010-11-20 15:46:23 +0900368 int switches[], List<IBinder> binders) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400369 enforceStatusBarService();
370
Joe Onorato0cbda992010-05-02 16:28:15 -0700371 Slog.i(TAG, "registerStatusBar bar=" + bar);
372 mBar = bar;
Joe Onorato75199e32010-05-29 17:22:51 -0400373 synchronized (mIcons) {
374 iconList.copyFrom(mIcons);
375 }
376 synchronized (mNotifications) {
377 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
378 notificationKeys.add(e.getKey());
379 notifications.add(e.getValue());
380 }
381 }
Joe Onorato93056472010-09-10 10:30:46 -0400382 synchronized (mLock) {
Joe Onoratoe4c7b3f2010-10-30 12:15:03 -0700383 switches[0] = gatherDisableActionsLocked();
384 switches[1] = mLightsOn ? 1 : 0;
385 switches[2] = mMenuVisible ? 1 : 0;
Joe Onorato857fd9b2011-01-27 15:08:35 -0800386 switches[3] = mImeWindowVis;
387 switches[4] = mImeBackDisposition;
388 binders.add(mImeToken);
Joe Onorato93056472010-09-10 10:30:46 -0400389 }
Jeff Brown2992ea72011-01-28 22:04:14 -0800390 switches[5] = mWindowManager.isHardKeyboardAvailable() ? 1 : 0;
391 switches[6] = mWindowManager.isHardKeyboardEnabled() ? 1 : 0;
Joe Onorato2314aab2010-04-08 16:41:23 -0500392 }
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400393
Joe Onorato4762c2d2010-05-17 15:42:59 -0700394 /**
Joe Onoratof1f25912010-06-07 11:52:41 -0700395 * The status bar service should call this each time the user brings the panel from
396 * invisible to visible in order to clear the notification light.
Joe Onorato4762c2d2010-05-17 15:42:59 -0700397 */
Joe Onoratof1f25912010-06-07 11:52:41 -0700398 public void onPanelRevealed() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400399 enforceStatusBarService();
400
Joe Onoratof1f25912010-06-07 11:52:41 -0700401 // tell the notification manager to turn off the lights.
402 mNotificationCallbacks.onPanelRevealed();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700403 }
404
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400405 public void onNotificationClick(String pkg, String tag, int id) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400406 enforceStatusBarService();
407
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400408 mNotificationCallbacks.onNotificationClick(pkg, tag, id);
409 }
410
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700411 public void onNotificationError(String pkg, String tag, int id,
412 int uid, int initialPid, String message) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400413 enforceStatusBarService();
414
Joe Onorato005847b2010-06-04 16:08:02 -0400415 // WARNING: this will call back into us to do the remove. Don't hold any locks.
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700416 mNotificationCallbacks.onNotificationError(pkg, tag, id, uid, initialPid, message);
Joe Onorato005847b2010-06-04 16:08:02 -0400417 }
418
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400419 public void onNotificationClear(String pkg, String tag, int id) {
420 enforceStatusBarService();
421
422 mNotificationCallbacks.onNotificationClear(pkg, tag, id);
423 }
424
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400425 public void onClearAllNotifications() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400426 enforceStatusBarService();
427
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400428 mNotificationCallbacks.onClearAll();
429 }
430
Joe Onorato18e69df2010-05-17 22:26:12 -0700431 // ================================================================================
432 // Callbacks for NotificationManagerService.
433 // ================================================================================
434 public IBinder addNotification(StatusBarNotification notification) {
435 synchronized (mNotifications) {
Joe Onoratoa0c56fe2010-05-20 10:21:52 -0700436 IBinder key = new Binder();
Joe Onorato75199e32010-05-29 17:22:51 -0400437 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400438 if (mBar != null) {
439 try {
440 mBar.addNotification(key, notification);
441 } catch (RemoteException ex) {
442 }
443 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700444 return key;
445 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700446 }
447
Joe Onorato18e69df2010-05-17 22:26:12 -0700448 public void updateNotification(IBinder key, StatusBarNotification notification) {
449 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400450 if (!mNotifications.containsKey(key)) {
451 throw new IllegalArgumentException("updateNotification key not found: " + key);
452 }
453 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400454 if (mBar != null) {
455 try {
456 mBar.updateNotification(key, notification);
457 } catch (RemoteException ex) {
458 }
459 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700460 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700461 }
462
463 public void removeNotification(IBinder key) {
Joe Onorato18e69df2010-05-17 22:26:12 -0700464 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400465 final StatusBarNotification n = mNotifications.remove(key);
466 if (n == null) {
467 throw new IllegalArgumentException("removeNotification key not found: " + key);
468 }
Joe Onoratoe345fff2010-05-23 15:18:27 -0400469 if (mBar != null) {
470 try {
471 mBar.removeNotification(key);
472 } catch (RemoteException ex) {
473 }
474 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700475 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700476 }
Joe Onorato2314aab2010-04-08 16:41:23 -0500477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800478 // ================================================================================
479 // Can be called from any thread
480 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800482 // lock on mDisableRecords
483 void manageDisableListLocked(int what, IBinder token, String pkg) {
484 if (SPEW) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700485 Slog.d(TAG, "manageDisableList what=0x" + Integer.toHexString(what) + " pkg=" + pkg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486 }
487 // update the list
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800488 final int N = mDisableRecords.size();
489 DisableRecord tok = null;
490 int i;
491 for (i=0; i<N; i++) {
492 DisableRecord t = mDisableRecords.get(i);
493 if (t.token == token) {
494 tok = t;
495 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800497 }
498 if (what == 0 || !token.isBinderAlive()) {
499 if (tok != null) {
500 mDisableRecords.remove(i);
501 tok.token.unlinkToDeath(tok, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800502 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800503 } else {
504 if (tok == null) {
505 tok = new DisableRecord();
506 try {
507 token.linkToDeath(tok, 0);
508 }
509 catch (RemoteException ex) {
510 return; // give up
511 }
512 mDisableRecords.add(tok);
513 }
514 tok.what = what;
515 tok.token = token;
516 tok.pkg = pkg;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 }
518 }
519
520 // lock on mDisableRecords
521 int gatherDisableActionsLocked() {
522 final int N = mDisableRecords.size();
523 // gather the new net flags
524 int net = 0;
525 for (int i=0; i<N; i++) {
526 net |= mDisableRecords.get(i).what;
527 }
528 return net;
529 }
530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800531 // ================================================================================
532 // Always called from UI thread
533 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800535 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
536 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
537 != PackageManager.PERMISSION_GRANTED) {
538 pw.println("Permission Denial: can't dump StatusBar from from pid="
539 + Binder.getCallingPid()
540 + ", uid=" + Binder.getCallingUid());
541 return;
542 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700543
Joe Onorato0cbda992010-05-02 16:28:15 -0700544 synchronized (mIcons) {
545 mIcons.dump(pw);
546 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700547
548 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400549 int i=0;
550 pw.println("Notification list:");
551 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
552 pw.printf(" %2d: %s\n", i, e.getValue().toString());
553 i++;
554 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800555 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700556
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800557 synchronized (mLock) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558 final int N = mDisableRecords.size();
559 pw.println(" mDisableRecords.size=" + N
560 + " mDisabled=0x" + Integer.toHexString(mDisabled));
561 for (int i=0; i<N; i++) {
562 DisableRecord tok = mDisableRecords.get(i);
563 pw.println(" [" + i + "] what=0x" + Integer.toHexString(tok.what)
564 + " pkg=" + tok.pkg + " token=" + tok.token);
565 }
566 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567 }
568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
570 public void onReceive(Context context, Intent intent) {
571 String action = intent.getAction();
Joe Onoratof9e0e6b2009-09-08 16:24:36 -0400572 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
573 || Intent.ACTION_SCREEN_OFF.equals(action)) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700574 collapse();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700576 /*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800577 else if (Telephony.Intents.SPN_STRINGS_UPDATED_ACTION.equals(action)) {
578 updateNetworkName(intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_SPN, false),
579 intent.getStringExtra(Telephony.Intents.EXTRA_SPN),
580 intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_PLMN, false),
581 intent.getStringExtra(Telephony.Intents.EXTRA_PLMN));
582 }
583 else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
584 updateResources();
585 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700586 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587 }
588 };
589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590}