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