blob: 43992c8800f47251e31946b3c5a0f189b849ac57 [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;
Daniel Sandler328310c2011-09-23 15:56:52 -040059
Jim Miller9a720f52012-05-30 03:19:43 -070060 public static final int FLAG_EXCLUDE_NONE = 0;
61 public static final int FLAG_EXCLUDE_SEARCH_PANEL = 1 << 0;
62 public static final int FLAG_EXCLUDE_RECENTS_PANEL = 1 << 1;
63 public static final int FLAG_EXCLUDE_NOTIFICATION_PANEL = 1 << 2;
64 public static final int FLAG_EXCLUDE_INPUT_METHODS_PANEL = 1 << 3;
65 public static final int FLAG_EXCLUDE_COMPAT_MODE_PANEL = 1 << 4;
66
Joe Onorato0cbda992010-05-02 16:28:15 -070067 private StatusBarIconList mList;
68 private Callbacks mCallbacks;
69 private Handler mHandler = new H();
70
Joe Onoratoa0c56fe2010-05-20 10:21:52 -070071 private class NotificationQueueEntry {
72 IBinder key;
73 StatusBarNotification notification;
74 }
75
Joe Onorato0cbda992010-05-02 16:28:15 -070076 /**
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 Onoratoa0c56fe2010-05-20 10:21:52 -070084 public void addNotification(IBinder key, StatusBarNotification notification);
85 public void updateNotification(IBinder key, StatusBarNotification notification);
86 public void removeNotification(IBinder key);
Joe Onoratof3f0e052010-05-14 18:49:29 -070087 public void disable(int state);
Daniel Sandler11cf1782012-09-27 14:03:08 -040088 public void animateExpandNotificationsPanel();
89 public void animateCollapsePanels(int flags);
90 public void animateExpandSettingsPanel();
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -070091 public void setSystemUiVisibility(int vis, int mask);
Dianne Hackborn7d049322011-06-14 15:00:32 -070092 public void topAppWindowChanged(boolean visible);
Joe Onorato857fd9b2011-01-27 15:08:35 -080093 public void setImeWindowStatus(IBinder token, int vis, int backDisposition);
Jeff Brown2992ea72011-01-28 22:04:14 -080094 public void setHardKeyboardStatus(boolean available, boolean enabled);
Michael Jurka3b1fc472011-06-13 10:54:40 -070095 public void toggleRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -070096 public void preloadRecentApps();
Jim Millere898ac52012-04-06 17:10:57 -070097 public void showSearchPanel();
98 public void hideSearchPanel();
Michael Jurka7f2668c2012-03-27 07:49:52 -070099 public void cancelPreloadRecentApps();
Daniel Sandler328310c2011-09-23 15:56:52 -0400100 public void setNavigationIconHints(int hints);
Joe Onorato0cbda992010-05-02 16:28:15 -0700101 }
102
103 public CommandQueue(Callbacks callbacks, StatusBarIconList list) {
104 mCallbacks = callbacks;
105 mList = list;
106 }
107
108 public void setIcon(int index, StatusBarIcon icon) {
109 synchronized (mList) {
110 int what = MSG_ICON | index;
111 mHandler.removeMessages(what);
112 mHandler.obtainMessage(what, OP_SET_ICON, 0, icon.clone()).sendToTarget();
113 }
114 }
115
116 public void removeIcon(int index) {
117 synchronized (mList) {
118 int what = MSG_ICON | index;
119 mHandler.removeMessages(what);
120 mHandler.obtainMessage(what, OP_REMOVE_ICON, 0, null).sendToTarget();
121 }
122 }
123
Joe Onoratoa0c56fe2010-05-20 10:21:52 -0700124 public void addNotification(IBinder key, StatusBarNotification notification) {
125 synchronized (mList) {
126 NotificationQueueEntry ne = new NotificationQueueEntry();
127 ne.key = key;
128 ne.notification = notification;
129 mHandler.obtainMessage(MSG_ADD_NOTIFICATION, 0, 0, ne).sendToTarget();
130 }
131 }
132
133 public void updateNotification(IBinder key, StatusBarNotification notification) {
134 synchronized (mList) {
135 NotificationQueueEntry ne = new NotificationQueueEntry();
136 ne.key = key;
137 ne.notification = notification;
138 mHandler.obtainMessage(MSG_UPDATE_NOTIFICATION, 0, 0, ne).sendToTarget();
139 }
140 }
141
142 public void removeNotification(IBinder key) {
143 synchronized (mList) {
144 mHandler.obtainMessage(MSG_REMOVE_NOTIFICATION, 0, 0, key).sendToTarget();
145 }
146 }
147
Joe Onoratof3f0e052010-05-14 18:49:29 -0700148 public void disable(int state) {
149 synchronized (mList) {
150 mHandler.removeMessages(MSG_DISABLE);
151 mHandler.obtainMessage(MSG_DISABLE, state, 0, null).sendToTarget();
152 }
153 }
154
Daniel Sandler11cf1782012-09-27 14:03:08 -0400155 public void animateExpandNotificationsPanel() {
Joe Onorato4762c2d2010-05-17 15:42:59 -0700156 synchronized (mList) {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700157 mHandler.removeMessages(MSG_EXPAND_NOTIFICATIONS);
158 mHandler.sendEmptyMessage(MSG_EXPAND_NOTIFICATIONS);
Joe Onorato4762c2d2010-05-17 15:42:59 -0700159 }
160 }
161
Daniel Sandler11cf1782012-09-27 14:03:08 -0400162 public void animateCollapsePanels() {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700163 synchronized (mList) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400164 mHandler.removeMessages(MSG_COLLAPSE_PANELS);
165 mHandler.sendEmptyMessage(MSG_COLLAPSE_PANELS);
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700166 }
Jim Miller9a720f52012-05-30 03:19:43 -0700167 }
168
Daniel Sandler11cf1782012-09-27 14:03:08 -0400169 public void animateExpandSettingsPanel() {
Joe Onorato4762c2d2010-05-17 15:42:59 -0700170 synchronized (mList) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400171 mHandler.removeMessages(MSG_EXPAND_SETTINGS);
172 mHandler.sendEmptyMessage(MSG_EXPAND_SETTINGS);
Joe Onorato4762c2d2010-05-17 15:42:59 -0700173 }
174 }
175
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700176 public void setSystemUiVisibility(int vis, int mask) {
Joe Onorato93056472010-09-10 10:30:46 -0400177 synchronized (mList) {
Daniel Sandler60ee2562011-07-22 12:34:33 -0400178 mHandler.removeMessages(MSG_SET_SYSTEMUI_VISIBILITY);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700179 mHandler.obtainMessage(MSG_SET_SYSTEMUI_VISIBILITY, vis, mask, null).sendToTarget();
Joe Onorato93056472010-09-10 10:30:46 -0400180 }
181 }
182
Dianne Hackborn7d049322011-06-14 15:00:32 -0700183 public void topAppWindowChanged(boolean menuVisible) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400184 synchronized (mList) {
Dianne Hackborn7d049322011-06-14 15:00:32 -0700185 mHandler.removeMessages(MSG_TOP_APP_WINDOW_CHANGED);
186 mHandler.obtainMessage(MSG_TOP_APP_WINDOW_CHANGED, menuVisible ? 1 : 0, 0,
187 null).sendToTarget();
Daniel Sandlere02d8082010-10-08 15:13:22 -0400188 }
189 }
190
Joe Onorato857fd9b2011-01-27 15:08:35 -0800191 public void setImeWindowStatus(IBinder token, int vis, int backDisposition) {
satok06487a52010-10-29 11:37:18 +0900192 synchronized (mList) {
193 mHandler.removeMessages(MSG_SHOW_IME_BUTTON);
Joe Onorato857fd9b2011-01-27 15:08:35 -0800194 mHandler.obtainMessage(MSG_SHOW_IME_BUTTON, vis, backDisposition, token)
195 .sendToTarget();
satok06487a52010-10-29 11:37:18 +0900196 }
197 }
198
Jeff Brown2992ea72011-01-28 22:04:14 -0800199 public void setHardKeyboardStatus(boolean available, boolean enabled) {
200 synchronized (mList) {
201 mHandler.removeMessages(MSG_SET_HARD_KEYBOARD_STATUS);
202 mHandler.obtainMessage(MSG_SET_HARD_KEYBOARD_STATUS,
203 available ? 1 : 0, enabled ? 1 : 0).sendToTarget();
204 }
205 }
206
Michael Jurka3b1fc472011-06-13 10:54:40 -0700207 public void toggleRecentApps() {
208 synchronized (mList) {
209 mHandler.removeMessages(MSG_TOGGLE_RECENT_APPS);
210 mHandler.obtainMessage(MSG_TOGGLE_RECENT_APPS, 0, 0, null).sendToTarget();
211 }
212 }
213
Michael Jurka7f2668c2012-03-27 07:49:52 -0700214 public void preloadRecentApps() {
215 synchronized (mList) {
216 mHandler.removeMessages(MSG_PRELOAD_RECENT_APPS);
217 mHandler.obtainMessage(MSG_PRELOAD_RECENT_APPS, 0, 0, null).sendToTarget();
218 }
219 }
220
221 public void cancelPreloadRecentApps() {
222 synchronized (mList) {
223 mHandler.removeMessages(MSG_CANCEL_PRELOAD_RECENT_APPS);
224 mHandler.obtainMessage(MSG_CANCEL_PRELOAD_RECENT_APPS, 0, 0, null).sendToTarget();
225 }
226 }
227
Daniel Sandler328310c2011-09-23 15:56:52 -0400228 public void setNavigationIconHints(int hints) {
229 synchronized (mList) {
230 mHandler.removeMessages(MSG_SET_NAVIGATION_ICON_HINTS);
231 mHandler.obtainMessage(MSG_SET_NAVIGATION_ICON_HINTS, hints, 0, null).sendToTarget();
232 }
233 }
234
Joe Onorato0cbda992010-05-02 16:28:15 -0700235 private final class H extends Handler {
236 public void handleMessage(Message msg) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700237 final int what = msg.what & MSG_MASK;
Joe Onorato66d7d012010-05-14 10:05:10 -0700238 switch (what) {
Joe Onorato0cbda992010-05-02 16:28:15 -0700239 case MSG_ICON: {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700240 final int index = msg.what & INDEX_MASK;
241 final int viewIndex = mList.getViewIndex(index);
Joe Onorato0cbda992010-05-02 16:28:15 -0700242 switch (msg.arg1) {
243 case OP_SET_ICON: {
244 StatusBarIcon icon = (StatusBarIcon)msg.obj;
245 StatusBarIcon old = mList.getIcon(index);
246 if (old == null) {
247 mList.setIcon(index, icon);
248 mCallbacks.addIcon(mList.getSlot(index), index, viewIndex, icon);
249 } else {
250 mList.setIcon(index, icon);
251 mCallbacks.updateIcon(mList.getSlot(index), index, viewIndex,
252 old, icon);
253 }
254 break;
255 }
256 case OP_REMOVE_ICON:
Joe Onorato795f2842010-09-27 11:34:46 -0700257 if (mList.getIcon(index) != null) {
258 mList.removeIcon(index);
259 mCallbacks.removeIcon(mList.getSlot(index), index, viewIndex);
260 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700261 break;
262 }
263 break;
Joe Onoratof3f0e052010-05-14 18:49:29 -0700264 }
Joe Onoratoa0c56fe2010-05-20 10:21:52 -0700265 case MSG_ADD_NOTIFICATION: {
266 final NotificationQueueEntry ne = (NotificationQueueEntry)msg.obj;
267 mCallbacks.addNotification(ne.key, ne.notification);
268 break;
269 }
270 case MSG_UPDATE_NOTIFICATION: {
271 final NotificationQueueEntry ne = (NotificationQueueEntry)msg.obj;
272 mCallbacks.updateNotification(ne.key, ne.notification);
273 break;
274 }
275 case MSG_REMOVE_NOTIFICATION: {
276 mCallbacks.removeNotification((IBinder)msg.obj);
277 break;
278 }
Joe Onoratof3f0e052010-05-14 18:49:29 -0700279 case MSG_DISABLE:
280 mCallbacks.disable(msg.arg1);
281 break;
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700282 case MSG_EXPAND_NOTIFICATIONS:
Daniel Sandler11cf1782012-09-27 14:03:08 -0400283 mCallbacks.animateExpandNotificationsPanel();
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700284 break;
Daniel Sandler11cf1782012-09-27 14:03:08 -0400285 case MSG_COLLAPSE_PANELS:
286 mCallbacks.animateCollapsePanels(0);
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700287 break;
Daniel Sandler11cf1782012-09-27 14:03:08 -0400288 case MSG_EXPAND_SETTINGS:
289 mCallbacks.animateExpandSettingsPanel();
Joe Onorato93056472010-09-10 10:30:46 -0400290 break;
Daniel Sandler60ee2562011-07-22 12:34:33 -0400291 case MSG_SET_SYSTEMUI_VISIBILITY:
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700292 mCallbacks.setSystemUiVisibility(msg.arg1, msg.arg2);
Joe Onorato93056472010-09-10 10:30:46 -0400293 break;
Dianne Hackborn7d049322011-06-14 15:00:32 -0700294 case MSG_TOP_APP_WINDOW_CHANGED:
295 mCallbacks.topAppWindowChanged(msg.arg1 != 0);
Daniel Sandlere02d8082010-10-08 15:13:22 -0400296 break;
satok06487a52010-10-29 11:37:18 +0900297 case MSG_SHOW_IME_BUTTON:
Joe Onorato857fd9b2011-01-27 15:08:35 -0800298 mCallbacks.setImeWindowStatus((IBinder)msg.obj, msg.arg1, msg.arg2);
satok06487a52010-10-29 11:37:18 +0900299 break;
Jeff Brown2992ea72011-01-28 22:04:14 -0800300 case MSG_SET_HARD_KEYBOARD_STATUS:
301 mCallbacks.setHardKeyboardStatus(msg.arg1 != 0, msg.arg2 != 0);
302 break;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700303 case MSG_TOGGLE_RECENT_APPS:
304 mCallbacks.toggleRecentApps();
305 break;
Michael Jurka7f2668c2012-03-27 07:49:52 -0700306 case MSG_PRELOAD_RECENT_APPS:
307 mCallbacks.preloadRecentApps();
308 break;
309 case MSG_CANCEL_PRELOAD_RECENT_APPS:
310 mCallbacks.cancelPreloadRecentApps();
311 break;
Daniel Sandler328310c2011-09-23 15:56:52 -0400312 case MSG_SET_NAVIGATION_ICON_HINTS:
313 mCallbacks.setNavigationIconHints(msg.arg1);
314 break;
Joe Onorato0cbda992010-05-02 16:28:15 -0700315 }
316 }
317 }
318}
319