blob: 1fe98afcf358a855c1ff4899e7707c9abe6a25d1 [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
John Spurlock13451a22012-09-28 14:40:41 -040067 final 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;
John Spurlock13451a22012-09-28 14:40:41 -040078 int mCurrentUserId;
satok06487a52010-10-29 11:37:18 +090079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080 private class DisableRecord implements IBinder.DeathRecipient {
John Spurlock13451a22012-09-28 14:40:41 -040081 int userId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 String pkg;
83 int what;
84 IBinder token;
85
86 public void binderDied() {
Joe Onorato8a9b2202010-02-26 18:56:32 -080087 Slog.i(TAG, "binder died for pkg=" + pkg);
John Spurlock13451a22012-09-28 14:40:41 -040088 disableInternal(userId, 0, token, pkg);
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -070089 token.unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 }
91 }
92
93 public interface NotificationCallbacks {
94 void onSetDisabled(int status);
95 void onClearAll();
Fred Quintana6ecaff12009-09-25 14:23:13 -070096 void onNotificationClick(String pkg, String tag, int id);
Daniel Sandler0f0b11c2010-08-04 15:54:58 -040097 void onNotificationClear(String pkg, String tag, int id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 void onPanelRevealed();
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -070099 void onNotificationError(String pkg, String tag, int id,
100 int uid, int initialPid, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101 }
102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 /**
104 * Construct the service, add the status bar view to the window manager
105 */
Jeff Brown2992ea72011-01-28 22:04:14 -0800106 public StatusBarManagerService(Context context, WindowManagerService windowManager) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 mContext = context;
Jeff Brown2992ea72011-01-28 22:04:14 -0800108 mWindowManager = windowManager;
109 mWindowManager.setOnHardKeyboardStatusChangeListener(this);
Joe Onorato0cbda992010-05-02 16:28:15 -0700110
111 final Resources res = context.getResources();
Joe Onorato75144ea2010-06-07 12:36:25 -0700112 mIcons.defineSlots(res.getStringArray(com.android.internal.R.array.config_statusBarIcons));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113 }
114
115 public void setNotificationCallbacks(NotificationCallbacks listener) {
116 mNotificationCallbacks = listener;
117 }
118
119 // ================================================================================
Joe Onorato25f95f92010-04-08 18:37:10 -0500120 // From IStatusBarService
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121 // ================================================================================
Daniel Sandler11cf1782012-09-27 14:03:08 -0400122 public void expandNotificationsPanel() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123 enforceExpandStatusBar();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700124
125 if (mBar != null) {
126 try {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400127 mBar.animateExpandNotificationsPanel();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700128 } catch (RemoteException ex) {
129 }
130 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131 }
132
Daniel Sandler11cf1782012-09-27 14:03:08 -0400133 public void collapsePanels() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 enforceExpandStatusBar();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135
Joe Onorato4762c2d2010-05-17 15:42:59 -0700136 if (mBar != null) {
137 try {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400138 mBar.animateCollapsePanels();
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700139 } catch (RemoteException ex) {
140 }
141 }
142 }
143
Daniel Sandler11cf1782012-09-27 14:03:08 -0400144 public void expandSettingsPanel() {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700145 enforceExpandStatusBar();
146
147 if (mBar != null) {
148 try {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400149 mBar.animateExpandSettingsPanel();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700150 } catch (RemoteException ex) {
151 }
152 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 }
154
155 public void disable(int what, IBinder token, String pkg) {
John Spurlock13451a22012-09-28 14:40:41 -0400156 disableInternal(mCurrentUserId, what, token, pkg);
157 }
158
159 private void disableInternal(int userId, int what, IBinder token, String pkg) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 enforceStatusBar();
Joe Onoratof3f0e052010-05-14 18:49:29 -0700161
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800162 synchronized (mLock) {
John Spurlock13451a22012-09-28 14:40:41 -0400163 disableLocked(userId, what, token, pkg);
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800164 }
165 }
166
John Spurlock13451a22012-09-28 14:40:41 -0400167 private void disableLocked(int userId, int what, IBinder token, String pkg) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700168 // It's important that the the callback and the call to mBar get done
169 // in the same order when multiple threads are calling this function
170 // so they are paired correctly. The messages on the handler will be
171 // handled in the order they were enqueued, but will be outside the lock.
John Spurlock13451a22012-09-28 14:40:41 -0400172 manageDisableListLocked(userId, what, token, pkg);
John Spurlock8f3e6d52012-11-29 13:56:24 -0500173
174 // Ensure state for the current user is applied, even if passed a non-current user.
175 final int net = gatherDisableActionsLocked(mCurrentUserId);
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800176 if (net != mDisabled) {
177 mDisabled = net;
178 mHandler.post(new Runnable() {
179 public void run() {
180 mNotificationCallbacks.onSetDisabled(net);
Joe Onoratof3f0e052010-05-14 18:49:29 -0700181 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800182 });
183 if (mBar != null) {
184 try {
185 mBar.disable(net);
186 } catch (RemoteException ex) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700187 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189 }
190 }
191
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700192 public void setIcon(String slot, String iconPackage, int iconId, int iconLevel,
193 String contentDescription) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700195
196 synchronized (mIcons) {
197 int index = mIcons.getSlotIndex(slot);
198 if (index < 0) {
199 throw new SecurityException("invalid status bar icon slot: " + slot);
200 }
201
Amith Yamasani98edc952012-09-25 14:09:27 -0700202 StatusBarIcon icon = new StatusBarIcon(iconPackage, UserHandle.OWNER, iconId,
203 iconLevel, 0,
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700204 contentDescription);
Joe Onorato66d7d012010-05-14 10:05:10 -0700205 //Slog.d(TAG, "setIcon slot=" + slot + " index=" + index + " icon=" + icon);
Joe Onorato0cbda992010-05-02 16:28:15 -0700206 mIcons.setIcon(index, icon);
207
Joe Onorato0cbda992010-05-02 16:28:15 -0700208 if (mBar != null) {
209 try {
210 mBar.setIcon(index, icon);
211 } catch (RemoteException ex) {
212 }
213 }
214 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215 }
216
Joe Onorato0cbda992010-05-02 16:28:15 -0700217 public void setIconVisibility(String slot, boolean visible) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700219
Joe Onorato514ad6632010-05-13 18:49:00 -0700220 synchronized (mIcons) {
221 int index = mIcons.getSlotIndex(slot);
222 if (index < 0) {
223 throw new SecurityException("invalid status bar icon slot: " + slot);
224 }
225
226 StatusBarIcon icon = mIcons.getIcon(index);
227 if (icon == null) {
228 return;
229 }
230
231 if (icon.visible != visible) {
232 icon.visible = visible;
233
Joe Onorato514ad6632010-05-13 18:49:00 -0700234 if (mBar != null) {
235 try {
236 mBar.setIcon(index, icon);
237 } catch (RemoteException ex) {
238 }
239 }
240 }
241 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700242 }
243
244 public void removeIcon(String slot) {
245 enforceStatusBar();
246
247 synchronized (mIcons) {
248 int index = mIcons.getSlotIndex(slot);
249 if (index < 0) {
250 throw new SecurityException("invalid status bar icon slot: " + slot);
251 }
252
253 mIcons.removeIcon(index);
254
Joe Onorato0cbda992010-05-02 16:28:15 -0700255 if (mBar != null) {
256 try {
257 mBar.removeIcon(index);
258 } catch (RemoteException ex) {
259 }
260 }
261 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800262 }
263
Daniel Sandlere02d8082010-10-08 15:13:22 -0400264 /**
265 * Hide or show the on-screen Menu key. Only call this from the window manager, typically in
266 * response to a window with FLAG_NEEDS_MENU_KEY set.
267 */
Dianne Hackborn7d049322011-06-14 15:00:32 -0700268 public void topAppWindowChanged(final boolean menuVisible) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400269 enforceStatusBar();
270
Dianne Hackborn7d049322011-06-14 15:00:32 -0700271 if (SPEW) Slog.d(TAG, (menuVisible?"showing":"hiding") + " MENU key");
Daniel Sandlere02d8082010-10-08 15:13:22 -0400272
273 synchronized(mLock) {
Dianne Hackborn7d049322011-06-14 15:00:32 -0700274 mMenuVisible = menuVisible;
275 mHandler.post(new Runnable() {
276 public void run() {
277 if (mBar != null) {
278 try {
279 mBar.topAppWindowChanged(menuVisible);
280 } catch (RemoteException ex) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400281 }
282 }
Dianne Hackborn7d049322011-06-14 15:00:32 -0700283 }
284 });
Daniel Sandlere02d8082010-10-08 15:13:22 -0400285 }
286 }
287
Joe Onorato857fd9b2011-01-27 15:08:35 -0800288 public void setImeWindowStatus(final IBinder token, final int vis, final int backDisposition) {
satok06487a52010-10-29 11:37:18 +0900289 enforceStatusBar();
290
Joe Onorato857fd9b2011-01-27 15:08:35 -0800291 if (SPEW) {
292 Slog.d(TAG, "swetImeWindowStatus vis=" + vis + " backDisposition=" + backDisposition);
293 }
satok06487a52010-10-29 11:37:18 +0900294
295 synchronized(mLock) {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800296 // In case of IME change, we need to call up setImeWindowStatus() regardless of
297 // mImeWindowVis because mImeWindowVis may not have been set to false when the
satok06e07442010-11-02 19:46:55 +0900298 // previous IME was destroyed.
Joe Onorato857fd9b2011-01-27 15:08:35 -0800299 mImeWindowVis = vis;
300 mImeBackDisposition = backDisposition;
301 mImeToken = token;
satok06e07442010-11-02 19:46:55 +0900302 mHandler.post(new Runnable() {
303 public void run() {
304 if (mBar != null) {
305 try {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800306 mBar.setImeWindowStatus(token, vis, backDisposition);
satok06e07442010-11-02 19:46:55 +0900307 } catch (RemoteException ex) {
satok06487a52010-10-29 11:37:18 +0900308 }
309 }
satok06e07442010-11-02 19:46:55 +0900310 }
311 });
satok06487a52010-10-29 11:37:18 +0900312 }
313 }
314
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700315 public void setSystemUiVisibility(int vis, int mask) {
Joe Onorato55bf3802011-01-25 13:42:10 -0800316 // also allows calls from window manager which is in this process.
Joe Onoratof63b0f42010-09-12 17:03:19 -0400317 enforceStatusBarService();
318
Jeff Sharkey4519a022011-09-07 23:24:53 -0700319 if (SPEW) Slog.d(TAG, "setSystemUiVisibility(0x" + Integer.toHexString(vis) + ")");
Daniel Sandler60ee2562011-07-22 12:34:33 -0400320
Joe Onoratof63b0f42010-09-12 17:03:19 -0400321 synchronized (mLock) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700322 updateUiVisibilityLocked(vis, mask);
John Spurlock13451a22012-09-28 14:40:41 -0400323 disableLocked(
324 mCurrentUserId,
325 vis & StatusBarManager.DISABLE_MASK,
326 mSysUiVisToken,
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800327 "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
John Spurlock13451a22012-09-28 14:40:41 -0400396 @Override
397 public void setCurrentUser(int newUserId) {
398 if (SPEW) Slog.d(TAG, "Setting current user to user " + newUserId);
399 mCurrentUserId = newUserId;
400 }
401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402 private void enforceStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700403 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700404 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800405 }
406
407 private void enforceExpandStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700408 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.EXPAND_STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700409 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800410 }
411
Joe Onorato8bc6c512010-06-04 16:21:12 -0400412 private void enforceStatusBarService() {
413 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
414 "StatusBarManagerService");
415 }
416
Joe Onorato4762c2d2010-05-17 15:42:59 -0700417 // ================================================================================
418 // Callbacks from the status bar service.
419 // ================================================================================
Joe Onorato75199e32010-05-29 17:22:51 -0400420 public void registerStatusBar(IStatusBar bar, StatusBarIconList iconList,
Joe Onorato93056472010-09-10 10:30:46 -0400421 List<IBinder> notificationKeys, List<StatusBarNotification> notifications,
satokcd7cd292010-11-20 15:46:23 +0900422 int switches[], List<IBinder> binders) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400423 enforceStatusBarService();
424
Joe Onorato0cbda992010-05-02 16:28:15 -0700425 Slog.i(TAG, "registerStatusBar bar=" + bar);
426 mBar = bar;
Joe Onorato75199e32010-05-29 17:22:51 -0400427 synchronized (mIcons) {
428 iconList.copyFrom(mIcons);
429 }
430 synchronized (mNotifications) {
431 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
432 notificationKeys.add(e.getKey());
433 notifications.add(e.getValue());
434 }
435 }
Joe Onorato93056472010-09-10 10:30:46 -0400436 synchronized (mLock) {
John Spurlock13451a22012-09-28 14:40:41 -0400437 switches[0] = gatherDisableActionsLocked(mCurrentUserId);
Daniel Sandler60ee2562011-07-22 12:34:33 -0400438 switches[1] = mSystemUiVisibility;
Joe Onoratoe4c7b3f2010-10-30 12:15:03 -0700439 switches[2] = mMenuVisible ? 1 : 0;
Joe Onorato857fd9b2011-01-27 15:08:35 -0800440 switches[3] = mImeWindowVis;
441 switches[4] = mImeBackDisposition;
442 binders.add(mImeToken);
Joe Onorato93056472010-09-10 10:30:46 -0400443 }
Jeff Brown2992ea72011-01-28 22:04:14 -0800444 switches[5] = mWindowManager.isHardKeyboardAvailable() ? 1 : 0;
445 switches[6] = mWindowManager.isHardKeyboardEnabled() ? 1 : 0;
Joe Onorato2314aab2010-04-08 16:41:23 -0500446 }
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400447
Joe Onorato4762c2d2010-05-17 15:42:59 -0700448 /**
Joe Onoratof1f25912010-06-07 11:52:41 -0700449 * The status bar service should call this each time the user brings the panel from
450 * invisible to visible in order to clear the notification light.
Joe Onorato4762c2d2010-05-17 15:42:59 -0700451 */
Joe Onoratof1f25912010-06-07 11:52:41 -0700452 public void onPanelRevealed() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400453 enforceStatusBarService();
454
Joe Onoratof1f25912010-06-07 11:52:41 -0700455 // tell the notification manager to turn off the lights.
456 mNotificationCallbacks.onPanelRevealed();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700457 }
458
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400459 public void onNotificationClick(String pkg, String tag, int id) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400460 enforceStatusBarService();
461
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400462 mNotificationCallbacks.onNotificationClick(pkg, tag, id);
463 }
464
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700465 public void onNotificationError(String pkg, String tag, int id,
466 int uid, int initialPid, String message) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400467 enforceStatusBarService();
468
Joe Onorato005847b2010-06-04 16:08:02 -0400469 // WARNING: this will call back into us to do the remove. Don't hold any locks.
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700470 mNotificationCallbacks.onNotificationError(pkg, tag, id, uid, initialPid, message);
Joe Onorato005847b2010-06-04 16:08:02 -0400471 }
472
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400473 public void onNotificationClear(String pkg, String tag, int id) {
474 enforceStatusBarService();
475
476 mNotificationCallbacks.onNotificationClear(pkg, tag, id);
477 }
478
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400479 public void onClearAllNotifications() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400480 enforceStatusBarService();
481
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400482 mNotificationCallbacks.onClearAll();
483 }
484
Joe Onorato18e69df2010-05-17 22:26:12 -0700485 // ================================================================================
486 // Callbacks for NotificationManagerService.
487 // ================================================================================
488 public IBinder addNotification(StatusBarNotification notification) {
489 synchronized (mNotifications) {
Joe Onoratoa0c56fe2010-05-20 10:21:52 -0700490 IBinder key = new Binder();
Joe Onorato75199e32010-05-29 17:22:51 -0400491 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400492 if (mBar != null) {
493 try {
494 mBar.addNotification(key, notification);
495 } catch (RemoteException ex) {
496 }
497 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700498 return key;
499 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700500 }
501
Joe Onorato18e69df2010-05-17 22:26:12 -0700502 public void updateNotification(IBinder key, StatusBarNotification notification) {
503 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400504 if (!mNotifications.containsKey(key)) {
505 throw new IllegalArgumentException("updateNotification key not found: " + key);
506 }
507 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400508 if (mBar != null) {
509 try {
510 mBar.updateNotification(key, notification);
511 } catch (RemoteException ex) {
512 }
513 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700514 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700515 }
516
517 public void removeNotification(IBinder key) {
Joe Onorato18e69df2010-05-17 22:26:12 -0700518 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400519 final StatusBarNotification n = mNotifications.remove(key);
520 if (n == null) {
Daniel Sandlerfe0806a2012-05-16 12:41:33 -0400521 Slog.e(TAG, "removeNotification key not found: " + key);
522 return;
Joe Onorato75199e32010-05-29 17:22:51 -0400523 }
Joe Onoratoe345fff2010-05-23 15:18:27 -0400524 if (mBar != null) {
525 try {
526 mBar.removeNotification(key);
527 } catch (RemoteException ex) {
528 }
529 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700530 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700531 }
Joe Onorato2314aab2010-04-08 16:41:23 -0500532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800533 // ================================================================================
534 // Can be called from any thread
535 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800537 // lock on mDisableRecords
John Spurlock13451a22012-09-28 14:40:41 -0400538 void manageDisableListLocked(int userId, int what, IBinder token, String pkg) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539 if (SPEW) {
John Spurlock13451a22012-09-28 14:40:41 -0400540 Slog.d(TAG, "manageDisableList userId=" + userId
541 + " what=0x" + Integer.toHexString(what) + " pkg=" + pkg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800542 }
543 // update the list
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800544 final int N = mDisableRecords.size();
545 DisableRecord tok = null;
546 int i;
547 for (i=0; i<N; i++) {
548 DisableRecord t = mDisableRecords.get(i);
John Spurlock4e6922d2012-10-04 14:51:51 -0400549 if (t.token == token && t.userId == userId) {
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800550 tok = t;
551 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800552 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800553 }
554 if (what == 0 || !token.isBinderAlive()) {
555 if (tok != null) {
556 mDisableRecords.remove(i);
557 tok.token.unlinkToDeath(tok, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800559 } else {
560 if (tok == null) {
561 tok = new DisableRecord();
John Spurlock13451a22012-09-28 14:40:41 -0400562 tok.userId = userId;
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800563 try {
564 token.linkToDeath(tok, 0);
565 }
566 catch (RemoteException ex) {
567 return; // give up
568 }
569 mDisableRecords.add(tok);
570 }
571 tok.what = what;
572 tok.token = token;
573 tok.pkg = pkg;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800574 }
575 }
576
577 // lock on mDisableRecords
John Spurlock13451a22012-09-28 14:40:41 -0400578 int gatherDisableActionsLocked(int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579 final int N = mDisableRecords.size();
580 // gather the new net flags
581 int net = 0;
582 for (int i=0; i<N; i++) {
John Spurlock13451a22012-09-28 14:40:41 -0400583 final DisableRecord rec = mDisableRecords.get(i);
584 if (rec.userId == userId) {
585 net |= rec.what;
586 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587 }
588 return net;
589 }
590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800591 // ================================================================================
592 // Always called from UI thread
593 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800595 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
596 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
597 != PackageManager.PERMISSION_GRANTED) {
598 pw.println("Permission Denial: can't dump StatusBar from from pid="
599 + Binder.getCallingPid()
600 + ", uid=" + Binder.getCallingUid());
601 return;
602 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700603
Joe Onorato0cbda992010-05-02 16:28:15 -0700604 synchronized (mIcons) {
605 mIcons.dump(pw);
606 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700607
608 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400609 int i=0;
610 pw.println("Notification list:");
611 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
612 pw.printf(" %2d: %s\n", i, e.getValue().toString());
613 i++;
614 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800615 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700616
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800617 synchronized (mLock) {
John Spurlock13451a22012-09-28 14:40:41 -0400618 pw.println(" mDisabled=0x" + Integer.toHexString(mDisabled));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800619 final int N = mDisableRecords.size();
John Spurlock13451a22012-09-28 14:40:41 -0400620 pw.println(" mDisableRecords.size=" + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800621 for (int i=0; i<N; i++) {
622 DisableRecord tok = mDisableRecords.get(i);
John Spurlock13451a22012-09-28 14:40:41 -0400623 pw.println(" [" + i + "] userId=" + tok.userId
624 + " what=0x" + Integer.toHexString(tok.what)
625 + " pkg=" + tok.pkg
626 + " token=" + tok.token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800627 }
628 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800629 }
630
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800631 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
632 public void onReceive(Context context, Intent intent) {
633 String action = intent.getAction();
Joe Onoratof9e0e6b2009-09-08 16:24:36 -0400634 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
635 || Intent.ACTION_SCREEN_OFF.equals(action)) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400636 collapsePanels();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800637 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700638 /*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800639 else if (Telephony.Intents.SPN_STRINGS_UPDATED_ACTION.equals(action)) {
640 updateNetworkName(intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_SPN, false),
641 intent.getStringExtra(Telephony.Intents.EXTRA_SPN),
642 intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_PLMN, false),
643 intent.getStringExtra(Telephony.Intents.EXTRA_PLMN));
644 }
645 else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
646 updateResources();
647 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700648 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800649 }
650 };
651
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800652}