blob: 3d57219209d723f5bf980433e20c0678f01a4f5e [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
Wale Ogunwale59507092018-10-29 09:00:30 -070017package com.android.server.wm;
Yorke Leebd54c2a2016-10-25 13:49:23 -070018
Mark Renoufc808f062019-02-07 15:20:37 -050019import android.app.ActivityManager;
20import android.app.ActivityManager.RunningTaskInfo;
Jorim Jaggifb9d78a2017-01-05 18:57:12 +010021import android.app.ActivityManager.TaskSnapshot;
Yorke Leebd54c2a2016-10-25 13:49:23 -070022import android.app.ITaskStackListener;
Mark Renoufc808f062019-02-07 15:20:37 -050023import android.app.TaskInfo;
Yorke Leebd54c2a2016-10-25 13:49:23 -070024import android.content.ComponentName;
Yorke Lee13294072017-01-06 14:59:58 -080025import android.os.Binder;
Yorke Leebd54c2a2016-10-25 13:49:23 -070026import android.os.Handler;
Riddle Hsu7b766fd2019-01-28 21:14:59 +080027import android.os.IBinder;
Yorke Leebd54c2a2016-10-25 13:49:23 -070028import android.os.Looper;
29import android.os.Message;
30import android.os.RemoteCallbackList;
31import android.os.RemoteException;
32
Yorke Lee13294072017-01-06 14:59:58 -080033import java.util.ArrayList;
34
Yorke Leebd54c2a2016-10-25 13:49:23 -070035class TaskChangeNotificationController {
Wale Ogunwalef1b2ec92017-06-05 07:09:35 -070036 private static final int LOG_STACK_STATE_MSG = 1;
37 private static final int NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG = 2;
38 private static final int NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG = 3;
39 private static final int NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG = 4;
40 private static final int NOTIFY_PINNED_STACK_ANIMATION_ENDED_LISTENERS_MSG = 5;
41 private static final int NOTIFY_FORCED_RESIZABLE_MSG = 6;
42 private static final int NOTIFY_ACTIVITY_DISMISSING_DOCKED_STACK_MSG = 7;
43 private static final int NOTIFY_TASK_ADDED_LISTENERS_MSG = 8;
44 private static final int NOTIFY_TASK_REMOVED_LISTENERS_MSG = 9;
45 private static final int NOTIFY_TASK_MOVED_TO_FRONT_LISTENERS_MSG = 10;
46 private static final int NOTIFY_TASK_DESCRIPTION_CHANGED_LISTENERS_MSG = 11;
47 private static final int NOTIFY_ACTIVITY_REQUESTED_ORIENTATION_CHANGED_LISTENERS = 12;
48 private static final int NOTIFY_TASK_REMOVAL_STARTED_LISTENERS = 13;
49 private static final int NOTIFY_TASK_PROFILE_LOCKED_LISTENERS_MSG = 14;
50 private static final int NOTIFY_TASK_SNAPSHOT_CHANGED_LISTENERS_MSG = 15;
51 private static final int NOTIFY_PINNED_STACK_ANIMATION_STARTED_LISTENERS_MSG = 16;
52 private static final int NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG = 17;
53 private static final int NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG = 18;
Jeff Changbf299862019-02-26 20:07:22 +080054 private static final int NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_REROUTED_MSG = 19;
Riddle Hsu7b766fd2019-01-28 21:14:59 +080055 private static final int NOTIFY_SIZE_COMPAT_MODE_ACTIVITY_CHANGED_MSG = 20;
Yorke Leebd54c2a2016-10-25 13:49:23 -070056
57 // Delay in notifying task stack change listeners (in millis)
Wale Ogunwalef1b2ec92017-06-05 07:09:35 -070058 private static final int NOTIFY_TASK_STACK_CHANGE_LISTENERS_DELAY = 100;
Yorke Leebd54c2a2016-10-25 13:49:23 -070059
Wale Ogunwalec9e57de2018-05-08 14:28:07 -070060 // Global lock used by the service the instantiate objects of this class.
61 private final Object mServiceLock;
Yorke Leebd54c2a2016-10-25 13:49:23 -070062 private final ActivityStackSupervisor mStackSupervisor;
63 private final Handler mHandler;
64
Yorke Lee13294072017-01-06 14:59:58 -080065 // Task stack change listeners in a remote process.
66 private final RemoteCallbackList<ITaskStackListener> mRemoteTaskStackListeners =
67 new RemoteCallbackList<>();
68
69 /*
70 * Task stack change listeners in a local process. Tracked separately so that they can be
71 * called on the same thread.
72 */
73 private final ArrayList<ITaskStackListener> mLocalTaskStackListeners = new ArrayList<>();
74
75 private final TaskStackConsumer mNotifyTaskStackChanged = (l, m) -> {
76 l.onTaskStackChanged();
77 };
78
79 private final TaskStackConsumer mNotifyTaskCreated = (l, m) -> {
80 l.onTaskCreated(m.arg1, (ComponentName) m.obj);
81 };
82
83 private final TaskStackConsumer mNotifyTaskRemoved = (l, m) -> {
84 l.onTaskRemoved(m.arg1);
85 };
86
87 private final TaskStackConsumer mNotifyTaskMovedToFront = (l, m) -> {
Mark Renoufc808f062019-02-07 15:20:37 -050088 l.onTaskMovedToFront((RunningTaskInfo) m.obj);
Yorke Lee13294072017-01-06 14:59:58 -080089 };
90
91 private final TaskStackConsumer mNotifyTaskDescriptionChanged = (l, m) -> {
Mark Renoufc808f062019-02-07 15:20:37 -050092 l.onTaskDescriptionChanged((RunningTaskInfo) m.obj);
Yorke Lee13294072017-01-06 14:59:58 -080093 };
94
95 private final TaskStackConsumer mNotifyActivityRequestedOrientationChanged = (l, m) -> {
96 l.onActivityRequestedOrientationChanged(m.arg1, m.arg2);
97 };
98
99 private final TaskStackConsumer mNotifyTaskRemovalStarted = (l, m) -> {
Mark Renoufc808f062019-02-07 15:20:37 -0500100 l.onTaskRemovalStarted((RunningTaskInfo) m.obj);
Yorke Lee13294072017-01-06 14:59:58 -0800101 };
102
103 private final TaskStackConsumer mNotifyActivityPinned = (l, m) -> {
Wale Ogunwaleb7cf0632017-11-07 13:20:53 -0800104 l.onActivityPinned((String) m.obj /* packageName */, m.sendingUid /* userId */,
105 m.arg1 /* taskId */, m.arg2 /* stackId */);
Winson Chungc81c0ce2017-03-17 12:27:30 -0700106 };
107
108 private final TaskStackConsumer mNotifyActivityUnpinned = (l, m) -> {
109 l.onActivityUnpinned();
Yorke Lee13294072017-01-06 14:59:58 -0800110 };
111
112 private final TaskStackConsumer mNotifyPinnedActivityRestartAttempt = (l, m) -> {
Winson Chunge6385a22017-05-02 18:15:16 -0700113 l.onPinnedActivityRestartAttempt(m.arg1 != 0);
Yorke Lee13294072017-01-06 14:59:58 -0800114 };
115
Winson Chung85d39982017-02-24 15:21:25 -0800116 private final TaskStackConsumer mNotifyPinnedStackAnimationStarted = (l, m) -> {
117 l.onPinnedStackAnimationStarted();
118 };
119
Yorke Lee13294072017-01-06 14:59:58 -0800120 private final TaskStackConsumer mNotifyPinnedStackAnimationEnded = (l, m) -> {
121 l.onPinnedStackAnimationEnded();
122 };
123
124 private final TaskStackConsumer mNotifyActivityForcedResizable = (l, m) -> {
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700125 l.onActivityForcedResizable((String) m.obj, m.arg1, m.arg2);
Yorke Lee13294072017-01-06 14:59:58 -0800126 };
127
128 private final TaskStackConsumer mNotifyActivityDismissingDockedStack = (l, m) -> {
129 l.onActivityDismissingDockedStack();
130 };
131
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700132 private final TaskStackConsumer mNotifyActivityLaunchOnSecondaryDisplayFailed = (l, m) -> {
Mark Renoufc808f062019-02-07 15:20:37 -0500133 l.onActivityLaunchOnSecondaryDisplayFailed((RunningTaskInfo) m.obj, m.arg1);
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700134 };
135
Jeff Changbf299862019-02-26 20:07:22 +0800136 private final TaskStackConsumer mNotifyActivityLaunchOnSecondaryDisplayRerouted = (l, m) -> {
137 l.onActivityLaunchOnSecondaryDisplayRerouted((RunningTaskInfo) m.obj, m.arg1);
138 };
139
Yorke Lee13294072017-01-06 14:59:58 -0800140 private final TaskStackConsumer mNotifyTaskProfileLocked = (l, m) -> {
141 l.onTaskProfileLocked(m.arg1, m.arg2);
142 };
Yorke Leebd54c2a2016-10-25 13:49:23 -0700143
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100144 private final TaskStackConsumer mNotifyTaskSnapshotChanged = (l, m) -> {
145 l.onTaskSnapshotChanged(m.arg1, (TaskSnapshot) m.obj);
146 };
147
Riddle Hsu7b766fd2019-01-28 21:14:59 +0800148 private final TaskStackConsumer mOnSizeCompatModeActivityChanged = (l, m) -> {
149 l.onSizeCompatModeActivityChanged(m.arg1, (IBinder) m.obj);
150 };
151
Yorke Leebd54c2a2016-10-25 13:49:23 -0700152 @FunctionalInterface
Yorke Lee13294072017-01-06 14:59:58 -0800153 public interface TaskStackConsumer {
154 void accept(ITaskStackListener t, Message m) throws RemoteException;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700155 }
156
157 private class MainHandler extends Handler {
158 public MainHandler(Looper looper) {
159 super(looper);
160 }
161
162 @Override
163 public void handleMessage(Message msg) {
164 switch (msg.what) {
165 case LOG_STACK_STATE_MSG: {
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700166 synchronized (mServiceLock) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700167 mStackSupervisor.logStackState();
168 }
169 break;
170 }
171 case NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800172 forAllRemoteListeners(mNotifyTaskStackChanged, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700173 break;
174 case NOTIFY_TASK_ADDED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800175 forAllRemoteListeners(mNotifyTaskCreated, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700176 break;
177 case NOTIFY_TASK_REMOVED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800178 forAllRemoteListeners(mNotifyTaskRemoved, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700179 break;
180 case NOTIFY_TASK_MOVED_TO_FRONT_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800181 forAllRemoteListeners(mNotifyTaskMovedToFront, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700182 break;
183 case NOTIFY_TASK_DESCRIPTION_CHANGED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800184 forAllRemoteListeners(mNotifyTaskDescriptionChanged, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700185 break;
186 case NOTIFY_ACTIVITY_REQUESTED_ORIENTATION_CHANGED_LISTENERS:
Yorke Lee13294072017-01-06 14:59:58 -0800187 forAllRemoteListeners(mNotifyActivityRequestedOrientationChanged, msg);
Yorke Lee64fd1ce2017-01-05 17:15:20 -0800188 break;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700189 case NOTIFY_TASK_REMOVAL_STARTED_LISTENERS:
Yorke Lee13294072017-01-06 14:59:58 -0800190 forAllRemoteListeners(mNotifyTaskRemovalStarted, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700191 break;
192 case NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800193 forAllRemoteListeners(mNotifyActivityPinned, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700194 break;
Winson Chungc81c0ce2017-03-17 12:27:30 -0700195 case NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG:
196 forAllRemoteListeners(mNotifyActivityUnpinned, msg);
197 break;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700198 case NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800199 forAllRemoteListeners(mNotifyPinnedActivityRestartAttempt, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700200 break;
Winson Chung85d39982017-02-24 15:21:25 -0800201 case NOTIFY_PINNED_STACK_ANIMATION_STARTED_LISTENERS_MSG:
202 forAllRemoteListeners(mNotifyPinnedStackAnimationStarted, msg);
203 break;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700204 case NOTIFY_PINNED_STACK_ANIMATION_ENDED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800205 forAllRemoteListeners(mNotifyPinnedStackAnimationEnded, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700206 break;
207 case NOTIFY_FORCED_RESIZABLE_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800208 forAllRemoteListeners(mNotifyActivityForcedResizable, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700209 break;
210 case NOTIFY_ACTIVITY_DISMISSING_DOCKED_STACK_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800211 forAllRemoteListeners(mNotifyActivityDismissingDockedStack, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700212 break;
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700213 case NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG:
214 forAllRemoteListeners(mNotifyActivityLaunchOnSecondaryDisplayFailed, msg);
215 break;
Jeff Changbf299862019-02-26 20:07:22 +0800216 case NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_REROUTED_MSG:
217 forAllRemoteListeners(mNotifyActivityLaunchOnSecondaryDisplayRerouted, msg);
218 break;
Robin Leec41f6ec2017-01-10 17:02:34 +0000219 case NOTIFY_TASK_PROFILE_LOCKED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800220 forAllRemoteListeners(mNotifyTaskProfileLocked, msg);
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100221 break;
222 case NOTIFY_TASK_SNAPSHOT_CHANGED_LISTENERS_MSG:
223 forAllRemoteListeners(mNotifyTaskSnapshotChanged, msg);
Robin Leec41f6ec2017-01-10 17:02:34 +0000224 break;
Riddle Hsu7b766fd2019-01-28 21:14:59 +0800225 case NOTIFY_SIZE_COMPAT_MODE_ACTIVITY_CHANGED_MSG:
226 forAllRemoteListeners(mOnSizeCompatModeActivityChanged, msg);
227 break;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700228 }
229 }
230 }
231
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700232 public TaskChangeNotificationController(Object serviceLock,
Yorke Leebd54c2a2016-10-25 13:49:23 -0700233 ActivityStackSupervisor stackSupervisor, Handler handler) {
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700234 mServiceLock = serviceLock;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700235 mStackSupervisor = stackSupervisor;
236 mHandler = new MainHandler(handler.getLooper());
237 }
238
239 public void registerTaskStackListener(ITaskStackListener listener) {
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700240 synchronized (mServiceLock) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700241 if (listener != null) {
Yorke Lee13294072017-01-06 14:59:58 -0800242 if (Binder.getCallingPid() == android.os.Process.myPid()) {
243 if (!mLocalTaskStackListeners.contains(listener)) {
244 mLocalTaskStackListeners.add(listener);
245 }
246 } else {
247 mRemoteTaskStackListeners.register(listener);
248 }
Yorke Leebd54c2a2016-10-25 13:49:23 -0700249 }
250 }
251 }
252
253 public void unregisterTaskStackListener(ITaskStackListener listener) {
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700254 synchronized (mServiceLock) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700255 if (listener != null) {
Yorke Lee13294072017-01-06 14:59:58 -0800256 if (Binder.getCallingPid() == android.os.Process.myPid()) {
257 mLocalTaskStackListeners.remove(listener);
258 } else {
259 mRemoteTaskStackListeners.unregister(listener);
260 }
Yorke Leebd54c2a2016-10-25 13:49:23 -0700261 }
262 }
263 }
264
Wale Ogunwalef1b2ec92017-06-05 07:09:35 -0700265 private void forAllRemoteListeners(TaskStackConsumer callback, Message message) {
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700266 synchronized (mServiceLock) {
Yorke Lee13294072017-01-06 14:59:58 -0800267 for (int i = mRemoteTaskStackListeners.beginBroadcast() - 1; i >= 0; i--) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700268 try {
269 // Make a one-way callback to the listener
Yorke Lee13294072017-01-06 14:59:58 -0800270 callback.accept(mRemoteTaskStackListeners.getBroadcastItem(i), message);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700271 } catch (RemoteException e) {
272 // Handled by the RemoteCallbackList.
273 }
274 }
Yorke Lee13294072017-01-06 14:59:58 -0800275 mRemoteTaskStackListeners.finishBroadcast();
276 }
277 }
278
Wale Ogunwalef1b2ec92017-06-05 07:09:35 -0700279 private void forAllLocalListeners(TaskStackConsumer callback, Message message) {
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700280 synchronized (mServiceLock) {
Yorke Lee13294072017-01-06 14:59:58 -0800281 for (int i = mLocalTaskStackListeners.size() - 1; i >= 0; i--) {
282 try {
283 callback.accept(mLocalTaskStackListeners.get(i), message);
284 } catch (RemoteException e) {
285 // Never thrown since this is called locally.
286 }
287 }
288 }
289 }
Yorke Leebd54c2a2016-10-25 13:49:23 -0700290
291 /** Notifies all listeners when the task stack has changed. */
292 void notifyTaskStackChanged() {
293 mHandler.sendEmptyMessage(LOG_STACK_STATE_MSG);
294 mHandler.removeMessages(NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG);
Yorke Lee13294072017-01-06 14:59:58 -0800295 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG);
296 forAllLocalListeners(mNotifyTaskStackChanged, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700297 // Only the main task stack change notification requires a delay.
298 mHandler.sendMessageDelayed(msg, NOTIFY_TASK_STACK_CHANGE_LISTENERS_DELAY);
299 }
300
301 /** Notifies all listeners when an Activity is pinned. */
Wale Ogunwale89be5762017-10-04 13:27:49 -0700302 void notifyActivityPinned(ActivityRecord r) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700303 mHandler.removeMessages(NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG);
Wale Ogunwaleb7cf0632017-11-07 13:20:53 -0800304 final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG,
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800305 r.getTaskRecord().taskId, r.getStackId(), r.packageName);
306 msg.sendingUid = r.mUserId;
Yorke Lee13294072017-01-06 14:59:58 -0800307 forAllLocalListeners(mNotifyActivityPinned, msg);
308 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700309 }
310
Winson Chungc81c0ce2017-03-17 12:27:30 -0700311 /** Notifies all listeners when an Activity is unpinned. */
312 void notifyActivityUnpinned() {
313 mHandler.removeMessages(NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG);
314 final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG);
315 forAllLocalListeners(mNotifyActivityUnpinned, msg);
316 msg.sendToTarget();
317 }
318
Yorke Leebd54c2a2016-10-25 13:49:23 -0700319 /**
320 * Notifies all listeners when an attempt was made to start an an activity that is already
321 * running in the pinned stack and the activity was not actually started, but the task is
322 * either brought to the front or a new Intent is delivered to it.
323 */
Winson Chunge6385a22017-05-02 18:15:16 -0700324 void notifyPinnedActivityRestartAttempt(boolean clearedTask) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700325 mHandler.removeMessages(NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG);
Yorke Lee13294072017-01-06 14:59:58 -0800326 final Message msg =
Winson Chunge6385a22017-05-02 18:15:16 -0700327 mHandler.obtainMessage(NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG,
328 clearedTask ? 1 : 0, 0);
Yorke Lee13294072017-01-06 14:59:58 -0800329 forAllLocalListeners(mNotifyPinnedActivityRestartAttempt, msg);
330 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700331 }
332
Winson Chung85d39982017-02-24 15:21:25 -0800333 /** Notifies all listeners when the pinned stack animation starts. */
334 void notifyPinnedStackAnimationStarted() {
335 mHandler.removeMessages(NOTIFY_PINNED_STACK_ANIMATION_STARTED_LISTENERS_MSG);
336 final Message msg =
337 mHandler.obtainMessage(NOTIFY_PINNED_STACK_ANIMATION_STARTED_LISTENERS_MSG);
338 forAllLocalListeners(mNotifyPinnedStackAnimationStarted, msg);
339 msg.sendToTarget();
340 }
341
Yorke Leebd54c2a2016-10-25 13:49:23 -0700342 /** Notifies all listeners when the pinned stack animation ends. */
343 void notifyPinnedStackAnimationEnded() {
344 mHandler.removeMessages(NOTIFY_PINNED_STACK_ANIMATION_ENDED_LISTENERS_MSG);
Yorke Lee13294072017-01-06 14:59:58 -0800345 final Message msg =
346 mHandler.obtainMessage(NOTIFY_PINNED_STACK_ANIMATION_ENDED_LISTENERS_MSG);
347 forAllLocalListeners(mNotifyPinnedStackAnimationEnded, msg);
348 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700349 }
350
351 void notifyActivityDismissingDockedStack() {
352 mHandler.removeMessages(NOTIFY_ACTIVITY_DISMISSING_DOCKED_STACK_MSG);
Wale Ogunwalef1b2ec92017-06-05 07:09:35 -0700353 final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_DISMISSING_DOCKED_STACK_MSG);
354 forAllLocalListeners(mNotifyActivityDismissingDockedStack, msg);
355 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700356 }
357
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700358 void notifyActivityForcedResizable(int taskId, int reason, String packageName) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700359 mHandler.removeMessages(NOTIFY_FORCED_RESIZABLE_MSG);
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700360 final Message msg = mHandler.obtainMessage(NOTIFY_FORCED_RESIZABLE_MSG, taskId, reason,
361 packageName);
Yorke Lee13294072017-01-06 14:59:58 -0800362 forAllLocalListeners(mNotifyActivityForcedResizable, msg);
363 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700364 }
365
Mark Renoufc808f062019-02-07 15:20:37 -0500366 void notifyActivityLaunchOnSecondaryDisplayFailed(TaskInfo ti, int requestedDisplayId) {
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700367 mHandler.removeMessages(NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG);
368 final Message msg = mHandler.obtainMessage(
Mark Renoufc808f062019-02-07 15:20:37 -0500369 NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG, requestedDisplayId,
370 0 /* unused */, ti);
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700371 forAllLocalListeners(mNotifyActivityLaunchOnSecondaryDisplayFailed, msg);
372 msg.sendToTarget();
373 }
374
Jeff Changbf299862019-02-26 20:07:22 +0800375 void notifyActivityLaunchOnSecondaryDisplayRerouted(TaskInfo ti, int requestedDisplayId) {
376 mHandler.removeMessages(NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_REROUTED_MSG);
377 final Message msg = mHandler.obtainMessage(
378 NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_REROUTED_MSG, requestedDisplayId,
379 0 /* unused */, ti);
380 forAllLocalListeners(mNotifyActivityLaunchOnSecondaryDisplayRerouted, msg);
381 msg.sendToTarget();
382 }
383
Yorke Leebd54c2a2016-10-25 13:49:23 -0700384 void notifyTaskCreated(int taskId, ComponentName componentName) {
Yorke Lee13294072017-01-06 14:59:58 -0800385 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_ADDED_LISTENERS_MSG,
386 taskId, 0 /* unused */, componentName);
387 forAllLocalListeners(mNotifyTaskCreated, msg);
388 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700389 }
390
391 void notifyTaskRemoved(int taskId) {
Yorke Lee13294072017-01-06 14:59:58 -0800392 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_REMOVED_LISTENERS_MSG,
393 taskId, 0 /* unused */);
394 forAllLocalListeners(mNotifyTaskRemoved, msg);
395 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700396 }
397
Mark Renoufc808f062019-02-07 15:20:37 -0500398 void notifyTaskMovedToFront(TaskInfo ti) {
399 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_MOVED_TO_FRONT_LISTENERS_MSG, ti);
Yorke Lee13294072017-01-06 14:59:58 -0800400 forAllLocalListeners(mNotifyTaskMovedToFront, msg);
401 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700402 }
403
Mark Renoufc808f062019-02-07 15:20:37 -0500404 void notifyTaskDescriptionChanged(TaskInfo taskInfo) {
Yorke Lee13294072017-01-06 14:59:58 -0800405 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_DESCRIPTION_CHANGED_LISTENERS_MSG,
Mark Renoufc808f062019-02-07 15:20:37 -0500406 taskInfo);
Yorke Lee13294072017-01-06 14:59:58 -0800407 forAllLocalListeners(mNotifyTaskDescriptionChanged, msg);
408 msg.sendToTarget();
409
Yorke Leebd54c2a2016-10-25 13:49:23 -0700410 }
411
412 void notifyActivityRequestedOrientationChanged(int taskId, int orientation) {
Yorke Lee13294072017-01-06 14:59:58 -0800413 final Message msg = mHandler.obtainMessage(
414 NOTIFY_ACTIVITY_REQUESTED_ORIENTATION_CHANGED_LISTENERS, taskId, orientation);
415 forAllLocalListeners(mNotifyActivityRequestedOrientationChanged, msg);
416 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700417 }
418
419 /**
420 * Notify listeners that the task is about to be finished before its surfaces are removed from
421 * the window manager. This allows interested parties to perform relevant animations before
422 * the window disappears.
423 */
Mark Renoufc808f062019-02-07 15:20:37 -0500424 void notifyTaskRemovalStarted(ActivityManager.RunningTaskInfo taskInfo) {
425 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_REMOVAL_STARTED_LISTENERS, taskInfo);
Yorke Lee13294072017-01-06 14:59:58 -0800426 forAllLocalListeners(mNotifyTaskRemovalStarted, msg);
427 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700428 }
Robin Leec41f6ec2017-01-10 17:02:34 +0000429
430 /**
431 * Notify listeners that the task has been put in a locked state because one or more of the
432 * activities inside it belong to a managed profile user that has been locked.
433 */
434 void notifyTaskProfileLocked(int taskId, int userId) {
Yorke Lee13294072017-01-06 14:59:58 -0800435 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_PROFILE_LOCKED_LISTENERS_MSG, taskId,
436 userId);
437 forAllLocalListeners(mNotifyTaskProfileLocked, msg);
438 msg.sendToTarget();
Robin Leec41f6ec2017-01-10 17:02:34 +0000439 }
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100440
441 /**
442 * Notify listeners that the snapshot of a task has changed.
443 */
444 void notifyTaskSnapshotChanged(int taskId, TaskSnapshot snapshot) {
445 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_SNAPSHOT_CHANGED_LISTENERS_MSG,
446 taskId, 0, snapshot);
447 forAllLocalListeners(mNotifyTaskSnapshotChanged, msg);
448 msg.sendToTarget();
449 }
Riddle Hsu7b766fd2019-01-28 21:14:59 +0800450
451 /**
452 * Notify listeners that whether a size compatibility mode activity is using the override
453 * bounds which is not fit its parent.
454 */
455 void notifySizeCompatModeActivityChanged(int displayId, IBinder activityToken) {
456 final Message msg = mHandler.obtainMessage(NOTIFY_SIZE_COMPAT_MODE_ACTIVITY_CHANGED_MSG,
457 displayId, 0 /* unused */, activityToken);
458 forAllLocalListeners(mOnSizeCompatModeActivityChanged, msg);
459 msg.sendToTarget();
460 }
Yorke Leebd54c2a2016-10-25 13:49:23 -0700461}