blob: 50ea3fa351b83299b5441b8a96c60cbd181cef15 [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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056{
Joe Onorato4762c2d2010-05-17 15:42:59 -070057 static final String TAG = "StatusBarManagerService";
Joe Onorato431bb222010-10-18 19:13:23 -040058 static final boolean SPEW = false;
Joe Onoratodf7dbb62009-11-17 10:43:37 -080059
Joe Onoratof3f0e052010-05-14 18:49:29 -070060 final Context mContext;
61 Handler mHandler = new Handler();
62 NotificationCallbacks mNotificationCallbacks;
Joe Onorato4762c2d2010-05-17 15:42:59 -070063 volatile IStatusBar mBar;
Joe Onoratof3f0e052010-05-14 18:49:29 -070064 StatusBarIconList mIcons = new StatusBarIconList();
Joe Onorato75199e32010-05-29 17:22:51 -040065 HashMap<IBinder,StatusBarNotification> mNotifications
66 = new HashMap<IBinder,StatusBarNotification>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067
Joe Onoratof3f0e052010-05-14 18:49:29 -070068 // for disabling the status bar
69 ArrayList<DisableRecord> mDisableRecords = new ArrayList<DisableRecord>();
70 int mDisabled = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071
Joe Onorato93056472010-09-10 10:30:46 -040072 Object mLock = new Object();
73 // We usually call it lights out mode, but double negatives are annoying
74 boolean mLightsOn = true;
Daniel Sandlere02d8082010-10-08 15:13:22 -040075 boolean mMenuVisible = false;
satok06487a52010-10-29 11:37:18 +090076 boolean mIMEButtonVisible = false;
satokcd7cd292010-11-20 15:46:23 +090077 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 */
Joe Onorato089de882010-04-12 08:18:45 -0700104 public StatusBarManagerService(Context context) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 mContext = context;
Joe Onorato0cbda992010-05-02 16:28:15 -0700106
107 final Resources res = context.getResources();
Joe Onorato75144ea2010-06-07 12:36:25 -0700108 mIcons.defineSlots(res.getStringArray(com.android.internal.R.array.config_statusBarIcons));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 }
110
111 public void setNotificationCallbacks(NotificationCallbacks listener) {
112 mNotificationCallbacks = listener;
113 }
114
115 // ================================================================================
Joe Onorato25f95f92010-04-08 18:37:10 -0500116 // From IStatusBarService
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 // ================================================================================
Joe Onoratof3f0e052010-05-14 18:49:29 -0700118 public void expand() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 enforceExpandStatusBar();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700120
121 if (mBar != null) {
122 try {
123 mBar.animateExpand();
124 } catch (RemoteException ex) {
125 }
126 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127 }
128
Joe Onoratof3f0e052010-05-14 18:49:29 -0700129 public void collapse() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 enforceExpandStatusBar();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131
Joe Onorato4762c2d2010-05-17 15:42:59 -0700132 if (mBar != null) {
133 try {
134 mBar.animateCollapse();
135 } catch (RemoteException ex) {
136 }
137 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 }
139
140 public void disable(int what, IBinder token, String pkg) {
141 enforceStatusBar();
Joe Onoratof3f0e052010-05-14 18:49:29 -0700142
143 // It's important that the the callback and the call to mBar get done
144 // in the same order when multiple threads are calling this function
145 // so they are paired correctly. The messages on the handler will be
146 // handled in the order they were enqueued, but will be outside the lock.
147 synchronized (mDisableRecords) {
148 manageDisableListLocked(what, token, pkg);
149 final int net = gatherDisableActionsLocked();
Joe Onoratof3f0e052010-05-14 18:49:29 -0700150 if (net != mDisabled) {
151 mDisabled = net;
152 mHandler.post(new Runnable() {
153 public void run() {
154 mNotificationCallbacks.onSetDisabled(net);
155 }
156 });
157 if (mBar != null) {
158 try {
159 mBar.disable(net);
160 } catch (RemoteException ex) {
161 }
162 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 }
165 }
166
Joe Onorato0cbda992010-05-02 16:28:15 -0700167 public void setIcon(String slot, String iconPackage, int iconId, int iconLevel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700169
170 synchronized (mIcons) {
171 int index = mIcons.getSlotIndex(slot);
172 if (index < 0) {
173 throw new SecurityException("invalid status bar icon slot: " + slot);
174 }
175
176 StatusBarIcon icon = new StatusBarIcon(iconPackage, iconId, iconLevel);
Joe Onorato66d7d012010-05-14 10:05:10 -0700177 //Slog.d(TAG, "setIcon slot=" + slot + " index=" + index + " icon=" + icon);
Joe Onorato0cbda992010-05-02 16:28:15 -0700178 mIcons.setIcon(index, icon);
179
Joe Onorato0cbda992010-05-02 16:28:15 -0700180 if (mBar != null) {
181 try {
182 mBar.setIcon(index, icon);
183 } catch (RemoteException ex) {
184 }
185 }
186 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800187 }
188
Joe Onorato0cbda992010-05-02 16:28:15 -0700189 public void setIconVisibility(String slot, boolean visible) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700191
Joe Onorato514ad6632010-05-13 18:49:00 -0700192 synchronized (mIcons) {
193 int index = mIcons.getSlotIndex(slot);
194 if (index < 0) {
195 throw new SecurityException("invalid status bar icon slot: " + slot);
196 }
197
198 StatusBarIcon icon = mIcons.getIcon(index);
199 if (icon == null) {
200 return;
201 }
202
203 if (icon.visible != visible) {
204 icon.visible = visible;
205
Joe Onorato514ad6632010-05-13 18:49:00 -0700206 if (mBar != null) {
207 try {
208 mBar.setIcon(index, icon);
209 } catch (RemoteException ex) {
210 }
211 }
212 }
213 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700214 }
215
216 public void removeIcon(String slot) {
217 enforceStatusBar();
218
219 synchronized (mIcons) {
220 int index = mIcons.getSlotIndex(slot);
221 if (index < 0) {
222 throw new SecurityException("invalid status bar icon slot: " + slot);
223 }
224
225 mIcons.removeIcon(index);
226
Joe Onorato0cbda992010-05-02 16:28:15 -0700227 if (mBar != null) {
228 try {
229 mBar.removeIcon(index);
230 } catch (RemoteException ex) {
231 }
232 }
233 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800234 }
235
Daniel Sandlere02d8082010-10-08 15:13:22 -0400236 /**
237 * Hide or show the on-screen Menu key. Only call this from the window manager, typically in
238 * response to a window with FLAG_NEEDS_MENU_KEY set.
239 */
240 public void setMenuKeyVisible(final boolean visible) {
241 enforceStatusBar();
242
243 if (SPEW) Slog.d(TAG, (visible?"showing":"hiding") + " MENU key");
244
245 synchronized(mLock) {
246 if (mMenuVisible != visible) {
247 mMenuVisible = visible;
248 mHandler.post(new Runnable() {
249 public void run() {
250 if (mBar != null) {
251 try {
252 mBar.setMenuKeyVisible(visible);
253 } catch (RemoteException ex) {
254 }
255 }
256 }
257 });
258 }
259 }
260 }
261
satokcd7cd292010-11-20 15:46:23 +0900262 public void setIMEButtonVisible(final IBinder token, final boolean visible) {
satok06487a52010-10-29 11:37:18 +0900263 enforceStatusBar();
264
265 if (SPEW) Slog.d(TAG, (visible?"showing":"hiding") + " IME Button");
266
267 synchronized(mLock) {
satok06e07442010-11-02 19:46:55 +0900268 // In case of IME change, we need to call up setIMEButtonVisible() regardless of
269 // mIMEButtonVisible because mIMEButtonVisible may not have been set to false when the
270 // previous IME was destroyed.
271 mIMEButtonVisible = visible;
satokcd7cd292010-11-20 15:46:23 +0900272 mIMEToken = token;
satok06e07442010-11-02 19:46:55 +0900273 mHandler.post(new Runnable() {
274 public void run() {
275 if (mBar != null) {
276 try {
satokcd7cd292010-11-20 15:46:23 +0900277 mBar.setIMEButtonVisible(token, visible);
satok06e07442010-11-02 19:46:55 +0900278 } catch (RemoteException ex) {
satok06487a52010-10-29 11:37:18 +0900279 }
280 }
satok06e07442010-11-02 19:46:55 +0900281 }
282 });
satok06487a52010-10-29 11:37:18 +0900283 }
284 }
285
Joe Onoratof63b0f42010-09-12 17:03:19 -0400286 /**
287 * This is used for the automatic version of lights-out mode. Only call this from
288 * the window manager.
289 *
290 * @see setLightsOn(boolean)
291 */
Joe Onorato93056472010-09-10 10:30:46 -0400292 public void setActiveWindowIsFullscreen(boolean fullscreen) {
293 // We could get away with a separate permission here, but STATUS_BAR is
294 // signatureOrSystem which is probably good enough. There is no public API
295 // for this, so the question is a security issue, not an API compatibility issue.
296 enforceStatusBar();
297
Joe Onorato93056472010-09-10 10:30:46 -0400298 synchronized (mLock) {
Joe Onoratof63b0f42010-09-12 17:03:19 -0400299 updateLightsOnLocked(!fullscreen);
300 }
301 }
302
303 /**
304 * This is used for the user-controlled version of lights-out mode. Only call this from
305 * the status bar itself.
306 *
307 * We have two different functions here, because I think we're going to want to
308 * tweak the behavior when the user keeps turning lights-out mode off and the
309 * app keeps trying to turn it on. For now they can just fight it out. Having
310 * these two separte inputs will allow us to keep that change local to here. --joeo
311 */
Joe Onorato664644d2011-01-23 17:53:23 -0800312 public void setSystemUiVisibility(int vis) {
Joe Onoratof63b0f42010-09-12 17:03:19 -0400313 enforceStatusBarService();
314
315 synchronized (mLock) {
Joe Onorato664644d2011-01-23 17:53:23 -0800316 final boolean lightsOn = (vis & View.STATUS_BAR_HIDDEN) == 0;
Joe Onoratof63b0f42010-09-12 17:03:19 -0400317 updateLightsOnLocked(lightsOn);
318 }
319 }
320
321 private void updateLightsOnLocked(final boolean lightsOn) {
322 if (mLightsOn != lightsOn) {
323 mLightsOn = lightsOn;
324 mHandler.post(new Runnable() {
325 public void run() {
326 if (mBar != null) {
327 try {
328 mBar.setLightsOn(lightsOn);
329 } catch (RemoteException ex) {
Joe Onorato93056472010-09-10 10:30:46 -0400330 }
331 }
Joe Onoratof63b0f42010-09-12 17:03:19 -0400332 }
333 });
Joe Onorato93056472010-09-10 10:30:46 -0400334 }
335 }
336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800337 private void enforceStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700338 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700339 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340 }
341
342 private void enforceExpandStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700343 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.EXPAND_STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700344 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800345 }
346
Joe Onorato8bc6c512010-06-04 16:21:12 -0400347 private void enforceStatusBarService() {
348 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
349 "StatusBarManagerService");
350 }
351
Joe Onorato4762c2d2010-05-17 15:42:59 -0700352
353 // ================================================================================
354 // Callbacks from the status bar service.
355 // ================================================================================
Joe Onorato75199e32010-05-29 17:22:51 -0400356 public void registerStatusBar(IStatusBar bar, StatusBarIconList iconList,
Joe Onorato93056472010-09-10 10:30:46 -0400357 List<IBinder> notificationKeys, List<StatusBarNotification> notifications,
satokcd7cd292010-11-20 15:46:23 +0900358 int switches[], List<IBinder> binders) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400359 enforceStatusBarService();
360
Joe Onorato0cbda992010-05-02 16:28:15 -0700361 Slog.i(TAG, "registerStatusBar bar=" + bar);
362 mBar = bar;
Joe Onorato75199e32010-05-29 17:22:51 -0400363 synchronized (mIcons) {
364 iconList.copyFrom(mIcons);
365 }
366 synchronized (mNotifications) {
367 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
368 notificationKeys.add(e.getKey());
369 notifications.add(e.getValue());
370 }
371 }
Joe Onorato93056472010-09-10 10:30:46 -0400372 synchronized (mLock) {
Joe Onoratoe4c7b3f2010-10-30 12:15:03 -0700373 switches[0] = gatherDisableActionsLocked();
374 switches[1] = mLightsOn ? 1 : 0;
375 switches[2] = mMenuVisible ? 1 : 0;
376 switches[3] = mIMEButtonVisible ? 1 : 0;
satokcd7cd292010-11-20 15:46:23 +0900377 binders.add(mIMEToken);
Joe Onorato93056472010-09-10 10:30:46 -0400378 }
Joe Onorato2314aab2010-04-08 16:41:23 -0500379 }
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400380
Joe Onorato4762c2d2010-05-17 15:42:59 -0700381 /**
Joe Onoratof1f25912010-06-07 11:52:41 -0700382 * The status bar service should call this each time the user brings the panel from
383 * invisible to visible in order to clear the notification light.
Joe Onorato4762c2d2010-05-17 15:42:59 -0700384 */
Joe Onoratof1f25912010-06-07 11:52:41 -0700385 public void onPanelRevealed() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400386 enforceStatusBarService();
387
Joe Onoratof1f25912010-06-07 11:52:41 -0700388 // tell the notification manager to turn off the lights.
389 mNotificationCallbacks.onPanelRevealed();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700390 }
391
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400392 public void onNotificationClick(String pkg, String tag, int id) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400393 enforceStatusBarService();
394
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400395 mNotificationCallbacks.onNotificationClick(pkg, tag, id);
396 }
397
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700398 public void onNotificationError(String pkg, String tag, int id,
399 int uid, int initialPid, String message) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400400 enforceStatusBarService();
401
Joe Onorato005847b2010-06-04 16:08:02 -0400402 // WARNING: this will call back into us to do the remove. Don't hold any locks.
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700403 mNotificationCallbacks.onNotificationError(pkg, tag, id, uid, initialPid, message);
Joe Onorato005847b2010-06-04 16:08:02 -0400404 }
405
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400406 public void onNotificationClear(String pkg, String tag, int id) {
407 enforceStatusBarService();
408
409 mNotificationCallbacks.onNotificationClear(pkg, tag, id);
410 }
411
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400412 public void onClearAllNotifications() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400413 enforceStatusBarService();
414
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400415 mNotificationCallbacks.onClearAll();
416 }
417
Joe Onorato18e69df2010-05-17 22:26:12 -0700418 // ================================================================================
419 // Callbacks for NotificationManagerService.
420 // ================================================================================
421 public IBinder addNotification(StatusBarNotification notification) {
422 synchronized (mNotifications) {
Joe Onoratoa0c56fe2010-05-20 10:21:52 -0700423 IBinder key = new Binder();
Joe Onorato75199e32010-05-29 17:22:51 -0400424 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400425 if (mBar != null) {
426 try {
427 mBar.addNotification(key, notification);
428 } catch (RemoteException ex) {
429 }
430 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700431 return key;
432 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700433 }
434
Joe Onorato18e69df2010-05-17 22:26:12 -0700435 public void updateNotification(IBinder key, StatusBarNotification notification) {
436 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400437 if (!mNotifications.containsKey(key)) {
438 throw new IllegalArgumentException("updateNotification key not found: " + key);
439 }
440 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400441 if (mBar != null) {
442 try {
443 mBar.updateNotification(key, notification);
444 } catch (RemoteException ex) {
445 }
446 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700447 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700448 }
449
450 public void removeNotification(IBinder key) {
Joe Onorato18e69df2010-05-17 22:26:12 -0700451 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400452 final StatusBarNotification n = mNotifications.remove(key);
453 if (n == null) {
454 throw new IllegalArgumentException("removeNotification key not found: " + key);
455 }
Joe Onoratoe345fff2010-05-23 15:18:27 -0400456 if (mBar != null) {
457 try {
458 mBar.removeNotification(key);
459 } catch (RemoteException ex) {
460 }
461 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700462 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700463 }
Joe Onorato2314aab2010-04-08 16:41:23 -0500464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800465 // ================================================================================
466 // Can be called from any thread
467 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800469 // lock on mDisableRecords
470 void manageDisableListLocked(int what, IBinder token, String pkg) {
471 if (SPEW) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700472 Slog.d(TAG, "manageDisableList what=0x" + Integer.toHexString(what) + " pkg=" + pkg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800473 }
474 // update the list
475 synchronized (mDisableRecords) {
476 final int N = mDisableRecords.size();
477 DisableRecord tok = null;
478 int i;
479 for (i=0; i<N; i++) {
480 DisableRecord t = mDisableRecords.get(i);
481 if (t.token == token) {
482 tok = t;
483 break;
484 }
485 }
486 if (what == 0 || !token.isBinderAlive()) {
487 if (tok != null) {
488 mDisableRecords.remove(i);
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -0700489 tok.token.unlinkToDeath(tok, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490 }
491 } else {
492 if (tok == null) {
493 tok = new DisableRecord();
494 try {
495 token.linkToDeath(tok, 0);
496 }
497 catch (RemoteException ex) {
498 return; // give up
499 }
500 mDisableRecords.add(tok);
501 }
502 tok.what = what;
503 tok.token = token;
504 tok.pkg = pkg;
505 }
506 }
507 }
508
509 // lock on mDisableRecords
510 int gatherDisableActionsLocked() {
511 final int N = mDisableRecords.size();
512 // gather the new net flags
513 int net = 0;
514 for (int i=0; i<N; i++) {
515 net |= mDisableRecords.get(i).what;
516 }
517 return net;
518 }
519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520 // ================================================================================
521 // Always called from UI thread
522 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800524 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
525 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
526 != PackageManager.PERMISSION_GRANTED) {
527 pw.println("Permission Denial: can't dump StatusBar from from pid="
528 + Binder.getCallingPid()
529 + ", uid=" + Binder.getCallingUid());
530 return;
531 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700532
Joe Onorato0cbda992010-05-02 16:28:15 -0700533 synchronized (mIcons) {
534 mIcons.dump(pw);
535 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700536
537 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400538 int i=0;
539 pw.println("Notification list:");
540 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
541 pw.printf(" %2d: %s\n", i, e.getValue().toString());
542 i++;
543 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700545
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800546 synchronized (mDisableRecords) {
547 final int N = mDisableRecords.size();
548 pw.println(" mDisableRecords.size=" + N
549 + " mDisabled=0x" + Integer.toHexString(mDisabled));
550 for (int i=0; i<N; i++) {
551 DisableRecord tok = mDisableRecords.get(i);
552 pw.println(" [" + i + "] what=0x" + Integer.toHexString(tok.what)
553 + " pkg=" + tok.pkg + " token=" + tok.token);
554 }
555 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556 }
557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
559 public void onReceive(Context context, Intent intent) {
560 String action = intent.getAction();
Joe Onoratof9e0e6b2009-09-08 16:24:36 -0400561 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
562 || Intent.ACTION_SCREEN_OFF.equals(action)) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700563 collapse();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700565 /*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566 else if (Telephony.Intents.SPN_STRINGS_UPDATED_ACTION.equals(action)) {
567 updateNetworkName(intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_SPN, false),
568 intent.getStringExtra(Telephony.Intents.EXTRA_SPN),
569 intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_PLMN, false),
570 intent.getStringExtra(Telephony.Intents.EXTRA_PLMN));
571 }
572 else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
573 updateResources();
574 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700575 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 }
577 };
578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579}