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