blob: 82971696d670507667f2ac9e2fb0c79073914007 [file] [log] [blame]
Yorke Leebd54c2a2016-10-25 13:49:23 -07001/*
2 * Copyright (C) 2016 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
17package com.android.server.am;
18
Jorim Jaggifb9d78a2017-01-05 18:57:12 +010019import android.app.ActivityManager.TaskSnapshot;
Yorke Leebd54c2a2016-10-25 13:49:23 -070020import android.app.ITaskStackListener;
21import android.app.ActivityManager.TaskDescription;
22import android.content.ComponentName;
Yorke Lee13294072017-01-06 14:59:58 -080023import android.os.Binder;
Yorke Leebd54c2a2016-10-25 13:49:23 -070024import android.os.Handler;
25import android.os.Looper;
26import android.os.Message;
27import android.os.RemoteCallbackList;
28import android.os.RemoteException;
29
Yorke Lee13294072017-01-06 14:59:58 -080030import java.util.ArrayList;
31
Yorke Leebd54c2a2016-10-25 13:49:23 -070032class TaskChangeNotificationController {
Wale Ogunwalef1b2ec92017-06-05 07:09:35 -070033 private static final int LOG_STACK_STATE_MSG = 1;
34 private static final int NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG = 2;
35 private static final int NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG = 3;
36 private static final int NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG = 4;
37 private static final int NOTIFY_PINNED_STACK_ANIMATION_ENDED_LISTENERS_MSG = 5;
38 private static final int NOTIFY_FORCED_RESIZABLE_MSG = 6;
39 private static final int NOTIFY_ACTIVITY_DISMISSING_DOCKED_STACK_MSG = 7;
40 private static final int NOTIFY_TASK_ADDED_LISTENERS_MSG = 8;
41 private static final int NOTIFY_TASK_REMOVED_LISTENERS_MSG = 9;
42 private static final int NOTIFY_TASK_MOVED_TO_FRONT_LISTENERS_MSG = 10;
43 private static final int NOTIFY_TASK_DESCRIPTION_CHANGED_LISTENERS_MSG = 11;
44 private static final int NOTIFY_ACTIVITY_REQUESTED_ORIENTATION_CHANGED_LISTENERS = 12;
45 private static final int NOTIFY_TASK_REMOVAL_STARTED_LISTENERS = 13;
46 private static final int NOTIFY_TASK_PROFILE_LOCKED_LISTENERS_MSG = 14;
47 private static final int NOTIFY_TASK_SNAPSHOT_CHANGED_LISTENERS_MSG = 15;
48 private static final int NOTIFY_PINNED_STACK_ANIMATION_STARTED_LISTENERS_MSG = 16;
49 private static final int NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG = 17;
50 private static final int NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG = 18;
Yorke Leebd54c2a2016-10-25 13:49:23 -070051
52 // Delay in notifying task stack change listeners (in millis)
Wale Ogunwalef1b2ec92017-06-05 07:09:35 -070053 private static final int NOTIFY_TASK_STACK_CHANGE_LISTENERS_DELAY = 100;
Yorke Leebd54c2a2016-10-25 13:49:23 -070054
55 private final ActivityManagerService mService;
56 private final ActivityStackSupervisor mStackSupervisor;
57 private final Handler mHandler;
58
Yorke Lee13294072017-01-06 14:59:58 -080059 // Task stack change listeners in a remote process.
60 private final RemoteCallbackList<ITaskStackListener> mRemoteTaskStackListeners =
61 new RemoteCallbackList<>();
62
63 /*
64 * Task stack change listeners in a local process. Tracked separately so that they can be
65 * called on the same thread.
66 */
67 private final ArrayList<ITaskStackListener> mLocalTaskStackListeners = new ArrayList<>();
68
69 private final TaskStackConsumer mNotifyTaskStackChanged = (l, m) -> {
70 l.onTaskStackChanged();
71 };
72
73 private final TaskStackConsumer mNotifyTaskCreated = (l, m) -> {
74 l.onTaskCreated(m.arg1, (ComponentName) m.obj);
75 };
76
77 private final TaskStackConsumer mNotifyTaskRemoved = (l, m) -> {
78 l.onTaskRemoved(m.arg1);
79 };
80
81 private final TaskStackConsumer mNotifyTaskMovedToFront = (l, m) -> {
82 l.onTaskMovedToFront(m.arg1);
83 };
84
85 private final TaskStackConsumer mNotifyTaskDescriptionChanged = (l, m) -> {
86 l.onTaskDescriptionChanged(m.arg1, (TaskDescription) m.obj);
87 };
88
89 private final TaskStackConsumer mNotifyActivityRequestedOrientationChanged = (l, m) -> {
90 l.onActivityRequestedOrientationChanged(m.arg1, m.arg2);
91 };
92
93 private final TaskStackConsumer mNotifyTaskRemovalStarted = (l, m) -> {
94 l.onTaskRemovalStarted(m.arg1);
95 };
96
97 private final TaskStackConsumer mNotifyActivityPinned = (l, m) -> {
Winson Chungb5026902017-05-03 12:45:13 -070098 l.onActivityPinned((String) m.obj, m.arg1);
Winson Chungc81c0ce2017-03-17 12:27:30 -070099 };
100
101 private final TaskStackConsumer mNotifyActivityUnpinned = (l, m) -> {
102 l.onActivityUnpinned();
Yorke Lee13294072017-01-06 14:59:58 -0800103 };
104
105 private final TaskStackConsumer mNotifyPinnedActivityRestartAttempt = (l, m) -> {
Winson Chunge6385a22017-05-02 18:15:16 -0700106 l.onPinnedActivityRestartAttempt(m.arg1 != 0);
Yorke Lee13294072017-01-06 14:59:58 -0800107 };
108
Winson Chung85d39982017-02-24 15:21:25 -0800109 private final TaskStackConsumer mNotifyPinnedStackAnimationStarted = (l, m) -> {
110 l.onPinnedStackAnimationStarted();
111 };
112
Yorke Lee13294072017-01-06 14:59:58 -0800113 private final TaskStackConsumer mNotifyPinnedStackAnimationEnded = (l, m) -> {
114 l.onPinnedStackAnimationEnded();
115 };
116
117 private final TaskStackConsumer mNotifyActivityForcedResizable = (l, m) -> {
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700118 l.onActivityForcedResizable((String) m.obj, m.arg1, m.arg2);
Yorke Lee13294072017-01-06 14:59:58 -0800119 };
120
121 private final TaskStackConsumer mNotifyActivityDismissingDockedStack = (l, m) -> {
122 l.onActivityDismissingDockedStack();
123 };
124
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700125 private final TaskStackConsumer mNotifyActivityLaunchOnSecondaryDisplayFailed = (l, m) -> {
126 l.onActivityLaunchOnSecondaryDisplayFailed();
127 };
128
Yorke Lee13294072017-01-06 14:59:58 -0800129 private final TaskStackConsumer mNotifyTaskProfileLocked = (l, m) -> {
130 l.onTaskProfileLocked(m.arg1, m.arg2);
131 };
Yorke Leebd54c2a2016-10-25 13:49:23 -0700132
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100133 private final TaskStackConsumer mNotifyTaskSnapshotChanged = (l, m) -> {
134 l.onTaskSnapshotChanged(m.arg1, (TaskSnapshot) m.obj);
135 };
136
Yorke Leebd54c2a2016-10-25 13:49:23 -0700137 @FunctionalInterface
Yorke Lee13294072017-01-06 14:59:58 -0800138 public interface TaskStackConsumer {
139 void accept(ITaskStackListener t, Message m) throws RemoteException;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700140 }
141
142 private class MainHandler extends Handler {
143 public MainHandler(Looper looper) {
144 super(looper);
145 }
146
147 @Override
148 public void handleMessage(Message msg) {
149 switch (msg.what) {
150 case LOG_STACK_STATE_MSG: {
151 synchronized (mService) {
152 mStackSupervisor.logStackState();
153 }
154 break;
155 }
156 case NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800157 forAllRemoteListeners(mNotifyTaskStackChanged, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700158 break;
159 case NOTIFY_TASK_ADDED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800160 forAllRemoteListeners(mNotifyTaskCreated, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700161 break;
162 case NOTIFY_TASK_REMOVED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800163 forAllRemoteListeners(mNotifyTaskRemoved, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700164 break;
165 case NOTIFY_TASK_MOVED_TO_FRONT_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800166 forAllRemoteListeners(mNotifyTaskMovedToFront, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700167 break;
168 case NOTIFY_TASK_DESCRIPTION_CHANGED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800169 forAllRemoteListeners(mNotifyTaskDescriptionChanged, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700170 break;
171 case NOTIFY_ACTIVITY_REQUESTED_ORIENTATION_CHANGED_LISTENERS:
Yorke Lee13294072017-01-06 14:59:58 -0800172 forAllRemoteListeners(mNotifyActivityRequestedOrientationChanged, msg);
Yorke Lee64fd1ce2017-01-05 17:15:20 -0800173 break;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700174 case NOTIFY_TASK_REMOVAL_STARTED_LISTENERS:
Yorke Lee13294072017-01-06 14:59:58 -0800175 forAllRemoteListeners(mNotifyTaskRemovalStarted, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700176 break;
177 case NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800178 forAllRemoteListeners(mNotifyActivityPinned, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700179 break;
Winson Chungc81c0ce2017-03-17 12:27:30 -0700180 case NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG:
181 forAllRemoteListeners(mNotifyActivityUnpinned, msg);
182 break;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700183 case NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800184 forAllRemoteListeners(mNotifyPinnedActivityRestartAttempt, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700185 break;
Winson Chung85d39982017-02-24 15:21:25 -0800186 case NOTIFY_PINNED_STACK_ANIMATION_STARTED_LISTENERS_MSG:
187 forAllRemoteListeners(mNotifyPinnedStackAnimationStarted, msg);
188 break;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700189 case NOTIFY_PINNED_STACK_ANIMATION_ENDED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800190 forAllRemoteListeners(mNotifyPinnedStackAnimationEnded, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700191 break;
192 case NOTIFY_FORCED_RESIZABLE_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800193 forAllRemoteListeners(mNotifyActivityForcedResizable, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700194 break;
195 case NOTIFY_ACTIVITY_DISMISSING_DOCKED_STACK_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800196 forAllRemoteListeners(mNotifyActivityDismissingDockedStack, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700197 break;
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700198 case NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG:
199 forAllRemoteListeners(mNotifyActivityLaunchOnSecondaryDisplayFailed, msg);
200 break;
Robin Leec41f6ec2017-01-10 17:02:34 +0000201 case NOTIFY_TASK_PROFILE_LOCKED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800202 forAllRemoteListeners(mNotifyTaskProfileLocked, msg);
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100203 break;
204 case NOTIFY_TASK_SNAPSHOT_CHANGED_LISTENERS_MSG:
205 forAllRemoteListeners(mNotifyTaskSnapshotChanged, msg);
Robin Leec41f6ec2017-01-10 17:02:34 +0000206 break;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700207 }
208 }
209 }
210
211 public TaskChangeNotificationController(ActivityManagerService service,
212 ActivityStackSupervisor stackSupervisor, Handler handler) {
213 mService = service;
214 mStackSupervisor = stackSupervisor;
215 mHandler = new MainHandler(handler.getLooper());
216 }
217
218 public void registerTaskStackListener(ITaskStackListener listener) {
219 synchronized (mService) {
220 if (listener != null) {
Yorke Lee13294072017-01-06 14:59:58 -0800221 if (Binder.getCallingPid() == android.os.Process.myPid()) {
222 if (!mLocalTaskStackListeners.contains(listener)) {
223 mLocalTaskStackListeners.add(listener);
224 }
225 } else {
226 mRemoteTaskStackListeners.register(listener);
227 }
Yorke Leebd54c2a2016-10-25 13:49:23 -0700228 }
229 }
230 }
231
232 public void unregisterTaskStackListener(ITaskStackListener listener) {
233 synchronized (mService) {
234 if (listener != null) {
Yorke Lee13294072017-01-06 14:59:58 -0800235 if (Binder.getCallingPid() == android.os.Process.myPid()) {
236 mLocalTaskStackListeners.remove(listener);
237 } else {
238 mRemoteTaskStackListeners.unregister(listener);
239 }
Yorke Leebd54c2a2016-10-25 13:49:23 -0700240 }
241 }
242 }
243
Wale Ogunwalef1b2ec92017-06-05 07:09:35 -0700244 private void forAllRemoteListeners(TaskStackConsumer callback, Message message) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700245 synchronized (mService) {
Yorke Lee13294072017-01-06 14:59:58 -0800246 for (int i = mRemoteTaskStackListeners.beginBroadcast() - 1; i >= 0; i--) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700247 try {
248 // Make a one-way callback to the listener
Yorke Lee13294072017-01-06 14:59:58 -0800249 callback.accept(mRemoteTaskStackListeners.getBroadcastItem(i), message);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700250 } catch (RemoteException e) {
251 // Handled by the RemoteCallbackList.
252 }
253 }
Yorke Lee13294072017-01-06 14:59:58 -0800254 mRemoteTaskStackListeners.finishBroadcast();
255 }
256 }
257
Wale Ogunwalef1b2ec92017-06-05 07:09:35 -0700258 private void forAllLocalListeners(TaskStackConsumer callback, Message message) {
Yorke Lee13294072017-01-06 14:59:58 -0800259 synchronized (mService) {
260 for (int i = mLocalTaskStackListeners.size() - 1; i >= 0; i--) {
261 try {
262 callback.accept(mLocalTaskStackListeners.get(i), message);
263 } catch (RemoteException e) {
264 // Never thrown since this is called locally.
265 }
266 }
267 }
268 }
Yorke Leebd54c2a2016-10-25 13:49:23 -0700269
270 /** Notifies all listeners when the task stack has changed. */
271 void notifyTaskStackChanged() {
272 mHandler.sendEmptyMessage(LOG_STACK_STATE_MSG);
273 mHandler.removeMessages(NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG);
Yorke Lee13294072017-01-06 14:59:58 -0800274 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG);
275 forAllLocalListeners(mNotifyTaskStackChanged, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700276 // Only the main task stack change notification requires a delay.
277 mHandler.sendMessageDelayed(msg, NOTIFY_TASK_STACK_CHANGE_LISTENERS_DELAY);
278 }
279
280 /** Notifies all listeners when an Activity is pinned. */
Winson Chungb5026902017-05-03 12:45:13 -0700281 void notifyActivityPinned(String packageName, int taskId) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700282 mHandler.removeMessages(NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG);
Winson Chungc81c0ce2017-03-17 12:27:30 -0700283 final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG,
Winson Chungb5026902017-05-03 12:45:13 -0700284 taskId, 0, packageName);
Yorke Lee13294072017-01-06 14:59:58 -0800285 forAllLocalListeners(mNotifyActivityPinned, msg);
286 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700287 }
288
Winson Chungc81c0ce2017-03-17 12:27:30 -0700289 /** Notifies all listeners when an Activity is unpinned. */
290 void notifyActivityUnpinned() {
291 mHandler.removeMessages(NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG);
292 final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG);
293 forAllLocalListeners(mNotifyActivityUnpinned, msg);
294 msg.sendToTarget();
295 }
296
Yorke Leebd54c2a2016-10-25 13:49:23 -0700297 /**
298 * Notifies all listeners when an attempt was made to start an an activity that is already
299 * running in the pinned stack and the activity was not actually started, but the task is
300 * either brought to the front or a new Intent is delivered to it.
301 */
Winson Chunge6385a22017-05-02 18:15:16 -0700302 void notifyPinnedActivityRestartAttempt(boolean clearedTask) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700303 mHandler.removeMessages(NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG);
Yorke Lee13294072017-01-06 14:59:58 -0800304 final Message msg =
Winson Chunge6385a22017-05-02 18:15:16 -0700305 mHandler.obtainMessage(NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG,
306 clearedTask ? 1 : 0, 0);
Yorke Lee13294072017-01-06 14:59:58 -0800307 forAllLocalListeners(mNotifyPinnedActivityRestartAttempt, msg);
308 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700309 }
310
Winson Chung85d39982017-02-24 15:21:25 -0800311 /** Notifies all listeners when the pinned stack animation starts. */
312 void notifyPinnedStackAnimationStarted() {
313 mHandler.removeMessages(NOTIFY_PINNED_STACK_ANIMATION_STARTED_LISTENERS_MSG);
314 final Message msg =
315 mHandler.obtainMessage(NOTIFY_PINNED_STACK_ANIMATION_STARTED_LISTENERS_MSG);
316 forAllLocalListeners(mNotifyPinnedStackAnimationStarted, msg);
317 msg.sendToTarget();
318 }
319
Yorke Leebd54c2a2016-10-25 13:49:23 -0700320 /** Notifies all listeners when the pinned stack animation ends. */
321 void notifyPinnedStackAnimationEnded() {
322 mHandler.removeMessages(NOTIFY_PINNED_STACK_ANIMATION_ENDED_LISTENERS_MSG);
Yorke Lee13294072017-01-06 14:59:58 -0800323 final Message msg =
324 mHandler.obtainMessage(NOTIFY_PINNED_STACK_ANIMATION_ENDED_LISTENERS_MSG);
325 forAllLocalListeners(mNotifyPinnedStackAnimationEnded, msg);
326 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700327 }
328
329 void notifyActivityDismissingDockedStack() {
330 mHandler.removeMessages(NOTIFY_ACTIVITY_DISMISSING_DOCKED_STACK_MSG);
Wale Ogunwalef1b2ec92017-06-05 07:09:35 -0700331 final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_DISMISSING_DOCKED_STACK_MSG);
332 forAllLocalListeners(mNotifyActivityDismissingDockedStack, msg);
333 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700334 }
335
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700336 void notifyActivityForcedResizable(int taskId, int reason, String packageName) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700337 mHandler.removeMessages(NOTIFY_FORCED_RESIZABLE_MSG);
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700338 final Message msg = mHandler.obtainMessage(NOTIFY_FORCED_RESIZABLE_MSG, taskId, reason,
339 packageName);
Yorke Lee13294072017-01-06 14:59:58 -0800340 forAllLocalListeners(mNotifyActivityForcedResizable, msg);
341 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700342 }
343
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700344 void notifyActivityLaunchOnSecondaryDisplayFailed() {
345 mHandler.removeMessages(NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG);
346 final Message msg = mHandler.obtainMessage(
347 NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG);
348 forAllLocalListeners(mNotifyActivityLaunchOnSecondaryDisplayFailed, msg);
349 msg.sendToTarget();
350 }
351
Yorke Leebd54c2a2016-10-25 13:49:23 -0700352 void notifyTaskCreated(int taskId, ComponentName componentName) {
Yorke Lee13294072017-01-06 14:59:58 -0800353 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_ADDED_LISTENERS_MSG,
354 taskId, 0 /* unused */, componentName);
355 forAllLocalListeners(mNotifyTaskCreated, msg);
356 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700357 }
358
359 void notifyTaskRemoved(int taskId) {
Yorke Lee13294072017-01-06 14:59:58 -0800360 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_REMOVED_LISTENERS_MSG,
361 taskId, 0 /* unused */);
362 forAllLocalListeners(mNotifyTaskRemoved, msg);
363 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700364 }
365
366 void notifyTaskMovedToFront(int taskId) {
Yorke Lee13294072017-01-06 14:59:58 -0800367 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_MOVED_TO_FRONT_LISTENERS_MSG,
368 taskId, 0 /* unused */);
369 forAllLocalListeners(mNotifyTaskMovedToFront, msg);
370 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700371 }
372
373 void notifyTaskDescriptionChanged(int taskId, TaskDescription taskDescription) {
Yorke Lee13294072017-01-06 14:59:58 -0800374 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_DESCRIPTION_CHANGED_LISTENERS_MSG,
375 taskId, 0 /* unused */, taskDescription);
376 forAllLocalListeners(mNotifyTaskDescriptionChanged, msg);
377 msg.sendToTarget();
378
Yorke Leebd54c2a2016-10-25 13:49:23 -0700379 }
380
381 void notifyActivityRequestedOrientationChanged(int taskId, int orientation) {
Yorke Lee13294072017-01-06 14:59:58 -0800382 final Message msg = mHandler.obtainMessage(
383 NOTIFY_ACTIVITY_REQUESTED_ORIENTATION_CHANGED_LISTENERS, taskId, orientation);
384 forAllLocalListeners(mNotifyActivityRequestedOrientationChanged, msg);
385 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700386 }
387
388 /**
389 * Notify listeners that the task is about to be finished before its surfaces are removed from
390 * the window manager. This allows interested parties to perform relevant animations before
391 * the window disappears.
392 */
393 void notifyTaskRemovalStarted(int taskId) {
Yorke Lee13294072017-01-06 14:59:58 -0800394 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_REMOVAL_STARTED_LISTENERS, taskId,
395 0 /* unused */);
396 forAllLocalListeners(mNotifyTaskRemovalStarted, msg);
397 msg.sendToTarget();
398
Yorke Leebd54c2a2016-10-25 13:49:23 -0700399 }
Robin Leec41f6ec2017-01-10 17:02:34 +0000400
401 /**
402 * Notify listeners that the task has been put in a locked state because one or more of the
403 * activities inside it belong to a managed profile user that has been locked.
404 */
405 void notifyTaskProfileLocked(int taskId, int userId) {
Yorke Lee13294072017-01-06 14:59:58 -0800406 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_PROFILE_LOCKED_LISTENERS_MSG, taskId,
407 userId);
408 forAllLocalListeners(mNotifyTaskProfileLocked, msg);
409 msg.sendToTarget();
Robin Leec41f6ec2017-01-10 17:02:34 +0000410 }
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100411
412 /**
413 * Notify listeners that the snapshot of a task has changed.
414 */
415 void notifyTaskSnapshotChanged(int taskId, TaskSnapshot snapshot) {
416 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_SNAPSHOT_CHANGED_LISTENERS_MSG,
417 taskId, 0, snapshot);
418 forAllLocalListeners(mNotifyTaskSnapshotChanged, msg);
419 msg.sendToTarget();
420 }
Yorke Leebd54c2a2016-10-25 13:49:23 -0700421}