| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 Onorato | 7a0f36b | 2010-06-07 10:24:36 -0700 | [diff] [blame] | 17 | package com.android.server; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | import android.app.PendingIntent; |
| 20 | import android.app.StatusBarManager; |
| 21 | import android.content.BroadcastReceiver; |
| Joe Onorato | 9e875fc | 2010-06-07 11:12:11 -0700 | [diff] [blame] | 22 | import android.content.ComponentName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import android.content.Context; |
| 24 | import android.content.Intent; |
| 25 | import android.content.IntentFilter; |
| 26 | import android.content.pm.PackageManager; |
| 27 | import android.content.res.Resources; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | import android.net.Uri; |
| 29 | import android.os.IBinder; |
| 30 | import android.os.RemoteException; |
| 31 | import android.os.Binder; |
| Joe Onorato | f3f0e05 | 2010-05-14 18:49:29 -0700 | [diff] [blame] | 32 | import android.os.Handler; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | import android.os.SystemClock; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 34 | import android.util.Slog; |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 35 | |
| 36 | import com.android.internal.statusbar.IStatusBar; |
| 37 | import com.android.internal.statusbar.IStatusBarService; |
| 38 | import com.android.internal.statusbar.StatusBarIcon; |
| 39 | import com.android.internal.statusbar.StatusBarIconList; |
| Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 40 | import com.android.internal.statusbar.StatusBarNotification; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 41 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | import java.io.FileDescriptor; |
| 43 | import java.io.PrintWriter; |
| 44 | import java.util.ArrayList; |
| 45 | import java.util.HashMap; |
| Joe Onorato | 75199e3 | 2010-05-29 17:22:51 -0400 | [diff] [blame] | 46 | import java.util.List; |
| 47 | import java.util.Map; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | |
| 49 | |
| 50 | /** |
| Joe Onorato | f3f0e05 | 2010-05-14 18:49:29 -0700 | [diff] [blame] | 51 | * A note on locking: We rely on the fact that calls onto mBar are oneway or |
| 52 | * if they are local, that they just enqueue messages to not deadlock. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | */ |
| Joe Onorato | 089de88 | 2010-04-12 08:18:45 -0700 | [diff] [blame] | 54 | public class StatusBarManagerService extends IStatusBarService.Stub |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | { |
| Joe Onorato | 4762c2d | 2010-05-17 15:42:59 -0700 | [diff] [blame] | 56 | static final String TAG = "StatusBarManagerService"; |
| Joe Onorato | f3f0e05 | 2010-05-14 18:49:29 -0700 | [diff] [blame] | 57 | static final boolean SPEW = true; |
| Joe Onorato | df7dbb6 | 2009-11-17 10:43:37 -0800 | [diff] [blame] | 58 | |
| Joe Onorato | f3f0e05 | 2010-05-14 18:49:29 -0700 | [diff] [blame] | 59 | final Context mContext; |
| 60 | Handler mHandler = new Handler(); |
| 61 | NotificationCallbacks mNotificationCallbacks; |
| Joe Onorato | 4762c2d | 2010-05-17 15:42:59 -0700 | [diff] [blame] | 62 | volatile IStatusBar mBar; |
| Joe Onorato | f3f0e05 | 2010-05-14 18:49:29 -0700 | [diff] [blame] | 63 | StatusBarIconList mIcons = new StatusBarIconList(); |
| Joe Onorato | 75199e3 | 2010-05-29 17:22:51 -0400 | [diff] [blame] | 64 | HashMap<IBinder,StatusBarNotification> mNotifications |
| 65 | = new HashMap<IBinder,StatusBarNotification>(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | |
| Joe Onorato | f3f0e05 | 2010-05-14 18:49:29 -0700 | [diff] [blame] | 67 | // for disabling the status bar |
| 68 | ArrayList<DisableRecord> mDisableRecords = new ArrayList<DisableRecord>(); |
| 69 | int mDisabled = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | |
| 71 | private class DisableRecord implements IBinder.DeathRecipient { |
| 72 | String pkg; |
| 73 | int what; |
| 74 | IBinder token; |
| 75 | |
| 76 | public void binderDied() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 77 | Slog.i(TAG, "binder died for pkg=" + pkg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | disable(0, token, pkg); |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 79 | token.unlinkToDeath(this, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | |
| 83 | public interface NotificationCallbacks { |
| 84 | void onSetDisabled(int status); |
| 85 | void onClearAll(); |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 86 | void onNotificationClick(String pkg, String tag, int id); |
| Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame^] | 87 | void onNotificationClear(String pkg, String tag, int id); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | void onPanelRevealed(); |
| Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 89 | void onNotificationError(String pkg, String tag, int id, |
| 90 | int uid, int initialPid, String message); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | } |
| 92 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | /** |
| 94 | * Construct the service, add the status bar view to the window manager |
| 95 | */ |
| Joe Onorato | 089de88 | 2010-04-12 08:18:45 -0700 | [diff] [blame] | 96 | public StatusBarManagerService(Context context) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | mContext = context; |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 98 | |
| 99 | final Resources res = context.getResources(); |
| Joe Onorato | 75144ea | 2010-06-07 12:36:25 -0700 | [diff] [blame] | 100 | mIcons.defineSlots(res.getStringArray(com.android.internal.R.array.config_statusBarIcons)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | public void setNotificationCallbacks(NotificationCallbacks listener) { |
| 104 | mNotificationCallbacks = listener; |
| 105 | } |
| 106 | |
| 107 | // ================================================================================ |
| 108 | // Constructing the view |
| 109 | // ================================================================================ |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | |
| 111 | public void systemReady() { |
| Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | public void systemReady2() { |
| Joe Onorato | 9e875fc | 2010-06-07 11:12:11 -0700 | [diff] [blame] | 115 | ComponentName cn = ComponentName.unflattenFromString( |
| 116 | mContext.getString(com.android.internal.R.string.config_statusBarComponent)); |
| 117 | Intent intent = new Intent(); |
| 118 | intent.setComponent(cn); |
| 119 | Slog.i(TAG, "Starting service: " + cn); |
| 120 | mContext.startService(intent); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 121 | } |
| Joe Onorato | 4762c2d | 2010-05-17 15:42:59 -0700 | [diff] [blame] | 122 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | // ================================================================================ |
| Joe Onorato | 25f95f9 | 2010-04-08 18:37:10 -0500 | [diff] [blame] | 124 | // From IStatusBarService |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | // ================================================================================ |
| Joe Onorato | f3f0e05 | 2010-05-14 18:49:29 -0700 | [diff] [blame] | 126 | public void expand() { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | enforceExpandStatusBar(); |
| Joe Onorato | 4762c2d | 2010-05-17 15:42:59 -0700 | [diff] [blame] | 128 | |
| 129 | if (mBar != null) { |
| 130 | try { |
| 131 | mBar.animateExpand(); |
| 132 | } catch (RemoteException ex) { |
| 133 | } |
| 134 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | } |
| 136 | |
| Joe Onorato | f3f0e05 | 2010-05-14 18:49:29 -0700 | [diff] [blame] | 137 | public void collapse() { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | enforceExpandStatusBar(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | |
| Joe Onorato | 4762c2d | 2010-05-17 15:42:59 -0700 | [diff] [blame] | 140 | if (mBar != null) { |
| 141 | try { |
| 142 | mBar.animateCollapse(); |
| 143 | } catch (RemoteException ex) { |
| 144 | } |
| 145 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | public void disable(int what, IBinder token, String pkg) { |
| 149 | enforceStatusBar(); |
| Joe Onorato | f3f0e05 | 2010-05-14 18:49:29 -0700 | [diff] [blame] | 150 | |
| 151 | // 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. |
| 155 | synchronized (mDisableRecords) { |
| 156 | manageDisableListLocked(what, token, pkg); |
| 157 | final int net = gatherDisableActionsLocked(); |
| 158 | Slog.d(TAG, "disable... net=0x" + Integer.toHexString(net)); |
| 159 | if (net != mDisabled) { |
| 160 | mDisabled = net; |
| 161 | mHandler.post(new Runnable() { |
| 162 | public void run() { |
| 163 | mNotificationCallbacks.onSetDisabled(net); |
| 164 | } |
| 165 | }); |
| 166 | if (mBar != null) { |
| 167 | try { |
| 168 | mBar.disable(net); |
| 169 | } catch (RemoteException ex) { |
| 170 | } |
| 171 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | } |
| 174 | } |
| 175 | |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 176 | public void setIcon(String slot, String iconPackage, int iconId, int iconLevel) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | enforceStatusBar(); |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 178 | |
| 179 | synchronized (mIcons) { |
| 180 | int index = mIcons.getSlotIndex(slot); |
| 181 | if (index < 0) { |
| 182 | throw new SecurityException("invalid status bar icon slot: " + slot); |
| 183 | } |
| 184 | |
| 185 | StatusBarIcon icon = new StatusBarIcon(iconPackage, iconId, iconLevel); |
| Joe Onorato | 66d7d01 | 2010-05-14 10:05:10 -0700 | [diff] [blame] | 186 | //Slog.d(TAG, "setIcon slot=" + slot + " index=" + index + " icon=" + icon); |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 187 | mIcons.setIcon(index, icon); |
| 188 | |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 189 | if (mBar != null) { |
| 190 | try { |
| 191 | mBar.setIcon(index, icon); |
| 192 | } catch (RemoteException ex) { |
| 193 | } |
| 194 | } |
| 195 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | } |
| 197 | |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 198 | public void setIconVisibility(String slot, boolean visible) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | enforceStatusBar(); |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 200 | |
| Joe Onorato | 514ad663 | 2010-05-13 18:49:00 -0700 | [diff] [blame] | 201 | 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 Onorato | 514ad663 | 2010-05-13 18:49:00 -0700 | [diff] [blame] | 215 | if (mBar != null) { |
| 216 | try { |
| 217 | mBar.setIcon(index, icon); |
| 218 | } catch (RemoteException ex) { |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | } |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 223 | } |
| 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 Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 236 | if (mBar != null) { |
| 237 | try { |
| 238 | mBar.removeIcon(index); |
| 239 | } catch (RemoteException ex) { |
| 240 | } |
| 241 | } |
| 242 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | private void enforceStatusBar() { |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 246 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR, |
| Joe Onorato | 089de88 | 2010-04-12 08:18:45 -0700 | [diff] [blame] | 247 | "StatusBarManagerService"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | private void enforceExpandStatusBar() { |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 251 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.EXPAND_STATUS_BAR, |
| Joe Onorato | 089de88 | 2010-04-12 08:18:45 -0700 | [diff] [blame] | 252 | "StatusBarManagerService"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | } |
| 254 | |
| Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 255 | private void enforceStatusBarService() { |
| 256 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE, |
| 257 | "StatusBarManagerService"); |
| 258 | } |
| 259 | |
| Joe Onorato | 4762c2d | 2010-05-17 15:42:59 -0700 | [diff] [blame] | 260 | |
| 261 | // ================================================================================ |
| 262 | // Callbacks from the status bar service. |
| 263 | // ================================================================================ |
| Joe Onorato | 75199e3 | 2010-05-29 17:22:51 -0400 | [diff] [blame] | 264 | public void registerStatusBar(IStatusBar bar, StatusBarIconList iconList, |
| 265 | List<IBinder> notificationKeys, List<StatusBarNotification> notifications) { |
| Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 266 | enforceStatusBarService(); |
| 267 | |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 268 | Slog.i(TAG, "registerStatusBar bar=" + bar); |
| 269 | mBar = bar; |
| Joe Onorato | 75199e3 | 2010-05-29 17:22:51 -0400 | [diff] [blame] | 270 | synchronized (mIcons) { |
| 271 | iconList.copyFrom(mIcons); |
| 272 | } |
| 273 | synchronized (mNotifications) { |
| 274 | for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) { |
| 275 | notificationKeys.add(e.getKey()); |
| 276 | notifications.add(e.getValue()); |
| 277 | } |
| 278 | } |
| Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 279 | } |
| Joe Onorato | aaba60b | 2010-05-23 15:18:41 -0400 | [diff] [blame] | 280 | |
| Joe Onorato | 4762c2d | 2010-05-17 15:42:59 -0700 | [diff] [blame] | 281 | /** |
| Joe Onorato | f1f2591 | 2010-06-07 11:52:41 -0700 | [diff] [blame] | 282 | * The status bar service should call this each time the user brings the panel from |
| 283 | * invisible to visible in order to clear the notification light. |
| Joe Onorato | 4762c2d | 2010-05-17 15:42:59 -0700 | [diff] [blame] | 284 | */ |
| Joe Onorato | f1f2591 | 2010-06-07 11:52:41 -0700 | [diff] [blame] | 285 | public void onPanelRevealed() { |
| Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 286 | enforceStatusBarService(); |
| 287 | |
| Joe Onorato | f1f2591 | 2010-06-07 11:52:41 -0700 | [diff] [blame] | 288 | // tell the notification manager to turn off the lights. |
| 289 | mNotificationCallbacks.onPanelRevealed(); |
| Joe Onorato | 4762c2d | 2010-05-17 15:42:59 -0700 | [diff] [blame] | 290 | } |
| 291 | |
| Joe Onorato | aaba60b | 2010-05-23 15:18:41 -0400 | [diff] [blame] | 292 | public void onNotificationClick(String pkg, String tag, int id) { |
| Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 293 | enforceStatusBarService(); |
| 294 | |
| Joe Onorato | aaba60b | 2010-05-23 15:18:41 -0400 | [diff] [blame] | 295 | mNotificationCallbacks.onNotificationClick(pkg, tag, id); |
| 296 | } |
| 297 | |
| Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 298 | public void onNotificationError(String pkg, String tag, int id, |
| 299 | int uid, int initialPid, String message) { |
| Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 300 | enforceStatusBarService(); |
| 301 | |
| Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 302 | // WARNING: this will call back into us to do the remove. Don't hold any locks. |
| Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 303 | mNotificationCallbacks.onNotificationError(pkg, tag, id, uid, initialPid, message); |
| Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 304 | } |
| 305 | |
| Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame^] | 306 | public void onNotificationClear(String pkg, String tag, int id) { |
| 307 | enforceStatusBarService(); |
| 308 | |
| 309 | mNotificationCallbacks.onNotificationClear(pkg, tag, id); |
| 310 | } |
| 311 | |
| Joe Onorato | aaba60b | 2010-05-23 15:18:41 -0400 | [diff] [blame] | 312 | public void onClearAllNotifications() { |
| Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 313 | enforceStatusBarService(); |
| 314 | |
| Joe Onorato | aaba60b | 2010-05-23 15:18:41 -0400 | [diff] [blame] | 315 | mNotificationCallbacks.onClearAll(); |
| 316 | } |
| 317 | |
| Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 318 | // ================================================================================ |
| 319 | // Callbacks for NotificationManagerService. |
| 320 | // ================================================================================ |
| 321 | public IBinder addNotification(StatusBarNotification notification) { |
| 322 | synchronized (mNotifications) { |
| Joe Onorato | a0c56fe | 2010-05-20 10:21:52 -0700 | [diff] [blame] | 323 | IBinder key = new Binder(); |
| Joe Onorato | 75199e3 | 2010-05-29 17:22:51 -0400 | [diff] [blame] | 324 | mNotifications.put(key, notification); |
| Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 325 | if (mBar != null) { |
| 326 | try { |
| 327 | mBar.addNotification(key, notification); |
| 328 | } catch (RemoteException ex) { |
| 329 | } |
| 330 | } |
| Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 331 | return key; |
| 332 | } |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 333 | } |
| 334 | |
| Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 335 | public void updateNotification(IBinder key, StatusBarNotification notification) { |
| 336 | synchronized (mNotifications) { |
| Joe Onorato | 75199e3 | 2010-05-29 17:22:51 -0400 | [diff] [blame] | 337 | if (!mNotifications.containsKey(key)) { |
| 338 | throw new IllegalArgumentException("updateNotification key not found: " + key); |
| 339 | } |
| 340 | mNotifications.put(key, notification); |
| Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 341 | if (mBar != null) { |
| 342 | try { |
| 343 | mBar.updateNotification(key, notification); |
| 344 | } catch (RemoteException ex) { |
| 345 | } |
| 346 | } |
| Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 347 | } |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | public void removeNotification(IBinder key) { |
| Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 351 | synchronized (mNotifications) { |
| Joe Onorato | 75199e3 | 2010-05-29 17:22:51 -0400 | [diff] [blame] | 352 | final StatusBarNotification n = mNotifications.remove(key); |
| 353 | if (n == null) { |
| 354 | throw new IllegalArgumentException("removeNotification key not found: " + key); |
| 355 | } |
| Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 356 | if (mBar != null) { |
| 357 | try { |
| 358 | mBar.removeNotification(key); |
| 359 | } catch (RemoteException ex) { |
| 360 | } |
| 361 | } |
| Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 362 | } |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 363 | } |
| Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 364 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 365 | // ================================================================================ |
| 366 | // Can be called from any thread |
| 367 | // ================================================================================ |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 369 | // lock on mDisableRecords |
| 370 | void manageDisableListLocked(int what, IBinder token, String pkg) { |
| 371 | if (SPEW) { |
| Joe Onorato | f3f0e05 | 2010-05-14 18:49:29 -0700 | [diff] [blame] | 372 | Slog.d(TAG, "manageDisableList what=0x" + Integer.toHexString(what) + " pkg=" + pkg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 373 | } |
| 374 | // update the list |
| 375 | synchronized (mDisableRecords) { |
| 376 | final int N = mDisableRecords.size(); |
| 377 | DisableRecord tok = null; |
| 378 | int i; |
| 379 | for (i=0; i<N; i++) { |
| 380 | DisableRecord t = mDisableRecords.get(i); |
| 381 | if (t.token == token) { |
| 382 | tok = t; |
| 383 | break; |
| 384 | } |
| 385 | } |
| 386 | if (what == 0 || !token.isBinderAlive()) { |
| 387 | if (tok != null) { |
| 388 | mDisableRecords.remove(i); |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 389 | tok.token.unlinkToDeath(tok, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 390 | } |
| 391 | } else { |
| 392 | if (tok == null) { |
| 393 | tok = new DisableRecord(); |
| 394 | try { |
| 395 | token.linkToDeath(tok, 0); |
| 396 | } |
| 397 | catch (RemoteException ex) { |
| 398 | return; // give up |
| 399 | } |
| 400 | mDisableRecords.add(tok); |
| 401 | } |
| 402 | tok.what = what; |
| 403 | tok.token = token; |
| 404 | tok.pkg = pkg; |
| 405 | } |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | // lock on mDisableRecords |
| 410 | int gatherDisableActionsLocked() { |
| 411 | final int N = mDisableRecords.size(); |
| 412 | // gather the new net flags |
| 413 | int net = 0; |
| 414 | for (int i=0; i<N; i++) { |
| 415 | net |= mDisableRecords.get(i).what; |
| 416 | } |
| 417 | return net; |
| 418 | } |
| 419 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 420 | // ================================================================================ |
| 421 | // Always called from UI thread |
| 422 | // ================================================================================ |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 423 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 424 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 425 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 426 | != PackageManager.PERMISSION_GRANTED) { |
| 427 | pw.println("Permission Denial: can't dump StatusBar from from pid=" |
| 428 | + Binder.getCallingPid() |
| 429 | + ", uid=" + Binder.getCallingUid()); |
| 430 | return; |
| 431 | } |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 432 | |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 433 | synchronized (mIcons) { |
| 434 | mIcons.dump(pw); |
| 435 | } |
| Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 436 | |
| 437 | synchronized (mNotifications) { |
| Joe Onorato | 75199e3 | 2010-05-29 17:22:51 -0400 | [diff] [blame] | 438 | int i=0; |
| 439 | pw.println("Notification list:"); |
| 440 | for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) { |
| 441 | pw.printf(" %2d: %s\n", i, e.getValue().toString()); |
| 442 | i++; |
| 443 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | } |
| Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 445 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 446 | synchronized (mDisableRecords) { |
| 447 | final int N = mDisableRecords.size(); |
| 448 | pw.println(" mDisableRecords.size=" + N |
| 449 | + " mDisabled=0x" + Integer.toHexString(mDisabled)); |
| 450 | for (int i=0; i<N; i++) { |
| 451 | DisableRecord tok = mDisableRecords.get(i); |
| 452 | pw.println(" [" + i + "] what=0x" + Integer.toHexString(tok.what) |
| 453 | + " pkg=" + tok.pkg + " token=" + tok.token); |
| 454 | } |
| 455 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 456 | } |
| 457 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 458 | private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 459 | public void onReceive(Context context, Intent intent) { |
| 460 | String action = intent.getAction(); |
| Joe Onorato | f9e0e6b | 2009-09-08 16:24:36 -0400 | [diff] [blame] | 461 | if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action) |
| 462 | || Intent.ACTION_SCREEN_OFF.equals(action)) { |
| Joe Onorato | f3f0e05 | 2010-05-14 18:49:29 -0700 | [diff] [blame] | 463 | collapse(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 464 | } |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 465 | /* |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 466 | else if (Telephony.Intents.SPN_STRINGS_UPDATED_ACTION.equals(action)) { |
| 467 | updateNetworkName(intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_SPN, false), |
| 468 | intent.getStringExtra(Telephony.Intents.EXTRA_SPN), |
| 469 | intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_PLMN, false), |
| 470 | intent.getStringExtra(Telephony.Intents.EXTRA_PLMN)); |
| 471 | } |
| 472 | else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) { |
| 473 | updateResources(); |
| 474 | } |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 475 | */ |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | } |
| 477 | }; |
| 478 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 479 | } |