blob: 789f987e3d4610be11333f35501f2fa244d9412d [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;
27import android.os.Looper;
28import android.os.Message;
29import android.os.RemoteCallbackList;
30import android.os.RemoteException;
31
Yorke Lee13294072017-01-06 14:59:58 -080032import java.util.ArrayList;
33
Yorke Leebd54c2a2016-10-25 13:49:23 -070034class TaskChangeNotificationController {
Wale Ogunwalef1b2ec92017-06-05 07:09:35 -070035 private static final int LOG_STACK_STATE_MSG = 1;
36 private static final int NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG = 2;
37 private static final int NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG = 3;
38 private static final int NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG = 4;
39 private static final int NOTIFY_PINNED_STACK_ANIMATION_ENDED_LISTENERS_MSG = 5;
40 private static final int NOTIFY_FORCED_RESIZABLE_MSG = 6;
41 private static final int NOTIFY_ACTIVITY_DISMISSING_DOCKED_STACK_MSG = 7;
42 private static final int NOTIFY_TASK_ADDED_LISTENERS_MSG = 8;
43 private static final int NOTIFY_TASK_REMOVED_LISTENERS_MSG = 9;
44 private static final int NOTIFY_TASK_MOVED_TO_FRONT_LISTENERS_MSG = 10;
45 private static final int NOTIFY_TASK_DESCRIPTION_CHANGED_LISTENERS_MSG = 11;
46 private static final int NOTIFY_ACTIVITY_REQUESTED_ORIENTATION_CHANGED_LISTENERS = 12;
47 private static final int NOTIFY_TASK_REMOVAL_STARTED_LISTENERS = 13;
48 private static final int NOTIFY_TASK_PROFILE_LOCKED_LISTENERS_MSG = 14;
49 private static final int NOTIFY_TASK_SNAPSHOT_CHANGED_LISTENERS_MSG = 15;
50 private static final int NOTIFY_PINNED_STACK_ANIMATION_STARTED_LISTENERS_MSG = 16;
51 private static final int NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG = 17;
52 private static final int NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG = 18;
Yorke Leebd54c2a2016-10-25 13:49:23 -070053
54 // Delay in notifying task stack change listeners (in millis)
Wale Ogunwalef1b2ec92017-06-05 07:09:35 -070055 private static final int NOTIFY_TASK_STACK_CHANGE_LISTENERS_DELAY = 100;
Yorke Leebd54c2a2016-10-25 13:49:23 -070056
Wale Ogunwalec9e57de2018-05-08 14:28:07 -070057 // Global lock used by the service the instantiate objects of this class.
58 private final Object mServiceLock;
Yorke Leebd54c2a2016-10-25 13:49:23 -070059 private final ActivityStackSupervisor mStackSupervisor;
60 private final Handler mHandler;
61
Yorke Lee13294072017-01-06 14:59:58 -080062 // Task stack change listeners in a remote process.
63 private final RemoteCallbackList<ITaskStackListener> mRemoteTaskStackListeners =
64 new RemoteCallbackList<>();
65
66 /*
67 * Task stack change listeners in a local process. Tracked separately so that they can be
68 * called on the same thread.
69 */
70 private final ArrayList<ITaskStackListener> mLocalTaskStackListeners = new ArrayList<>();
71
72 private final TaskStackConsumer mNotifyTaskStackChanged = (l, m) -> {
73 l.onTaskStackChanged();
74 };
75
76 private final TaskStackConsumer mNotifyTaskCreated = (l, m) -> {
77 l.onTaskCreated(m.arg1, (ComponentName) m.obj);
78 };
79
80 private final TaskStackConsumer mNotifyTaskRemoved = (l, m) -> {
81 l.onTaskRemoved(m.arg1);
82 };
83
84 private final TaskStackConsumer mNotifyTaskMovedToFront = (l, m) -> {
Mark Renoufc808f062019-02-07 15:20:37 -050085 l.onTaskMovedToFront((RunningTaskInfo) m.obj);
Yorke Lee13294072017-01-06 14:59:58 -080086 };
87
88 private final TaskStackConsumer mNotifyTaskDescriptionChanged = (l, m) -> {
Mark Renoufc808f062019-02-07 15:20:37 -050089 l.onTaskDescriptionChanged((RunningTaskInfo) m.obj);
Yorke Lee13294072017-01-06 14:59:58 -080090 };
91
92 private final TaskStackConsumer mNotifyActivityRequestedOrientationChanged = (l, m) -> {
93 l.onActivityRequestedOrientationChanged(m.arg1, m.arg2);
94 };
95
96 private final TaskStackConsumer mNotifyTaskRemovalStarted = (l, m) -> {
Mark Renoufc808f062019-02-07 15:20:37 -050097 l.onTaskRemovalStarted((RunningTaskInfo) m.obj);
Yorke Lee13294072017-01-06 14:59:58 -080098 };
99
100 private final TaskStackConsumer mNotifyActivityPinned = (l, m) -> {
Wale Ogunwaleb7cf0632017-11-07 13:20:53 -0800101 l.onActivityPinned((String) m.obj /* packageName */, m.sendingUid /* userId */,
102 m.arg1 /* taskId */, m.arg2 /* stackId */);
Winson Chungc81c0ce2017-03-17 12:27:30 -0700103 };
104
105 private final TaskStackConsumer mNotifyActivityUnpinned = (l, m) -> {
106 l.onActivityUnpinned();
Yorke Lee13294072017-01-06 14:59:58 -0800107 };
108
109 private final TaskStackConsumer mNotifyPinnedActivityRestartAttempt = (l, m) -> {
Winson Chunge6385a22017-05-02 18:15:16 -0700110 l.onPinnedActivityRestartAttempt(m.arg1 != 0);
Yorke Lee13294072017-01-06 14:59:58 -0800111 };
112
Winson Chung85d39982017-02-24 15:21:25 -0800113 private final TaskStackConsumer mNotifyPinnedStackAnimationStarted = (l, m) -> {
114 l.onPinnedStackAnimationStarted();
115 };
116
Yorke Lee13294072017-01-06 14:59:58 -0800117 private final TaskStackConsumer mNotifyPinnedStackAnimationEnded = (l, m) -> {
118 l.onPinnedStackAnimationEnded();
119 };
120
121 private final TaskStackConsumer mNotifyActivityForcedResizable = (l, m) -> {
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700122 l.onActivityForcedResizable((String) m.obj, m.arg1, m.arg2);
Yorke Lee13294072017-01-06 14:59:58 -0800123 };
124
125 private final TaskStackConsumer mNotifyActivityDismissingDockedStack = (l, m) -> {
126 l.onActivityDismissingDockedStack();
127 };
128
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700129 private final TaskStackConsumer mNotifyActivityLaunchOnSecondaryDisplayFailed = (l, m) -> {
Mark Renoufc808f062019-02-07 15:20:37 -0500130 l.onActivityLaunchOnSecondaryDisplayFailed((RunningTaskInfo) m.obj, m.arg1);
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700131 };
132
Yorke Lee13294072017-01-06 14:59:58 -0800133 private final TaskStackConsumer mNotifyTaskProfileLocked = (l, m) -> {
134 l.onTaskProfileLocked(m.arg1, m.arg2);
135 };
Yorke Leebd54c2a2016-10-25 13:49:23 -0700136
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100137 private final TaskStackConsumer mNotifyTaskSnapshotChanged = (l, m) -> {
138 l.onTaskSnapshotChanged(m.arg1, (TaskSnapshot) m.obj);
139 };
140
Yorke Leebd54c2a2016-10-25 13:49:23 -0700141 @FunctionalInterface
Yorke Lee13294072017-01-06 14:59:58 -0800142 public interface TaskStackConsumer {
143 void accept(ITaskStackListener t, Message m) throws RemoteException;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700144 }
145
146 private class MainHandler extends Handler {
147 public MainHandler(Looper looper) {
148 super(looper);
149 }
150
151 @Override
152 public void handleMessage(Message msg) {
153 switch (msg.what) {
154 case LOG_STACK_STATE_MSG: {
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700155 synchronized (mServiceLock) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700156 mStackSupervisor.logStackState();
157 }
158 break;
159 }
160 case NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800161 forAllRemoteListeners(mNotifyTaskStackChanged, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700162 break;
163 case NOTIFY_TASK_ADDED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800164 forAllRemoteListeners(mNotifyTaskCreated, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700165 break;
166 case NOTIFY_TASK_REMOVED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800167 forAllRemoteListeners(mNotifyTaskRemoved, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700168 break;
169 case NOTIFY_TASK_MOVED_TO_FRONT_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800170 forAllRemoteListeners(mNotifyTaskMovedToFront, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700171 break;
172 case NOTIFY_TASK_DESCRIPTION_CHANGED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800173 forAllRemoteListeners(mNotifyTaskDescriptionChanged, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700174 break;
175 case NOTIFY_ACTIVITY_REQUESTED_ORIENTATION_CHANGED_LISTENERS:
Yorke Lee13294072017-01-06 14:59:58 -0800176 forAllRemoteListeners(mNotifyActivityRequestedOrientationChanged, msg);
Yorke Lee64fd1ce2017-01-05 17:15:20 -0800177 break;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700178 case NOTIFY_TASK_REMOVAL_STARTED_LISTENERS:
Yorke Lee13294072017-01-06 14:59:58 -0800179 forAllRemoteListeners(mNotifyTaskRemovalStarted, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700180 break;
181 case NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800182 forAllRemoteListeners(mNotifyActivityPinned, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700183 break;
Winson Chungc81c0ce2017-03-17 12:27:30 -0700184 case NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG:
185 forAllRemoteListeners(mNotifyActivityUnpinned, msg);
186 break;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700187 case NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800188 forAllRemoteListeners(mNotifyPinnedActivityRestartAttempt, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700189 break;
Winson Chung85d39982017-02-24 15:21:25 -0800190 case NOTIFY_PINNED_STACK_ANIMATION_STARTED_LISTENERS_MSG:
191 forAllRemoteListeners(mNotifyPinnedStackAnimationStarted, msg);
192 break;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700193 case NOTIFY_PINNED_STACK_ANIMATION_ENDED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800194 forAllRemoteListeners(mNotifyPinnedStackAnimationEnded, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700195 break;
196 case NOTIFY_FORCED_RESIZABLE_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800197 forAllRemoteListeners(mNotifyActivityForcedResizable, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700198 break;
199 case NOTIFY_ACTIVITY_DISMISSING_DOCKED_STACK_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800200 forAllRemoteListeners(mNotifyActivityDismissingDockedStack, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700201 break;
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700202 case NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG:
203 forAllRemoteListeners(mNotifyActivityLaunchOnSecondaryDisplayFailed, msg);
204 break;
Robin Leec41f6ec2017-01-10 17:02:34 +0000205 case NOTIFY_TASK_PROFILE_LOCKED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800206 forAllRemoteListeners(mNotifyTaskProfileLocked, msg);
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100207 break;
208 case NOTIFY_TASK_SNAPSHOT_CHANGED_LISTENERS_MSG:
209 forAllRemoteListeners(mNotifyTaskSnapshotChanged, msg);
Robin Leec41f6ec2017-01-10 17:02:34 +0000210 break;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700211 }
212 }
213 }
214
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700215 public TaskChangeNotificationController(Object serviceLock,
Yorke Leebd54c2a2016-10-25 13:49:23 -0700216 ActivityStackSupervisor stackSupervisor, Handler handler) {
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700217 mServiceLock = serviceLock;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700218 mStackSupervisor = stackSupervisor;
219 mHandler = new MainHandler(handler.getLooper());
220 }
221
222 public void registerTaskStackListener(ITaskStackListener listener) {
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700223 synchronized (mServiceLock) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700224 if (listener != null) {
Yorke Lee13294072017-01-06 14:59:58 -0800225 if (Binder.getCallingPid() == android.os.Process.myPid()) {
226 if (!mLocalTaskStackListeners.contains(listener)) {
227 mLocalTaskStackListeners.add(listener);
228 }
229 } else {
230 mRemoteTaskStackListeners.register(listener);
231 }
Yorke Leebd54c2a2016-10-25 13:49:23 -0700232 }
233 }
234 }
235
236 public void unregisterTaskStackListener(ITaskStackListener listener) {
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700237 synchronized (mServiceLock) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700238 if (listener != null) {
Yorke Lee13294072017-01-06 14:59:58 -0800239 if (Binder.getCallingPid() == android.os.Process.myPid()) {
240 mLocalTaskStackListeners.remove(listener);
241 } else {
242 mRemoteTaskStackListeners.unregister(listener);
243 }
Yorke Leebd54c2a2016-10-25 13:49:23 -0700244 }
245 }
246 }
247
Wale Ogunwalef1b2ec92017-06-05 07:09:35 -0700248 private void forAllRemoteListeners(TaskStackConsumer callback, Message message) {
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700249 synchronized (mServiceLock) {
Yorke Lee13294072017-01-06 14:59:58 -0800250 for (int i = mRemoteTaskStackListeners.beginBroadcast() - 1; i >= 0; i--) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700251 try {
252 // Make a one-way callback to the listener
Yorke Lee13294072017-01-06 14:59:58 -0800253 callback.accept(mRemoteTaskStackListeners.getBroadcastItem(i), message);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700254 } catch (RemoteException e) {
255 // Handled by the RemoteCallbackList.
256 }
257 }
Yorke Lee13294072017-01-06 14:59:58 -0800258 mRemoteTaskStackListeners.finishBroadcast();
259 }
260 }
261
Wale Ogunwalef1b2ec92017-06-05 07:09:35 -0700262 private void forAllLocalListeners(TaskStackConsumer callback, Message message) {
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700263 synchronized (mServiceLock) {
Yorke Lee13294072017-01-06 14:59:58 -0800264 for (int i = mLocalTaskStackListeners.size() - 1; i >= 0; i--) {
265 try {
266 callback.accept(mLocalTaskStackListeners.get(i), message);
267 } catch (RemoteException e) {
268 // Never thrown since this is called locally.
269 }
270 }
271 }
272 }
Yorke Leebd54c2a2016-10-25 13:49:23 -0700273
274 /** Notifies all listeners when the task stack has changed. */
275 void notifyTaskStackChanged() {
276 mHandler.sendEmptyMessage(LOG_STACK_STATE_MSG);
277 mHandler.removeMessages(NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG);
Yorke Lee13294072017-01-06 14:59:58 -0800278 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG);
279 forAllLocalListeners(mNotifyTaskStackChanged, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700280 // Only the main task stack change notification requires a delay.
281 mHandler.sendMessageDelayed(msg, NOTIFY_TASK_STACK_CHANGE_LISTENERS_DELAY);
282 }
283
284 /** Notifies all listeners when an Activity is pinned. */
Wale Ogunwale89be5762017-10-04 13:27:49 -0700285 void notifyActivityPinned(ActivityRecord r) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700286 mHandler.removeMessages(NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG);
Wale Ogunwaleb7cf0632017-11-07 13:20:53 -0800287 final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG,
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800288 r.getTaskRecord().taskId, r.getStackId(), r.packageName);
289 msg.sendingUid = r.mUserId;
Yorke Lee13294072017-01-06 14:59:58 -0800290 forAllLocalListeners(mNotifyActivityPinned, msg);
291 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700292 }
293
Winson Chungc81c0ce2017-03-17 12:27:30 -0700294 /** Notifies all listeners when an Activity is unpinned. */
295 void notifyActivityUnpinned() {
296 mHandler.removeMessages(NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG);
297 final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG);
298 forAllLocalListeners(mNotifyActivityUnpinned, msg);
299 msg.sendToTarget();
300 }
301
Yorke Leebd54c2a2016-10-25 13:49:23 -0700302 /**
303 * Notifies all listeners when an attempt was made to start an an activity that is already
304 * running in the pinned stack and the activity was not actually started, but the task is
305 * either brought to the front or a new Intent is delivered to it.
306 */
Winson Chunge6385a22017-05-02 18:15:16 -0700307 void notifyPinnedActivityRestartAttempt(boolean clearedTask) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700308 mHandler.removeMessages(NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG);
Yorke Lee13294072017-01-06 14:59:58 -0800309 final Message msg =
Winson Chunge6385a22017-05-02 18:15:16 -0700310 mHandler.obtainMessage(NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG,
311 clearedTask ? 1 : 0, 0);
Yorke Lee13294072017-01-06 14:59:58 -0800312 forAllLocalListeners(mNotifyPinnedActivityRestartAttempt, msg);
313 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700314 }
315
Winson Chung85d39982017-02-24 15:21:25 -0800316 /** Notifies all listeners when the pinned stack animation starts. */
317 void notifyPinnedStackAnimationStarted() {
318 mHandler.removeMessages(NOTIFY_PINNED_STACK_ANIMATION_STARTED_LISTENERS_MSG);
319 final Message msg =
320 mHandler.obtainMessage(NOTIFY_PINNED_STACK_ANIMATION_STARTED_LISTENERS_MSG);
321 forAllLocalListeners(mNotifyPinnedStackAnimationStarted, msg);
322 msg.sendToTarget();
323 }
324
Yorke Leebd54c2a2016-10-25 13:49:23 -0700325 /** Notifies all listeners when the pinned stack animation ends. */
326 void notifyPinnedStackAnimationEnded() {
327 mHandler.removeMessages(NOTIFY_PINNED_STACK_ANIMATION_ENDED_LISTENERS_MSG);
Yorke Lee13294072017-01-06 14:59:58 -0800328 final Message msg =
329 mHandler.obtainMessage(NOTIFY_PINNED_STACK_ANIMATION_ENDED_LISTENERS_MSG);
330 forAllLocalListeners(mNotifyPinnedStackAnimationEnded, msg);
331 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700332 }
333
334 void notifyActivityDismissingDockedStack() {
335 mHandler.removeMessages(NOTIFY_ACTIVITY_DISMISSING_DOCKED_STACK_MSG);
Wale Ogunwalef1b2ec92017-06-05 07:09:35 -0700336 final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_DISMISSING_DOCKED_STACK_MSG);
337 forAllLocalListeners(mNotifyActivityDismissingDockedStack, msg);
338 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700339 }
340
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700341 void notifyActivityForcedResizable(int taskId, int reason, String packageName) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700342 mHandler.removeMessages(NOTIFY_FORCED_RESIZABLE_MSG);
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700343 final Message msg = mHandler.obtainMessage(NOTIFY_FORCED_RESIZABLE_MSG, taskId, reason,
344 packageName);
Yorke Lee13294072017-01-06 14:59:58 -0800345 forAllLocalListeners(mNotifyActivityForcedResizable, msg);
346 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700347 }
348
Mark Renoufc808f062019-02-07 15:20:37 -0500349 void notifyActivityLaunchOnSecondaryDisplayFailed(TaskInfo ti, int requestedDisplayId) {
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700350 mHandler.removeMessages(NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG);
351 final Message msg = mHandler.obtainMessage(
Mark Renoufc808f062019-02-07 15:20:37 -0500352 NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG, requestedDisplayId,
353 0 /* unused */, ti);
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700354 forAllLocalListeners(mNotifyActivityLaunchOnSecondaryDisplayFailed, msg);
355 msg.sendToTarget();
356 }
357
Yorke Leebd54c2a2016-10-25 13:49:23 -0700358 void notifyTaskCreated(int taskId, ComponentName componentName) {
Yorke Lee13294072017-01-06 14:59:58 -0800359 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_ADDED_LISTENERS_MSG,
360 taskId, 0 /* unused */, componentName);
361 forAllLocalListeners(mNotifyTaskCreated, msg);
362 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700363 }
364
365 void notifyTaskRemoved(int taskId) {
Yorke Lee13294072017-01-06 14:59:58 -0800366 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_REMOVED_LISTENERS_MSG,
367 taskId, 0 /* unused */);
368 forAllLocalListeners(mNotifyTaskRemoved, msg);
369 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700370 }
371
Mark Renoufc808f062019-02-07 15:20:37 -0500372 void notifyTaskMovedToFront(TaskInfo ti) {
373 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_MOVED_TO_FRONT_LISTENERS_MSG, ti);
Yorke Lee13294072017-01-06 14:59:58 -0800374 forAllLocalListeners(mNotifyTaskMovedToFront, msg);
375 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700376 }
377
Mark Renoufc808f062019-02-07 15:20:37 -0500378 void notifyTaskDescriptionChanged(TaskInfo taskInfo) {
Yorke Lee13294072017-01-06 14:59:58 -0800379 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_DESCRIPTION_CHANGED_LISTENERS_MSG,
Mark Renoufc808f062019-02-07 15:20:37 -0500380 taskInfo);
Yorke Lee13294072017-01-06 14:59:58 -0800381 forAllLocalListeners(mNotifyTaskDescriptionChanged, msg);
382 msg.sendToTarget();
383
Yorke Leebd54c2a2016-10-25 13:49:23 -0700384 }
385
386 void notifyActivityRequestedOrientationChanged(int taskId, int orientation) {
Yorke Lee13294072017-01-06 14:59:58 -0800387 final Message msg = mHandler.obtainMessage(
388 NOTIFY_ACTIVITY_REQUESTED_ORIENTATION_CHANGED_LISTENERS, taskId, orientation);
389 forAllLocalListeners(mNotifyActivityRequestedOrientationChanged, msg);
390 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700391 }
392
393 /**
394 * Notify listeners that the task is about to be finished before its surfaces are removed from
395 * the window manager. This allows interested parties to perform relevant animations before
396 * the window disappears.
397 */
Mark Renoufc808f062019-02-07 15:20:37 -0500398 void notifyTaskRemovalStarted(ActivityManager.RunningTaskInfo taskInfo) {
399 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_REMOVAL_STARTED_LISTENERS, taskInfo);
Yorke Lee13294072017-01-06 14:59:58 -0800400 forAllLocalListeners(mNotifyTaskRemovalStarted, msg);
401 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700402 }
Robin Leec41f6ec2017-01-10 17:02:34 +0000403
404 /**
405 * Notify listeners that the task has been put in a locked state because one or more of the
406 * activities inside it belong to a managed profile user that has been locked.
407 */
408 void notifyTaskProfileLocked(int taskId, int userId) {
Yorke Lee13294072017-01-06 14:59:58 -0800409 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_PROFILE_LOCKED_LISTENERS_MSG, taskId,
410 userId);
411 forAllLocalListeners(mNotifyTaskProfileLocked, msg);
412 msg.sendToTarget();
Robin Leec41f6ec2017-01-10 17:02:34 +0000413 }
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100414
415 /**
416 * Notify listeners that the snapshot of a task has changed.
417 */
418 void notifyTaskSnapshotChanged(int taskId, TaskSnapshot snapshot) {
419 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_SNAPSHOT_CHANGED_LISTENERS_MSG,
420 taskId, 0, snapshot);
421 forAllLocalListeners(mNotifyTaskSnapshotChanged, msg);
422 msg.sendToTarget();
423 }
Yorke Leebd54c2a2016-10-25 13:49:23 -0700424}