blob: 78c0c12d3551b59de1db6b4db43f347ef6e831bf [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 // ================================================================================
Joe Onoratof3f0e052010-05-14 18:49:29 -0700120 public void expand() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121 enforceExpandStatusBar();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700122
123 if (mBar != null) {
124 try {
125 mBar.animateExpand();
126 } catch (RemoteException ex) {
127 }
128 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 }
130
Joe Onoratof3f0e052010-05-14 18:49:29 -0700131 public void collapse() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 enforceExpandStatusBar();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133
Joe Onorato4762c2d2010-05-17 15:42:59 -0700134 if (mBar != null) {
135 try {
136 mBar.animateCollapse();
137 } catch (RemoteException ex) {
138 }
139 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 }
141
142 public void disable(int what, IBinder token, String pkg) {
143 enforceStatusBar();
Joe Onoratof3f0e052010-05-14 18:49:29 -0700144
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800145 synchronized (mLock) {
146 disableLocked(what, token, pkg);
147 }
148 }
149
150 private void disableLocked(int what, IBinder token, String pkg) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700151 // It's important that the the callback and the call to mBar get done
152 // in the same order when multiple threads are calling this function
153 // so they are paired correctly. The messages on the handler will be
154 // handled in the order they were enqueued, but will be outside the lock.
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800155 manageDisableListLocked(what, token, pkg);
156 final int net = gatherDisableActionsLocked();
157 if (net != mDisabled) {
158 mDisabled = net;
159 mHandler.post(new Runnable() {
160 public void run() {
161 mNotificationCallbacks.onSetDisabled(net);
Joe Onoratof3f0e052010-05-14 18:49:29 -0700162 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800163 });
164 if (mBar != null) {
165 try {
166 mBar.disable(net);
167 } catch (RemoteException ex) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700168 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 }
171 }
172
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700173 public void setIcon(String slot, String iconPackage, int iconId, int iconLevel,
174 String contentDescription) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700176
177 synchronized (mIcons) {
178 int index = mIcons.getSlotIndex(slot);
179 if (index < 0) {
180 throw new SecurityException("invalid status bar icon slot: " + slot);
181 }
182
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700183 StatusBarIcon icon = new StatusBarIcon(iconPackage, iconId, iconLevel, 0,
184 contentDescription);
Joe Onorato66d7d012010-05-14 10:05:10 -0700185 //Slog.d(TAG, "setIcon slot=" + slot + " index=" + index + " icon=" + icon);
Joe Onorato0cbda992010-05-02 16:28:15 -0700186 mIcons.setIcon(index, icon);
187
Joe Onorato0cbda992010-05-02 16:28:15 -0700188 if (mBar != null) {
189 try {
190 mBar.setIcon(index, icon);
191 } catch (RemoteException ex) {
192 }
193 }
194 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195 }
196
Joe Onorato0cbda992010-05-02 16:28:15 -0700197 public void setIconVisibility(String slot, boolean visible) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700199
Joe Onorato514ad6632010-05-13 18:49:00 -0700200 synchronized (mIcons) {
201 int index = mIcons.getSlotIndex(slot);
202 if (index < 0) {
203 throw new SecurityException("invalid status bar icon slot: " + slot);
204 }
205
206 StatusBarIcon icon = mIcons.getIcon(index);
207 if (icon == null) {
208 return;
209 }
210
211 if (icon.visible != visible) {
212 icon.visible = visible;
213
Joe Onorato514ad6632010-05-13 18:49:00 -0700214 if (mBar != null) {
215 try {
216 mBar.setIcon(index, icon);
217 } catch (RemoteException ex) {
218 }
219 }
220 }
221 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700222 }
223
224 public void removeIcon(String slot) {
225 enforceStatusBar();
226
227 synchronized (mIcons) {
228 int index = mIcons.getSlotIndex(slot);
229 if (index < 0) {
230 throw new SecurityException("invalid status bar icon slot: " + slot);
231 }
232
233 mIcons.removeIcon(index);
234
Joe Onorato0cbda992010-05-02 16:28:15 -0700235 if (mBar != null) {
236 try {
237 mBar.removeIcon(index);
238 } catch (RemoteException ex) {
239 }
240 }
241 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242 }
243
Daniel Sandlere02d8082010-10-08 15:13:22 -0400244 /**
245 * Hide or show the on-screen Menu key. Only call this from the window manager, typically in
246 * response to a window with FLAG_NEEDS_MENU_KEY set.
247 */
Dianne Hackborn7d049322011-06-14 15:00:32 -0700248 public void topAppWindowChanged(final boolean menuVisible) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400249 enforceStatusBar();
250
Dianne Hackborn7d049322011-06-14 15:00:32 -0700251 if (SPEW) Slog.d(TAG, (menuVisible?"showing":"hiding") + " MENU key");
Daniel Sandlere02d8082010-10-08 15:13:22 -0400252
253 synchronized(mLock) {
Dianne Hackborn7d049322011-06-14 15:00:32 -0700254 mMenuVisible = menuVisible;
255 mHandler.post(new Runnable() {
256 public void run() {
257 if (mBar != null) {
258 try {
259 mBar.topAppWindowChanged(menuVisible);
260 } catch (RemoteException ex) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400261 }
262 }
Dianne Hackborn7d049322011-06-14 15:00:32 -0700263 }
264 });
Daniel Sandlere02d8082010-10-08 15:13:22 -0400265 }
266 }
267
Joe Onorato857fd9b2011-01-27 15:08:35 -0800268 public void setImeWindowStatus(final IBinder token, final int vis, final int backDisposition) {
satok06487a52010-10-29 11:37:18 +0900269 enforceStatusBar();
270
Joe Onorato857fd9b2011-01-27 15:08:35 -0800271 if (SPEW) {
272 Slog.d(TAG, "swetImeWindowStatus vis=" + vis + " backDisposition=" + backDisposition);
273 }
satok06487a52010-10-29 11:37:18 +0900274
275 synchronized(mLock) {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800276 // In case of IME change, we need to call up setImeWindowStatus() regardless of
277 // mImeWindowVis because mImeWindowVis may not have been set to false when the
satok06e07442010-11-02 19:46:55 +0900278 // previous IME was destroyed.
Joe Onorato857fd9b2011-01-27 15:08:35 -0800279 mImeWindowVis = vis;
280 mImeBackDisposition = backDisposition;
281 mImeToken = token;
satok06e07442010-11-02 19:46:55 +0900282 mHandler.post(new Runnable() {
283 public void run() {
284 if (mBar != null) {
285 try {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800286 mBar.setImeWindowStatus(token, vis, backDisposition);
satok06e07442010-11-02 19:46:55 +0900287 } catch (RemoteException ex) {
satok06487a52010-10-29 11:37:18 +0900288 }
289 }
satok06e07442010-11-02 19:46:55 +0900290 }
291 });
satok06487a52010-10-29 11:37:18 +0900292 }
293 }
294
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700295 public void setSystemUiVisibility(int vis, int mask) {
Joe Onorato55bf3802011-01-25 13:42:10 -0800296 // also allows calls from window manager which is in this process.
Joe Onoratof63b0f42010-09-12 17:03:19 -0400297 enforceStatusBarService();
298
Jeff Sharkey4519a022011-09-07 23:24:53 -0700299 if (SPEW) Slog.d(TAG, "setSystemUiVisibility(0x" + Integer.toHexString(vis) + ")");
Daniel Sandler60ee2562011-07-22 12:34:33 -0400300
Joe Onoratof63b0f42010-09-12 17:03:19 -0400301 synchronized (mLock) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700302 updateUiVisibilityLocked(vis, mask);
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800303 disableLocked(vis & StatusBarManager.DISABLE_MASK, mSysUiVisToken,
304 "WindowManager.LayoutParams");
Joe Onoratof63b0f42010-09-12 17:03:19 -0400305 }
306 }
307
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700308 private void updateUiVisibilityLocked(final int vis, final int mask) {
Daniel Sandler60ee2562011-07-22 12:34:33 -0400309 if (mSystemUiVisibility != vis) {
310 mSystemUiVisibility = vis;
Joe Onoratof63b0f42010-09-12 17:03:19 -0400311 mHandler.post(new Runnable() {
312 public void run() {
313 if (mBar != null) {
314 try {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700315 mBar.setSystemUiVisibility(vis, mask);
Joe Onoratof63b0f42010-09-12 17:03:19 -0400316 } catch (RemoteException ex) {
Joe Onorato93056472010-09-10 10:30:46 -0400317 }
318 }
Joe Onoratof63b0f42010-09-12 17:03:19 -0400319 }
320 });
Joe Onorato93056472010-09-10 10:30:46 -0400321 }
322 }
323
Jeff Brown2992ea72011-01-28 22:04:14 -0800324 public void setHardKeyboardEnabled(final boolean enabled) {
325 mHandler.post(new Runnable() {
326 public void run() {
327 mWindowManager.setHardKeyboardEnabled(enabled);
328 }
329 });
330 }
331
332 @Override
333 public void onHardKeyboardStatusChange(final boolean available, final boolean enabled) {
334 mHandler.post(new Runnable() {
335 public void run() {
336 if (mBar != null) {
337 try {
338 mBar.setHardKeyboardStatus(available, enabled);
339 } catch (RemoteException ex) {
340 }
341 }
342 }
343 });
344 }
345
Michael Jurka3b1fc472011-06-13 10:54:40 -0700346 @Override
347 public void toggleRecentApps() {
348 if (mBar != null) {
349 try {
350 mBar.toggleRecentApps();
351 } catch (RemoteException ex) {}
352 }
353 }
354
Michael Jurka7f2668c2012-03-27 07:49:52 -0700355 @Override
356 public void preloadRecentApps() {
357 if (mBar != null) {
358 try {
359 mBar.preloadRecentApps();
360 } catch (RemoteException ex) {}
361 }
362 }
363
364 @Override
365 public void cancelPreloadRecentApps() {
366 if (mBar != null) {
367 try {
368 mBar.cancelPreloadRecentApps();
369 } catch (RemoteException ex) {}
370 }
371 }
372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 private void enforceStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700374 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700375 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 }
377
378 private void enforceExpandStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700379 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.EXPAND_STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700380 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800381 }
382
Joe Onorato8bc6c512010-06-04 16:21:12 -0400383 private void enforceStatusBarService() {
384 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
385 "StatusBarManagerService");
386 }
387
Joe Onorato4762c2d2010-05-17 15:42:59 -0700388 // ================================================================================
389 // Callbacks from the status bar service.
390 // ================================================================================
Joe Onorato75199e32010-05-29 17:22:51 -0400391 public void registerStatusBar(IStatusBar bar, StatusBarIconList iconList,
Joe Onorato93056472010-09-10 10:30:46 -0400392 List<IBinder> notificationKeys, List<StatusBarNotification> notifications,
satokcd7cd292010-11-20 15:46:23 +0900393 int switches[], List<IBinder> binders) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400394 enforceStatusBarService();
395
Joe Onorato0cbda992010-05-02 16:28:15 -0700396 Slog.i(TAG, "registerStatusBar bar=" + bar);
397 mBar = bar;
Joe Onorato75199e32010-05-29 17:22:51 -0400398 synchronized (mIcons) {
399 iconList.copyFrom(mIcons);
400 }
401 synchronized (mNotifications) {
402 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
403 notificationKeys.add(e.getKey());
404 notifications.add(e.getValue());
405 }
406 }
Joe Onorato93056472010-09-10 10:30:46 -0400407 synchronized (mLock) {
Joe Onoratoe4c7b3f2010-10-30 12:15:03 -0700408 switches[0] = gatherDisableActionsLocked();
Daniel Sandler60ee2562011-07-22 12:34:33 -0400409 switches[1] = mSystemUiVisibility;
Joe Onoratoe4c7b3f2010-10-30 12:15:03 -0700410 switches[2] = mMenuVisible ? 1 : 0;
Joe Onorato857fd9b2011-01-27 15:08:35 -0800411 switches[3] = mImeWindowVis;
412 switches[4] = mImeBackDisposition;
413 binders.add(mImeToken);
Joe Onorato93056472010-09-10 10:30:46 -0400414 }
Jeff Brown2992ea72011-01-28 22:04:14 -0800415 switches[5] = mWindowManager.isHardKeyboardAvailable() ? 1 : 0;
416 switches[6] = mWindowManager.isHardKeyboardEnabled() ? 1 : 0;
Joe Onorato2314aab2010-04-08 16:41:23 -0500417 }
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400418
Joe Onorato4762c2d2010-05-17 15:42:59 -0700419 /**
Joe Onoratof1f25912010-06-07 11:52:41 -0700420 * The status bar service should call this each time the user brings the panel from
421 * invisible to visible in order to clear the notification light.
Joe Onorato4762c2d2010-05-17 15:42:59 -0700422 */
Joe Onoratof1f25912010-06-07 11:52:41 -0700423 public void onPanelRevealed() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400424 enforceStatusBarService();
425
Joe Onoratof1f25912010-06-07 11:52:41 -0700426 // tell the notification manager to turn off the lights.
427 mNotificationCallbacks.onPanelRevealed();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700428 }
429
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400430 public void onNotificationClick(String pkg, String tag, int id) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400431 enforceStatusBarService();
432
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400433 mNotificationCallbacks.onNotificationClick(pkg, tag, id);
434 }
435
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700436 public void onNotificationError(String pkg, String tag, int id,
437 int uid, int initialPid, String message) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400438 enforceStatusBarService();
439
Joe Onorato005847b2010-06-04 16:08:02 -0400440 // WARNING: this will call back into us to do the remove. Don't hold any locks.
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700441 mNotificationCallbacks.onNotificationError(pkg, tag, id, uid, initialPid, message);
Joe Onorato005847b2010-06-04 16:08:02 -0400442 }
443
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400444 public void onNotificationClear(String pkg, String tag, int id) {
445 enforceStatusBarService();
446
447 mNotificationCallbacks.onNotificationClear(pkg, tag, id);
448 }
449
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400450 public void onClearAllNotifications() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400451 enforceStatusBarService();
452
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400453 mNotificationCallbacks.onClearAll();
454 }
455
Joe Onorato18e69df2010-05-17 22:26:12 -0700456 // ================================================================================
457 // Callbacks for NotificationManagerService.
458 // ================================================================================
459 public IBinder addNotification(StatusBarNotification notification) {
460 synchronized (mNotifications) {
Joe Onoratoa0c56fe2010-05-20 10:21:52 -0700461 IBinder key = new Binder();
Joe Onorato75199e32010-05-29 17:22:51 -0400462 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400463 if (mBar != null) {
464 try {
465 mBar.addNotification(key, notification);
466 } catch (RemoteException ex) {
467 }
468 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700469 return key;
470 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700471 }
472
Joe Onorato18e69df2010-05-17 22:26:12 -0700473 public void updateNotification(IBinder key, StatusBarNotification notification) {
474 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400475 if (!mNotifications.containsKey(key)) {
476 throw new IllegalArgumentException("updateNotification key not found: " + key);
477 }
478 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400479 if (mBar != null) {
480 try {
481 mBar.updateNotification(key, notification);
482 } catch (RemoteException ex) {
483 }
484 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700485 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700486 }
487
488 public void removeNotification(IBinder key) {
Joe Onorato18e69df2010-05-17 22:26:12 -0700489 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400490 final StatusBarNotification n = mNotifications.remove(key);
491 if (n == null) {
Daniel Sandlerfe0806a2012-05-16 12:41:33 -0400492 Slog.e(TAG, "removeNotification key not found: " + key);
493 return;
Joe Onorato75199e32010-05-29 17:22:51 -0400494 }
Joe Onoratoe345fff2010-05-23 15:18:27 -0400495 if (mBar != null) {
496 try {
497 mBar.removeNotification(key);
498 } catch (RemoteException ex) {
499 }
500 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700501 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700502 }
Joe Onorato2314aab2010-04-08 16:41:23 -0500503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 // ================================================================================
505 // Can be called from any thread
506 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508 // lock on mDisableRecords
509 void manageDisableListLocked(int what, IBinder token, String pkg) {
510 if (SPEW) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700511 Slog.d(TAG, "manageDisableList what=0x" + Integer.toHexString(what) + " pkg=" + pkg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800512 }
513 // update the list
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800514 final int N = mDisableRecords.size();
515 DisableRecord tok = null;
516 int i;
517 for (i=0; i<N; i++) {
518 DisableRecord t = mDisableRecords.get(i);
519 if (t.token == token) {
520 tok = t;
521 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800522 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800523 }
524 if (what == 0 || !token.isBinderAlive()) {
525 if (tok != null) {
526 mDisableRecords.remove(i);
527 tok.token.unlinkToDeath(tok, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800529 } else {
530 if (tok == null) {
531 tok = new DisableRecord();
532 try {
533 token.linkToDeath(tok, 0);
534 }
535 catch (RemoteException ex) {
536 return; // give up
537 }
538 mDisableRecords.add(tok);
539 }
540 tok.what = what;
541 tok.token = token;
542 tok.pkg = pkg;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800543 }
544 }
545
546 // lock on mDisableRecords
547 int gatherDisableActionsLocked() {
548 final int N = mDisableRecords.size();
549 // gather the new net flags
550 int net = 0;
551 for (int i=0; i<N; i++) {
552 net |= mDisableRecords.get(i).what;
553 }
554 return net;
555 }
556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800557 // ================================================================================
558 // Always called from UI thread
559 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800561 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
562 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
563 != PackageManager.PERMISSION_GRANTED) {
564 pw.println("Permission Denial: can't dump StatusBar from from pid="
565 + Binder.getCallingPid()
566 + ", uid=" + Binder.getCallingUid());
567 return;
568 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700569
Joe Onorato0cbda992010-05-02 16:28:15 -0700570 synchronized (mIcons) {
571 mIcons.dump(pw);
572 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700573
574 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400575 int i=0;
576 pw.println("Notification list:");
577 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
578 pw.printf(" %2d: %s\n", i, e.getValue().toString());
579 i++;
580 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800581 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700582
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800583 synchronized (mLock) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 final int N = mDisableRecords.size();
585 pw.println(" mDisableRecords.size=" + N
586 + " mDisabled=0x" + Integer.toHexString(mDisabled));
587 for (int i=0; i<N; i++) {
588 DisableRecord tok = mDisableRecords.get(i);
589 pw.println(" [" + i + "] what=0x" + Integer.toHexString(tok.what)
590 + " pkg=" + tok.pkg + " token=" + tok.token);
591 }
592 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 }
594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800595 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
596 public void onReceive(Context context, Intent intent) {
597 String action = intent.getAction();
Joe Onoratof9e0e6b2009-09-08 16:24:36 -0400598 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
599 || Intent.ACTION_SCREEN_OFF.equals(action)) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700600 collapse();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800601 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700602 /*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800603 else if (Telephony.Intents.SPN_STRINGS_UPDATED_ACTION.equals(action)) {
604 updateNetworkName(intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_SPN, false),
605 intent.getStringExtra(Telephony.Intents.EXTRA_SPN),
606 intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_PLMN, false),
607 intent.getStringExtra(Telephony.Intents.EXTRA_PLMN));
608 }
609 else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
610 updateResources();
611 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700612 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800613 }
614 };
615
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800616}