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