blob: 9f53fadbd1912c46de79aacaf35083d12f049582 [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 Onorato0cbda992010-05-02 16:28:15 -070030
31import com.android.internal.statusbar.IStatusBar;
32import com.android.internal.statusbar.IStatusBarService;
33import com.android.internal.statusbar.StatusBarIcon;
34import com.android.internal.statusbar.StatusBarIconList;
Joe Onorato18e69df2010-05-17 22:26:12 -070035import com.android.internal.statusbar.StatusBarNotification;
Dianne Hackborna924dc0d2011-02-17 14:22:17 -080036import com.android.server.wm.WindowManagerService;
The Android Open Source Project10592532009-03-18 17:39:46 -070037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038import java.io.FileDescriptor;
39import java.io.PrintWriter;
40import java.util.ArrayList;
41import java.util.HashMap;
Joe Onorato75199e32010-05-29 17:22:51 -040042import java.util.List;
43import java.util.Map;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044
45
46/**
Joe Onoratof3f0e052010-05-14 18:49:29 -070047 * A note on locking: We rely on the fact that calls onto mBar are oneway or
48 * if they are local, that they just enqueue messages to not deadlock.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049 */
Joe Onorato089de882010-04-12 08:18:45 -070050public class StatusBarManagerService extends IStatusBarService.Stub
Jeff Brown2992ea72011-01-28 22:04:14 -080051 implements WindowManagerService.OnHardKeyboardStatusChangeListener
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052{
Joe Onorato4762c2d2010-05-17 15:42:59 -070053 static final String TAG = "StatusBarManagerService";
Joe Onorato431bb222010-10-18 19:13:23 -040054 static final boolean SPEW = false;
Joe Onoratodf7dbb62009-11-17 10:43:37 -080055
Joe Onoratof3f0e052010-05-14 18:49:29 -070056 final Context mContext;
Jeff Brown2992ea72011-01-28 22:04:14 -080057 final WindowManagerService mWindowManager;
Joe Onoratof3f0e052010-05-14 18:49:29 -070058 Handler mHandler = new Handler();
59 NotificationCallbacks mNotificationCallbacks;
Joe Onorato4762c2d2010-05-17 15:42:59 -070060 volatile IStatusBar mBar;
Joe Onoratof3f0e052010-05-14 18:49:29 -070061 StatusBarIconList mIcons = new StatusBarIconList();
Joe Onorato75199e32010-05-29 17:22:51 -040062 HashMap<IBinder,StatusBarNotification> mNotifications
63 = new HashMap<IBinder,StatusBarNotification>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064
Joe Onoratof3f0e052010-05-14 18:49:29 -070065 // for disabling the status bar
66 ArrayList<DisableRecord> mDisableRecords = new ArrayList<DisableRecord>();
Joe Onorato7bb8eeb2011-01-27 16:00:58 -080067 IBinder mSysUiVisToken = new Binder();
Joe Onoratof3f0e052010-05-14 18:49:29 -070068 int mDisabled = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069
Joe Onorato93056472010-09-10 10:30:46 -040070 Object mLock = new Object();
Daniel Sandler60ee2562011-07-22 12:34:33 -040071 // encompasses lights-out mode and other flags defined on View
72 int mSystemUiVisibility = 0;
Daniel Sandlere02d8082010-10-08 15:13:22 -040073 boolean mMenuVisible = false;
Joe Onorato857fd9b2011-01-27 15:08:35 -080074 int mImeWindowVis = 0;
75 int mImeBackDisposition;
76 IBinder mImeToken = null;
satok06487a52010-10-29 11:37:18 +090077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078 private class DisableRecord implements IBinder.DeathRecipient {
79 String pkg;
80 int what;
81 IBinder token;
82
83 public void binderDied() {
Joe Onorato8a9b2202010-02-26 18:56:32 -080084 Slog.i(TAG, "binder died for pkg=" + pkg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085 disable(0, token, pkg);
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -070086 token.unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087 }
88 }
89
90 public interface NotificationCallbacks {
91 void onSetDisabled(int status);
92 void onClearAll();
Fred Quintana6ecaff12009-09-25 14:23:13 -070093 void onNotificationClick(String pkg, String tag, int id);
Daniel Sandler0f0b11c2010-08-04 15:54:58 -040094 void onNotificationClear(String pkg, String tag, int id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 void onPanelRevealed();
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -070096 void onNotificationError(String pkg, String tag, int id,
97 int uid, int initialPid, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 }
99
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 /**
101 * Construct the service, add the status bar view to the window manager
102 */
Jeff Brown2992ea72011-01-28 22:04:14 -0800103 public StatusBarManagerService(Context context, WindowManagerService windowManager) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104 mContext = context;
Jeff Brown2992ea72011-01-28 22:04:14 -0800105 mWindowManager = windowManager;
106 mWindowManager.setOnHardKeyboardStatusChangeListener(this);
Joe Onorato0cbda992010-05-02 16:28:15 -0700107
108 final Resources res = context.getResources();
Joe Onorato75144ea2010-06-07 12:36:25 -0700109 mIcons.defineSlots(res.getStringArray(com.android.internal.R.array.config_statusBarIcons));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110 }
111
112 public void setNotificationCallbacks(NotificationCallbacks listener) {
113 mNotificationCallbacks = listener;
114 }
115
116 // ================================================================================
Joe Onorato25f95f92010-04-08 18:37:10 -0500117 // From IStatusBarService
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118 // ================================================================================
Joe Onoratof3f0e052010-05-14 18:49:29 -0700119 public void expand() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120 enforceExpandStatusBar();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700121
122 if (mBar != null) {
123 try {
124 mBar.animateExpand();
125 } catch (RemoteException ex) {
126 }
127 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 }
129
Joe Onoratof3f0e052010-05-14 18:49:29 -0700130 public void collapse() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131 enforceExpandStatusBar();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132
Joe Onorato4762c2d2010-05-17 15:42:59 -0700133 if (mBar != null) {
134 try {
135 mBar.animateCollapse();
136 } catch (RemoteException ex) {
137 }
138 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 }
140
141 public void disable(int what, IBinder token, String pkg) {
142 enforceStatusBar();
Joe Onoratof3f0e052010-05-14 18:49:29 -0700143
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800144 synchronized (mLock) {
145 disableLocked(what, token, pkg);
146 }
147 }
148
149 private void disableLocked(int what, IBinder token, String pkg) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700150 // It's important that the the callback and the call to mBar get done
151 // in the same order when multiple threads are calling this function
152 // so they are paired correctly. The messages on the handler will be
153 // handled in the order they were enqueued, but will be outside the lock.
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800154 manageDisableListLocked(what, token, pkg);
155 final int net = gatherDisableActionsLocked();
156 if (net != mDisabled) {
157 mDisabled = net;
158 mHandler.post(new Runnable() {
159 public void run() {
160 mNotificationCallbacks.onSetDisabled(net);
Joe Onoratof3f0e052010-05-14 18:49:29 -0700161 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800162 });
163 if (mBar != null) {
164 try {
165 mBar.disable(net);
166 } catch (RemoteException ex) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700167 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 }
170 }
171
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700172 public void setIcon(String slot, String iconPackage, int iconId, int iconLevel,
173 String contentDescription) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700175
176 synchronized (mIcons) {
177 int index = mIcons.getSlotIndex(slot);
178 if (index < 0) {
179 throw new SecurityException("invalid status bar icon slot: " + slot);
180 }
181
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700182 StatusBarIcon icon = new StatusBarIcon(iconPackage, iconId, iconLevel, 0,
183 contentDescription);
Joe Onorato66d7d012010-05-14 10:05:10 -0700184 //Slog.d(TAG, "setIcon slot=" + slot + " index=" + index + " icon=" + icon);
Joe Onorato0cbda992010-05-02 16:28:15 -0700185 mIcons.setIcon(index, icon);
186
Joe Onorato0cbda992010-05-02 16:28:15 -0700187 if (mBar != null) {
188 try {
189 mBar.setIcon(index, icon);
190 } catch (RemoteException ex) {
191 }
192 }
193 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194 }
195
Joe Onorato0cbda992010-05-02 16:28:15 -0700196 public void setIconVisibility(String slot, boolean visible) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700198
Joe Onorato514ad6632010-05-13 18:49:00 -0700199 synchronized (mIcons) {
200 int index = mIcons.getSlotIndex(slot);
201 if (index < 0) {
202 throw new SecurityException("invalid status bar icon slot: " + slot);
203 }
204
205 StatusBarIcon icon = mIcons.getIcon(index);
206 if (icon == null) {
207 return;
208 }
209
210 if (icon.visible != visible) {
211 icon.visible = visible;
212
Joe Onorato514ad6632010-05-13 18:49:00 -0700213 if (mBar != null) {
214 try {
215 mBar.setIcon(index, icon);
216 } catch (RemoteException ex) {
217 }
218 }
219 }
220 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700221 }
222
223 public void removeIcon(String slot) {
224 enforceStatusBar();
225
226 synchronized (mIcons) {
227 int index = mIcons.getSlotIndex(slot);
228 if (index < 0) {
229 throw new SecurityException("invalid status bar icon slot: " + slot);
230 }
231
232 mIcons.removeIcon(index);
233
Joe Onorato0cbda992010-05-02 16:28:15 -0700234 if (mBar != null) {
235 try {
236 mBar.removeIcon(index);
237 } catch (RemoteException ex) {
238 }
239 }
240 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800241 }
242
Daniel Sandlere02d8082010-10-08 15:13:22 -0400243 /**
244 * Hide or show the on-screen Menu key. Only call this from the window manager, typically in
245 * response to a window with FLAG_NEEDS_MENU_KEY set.
246 */
Dianne Hackborn7d049322011-06-14 15:00:32 -0700247 public void topAppWindowChanged(final boolean menuVisible) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400248 enforceStatusBar();
249
Dianne Hackborn7d049322011-06-14 15:00:32 -0700250 if (SPEW) Slog.d(TAG, (menuVisible?"showing":"hiding") + " MENU key");
Daniel Sandlere02d8082010-10-08 15:13:22 -0400251
252 synchronized(mLock) {
Dianne Hackborn7d049322011-06-14 15:00:32 -0700253 mMenuVisible = menuVisible;
254 mHandler.post(new Runnable() {
255 public void run() {
256 if (mBar != null) {
257 try {
258 mBar.topAppWindowChanged(menuVisible);
259 } catch (RemoteException ex) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400260 }
261 }
Dianne Hackborn7d049322011-06-14 15:00:32 -0700262 }
263 });
Daniel Sandlere02d8082010-10-08 15:13:22 -0400264 }
265 }
266
Joe Onorato857fd9b2011-01-27 15:08:35 -0800267 public void setImeWindowStatus(final IBinder token, final int vis, final int backDisposition) {
satok06487a52010-10-29 11:37:18 +0900268 enforceStatusBar();
269
Joe Onorato857fd9b2011-01-27 15:08:35 -0800270 if (SPEW) {
271 Slog.d(TAG, "swetImeWindowStatus vis=" + vis + " backDisposition=" + backDisposition);
272 }
satok06487a52010-10-29 11:37:18 +0900273
274 synchronized(mLock) {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800275 // In case of IME change, we need to call up setImeWindowStatus() regardless of
276 // mImeWindowVis because mImeWindowVis may not have been set to false when the
satok06e07442010-11-02 19:46:55 +0900277 // previous IME was destroyed.
Joe Onorato857fd9b2011-01-27 15:08:35 -0800278 mImeWindowVis = vis;
279 mImeBackDisposition = backDisposition;
280 mImeToken = token;
satok06e07442010-11-02 19:46:55 +0900281 mHandler.post(new Runnable() {
282 public void run() {
283 if (mBar != null) {
284 try {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800285 mBar.setImeWindowStatus(token, vis, backDisposition);
satok06e07442010-11-02 19:46:55 +0900286 } catch (RemoteException ex) {
satok06487a52010-10-29 11:37:18 +0900287 }
288 }
satok06e07442010-11-02 19:46:55 +0900289 }
290 });
satok06487a52010-10-29 11:37:18 +0900291 }
292 }
293
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700294 public void setSystemUiVisibility(int vis, int mask) {
Joe Onorato55bf3802011-01-25 13:42:10 -0800295 // also allows calls from window manager which is in this process.
Joe Onoratof63b0f42010-09-12 17:03:19 -0400296 enforceStatusBarService();
297
Jeff Sharkey4519a022011-09-07 23:24:53 -0700298 if (SPEW) Slog.d(TAG, "setSystemUiVisibility(0x" + Integer.toHexString(vis) + ")");
Daniel Sandler60ee2562011-07-22 12:34:33 -0400299
Joe Onoratof63b0f42010-09-12 17:03:19 -0400300 synchronized (mLock) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700301 updateUiVisibilityLocked(vis, mask);
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800302 disableLocked(vis & StatusBarManager.DISABLE_MASK, mSysUiVisToken,
303 "WindowManager.LayoutParams");
Joe Onoratof63b0f42010-09-12 17:03:19 -0400304 }
305 }
306
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700307 private void updateUiVisibilityLocked(final int vis, final int mask) {
Daniel Sandler60ee2562011-07-22 12:34:33 -0400308 if (mSystemUiVisibility != vis) {
309 mSystemUiVisibility = vis;
Joe Onoratof63b0f42010-09-12 17:03:19 -0400310 mHandler.post(new Runnable() {
311 public void run() {
312 if (mBar != null) {
313 try {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700314 mBar.setSystemUiVisibility(vis, mask);
Joe Onoratof63b0f42010-09-12 17:03:19 -0400315 } catch (RemoteException ex) {
Joe Onorato93056472010-09-10 10:30:46 -0400316 }
317 }
Joe Onoratof63b0f42010-09-12 17:03:19 -0400318 }
319 });
Joe Onorato93056472010-09-10 10:30:46 -0400320 }
321 }
322
Jeff Brown2992ea72011-01-28 22:04:14 -0800323 public void setHardKeyboardEnabled(final boolean enabled) {
324 mHandler.post(new Runnable() {
325 public void run() {
326 mWindowManager.setHardKeyboardEnabled(enabled);
327 }
328 });
329 }
330
331 @Override
332 public void onHardKeyboardStatusChange(final boolean available, final boolean enabled) {
333 mHandler.post(new Runnable() {
334 public void run() {
335 if (mBar != null) {
336 try {
337 mBar.setHardKeyboardStatus(available, enabled);
338 } catch (RemoteException ex) {
339 }
340 }
341 }
342 });
343 }
344
Michael Jurka3b1fc472011-06-13 10:54:40 -0700345 @Override
346 public void toggleRecentApps() {
347 if (mBar != null) {
348 try {
349 mBar.toggleRecentApps();
350 } catch (RemoteException ex) {}
351 }
352 }
353
Michael Jurka7f2668c2012-03-27 07:49:52 -0700354 @Override
355 public void preloadRecentApps() {
356 if (mBar != null) {
357 try {
358 mBar.preloadRecentApps();
359 } catch (RemoteException ex) {}
360 }
361 }
362
363 @Override
364 public void cancelPreloadRecentApps() {
365 if (mBar != null) {
366 try {
367 mBar.cancelPreloadRecentApps();
368 } catch (RemoteException ex) {}
369 }
370 }
371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372 private void enforceStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700373 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700374 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 }
376
377 private void enforceExpandStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700378 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.EXPAND_STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700379 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380 }
381
Joe Onorato8bc6c512010-06-04 16:21:12 -0400382 private void enforceStatusBarService() {
383 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
384 "StatusBarManagerService");
385 }
386
Joe Onorato4762c2d2010-05-17 15:42:59 -0700387 // ================================================================================
388 // Callbacks from the status bar service.
389 // ================================================================================
Joe Onorato75199e32010-05-29 17:22:51 -0400390 public void registerStatusBar(IStatusBar bar, StatusBarIconList iconList,
Joe Onorato93056472010-09-10 10:30:46 -0400391 List<IBinder> notificationKeys, List<StatusBarNotification> notifications,
satokcd7cd292010-11-20 15:46:23 +0900392 int switches[], List<IBinder> binders) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400393 enforceStatusBarService();
394
Joe Onorato0cbda992010-05-02 16:28:15 -0700395 Slog.i(TAG, "registerStatusBar bar=" + bar);
396 mBar = bar;
Joe Onorato75199e32010-05-29 17:22:51 -0400397 synchronized (mIcons) {
398 iconList.copyFrom(mIcons);
399 }
400 synchronized (mNotifications) {
401 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
402 notificationKeys.add(e.getKey());
403 notifications.add(e.getValue());
404 }
405 }
Joe Onorato93056472010-09-10 10:30:46 -0400406 synchronized (mLock) {
Joe Onoratoe4c7b3f2010-10-30 12:15:03 -0700407 switches[0] = gatherDisableActionsLocked();
Daniel Sandler60ee2562011-07-22 12:34:33 -0400408 switches[1] = mSystemUiVisibility;
Joe Onoratoe4c7b3f2010-10-30 12:15:03 -0700409 switches[2] = mMenuVisible ? 1 : 0;
Joe Onorato857fd9b2011-01-27 15:08:35 -0800410 switches[3] = mImeWindowVis;
411 switches[4] = mImeBackDisposition;
412 binders.add(mImeToken);
Joe Onorato93056472010-09-10 10:30:46 -0400413 }
Jeff Brown2992ea72011-01-28 22:04:14 -0800414 switches[5] = mWindowManager.isHardKeyboardAvailable() ? 1 : 0;
415 switches[6] = mWindowManager.isHardKeyboardEnabled() ? 1 : 0;
Joe Onorato2314aab2010-04-08 16:41:23 -0500416 }
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400417
Joe Onorato4762c2d2010-05-17 15:42:59 -0700418 /**
Joe Onoratof1f25912010-06-07 11:52:41 -0700419 * The status bar service should call this each time the user brings the panel from
420 * invisible to visible in order to clear the notification light.
Joe Onorato4762c2d2010-05-17 15:42:59 -0700421 */
Joe Onoratof1f25912010-06-07 11:52:41 -0700422 public void onPanelRevealed() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400423 enforceStatusBarService();
424
Joe Onoratof1f25912010-06-07 11:52:41 -0700425 // tell the notification manager to turn off the lights.
426 mNotificationCallbacks.onPanelRevealed();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700427 }
428
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400429 public void onNotificationClick(String pkg, String tag, int id) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400430 enforceStatusBarService();
431
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400432 mNotificationCallbacks.onNotificationClick(pkg, tag, id);
433 }
434
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700435 public void onNotificationError(String pkg, String tag, int id,
436 int uid, int initialPid, String message) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400437 enforceStatusBarService();
438
Joe Onorato005847b2010-06-04 16:08:02 -0400439 // WARNING: this will call back into us to do the remove. Don't hold any locks.
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700440 mNotificationCallbacks.onNotificationError(pkg, tag, id, uid, initialPid, message);
Joe Onorato005847b2010-06-04 16:08:02 -0400441 }
442
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400443 public void onNotificationClear(String pkg, String tag, int id) {
444 enforceStatusBarService();
445
446 mNotificationCallbacks.onNotificationClear(pkg, tag, id);
447 }
448
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400449 public void onClearAllNotifications() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400450 enforceStatusBarService();
451
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400452 mNotificationCallbacks.onClearAll();
453 }
454
Joe Onorato18e69df2010-05-17 22:26:12 -0700455 // ================================================================================
456 // Callbacks for NotificationManagerService.
457 // ================================================================================
458 public IBinder addNotification(StatusBarNotification notification) {
459 synchronized (mNotifications) {
Joe Onoratoa0c56fe2010-05-20 10:21:52 -0700460 IBinder key = new Binder();
Joe Onorato75199e32010-05-29 17:22:51 -0400461 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400462 if (mBar != null) {
463 try {
464 mBar.addNotification(key, notification);
465 } catch (RemoteException ex) {
466 }
467 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700468 return key;
469 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700470 }
471
Joe Onorato18e69df2010-05-17 22:26:12 -0700472 public void updateNotification(IBinder key, StatusBarNotification notification) {
473 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400474 if (!mNotifications.containsKey(key)) {
475 throw new IllegalArgumentException("updateNotification key not found: " + key);
476 }
477 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400478 if (mBar != null) {
479 try {
480 mBar.updateNotification(key, notification);
481 } catch (RemoteException ex) {
482 }
483 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700484 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700485 }
486
487 public void removeNotification(IBinder key) {
Joe Onorato18e69df2010-05-17 22:26:12 -0700488 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400489 final StatusBarNotification n = mNotifications.remove(key);
490 if (n == null) {
Daniel Sandlerfe0806a2012-05-16 12:41:33 -0400491 Slog.e(TAG, "removeNotification key not found: " + key);
492 return;
Joe Onorato75199e32010-05-29 17:22:51 -0400493 }
Joe Onoratoe345fff2010-05-23 15:18:27 -0400494 if (mBar != null) {
495 try {
496 mBar.removeNotification(key);
497 } catch (RemoteException ex) {
498 }
499 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700500 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700501 }
Joe Onorato2314aab2010-04-08 16:41:23 -0500502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503 // ================================================================================
504 // Can be called from any thread
505 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 // lock on mDisableRecords
508 void manageDisableListLocked(int what, IBinder token, String pkg) {
509 if (SPEW) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700510 Slog.d(TAG, "manageDisableList what=0x" + Integer.toHexString(what) + " pkg=" + pkg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511 }
512 // update the list
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800513 final int N = mDisableRecords.size();
514 DisableRecord tok = null;
515 int i;
516 for (i=0; i<N; i++) {
517 DisableRecord t = mDisableRecords.get(i);
518 if (t.token == token) {
519 tok = t;
520 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800521 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800522 }
523 if (what == 0 || !token.isBinderAlive()) {
524 if (tok != null) {
525 mDisableRecords.remove(i);
526 tok.token.unlinkToDeath(tok, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800527 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800528 } else {
529 if (tok == null) {
530 tok = new DisableRecord();
531 try {
532 token.linkToDeath(tok, 0);
533 }
534 catch (RemoteException ex) {
535 return; // give up
536 }
537 mDisableRecords.add(tok);
538 }
539 tok.what = what;
540 tok.token = token;
541 tok.pkg = pkg;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800542 }
543 }
544
545 // lock on mDisableRecords
546 int gatherDisableActionsLocked() {
547 final int N = mDisableRecords.size();
548 // gather the new net flags
549 int net = 0;
550 for (int i=0; i<N; i++) {
551 net |= mDisableRecords.get(i).what;
552 }
553 return net;
554 }
555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556 // ================================================================================
557 // Always called from UI thread
558 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800559
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800560 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
561 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
562 != PackageManager.PERMISSION_GRANTED) {
563 pw.println("Permission Denial: can't dump StatusBar from from pid="
564 + Binder.getCallingPid()
565 + ", uid=" + Binder.getCallingUid());
566 return;
567 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700568
Joe Onorato0cbda992010-05-02 16:28:15 -0700569 synchronized (mIcons) {
570 mIcons.dump(pw);
571 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700572
573 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400574 int i=0;
575 pw.println("Notification list:");
576 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
577 pw.printf(" %2d: %s\n", i, e.getValue().toString());
578 i++;
579 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800580 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700581
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800582 synchronized (mLock) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 final int N = mDisableRecords.size();
584 pw.println(" mDisableRecords.size=" + N
585 + " mDisabled=0x" + Integer.toHexString(mDisabled));
586 for (int i=0; i<N; i++) {
587 DisableRecord tok = mDisableRecords.get(i);
588 pw.println(" [" + i + "] what=0x" + Integer.toHexString(tok.what)
589 + " pkg=" + tok.pkg + " token=" + tok.token);
590 }
591 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800592 }
593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
595 public void onReceive(Context context, Intent intent) {
596 String action = intent.getAction();
Joe Onoratof9e0e6b2009-09-08 16:24:36 -0400597 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
598 || Intent.ACTION_SCREEN_OFF.equals(action)) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700599 collapse();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800600 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700601 /*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800602 else if (Telephony.Intents.SPN_STRINGS_UPDATED_ACTION.equals(action)) {
603 updateNetworkName(intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_SPN, false),
604 intent.getStringExtra(Telephony.Intents.EXTRA_SPN),
605 intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_PLMN, false),
606 intent.getStringExtra(Telephony.Intents.EXTRA_PLMN));
607 }
608 else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
609 updateResources();
610 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700611 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800612 }
613 };
614
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800615}