blob: ebab7fbff78c700e8d3c3f779d9118789d8dc027 [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;
Daniel Sandler5feceeb2013-03-22 18:29:23 -070022import android.service.notification.StatusBarNotification;
John Spurlockde84f0e2013-06-12 12:41:00 -040023
Jorim Jaggi380ecb82014-03-14 17:25:20 +010024import com.android.internal.policy.IKeyguardShowCallback;
Joe Onorato0cbda992010-05-02 16:28:15 -070025import com.android.internal.statusbar.IStatusBar;
26import com.android.internal.statusbar.StatusBarIcon;
27import com.android.internal.statusbar.StatusBarIconList;
28
Joe Onoratof3f0e052010-05-14 18:49:29 -070029/**
30 * This class takes the functions from IStatusBar that come in on
31 * binder pool threads and posts messages to get them onto the main
32 * thread, and calls onto Callbacks. It also takes care of
Joe Onorato4762c2d2010-05-17 15:42:59 -070033 * coalescing these calls so they don't stack up. For the calls
34 * are coalesced, note that they are all idempotent.
Joe Onoratof3f0e052010-05-14 18:49:29 -070035 */
Joe Onorato808182d2010-07-09 18:52:06 -040036public class CommandQueue extends IStatusBar.Stub {
Daniel Sandler1d4d30a2011-04-28 12:35:29 -040037 private static final int INDEX_MASK = 0xffff;
38 private static final int MSG_SHIFT = 16;
39 private static final int MSG_MASK = 0xffff << MSG_SHIFT;
Joe Onorato0cbda992010-05-02 16:28:15 -070040
Daniel Sandler1d4d30a2011-04-28 12:35:29 -040041 private static final int OP_SET_ICON = 1;
Joe Onorato0cbda992010-05-02 16:28:15 -070042 private static final int OP_REMOVE_ICON = 2;
43
Svetoslav Ganove20a1772012-09-25 16:07:46 -070044 private static final int MSG_ICON = 1 << MSG_SHIFT;
45 private static final int MSG_ADD_NOTIFICATION = 2 << MSG_SHIFT;
46 private static final int MSG_UPDATE_NOTIFICATION = 3 << MSG_SHIFT;
47 private static final int MSG_REMOVE_NOTIFICATION = 4 << MSG_SHIFT;
48 private static final int MSG_DISABLE = 5 << MSG_SHIFT;
49 private static final int MSG_EXPAND_NOTIFICATIONS = 6 << MSG_SHIFT;
Daniel Sandler11cf1782012-09-27 14:03:08 -040050 private static final int MSG_COLLAPSE_PANELS = 7 << MSG_SHIFT;
51 private static final int MSG_EXPAND_SETTINGS = 8 << MSG_SHIFT;
52 private static final int MSG_SET_SYSTEMUI_VISIBILITY = 9 << MSG_SHIFT;
53 private static final int MSG_TOP_APP_WINDOW_CHANGED = 10 << MSG_SHIFT;
54 private static final int MSG_SHOW_IME_BUTTON = 11 << MSG_SHIFT;
55 private static final int MSG_SET_HARD_KEYBOARD_STATUS = 12 << MSG_SHIFT;
56 private static final int MSG_TOGGLE_RECENT_APPS = 13 << MSG_SHIFT;
57 private static final int MSG_PRELOAD_RECENT_APPS = 14 << MSG_SHIFT;
58 private static final int MSG_CANCEL_PRELOAD_RECENT_APPS = 15 << MSG_SHIFT;
John Spurlock56d007b2013-10-28 18:40:56 -040059 private static final int MSG_SET_WINDOW_STATE = 16 << MSG_SHIFT;
Winson Chung1e8d71b2014-05-16 17:05:22 -070060 private static final int MSG_SHOW_RECENT_APPS = 17 << MSG_SHIFT;
61 private static final int MSG_HIDE_RECENT_APPS = 18 << MSG_SHIFT;
Daniel Sandler328310c2011-09-23 15:56:52 -040062
Jim Miller9a720f52012-05-30 03:19:43 -070063 public static final int FLAG_EXCLUDE_NONE = 0;
64 public static final int FLAG_EXCLUDE_SEARCH_PANEL = 1 << 0;
65 public static final int FLAG_EXCLUDE_RECENTS_PANEL = 1 << 1;
66 public static final int FLAG_EXCLUDE_NOTIFICATION_PANEL = 1 << 2;
67 public static final int FLAG_EXCLUDE_INPUT_METHODS_PANEL = 1 << 3;
68 public static final int FLAG_EXCLUDE_COMPAT_MODE_PANEL = 1 << 4;
69
Jason Monkb605fec2014-05-02 17:04:10 -040070 private static final String SHOW_IME_SWITCHER_KEY = "showImeSwitcherKey";
71
Joe Onorato0cbda992010-05-02 16:28:15 -070072 private StatusBarIconList mList;
73 private Callbacks mCallbacks;
74 private Handler mHandler = new H();
75
Joe Onoratoa0c56fe2010-05-20 10:21:52 -070076 private class NotificationQueueEntry {
77 IBinder key;
78 StatusBarNotification notification;
79 }
80
Joe Onorato0cbda992010-05-02 16:28:15 -070081 /**
82 * These methods are called back on the main thread.
83 */
84 public interface Callbacks {
85 public void addIcon(String slot, int index, int viewIndex, StatusBarIcon icon);
86 public void updateIcon(String slot, int index, int viewIndex,
87 StatusBarIcon old, StatusBarIcon icon);
88 public void removeIcon(String slot, int index, int viewIndex);
Joe Onoratoa0c56fe2010-05-20 10:21:52 -070089 public void addNotification(IBinder key, StatusBarNotification notification);
90 public void updateNotification(IBinder key, StatusBarNotification notification);
91 public void removeNotification(IBinder key);
Joe Onoratof3f0e052010-05-14 18:49:29 -070092 public void disable(int state);
Daniel Sandler11cf1782012-09-27 14:03:08 -040093 public void animateExpandNotificationsPanel();
94 public void animateCollapsePanels(int flags);
95 public void animateExpandSettingsPanel();
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -070096 public void setSystemUiVisibility(int vis, int mask);
Dianne Hackborn7d049322011-06-14 15:00:32 -070097 public void topAppWindowChanged(boolean visible);
Jason Monkb605fec2014-05-02 17:04:10 -040098 public void setImeWindowStatus(IBinder token, int vis, int backDisposition,
99 boolean showImeSwitcher);
Jeff Brown2992ea72011-01-28 22:04:14 -0800100 public void setHardKeyboardStatus(boolean available, boolean enabled);
Winson Chung1e8d71b2014-05-16 17:05:22 -0700101 public void showRecentApps(boolean triggeredFromAltTab);
102 public void hideRecentApps();
Michael Jurka3b1fc472011-06-13 10:54:40 -0700103 public void toggleRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -0700104 public void preloadRecentApps();
Winson Chung1e8d71b2014-05-16 17:05:22 -0700105 public void cancelPreloadRecentApps();
Jim Millere898ac52012-04-06 17:10:57 -0700106 public void showSearchPanel();
107 public void hideSearchPanel();
John Spurlock97642182013-07-29 17:58:39 -0400108 public void setWindowState(int window, int state);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100109
Joe Onorato0cbda992010-05-02 16:28:15 -0700110 }
111
112 public CommandQueue(Callbacks callbacks, StatusBarIconList list) {
113 mCallbacks = callbacks;
114 mList = list;
115 }
116
117 public void setIcon(int index, StatusBarIcon icon) {
118 synchronized (mList) {
119 int what = MSG_ICON | index;
120 mHandler.removeMessages(what);
121 mHandler.obtainMessage(what, OP_SET_ICON, 0, icon.clone()).sendToTarget();
122 }
123 }
124
125 public void removeIcon(int index) {
126 synchronized (mList) {
127 int what = MSG_ICON | index;
128 mHandler.removeMessages(what);
129 mHandler.obtainMessage(what, OP_REMOVE_ICON, 0, null).sendToTarget();
130 }
131 }
132
Joe Onoratoa0c56fe2010-05-20 10:21:52 -0700133 public void addNotification(IBinder key, StatusBarNotification notification) {
134 synchronized (mList) {
135 NotificationQueueEntry ne = new NotificationQueueEntry();
136 ne.key = key;
137 ne.notification = notification;
138 mHandler.obtainMessage(MSG_ADD_NOTIFICATION, 0, 0, ne).sendToTarget();
139 }
140 }
141
142 public void updateNotification(IBinder key, StatusBarNotification notification) {
143 synchronized (mList) {
144 NotificationQueueEntry ne = new NotificationQueueEntry();
145 ne.key = key;
146 ne.notification = notification;
147 mHandler.obtainMessage(MSG_UPDATE_NOTIFICATION, 0, 0, ne).sendToTarget();
148 }
149 }
150
151 public void removeNotification(IBinder key) {
152 synchronized (mList) {
153 mHandler.obtainMessage(MSG_REMOVE_NOTIFICATION, 0, 0, key).sendToTarget();
154 }
155 }
156
Joe Onoratof3f0e052010-05-14 18:49:29 -0700157 public void disable(int state) {
158 synchronized (mList) {
159 mHandler.removeMessages(MSG_DISABLE);
160 mHandler.obtainMessage(MSG_DISABLE, state, 0, null).sendToTarget();
161 }
162 }
163
Daniel Sandler11cf1782012-09-27 14:03:08 -0400164 public void animateExpandNotificationsPanel() {
Joe Onorato4762c2d2010-05-17 15:42:59 -0700165 synchronized (mList) {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700166 mHandler.removeMessages(MSG_EXPAND_NOTIFICATIONS);
167 mHandler.sendEmptyMessage(MSG_EXPAND_NOTIFICATIONS);
Joe Onorato4762c2d2010-05-17 15:42:59 -0700168 }
169 }
170
Daniel Sandler11cf1782012-09-27 14:03:08 -0400171 public void animateCollapsePanels() {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700172 synchronized (mList) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400173 mHandler.removeMessages(MSG_COLLAPSE_PANELS);
174 mHandler.sendEmptyMessage(MSG_COLLAPSE_PANELS);
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700175 }
Jim Miller9a720f52012-05-30 03:19:43 -0700176 }
177
Daniel Sandler11cf1782012-09-27 14:03:08 -0400178 public void animateExpandSettingsPanel() {
Joe Onorato4762c2d2010-05-17 15:42:59 -0700179 synchronized (mList) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400180 mHandler.removeMessages(MSG_EXPAND_SETTINGS);
181 mHandler.sendEmptyMessage(MSG_EXPAND_SETTINGS);
Joe Onorato4762c2d2010-05-17 15:42:59 -0700182 }
183 }
184
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700185 public void setSystemUiVisibility(int vis, int mask) {
Joe Onorato93056472010-09-10 10:30:46 -0400186 synchronized (mList) {
Daniel Sandler60ee2562011-07-22 12:34:33 -0400187 mHandler.removeMessages(MSG_SET_SYSTEMUI_VISIBILITY);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700188 mHandler.obtainMessage(MSG_SET_SYSTEMUI_VISIBILITY, vis, mask, null).sendToTarget();
Joe Onorato93056472010-09-10 10:30:46 -0400189 }
190 }
191
Dianne Hackborn7d049322011-06-14 15:00:32 -0700192 public void topAppWindowChanged(boolean menuVisible) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400193 synchronized (mList) {
Dianne Hackborn7d049322011-06-14 15:00:32 -0700194 mHandler.removeMessages(MSG_TOP_APP_WINDOW_CHANGED);
195 mHandler.obtainMessage(MSG_TOP_APP_WINDOW_CHANGED, menuVisible ? 1 : 0, 0,
196 null).sendToTarget();
Daniel Sandlere02d8082010-10-08 15:13:22 -0400197 }
198 }
199
Jason Monkb605fec2014-05-02 17:04:10 -0400200 public void setImeWindowStatus(IBinder token, int vis, int backDisposition,
201 boolean showImeSwitcher) {
satok06487a52010-10-29 11:37:18 +0900202 synchronized (mList) {
203 mHandler.removeMessages(MSG_SHOW_IME_BUTTON);
Jason Monkb605fec2014-05-02 17:04:10 -0400204 Message m = mHandler.obtainMessage(MSG_SHOW_IME_BUTTON, vis, backDisposition, token);
205 m.getData().putBoolean(SHOW_IME_SWITCHER_KEY, showImeSwitcher);
206 m.sendToTarget();
satok06487a52010-10-29 11:37:18 +0900207 }
208 }
209
Jeff Brown2992ea72011-01-28 22:04:14 -0800210 public void setHardKeyboardStatus(boolean available, boolean enabled) {
211 synchronized (mList) {
212 mHandler.removeMessages(MSG_SET_HARD_KEYBOARD_STATUS);
213 mHandler.obtainMessage(MSG_SET_HARD_KEYBOARD_STATUS,
214 available ? 1 : 0, enabled ? 1 : 0).sendToTarget();
215 }
216 }
217
Winson Chung1e8d71b2014-05-16 17:05:22 -0700218 public void showRecentApps(boolean triggeredFromAltTab) {
219 synchronized (mList) {
220 mHandler.removeMessages(MSG_SHOW_RECENT_APPS);
221 mHandler.obtainMessage(MSG_SHOW_RECENT_APPS,
222 triggeredFromAltTab ? 1 : 0, 0, null).sendToTarget();
223 }
224 }
225
226 public void hideRecentApps() {
227 synchronized (mList) {
228 mHandler.removeMessages(MSG_HIDE_RECENT_APPS);
229 mHandler.obtainMessage(MSG_HIDE_RECENT_APPS, 0, 0, null).sendToTarget();
230 }
231 }
232
Michael Jurka3b1fc472011-06-13 10:54:40 -0700233 public void toggleRecentApps() {
234 synchronized (mList) {
235 mHandler.removeMessages(MSG_TOGGLE_RECENT_APPS);
236 mHandler.obtainMessage(MSG_TOGGLE_RECENT_APPS, 0, 0, null).sendToTarget();
237 }
238 }
239
Michael Jurka7f2668c2012-03-27 07:49:52 -0700240 public void preloadRecentApps() {
241 synchronized (mList) {
242 mHandler.removeMessages(MSG_PRELOAD_RECENT_APPS);
243 mHandler.obtainMessage(MSG_PRELOAD_RECENT_APPS, 0, 0, null).sendToTarget();
244 }
245 }
246
247 public void cancelPreloadRecentApps() {
248 synchronized (mList) {
249 mHandler.removeMessages(MSG_CANCEL_PRELOAD_RECENT_APPS);
250 mHandler.obtainMessage(MSG_CANCEL_PRELOAD_RECENT_APPS, 0, 0, null).sendToTarget();
251 }
252 }
253
John Spurlock97642182013-07-29 17:58:39 -0400254 public void setWindowState(int window, int state) {
255 synchronized (mList) {
John Spurlock5b9145b2013-08-20 15:13:47 -0400256 // don't coalesce these
John Spurlock97642182013-07-29 17:58:39 -0400257 mHandler.obtainMessage(MSG_SET_WINDOW_STATE, window, state, null).sendToTarget();
258 }
259 }
260
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100261
Joe Onorato0cbda992010-05-02 16:28:15 -0700262 private final class H extends Handler {
263 public void handleMessage(Message msg) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700264 final int what = msg.what & MSG_MASK;
Joe Onorato66d7d012010-05-14 10:05:10 -0700265 switch (what) {
Joe Onorato0cbda992010-05-02 16:28:15 -0700266 case MSG_ICON: {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700267 final int index = msg.what & INDEX_MASK;
268 final int viewIndex = mList.getViewIndex(index);
Joe Onorato0cbda992010-05-02 16:28:15 -0700269 switch (msg.arg1) {
270 case OP_SET_ICON: {
271 StatusBarIcon icon = (StatusBarIcon)msg.obj;
272 StatusBarIcon old = mList.getIcon(index);
273 if (old == null) {
274 mList.setIcon(index, icon);
275 mCallbacks.addIcon(mList.getSlot(index), index, viewIndex, icon);
276 } else {
277 mList.setIcon(index, icon);
278 mCallbacks.updateIcon(mList.getSlot(index), index, viewIndex,
279 old, icon);
280 }
281 break;
282 }
283 case OP_REMOVE_ICON:
Joe Onorato795f2842010-09-27 11:34:46 -0700284 if (mList.getIcon(index) != null) {
285 mList.removeIcon(index);
286 mCallbacks.removeIcon(mList.getSlot(index), index, viewIndex);
287 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700288 break;
289 }
290 break;
Joe Onoratof3f0e052010-05-14 18:49:29 -0700291 }
Joe Onoratoa0c56fe2010-05-20 10:21:52 -0700292 case MSG_ADD_NOTIFICATION: {
293 final NotificationQueueEntry ne = (NotificationQueueEntry)msg.obj;
294 mCallbacks.addNotification(ne.key, ne.notification);
295 break;
296 }
297 case MSG_UPDATE_NOTIFICATION: {
298 final NotificationQueueEntry ne = (NotificationQueueEntry)msg.obj;
299 mCallbacks.updateNotification(ne.key, ne.notification);
300 break;
301 }
302 case MSG_REMOVE_NOTIFICATION: {
303 mCallbacks.removeNotification((IBinder)msg.obj);
304 break;
305 }
Joe Onoratof3f0e052010-05-14 18:49:29 -0700306 case MSG_DISABLE:
307 mCallbacks.disable(msg.arg1);
308 break;
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700309 case MSG_EXPAND_NOTIFICATIONS:
Daniel Sandler11cf1782012-09-27 14:03:08 -0400310 mCallbacks.animateExpandNotificationsPanel();
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700311 break;
Daniel Sandler11cf1782012-09-27 14:03:08 -0400312 case MSG_COLLAPSE_PANELS:
313 mCallbacks.animateCollapsePanels(0);
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700314 break;
Daniel Sandler11cf1782012-09-27 14:03:08 -0400315 case MSG_EXPAND_SETTINGS:
316 mCallbacks.animateExpandSettingsPanel();
Joe Onorato93056472010-09-10 10:30:46 -0400317 break;
Daniel Sandler60ee2562011-07-22 12:34:33 -0400318 case MSG_SET_SYSTEMUI_VISIBILITY:
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700319 mCallbacks.setSystemUiVisibility(msg.arg1, msg.arg2);
Joe Onorato93056472010-09-10 10:30:46 -0400320 break;
Dianne Hackborn7d049322011-06-14 15:00:32 -0700321 case MSG_TOP_APP_WINDOW_CHANGED:
322 mCallbacks.topAppWindowChanged(msg.arg1 != 0);
Daniel Sandlere02d8082010-10-08 15:13:22 -0400323 break;
satok06487a52010-10-29 11:37:18 +0900324 case MSG_SHOW_IME_BUTTON:
Jason Monkb605fec2014-05-02 17:04:10 -0400325 mCallbacks.setImeWindowStatus((IBinder) msg.obj, msg.arg1, msg.arg2,
326 msg.getData().getBoolean(SHOW_IME_SWITCHER_KEY, false));
satok06487a52010-10-29 11:37:18 +0900327 break;
Jeff Brown2992ea72011-01-28 22:04:14 -0800328 case MSG_SET_HARD_KEYBOARD_STATUS:
329 mCallbacks.setHardKeyboardStatus(msg.arg1 != 0, msg.arg2 != 0);
330 break;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700331 case MSG_SHOW_RECENT_APPS:
332 mCallbacks.showRecentApps(msg.arg1 != 0);
333 break;
334 case MSG_HIDE_RECENT_APPS:
335 mCallbacks.hideRecentApps();
336 break;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700337 case MSG_TOGGLE_RECENT_APPS:
338 mCallbacks.toggleRecentApps();
339 break;
Michael Jurka7f2668c2012-03-27 07:49:52 -0700340 case MSG_PRELOAD_RECENT_APPS:
341 mCallbacks.preloadRecentApps();
342 break;
343 case MSG_CANCEL_PRELOAD_RECENT_APPS:
344 mCallbacks.cancelPreloadRecentApps();
345 break;
John Spurlock97642182013-07-29 17:58:39 -0400346 case MSG_SET_WINDOW_STATE:
347 mCallbacks.setWindowState(msg.arg1, msg.arg2);
348 break;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100349
Joe Onorato0cbda992010-05-02 16:28:15 -0700350 }
351 }
352 }
353}
354