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