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