Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | 79de0c5 | 2010-05-26 17:03:26 -0400 | [diff] [blame] | 17 | package com.android.systemui.statusbar; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 18 | |
| 19 | import android.os.Handler; |
Joe Onorato | a0c56fe | 2010-05-20 10:21:52 -0700 | [diff] [blame] | 20 | import android.os.IBinder; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 21 | import android.os.Message; |
| 22 | |
| 23 | import com.android.internal.statusbar.IStatusBar; |
| 24 | import com.android.internal.statusbar.StatusBarIcon; |
| 25 | import com.android.internal.statusbar.StatusBarIconList; |
Joe Onorato | a0c56fe | 2010-05-20 10:21:52 -0700 | [diff] [blame] | 26 | import com.android.internal.statusbar.StatusBarNotification; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 27 | |
Joe Onorato | f3f0e05 | 2010-05-14 18:49:29 -0700 | [diff] [blame] | 28 | /** |
| 29 | * This class takes the functions from IStatusBar that come in on |
| 30 | * binder pool threads and posts messages to get them onto the main |
| 31 | * thread, and calls onto Callbacks. It also takes care of |
Joe Onorato | 4762c2d | 2010-05-17 15:42:59 -0700 | [diff] [blame] | 32 | * coalescing these calls so they don't stack up. For the calls |
| 33 | * are coalesced, note that they are all idempotent. |
Joe Onorato | f3f0e05 | 2010-05-14 18:49:29 -0700 | [diff] [blame] | 34 | */ |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 35 | public class CommandQueue extends IStatusBar.Stub { |
Joe Onorato | 514ad663 | 2010-05-13 18:49:00 -0700 | [diff] [blame] | 36 | private static final String TAG = "StatusBar.CommandQueue"; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 37 | |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 38 | private static final int INDEX_MASK = 0xffff; |
| 39 | private static final int MSG_SHIFT = 16; |
| 40 | private static final int MSG_MASK = 0xffff << MSG_SHIFT; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 41 | |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 42 | |
| 43 | private static final int MSG_ICON = 1 << MSG_SHIFT; |
| 44 | private static final int OP_SET_ICON = 1; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 45 | private static final int OP_REMOVE_ICON = 2; |
| 46 | |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 47 | private static final int MSG_ADD_NOTIFICATION = 2 << MSG_SHIFT; |
| 48 | private static final int MSG_UPDATE_NOTIFICATION = 3 << MSG_SHIFT; |
| 49 | private static final int MSG_REMOVE_NOTIFICATION = 4 << MSG_SHIFT; |
Joe Onorato | f3f0e05 | 2010-05-14 18:49:29 -0700 | [diff] [blame] | 50 | |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 51 | private static final int MSG_DISABLE = 5 << MSG_SHIFT; |
Joe Onorato | a0c56fe | 2010-05-20 10:21:52 -0700 | [diff] [blame] | 52 | |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 53 | private static final int MSG_SET_VISIBILITY = 6 << MSG_SHIFT; |
| 54 | private static final int OP_EXPAND = 1; |
| 55 | private static final int OP_COLLAPSE = 2; |
Joe Onorato | 4762c2d | 2010-05-17 15:42:59 -0700 | [diff] [blame] | 56 | |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 57 | private static final int MSG_SET_SYSTEMUI_VISIBILITY = 7 << MSG_SHIFT; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 58 | |
Dianne Hackborn | 3fe9cc5 | 2011-06-14 16:13:26 -0700 | [diff] [blame] | 59 | private static final int MSG_TOP_APP_WINDOW_CHANGED = 8 << MSG_SHIFT; |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 60 | private static final int MSG_SHOW_IME_BUTTON = 9 << MSG_SHIFT; |
| 61 | private static final int MSG_SET_HARD_KEYBOARD_STATUS = 10 << MSG_SHIFT; |
| 62 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 63 | private static final int MSG_TOGGLE_RECENT_APPS = 11 << MSG_SHIFT; |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 64 | |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame^] | 65 | private static final int MSG_SET_NAVIGATION_ICON_HINTS = 13 << MSG_SHIFT; |
| 66 | |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 67 | private StatusBarIconList mList; |
| 68 | private Callbacks mCallbacks; |
| 69 | private Handler mHandler = new H(); |
| 70 | |
Joe Onorato | a0c56fe | 2010-05-20 10:21:52 -0700 | [diff] [blame] | 71 | private class NotificationQueueEntry { |
| 72 | IBinder key; |
| 73 | StatusBarNotification notification; |
| 74 | } |
| 75 | |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 76 | /** |
| 77 | * These methods are called back on the main thread. |
| 78 | */ |
| 79 | public interface Callbacks { |
| 80 | public void addIcon(String slot, int index, int viewIndex, StatusBarIcon icon); |
| 81 | public void updateIcon(String slot, int index, int viewIndex, |
| 82 | StatusBarIcon old, StatusBarIcon icon); |
| 83 | public void removeIcon(String slot, int index, int viewIndex); |
Joe Onorato | a0c56fe | 2010-05-20 10:21:52 -0700 | [diff] [blame] | 84 | public void addNotification(IBinder key, StatusBarNotification notification); |
| 85 | public void updateNotification(IBinder key, StatusBarNotification notification); |
| 86 | public void removeNotification(IBinder key); |
Joe Onorato | f3f0e05 | 2010-05-14 18:49:29 -0700 | [diff] [blame] | 87 | public void disable(int state); |
Joe Onorato | 4762c2d | 2010-05-17 15:42:59 -0700 | [diff] [blame] | 88 | public void animateExpand(); |
| 89 | public void animateCollapse(); |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 90 | public void setSystemUiVisibility(int vis); |
Dianne Hackborn | 7d04932 | 2011-06-14 15:00:32 -0700 | [diff] [blame] | 91 | public void topAppWindowChanged(boolean visible); |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 92 | public void setImeWindowStatus(IBinder token, int vis, int backDisposition); |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 93 | public void setHardKeyboardStatus(boolean available, boolean enabled); |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 94 | public void toggleRecentApps(); |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame^] | 95 | public void setNavigationIconHints(int hints); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | public CommandQueue(Callbacks callbacks, StatusBarIconList list) { |
| 99 | mCallbacks = callbacks; |
| 100 | mList = list; |
| 101 | } |
| 102 | |
| 103 | public void setIcon(int index, StatusBarIcon icon) { |
| 104 | synchronized (mList) { |
| 105 | int what = MSG_ICON | index; |
| 106 | mHandler.removeMessages(what); |
| 107 | mHandler.obtainMessage(what, OP_SET_ICON, 0, icon.clone()).sendToTarget(); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | public void removeIcon(int index) { |
| 112 | synchronized (mList) { |
| 113 | int what = MSG_ICON | index; |
| 114 | mHandler.removeMessages(what); |
| 115 | mHandler.obtainMessage(what, OP_REMOVE_ICON, 0, null).sendToTarget(); |
| 116 | } |
| 117 | } |
| 118 | |
Joe Onorato | a0c56fe | 2010-05-20 10:21:52 -0700 | [diff] [blame] | 119 | public void addNotification(IBinder key, StatusBarNotification notification) { |
| 120 | synchronized (mList) { |
| 121 | NotificationQueueEntry ne = new NotificationQueueEntry(); |
| 122 | ne.key = key; |
| 123 | ne.notification = notification; |
| 124 | mHandler.obtainMessage(MSG_ADD_NOTIFICATION, 0, 0, ne).sendToTarget(); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | public void updateNotification(IBinder key, StatusBarNotification notification) { |
| 129 | synchronized (mList) { |
| 130 | NotificationQueueEntry ne = new NotificationQueueEntry(); |
| 131 | ne.key = key; |
| 132 | ne.notification = notification; |
| 133 | mHandler.obtainMessage(MSG_UPDATE_NOTIFICATION, 0, 0, ne).sendToTarget(); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | public void removeNotification(IBinder key) { |
| 138 | synchronized (mList) { |
| 139 | mHandler.obtainMessage(MSG_REMOVE_NOTIFICATION, 0, 0, key).sendToTarget(); |
| 140 | } |
| 141 | } |
| 142 | |
Joe Onorato | f3f0e05 | 2010-05-14 18:49:29 -0700 | [diff] [blame] | 143 | public void disable(int state) { |
| 144 | synchronized (mList) { |
| 145 | mHandler.removeMessages(MSG_DISABLE); |
| 146 | mHandler.obtainMessage(MSG_DISABLE, state, 0, null).sendToTarget(); |
| 147 | } |
| 148 | } |
| 149 | |
Joe Onorato | 4762c2d | 2010-05-17 15:42:59 -0700 | [diff] [blame] | 150 | public void animateExpand() { |
| 151 | synchronized (mList) { |
| 152 | mHandler.removeMessages(MSG_SET_VISIBILITY); |
| 153 | mHandler.obtainMessage(MSG_SET_VISIBILITY, OP_EXPAND, 0, null).sendToTarget(); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | public void animateCollapse() { |
| 158 | synchronized (mList) { |
| 159 | mHandler.removeMessages(MSG_SET_VISIBILITY); |
| 160 | mHandler.obtainMessage(MSG_SET_VISIBILITY, OP_COLLAPSE, 0, null).sendToTarget(); |
| 161 | } |
| 162 | } |
| 163 | |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 164 | public void setSystemUiVisibility(int vis) { |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 165 | synchronized (mList) { |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 166 | mHandler.removeMessages(MSG_SET_SYSTEMUI_VISIBILITY); |
| 167 | mHandler.obtainMessage(MSG_SET_SYSTEMUI_VISIBILITY, vis, 0, null).sendToTarget(); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 168 | } |
| 169 | } |
| 170 | |
Dianne Hackborn | 7d04932 | 2011-06-14 15:00:32 -0700 | [diff] [blame] | 171 | public void topAppWindowChanged(boolean menuVisible) { |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 172 | synchronized (mList) { |
Dianne Hackborn | 7d04932 | 2011-06-14 15:00:32 -0700 | [diff] [blame] | 173 | mHandler.removeMessages(MSG_TOP_APP_WINDOW_CHANGED); |
| 174 | mHandler.obtainMessage(MSG_TOP_APP_WINDOW_CHANGED, menuVisible ? 1 : 0, 0, |
| 175 | null).sendToTarget(); |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 179 | public void setImeWindowStatus(IBinder token, int vis, int backDisposition) { |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 180 | synchronized (mList) { |
| 181 | mHandler.removeMessages(MSG_SHOW_IME_BUTTON); |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 182 | mHandler.obtainMessage(MSG_SHOW_IME_BUTTON, vis, backDisposition, token) |
| 183 | .sendToTarget(); |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 184 | } |
| 185 | } |
| 186 | |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 187 | public void setHardKeyboardStatus(boolean available, boolean enabled) { |
| 188 | synchronized (mList) { |
| 189 | mHandler.removeMessages(MSG_SET_HARD_KEYBOARD_STATUS); |
| 190 | mHandler.obtainMessage(MSG_SET_HARD_KEYBOARD_STATUS, |
| 191 | available ? 1 : 0, enabled ? 1 : 0).sendToTarget(); |
| 192 | } |
| 193 | } |
| 194 | |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 195 | public void toggleRecentApps() { |
| 196 | synchronized (mList) { |
| 197 | mHandler.removeMessages(MSG_TOGGLE_RECENT_APPS); |
| 198 | mHandler.obtainMessage(MSG_TOGGLE_RECENT_APPS, 0, 0, null).sendToTarget(); |
| 199 | } |
| 200 | } |
| 201 | |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame^] | 202 | public void setNavigationIconHints(int hints) { |
| 203 | synchronized (mList) { |
| 204 | mHandler.removeMessages(MSG_SET_NAVIGATION_ICON_HINTS); |
| 205 | mHandler.obtainMessage(MSG_SET_NAVIGATION_ICON_HINTS, hints, 0, null).sendToTarget(); |
| 206 | } |
| 207 | } |
| 208 | |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 209 | private final class H extends Handler { |
| 210 | public void handleMessage(Message msg) { |
Joe Onorato | f3f0e05 | 2010-05-14 18:49:29 -0700 | [diff] [blame] | 211 | final int what = msg.what & MSG_MASK; |
Joe Onorato | 66d7d01 | 2010-05-14 10:05:10 -0700 | [diff] [blame] | 212 | switch (what) { |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 213 | case MSG_ICON: { |
Joe Onorato | f3f0e05 | 2010-05-14 18:49:29 -0700 | [diff] [blame] | 214 | final int index = msg.what & INDEX_MASK; |
| 215 | final int viewIndex = mList.getViewIndex(index); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 216 | switch (msg.arg1) { |
| 217 | case OP_SET_ICON: { |
| 218 | StatusBarIcon icon = (StatusBarIcon)msg.obj; |
| 219 | StatusBarIcon old = mList.getIcon(index); |
| 220 | if (old == null) { |
| 221 | mList.setIcon(index, icon); |
| 222 | mCallbacks.addIcon(mList.getSlot(index), index, viewIndex, icon); |
| 223 | } else { |
| 224 | mList.setIcon(index, icon); |
| 225 | mCallbacks.updateIcon(mList.getSlot(index), index, viewIndex, |
| 226 | old, icon); |
| 227 | } |
| 228 | break; |
| 229 | } |
| 230 | case OP_REMOVE_ICON: |
Joe Onorato | 795f284 | 2010-09-27 11:34:46 -0700 | [diff] [blame] | 231 | if (mList.getIcon(index) != null) { |
| 232 | mList.removeIcon(index); |
| 233 | mCallbacks.removeIcon(mList.getSlot(index), index, viewIndex); |
| 234 | } |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 235 | break; |
| 236 | } |
| 237 | break; |
Joe Onorato | f3f0e05 | 2010-05-14 18:49:29 -0700 | [diff] [blame] | 238 | } |
Joe Onorato | a0c56fe | 2010-05-20 10:21:52 -0700 | [diff] [blame] | 239 | case MSG_ADD_NOTIFICATION: { |
| 240 | final NotificationQueueEntry ne = (NotificationQueueEntry)msg.obj; |
| 241 | mCallbacks.addNotification(ne.key, ne.notification); |
| 242 | break; |
| 243 | } |
| 244 | case MSG_UPDATE_NOTIFICATION: { |
| 245 | final NotificationQueueEntry ne = (NotificationQueueEntry)msg.obj; |
| 246 | mCallbacks.updateNotification(ne.key, ne.notification); |
| 247 | break; |
| 248 | } |
| 249 | case MSG_REMOVE_NOTIFICATION: { |
| 250 | mCallbacks.removeNotification((IBinder)msg.obj); |
| 251 | break; |
| 252 | } |
Joe Onorato | f3f0e05 | 2010-05-14 18:49:29 -0700 | [diff] [blame] | 253 | case MSG_DISABLE: |
| 254 | mCallbacks.disable(msg.arg1); |
| 255 | break; |
Joe Onorato | 4762c2d | 2010-05-17 15:42:59 -0700 | [diff] [blame] | 256 | case MSG_SET_VISIBILITY: |
| 257 | if (msg.arg1 == OP_EXPAND) { |
| 258 | mCallbacks.animateExpand(); |
| 259 | } else { |
| 260 | mCallbacks.animateCollapse(); |
| 261 | } |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 262 | break; |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 263 | case MSG_SET_SYSTEMUI_VISIBILITY: |
| 264 | mCallbacks.setSystemUiVisibility(msg.arg1); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 265 | break; |
Dianne Hackborn | 7d04932 | 2011-06-14 15:00:32 -0700 | [diff] [blame] | 266 | case MSG_TOP_APP_WINDOW_CHANGED: |
| 267 | mCallbacks.topAppWindowChanged(msg.arg1 != 0); |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 268 | break; |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 269 | case MSG_SHOW_IME_BUTTON: |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 270 | mCallbacks.setImeWindowStatus((IBinder)msg.obj, msg.arg1, msg.arg2); |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 271 | break; |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 272 | case MSG_SET_HARD_KEYBOARD_STATUS: |
| 273 | mCallbacks.setHardKeyboardStatus(msg.arg1 != 0, msg.arg2 != 0); |
| 274 | break; |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 275 | case MSG_TOGGLE_RECENT_APPS: |
| 276 | mCallbacks.toggleRecentApps(); |
| 277 | break; |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame^] | 278 | case MSG_SET_NAVIGATION_ICON_HINTS: |
| 279 | mCallbacks.setNavigationIconHints(msg.arg1); |
| 280 | break; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | |