blob: b567992ea46dfa4835755db111e8f5a26420d9cb [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 // ================================================================================
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700120 public void expandNotifications() {
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 {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700125 mBar.animateExpandNotifications();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700126 } catch (RemoteException ex) {
127 }
128 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 }
130
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700131 public void collapseNotifications() {
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 {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700136 mBar.animateCollapseNotifications();
137 } catch (RemoteException ex) {
138 }
139 }
140 }
141
142 public void expandQuickSettings() {
143 enforceExpandStatusBar();
144
145 if (mBar != null) {
146 try {
147 mBar.animateExpandQuickSettings();
148 } catch (RemoteException ex) {
149 }
150 }
151 }
152
153 public void collapseQuickSettings() {
154 enforceExpandStatusBar();
155
156 if (mBar != null) {
157 try {
158 mBar.animateCollapseQuickSettings();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700159 } catch (RemoteException ex) {
160 }
161 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 }
163
164 public void disable(int what, IBinder token, String pkg) {
165 enforceStatusBar();
Joe Onoratof3f0e052010-05-14 18:49:29 -0700166
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800167 synchronized (mLock) {
168 disableLocked(what, token, pkg);
169 }
170 }
171
172 private void disableLocked(int what, IBinder token, String pkg) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700173 // It's important that the the callback and the call to mBar get done
174 // in the same order when multiple threads are calling this function
175 // so they are paired correctly. The messages on the handler will be
176 // handled in the order they were enqueued, but will be outside the lock.
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800177 manageDisableListLocked(what, token, pkg);
178 final int net = gatherDisableActionsLocked();
179 if (net != mDisabled) {
180 mDisabled = net;
181 mHandler.post(new Runnable() {
182 public void run() {
183 mNotificationCallbacks.onSetDisabled(net);
Joe Onoratof3f0e052010-05-14 18:49:29 -0700184 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800185 });
186 if (mBar != null) {
187 try {
188 mBar.disable(net);
189 } catch (RemoteException ex) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700190 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800192 }
193 }
194
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700195 public void setIcon(String slot, String iconPackage, int iconId, int iconLevel,
196 String contentDescription) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700198
199 synchronized (mIcons) {
200 int index = mIcons.getSlotIndex(slot);
201 if (index < 0) {
202 throw new SecurityException("invalid status bar icon slot: " + slot);
203 }
204
Amith Yamasani98edc952012-09-25 14:09:27 -0700205 StatusBarIcon icon = new StatusBarIcon(iconPackage, UserHandle.OWNER, iconId,
206 iconLevel, 0,
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700207 contentDescription);
Joe Onorato66d7d012010-05-14 10:05:10 -0700208 //Slog.d(TAG, "setIcon slot=" + slot + " index=" + index + " icon=" + icon);
Joe Onorato0cbda992010-05-02 16:28:15 -0700209 mIcons.setIcon(index, icon);
210
Joe Onorato0cbda992010-05-02 16:28:15 -0700211 if (mBar != null) {
212 try {
213 mBar.setIcon(index, icon);
214 } catch (RemoteException ex) {
215 }
216 }
217 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218 }
219
Joe Onorato0cbda992010-05-02 16:28:15 -0700220 public void setIconVisibility(String slot, boolean visible) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700222
Joe Onorato514ad6632010-05-13 18:49:00 -0700223 synchronized (mIcons) {
224 int index = mIcons.getSlotIndex(slot);
225 if (index < 0) {
226 throw new SecurityException("invalid status bar icon slot: " + slot);
227 }
228
229 StatusBarIcon icon = mIcons.getIcon(index);
230 if (icon == null) {
231 return;
232 }
233
234 if (icon.visible != visible) {
235 icon.visible = visible;
236
Joe Onorato514ad6632010-05-13 18:49:00 -0700237 if (mBar != null) {
238 try {
239 mBar.setIcon(index, icon);
240 } catch (RemoteException ex) {
241 }
242 }
243 }
244 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700245 }
246
247 public void removeIcon(String slot) {
248 enforceStatusBar();
249
250 synchronized (mIcons) {
251 int index = mIcons.getSlotIndex(slot);
252 if (index < 0) {
253 throw new SecurityException("invalid status bar icon slot: " + slot);
254 }
255
256 mIcons.removeIcon(index);
257
Joe Onorato0cbda992010-05-02 16:28:15 -0700258 if (mBar != null) {
259 try {
260 mBar.removeIcon(index);
261 } catch (RemoteException ex) {
262 }
263 }
264 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265 }
266
Daniel Sandlere02d8082010-10-08 15:13:22 -0400267 /**
268 * Hide or show the on-screen Menu key. Only call this from the window manager, typically in
269 * response to a window with FLAG_NEEDS_MENU_KEY set.
270 */
Dianne Hackborn7d049322011-06-14 15:00:32 -0700271 public void topAppWindowChanged(final boolean menuVisible) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400272 enforceStatusBar();
273
Dianne Hackborn7d049322011-06-14 15:00:32 -0700274 if (SPEW) Slog.d(TAG, (menuVisible?"showing":"hiding") + " MENU key");
Daniel Sandlere02d8082010-10-08 15:13:22 -0400275
276 synchronized(mLock) {
Dianne Hackborn7d049322011-06-14 15:00:32 -0700277 mMenuVisible = menuVisible;
278 mHandler.post(new Runnable() {
279 public void run() {
280 if (mBar != null) {
281 try {
282 mBar.topAppWindowChanged(menuVisible);
283 } catch (RemoteException ex) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400284 }
285 }
Dianne Hackborn7d049322011-06-14 15:00:32 -0700286 }
287 });
Daniel Sandlere02d8082010-10-08 15:13:22 -0400288 }
289 }
290
Joe Onorato857fd9b2011-01-27 15:08:35 -0800291 public void setImeWindowStatus(final IBinder token, final int vis, final int backDisposition) {
satok06487a52010-10-29 11:37:18 +0900292 enforceStatusBar();
293
Joe Onorato857fd9b2011-01-27 15:08:35 -0800294 if (SPEW) {
295 Slog.d(TAG, "swetImeWindowStatus vis=" + vis + " backDisposition=" + backDisposition);
296 }
satok06487a52010-10-29 11:37:18 +0900297
298 synchronized(mLock) {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800299 // In case of IME change, we need to call up setImeWindowStatus() regardless of
300 // mImeWindowVis because mImeWindowVis may not have been set to false when the
satok06e07442010-11-02 19:46:55 +0900301 // previous IME was destroyed.
Joe Onorato857fd9b2011-01-27 15:08:35 -0800302 mImeWindowVis = vis;
303 mImeBackDisposition = backDisposition;
304 mImeToken = token;
satok06e07442010-11-02 19:46:55 +0900305 mHandler.post(new Runnable() {
306 public void run() {
307 if (mBar != null) {
308 try {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800309 mBar.setImeWindowStatus(token, vis, backDisposition);
satok06e07442010-11-02 19:46:55 +0900310 } catch (RemoteException ex) {
satok06487a52010-10-29 11:37:18 +0900311 }
312 }
satok06e07442010-11-02 19:46:55 +0900313 }
314 });
satok06487a52010-10-29 11:37:18 +0900315 }
316 }
317
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700318 public void setSystemUiVisibility(int vis, int mask) {
Joe Onorato55bf3802011-01-25 13:42:10 -0800319 // also allows calls from window manager which is in this process.
Joe Onoratof63b0f42010-09-12 17:03:19 -0400320 enforceStatusBarService();
321
Jeff Sharkey4519a022011-09-07 23:24:53 -0700322 if (SPEW) Slog.d(TAG, "setSystemUiVisibility(0x" + Integer.toHexString(vis) + ")");
Daniel Sandler60ee2562011-07-22 12:34:33 -0400323
Joe Onoratof63b0f42010-09-12 17:03:19 -0400324 synchronized (mLock) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700325 updateUiVisibilityLocked(vis, mask);
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800326 disableLocked(vis & StatusBarManager.DISABLE_MASK, mSysUiVisToken,
327 "WindowManager.LayoutParams");
Joe Onoratof63b0f42010-09-12 17:03:19 -0400328 }
329 }
330
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700331 private void updateUiVisibilityLocked(final int vis, final int mask) {
Daniel Sandler60ee2562011-07-22 12:34:33 -0400332 if (mSystemUiVisibility != vis) {
333 mSystemUiVisibility = vis;
Joe Onoratof63b0f42010-09-12 17:03:19 -0400334 mHandler.post(new Runnable() {
335 public void run() {
336 if (mBar != null) {
337 try {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700338 mBar.setSystemUiVisibility(vis, mask);
Joe Onoratof63b0f42010-09-12 17:03:19 -0400339 } catch (RemoteException ex) {
Joe Onorato93056472010-09-10 10:30:46 -0400340 }
341 }
Joe Onoratof63b0f42010-09-12 17:03:19 -0400342 }
343 });
Joe Onorato93056472010-09-10 10:30:46 -0400344 }
345 }
346
Jeff Brown2992ea72011-01-28 22:04:14 -0800347 public void setHardKeyboardEnabled(final boolean enabled) {
348 mHandler.post(new Runnable() {
349 public void run() {
350 mWindowManager.setHardKeyboardEnabled(enabled);
351 }
352 });
353 }
354
355 @Override
356 public void onHardKeyboardStatusChange(final boolean available, final boolean enabled) {
357 mHandler.post(new Runnable() {
358 public void run() {
359 if (mBar != null) {
360 try {
361 mBar.setHardKeyboardStatus(available, enabled);
362 } catch (RemoteException ex) {
363 }
364 }
365 }
366 });
367 }
368
Michael Jurka3b1fc472011-06-13 10:54:40 -0700369 @Override
370 public void toggleRecentApps() {
371 if (mBar != null) {
372 try {
373 mBar.toggleRecentApps();
374 } catch (RemoteException ex) {}
375 }
376 }
377
Michael Jurka7f2668c2012-03-27 07:49:52 -0700378 @Override
379 public void preloadRecentApps() {
380 if (mBar != null) {
381 try {
382 mBar.preloadRecentApps();
383 } catch (RemoteException ex) {}
384 }
385 }
386
387 @Override
388 public void cancelPreloadRecentApps() {
389 if (mBar != null) {
390 try {
391 mBar.cancelPreloadRecentApps();
392 } catch (RemoteException ex) {}
393 }
394 }
395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800396 private void enforceStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700397 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700398 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 }
400
401 private void enforceExpandStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700402 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.EXPAND_STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700403 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 }
405
Joe Onorato8bc6c512010-06-04 16:21:12 -0400406 private void enforceStatusBarService() {
407 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
408 "StatusBarManagerService");
409 }
410
Joe Onorato4762c2d2010-05-17 15:42:59 -0700411 // ================================================================================
412 // Callbacks from the status bar service.
413 // ================================================================================
Joe Onorato75199e32010-05-29 17:22:51 -0400414 public void registerStatusBar(IStatusBar bar, StatusBarIconList iconList,
Joe Onorato93056472010-09-10 10:30:46 -0400415 List<IBinder> notificationKeys, List<StatusBarNotification> notifications,
satokcd7cd292010-11-20 15:46:23 +0900416 int switches[], List<IBinder> binders) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400417 enforceStatusBarService();
418
Joe Onorato0cbda992010-05-02 16:28:15 -0700419 Slog.i(TAG, "registerStatusBar bar=" + bar);
420 mBar = bar;
Joe Onorato75199e32010-05-29 17:22:51 -0400421 synchronized (mIcons) {
422 iconList.copyFrom(mIcons);
423 }
424 synchronized (mNotifications) {
425 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
426 notificationKeys.add(e.getKey());
427 notifications.add(e.getValue());
428 }
429 }
Joe Onorato93056472010-09-10 10:30:46 -0400430 synchronized (mLock) {
Joe Onoratoe4c7b3f2010-10-30 12:15:03 -0700431 switches[0] = gatherDisableActionsLocked();
Daniel Sandler60ee2562011-07-22 12:34:33 -0400432 switches[1] = mSystemUiVisibility;
Joe Onoratoe4c7b3f2010-10-30 12:15:03 -0700433 switches[2] = mMenuVisible ? 1 : 0;
Joe Onorato857fd9b2011-01-27 15:08:35 -0800434 switches[3] = mImeWindowVis;
435 switches[4] = mImeBackDisposition;
436 binders.add(mImeToken);
Joe Onorato93056472010-09-10 10:30:46 -0400437 }
Jeff Brown2992ea72011-01-28 22:04:14 -0800438 switches[5] = mWindowManager.isHardKeyboardAvailable() ? 1 : 0;
439 switches[6] = mWindowManager.isHardKeyboardEnabled() ? 1 : 0;
Joe Onorato2314aab2010-04-08 16:41:23 -0500440 }
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400441
Joe Onorato4762c2d2010-05-17 15:42:59 -0700442 /**
Joe Onoratof1f25912010-06-07 11:52:41 -0700443 * The status bar service should call this each time the user brings the panel from
444 * invisible to visible in order to clear the notification light.
Joe Onorato4762c2d2010-05-17 15:42:59 -0700445 */
Joe Onoratof1f25912010-06-07 11:52:41 -0700446 public void onPanelRevealed() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400447 enforceStatusBarService();
448
Joe Onoratof1f25912010-06-07 11:52:41 -0700449 // tell the notification manager to turn off the lights.
450 mNotificationCallbacks.onPanelRevealed();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700451 }
452
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400453 public void onNotificationClick(String pkg, String tag, int id) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400454 enforceStatusBarService();
455
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400456 mNotificationCallbacks.onNotificationClick(pkg, tag, id);
457 }
458
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700459 public void onNotificationError(String pkg, String tag, int id,
460 int uid, int initialPid, String message) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400461 enforceStatusBarService();
462
Joe Onorato005847b2010-06-04 16:08:02 -0400463 // WARNING: this will call back into us to do the remove. Don't hold any locks.
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700464 mNotificationCallbacks.onNotificationError(pkg, tag, id, uid, initialPid, message);
Joe Onorato005847b2010-06-04 16:08:02 -0400465 }
466
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400467 public void onNotificationClear(String pkg, String tag, int id) {
468 enforceStatusBarService();
469
470 mNotificationCallbacks.onNotificationClear(pkg, tag, id);
471 }
472
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400473 public void onClearAllNotifications() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400474 enforceStatusBarService();
475
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400476 mNotificationCallbacks.onClearAll();
477 }
478
Joe Onorato18e69df2010-05-17 22:26:12 -0700479 // ================================================================================
480 // Callbacks for NotificationManagerService.
481 // ================================================================================
482 public IBinder addNotification(StatusBarNotification notification) {
483 synchronized (mNotifications) {
Joe Onoratoa0c56fe2010-05-20 10:21:52 -0700484 IBinder key = new Binder();
Joe Onorato75199e32010-05-29 17:22:51 -0400485 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400486 if (mBar != null) {
487 try {
488 mBar.addNotification(key, notification);
489 } catch (RemoteException ex) {
490 }
491 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700492 return key;
493 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700494 }
495
Joe Onorato18e69df2010-05-17 22:26:12 -0700496 public void updateNotification(IBinder key, StatusBarNotification notification) {
497 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400498 if (!mNotifications.containsKey(key)) {
499 throw new IllegalArgumentException("updateNotification key not found: " + key);
500 }
501 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400502 if (mBar != null) {
503 try {
504 mBar.updateNotification(key, notification);
505 } catch (RemoteException ex) {
506 }
507 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700508 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700509 }
510
511 public void removeNotification(IBinder key) {
Joe Onorato18e69df2010-05-17 22:26:12 -0700512 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400513 final StatusBarNotification n = mNotifications.remove(key);
514 if (n == null) {
Daniel Sandlerfe0806a2012-05-16 12:41:33 -0400515 Slog.e(TAG, "removeNotification key not found: " + key);
516 return;
Joe Onorato75199e32010-05-29 17:22:51 -0400517 }
Joe Onoratoe345fff2010-05-23 15:18:27 -0400518 if (mBar != null) {
519 try {
520 mBar.removeNotification(key);
521 } catch (RemoteException ex) {
522 }
523 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700524 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700525 }
Joe Onorato2314aab2010-04-08 16:41:23 -0500526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800527 // ================================================================================
528 // Can be called from any thread
529 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800531 // lock on mDisableRecords
532 void manageDisableListLocked(int what, IBinder token, String pkg) {
533 if (SPEW) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700534 Slog.d(TAG, "manageDisableList what=0x" + Integer.toHexString(what) + " pkg=" + pkg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800535 }
536 // update the list
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800537 final int N = mDisableRecords.size();
538 DisableRecord tok = null;
539 int i;
540 for (i=0; i<N; i++) {
541 DisableRecord t = mDisableRecords.get(i);
542 if (t.token == token) {
543 tok = t;
544 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800545 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800546 }
547 if (what == 0 || !token.isBinderAlive()) {
548 if (tok != null) {
549 mDisableRecords.remove(i);
550 tok.token.unlinkToDeath(tok, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800551 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800552 } else {
553 if (tok == null) {
554 tok = new DisableRecord();
555 try {
556 token.linkToDeath(tok, 0);
557 }
558 catch (RemoteException ex) {
559 return; // give up
560 }
561 mDisableRecords.add(tok);
562 }
563 tok.what = what;
564 tok.token = token;
565 tok.pkg = pkg;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566 }
567 }
568
569 // lock on mDisableRecords
570 int gatherDisableActionsLocked() {
571 final int N = mDisableRecords.size();
572 // gather the new net flags
573 int net = 0;
574 for (int i=0; i<N; i++) {
575 net |= mDisableRecords.get(i).what;
576 }
577 return net;
578 }
579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800580 // ================================================================================
581 // Always called from UI thread
582 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
585 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
586 != PackageManager.PERMISSION_GRANTED) {
587 pw.println("Permission Denial: can't dump StatusBar from from pid="
588 + Binder.getCallingPid()
589 + ", uid=" + Binder.getCallingUid());
590 return;
591 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700592
Joe Onorato0cbda992010-05-02 16:28:15 -0700593 synchronized (mIcons) {
594 mIcons.dump(pw);
595 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700596
597 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400598 int i=0;
599 pw.println("Notification list:");
600 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
601 pw.printf(" %2d: %s\n", i, e.getValue().toString());
602 i++;
603 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800604 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700605
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800606 synchronized (mLock) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800607 final int N = mDisableRecords.size();
608 pw.println(" mDisableRecords.size=" + N
609 + " mDisabled=0x" + Integer.toHexString(mDisabled));
610 for (int i=0; i<N; i++) {
611 DisableRecord tok = mDisableRecords.get(i);
612 pw.println(" [" + i + "] what=0x" + Integer.toHexString(tok.what)
613 + " pkg=" + tok.pkg + " token=" + tok.token);
614 }
615 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800616 }
617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800618 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
619 public void onReceive(Context context, Intent intent) {
620 String action = intent.getAction();
Joe Onoratof9e0e6b2009-09-08 16:24:36 -0400621 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
622 || Intent.ACTION_SCREEN_OFF.equals(action)) {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700623 collapseNotifications();
624 collapseQuickSettings();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800625 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700626 /*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800627 else if (Telephony.Intents.SPN_STRINGS_UPDATED_ACTION.equals(action)) {
628 updateNetworkName(intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_SPN, false),
629 intent.getStringExtra(Telephony.Intents.EXTRA_SPN),
630 intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_PLMN, false),
631 intent.getStringExtra(Telephony.Intents.EXTRA_PLMN));
632 }
633 else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
634 updateResources();
635 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700636 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800637 }
638 };
639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640}