blob: 5ada77bba9a2732846f4b73d3e33ca6075e9ccfa [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Joe Onorato7a0f36b2010-06-07 10:24:36 -070017package com.android.server;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import android.app.PendingIntent;
20import android.app.StatusBarManager;
21import android.content.BroadcastReceiver;
Joe Onorato9e875fc2010-06-07 11:12:11 -070022import android.content.ComponentName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.content.Context;
24import android.content.Intent;
25import android.content.IntentFilter;
26import android.content.pm.PackageManager;
27import android.content.res.Resources;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.net.Uri;
29import android.os.IBinder;
30import android.os.RemoteException;
31import android.os.Binder;
Joe Onoratof3f0e052010-05-14 18:49:29 -070032import android.os.Handler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.os.SystemClock;
Joe Onorato8a9b2202010-02-26 18:56:32 -080034import android.util.Slog;
Joe Onorato664644d2011-01-23 17:53:23 -080035import android.view.View;
Joe Onorato0cbda992010-05-02 16:28:15 -070036
37import com.android.internal.statusbar.IStatusBar;
38import com.android.internal.statusbar.IStatusBarService;
39import com.android.internal.statusbar.StatusBarIcon;
40import com.android.internal.statusbar.StatusBarIconList;
Joe Onorato18e69df2010-05-17 22:26:12 -070041import com.android.internal.statusbar.StatusBarNotification;
The Android Open Source Project10592532009-03-18 17:39:46 -070042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043import java.io.FileDescriptor;
44import java.io.PrintWriter;
45import java.util.ArrayList;
46import java.util.HashMap;
Joe Onorato75199e32010-05-29 17:22:51 -040047import java.util.List;
48import java.util.Map;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049
50
51/**
Joe Onoratof3f0e052010-05-14 18:49:29 -070052 * A note on locking: We rely on the fact that calls onto mBar are oneway or
53 * if they are local, that they just enqueue messages to not deadlock.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054 */
Joe Onorato089de882010-04-12 08:18:45 -070055public class StatusBarManagerService extends IStatusBarService.Stub
Jeff Brown2992ea72011-01-28 22:04:14 -080056 implements WindowManagerService.OnHardKeyboardStatusChangeListener
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057{
Joe Onorato4762c2d2010-05-17 15:42:59 -070058 static final String TAG = "StatusBarManagerService";
Joe Onorato431bb222010-10-18 19:13:23 -040059 static final boolean SPEW = false;
Joe Onoratodf7dbb62009-11-17 10:43:37 -080060
Joe Onoratof3f0e052010-05-14 18:49:29 -070061 final Context mContext;
Jeff Brown2992ea72011-01-28 22:04:14 -080062 final WindowManagerService mWindowManager;
Joe Onoratof3f0e052010-05-14 18:49:29 -070063 Handler mHandler = new Handler();
64 NotificationCallbacks mNotificationCallbacks;
Joe Onorato4762c2d2010-05-17 15:42:59 -070065 volatile IStatusBar mBar;
Joe Onoratof3f0e052010-05-14 18:49:29 -070066 StatusBarIconList mIcons = new StatusBarIconList();
Joe Onorato75199e32010-05-29 17:22:51 -040067 HashMap<IBinder,StatusBarNotification> mNotifications
68 = new HashMap<IBinder,StatusBarNotification>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069
Joe Onoratof3f0e052010-05-14 18:49:29 -070070 // for disabling the status bar
71 ArrayList<DisableRecord> mDisableRecords = new ArrayList<DisableRecord>();
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080072 IBinder mSysUiVisToken = new Binder();
Joe Onoratof3f0e052010-05-14 18:49:29 -070073 int mDisabled = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074
Joe Onorato93056472010-09-10 10:30:46 -040075 Object mLock = new Object();
76 // We usually call it lights out mode, but double negatives are annoying
77 boolean mLightsOn = true;
Daniel Sandlere02d8082010-10-08 15:13:22 -040078 boolean mMenuVisible = false;
Joe Onorato857fd9b2011-01-27 15:08:35 -080079 int mImeWindowVis = 0;
80 int mImeBackDisposition;
81 IBinder mImeToken = null;
satok06487a52010-10-29 11:37:18 +090082
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083 private class DisableRecord implements IBinder.DeathRecipient {
84 String pkg;
85 int what;
86 IBinder token;
87
88 public void binderDied() {
Joe Onorato8a9b2202010-02-26 18:56:32 -080089 Slog.i(TAG, "binder died for pkg=" + pkg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 disable(0, token, pkg);
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -070091 token.unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 }
93 }
94
95 public interface NotificationCallbacks {
96 void onSetDisabled(int status);
97 void onClearAll();
Fred Quintana6ecaff12009-09-25 14:23:13 -070098 void onNotificationClick(String pkg, String tag, int id);
Daniel Sandler0f0b11c2010-08-04 15:54:58 -040099 void onNotificationClear(String pkg, String tag, int id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 void onPanelRevealed();
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700101 void onNotificationError(String pkg, String tag, int id,
102 int uid, int initialPid, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 }
104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 /**
106 * Construct the service, add the status bar view to the window manager
107 */
Jeff Brown2992ea72011-01-28 22:04:14 -0800108 public StatusBarManagerService(Context context, WindowManagerService windowManager) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 mContext = context;
Jeff Brown2992ea72011-01-28 22:04:14 -0800110 mWindowManager = windowManager;
111 mWindowManager.setOnHardKeyboardStatusChangeListener(this);
Joe Onorato0cbda992010-05-02 16:28:15 -0700112
113 final Resources res = context.getResources();
Joe Onorato75144ea2010-06-07 12:36:25 -0700114 mIcons.defineSlots(res.getStringArray(com.android.internal.R.array.config_statusBarIcons));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 }
116
117 public void setNotificationCallbacks(NotificationCallbacks listener) {
118 mNotificationCallbacks = listener;
119 }
120
121 // ================================================================================
Joe Onorato25f95f92010-04-08 18:37:10 -0500122 // From IStatusBarService
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123 // ================================================================================
Joe Onoratof3f0e052010-05-14 18:49:29 -0700124 public void expand() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125 enforceExpandStatusBar();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700126
127 if (mBar != null) {
128 try {
129 mBar.animateExpand();
130 } catch (RemoteException ex) {
131 }
132 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 }
134
Joe Onoratof3f0e052010-05-14 18:49:29 -0700135 public void collapse() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136 enforceExpandStatusBar();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137
Joe Onorato4762c2d2010-05-17 15:42:59 -0700138 if (mBar != null) {
139 try {
140 mBar.animateCollapse();
141 } catch (RemoteException ex) {
142 }
143 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 }
145
146 public void disable(int what, IBinder token, String pkg) {
147 enforceStatusBar();
Joe Onoratof3f0e052010-05-14 18:49:29 -0700148
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800149 synchronized (mLock) {
150 disableLocked(what, token, pkg);
151 }
152 }
153
154 private void disableLocked(int what, IBinder token, String pkg) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700155 // It's important that the the callback and the call to mBar get done
156 // in the same order when multiple threads are calling this function
157 // so they are paired correctly. The messages on the handler will be
158 // handled in the order they were enqueued, but will be outside the lock.
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800159 manageDisableListLocked(what, token, pkg);
160 final int net = gatherDisableActionsLocked();
161 if (net != mDisabled) {
162 mDisabled = net;
163 mHandler.post(new Runnable() {
164 public void run() {
165 mNotificationCallbacks.onSetDisabled(net);
Joe Onoratof3f0e052010-05-14 18:49:29 -0700166 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800167 });
168 if (mBar != null) {
169 try {
170 mBar.disable(net);
171 } catch (RemoteException ex) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700172 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 }
175 }
176
Joe Onorato0cbda992010-05-02 16:28:15 -0700177 public void setIcon(String slot, String iconPackage, int iconId, int iconLevel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700179
180 synchronized (mIcons) {
181 int index = mIcons.getSlotIndex(slot);
182 if (index < 0) {
183 throw new SecurityException("invalid status bar icon slot: " + slot);
184 }
185
186 StatusBarIcon icon = new StatusBarIcon(iconPackage, iconId, iconLevel);
Joe Onorato66d7d012010-05-14 10:05:10 -0700187 //Slog.d(TAG, "setIcon slot=" + slot + " index=" + index + " icon=" + icon);
Joe Onorato0cbda992010-05-02 16:28:15 -0700188 mIcons.setIcon(index, icon);
189
Joe Onorato0cbda992010-05-02 16:28:15 -0700190 if (mBar != null) {
191 try {
192 mBar.setIcon(index, icon);
193 } catch (RemoteException ex) {
194 }
195 }
196 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197 }
198
Joe Onorato0cbda992010-05-02 16:28:15 -0700199 public void setIconVisibility(String slot, boolean visible) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700201
Joe Onorato514ad6632010-05-13 18:49:00 -0700202 synchronized (mIcons) {
203 int index = mIcons.getSlotIndex(slot);
204 if (index < 0) {
205 throw new SecurityException("invalid status bar icon slot: " + slot);
206 }
207
208 StatusBarIcon icon = mIcons.getIcon(index);
209 if (icon == null) {
210 return;
211 }
212
213 if (icon.visible != visible) {
214 icon.visible = visible;
215
Joe Onorato514ad6632010-05-13 18:49:00 -0700216 if (mBar != null) {
217 try {
218 mBar.setIcon(index, icon);
219 } catch (RemoteException ex) {
220 }
221 }
222 }
223 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700224 }
225
226 public void removeIcon(String slot) {
227 enforceStatusBar();
228
229 synchronized (mIcons) {
230 int index = mIcons.getSlotIndex(slot);
231 if (index < 0) {
232 throw new SecurityException("invalid status bar icon slot: " + slot);
233 }
234
235 mIcons.removeIcon(index);
236
Joe Onorato0cbda992010-05-02 16:28:15 -0700237 if (mBar != null) {
238 try {
239 mBar.removeIcon(index);
240 } catch (RemoteException ex) {
241 }
242 }
243 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244 }
245
Daniel Sandlere02d8082010-10-08 15:13:22 -0400246 /**
247 * Hide or show the on-screen Menu key. Only call this from the window manager, typically in
248 * response to a window with FLAG_NEEDS_MENU_KEY set.
249 */
250 public void setMenuKeyVisible(final boolean visible) {
251 enforceStatusBar();
252
253 if (SPEW) Slog.d(TAG, (visible?"showing":"hiding") + " MENU key");
254
255 synchronized(mLock) {
256 if (mMenuVisible != visible) {
257 mMenuVisible = visible;
258 mHandler.post(new Runnable() {
259 public void run() {
260 if (mBar != null) {
261 try {
262 mBar.setMenuKeyVisible(visible);
263 } catch (RemoteException ex) {
264 }
265 }
266 }
267 });
268 }
269 }
270 }
271
Joe Onorato857fd9b2011-01-27 15:08:35 -0800272 public void setImeWindowStatus(final IBinder token, final int vis, final int backDisposition) {
satok06487a52010-10-29 11:37:18 +0900273 enforceStatusBar();
274
Joe Onorato857fd9b2011-01-27 15:08:35 -0800275 if (SPEW) {
276 Slog.d(TAG, "swetImeWindowStatus vis=" + vis + " backDisposition=" + backDisposition);
277 }
satok06487a52010-10-29 11:37:18 +0900278
279 synchronized(mLock) {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800280 // In case of IME change, we need to call up setImeWindowStatus() regardless of
281 // mImeWindowVis because mImeWindowVis may not have been set to false when the
satok06e07442010-11-02 19:46:55 +0900282 // previous IME was destroyed.
Joe Onorato857fd9b2011-01-27 15:08:35 -0800283 mImeWindowVis = vis;
284 mImeBackDisposition = backDisposition;
285 mImeToken = token;
satok06e07442010-11-02 19:46:55 +0900286 mHandler.post(new Runnable() {
287 public void run() {
288 if (mBar != null) {
289 try {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800290 mBar.setImeWindowStatus(token, vis, backDisposition);
satok06e07442010-11-02 19:46:55 +0900291 } catch (RemoteException ex) {
satok06487a52010-10-29 11:37:18 +0900292 }
293 }
satok06e07442010-11-02 19:46:55 +0900294 }
295 });
satok06487a52010-10-29 11:37:18 +0900296 }
297 }
298
Joe Onorato664644d2011-01-23 17:53:23 -0800299 public void setSystemUiVisibility(int vis) {
Joe Onorato55bf3802011-01-25 13:42:10 -0800300 // also allows calls from window manager which is in this process.
Joe Onoratof63b0f42010-09-12 17:03:19 -0400301 enforceStatusBarService();
302
303 synchronized (mLock) {
Joe Onorato664644d2011-01-23 17:53:23 -0800304 final boolean lightsOn = (vis & View.STATUS_BAR_HIDDEN) == 0;
Joe Onoratof63b0f42010-09-12 17:03:19 -0400305 updateLightsOnLocked(lightsOn);
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800306 disableLocked(vis & StatusBarManager.DISABLE_MASK, mSysUiVisToken,
307 "WindowManager.LayoutParams");
Joe Onoratof63b0f42010-09-12 17:03:19 -0400308 }
309 }
310
311 private void updateLightsOnLocked(final boolean lightsOn) {
312 if (mLightsOn != lightsOn) {
313 mLightsOn = lightsOn;
314 mHandler.post(new Runnable() {
315 public void run() {
316 if (mBar != null) {
317 try {
318 mBar.setLightsOn(lightsOn);
319 } catch (RemoteException ex) {
Joe Onorato93056472010-09-10 10:30:46 -0400320 }
321 }
Joe Onoratof63b0f42010-09-12 17:03:19 -0400322 }
323 });
Joe Onorato93056472010-09-10 10:30:46 -0400324 }
325 }
326
Jeff Brown2992ea72011-01-28 22:04:14 -0800327 public void setHardKeyboardEnabled(final boolean enabled) {
328 mHandler.post(new Runnable() {
329 public void run() {
330 mWindowManager.setHardKeyboardEnabled(enabled);
331 }
332 });
333 }
334
335 @Override
336 public void onHardKeyboardStatusChange(final boolean available, final boolean enabled) {
337 mHandler.post(new Runnable() {
338 public void run() {
339 if (mBar != null) {
340 try {
341 mBar.setHardKeyboardStatus(available, enabled);
342 } catch (RemoteException ex) {
343 }
344 }
345 }
346 });
347 }
348
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800349 private void enforceStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700350 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700351 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352 }
353
354 private void enforceExpandStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700355 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.EXPAND_STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700356 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357 }
358
Joe Onorato8bc6c512010-06-04 16:21:12 -0400359 private void enforceStatusBarService() {
360 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
361 "StatusBarManagerService");
362 }
363
Joe Onorato4762c2d2010-05-17 15:42:59 -0700364 // ================================================================================
365 // Callbacks from the status bar service.
366 // ================================================================================
Joe Onorato75199e32010-05-29 17:22:51 -0400367 public void registerStatusBar(IStatusBar bar, StatusBarIconList iconList,
Joe Onorato93056472010-09-10 10:30:46 -0400368 List<IBinder> notificationKeys, List<StatusBarNotification> notifications,
satokcd7cd292010-11-20 15:46:23 +0900369 int switches[], List<IBinder> binders) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400370 enforceStatusBarService();
371
Joe Onorato0cbda992010-05-02 16:28:15 -0700372 Slog.i(TAG, "registerStatusBar bar=" + bar);
373 mBar = bar;
Joe Onorato75199e32010-05-29 17:22:51 -0400374 synchronized (mIcons) {
375 iconList.copyFrom(mIcons);
376 }
377 synchronized (mNotifications) {
378 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
379 notificationKeys.add(e.getKey());
380 notifications.add(e.getValue());
381 }
382 }
Joe Onorato93056472010-09-10 10:30:46 -0400383 synchronized (mLock) {
Joe Onoratoe4c7b3f2010-10-30 12:15:03 -0700384 switches[0] = gatherDisableActionsLocked();
385 switches[1] = mLightsOn ? 1 : 0;
386 switches[2] = mMenuVisible ? 1 : 0;
Joe Onorato857fd9b2011-01-27 15:08:35 -0800387 switches[3] = mImeWindowVis;
388 switches[4] = mImeBackDisposition;
389 binders.add(mImeToken);
Joe Onorato93056472010-09-10 10:30:46 -0400390 }
Jeff Brown2992ea72011-01-28 22:04:14 -0800391 switches[5] = mWindowManager.isHardKeyboardAvailable() ? 1 : 0;
392 switches[6] = mWindowManager.isHardKeyboardEnabled() ? 1 : 0;
Joe Onorato2314aab2010-04-08 16:41:23 -0500393 }
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400394
Joe Onorato4762c2d2010-05-17 15:42:59 -0700395 /**
Joe Onoratof1f25912010-06-07 11:52:41 -0700396 * The status bar service should call this each time the user brings the panel from
397 * invisible to visible in order to clear the notification light.
Joe Onorato4762c2d2010-05-17 15:42:59 -0700398 */
Joe Onoratof1f25912010-06-07 11:52:41 -0700399 public void onPanelRevealed() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400400 enforceStatusBarService();
401
Joe Onoratof1f25912010-06-07 11:52:41 -0700402 // tell the notification manager to turn off the lights.
403 mNotificationCallbacks.onPanelRevealed();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700404 }
405
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400406 public void onNotificationClick(String pkg, String tag, int id) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400407 enforceStatusBarService();
408
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400409 mNotificationCallbacks.onNotificationClick(pkg, tag, id);
410 }
411
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700412 public void onNotificationError(String pkg, String tag, int id,
413 int uid, int initialPid, String message) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400414 enforceStatusBarService();
415
Joe Onorato005847b2010-06-04 16:08:02 -0400416 // WARNING: this will call back into us to do the remove. Don't hold any locks.
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700417 mNotificationCallbacks.onNotificationError(pkg, tag, id, uid, initialPid, message);
Joe Onorato005847b2010-06-04 16:08:02 -0400418 }
419
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400420 public void onNotificationClear(String pkg, String tag, int id) {
421 enforceStatusBarService();
422
423 mNotificationCallbacks.onNotificationClear(pkg, tag, id);
424 }
425
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400426 public void onClearAllNotifications() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400427 enforceStatusBarService();
428
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400429 mNotificationCallbacks.onClearAll();
430 }
431
Joe Onorato18e69df2010-05-17 22:26:12 -0700432 // ================================================================================
433 // Callbacks for NotificationManagerService.
434 // ================================================================================
435 public IBinder addNotification(StatusBarNotification notification) {
436 synchronized (mNotifications) {
Joe Onoratoa0c56fe2010-05-20 10:21:52 -0700437 IBinder key = new Binder();
Joe Onorato75199e32010-05-29 17:22:51 -0400438 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400439 if (mBar != null) {
440 try {
441 mBar.addNotification(key, notification);
442 } catch (RemoteException ex) {
443 }
444 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700445 return key;
446 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700447 }
448
Joe Onorato18e69df2010-05-17 22:26:12 -0700449 public void updateNotification(IBinder key, StatusBarNotification notification) {
450 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400451 if (!mNotifications.containsKey(key)) {
452 throw new IllegalArgumentException("updateNotification key not found: " + key);
453 }
454 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400455 if (mBar != null) {
456 try {
457 mBar.updateNotification(key, notification);
458 } catch (RemoteException ex) {
459 }
460 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700461 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700462 }
463
464 public void removeNotification(IBinder key) {
Joe Onorato18e69df2010-05-17 22:26:12 -0700465 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400466 final StatusBarNotification n = mNotifications.remove(key);
467 if (n == null) {
468 throw new IllegalArgumentException("removeNotification key not found: " + key);
469 }
Joe Onoratoe345fff2010-05-23 15:18:27 -0400470 if (mBar != null) {
471 try {
472 mBar.removeNotification(key);
473 } catch (RemoteException ex) {
474 }
475 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700476 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700477 }
Joe Onorato2314aab2010-04-08 16:41:23 -0500478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800479 // ================================================================================
480 // Can be called from any thread
481 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800483 // lock on mDisableRecords
484 void manageDisableListLocked(int what, IBinder token, String pkg) {
485 if (SPEW) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700486 Slog.d(TAG, "manageDisableList what=0x" + Integer.toHexString(what) + " pkg=" + pkg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800487 }
488 // update the list
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800489 final int N = mDisableRecords.size();
490 DisableRecord tok = null;
491 int i;
492 for (i=0; i<N; i++) {
493 DisableRecord t = mDisableRecords.get(i);
494 if (t.token == token) {
495 tok = t;
496 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800498 }
499 if (what == 0 || !token.isBinderAlive()) {
500 if (tok != null) {
501 mDisableRecords.remove(i);
502 tok.token.unlinkToDeath(tok, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800504 } else {
505 if (tok == null) {
506 tok = new DisableRecord();
507 try {
508 token.linkToDeath(tok, 0);
509 }
510 catch (RemoteException ex) {
511 return; // give up
512 }
513 mDisableRecords.add(tok);
514 }
515 tok.what = what;
516 tok.token = token;
517 tok.pkg = pkg;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800518 }
519 }
520
521 // lock on mDisableRecords
522 int gatherDisableActionsLocked() {
523 final int N = mDisableRecords.size();
524 // gather the new net flags
525 int net = 0;
526 for (int i=0; i<N; i++) {
527 net |= mDisableRecords.get(i).what;
528 }
529 return net;
530 }
531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 // ================================================================================
533 // Always called from UI thread
534 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
537 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
538 != PackageManager.PERMISSION_GRANTED) {
539 pw.println("Permission Denial: can't dump StatusBar from from pid="
540 + Binder.getCallingPid()
541 + ", uid=" + Binder.getCallingUid());
542 return;
543 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700544
Joe Onorato0cbda992010-05-02 16:28:15 -0700545 synchronized (mIcons) {
546 mIcons.dump(pw);
547 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700548
549 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400550 int i=0;
551 pw.println("Notification list:");
552 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
553 pw.printf(" %2d: %s\n", i, e.getValue().toString());
554 i++;
555 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700557
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800558 synchronized (mLock) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800559 final int N = mDisableRecords.size();
560 pw.println(" mDisableRecords.size=" + N
561 + " mDisabled=0x" + Integer.toHexString(mDisabled));
562 for (int i=0; i<N; i++) {
563 DisableRecord tok = mDisableRecords.get(i);
564 pw.println(" [" + i + "] what=0x" + Integer.toHexString(tok.what)
565 + " pkg=" + tok.pkg + " token=" + tok.token);
566 }
567 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800568 }
569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800570 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
571 public void onReceive(Context context, Intent intent) {
572 String action = intent.getAction();
Joe Onoratof9e0e6b2009-09-08 16:24:36 -0400573 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
574 || Intent.ACTION_SCREEN_OFF.equals(action)) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700575 collapse();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700577 /*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 else if (Telephony.Intents.SPN_STRINGS_UPDATED_ACTION.equals(action)) {
579 updateNetworkName(intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_SPN, false),
580 intent.getStringExtra(Telephony.Intents.EXTRA_SPN),
581 intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_PLMN, false),
582 intent.getStringExtra(Telephony.Intents.EXTRA_PLMN));
583 }
584 else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
585 updateResources();
586 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700587 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800588 }
589 };
590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800591}