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