blob: ca3b12d9cdad2a2020d0802689a04a8a0427f3c5 [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.Binder;
Joe Onoratof3f0e052010-05-14 18:49:29 -070026import android.os.Handler;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -070027import android.os.IBinder;
28import android.os.RemoteException;
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();
Daniel Sandler60ee2562011-07-22 12:34:33 -040072 // encompasses lights-out mode and other flags defined on View
73 int mSystemUiVisibility = 0;
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
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700178 public void setIcon(String slot, String iconPackage, int iconId, int iconLevel,
179 String contentDescription) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800180 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700181
182 synchronized (mIcons) {
183 int index = mIcons.getSlotIndex(slot);
184 if (index < 0) {
185 throw new SecurityException("invalid status bar icon slot: " + slot);
186 }
187
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700188 StatusBarIcon icon = new StatusBarIcon(iconPackage, iconId, iconLevel, 0,
189 contentDescription);
Joe Onorato66d7d012010-05-14 10:05:10 -0700190 //Slog.d(TAG, "setIcon slot=" + slot + " index=" + index + " icon=" + icon);
Joe Onorato0cbda992010-05-02 16:28:15 -0700191 mIcons.setIcon(index, icon);
192
Joe Onorato0cbda992010-05-02 16:28:15 -0700193 if (mBar != null) {
194 try {
195 mBar.setIcon(index, icon);
196 } catch (RemoteException ex) {
197 }
198 }
199 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200 }
201
Joe Onorato0cbda992010-05-02 16:28:15 -0700202 public void setIconVisibility(String slot, boolean visible) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800203 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700204
Joe Onorato514ad6632010-05-13 18:49:00 -0700205 synchronized (mIcons) {
206 int index = mIcons.getSlotIndex(slot);
207 if (index < 0) {
208 throw new SecurityException("invalid status bar icon slot: " + slot);
209 }
210
211 StatusBarIcon icon = mIcons.getIcon(index);
212 if (icon == null) {
213 return;
214 }
215
216 if (icon.visible != visible) {
217 icon.visible = visible;
218
Joe Onorato514ad6632010-05-13 18:49:00 -0700219 if (mBar != null) {
220 try {
221 mBar.setIcon(index, icon);
222 } catch (RemoteException ex) {
223 }
224 }
225 }
226 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700227 }
228
229 public void removeIcon(String slot) {
230 enforceStatusBar();
231
232 synchronized (mIcons) {
233 int index = mIcons.getSlotIndex(slot);
234 if (index < 0) {
235 throw new SecurityException("invalid status bar icon slot: " + slot);
236 }
237
238 mIcons.removeIcon(index);
239
Joe Onorato0cbda992010-05-02 16:28:15 -0700240 if (mBar != null) {
241 try {
242 mBar.removeIcon(index);
243 } catch (RemoteException ex) {
244 }
245 }
246 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247 }
248
Daniel Sandlere02d8082010-10-08 15:13:22 -0400249 /**
250 * Hide or show the on-screen Menu key. Only call this from the window manager, typically in
251 * response to a window with FLAG_NEEDS_MENU_KEY set.
252 */
Dianne Hackborn7d049322011-06-14 15:00:32 -0700253 public void topAppWindowChanged(final boolean menuVisible) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400254 enforceStatusBar();
255
Dianne Hackborn7d049322011-06-14 15:00:32 -0700256 if (SPEW) Slog.d(TAG, (menuVisible?"showing":"hiding") + " MENU key");
Daniel Sandlere02d8082010-10-08 15:13:22 -0400257
258 synchronized(mLock) {
Dianne Hackborn7d049322011-06-14 15:00:32 -0700259 mMenuVisible = menuVisible;
260 mHandler.post(new Runnable() {
261 public void run() {
262 if (mBar != null) {
263 try {
264 mBar.topAppWindowChanged(menuVisible);
265 } catch (RemoteException ex) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400266 }
267 }
Dianne Hackborn7d049322011-06-14 15:00:32 -0700268 }
269 });
Daniel Sandlere02d8082010-10-08 15:13:22 -0400270 }
271 }
272
Joe Onorato857fd9b2011-01-27 15:08:35 -0800273 public void setImeWindowStatus(final IBinder token, final int vis, final int backDisposition) {
satok06487a52010-10-29 11:37:18 +0900274 enforceStatusBar();
275
Joe Onorato857fd9b2011-01-27 15:08:35 -0800276 if (SPEW) {
277 Slog.d(TAG, "swetImeWindowStatus vis=" + vis + " backDisposition=" + backDisposition);
278 }
satok06487a52010-10-29 11:37:18 +0900279
280 synchronized(mLock) {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800281 // In case of IME change, we need to call up setImeWindowStatus() regardless of
282 // mImeWindowVis because mImeWindowVis may not have been set to false when the
satok06e07442010-11-02 19:46:55 +0900283 // previous IME was destroyed.
Joe Onorato857fd9b2011-01-27 15:08:35 -0800284 mImeWindowVis = vis;
285 mImeBackDisposition = backDisposition;
286 mImeToken = token;
satok06e07442010-11-02 19:46:55 +0900287 mHandler.post(new Runnable() {
288 public void run() {
289 if (mBar != null) {
290 try {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800291 mBar.setImeWindowStatus(token, vis, backDisposition);
satok06e07442010-11-02 19:46:55 +0900292 } catch (RemoteException ex) {
satok06487a52010-10-29 11:37:18 +0900293 }
294 }
satok06e07442010-11-02 19:46:55 +0900295 }
296 });
satok06487a52010-10-29 11:37:18 +0900297 }
298 }
299
Joe Onorato664644d2011-01-23 17:53:23 -0800300 public void setSystemUiVisibility(int vis) {
Joe Onorato55bf3802011-01-25 13:42:10 -0800301 // also allows calls from window manager which is in this process.
Joe Onoratof63b0f42010-09-12 17:03:19 -0400302 enforceStatusBarService();
303
Daniel Sandler60ee2562011-07-22 12:34:33 -0400304 if (SPEW) Slog.d(TAG, "setSystemUiVisibility(" + vis + ")");
305
Joe Onoratof63b0f42010-09-12 17:03:19 -0400306 synchronized (mLock) {
Daniel Sandler60ee2562011-07-22 12:34:33 -0400307 updateUiVisibilityLocked(vis);
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800308 disableLocked(vis & StatusBarManager.DISABLE_MASK, mSysUiVisToken,
309 "WindowManager.LayoutParams");
Joe Onoratof63b0f42010-09-12 17:03:19 -0400310 }
311 }
312
Daniel Sandler60ee2562011-07-22 12:34:33 -0400313 private void updateUiVisibilityLocked(final int vis) {
314 if (mSystemUiVisibility != vis) {
315 mSystemUiVisibility = vis;
Joe Onoratof63b0f42010-09-12 17:03:19 -0400316 mHandler.post(new Runnable() {
317 public void run() {
318 if (mBar != null) {
319 try {
Daniel Sandler60ee2562011-07-22 12:34:33 -0400320 mBar.setSystemUiVisibility(vis);
Joe Onoratof63b0f42010-09-12 17:03:19 -0400321 } catch (RemoteException ex) {
Joe Onorato93056472010-09-10 10:30:46 -0400322 }
323 }
Joe Onoratof63b0f42010-09-12 17:03:19 -0400324 }
325 });
Joe Onorato93056472010-09-10 10:30:46 -0400326 }
327 }
328
Jeff Brown2992ea72011-01-28 22:04:14 -0800329 public void setHardKeyboardEnabled(final boolean enabled) {
330 mHandler.post(new Runnable() {
331 public void run() {
332 mWindowManager.setHardKeyboardEnabled(enabled);
333 }
334 });
335 }
336
337 @Override
338 public void onHardKeyboardStatusChange(final boolean available, final boolean enabled) {
339 mHandler.post(new Runnable() {
340 public void run() {
341 if (mBar != null) {
342 try {
343 mBar.setHardKeyboardStatus(available, enabled);
344 } catch (RemoteException ex) {
345 }
346 }
347 }
348 });
349 }
350
Michael Jurka3b1fc472011-06-13 10:54:40 -0700351 @Override
352 public void toggleRecentApps() {
353 if (mBar != null) {
354 try {
355 mBar.toggleRecentApps();
356 } catch (RemoteException ex) {}
357 }
358 }
359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800360 private void enforceStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700361 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700362 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363 }
364
365 private void enforceExpandStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700366 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.EXPAND_STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700367 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800368 }
369
Joe Onorato8bc6c512010-06-04 16:21:12 -0400370 private void enforceStatusBarService() {
371 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
372 "StatusBarManagerService");
373 }
374
Joe Onorato4762c2d2010-05-17 15:42:59 -0700375 // ================================================================================
376 // Callbacks from the status bar service.
377 // ================================================================================
Joe Onorato75199e32010-05-29 17:22:51 -0400378 public void registerStatusBar(IStatusBar bar, StatusBarIconList iconList,
Joe Onorato93056472010-09-10 10:30:46 -0400379 List<IBinder> notificationKeys, List<StatusBarNotification> notifications,
satokcd7cd292010-11-20 15:46:23 +0900380 int switches[], List<IBinder> binders) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400381 enforceStatusBarService();
382
Joe Onorato0cbda992010-05-02 16:28:15 -0700383 Slog.i(TAG, "registerStatusBar bar=" + bar);
384 mBar = bar;
Joe Onorato75199e32010-05-29 17:22:51 -0400385 synchronized (mIcons) {
386 iconList.copyFrom(mIcons);
387 }
388 synchronized (mNotifications) {
389 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
390 notificationKeys.add(e.getKey());
391 notifications.add(e.getValue());
392 }
393 }
Joe Onorato93056472010-09-10 10:30:46 -0400394 synchronized (mLock) {
Joe Onoratoe4c7b3f2010-10-30 12:15:03 -0700395 switches[0] = gatherDisableActionsLocked();
Daniel Sandler60ee2562011-07-22 12:34:33 -0400396 switches[1] = mSystemUiVisibility;
Joe Onoratoe4c7b3f2010-10-30 12:15:03 -0700397 switches[2] = mMenuVisible ? 1 : 0;
Joe Onorato857fd9b2011-01-27 15:08:35 -0800398 switches[3] = mImeWindowVis;
399 switches[4] = mImeBackDisposition;
400 binders.add(mImeToken);
Joe Onorato93056472010-09-10 10:30:46 -0400401 }
Jeff Brown2992ea72011-01-28 22:04:14 -0800402 switches[5] = mWindowManager.isHardKeyboardAvailable() ? 1 : 0;
403 switches[6] = mWindowManager.isHardKeyboardEnabled() ? 1 : 0;
Joe Onorato2314aab2010-04-08 16:41:23 -0500404 }
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400405
Joe Onorato4762c2d2010-05-17 15:42:59 -0700406 /**
Joe Onoratof1f25912010-06-07 11:52:41 -0700407 * The status bar service should call this each time the user brings the panel from
408 * invisible to visible in order to clear the notification light.
Joe Onorato4762c2d2010-05-17 15:42:59 -0700409 */
Joe Onoratof1f25912010-06-07 11:52:41 -0700410 public void onPanelRevealed() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400411 enforceStatusBarService();
412
Joe Onoratof1f25912010-06-07 11:52:41 -0700413 // tell the notification manager to turn off the lights.
414 mNotificationCallbacks.onPanelRevealed();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700415 }
416
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400417 public void onNotificationClick(String pkg, String tag, int id) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400418 enforceStatusBarService();
419
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400420 mNotificationCallbacks.onNotificationClick(pkg, tag, id);
421 }
422
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700423 public void onNotificationError(String pkg, String tag, int id,
424 int uid, int initialPid, String message) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400425 enforceStatusBarService();
426
Joe Onorato005847b2010-06-04 16:08:02 -0400427 // WARNING: this will call back into us to do the remove. Don't hold any locks.
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700428 mNotificationCallbacks.onNotificationError(pkg, tag, id, uid, initialPid, message);
Joe Onorato005847b2010-06-04 16:08:02 -0400429 }
430
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400431 public void onNotificationClear(String pkg, String tag, int id) {
432 enforceStatusBarService();
433
434 mNotificationCallbacks.onNotificationClear(pkg, tag, id);
435 }
436
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400437 public void onClearAllNotifications() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400438 enforceStatusBarService();
439
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400440 mNotificationCallbacks.onClearAll();
441 }
442
Joe Onorato18e69df2010-05-17 22:26:12 -0700443 // ================================================================================
444 // Callbacks for NotificationManagerService.
445 // ================================================================================
446 public IBinder addNotification(StatusBarNotification notification) {
447 synchronized (mNotifications) {
Joe Onoratoa0c56fe2010-05-20 10:21:52 -0700448 IBinder key = new Binder();
Joe Onorato75199e32010-05-29 17:22:51 -0400449 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400450 if (mBar != null) {
451 try {
452 mBar.addNotification(key, notification);
453 } catch (RemoteException ex) {
454 }
455 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700456 return key;
457 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700458 }
459
Joe Onorato18e69df2010-05-17 22:26:12 -0700460 public void updateNotification(IBinder key, StatusBarNotification notification) {
461 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400462 if (!mNotifications.containsKey(key)) {
463 throw new IllegalArgumentException("updateNotification key not found: " + key);
464 }
465 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400466 if (mBar != null) {
467 try {
468 mBar.updateNotification(key, notification);
469 } catch (RemoteException ex) {
470 }
471 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700472 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700473 }
474
475 public void removeNotification(IBinder key) {
Joe Onorato18e69df2010-05-17 22:26:12 -0700476 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400477 final StatusBarNotification n = mNotifications.remove(key);
478 if (n == null) {
479 throw new IllegalArgumentException("removeNotification key not found: " + key);
480 }
Joe Onoratoe345fff2010-05-23 15:18:27 -0400481 if (mBar != null) {
482 try {
483 mBar.removeNotification(key);
484 } catch (RemoteException ex) {
485 }
486 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700487 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700488 }
Joe Onorato2314aab2010-04-08 16:41:23 -0500489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490 // ================================================================================
491 // Can be called from any thread
492 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800494 // lock on mDisableRecords
495 void manageDisableListLocked(int what, IBinder token, String pkg) {
496 if (SPEW) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700497 Slog.d(TAG, "manageDisableList what=0x" + Integer.toHexString(what) + " pkg=" + pkg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498 }
499 // update the list
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800500 final int N = mDisableRecords.size();
501 DisableRecord tok = null;
502 int i;
503 for (i=0; i<N; i++) {
504 DisableRecord t = mDisableRecords.get(i);
505 if (t.token == token) {
506 tok = t;
507 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800509 }
510 if (what == 0 || !token.isBinderAlive()) {
511 if (tok != null) {
512 mDisableRecords.remove(i);
513 tok.token.unlinkToDeath(tok, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800514 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800515 } else {
516 if (tok == null) {
517 tok = new DisableRecord();
518 try {
519 token.linkToDeath(tok, 0);
520 }
521 catch (RemoteException ex) {
522 return; // give up
523 }
524 mDisableRecords.add(tok);
525 }
526 tok.what = what;
527 tok.token = token;
528 tok.pkg = pkg;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800529 }
530 }
531
532 // lock on mDisableRecords
533 int gatherDisableActionsLocked() {
534 final int N = mDisableRecords.size();
535 // gather the new net flags
536 int net = 0;
537 for (int i=0; i<N; i++) {
538 net |= mDisableRecords.get(i).what;
539 }
540 return net;
541 }
542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800543 // ================================================================================
544 // Always called from UI thread
545 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800547 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
548 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
549 != PackageManager.PERMISSION_GRANTED) {
550 pw.println("Permission Denial: can't dump StatusBar from from pid="
551 + Binder.getCallingPid()
552 + ", uid=" + Binder.getCallingUid());
553 return;
554 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700555
Joe Onorato0cbda992010-05-02 16:28:15 -0700556 synchronized (mIcons) {
557 mIcons.dump(pw);
558 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700559
560 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400561 int i=0;
562 pw.println("Notification list:");
563 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
564 pw.printf(" %2d: %s\n", i, e.getValue().toString());
565 i++;
566 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700568
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800569 synchronized (mLock) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800570 final int N = mDisableRecords.size();
571 pw.println(" mDisableRecords.size=" + N
572 + " mDisabled=0x" + Integer.toHexString(mDisabled));
573 for (int i=0; i<N; i++) {
574 DisableRecord tok = mDisableRecords.get(i);
575 pw.println(" [" + i + "] what=0x" + Integer.toHexString(tok.what)
576 + " pkg=" + tok.pkg + " token=" + tok.token);
577 }
578 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579 }
580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800581 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
582 public void onReceive(Context context, Intent intent) {
583 String action = intent.getAction();
Joe Onoratof9e0e6b2009-09-08 16:24:36 -0400584 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
585 || Intent.ACTION_SCREEN_OFF.equals(action)) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700586 collapse();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700588 /*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800589 else if (Telephony.Intents.SPN_STRINGS_UPDATED_ACTION.equals(action)) {
590 updateNetworkName(intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_SPN, false),
591 intent.getStringExtra(Telephony.Intents.EXTRA_SPN),
592 intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_PLMN, false),
593 intent.getStringExtra(Telephony.Intents.EXTRA_PLMN));
594 }
595 else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
596 updateResources();
597 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700598 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800599 }
600 };
601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800602}