blob: e8173b7995860cb4c4dfc824a724044339e267b3 [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
Joe Onorato0cbda992010-05-02 16:28:15 -070024import com.android.internal.statusbar.IStatusBar;
25import com.android.internal.statusbar.StatusBarIcon;
26import com.android.internal.statusbar.StatusBarIconList;
27
Joe Onoratof3f0e052010-05-14 18:49:29 -070028/**
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 Onorato4762c2d2010-05-17 15:42:59 -070032 * coalescing these calls so they don't stack up. For the calls
33 * are coalesced, note that they are all idempotent.
Joe Onoratof3f0e052010-05-14 18:49:29 -070034 */
Joe Onorato808182d2010-07-09 18:52:06 -040035public class CommandQueue extends IStatusBar.Stub {
Daniel Sandler1d4d30a2011-04-28 12:35:29 -040036 private static final int INDEX_MASK = 0xffff;
37 private static final int MSG_SHIFT = 16;
38 private static final int MSG_MASK = 0xffff << MSG_SHIFT;
Joe Onorato0cbda992010-05-02 16:28:15 -070039
Daniel Sandler1d4d30a2011-04-28 12:35:29 -040040 private static final int OP_SET_ICON = 1;
Joe Onorato0cbda992010-05-02 16:28:15 -070041 private static final int OP_REMOVE_ICON = 2;
42
Svetoslav Ganove20a1772012-09-25 16:07:46 -070043 private static final int MSG_ICON = 1 << MSG_SHIFT;
44 private static final int MSG_ADD_NOTIFICATION = 2 << MSG_SHIFT;
45 private static final int MSG_UPDATE_NOTIFICATION = 3 << MSG_SHIFT;
46 private static final int MSG_REMOVE_NOTIFICATION = 4 << MSG_SHIFT;
47 private static final int MSG_DISABLE = 5 << MSG_SHIFT;
48 private static final int MSG_EXPAND_NOTIFICATIONS = 6 << MSG_SHIFT;
Daniel Sandler11cf1782012-09-27 14:03:08 -040049 private static final int MSG_COLLAPSE_PANELS = 7 << MSG_SHIFT;
50 private static final int MSG_EXPAND_SETTINGS = 8 << MSG_SHIFT;
51 private static final int MSG_SET_SYSTEMUI_VISIBILITY = 9 << MSG_SHIFT;
52 private static final int MSG_TOP_APP_WINDOW_CHANGED = 10 << MSG_SHIFT;
53 private static final int MSG_SHOW_IME_BUTTON = 11 << MSG_SHIFT;
54 private static final int MSG_SET_HARD_KEYBOARD_STATUS = 12 << MSG_SHIFT;
55 private static final int MSG_TOGGLE_RECENT_APPS = 13 << MSG_SHIFT;
56 private static final int MSG_PRELOAD_RECENT_APPS = 14 << MSG_SHIFT;
57 private static final int MSG_CANCEL_PRELOAD_RECENT_APPS = 15 << MSG_SHIFT;
58 private static final int MSG_SET_NAVIGATION_ICON_HINTS = 16 << MSG_SHIFT;
John Spurlock97642182013-07-29 17:58:39 -040059 private static final int MSG_SET_WINDOW_STATE = 17 << 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
Joe Onorato0cbda992010-05-02 16:28:15 -070068 private StatusBarIconList mList;
69 private Callbacks mCallbacks;
70 private Handler mHandler = new H();
71
Joe Onoratoa0c56fe2010-05-20 10:21:52 -070072 private class NotificationQueueEntry {
73 IBinder key;
74 StatusBarNotification notification;
75 }
76
Joe Onorato0cbda992010-05-02 16:28:15 -070077 /**
78 * These methods are called back on the main thread.
79 */
80 public interface Callbacks {
81 public void addIcon(String slot, int index, int viewIndex, StatusBarIcon icon);
82 public void updateIcon(String slot, int index, int viewIndex,
83 StatusBarIcon old, StatusBarIcon icon);
84 public void removeIcon(String slot, int index, int viewIndex);
Joe Onoratoa0c56fe2010-05-20 10:21:52 -070085 public void addNotification(IBinder key, StatusBarNotification notification);
86 public void updateNotification(IBinder key, StatusBarNotification notification);
87 public void removeNotification(IBinder key);
Joe Onoratof3f0e052010-05-14 18:49:29 -070088 public void disable(int state);
Daniel Sandler11cf1782012-09-27 14:03:08 -040089 public void animateExpandNotificationsPanel();
90 public void animateCollapsePanels(int flags);
91 public void animateExpandSettingsPanel();
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -070092 public void setSystemUiVisibility(int vis, int mask);
Dianne Hackborn7d049322011-06-14 15:00:32 -070093 public void topAppWindowChanged(boolean visible);
Joe Onorato857fd9b2011-01-27 15:08:35 -080094 public void setImeWindowStatus(IBinder token, int vis, int backDisposition);
Jeff Brown2992ea72011-01-28 22:04:14 -080095 public void setHardKeyboardStatus(boolean available, boolean enabled);
Michael Jurka3b1fc472011-06-13 10:54:40 -070096 public void toggleRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -070097 public void preloadRecentApps();
Jim Millere898ac52012-04-06 17:10:57 -070098 public void showSearchPanel();
99 public void hideSearchPanel();
Michael Jurka7f2668c2012-03-27 07:49:52 -0700100 public void cancelPreloadRecentApps();
Daniel Sandler328310c2011-09-23 15:56:52 -0400101 public void setNavigationIconHints(int hints);
John Spurlock97642182013-07-29 17:58:39 -0400102 public void setWindowState(int window, int state);
Joe Onorato0cbda992010-05-02 16:28:15 -0700103 }
104
105 public CommandQueue(Callbacks callbacks, StatusBarIconList list) {
106 mCallbacks = callbacks;
107 mList = list;
108 }
109
110 public void setIcon(int index, StatusBarIcon icon) {
111 synchronized (mList) {
112 int what = MSG_ICON | index;
113 mHandler.removeMessages(what);
114 mHandler.obtainMessage(what, OP_SET_ICON, 0, icon.clone()).sendToTarget();
115 }
116 }
117
118 public void removeIcon(int index) {
119 synchronized (mList) {
120 int what = MSG_ICON | index;
121 mHandler.removeMessages(what);
122 mHandler.obtainMessage(what, OP_REMOVE_ICON, 0, null).sendToTarget();
123 }
124 }
125
Joe Onoratoa0c56fe2010-05-20 10:21:52 -0700126 public void addNotification(IBinder key, StatusBarNotification notification) {
127 synchronized (mList) {
128 NotificationQueueEntry ne = new NotificationQueueEntry();
129 ne.key = key;
130 ne.notification = notification;
131 mHandler.obtainMessage(MSG_ADD_NOTIFICATION, 0, 0, ne).sendToTarget();
132 }
133 }
134
135 public void updateNotification(IBinder key, StatusBarNotification notification) {
136 synchronized (mList) {
137 NotificationQueueEntry ne = new NotificationQueueEntry();
138 ne.key = key;
139 ne.notification = notification;
140 mHandler.obtainMessage(MSG_UPDATE_NOTIFICATION, 0, 0, ne).sendToTarget();
141 }
142 }
143
144 public void removeNotification(IBinder key) {
145 synchronized (mList) {
146 mHandler.obtainMessage(MSG_REMOVE_NOTIFICATION, 0, 0, key).sendToTarget();
147 }
148 }
149
Joe Onoratof3f0e052010-05-14 18:49:29 -0700150 public void disable(int state) {
151 synchronized (mList) {
152 mHandler.removeMessages(MSG_DISABLE);
153 mHandler.obtainMessage(MSG_DISABLE, state, 0, null).sendToTarget();
154 }
155 }
156
Daniel Sandler11cf1782012-09-27 14:03:08 -0400157 public void animateExpandNotificationsPanel() {
Joe Onorato4762c2d2010-05-17 15:42:59 -0700158 synchronized (mList) {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700159 mHandler.removeMessages(MSG_EXPAND_NOTIFICATIONS);
160 mHandler.sendEmptyMessage(MSG_EXPAND_NOTIFICATIONS);
Joe Onorato4762c2d2010-05-17 15:42:59 -0700161 }
162 }
163
Daniel Sandler11cf1782012-09-27 14:03:08 -0400164 public void animateCollapsePanels() {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700165 synchronized (mList) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400166 mHandler.removeMessages(MSG_COLLAPSE_PANELS);
167 mHandler.sendEmptyMessage(MSG_COLLAPSE_PANELS);
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700168 }
Jim Miller9a720f52012-05-30 03:19:43 -0700169 }
170
Daniel Sandler11cf1782012-09-27 14:03:08 -0400171 public void animateExpandSettingsPanel() {
Joe Onorato4762c2d2010-05-17 15:42:59 -0700172 synchronized (mList) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400173 mHandler.removeMessages(MSG_EXPAND_SETTINGS);
174 mHandler.sendEmptyMessage(MSG_EXPAND_SETTINGS);
Joe Onorato4762c2d2010-05-17 15:42:59 -0700175 }
176 }
177
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700178 public void setSystemUiVisibility(int vis, int mask) {
Joe Onorato93056472010-09-10 10:30:46 -0400179 synchronized (mList) {
Daniel Sandler60ee2562011-07-22 12:34:33 -0400180 mHandler.removeMessages(MSG_SET_SYSTEMUI_VISIBILITY);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700181 mHandler.obtainMessage(MSG_SET_SYSTEMUI_VISIBILITY, vis, mask, null).sendToTarget();
Joe Onorato93056472010-09-10 10:30:46 -0400182 }
183 }
184
Dianne Hackborn7d049322011-06-14 15:00:32 -0700185 public void topAppWindowChanged(boolean menuVisible) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400186 synchronized (mList) {
Dianne Hackborn7d049322011-06-14 15:00:32 -0700187 mHandler.removeMessages(MSG_TOP_APP_WINDOW_CHANGED);
188 mHandler.obtainMessage(MSG_TOP_APP_WINDOW_CHANGED, menuVisible ? 1 : 0, 0,
189 null).sendToTarget();
Daniel Sandlere02d8082010-10-08 15:13:22 -0400190 }
191 }
192
Joe Onorato857fd9b2011-01-27 15:08:35 -0800193 public void setImeWindowStatus(IBinder token, int vis, int backDisposition) {
satok06487a52010-10-29 11:37:18 +0900194 synchronized (mList) {
195 mHandler.removeMessages(MSG_SHOW_IME_BUTTON);
Joe Onorato857fd9b2011-01-27 15:08:35 -0800196 mHandler.obtainMessage(MSG_SHOW_IME_BUTTON, vis, backDisposition, token)
197 .sendToTarget();
satok06487a52010-10-29 11:37:18 +0900198 }
199 }
200
Jeff Brown2992ea72011-01-28 22:04:14 -0800201 public void setHardKeyboardStatus(boolean available, boolean enabled) {
202 synchronized (mList) {
203 mHandler.removeMessages(MSG_SET_HARD_KEYBOARD_STATUS);
204 mHandler.obtainMessage(MSG_SET_HARD_KEYBOARD_STATUS,
205 available ? 1 : 0, enabled ? 1 : 0).sendToTarget();
206 }
207 }
208
Michael Jurka3b1fc472011-06-13 10:54:40 -0700209 public void toggleRecentApps() {
210 synchronized (mList) {
211 mHandler.removeMessages(MSG_TOGGLE_RECENT_APPS);
212 mHandler.obtainMessage(MSG_TOGGLE_RECENT_APPS, 0, 0, null).sendToTarget();
213 }
214 }
215
Michael Jurka7f2668c2012-03-27 07:49:52 -0700216 public void preloadRecentApps() {
217 synchronized (mList) {
218 mHandler.removeMessages(MSG_PRELOAD_RECENT_APPS);
219 mHandler.obtainMessage(MSG_PRELOAD_RECENT_APPS, 0, 0, null).sendToTarget();
220 }
221 }
222
223 public void cancelPreloadRecentApps() {
224 synchronized (mList) {
225 mHandler.removeMessages(MSG_CANCEL_PRELOAD_RECENT_APPS);
226 mHandler.obtainMessage(MSG_CANCEL_PRELOAD_RECENT_APPS, 0, 0, null).sendToTarget();
227 }
228 }
229
Daniel Sandler328310c2011-09-23 15:56:52 -0400230 public void setNavigationIconHints(int hints) {
231 synchronized (mList) {
232 mHandler.removeMessages(MSG_SET_NAVIGATION_ICON_HINTS);
233 mHandler.obtainMessage(MSG_SET_NAVIGATION_ICON_HINTS, hints, 0, null).sendToTarget();
234 }
235 }
236
John Spurlock97642182013-07-29 17:58:39 -0400237 public void setWindowState(int window, int state) {
238 synchronized (mList) {
John Spurlock5b9145b2013-08-20 15:13:47 -0400239 // don't coalesce these
John Spurlock97642182013-07-29 17:58:39 -0400240 mHandler.obtainMessage(MSG_SET_WINDOW_STATE, window, state, null).sendToTarget();
241 }
242 }
243
Joe Onorato0cbda992010-05-02 16:28:15 -0700244 private final class H extends Handler {
245 public void handleMessage(Message msg) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700246 final int what = msg.what & MSG_MASK;
Joe Onorato66d7d012010-05-14 10:05:10 -0700247 switch (what) {
Joe Onorato0cbda992010-05-02 16:28:15 -0700248 case MSG_ICON: {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700249 final int index = msg.what & INDEX_MASK;
250 final int viewIndex = mList.getViewIndex(index);
Joe Onorato0cbda992010-05-02 16:28:15 -0700251 switch (msg.arg1) {
252 case OP_SET_ICON: {
253 StatusBarIcon icon = (StatusBarIcon)msg.obj;
254 StatusBarIcon old = mList.getIcon(index);
255 if (old == null) {
256 mList.setIcon(index, icon);
257 mCallbacks.addIcon(mList.getSlot(index), index, viewIndex, icon);
258 } else {
259 mList.setIcon(index, icon);
260 mCallbacks.updateIcon(mList.getSlot(index), index, viewIndex,
261 old, icon);
262 }
263 break;
264 }
265 case OP_REMOVE_ICON:
Joe Onorato795f2842010-09-27 11:34:46 -0700266 if (mList.getIcon(index) != null) {
267 mList.removeIcon(index);
268 mCallbacks.removeIcon(mList.getSlot(index), index, viewIndex);
269 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700270 break;
271 }
272 break;
Joe Onoratof3f0e052010-05-14 18:49:29 -0700273 }
Joe Onoratoa0c56fe2010-05-20 10:21:52 -0700274 case MSG_ADD_NOTIFICATION: {
275 final NotificationQueueEntry ne = (NotificationQueueEntry)msg.obj;
276 mCallbacks.addNotification(ne.key, ne.notification);
277 break;
278 }
279 case MSG_UPDATE_NOTIFICATION: {
280 final NotificationQueueEntry ne = (NotificationQueueEntry)msg.obj;
281 mCallbacks.updateNotification(ne.key, ne.notification);
282 break;
283 }
284 case MSG_REMOVE_NOTIFICATION: {
285 mCallbacks.removeNotification((IBinder)msg.obj);
286 break;
287 }
Joe Onoratof3f0e052010-05-14 18:49:29 -0700288 case MSG_DISABLE:
289 mCallbacks.disable(msg.arg1);
290 break;
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700291 case MSG_EXPAND_NOTIFICATIONS:
Daniel Sandler11cf1782012-09-27 14:03:08 -0400292 mCallbacks.animateExpandNotificationsPanel();
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700293 break;
Daniel Sandler11cf1782012-09-27 14:03:08 -0400294 case MSG_COLLAPSE_PANELS:
295 mCallbacks.animateCollapsePanels(0);
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700296 break;
Daniel Sandler11cf1782012-09-27 14:03:08 -0400297 case MSG_EXPAND_SETTINGS:
298 mCallbacks.animateExpandSettingsPanel();
Joe Onorato93056472010-09-10 10:30:46 -0400299 break;
Daniel Sandler60ee2562011-07-22 12:34:33 -0400300 case MSG_SET_SYSTEMUI_VISIBILITY:
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700301 mCallbacks.setSystemUiVisibility(msg.arg1, msg.arg2);
Joe Onorato93056472010-09-10 10:30:46 -0400302 break;
Dianne Hackborn7d049322011-06-14 15:00:32 -0700303 case MSG_TOP_APP_WINDOW_CHANGED:
304 mCallbacks.topAppWindowChanged(msg.arg1 != 0);
Daniel Sandlere02d8082010-10-08 15:13:22 -0400305 break;
satok06487a52010-10-29 11:37:18 +0900306 case MSG_SHOW_IME_BUTTON:
Joe Onorato857fd9b2011-01-27 15:08:35 -0800307 mCallbacks.setImeWindowStatus((IBinder)msg.obj, msg.arg1, msg.arg2);
satok06487a52010-10-29 11:37:18 +0900308 break;
Jeff Brown2992ea72011-01-28 22:04:14 -0800309 case MSG_SET_HARD_KEYBOARD_STATUS:
310 mCallbacks.setHardKeyboardStatus(msg.arg1 != 0, msg.arg2 != 0);
311 break;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700312 case MSG_TOGGLE_RECENT_APPS:
313 mCallbacks.toggleRecentApps();
314 break;
Michael Jurka7f2668c2012-03-27 07:49:52 -0700315 case MSG_PRELOAD_RECENT_APPS:
316 mCallbacks.preloadRecentApps();
317 break;
318 case MSG_CANCEL_PRELOAD_RECENT_APPS:
319 mCallbacks.cancelPreloadRecentApps();
320 break;
Daniel Sandler328310c2011-09-23 15:56:52 -0400321 case MSG_SET_NAVIGATION_ICON_HINTS:
322 mCallbacks.setNavigationIconHints(msg.arg1);
323 break;
John Spurlock97642182013-07-29 17:58:39 -0400324 case MSG_SET_WINDOW_STATE:
325 mCallbacks.setWindowState(msg.arg1, msg.arg2);
326 break;
Joe Onorato0cbda992010-05-02 16:28:15 -0700327 }
328 }
329 }
330}
331