blob: 91077908f42d993d595518b78ddd3967934c19f1 [file] [log] [blame]
Joe Onorato0cbda992010-05-02 16:28:15 -07001/*
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 Onorato79de0c52010-05-26 17:03:26 -040017package com.android.systemui.statusbar;
Joe Onorato0cbda992010-05-02 16:28:15 -070018
19import android.os.Handler;
Joe Onoratoa0c56fe2010-05-20 10:21:52 -070020import android.os.IBinder;
Joe Onorato0cbda992010-05-02 16:28:15 -070021import android.os.Message;
John Spurlockde84f0e2013-06-12 12:41:00 -040022
Joe Onorato0cbda992010-05-02 16:28:15 -070023import com.android.internal.statusbar.IStatusBar;
24import com.android.internal.statusbar.StatusBarIcon;
25import com.android.internal.statusbar.StatusBarIconList;
26
Joe Onoratof3f0e052010-05-14 18:49:29 -070027/**
28 * This class takes the functions from IStatusBar that come in on
29 * binder pool threads and posts messages to get them onto the main
30 * thread, and calls onto Callbacks. It also takes care of
Joe Onorato4762c2d2010-05-17 15:42:59 -070031 * coalescing these calls so they don't stack up. For the calls
32 * are coalesced, note that they are all idempotent.
Joe Onoratof3f0e052010-05-14 18:49:29 -070033 */
Joe Onorato808182d2010-07-09 18:52:06 -040034public class CommandQueue extends IStatusBar.Stub {
Daniel Sandler1d4d30a2011-04-28 12:35:29 -040035 private static final int INDEX_MASK = 0xffff;
36 private static final int MSG_SHIFT = 16;
37 private static final int MSG_MASK = 0xffff << MSG_SHIFT;
Joe Onorato0cbda992010-05-02 16:28:15 -070038
Daniel Sandler1d4d30a2011-04-28 12:35:29 -040039 private static final int OP_SET_ICON = 1;
Joe Onorato0cbda992010-05-02 16:28:15 -070040 private static final int OP_REMOVE_ICON = 2;
41
Svetoslav Ganove20a1772012-09-25 16:07:46 -070042 private static final int MSG_ICON = 1 << MSG_SHIFT;
Christoph Studere71fefc2014-06-24 16:16:49 +020043 private static final int MSG_DISABLE = 2 << MSG_SHIFT;
44 private static final int MSG_EXPAND_NOTIFICATIONS = 3 << MSG_SHIFT;
45 private static final int MSG_COLLAPSE_PANELS = 4 << MSG_SHIFT;
46 private static final int MSG_EXPAND_SETTINGS = 5 << MSG_SHIFT;
47 private static final int MSG_SET_SYSTEMUI_VISIBILITY = 6 << MSG_SHIFT;
48 private static final int MSG_TOP_APP_WINDOW_CHANGED = 7 << MSG_SHIFT;
49 private static final int MSG_SHOW_IME_BUTTON = 8 << MSG_SHIFT;
50 private static final int MSG_SET_HARD_KEYBOARD_STATUS = 9 << MSG_SHIFT;
51 private static final int MSG_TOGGLE_RECENT_APPS = 10 << MSG_SHIFT;
52 private static final int MSG_PRELOAD_RECENT_APPS = 11 << MSG_SHIFT;
53 private static final int MSG_CANCEL_PRELOAD_RECENT_APPS = 12 << MSG_SHIFT;
54 private static final int MSG_SET_WINDOW_STATE = 13 << MSG_SHIFT;
55 private static final int MSG_SHOW_RECENT_APPS = 14 << MSG_SHIFT;
56 private static final int MSG_HIDE_RECENT_APPS = 15 << MSG_SHIFT;
John Spurlockcad57682014-07-26 17:09:56 -040057 private static final int MSG_BUZZ_BEEP_BLINKED = 16 << MSG_SHIFT;
John Spurlockcb566aa2014-08-03 22:58:28 -040058 private static final int MSG_NOTIFICATION_LIGHT_OFF = 17 << MSG_SHIFT;
59 private static final int MSG_NOTIFICATION_LIGHT_PULSE = 18 << MSG_SHIFT;
Daniel Sandler328310c2011-09-23 15:56:52 -040060
Jim Miller9a720f52012-05-30 03:19:43 -070061 public static final int FLAG_EXCLUDE_NONE = 0;
62 public static final int FLAG_EXCLUDE_SEARCH_PANEL = 1 << 0;
63 public static final int FLAG_EXCLUDE_RECENTS_PANEL = 1 << 1;
64 public static final int FLAG_EXCLUDE_NOTIFICATION_PANEL = 1 << 2;
65 public static final int FLAG_EXCLUDE_INPUT_METHODS_PANEL = 1 << 3;
66 public static final int FLAG_EXCLUDE_COMPAT_MODE_PANEL = 1 << 4;
67
Jason Monkb605fec2014-05-02 17:04:10 -040068 private static final String SHOW_IME_SWITCHER_KEY = "showImeSwitcherKey";
69
Joe Onorato0cbda992010-05-02 16:28:15 -070070 private StatusBarIconList mList;
71 private Callbacks mCallbacks;
72 private Handler mHandler = new H();
73
74 /**
75 * These methods are called back on the main thread.
76 */
77 public interface Callbacks {
78 public void addIcon(String slot, int index, int viewIndex, StatusBarIcon icon);
79 public void updateIcon(String slot, int index, int viewIndex,
80 StatusBarIcon old, StatusBarIcon icon);
81 public void removeIcon(String slot, int index, int viewIndex);
Jorim Jaggi2580a9762014-06-25 03:08:25 +020082 public void disable(int state, boolean animate);
Daniel Sandler11cf1782012-09-27 14:03:08 -040083 public void animateExpandNotificationsPanel();
84 public void animateCollapsePanels(int flags);
85 public void animateExpandSettingsPanel();
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -070086 public void setSystemUiVisibility(int vis, int mask);
Dianne Hackborn7d049322011-06-14 15:00:32 -070087 public void topAppWindowChanged(boolean visible);
Jason Monkb605fec2014-05-02 17:04:10 -040088 public void setImeWindowStatus(IBinder token, int vis, int backDisposition,
89 boolean showImeSwitcher);
Jeff Brown2992ea72011-01-28 22:04:14 -080090 public void setHardKeyboardStatus(boolean available, boolean enabled);
Winson Chung1e8d71b2014-05-16 17:05:22 -070091 public void showRecentApps(boolean triggeredFromAltTab);
Winson Chung6cb485f2014-05-19 10:30:43 -070092 public void hideRecentApps(boolean triggeredFromAltTab);
Michael Jurka3b1fc472011-06-13 10:54:40 -070093 public void toggleRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -070094 public void preloadRecentApps();
Winson Chung1e8d71b2014-05-16 17:05:22 -070095 public void cancelPreloadRecentApps();
Jim Millere898ac52012-04-06 17:10:57 -070096 public void showSearchPanel();
97 public void hideSearchPanel();
John Spurlock97642182013-07-29 17:58:39 -040098 public void setWindowState(int window, int state);
John Spurlockcad57682014-07-26 17:09:56 -040099 public void buzzBeepBlinked();
John Spurlockcb566aa2014-08-03 22:58:28 -0400100 public void notificationLightOff();
101 public void notificationLightPulse(int argb, int onMillis, int offMillis);
Joe Onorato0cbda992010-05-02 16:28:15 -0700102 }
103
104 public CommandQueue(Callbacks callbacks, StatusBarIconList list) {
105 mCallbacks = callbacks;
106 mList = list;
107 }
108
109 public void setIcon(int index, StatusBarIcon icon) {
110 synchronized (mList) {
111 int what = MSG_ICON | index;
112 mHandler.removeMessages(what);
113 mHandler.obtainMessage(what, OP_SET_ICON, 0, icon.clone()).sendToTarget();
114 }
115 }
116
117 public void removeIcon(int index) {
118 synchronized (mList) {
119 int what = MSG_ICON | index;
120 mHandler.removeMessages(what);
121 mHandler.obtainMessage(what, OP_REMOVE_ICON, 0, null).sendToTarget();
122 }
123 }
124
Joe Onoratof3f0e052010-05-14 18:49:29 -0700125 public void disable(int state) {
126 synchronized (mList) {
127 mHandler.removeMessages(MSG_DISABLE);
128 mHandler.obtainMessage(MSG_DISABLE, state, 0, null).sendToTarget();
129 }
130 }
131
Daniel Sandler11cf1782012-09-27 14:03:08 -0400132 public void animateExpandNotificationsPanel() {
Joe Onorato4762c2d2010-05-17 15:42:59 -0700133 synchronized (mList) {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700134 mHandler.removeMessages(MSG_EXPAND_NOTIFICATIONS);
135 mHandler.sendEmptyMessage(MSG_EXPAND_NOTIFICATIONS);
Joe Onorato4762c2d2010-05-17 15:42:59 -0700136 }
137 }
138
Daniel Sandler11cf1782012-09-27 14:03:08 -0400139 public void animateCollapsePanels() {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700140 synchronized (mList) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400141 mHandler.removeMessages(MSG_COLLAPSE_PANELS);
142 mHandler.sendEmptyMessage(MSG_COLLAPSE_PANELS);
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700143 }
Jim Miller9a720f52012-05-30 03:19:43 -0700144 }
145
Daniel Sandler11cf1782012-09-27 14:03:08 -0400146 public void animateExpandSettingsPanel() {
Joe Onorato4762c2d2010-05-17 15:42:59 -0700147 synchronized (mList) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400148 mHandler.removeMessages(MSG_EXPAND_SETTINGS);
149 mHandler.sendEmptyMessage(MSG_EXPAND_SETTINGS);
Joe Onorato4762c2d2010-05-17 15:42:59 -0700150 }
151 }
152
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700153 public void setSystemUiVisibility(int vis, int mask) {
Joe Onorato93056472010-09-10 10:30:46 -0400154 synchronized (mList) {
Daniel Sandler60ee2562011-07-22 12:34:33 -0400155 mHandler.removeMessages(MSG_SET_SYSTEMUI_VISIBILITY);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700156 mHandler.obtainMessage(MSG_SET_SYSTEMUI_VISIBILITY, vis, mask, null).sendToTarget();
Joe Onorato93056472010-09-10 10:30:46 -0400157 }
158 }
159
Dianne Hackborn7d049322011-06-14 15:00:32 -0700160 public void topAppWindowChanged(boolean menuVisible) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400161 synchronized (mList) {
Dianne Hackborn7d049322011-06-14 15:00:32 -0700162 mHandler.removeMessages(MSG_TOP_APP_WINDOW_CHANGED);
163 mHandler.obtainMessage(MSG_TOP_APP_WINDOW_CHANGED, menuVisible ? 1 : 0, 0,
164 null).sendToTarget();
Daniel Sandlere02d8082010-10-08 15:13:22 -0400165 }
166 }
167
Jason Monkb605fec2014-05-02 17:04:10 -0400168 public void setImeWindowStatus(IBinder token, int vis, int backDisposition,
169 boolean showImeSwitcher) {
satok06487a52010-10-29 11:37:18 +0900170 synchronized (mList) {
171 mHandler.removeMessages(MSG_SHOW_IME_BUTTON);
Jason Monkb605fec2014-05-02 17:04:10 -0400172 Message m = mHandler.obtainMessage(MSG_SHOW_IME_BUTTON, vis, backDisposition, token);
173 m.getData().putBoolean(SHOW_IME_SWITCHER_KEY, showImeSwitcher);
174 m.sendToTarget();
satok06487a52010-10-29 11:37:18 +0900175 }
176 }
177
Jeff Brown2992ea72011-01-28 22:04:14 -0800178 public void setHardKeyboardStatus(boolean available, boolean enabled) {
179 synchronized (mList) {
180 mHandler.removeMessages(MSG_SET_HARD_KEYBOARD_STATUS);
181 mHandler.obtainMessage(MSG_SET_HARD_KEYBOARD_STATUS,
182 available ? 1 : 0, enabled ? 1 : 0).sendToTarget();
183 }
184 }
185
Winson Chung1e8d71b2014-05-16 17:05:22 -0700186 public void showRecentApps(boolean triggeredFromAltTab) {
187 synchronized (mList) {
188 mHandler.removeMessages(MSG_SHOW_RECENT_APPS);
189 mHandler.obtainMessage(MSG_SHOW_RECENT_APPS,
190 triggeredFromAltTab ? 1 : 0, 0, null).sendToTarget();
191 }
192 }
193
Winson Chung6cb485f2014-05-19 10:30:43 -0700194 public void hideRecentApps(boolean triggeredFromAltTab) {
Winson Chung1e8d71b2014-05-16 17:05:22 -0700195 synchronized (mList) {
196 mHandler.removeMessages(MSG_HIDE_RECENT_APPS);
Winson Chung6cb485f2014-05-19 10:30:43 -0700197 mHandler.obtainMessage(MSG_HIDE_RECENT_APPS,
198 triggeredFromAltTab ? 1 : 0, 0, null).sendToTarget();
Winson Chung1e8d71b2014-05-16 17:05:22 -0700199 }
200 }
201
Michael Jurka3b1fc472011-06-13 10:54:40 -0700202 public void toggleRecentApps() {
203 synchronized (mList) {
204 mHandler.removeMessages(MSG_TOGGLE_RECENT_APPS);
205 mHandler.obtainMessage(MSG_TOGGLE_RECENT_APPS, 0, 0, null).sendToTarget();
206 }
207 }
208
Michael Jurka7f2668c2012-03-27 07:49:52 -0700209 public void preloadRecentApps() {
210 synchronized (mList) {
211 mHandler.removeMessages(MSG_PRELOAD_RECENT_APPS);
212 mHandler.obtainMessage(MSG_PRELOAD_RECENT_APPS, 0, 0, null).sendToTarget();
213 }
214 }
215
216 public void cancelPreloadRecentApps() {
217 synchronized (mList) {
218 mHandler.removeMessages(MSG_CANCEL_PRELOAD_RECENT_APPS);
219 mHandler.obtainMessage(MSG_CANCEL_PRELOAD_RECENT_APPS, 0, 0, null).sendToTarget();
220 }
221 }
222
John Spurlock97642182013-07-29 17:58:39 -0400223 public void setWindowState(int window, int state) {
224 synchronized (mList) {
John Spurlock5b9145b2013-08-20 15:13:47 -0400225 // don't coalesce these
John Spurlock97642182013-07-29 17:58:39 -0400226 mHandler.obtainMessage(MSG_SET_WINDOW_STATE, window, state, null).sendToTarget();
227 }
228 }
229
John Spurlockcad57682014-07-26 17:09:56 -0400230 public void buzzBeepBlinked() {
231 synchronized (mList) {
232 mHandler.removeMessages(MSG_BUZZ_BEEP_BLINKED);
233 mHandler.sendEmptyMessage(MSG_BUZZ_BEEP_BLINKED);
234 }
235 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100236
John Spurlockcb566aa2014-08-03 22:58:28 -0400237 public void notificationLightOff() {
238 synchronized (mList) {
239 mHandler.sendEmptyMessage(MSG_NOTIFICATION_LIGHT_OFF);
240 }
241 }
242
243 public void notificationLightPulse(int argb, int onMillis, int offMillis) {
244 synchronized (mList) {
245 mHandler.obtainMessage(MSG_NOTIFICATION_LIGHT_PULSE, onMillis, offMillis, argb)
246 .sendToTarget();
247 }
248 }
249
Joe Onorato0cbda992010-05-02 16:28:15 -0700250 private final class H extends Handler {
251 public void handleMessage(Message msg) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700252 final int what = msg.what & MSG_MASK;
Joe Onorato66d7d012010-05-14 10:05:10 -0700253 switch (what) {
Joe Onorato0cbda992010-05-02 16:28:15 -0700254 case MSG_ICON: {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700255 final int index = msg.what & INDEX_MASK;
256 final int viewIndex = mList.getViewIndex(index);
Joe Onorato0cbda992010-05-02 16:28:15 -0700257 switch (msg.arg1) {
258 case OP_SET_ICON: {
259 StatusBarIcon icon = (StatusBarIcon)msg.obj;
260 StatusBarIcon old = mList.getIcon(index);
261 if (old == null) {
262 mList.setIcon(index, icon);
263 mCallbacks.addIcon(mList.getSlot(index), index, viewIndex, icon);
264 } else {
265 mList.setIcon(index, icon);
266 mCallbacks.updateIcon(mList.getSlot(index), index, viewIndex,
267 old, icon);
268 }
269 break;
270 }
271 case OP_REMOVE_ICON:
Joe Onorato795f2842010-09-27 11:34:46 -0700272 if (mList.getIcon(index) != null) {
273 mList.removeIcon(index);
274 mCallbacks.removeIcon(mList.getSlot(index), index, viewIndex);
275 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700276 break;
277 }
278 break;
Joe Onoratof3f0e052010-05-14 18:49:29 -0700279 }
280 case MSG_DISABLE:
Jorim Jaggi2580a9762014-06-25 03:08:25 +0200281 mCallbacks.disable(msg.arg1, true /* animate */);
Joe Onoratof3f0e052010-05-14 18:49:29 -0700282 break;
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700283 case MSG_EXPAND_NOTIFICATIONS:
Daniel Sandler11cf1782012-09-27 14:03:08 -0400284 mCallbacks.animateExpandNotificationsPanel();
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700285 break;
Daniel Sandler11cf1782012-09-27 14:03:08 -0400286 case MSG_COLLAPSE_PANELS:
287 mCallbacks.animateCollapsePanels(0);
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700288 break;
Daniel Sandler11cf1782012-09-27 14:03:08 -0400289 case MSG_EXPAND_SETTINGS:
290 mCallbacks.animateExpandSettingsPanel();
Joe Onorato93056472010-09-10 10:30:46 -0400291 break;
Daniel Sandler60ee2562011-07-22 12:34:33 -0400292 case MSG_SET_SYSTEMUI_VISIBILITY:
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700293 mCallbacks.setSystemUiVisibility(msg.arg1, msg.arg2);
Joe Onorato93056472010-09-10 10:30:46 -0400294 break;
Dianne Hackborn7d049322011-06-14 15:00:32 -0700295 case MSG_TOP_APP_WINDOW_CHANGED:
296 mCallbacks.topAppWindowChanged(msg.arg1 != 0);
Daniel Sandlere02d8082010-10-08 15:13:22 -0400297 break;
satok06487a52010-10-29 11:37:18 +0900298 case MSG_SHOW_IME_BUTTON:
Jason Monkb605fec2014-05-02 17:04:10 -0400299 mCallbacks.setImeWindowStatus((IBinder) msg.obj, msg.arg1, msg.arg2,
300 msg.getData().getBoolean(SHOW_IME_SWITCHER_KEY, false));
satok06487a52010-10-29 11:37:18 +0900301 break;
Jeff Brown2992ea72011-01-28 22:04:14 -0800302 case MSG_SET_HARD_KEYBOARD_STATUS:
303 mCallbacks.setHardKeyboardStatus(msg.arg1 != 0, msg.arg2 != 0);
304 break;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700305 case MSG_SHOW_RECENT_APPS:
306 mCallbacks.showRecentApps(msg.arg1 != 0);
307 break;
308 case MSG_HIDE_RECENT_APPS:
Winson Chung6cb485f2014-05-19 10:30:43 -0700309 mCallbacks.hideRecentApps(msg.arg1 != 0);
Winson Chung1e8d71b2014-05-16 17:05:22 -0700310 break;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700311 case MSG_TOGGLE_RECENT_APPS:
312 mCallbacks.toggleRecentApps();
313 break;
Michael Jurka7f2668c2012-03-27 07:49:52 -0700314 case MSG_PRELOAD_RECENT_APPS:
315 mCallbacks.preloadRecentApps();
316 break;
317 case MSG_CANCEL_PRELOAD_RECENT_APPS:
318 mCallbacks.cancelPreloadRecentApps();
319 break;
John Spurlock97642182013-07-29 17:58:39 -0400320 case MSG_SET_WINDOW_STATE:
321 mCallbacks.setWindowState(msg.arg1, msg.arg2);
322 break;
John Spurlockcad57682014-07-26 17:09:56 -0400323 case MSG_BUZZ_BEEP_BLINKED:
324 mCallbacks.buzzBeepBlinked();
325 break;
John Spurlockcb566aa2014-08-03 22:58:28 -0400326 case MSG_NOTIFICATION_LIGHT_OFF:
327 mCallbacks.notificationLightOff();
328 break;
329 case MSG_NOTIFICATION_LIGHT_PULSE:
330 mCallbacks.notificationLightPulse((Integer) msg.obj, msg.arg1, msg.arg2);
331 break;
Joe Onorato0cbda992010-05-02 16:28:15 -0700332 }
333 }
334 }
335}
336