blob: cf6f60cfc9e9e7d16156bce47f53f5c5e0c8020b [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;
Jorim Jaggi380ecb82014-03-14 17:25:20 +010060 private static final int MSG_SET_KEYGUARD_SHOWN = 17 << MSG_SHIFT;
Daniel Sandler328310c2011-09-23 15:56:52 -040061
Jim Miller9a720f52012-05-30 03:19:43 -070062 public static final int FLAG_EXCLUDE_NONE = 0;
63 public static final int FLAG_EXCLUDE_SEARCH_PANEL = 1 << 0;
64 public static final int FLAG_EXCLUDE_RECENTS_PANEL = 1 << 1;
65 public static final int FLAG_EXCLUDE_NOTIFICATION_PANEL = 1 << 2;
66 public static final int FLAG_EXCLUDE_INPUT_METHODS_PANEL = 1 << 3;
67 public static final int FLAG_EXCLUDE_COMPAT_MODE_PANEL = 1 << 4;
68
Joe Onorato0cbda992010-05-02 16:28:15 -070069 private StatusBarIconList mList;
70 private Callbacks mCallbacks;
71 private Handler mHandler = new H();
72
Joe Onoratoa0c56fe2010-05-20 10:21:52 -070073 private class NotificationQueueEntry {
74 IBinder key;
75 StatusBarNotification notification;
76 }
77
Joe Onorato0cbda992010-05-02 16:28:15 -070078 /**
79 * These methods are called back on the main thread.
80 */
81 public interface Callbacks {
82 public void addIcon(String slot, int index, int viewIndex, StatusBarIcon icon);
83 public void updateIcon(String slot, int index, int viewIndex,
84 StatusBarIcon old, StatusBarIcon icon);
85 public void removeIcon(String slot, int index, int viewIndex);
Joe Onoratoa0c56fe2010-05-20 10:21:52 -070086 public void addNotification(IBinder key, StatusBarNotification notification);
87 public void updateNotification(IBinder key, StatusBarNotification notification);
88 public void removeNotification(IBinder key);
Joe Onoratof3f0e052010-05-14 18:49:29 -070089 public void disable(int state);
Daniel Sandler11cf1782012-09-27 14:03:08 -040090 public void animateExpandNotificationsPanel();
91 public void animateCollapsePanels(int flags);
92 public void animateExpandSettingsPanel();
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -070093 public void setSystemUiVisibility(int vis, int mask);
Dianne Hackborn7d049322011-06-14 15:00:32 -070094 public void topAppWindowChanged(boolean visible);
Joe Onorato857fd9b2011-01-27 15:08:35 -080095 public void setImeWindowStatus(IBinder token, int vis, int backDisposition);
Jeff Brown2992ea72011-01-28 22:04:14 -080096 public void setHardKeyboardStatus(boolean available, boolean enabled);
Michael Jurka3b1fc472011-06-13 10:54:40 -070097 public void toggleRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -070098 public void preloadRecentApps();
Jim Millere898ac52012-04-06 17:10:57 -070099 public void showSearchPanel();
100 public void hideSearchPanel();
Michael Jurka7f2668c2012-03-27 07:49:52 -0700101 public void cancelPreloadRecentApps();
John Spurlock97642182013-07-29 17:58:39 -0400102 public void setWindowState(int window, int state);
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100103 public void setKeyguardShown(boolean showKeyguard, IKeyguardShowCallback callback,
104 boolean updateWindowFlags);
Joe Onorato0cbda992010-05-02 16:28:15 -0700105 }
106
107 public CommandQueue(Callbacks callbacks, StatusBarIconList list) {
108 mCallbacks = callbacks;
109 mList = list;
110 }
111
112 public void setIcon(int index, StatusBarIcon icon) {
113 synchronized (mList) {
114 int what = MSG_ICON | index;
115 mHandler.removeMessages(what);
116 mHandler.obtainMessage(what, OP_SET_ICON, 0, icon.clone()).sendToTarget();
117 }
118 }
119
120 public void removeIcon(int index) {
121 synchronized (mList) {
122 int what = MSG_ICON | index;
123 mHandler.removeMessages(what);
124 mHandler.obtainMessage(what, OP_REMOVE_ICON, 0, null).sendToTarget();
125 }
126 }
127
Joe Onoratoa0c56fe2010-05-20 10:21:52 -0700128 public void addNotification(IBinder key, StatusBarNotification notification) {
129 synchronized (mList) {
130 NotificationQueueEntry ne = new NotificationQueueEntry();
131 ne.key = key;
132 ne.notification = notification;
133 mHandler.obtainMessage(MSG_ADD_NOTIFICATION, 0, 0, ne).sendToTarget();
134 }
135 }
136
137 public void updateNotification(IBinder key, StatusBarNotification notification) {
138 synchronized (mList) {
139 NotificationQueueEntry ne = new NotificationQueueEntry();
140 ne.key = key;
141 ne.notification = notification;
142 mHandler.obtainMessage(MSG_UPDATE_NOTIFICATION, 0, 0, ne).sendToTarget();
143 }
144 }
145
146 public void removeNotification(IBinder key) {
147 synchronized (mList) {
148 mHandler.obtainMessage(MSG_REMOVE_NOTIFICATION, 0, 0, key).sendToTarget();
149 }
150 }
151
Joe Onoratof3f0e052010-05-14 18:49:29 -0700152 public void disable(int state) {
153 synchronized (mList) {
154 mHandler.removeMessages(MSG_DISABLE);
155 mHandler.obtainMessage(MSG_DISABLE, state, 0, null).sendToTarget();
156 }
157 }
158
Daniel Sandler11cf1782012-09-27 14:03:08 -0400159 public void animateExpandNotificationsPanel() {
Joe Onorato4762c2d2010-05-17 15:42:59 -0700160 synchronized (mList) {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700161 mHandler.removeMessages(MSG_EXPAND_NOTIFICATIONS);
162 mHandler.sendEmptyMessage(MSG_EXPAND_NOTIFICATIONS);
Joe Onorato4762c2d2010-05-17 15:42:59 -0700163 }
164 }
165
Daniel Sandler11cf1782012-09-27 14:03:08 -0400166 public void animateCollapsePanels() {
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700167 synchronized (mList) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400168 mHandler.removeMessages(MSG_COLLAPSE_PANELS);
169 mHandler.sendEmptyMessage(MSG_COLLAPSE_PANELS);
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700170 }
Jim Miller9a720f52012-05-30 03:19:43 -0700171 }
172
Daniel Sandler11cf1782012-09-27 14:03:08 -0400173 public void animateExpandSettingsPanel() {
Joe Onorato4762c2d2010-05-17 15:42:59 -0700174 synchronized (mList) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400175 mHandler.removeMessages(MSG_EXPAND_SETTINGS);
176 mHandler.sendEmptyMessage(MSG_EXPAND_SETTINGS);
Joe Onorato4762c2d2010-05-17 15:42:59 -0700177 }
178 }
179
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700180 public void setSystemUiVisibility(int vis, int mask) {
Joe Onorato93056472010-09-10 10:30:46 -0400181 synchronized (mList) {
Daniel Sandler60ee2562011-07-22 12:34:33 -0400182 mHandler.removeMessages(MSG_SET_SYSTEMUI_VISIBILITY);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700183 mHandler.obtainMessage(MSG_SET_SYSTEMUI_VISIBILITY, vis, mask, null).sendToTarget();
Joe Onorato93056472010-09-10 10:30:46 -0400184 }
185 }
186
Dianne Hackborn7d049322011-06-14 15:00:32 -0700187 public void topAppWindowChanged(boolean menuVisible) {
Daniel Sandlere02d8082010-10-08 15:13:22 -0400188 synchronized (mList) {
Dianne Hackborn7d049322011-06-14 15:00:32 -0700189 mHandler.removeMessages(MSG_TOP_APP_WINDOW_CHANGED);
190 mHandler.obtainMessage(MSG_TOP_APP_WINDOW_CHANGED, menuVisible ? 1 : 0, 0,
191 null).sendToTarget();
Daniel Sandlere02d8082010-10-08 15:13:22 -0400192 }
193 }
194
Joe Onorato857fd9b2011-01-27 15:08:35 -0800195 public void setImeWindowStatus(IBinder token, int vis, int backDisposition) {
satok06487a52010-10-29 11:37:18 +0900196 synchronized (mList) {
197 mHandler.removeMessages(MSG_SHOW_IME_BUTTON);
Joe Onorato857fd9b2011-01-27 15:08:35 -0800198 mHandler.obtainMessage(MSG_SHOW_IME_BUTTON, vis, backDisposition, token)
199 .sendToTarget();
satok06487a52010-10-29 11:37:18 +0900200 }
201 }
202
Jeff Brown2992ea72011-01-28 22:04:14 -0800203 public void setHardKeyboardStatus(boolean available, boolean enabled) {
204 synchronized (mList) {
205 mHandler.removeMessages(MSG_SET_HARD_KEYBOARD_STATUS);
206 mHandler.obtainMessage(MSG_SET_HARD_KEYBOARD_STATUS,
207 available ? 1 : 0, enabled ? 1 : 0).sendToTarget();
208 }
209 }
210
Michael Jurka3b1fc472011-06-13 10:54:40 -0700211 public void toggleRecentApps() {
212 synchronized (mList) {
213 mHandler.removeMessages(MSG_TOGGLE_RECENT_APPS);
214 mHandler.obtainMessage(MSG_TOGGLE_RECENT_APPS, 0, 0, null).sendToTarget();
215 }
216 }
217
Michael Jurka7f2668c2012-03-27 07:49:52 -0700218 public void preloadRecentApps() {
219 synchronized (mList) {
220 mHandler.removeMessages(MSG_PRELOAD_RECENT_APPS);
221 mHandler.obtainMessage(MSG_PRELOAD_RECENT_APPS, 0, 0, null).sendToTarget();
222 }
223 }
224
225 public void cancelPreloadRecentApps() {
226 synchronized (mList) {
227 mHandler.removeMessages(MSG_CANCEL_PRELOAD_RECENT_APPS);
228 mHandler.obtainMessage(MSG_CANCEL_PRELOAD_RECENT_APPS, 0, 0, null).sendToTarget();
229 }
230 }
231
John Spurlock97642182013-07-29 17:58:39 -0400232 public void setWindowState(int window, int state) {
233 synchronized (mList) {
John Spurlock5b9145b2013-08-20 15:13:47 -0400234 // don't coalesce these
John Spurlock97642182013-07-29 17:58:39 -0400235 mHandler.obtainMessage(MSG_SET_WINDOW_STATE, window, state, null).sendToTarget();
236 }
237 }
238
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100239 public void setKeyguardShown(boolean showKeyguard, IKeyguardShowCallback callback,
240 boolean updateWindowFlags) {
241 synchronized (mList) {
242 mHandler.removeMessages(MSG_SET_KEYGUARD_SHOWN);
243 mHandler.obtainMessage(MSG_SET_KEYGUARD_SHOWN,
244 showKeyguard ? 1 : 0, updateWindowFlags ? 1 : 0, callback).sendToTarget();
245 }
246 }
247
Joe Onorato0cbda992010-05-02 16:28:15 -0700248 private final class H extends Handler {
249 public void handleMessage(Message msg) {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700250 final int what = msg.what & MSG_MASK;
Joe Onorato66d7d012010-05-14 10:05:10 -0700251 switch (what) {
Joe Onorato0cbda992010-05-02 16:28:15 -0700252 case MSG_ICON: {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700253 final int index = msg.what & INDEX_MASK;
254 final int viewIndex = mList.getViewIndex(index);
Joe Onorato0cbda992010-05-02 16:28:15 -0700255 switch (msg.arg1) {
256 case OP_SET_ICON: {
257 StatusBarIcon icon = (StatusBarIcon)msg.obj;
258 StatusBarIcon old = mList.getIcon(index);
259 if (old == null) {
260 mList.setIcon(index, icon);
261 mCallbacks.addIcon(mList.getSlot(index), index, viewIndex, icon);
262 } else {
263 mList.setIcon(index, icon);
264 mCallbacks.updateIcon(mList.getSlot(index), index, viewIndex,
265 old, icon);
266 }
267 break;
268 }
269 case OP_REMOVE_ICON:
Joe Onorato795f2842010-09-27 11:34:46 -0700270 if (mList.getIcon(index) != null) {
271 mList.removeIcon(index);
272 mCallbacks.removeIcon(mList.getSlot(index), index, viewIndex);
273 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700274 break;
275 }
276 break;
Joe Onoratof3f0e052010-05-14 18:49:29 -0700277 }
Joe Onoratoa0c56fe2010-05-20 10:21:52 -0700278 case MSG_ADD_NOTIFICATION: {
279 final NotificationQueueEntry ne = (NotificationQueueEntry)msg.obj;
280 mCallbacks.addNotification(ne.key, ne.notification);
281 break;
282 }
283 case MSG_UPDATE_NOTIFICATION: {
284 final NotificationQueueEntry ne = (NotificationQueueEntry)msg.obj;
285 mCallbacks.updateNotification(ne.key, ne.notification);
286 break;
287 }
288 case MSG_REMOVE_NOTIFICATION: {
289 mCallbacks.removeNotification((IBinder)msg.obj);
290 break;
291 }
Joe Onoratof3f0e052010-05-14 18:49:29 -0700292 case MSG_DISABLE:
293 mCallbacks.disable(msg.arg1);
294 break;
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700295 case MSG_EXPAND_NOTIFICATIONS:
Daniel Sandler11cf1782012-09-27 14:03:08 -0400296 mCallbacks.animateExpandNotificationsPanel();
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700297 break;
Daniel Sandler11cf1782012-09-27 14:03:08 -0400298 case MSG_COLLAPSE_PANELS:
299 mCallbacks.animateCollapsePanels(0);
Svetoslav Ganove20a1772012-09-25 16:07:46 -0700300 break;
Daniel Sandler11cf1782012-09-27 14:03:08 -0400301 case MSG_EXPAND_SETTINGS:
302 mCallbacks.animateExpandSettingsPanel();
Joe Onorato93056472010-09-10 10:30:46 -0400303 break;
Daniel Sandler60ee2562011-07-22 12:34:33 -0400304 case MSG_SET_SYSTEMUI_VISIBILITY:
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700305 mCallbacks.setSystemUiVisibility(msg.arg1, msg.arg2);
Joe Onorato93056472010-09-10 10:30:46 -0400306 break;
Dianne Hackborn7d049322011-06-14 15:00:32 -0700307 case MSG_TOP_APP_WINDOW_CHANGED:
308 mCallbacks.topAppWindowChanged(msg.arg1 != 0);
Daniel Sandlere02d8082010-10-08 15:13:22 -0400309 break;
satok06487a52010-10-29 11:37:18 +0900310 case MSG_SHOW_IME_BUTTON:
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100311 mCallbacks.setImeWindowStatus((IBinder) msg.obj, msg.arg1, msg.arg2);
satok06487a52010-10-29 11:37:18 +0900312 break;
Jeff Brown2992ea72011-01-28 22:04:14 -0800313 case MSG_SET_HARD_KEYBOARD_STATUS:
314 mCallbacks.setHardKeyboardStatus(msg.arg1 != 0, msg.arg2 != 0);
315 break;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700316 case MSG_TOGGLE_RECENT_APPS:
317 mCallbacks.toggleRecentApps();
318 break;
Michael Jurka7f2668c2012-03-27 07:49:52 -0700319 case MSG_PRELOAD_RECENT_APPS:
320 mCallbacks.preloadRecentApps();
321 break;
322 case MSG_CANCEL_PRELOAD_RECENT_APPS:
323 mCallbacks.cancelPreloadRecentApps();
324 break;
John Spurlock97642182013-07-29 17:58:39 -0400325 case MSG_SET_WINDOW_STATE:
326 mCallbacks.setWindowState(msg.arg1, msg.arg2);
327 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100328 case MSG_SET_KEYGUARD_SHOWN:
329 mCallbacks.setKeyguardShown(msg.arg1 != 0, (IKeyguardShowCallback) msg.obj,
330 msg.arg2 != 0);
331 break;
Joe Onorato0cbda992010-05-02 16:28:15 -0700332 }
333 }
334 }
335}
336