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