blob: 46dcedcefc6ced801d50311dccedfbc485d8adb6 [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;
Amith Yamasani98edc952012-09-25 14:09:27 -070029import android.os.UserHandle;
Joe Onorato8a9b2202010-02-26 18:56:32 -080030import android.util.Slog;
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
Amith Yamasani98edc952012-09-25 14:09:27 -0700183 StatusBarIcon icon = new StatusBarIcon(iconPackage, UserHandle.OWNER, iconId,
184 iconLevel, 0,
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700185 contentDescription);
Joe Onorato66d7d012010-05-14 10:05:10 -0700186 //Slog.d(TAG, "setIcon slot=" + slot + " index=" + index + " icon=" + icon);
Joe Onorato0cbda992010-05-02 16:28:15 -0700187 mIcons.setIcon(index, icon);
188
Joe Onorato0cbda992010-05-02 16:28:15 -0700189 if (mBar != null) {
190 try {
191 mBar.setIcon(index, icon);
192 } catch (RemoteException ex) {
193 }
194 }
195 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800196 }
197
Joe Onorato0cbda992010-05-02 16:28:15 -0700198 public void setIconVisibility(String slot, boolean visible) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700200
Joe Onorato514ad6632010-05-13 18:49:00 -0700201 synchronized (mIcons) {
202 int index = mIcons.getSlotIndex(slot);
203 if (index < 0) {
204 throw new SecurityException("invalid status bar icon slot: " + slot);
205 }
206
207 StatusBarIcon icon = mIcons.getIcon(index);
208 if (icon == null) {
209 return;
210 }
211
212 if (icon.visible != visible) {
213 icon.visible = visible;
214
Joe Onorato514ad6632010-05-13 18:49:00 -0700215 if (mBar != null) {
216 try {
217 mBar.setIcon(index, icon);
218 } catch (RemoteException ex) {
219 }
220 }
221 }
222 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700223 }
224
225 public void removeIcon(String slot) {
226 enforceStatusBar();
227
228 synchronized (mIcons) {
229 int index = mIcons.getSlotIndex(slot);
230 if (index < 0) {
231 throw new SecurityException("invalid status bar icon slot: " + slot);
232 }
233
234 mIcons.removeIcon(index);
235
Joe Onorato0cbda992010-05-02 16:28:15 -0700236 if (mBar != null) {
237 try {
238 mBar.removeIcon(index);
239 } catch (RemoteException ex) {
240 }
241 }
242 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243 }
244
Daniel Sandlere02d8082010-10-08 15:13:22 -0400245 /**
246 * Hide or show the on-screen Menu key. Only call this from the window manager, typically in
247 * response to a window with FLAG_NEEDS_MENU_KEY set.
248 */
Dianne Hackborn7d049322011-06-14 15:00:32 -0700249 public void topAppWindowChanged(final boolean menuVisible) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400250 enforceStatusBar();
251
Dianne Hackborn7d049322011-06-14 15:00:32 -0700252 if (SPEW) Slog.d(TAG, (menuVisible?"showing":"hiding") + " MENU key");
Daniel Sandlere02d8082010-10-08 15:13:22 -0400253
254 synchronized(mLock) {
Dianne Hackborn7d049322011-06-14 15:00:32 -0700255 mMenuVisible = menuVisible;
256 mHandler.post(new Runnable() {
257 public void run() {
258 if (mBar != null) {
259 try {
260 mBar.topAppWindowChanged(menuVisible);
261 } catch (RemoteException ex) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400262 }
263 }
Dianne Hackborn7d049322011-06-14 15:00:32 -0700264 }
265 });
Daniel Sandlere02d8082010-10-08 15:13:22 -0400266 }
267 }
268
Joe Onorato857fd9b2011-01-27 15:08:35 -0800269 public void setImeWindowStatus(final IBinder token, final int vis, final int backDisposition) {
satok06487a52010-10-29 11:37:18 +0900270 enforceStatusBar();
271
Joe Onorato857fd9b2011-01-27 15:08:35 -0800272 if (SPEW) {
273 Slog.d(TAG, "swetImeWindowStatus vis=" + vis + " backDisposition=" + backDisposition);
274 }
satok06487a52010-10-29 11:37:18 +0900275
276 synchronized(mLock) {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800277 // In case of IME change, we need to call up setImeWindowStatus() regardless of
278 // mImeWindowVis because mImeWindowVis may not have been set to false when the
satok06e07442010-11-02 19:46:55 +0900279 // previous IME was destroyed.
Joe Onorato857fd9b2011-01-27 15:08:35 -0800280 mImeWindowVis = vis;
281 mImeBackDisposition = backDisposition;
282 mImeToken = token;
satok06e07442010-11-02 19:46:55 +0900283 mHandler.post(new Runnable() {
284 public void run() {
285 if (mBar != null) {
286 try {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800287 mBar.setImeWindowStatus(token, vis, backDisposition);
satok06e07442010-11-02 19:46:55 +0900288 } catch (RemoteException ex) {
satok06487a52010-10-29 11:37:18 +0900289 }
290 }
satok06e07442010-11-02 19:46:55 +0900291 }
292 });
satok06487a52010-10-29 11:37:18 +0900293 }
294 }
295
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700296 public void setSystemUiVisibility(int vis, int mask) {
Joe Onorato55bf3802011-01-25 13:42:10 -0800297 // also allows calls from window manager which is in this process.
Joe Onoratof63b0f42010-09-12 17:03:19 -0400298 enforceStatusBarService();
299
Jeff Sharkey4519a022011-09-07 23:24:53 -0700300 if (SPEW) Slog.d(TAG, "setSystemUiVisibility(0x" + Integer.toHexString(vis) + ")");
Daniel Sandler60ee2562011-07-22 12:34:33 -0400301
Joe Onoratof63b0f42010-09-12 17:03:19 -0400302 synchronized (mLock) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700303 updateUiVisibilityLocked(vis, mask);
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800304 disableLocked(vis & StatusBarManager.DISABLE_MASK, mSysUiVisToken,
305 "WindowManager.LayoutParams");
Joe Onoratof63b0f42010-09-12 17:03:19 -0400306 }
307 }
308
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700309 private void updateUiVisibilityLocked(final int vis, final int mask) {
Daniel Sandler60ee2562011-07-22 12:34:33 -0400310 if (mSystemUiVisibility != vis) {
311 mSystemUiVisibility = vis;
Joe Onoratof63b0f42010-09-12 17:03:19 -0400312 mHandler.post(new Runnable() {
313 public void run() {
314 if (mBar != null) {
315 try {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700316 mBar.setSystemUiVisibility(vis, mask);
Joe Onoratof63b0f42010-09-12 17:03:19 -0400317 } catch (RemoteException ex) {
Joe Onorato93056472010-09-10 10:30:46 -0400318 }
319 }
Joe Onoratof63b0f42010-09-12 17:03:19 -0400320 }
321 });
Joe Onorato93056472010-09-10 10:30:46 -0400322 }
323 }
324
Jeff Brown2992ea72011-01-28 22:04:14 -0800325 public void setHardKeyboardEnabled(final boolean enabled) {
326 mHandler.post(new Runnable() {
327 public void run() {
328 mWindowManager.setHardKeyboardEnabled(enabled);
329 }
330 });
331 }
332
333 @Override
334 public void onHardKeyboardStatusChange(final boolean available, final boolean enabled) {
335 mHandler.post(new Runnable() {
336 public void run() {
337 if (mBar != null) {
338 try {
339 mBar.setHardKeyboardStatus(available, enabled);
340 } catch (RemoteException ex) {
341 }
342 }
343 }
344 });
345 }
346
Michael Jurka3b1fc472011-06-13 10:54:40 -0700347 @Override
348 public void toggleRecentApps() {
349 if (mBar != null) {
350 try {
351 mBar.toggleRecentApps();
352 } catch (RemoteException ex) {}
353 }
354 }
355
Michael Jurka7f2668c2012-03-27 07:49:52 -0700356 @Override
357 public void preloadRecentApps() {
358 if (mBar != null) {
359 try {
360 mBar.preloadRecentApps();
361 } catch (RemoteException ex) {}
362 }
363 }
364
365 @Override
366 public void cancelPreloadRecentApps() {
367 if (mBar != null) {
368 try {
369 mBar.cancelPreloadRecentApps();
370 } catch (RemoteException ex) {}
371 }
372 }
373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 private void enforceStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700375 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700376 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377 }
378
379 private void enforceExpandStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700380 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.EXPAND_STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700381 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 }
383
Joe Onorato8bc6c512010-06-04 16:21:12 -0400384 private void enforceStatusBarService() {
385 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
386 "StatusBarManagerService");
387 }
388
Joe Onorato4762c2d2010-05-17 15:42:59 -0700389 // ================================================================================
390 // Callbacks from the status bar service.
391 // ================================================================================
Joe Onorato75199e32010-05-29 17:22:51 -0400392 public void registerStatusBar(IStatusBar bar, StatusBarIconList iconList,
Joe Onorato93056472010-09-10 10:30:46 -0400393 List<IBinder> notificationKeys, List<StatusBarNotification> notifications,
satokcd7cd292010-11-20 15:46:23 +0900394 int switches[], List<IBinder> binders) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400395 enforceStatusBarService();
396
Joe Onorato0cbda992010-05-02 16:28:15 -0700397 Slog.i(TAG, "registerStatusBar bar=" + bar);
398 mBar = bar;
Joe Onorato75199e32010-05-29 17:22:51 -0400399 synchronized (mIcons) {
400 iconList.copyFrom(mIcons);
401 }
402 synchronized (mNotifications) {
403 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
404 notificationKeys.add(e.getKey());
405 notifications.add(e.getValue());
406 }
407 }
Joe Onorato93056472010-09-10 10:30:46 -0400408 synchronized (mLock) {
Joe Onoratoe4c7b3f2010-10-30 12:15:03 -0700409 switches[0] = gatherDisableActionsLocked();
Daniel Sandler60ee2562011-07-22 12:34:33 -0400410 switches[1] = mSystemUiVisibility;
Joe Onoratoe4c7b3f2010-10-30 12:15:03 -0700411 switches[2] = mMenuVisible ? 1 : 0;
Joe Onorato857fd9b2011-01-27 15:08:35 -0800412 switches[3] = mImeWindowVis;
413 switches[4] = mImeBackDisposition;
414 binders.add(mImeToken);
Joe Onorato93056472010-09-10 10:30:46 -0400415 }
Jeff Brown2992ea72011-01-28 22:04:14 -0800416 switches[5] = mWindowManager.isHardKeyboardAvailable() ? 1 : 0;
417 switches[6] = mWindowManager.isHardKeyboardEnabled() ? 1 : 0;
Joe Onorato2314aab2010-04-08 16:41:23 -0500418 }
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400419
Joe Onorato4762c2d2010-05-17 15:42:59 -0700420 /**
Joe Onoratof1f25912010-06-07 11:52:41 -0700421 * The status bar service should call this each time the user brings the panel from
422 * invisible to visible in order to clear the notification light.
Joe Onorato4762c2d2010-05-17 15:42:59 -0700423 */
Joe Onoratof1f25912010-06-07 11:52:41 -0700424 public void onPanelRevealed() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400425 enforceStatusBarService();
426
Joe Onoratof1f25912010-06-07 11:52:41 -0700427 // tell the notification manager to turn off the lights.
428 mNotificationCallbacks.onPanelRevealed();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700429 }
430
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400431 public void onNotificationClick(String pkg, String tag, int id) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400432 enforceStatusBarService();
433
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400434 mNotificationCallbacks.onNotificationClick(pkg, tag, id);
435 }
436
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700437 public void onNotificationError(String pkg, String tag, int id,
438 int uid, int initialPid, String message) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400439 enforceStatusBarService();
440
Joe Onorato005847b2010-06-04 16:08:02 -0400441 // WARNING: this will call back into us to do the remove. Don't hold any locks.
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700442 mNotificationCallbacks.onNotificationError(pkg, tag, id, uid, initialPid, message);
Joe Onorato005847b2010-06-04 16:08:02 -0400443 }
444
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400445 public void onNotificationClear(String pkg, String tag, int id) {
446 enforceStatusBarService();
447
448 mNotificationCallbacks.onNotificationClear(pkg, tag, id);
449 }
450
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400451 public void onClearAllNotifications() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400452 enforceStatusBarService();
453
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400454 mNotificationCallbacks.onClearAll();
455 }
456
Joe Onorato18e69df2010-05-17 22:26:12 -0700457 // ================================================================================
458 // Callbacks for NotificationManagerService.
459 // ================================================================================
460 public IBinder addNotification(StatusBarNotification notification) {
461 synchronized (mNotifications) {
Joe Onoratoa0c56fe2010-05-20 10:21:52 -0700462 IBinder key = new Binder();
Joe Onorato75199e32010-05-29 17:22:51 -0400463 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400464 if (mBar != null) {
465 try {
466 mBar.addNotification(key, notification);
467 } catch (RemoteException ex) {
468 }
469 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700470 return key;
471 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700472 }
473
Joe Onorato18e69df2010-05-17 22:26:12 -0700474 public void updateNotification(IBinder key, StatusBarNotification notification) {
475 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400476 if (!mNotifications.containsKey(key)) {
477 throw new IllegalArgumentException("updateNotification key not found: " + key);
478 }
479 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400480 if (mBar != null) {
481 try {
482 mBar.updateNotification(key, notification);
483 } catch (RemoteException ex) {
484 }
485 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700486 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700487 }
488
489 public void removeNotification(IBinder key) {
Joe Onorato18e69df2010-05-17 22:26:12 -0700490 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400491 final StatusBarNotification n = mNotifications.remove(key);
492 if (n == null) {
Daniel Sandlerfe0806a2012-05-16 12:41:33 -0400493 Slog.e(TAG, "removeNotification key not found: " + key);
494 return;
Joe Onorato75199e32010-05-29 17:22:51 -0400495 }
Joe Onoratoe345fff2010-05-23 15:18:27 -0400496 if (mBar != null) {
497 try {
498 mBar.removeNotification(key);
499 } catch (RemoteException ex) {
500 }
501 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700502 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700503 }
Joe Onorato2314aab2010-04-08 16:41:23 -0500504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800505 // ================================================================================
506 // Can be called from any thread
507 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800509 // lock on mDisableRecords
510 void manageDisableListLocked(int what, IBinder token, String pkg) {
511 if (SPEW) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700512 Slog.d(TAG, "manageDisableList what=0x" + Integer.toHexString(what) + " pkg=" + pkg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800513 }
514 // update the list
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800515 final int N = mDisableRecords.size();
516 DisableRecord tok = null;
517 int i;
518 for (i=0; i<N; i++) {
519 DisableRecord t = mDisableRecords.get(i);
520 if (t.token == token) {
521 tok = t;
522 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800523 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800524 }
525 if (what == 0 || !token.isBinderAlive()) {
526 if (tok != null) {
527 mDisableRecords.remove(i);
528 tok.token.unlinkToDeath(tok, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800529 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800530 } else {
531 if (tok == null) {
532 tok = new DisableRecord();
533 try {
534 token.linkToDeath(tok, 0);
535 }
536 catch (RemoteException ex) {
537 return; // give up
538 }
539 mDisableRecords.add(tok);
540 }
541 tok.what = what;
542 tok.token = token;
543 tok.pkg = pkg;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544 }
545 }
546
547 // lock on mDisableRecords
548 int gatherDisableActionsLocked() {
549 final int N = mDisableRecords.size();
550 // gather the new net flags
551 int net = 0;
552 for (int i=0; i<N; i++) {
553 net |= mDisableRecords.get(i).what;
554 }
555 return net;
556 }
557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558 // ================================================================================
559 // Always called from UI thread
560 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800562 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
563 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
564 != PackageManager.PERMISSION_GRANTED) {
565 pw.println("Permission Denial: can't dump StatusBar from from pid="
566 + Binder.getCallingPid()
567 + ", uid=" + Binder.getCallingUid());
568 return;
569 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700570
Joe Onorato0cbda992010-05-02 16:28:15 -0700571 synchronized (mIcons) {
572 mIcons.dump(pw);
573 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700574
575 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400576 int i=0;
577 pw.println("Notification list:");
578 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
579 pw.printf(" %2d: %s\n", i, e.getValue().toString());
580 i++;
581 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800582 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700583
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800584 synchronized (mLock) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585 final int N = mDisableRecords.size();
586 pw.println(" mDisableRecords.size=" + N
587 + " mDisabled=0x" + Integer.toHexString(mDisabled));
588 for (int i=0; i<N; i++) {
589 DisableRecord tok = mDisableRecords.get(i);
590 pw.println(" [" + i + "] what=0x" + Integer.toHexString(tok.what)
591 + " pkg=" + tok.pkg + " token=" + tok.token);
592 }
593 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 }
595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
597 public void onReceive(Context context, Intent intent) {
598 String action = intent.getAction();
Joe Onoratof9e0e6b2009-09-08 16:24:36 -0400599 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
600 || Intent.ACTION_SCREEN_OFF.equals(action)) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700601 collapse();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800602 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700603 /*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800604 else if (Telephony.Intents.SPN_STRINGS_UPDATED_ACTION.equals(action)) {
605 updateNetworkName(intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_SPN, false),
606 intent.getStringExtra(Telephony.Intents.EXTRA_SPN),
607 intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_PLMN, false),
608 intent.getStringExtra(Telephony.Intents.EXTRA_PLMN));
609 }
610 else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
611 updateResources();
612 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700613 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800614 }
615 };
616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800617}