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