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