blob: 29608a21b19eddaad45b0f721bf7825c6948d925 [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 // ================================================================================
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700119 public void expandNotifications() {
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 {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700124 mBar.animateExpandNotifications();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700125 } catch (RemoteException ex) {
126 }
127 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 }
129
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700130 public void collapseNotifications() {
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 {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700135 mBar.animateCollapseNotifications();
136 } catch (RemoteException ex) {
137 }
138 }
139 }
140
141 public void expandQuickSettings() {
142 enforceExpandStatusBar();
143
144 if (mBar != null) {
145 try {
146 mBar.animateExpandQuickSettings();
147 } catch (RemoteException ex) {
148 }
149 }
150 }
151
152 public void collapseQuickSettings() {
153 enforceExpandStatusBar();
154
155 if (mBar != null) {
156 try {
157 mBar.animateCollapseQuickSettings();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700158 } catch (RemoteException ex) {
159 }
160 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 }
162
163 public void disable(int what, IBinder token, String pkg) {
164 enforceStatusBar();
Joe Onoratof3f0e052010-05-14 18:49:29 -0700165
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800166 synchronized (mLock) {
167 disableLocked(what, token, pkg);
168 }
169 }
170
171 private void disableLocked(int what, IBinder token, String pkg) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700172 // It's important that the the callback and the call to mBar get done
173 // in the same order when multiple threads are calling this function
174 // so they are paired correctly. The messages on the handler will be
175 // handled in the order they were enqueued, but will be outside the lock.
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800176 manageDisableListLocked(what, token, pkg);
177 final int net = gatherDisableActionsLocked();
178 if (net != mDisabled) {
179 mDisabled = net;
180 mHandler.post(new Runnable() {
181 public void run() {
182 mNotificationCallbacks.onSetDisabled(net);
Joe Onoratof3f0e052010-05-14 18:49:29 -0700183 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800184 });
185 if (mBar != null) {
186 try {
187 mBar.disable(net);
188 } catch (RemoteException ex) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700189 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 }
192 }
193
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700194 public void setIcon(String slot, String iconPackage, int iconId, int iconLevel,
195 String contentDescription) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800196 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700197
198 synchronized (mIcons) {
199 int index = mIcons.getSlotIndex(slot);
200 if (index < 0) {
201 throw new SecurityException("invalid status bar icon slot: " + slot);
202 }
203
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700204 StatusBarIcon icon = new StatusBarIcon(iconPackage, iconId, iconLevel, 0,
205 contentDescription);
Joe Onorato66d7d012010-05-14 10:05:10 -0700206 //Slog.d(TAG, "setIcon slot=" + slot + " index=" + index + " icon=" + icon);
Joe Onorato0cbda992010-05-02 16:28:15 -0700207 mIcons.setIcon(index, icon);
208
Joe Onorato0cbda992010-05-02 16:28:15 -0700209 if (mBar != null) {
210 try {
211 mBar.setIcon(index, icon);
212 } catch (RemoteException ex) {
213 }
214 }
215 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 }
217
Joe Onorato0cbda992010-05-02 16:28:15 -0700218 public void setIconVisibility(String slot, boolean visible) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219 enforceStatusBar();
Joe Onorato0cbda992010-05-02 16:28:15 -0700220
Joe Onorato514ad6632010-05-13 18:49:00 -0700221 synchronized (mIcons) {
222 int index = mIcons.getSlotIndex(slot);
223 if (index < 0) {
224 throw new SecurityException("invalid status bar icon slot: " + slot);
225 }
226
227 StatusBarIcon icon = mIcons.getIcon(index);
228 if (icon == null) {
229 return;
230 }
231
232 if (icon.visible != visible) {
233 icon.visible = visible;
234
Joe Onorato514ad6632010-05-13 18:49:00 -0700235 if (mBar != null) {
236 try {
237 mBar.setIcon(index, icon);
238 } catch (RemoteException ex) {
239 }
240 }
241 }
242 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700243 }
244
245 public void removeIcon(String slot) {
246 enforceStatusBar();
247
248 synchronized (mIcons) {
249 int index = mIcons.getSlotIndex(slot);
250 if (index < 0) {
251 throw new SecurityException("invalid status bar icon slot: " + slot);
252 }
253
254 mIcons.removeIcon(index);
255
Joe Onorato0cbda992010-05-02 16:28:15 -0700256 if (mBar != null) {
257 try {
258 mBar.removeIcon(index);
259 } catch (RemoteException ex) {
260 }
261 }
262 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800263 }
264
Daniel Sandlere02d8082010-10-08 15:13:22 -0400265 /**
266 * Hide or show the on-screen Menu key. Only call this from the window manager, typically in
267 * response to a window with FLAG_NEEDS_MENU_KEY set.
268 */
Dianne Hackborn7d049322011-06-14 15:00:32 -0700269 public void topAppWindowChanged(final boolean menuVisible) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400270 enforceStatusBar();
271
Dianne Hackborn7d049322011-06-14 15:00:32 -0700272 if (SPEW) Slog.d(TAG, (menuVisible?"showing":"hiding") + " MENU key");
Daniel Sandlere02d8082010-10-08 15:13:22 -0400273
274 synchronized(mLock) {
Dianne Hackborn7d049322011-06-14 15:00:32 -0700275 mMenuVisible = menuVisible;
276 mHandler.post(new Runnable() {
277 public void run() {
278 if (mBar != null) {
279 try {
280 mBar.topAppWindowChanged(menuVisible);
281 } catch (RemoteException ex) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400282 }
283 }
Dianne Hackborn7d049322011-06-14 15:00:32 -0700284 }
285 });
Daniel Sandlere02d8082010-10-08 15:13:22 -0400286 }
287 }
288
Joe Onorato857fd9b2011-01-27 15:08:35 -0800289 public void setImeWindowStatus(final IBinder token, final int vis, final int backDisposition) {
satok06487a52010-10-29 11:37:18 +0900290 enforceStatusBar();
291
Joe Onorato857fd9b2011-01-27 15:08:35 -0800292 if (SPEW) {
293 Slog.d(TAG, "swetImeWindowStatus vis=" + vis + " backDisposition=" + backDisposition);
294 }
satok06487a52010-10-29 11:37:18 +0900295
296 synchronized(mLock) {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800297 // In case of IME change, we need to call up setImeWindowStatus() regardless of
298 // mImeWindowVis because mImeWindowVis may not have been set to false when the
satok06e07442010-11-02 19:46:55 +0900299 // previous IME was destroyed.
Joe Onorato857fd9b2011-01-27 15:08:35 -0800300 mImeWindowVis = vis;
301 mImeBackDisposition = backDisposition;
302 mImeToken = token;
satok06e07442010-11-02 19:46:55 +0900303 mHandler.post(new Runnable() {
304 public void run() {
305 if (mBar != null) {
306 try {
Joe Onorato857fd9b2011-01-27 15:08:35 -0800307 mBar.setImeWindowStatus(token, vis, backDisposition);
satok06e07442010-11-02 19:46:55 +0900308 } catch (RemoteException ex) {
satok06487a52010-10-29 11:37:18 +0900309 }
310 }
satok06e07442010-11-02 19:46:55 +0900311 }
312 });
satok06487a52010-10-29 11:37:18 +0900313 }
314 }
315
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700316 public void setSystemUiVisibility(int vis, int mask) {
Joe Onorato55bf3802011-01-25 13:42:10 -0800317 // also allows calls from window manager which is in this process.
Joe Onoratof63b0f42010-09-12 17:03:19 -0400318 enforceStatusBarService();
319
Jeff Sharkey4519a022011-09-07 23:24:53 -0700320 if (SPEW) Slog.d(TAG, "setSystemUiVisibility(0x" + Integer.toHexString(vis) + ")");
Daniel Sandler60ee2562011-07-22 12:34:33 -0400321
Joe Onoratof63b0f42010-09-12 17:03:19 -0400322 synchronized (mLock) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700323 updateUiVisibilityLocked(vis, mask);
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800324 disableLocked(vis & StatusBarManager.DISABLE_MASK, mSysUiVisToken,
325 "WindowManager.LayoutParams");
Joe Onoratof63b0f42010-09-12 17:03:19 -0400326 }
327 }
328
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700329 private void updateUiVisibilityLocked(final int vis, final int mask) {
Daniel Sandler60ee2562011-07-22 12:34:33 -0400330 if (mSystemUiVisibility != vis) {
331 mSystemUiVisibility = vis;
Joe Onoratof63b0f42010-09-12 17:03:19 -0400332 mHandler.post(new Runnable() {
333 public void run() {
334 if (mBar != null) {
335 try {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700336 mBar.setSystemUiVisibility(vis, mask);
Joe Onoratof63b0f42010-09-12 17:03:19 -0400337 } catch (RemoteException ex) {
Joe Onorato93056472010-09-10 10:30:46 -0400338 }
339 }
Joe Onoratof63b0f42010-09-12 17:03:19 -0400340 }
341 });
Joe Onorato93056472010-09-10 10:30:46 -0400342 }
343 }
344
Jeff Brown2992ea72011-01-28 22:04:14 -0800345 public void setHardKeyboardEnabled(final boolean enabled) {
346 mHandler.post(new Runnable() {
347 public void run() {
348 mWindowManager.setHardKeyboardEnabled(enabled);
349 }
350 });
351 }
352
353 @Override
354 public void onHardKeyboardStatusChange(final boolean available, final boolean enabled) {
355 mHandler.post(new Runnable() {
356 public void run() {
357 if (mBar != null) {
358 try {
359 mBar.setHardKeyboardStatus(available, enabled);
360 } catch (RemoteException ex) {
361 }
362 }
363 }
364 });
365 }
366
Michael Jurka3b1fc472011-06-13 10:54:40 -0700367 @Override
368 public void toggleRecentApps() {
369 if (mBar != null) {
370 try {
371 mBar.toggleRecentApps();
372 } catch (RemoteException ex) {}
373 }
374 }
375
Michael Jurka7f2668c2012-03-27 07:49:52 -0700376 @Override
377 public void preloadRecentApps() {
378 if (mBar != null) {
379 try {
380 mBar.preloadRecentApps();
381 } catch (RemoteException ex) {}
382 }
383 }
384
385 @Override
386 public void cancelPreloadRecentApps() {
387 if (mBar != null) {
388 try {
389 mBar.cancelPreloadRecentApps();
390 } catch (RemoteException ex) {}
391 }
392 }
393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800394 private void enforceStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700395 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700396 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800397 }
398
399 private void enforceExpandStatusBar() {
Joe Onorato0cbda992010-05-02 16:28:15 -0700400 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.EXPAND_STATUS_BAR,
Joe Onorato089de882010-04-12 08:18:45 -0700401 "StatusBarManagerService");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402 }
403
Joe Onorato8bc6c512010-06-04 16:21:12 -0400404 private void enforceStatusBarService() {
405 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
406 "StatusBarManagerService");
407 }
408
Joe Onorato4762c2d2010-05-17 15:42:59 -0700409 // ================================================================================
410 // Callbacks from the status bar service.
411 // ================================================================================
Joe Onorato75199e32010-05-29 17:22:51 -0400412 public void registerStatusBar(IStatusBar bar, StatusBarIconList iconList,
Joe Onorato93056472010-09-10 10:30:46 -0400413 List<IBinder> notificationKeys, List<StatusBarNotification> notifications,
satokcd7cd292010-11-20 15:46:23 +0900414 int switches[], List<IBinder> binders) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400415 enforceStatusBarService();
416
Joe Onorato0cbda992010-05-02 16:28:15 -0700417 Slog.i(TAG, "registerStatusBar bar=" + bar);
418 mBar = bar;
Joe Onorato75199e32010-05-29 17:22:51 -0400419 synchronized (mIcons) {
420 iconList.copyFrom(mIcons);
421 }
422 synchronized (mNotifications) {
423 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
424 notificationKeys.add(e.getKey());
425 notifications.add(e.getValue());
426 }
427 }
Joe Onorato93056472010-09-10 10:30:46 -0400428 synchronized (mLock) {
Joe Onoratoe4c7b3f2010-10-30 12:15:03 -0700429 switches[0] = gatherDisableActionsLocked();
Daniel Sandler60ee2562011-07-22 12:34:33 -0400430 switches[1] = mSystemUiVisibility;
Joe Onoratoe4c7b3f2010-10-30 12:15:03 -0700431 switches[2] = mMenuVisible ? 1 : 0;
Joe Onorato857fd9b2011-01-27 15:08:35 -0800432 switches[3] = mImeWindowVis;
433 switches[4] = mImeBackDisposition;
434 binders.add(mImeToken);
Joe Onorato93056472010-09-10 10:30:46 -0400435 }
Jeff Brown2992ea72011-01-28 22:04:14 -0800436 switches[5] = mWindowManager.isHardKeyboardAvailable() ? 1 : 0;
437 switches[6] = mWindowManager.isHardKeyboardEnabled() ? 1 : 0;
Joe Onorato2314aab2010-04-08 16:41:23 -0500438 }
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400439
Joe Onorato4762c2d2010-05-17 15:42:59 -0700440 /**
Joe Onoratof1f25912010-06-07 11:52:41 -0700441 * The status bar service should call this each time the user brings the panel from
442 * invisible to visible in order to clear the notification light.
Joe Onorato4762c2d2010-05-17 15:42:59 -0700443 */
Joe Onoratof1f25912010-06-07 11:52:41 -0700444 public void onPanelRevealed() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400445 enforceStatusBarService();
446
Joe Onoratof1f25912010-06-07 11:52:41 -0700447 // tell the notification manager to turn off the lights.
448 mNotificationCallbacks.onPanelRevealed();
Joe Onorato4762c2d2010-05-17 15:42:59 -0700449 }
450
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400451 public void onNotificationClick(String pkg, String tag, int id) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400452 enforceStatusBarService();
453
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400454 mNotificationCallbacks.onNotificationClick(pkg, tag, id);
455 }
456
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700457 public void onNotificationError(String pkg, String tag, int id,
458 int uid, int initialPid, String message) {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400459 enforceStatusBarService();
460
Joe Onorato005847b2010-06-04 16:08:02 -0400461 // WARNING: this will call back into us to do the remove. Don't hold any locks.
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700462 mNotificationCallbacks.onNotificationError(pkg, tag, id, uid, initialPid, message);
Joe Onorato005847b2010-06-04 16:08:02 -0400463 }
464
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400465 public void onNotificationClear(String pkg, String tag, int id) {
466 enforceStatusBarService();
467
468 mNotificationCallbacks.onNotificationClear(pkg, tag, id);
469 }
470
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400471 public void onClearAllNotifications() {
Joe Onorato8bc6c512010-06-04 16:21:12 -0400472 enforceStatusBarService();
473
Joe Onoratoaaba60b2010-05-23 15:18:41 -0400474 mNotificationCallbacks.onClearAll();
475 }
476
Joe Onorato18e69df2010-05-17 22:26:12 -0700477 // ================================================================================
478 // Callbacks for NotificationManagerService.
479 // ================================================================================
480 public IBinder addNotification(StatusBarNotification notification) {
481 synchronized (mNotifications) {
Joe Onoratoa0c56fe2010-05-20 10:21:52 -0700482 IBinder key = new Binder();
Joe Onorato75199e32010-05-29 17:22:51 -0400483 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400484 if (mBar != null) {
485 try {
486 mBar.addNotification(key, notification);
487 } catch (RemoteException ex) {
488 }
489 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700490 return key;
491 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700492 }
493
Joe Onorato18e69df2010-05-17 22:26:12 -0700494 public void updateNotification(IBinder key, StatusBarNotification notification) {
495 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400496 if (!mNotifications.containsKey(key)) {
497 throw new IllegalArgumentException("updateNotification key not found: " + key);
498 }
499 mNotifications.put(key, notification);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400500 if (mBar != null) {
501 try {
502 mBar.updateNotification(key, notification);
503 } catch (RemoteException ex) {
504 }
505 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700506 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700507 }
508
509 public void removeNotification(IBinder key) {
Joe Onorato18e69df2010-05-17 22:26:12 -0700510 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400511 final StatusBarNotification n = mNotifications.remove(key);
512 if (n == null) {
Daniel Sandlerfe0806a2012-05-16 12:41:33 -0400513 Slog.e(TAG, "removeNotification key not found: " + key);
514 return;
Joe Onorato75199e32010-05-29 17:22:51 -0400515 }
Joe Onoratoe345fff2010-05-23 15:18:27 -0400516 if (mBar != null) {
517 try {
518 mBar.removeNotification(key);
519 } catch (RemoteException ex) {
520 }
521 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700522 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700523 }
Joe Onorato2314aab2010-04-08 16:41:23 -0500524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800525 // ================================================================================
526 // Can be called from any thread
527 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800529 // lock on mDisableRecords
530 void manageDisableListLocked(int what, IBinder token, String pkg) {
531 if (SPEW) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700532 Slog.d(TAG, "manageDisableList what=0x" + Integer.toHexString(what) + " pkg=" + pkg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800533 }
534 // update the list
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800535 final int N = mDisableRecords.size();
536 DisableRecord tok = null;
537 int i;
538 for (i=0; i<N; i++) {
539 DisableRecord t = mDisableRecords.get(i);
540 if (t.token == token) {
541 tok = t;
542 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800543 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800544 }
545 if (what == 0 || !token.isBinderAlive()) {
546 if (tok != null) {
547 mDisableRecords.remove(i);
548 tok.token.unlinkToDeath(tok, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800549 }
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800550 } else {
551 if (tok == null) {
552 tok = new DisableRecord();
553 try {
554 token.linkToDeath(tok, 0);
555 }
556 catch (RemoteException ex) {
557 return; // give up
558 }
559 mDisableRecords.add(tok);
560 }
561 tok.what = what;
562 tok.token = token;
563 tok.pkg = pkg;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 }
565 }
566
567 // lock on mDisableRecords
568 int gatherDisableActionsLocked() {
569 final int N = mDisableRecords.size();
570 // gather the new net flags
571 int net = 0;
572 for (int i=0; i<N; i++) {
573 net |= mDisableRecords.get(i).what;
574 }
575 return net;
576 }
577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 // ================================================================================
579 // Always called from UI thread
580 // ================================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800582 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
583 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
584 != PackageManager.PERMISSION_GRANTED) {
585 pw.println("Permission Denial: can't dump StatusBar from from pid="
586 + Binder.getCallingPid()
587 + ", uid=" + Binder.getCallingUid());
588 return;
589 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700590
Joe Onorato0cbda992010-05-02 16:28:15 -0700591 synchronized (mIcons) {
592 mIcons.dump(pw);
593 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700594
595 synchronized (mNotifications) {
Joe Onorato75199e32010-05-29 17:22:51 -0400596 int i=0;
597 pw.println("Notification list:");
598 for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
599 pw.printf(" %2d: %s\n", i, e.getValue().toString());
600 i++;
601 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800602 }
Joe Onorato18e69df2010-05-17 22:26:12 -0700603
Joe Onorato7bb8eeb2011-01-27 16:00:58 -0800604 synchronized (mLock) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 final int N = mDisableRecords.size();
606 pw.println(" mDisableRecords.size=" + N
607 + " mDisabled=0x" + Integer.toHexString(mDisabled));
608 for (int i=0; i<N; i++) {
609 DisableRecord tok = mDisableRecords.get(i);
610 pw.println(" [" + i + "] what=0x" + Integer.toHexString(tok.what)
611 + " pkg=" + tok.pkg + " token=" + tok.token);
612 }
613 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800614 }
615
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800616 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
617 public void onReceive(Context context, Intent intent) {
618 String action = intent.getAction();
Joe Onoratof9e0e6b2009-09-08 16:24:36 -0400619 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
620 || Intent.ACTION_SCREEN_OFF.equals(action)) {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700621 collapseNotifications();
622 collapseQuickSettings();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800623 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700624 /*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800625 else if (Telephony.Intents.SPN_STRINGS_UPDATED_ACTION.equals(action)) {
626 updateNetworkName(intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_SPN, false),
627 intent.getStringExtra(Telephony.Intents.EXTRA_SPN),
628 intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_PLMN, false),
629 intent.getStringExtra(Telephony.Intents.EXTRA_PLMN));
630 }
631 else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
632 updateResources();
633 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700634 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 }
636 };
637
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800638}