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