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