| 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 | // ================================================================================ |
| 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 | */ |
| 251 | public void setMenuKeyVisible(final boolean visible) { |
| 252 | enforceStatusBar(); |
| 253 | |
| 254 | if (SPEW) Slog.d(TAG, (visible?"showing":"hiding") + " MENU key"); |
| 255 | |
| 256 | synchronized(mLock) { |
| 257 | if (mMenuVisible != visible) { |
| 258 | mMenuVisible = visible; |
| 259 | mHandler.post(new Runnable() { |
| 260 | public void run() { |
| 261 | if (mBar != null) { |
| 262 | try { |
| 263 | mBar.setMenuKeyVisible(visible); |
| 264 | } catch (RemoteException ex) { |
| 265 | } |
| 266 | } |
| 267 | } |
| 268 | }); |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | |
| Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 273 | public void setImeWindowStatus(final IBinder token, final int vis, final int backDisposition) { |
| satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 274 | enforceStatusBar(); |
| 275 | |
| Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 276 | if (SPEW) { |
| 277 | Slog.d(TAG, "swetImeWindowStatus vis=" + vis + " backDisposition=" + backDisposition); |
| 278 | } |
| satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 279 | |
| 280 | synchronized(mLock) { |
| Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 281 | // In case of IME change, we need to call up setImeWindowStatus() regardless of |
| 282 | // mImeWindowVis because mImeWindowVis may not have been set to false when the |
| satok | 06e0744 | 2010-11-02 19:46:55 +0900 | [diff] [blame] | 283 | // previous IME was destroyed. |
| Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 284 | mImeWindowVis = vis; |
| 285 | mImeBackDisposition = backDisposition; |
| 286 | mImeToken = token; |
| satok | 06e0744 | 2010-11-02 19:46:55 +0900 | [diff] [blame] | 287 | mHandler.post(new Runnable() { |
| 288 | public void run() { |
| 289 | if (mBar != null) { |
| 290 | try { |
| Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 291 | mBar.setImeWindowStatus(token, vis, backDisposition); |
| satok | 06e0744 | 2010-11-02 19:46:55 +0900 | [diff] [blame] | 292 | } catch (RemoteException ex) { |
| satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 293 | } |
| 294 | } |
| satok | 06e0744 | 2010-11-02 19:46:55 +0900 | [diff] [blame] | 295 | } |
| 296 | }); |
| satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 297 | } |
| 298 | } |
| 299 | |
| Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 300 | public void setSystemUiVisibility(int vis) { |
| Joe Onorato | 55bf380 | 2011-01-25 13:42:10 -0800 | [diff] [blame] | 301 | // also allows calls from window manager which is in this process. |
| Joe Onorato | f63b0f4 | 2010-09-12 17:03:19 -0400 | [diff] [blame] | 302 | enforceStatusBarService(); |
| 303 | |
| 304 | synchronized (mLock) { |
| Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 305 | final boolean lightsOn = (vis & View.STATUS_BAR_HIDDEN) == 0; |
| Joe Onorato | f63b0f4 | 2010-09-12 17:03:19 -0400 | [diff] [blame] | 306 | updateLightsOnLocked(lightsOn); |
| Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 307 | disableLocked(vis & StatusBarManager.DISABLE_MASK, mSysUiVisToken, |
| 308 | "WindowManager.LayoutParams"); |
| Joe Onorato | f63b0f4 | 2010-09-12 17:03:19 -0400 | [diff] [blame] | 309 | } |
| 310 | } |
| 311 | |
| 312 | private void updateLightsOnLocked(final boolean lightsOn) { |
| 313 | if (mLightsOn != lightsOn) { |
| 314 | mLightsOn = lightsOn; |
| 315 | mHandler.post(new Runnable() { |
| 316 | public void run() { |
| 317 | if (mBar != null) { |
| 318 | try { |
| 319 | mBar.setLightsOn(lightsOn); |
| 320 | } catch (RemoteException ex) { |
| Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 321 | } |
| 322 | } |
| Joe Onorato | f63b0f4 | 2010-09-12 17:03:19 -0400 | [diff] [blame] | 323 | } |
| 324 | }); |
| Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 325 | } |
| 326 | } |
| 327 | |
| Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 328 | public void setHardKeyboardEnabled(final boolean enabled) { |
| 329 | mHandler.post(new Runnable() { |
| 330 | public void run() { |
| 331 | mWindowManager.setHardKeyboardEnabled(enabled); |
| 332 | } |
| 333 | }); |
| 334 | } |
| 335 | |
| 336 | @Override |
| 337 | public void onHardKeyboardStatusChange(final boolean available, final boolean enabled) { |
| 338 | mHandler.post(new Runnable() { |
| 339 | public void run() { |
| 340 | if (mBar != null) { |
| 341 | try { |
| 342 | mBar.setHardKeyboardStatus(available, enabled); |
| 343 | } catch (RemoteException ex) { |
| 344 | } |
| 345 | } |
| 346 | } |
| 347 | }); |
| 348 | } |
| 349 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 350 | private void enforceStatusBar() { |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 351 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR, |
| Joe Onorato | 089de88 | 2010-04-12 08:18:45 -0700 | [diff] [blame] | 352 | "StatusBarManagerService"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | private void enforceExpandStatusBar() { |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 356 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.EXPAND_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 | |
| Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 360 | private void enforceStatusBarService() { |
| 361 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE, |
| 362 | "StatusBarManagerService"); |
| 363 | } |
| 364 | |
| Joe Onorato | 4762c2d | 2010-05-17 15:42:59 -0700 | [diff] [blame] | 365 | // ================================================================================ |
| 366 | // Callbacks from the status bar service. |
| 367 | // ================================================================================ |
| Joe Onorato | 75199e3 | 2010-05-29 17:22:51 -0400 | [diff] [blame] | 368 | public void registerStatusBar(IStatusBar bar, StatusBarIconList iconList, |
| Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 369 | List<IBinder> notificationKeys, List<StatusBarNotification> notifications, |
| satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 370 | int switches[], List<IBinder> binders) { |
| Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 371 | enforceStatusBarService(); |
| 372 | |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 373 | Slog.i(TAG, "registerStatusBar bar=" + bar); |
| 374 | mBar = bar; |
| Joe Onorato | 75199e3 | 2010-05-29 17:22:51 -0400 | [diff] [blame] | 375 | synchronized (mIcons) { |
| 376 | iconList.copyFrom(mIcons); |
| 377 | } |
| 378 | synchronized (mNotifications) { |
| 379 | for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) { |
| 380 | notificationKeys.add(e.getKey()); |
| 381 | notifications.add(e.getValue()); |
| 382 | } |
| 383 | } |
| Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 384 | synchronized (mLock) { |
| Joe Onorato | e4c7b3f | 2010-10-30 12:15:03 -0700 | [diff] [blame] | 385 | switches[0] = gatherDisableActionsLocked(); |
| 386 | switches[1] = mLightsOn ? 1 : 0; |
| 387 | switches[2] = mMenuVisible ? 1 : 0; |
| Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 388 | switches[3] = mImeWindowVis; |
| 389 | switches[4] = mImeBackDisposition; |
| 390 | binders.add(mImeToken); |
| Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 391 | } |
| Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 392 | switches[5] = mWindowManager.isHardKeyboardAvailable() ? 1 : 0; |
| 393 | switches[6] = mWindowManager.isHardKeyboardEnabled() ? 1 : 0; |
| Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 394 | } |
| Joe Onorato | aaba60b | 2010-05-23 15:18:41 -0400 | [diff] [blame] | 395 | |
| Joe Onorato | 4762c2d | 2010-05-17 15:42:59 -0700 | [diff] [blame] | 396 | /** |
| Joe Onorato | f1f2591 | 2010-06-07 11:52:41 -0700 | [diff] [blame] | 397 | * The status bar service should call this each time the user brings the panel from |
| 398 | * invisible to visible in order to clear the notification light. |
| Joe Onorato | 4762c2d | 2010-05-17 15:42:59 -0700 | [diff] [blame] | 399 | */ |
| Joe Onorato | f1f2591 | 2010-06-07 11:52:41 -0700 | [diff] [blame] | 400 | public void onPanelRevealed() { |
| Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 401 | enforceStatusBarService(); |
| 402 | |
| Joe Onorato | f1f2591 | 2010-06-07 11:52:41 -0700 | [diff] [blame] | 403 | // tell the notification manager to turn off the lights. |
| 404 | mNotificationCallbacks.onPanelRevealed(); |
| Joe Onorato | 4762c2d | 2010-05-17 15:42:59 -0700 | [diff] [blame] | 405 | } |
| 406 | |
| Joe Onorato | aaba60b | 2010-05-23 15:18:41 -0400 | [diff] [blame] | 407 | public void onNotificationClick(String pkg, String tag, int id) { |
| Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 408 | enforceStatusBarService(); |
| 409 | |
| Joe Onorato | aaba60b | 2010-05-23 15:18:41 -0400 | [diff] [blame] | 410 | mNotificationCallbacks.onNotificationClick(pkg, tag, id); |
| 411 | } |
| 412 | |
| Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 413 | public void onNotificationError(String pkg, String tag, int id, |
| 414 | int uid, int initialPid, String message) { |
| Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 415 | enforceStatusBarService(); |
| 416 | |
| Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 417 | // 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] | 418 | mNotificationCallbacks.onNotificationError(pkg, tag, id, uid, initialPid, message); |
| Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 419 | } |
| 420 | |
| Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 421 | public void onNotificationClear(String pkg, String tag, int id) { |
| 422 | enforceStatusBarService(); |
| 423 | |
| 424 | mNotificationCallbacks.onNotificationClear(pkg, tag, id); |
| 425 | } |
| 426 | |
| Joe Onorato | aaba60b | 2010-05-23 15:18:41 -0400 | [diff] [blame] | 427 | public void onClearAllNotifications() { |
| Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 428 | enforceStatusBarService(); |
| 429 | |
| Joe Onorato | aaba60b | 2010-05-23 15:18:41 -0400 | [diff] [blame] | 430 | mNotificationCallbacks.onClearAll(); |
| 431 | } |
| 432 | |
| Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 433 | // ================================================================================ |
| 434 | // Callbacks for NotificationManagerService. |
| 435 | // ================================================================================ |
| 436 | public IBinder addNotification(StatusBarNotification notification) { |
| 437 | synchronized (mNotifications) { |
| Joe Onorato | a0c56fe | 2010-05-20 10:21:52 -0700 | [diff] [blame] | 438 | IBinder key = new Binder(); |
| Joe Onorato | 75199e3 | 2010-05-29 17:22:51 -0400 | [diff] [blame] | 439 | mNotifications.put(key, notification); |
| Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 440 | if (mBar != null) { |
| 441 | try { |
| 442 | mBar.addNotification(key, notification); |
| 443 | } catch (RemoteException ex) { |
| 444 | } |
| 445 | } |
| Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 446 | return key; |
| 447 | } |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 448 | } |
| 449 | |
| Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 450 | public void updateNotification(IBinder key, StatusBarNotification notification) { |
| 451 | synchronized (mNotifications) { |
| Joe Onorato | 75199e3 | 2010-05-29 17:22:51 -0400 | [diff] [blame] | 452 | if (!mNotifications.containsKey(key)) { |
| 453 | throw new IllegalArgumentException("updateNotification key not found: " + key); |
| 454 | } |
| 455 | mNotifications.put(key, notification); |
| Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 456 | if (mBar != null) { |
| 457 | try { |
| 458 | mBar.updateNotification(key, notification); |
| 459 | } catch (RemoteException ex) { |
| 460 | } |
| 461 | } |
| Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 462 | } |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | public void removeNotification(IBinder key) { |
| Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 466 | synchronized (mNotifications) { |
| Joe Onorato | 75199e3 | 2010-05-29 17:22:51 -0400 | [diff] [blame] | 467 | final StatusBarNotification n = mNotifications.remove(key); |
| 468 | if (n == null) { |
| 469 | throw new IllegalArgumentException("removeNotification key not found: " + key); |
| 470 | } |
| Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 471 | if (mBar != null) { |
| 472 | try { |
| 473 | mBar.removeNotification(key); |
| 474 | } catch (RemoteException ex) { |
| 475 | } |
| 476 | } |
| Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 477 | } |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 478 | } |
| Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 479 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 480 | // ================================================================================ |
| 481 | // Can be called from any thread |
| 482 | // ================================================================================ |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 483 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 484 | // lock on mDisableRecords |
| 485 | void manageDisableListLocked(int what, IBinder token, String pkg) { |
| 486 | if (SPEW) { |
| Joe Onorato | f3f0e05 | 2010-05-14 18:49:29 -0700 | [diff] [blame] | 487 | 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] | 488 | } |
| 489 | // update the list |
| Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 490 | final int N = mDisableRecords.size(); |
| 491 | DisableRecord tok = null; |
| 492 | int i; |
| 493 | for (i=0; i<N; i++) { |
| 494 | DisableRecord t = mDisableRecords.get(i); |
| 495 | if (t.token == token) { |
| 496 | tok = t; |
| 497 | break; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 498 | } |
| Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 499 | } |
| 500 | if (what == 0 || !token.isBinderAlive()) { |
| 501 | if (tok != null) { |
| 502 | mDisableRecords.remove(i); |
| 503 | tok.token.unlinkToDeath(tok, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 504 | } |
| Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 505 | } else { |
| 506 | if (tok == null) { |
| 507 | tok = new DisableRecord(); |
| 508 | try { |
| 509 | token.linkToDeath(tok, 0); |
| 510 | } |
| 511 | catch (RemoteException ex) { |
| 512 | return; // give up |
| 513 | } |
| 514 | mDisableRecords.add(tok); |
| 515 | } |
| 516 | tok.what = what; |
| 517 | tok.token = token; |
| 518 | tok.pkg = pkg; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 519 | } |
| 520 | } |
| 521 | |
| 522 | // lock on mDisableRecords |
| 523 | int gatherDisableActionsLocked() { |
| 524 | final int N = mDisableRecords.size(); |
| 525 | // gather the new net flags |
| 526 | int net = 0; |
| 527 | for (int i=0; i<N; i++) { |
| 528 | net |= mDisableRecords.get(i).what; |
| 529 | } |
| 530 | return net; |
| 531 | } |
| 532 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 533 | // ================================================================================ |
| 534 | // Always called from UI thread |
| 535 | // ================================================================================ |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 536 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 537 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 538 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 539 | != PackageManager.PERMISSION_GRANTED) { |
| 540 | pw.println("Permission Denial: can't dump StatusBar from from pid=" |
| 541 | + Binder.getCallingPid() |
| 542 | + ", uid=" + Binder.getCallingUid()); |
| 543 | return; |
| 544 | } |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 545 | |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 546 | synchronized (mIcons) { |
| 547 | mIcons.dump(pw); |
| 548 | } |
| Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 549 | |
| 550 | synchronized (mNotifications) { |
| Joe Onorato | 75199e3 | 2010-05-29 17:22:51 -0400 | [diff] [blame] | 551 | int i=0; |
| 552 | pw.println("Notification list:"); |
| 553 | for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) { |
| 554 | pw.printf(" %2d: %s\n", i, e.getValue().toString()); |
| 555 | i++; |
| 556 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 557 | } |
| Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 558 | |
| Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 559 | synchronized (mLock) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 560 | final int N = mDisableRecords.size(); |
| 561 | pw.println(" mDisableRecords.size=" + N |
| 562 | + " mDisabled=0x" + Integer.toHexString(mDisabled)); |
| 563 | for (int i=0; i<N; i++) { |
| 564 | DisableRecord tok = mDisableRecords.get(i); |
| 565 | pw.println(" [" + i + "] what=0x" + Integer.toHexString(tok.what) |
| 566 | + " pkg=" + tok.pkg + " token=" + tok.token); |
| 567 | } |
| 568 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 569 | } |
| 570 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 571 | private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 572 | public void onReceive(Context context, Intent intent) { |
| 573 | String action = intent.getAction(); |
| Joe Onorato | f9e0e6b | 2009-09-08 16:24:36 -0400 | [diff] [blame] | 574 | if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action) |
| 575 | || Intent.ACTION_SCREEN_OFF.equals(action)) { |
| Joe Onorato | f3f0e05 | 2010-05-14 18:49:29 -0700 | [diff] [blame] | 576 | collapse(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 577 | } |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 578 | /* |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 579 | else if (Telephony.Intents.SPN_STRINGS_UPDATED_ACTION.equals(action)) { |
| 580 | updateNetworkName(intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_SPN, false), |
| 581 | intent.getStringExtra(Telephony.Intents.EXTRA_SPN), |
| 582 | intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_PLMN, false), |
| 583 | intent.getStringExtra(Telephony.Intents.EXTRA_PLMN)); |
| 584 | } |
| 585 | else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) { |
| 586 | updateResources(); |
| 587 | } |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 588 | */ |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 589 | } |
| 590 | }; |
| 591 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 592 | } |