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