blob: f776062b31a117f6674e1b1c3ab535c3a6f637a8 [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;
Mark Renouf446251d2019-04-26 10:22:41 -040056 private static final int NOTIFY_BACK_PRESSED_ON_TASK_ROOT = 21;
Issei Suzukicac2a502019-04-16 16:52:50 +020057 private static final int NOTIFY_SINGLE_TASK_DISPLAY_DRAWN = 22;
davidln1ceedb52019-05-30 14:25:01 -070058 private static final int NOTIFY_TASK_DISPLAY_CHANGED_LISTENERS_MSG = 23;
Yorke Leebd54c2a2016-10-25 13:49:23 -070059
60 // Delay in notifying task stack change listeners (in millis)
Wale Ogunwalef1b2ec92017-06-05 07:09:35 -070061 private static final int NOTIFY_TASK_STACK_CHANGE_LISTENERS_DELAY = 100;
Yorke Leebd54c2a2016-10-25 13:49:23 -070062
Wale Ogunwalec9e57de2018-05-08 14:28:07 -070063 // Global lock used by the service the instantiate objects of this class.
64 private final Object mServiceLock;
Yorke Leebd54c2a2016-10-25 13:49:23 -070065 private final ActivityStackSupervisor mStackSupervisor;
66 private final Handler mHandler;
67
Yorke Lee13294072017-01-06 14:59:58 -080068 // Task stack change listeners in a remote process.
69 private final RemoteCallbackList<ITaskStackListener> mRemoteTaskStackListeners =
70 new RemoteCallbackList<>();
71
72 /*
73 * Task stack change listeners in a local process. Tracked separately so that they can be
74 * called on the same thread.
75 */
76 private final ArrayList<ITaskStackListener> mLocalTaskStackListeners = new ArrayList<>();
77
78 private final TaskStackConsumer mNotifyTaskStackChanged = (l, m) -> {
79 l.onTaskStackChanged();
80 };
81
82 private final TaskStackConsumer mNotifyTaskCreated = (l, m) -> {
83 l.onTaskCreated(m.arg1, (ComponentName) m.obj);
84 };
85
86 private final TaskStackConsumer mNotifyTaskRemoved = (l, m) -> {
87 l.onTaskRemoved(m.arg1);
88 };
89
90 private final TaskStackConsumer mNotifyTaskMovedToFront = (l, m) -> {
Mark Renoufc808f062019-02-07 15:20:37 -050091 l.onTaskMovedToFront((RunningTaskInfo) m.obj);
Yorke Lee13294072017-01-06 14:59:58 -080092 };
93
94 private final TaskStackConsumer mNotifyTaskDescriptionChanged = (l, m) -> {
Mark Renoufc808f062019-02-07 15:20:37 -050095 l.onTaskDescriptionChanged((RunningTaskInfo) m.obj);
Yorke Lee13294072017-01-06 14:59:58 -080096 };
97
Mark Renouf446251d2019-04-26 10:22:41 -040098 private final TaskStackConsumer mNotifyBackPressedOnTaskRoot = (l, m) -> {
99 l.onBackPressedOnTaskRoot((RunningTaskInfo) m.obj);
100 };
101
Yorke Lee13294072017-01-06 14:59:58 -0800102 private final TaskStackConsumer mNotifyActivityRequestedOrientationChanged = (l, m) -> {
103 l.onActivityRequestedOrientationChanged(m.arg1, m.arg2);
104 };
105
106 private final TaskStackConsumer mNotifyTaskRemovalStarted = (l, m) -> {
Mark Renoufc808f062019-02-07 15:20:37 -0500107 l.onTaskRemovalStarted((RunningTaskInfo) m.obj);
Yorke Lee13294072017-01-06 14:59:58 -0800108 };
109
110 private final TaskStackConsumer mNotifyActivityPinned = (l, m) -> {
Wale Ogunwaleb7cf0632017-11-07 13:20:53 -0800111 l.onActivityPinned((String) m.obj /* packageName */, m.sendingUid /* userId */,
112 m.arg1 /* taskId */, m.arg2 /* stackId */);
Winson Chungc81c0ce2017-03-17 12:27:30 -0700113 };
114
115 private final TaskStackConsumer mNotifyActivityUnpinned = (l, m) -> {
116 l.onActivityUnpinned();
Yorke Lee13294072017-01-06 14:59:58 -0800117 };
118
119 private final TaskStackConsumer mNotifyPinnedActivityRestartAttempt = (l, m) -> {
Winson Chunge6385a22017-05-02 18:15:16 -0700120 l.onPinnedActivityRestartAttempt(m.arg1 != 0);
Yorke Lee13294072017-01-06 14:59:58 -0800121 };
122
Winson Chung85d39982017-02-24 15:21:25 -0800123 private final TaskStackConsumer mNotifyPinnedStackAnimationStarted = (l, m) -> {
124 l.onPinnedStackAnimationStarted();
125 };
126
Yorke Lee13294072017-01-06 14:59:58 -0800127 private final TaskStackConsumer mNotifyPinnedStackAnimationEnded = (l, m) -> {
128 l.onPinnedStackAnimationEnded();
129 };
130
131 private final TaskStackConsumer mNotifyActivityForcedResizable = (l, m) -> {
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700132 l.onActivityForcedResizable((String) m.obj, m.arg1, m.arg2);
Yorke Lee13294072017-01-06 14:59:58 -0800133 };
134
135 private final TaskStackConsumer mNotifyActivityDismissingDockedStack = (l, m) -> {
136 l.onActivityDismissingDockedStack();
137 };
138
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700139 private final TaskStackConsumer mNotifyActivityLaunchOnSecondaryDisplayFailed = (l, m) -> {
Mark Renoufc808f062019-02-07 15:20:37 -0500140 l.onActivityLaunchOnSecondaryDisplayFailed((RunningTaskInfo) m.obj, m.arg1);
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700141 };
142
Jeff Changbf299862019-02-26 20:07:22 +0800143 private final TaskStackConsumer mNotifyActivityLaunchOnSecondaryDisplayRerouted = (l, m) -> {
144 l.onActivityLaunchOnSecondaryDisplayRerouted((RunningTaskInfo) m.obj, m.arg1);
145 };
146
Yorke Lee13294072017-01-06 14:59:58 -0800147 private final TaskStackConsumer mNotifyTaskProfileLocked = (l, m) -> {
148 l.onTaskProfileLocked(m.arg1, m.arg2);
149 };
Yorke Leebd54c2a2016-10-25 13:49:23 -0700150
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100151 private final TaskStackConsumer mNotifyTaskSnapshotChanged = (l, m) -> {
152 l.onTaskSnapshotChanged(m.arg1, (TaskSnapshot) m.obj);
153 };
154
Riddle Hsu7b766fd2019-01-28 21:14:59 +0800155 private final TaskStackConsumer mOnSizeCompatModeActivityChanged = (l, m) -> {
156 l.onSizeCompatModeActivityChanged(m.arg1, (IBinder) m.obj);
157 };
158
Issei Suzukicac2a502019-04-16 16:52:50 +0200159 private final TaskStackConsumer mNotifySingleTaskDisplayDrawn = (l, m) -> {
160 l.onSingleTaskDisplayDrawn(m.arg1);
161 };
162
davidln1ceedb52019-05-30 14:25:01 -0700163 private final TaskStackConsumer mNotifyTaskDisplayChanged = (l, m) -> {
164 l.onTaskDisplayChanged(m.arg1, m.arg2);
165 };
166
Yorke Leebd54c2a2016-10-25 13:49:23 -0700167 @FunctionalInterface
Yorke Lee13294072017-01-06 14:59:58 -0800168 public interface TaskStackConsumer {
169 void accept(ITaskStackListener t, Message m) throws RemoteException;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700170 }
171
172 private class MainHandler extends Handler {
173 public MainHandler(Looper looper) {
174 super(looper);
175 }
176
177 @Override
178 public void handleMessage(Message msg) {
179 switch (msg.what) {
180 case LOG_STACK_STATE_MSG: {
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700181 synchronized (mServiceLock) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700182 mStackSupervisor.logStackState();
183 }
184 break;
185 }
186 case NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800187 forAllRemoteListeners(mNotifyTaskStackChanged, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700188 break;
189 case NOTIFY_TASK_ADDED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800190 forAllRemoteListeners(mNotifyTaskCreated, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700191 break;
192 case NOTIFY_TASK_REMOVED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800193 forAllRemoteListeners(mNotifyTaskRemoved, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700194 break;
195 case NOTIFY_TASK_MOVED_TO_FRONT_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800196 forAllRemoteListeners(mNotifyTaskMovedToFront, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700197 break;
198 case NOTIFY_TASK_DESCRIPTION_CHANGED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800199 forAllRemoteListeners(mNotifyTaskDescriptionChanged, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700200 break;
201 case NOTIFY_ACTIVITY_REQUESTED_ORIENTATION_CHANGED_LISTENERS:
Yorke Lee13294072017-01-06 14:59:58 -0800202 forAllRemoteListeners(mNotifyActivityRequestedOrientationChanged, msg);
Yorke Lee64fd1ce2017-01-05 17:15:20 -0800203 break;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700204 case NOTIFY_TASK_REMOVAL_STARTED_LISTENERS:
Yorke Lee13294072017-01-06 14:59:58 -0800205 forAllRemoteListeners(mNotifyTaskRemovalStarted, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700206 break;
207 case NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800208 forAllRemoteListeners(mNotifyActivityPinned, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700209 break;
Winson Chungc81c0ce2017-03-17 12:27:30 -0700210 case NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG:
211 forAllRemoteListeners(mNotifyActivityUnpinned, msg);
212 break;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700213 case NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800214 forAllRemoteListeners(mNotifyPinnedActivityRestartAttempt, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700215 break;
Winson Chung85d39982017-02-24 15:21:25 -0800216 case NOTIFY_PINNED_STACK_ANIMATION_STARTED_LISTENERS_MSG:
217 forAllRemoteListeners(mNotifyPinnedStackAnimationStarted, msg);
218 break;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700219 case NOTIFY_PINNED_STACK_ANIMATION_ENDED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800220 forAllRemoteListeners(mNotifyPinnedStackAnimationEnded, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700221 break;
222 case NOTIFY_FORCED_RESIZABLE_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800223 forAllRemoteListeners(mNotifyActivityForcedResizable, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700224 break;
225 case NOTIFY_ACTIVITY_DISMISSING_DOCKED_STACK_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800226 forAllRemoteListeners(mNotifyActivityDismissingDockedStack, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700227 break;
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700228 case NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG:
229 forAllRemoteListeners(mNotifyActivityLaunchOnSecondaryDisplayFailed, msg);
230 break;
Jeff Changbf299862019-02-26 20:07:22 +0800231 case NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_REROUTED_MSG:
232 forAllRemoteListeners(mNotifyActivityLaunchOnSecondaryDisplayRerouted, msg);
233 break;
Robin Leec41f6ec2017-01-10 17:02:34 +0000234 case NOTIFY_TASK_PROFILE_LOCKED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800235 forAllRemoteListeners(mNotifyTaskProfileLocked, msg);
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100236 break;
237 case NOTIFY_TASK_SNAPSHOT_CHANGED_LISTENERS_MSG:
238 forAllRemoteListeners(mNotifyTaskSnapshotChanged, msg);
Robin Leec41f6ec2017-01-10 17:02:34 +0000239 break;
Riddle Hsu7b766fd2019-01-28 21:14:59 +0800240 case NOTIFY_SIZE_COMPAT_MODE_ACTIVITY_CHANGED_MSG:
241 forAllRemoteListeners(mOnSizeCompatModeActivityChanged, msg);
242 break;
Mark Renouf446251d2019-04-26 10:22:41 -0400243 case NOTIFY_BACK_PRESSED_ON_TASK_ROOT:
244 forAllRemoteListeners(mNotifyBackPressedOnTaskRoot, msg);
245 break;
Issei Suzukicac2a502019-04-16 16:52:50 +0200246 case NOTIFY_SINGLE_TASK_DISPLAY_DRAWN:
247 forAllRemoteListeners(mNotifySingleTaskDisplayDrawn, msg);
248 break;
davidln1ceedb52019-05-30 14:25:01 -0700249 case NOTIFY_TASK_DISPLAY_CHANGED_LISTENERS_MSG:
250 forAllRemoteListeners(mNotifyTaskDisplayChanged, msg);
251 break;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700252 }
253 }
254 }
255
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700256 public TaskChangeNotificationController(Object serviceLock,
Yorke Leebd54c2a2016-10-25 13:49:23 -0700257 ActivityStackSupervisor stackSupervisor, Handler handler) {
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700258 mServiceLock = serviceLock;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700259 mStackSupervisor = stackSupervisor;
260 mHandler = new MainHandler(handler.getLooper());
261 }
262
263 public void registerTaskStackListener(ITaskStackListener listener) {
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700264 synchronized (mServiceLock) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700265 if (listener != null) {
Yorke Lee13294072017-01-06 14:59:58 -0800266 if (Binder.getCallingPid() == android.os.Process.myPid()) {
267 if (!mLocalTaskStackListeners.contains(listener)) {
268 mLocalTaskStackListeners.add(listener);
269 }
270 } else {
271 mRemoteTaskStackListeners.register(listener);
272 }
Yorke Leebd54c2a2016-10-25 13:49:23 -0700273 }
274 }
275 }
276
277 public void unregisterTaskStackListener(ITaskStackListener listener) {
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700278 synchronized (mServiceLock) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700279 if (listener != null) {
Yorke Lee13294072017-01-06 14:59:58 -0800280 if (Binder.getCallingPid() == android.os.Process.myPid()) {
281 mLocalTaskStackListeners.remove(listener);
282 } else {
283 mRemoteTaskStackListeners.unregister(listener);
284 }
Yorke Leebd54c2a2016-10-25 13:49:23 -0700285 }
286 }
287 }
288
Wale Ogunwalef1b2ec92017-06-05 07:09:35 -0700289 private void forAllRemoteListeners(TaskStackConsumer callback, Message message) {
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700290 synchronized (mServiceLock) {
Yorke Lee13294072017-01-06 14:59:58 -0800291 for (int i = mRemoteTaskStackListeners.beginBroadcast() - 1; i >= 0; i--) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700292 try {
293 // Make a one-way callback to the listener
Yorke Lee13294072017-01-06 14:59:58 -0800294 callback.accept(mRemoteTaskStackListeners.getBroadcastItem(i), message);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700295 } catch (RemoteException e) {
296 // Handled by the RemoteCallbackList.
297 }
298 }
Yorke Lee13294072017-01-06 14:59:58 -0800299 mRemoteTaskStackListeners.finishBroadcast();
300 }
301 }
302
Wale Ogunwalef1b2ec92017-06-05 07:09:35 -0700303 private void forAllLocalListeners(TaskStackConsumer callback, Message message) {
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700304 synchronized (mServiceLock) {
Yorke Lee13294072017-01-06 14:59:58 -0800305 for (int i = mLocalTaskStackListeners.size() - 1; i >= 0; i--) {
306 try {
307 callback.accept(mLocalTaskStackListeners.get(i), message);
308 } catch (RemoteException e) {
309 // Never thrown since this is called locally.
310 }
311 }
312 }
313 }
Yorke Leebd54c2a2016-10-25 13:49:23 -0700314
315 /** Notifies all listeners when the task stack has changed. */
316 void notifyTaskStackChanged() {
317 mHandler.sendEmptyMessage(LOG_STACK_STATE_MSG);
318 mHandler.removeMessages(NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG);
Yorke Lee13294072017-01-06 14:59:58 -0800319 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG);
320 forAllLocalListeners(mNotifyTaskStackChanged, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700321 // Only the main task stack change notification requires a delay.
322 mHandler.sendMessageDelayed(msg, NOTIFY_TASK_STACK_CHANGE_LISTENERS_DELAY);
323 }
324
325 /** Notifies all listeners when an Activity is pinned. */
Wale Ogunwale89be5762017-10-04 13:27:49 -0700326 void notifyActivityPinned(ActivityRecord r) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700327 mHandler.removeMessages(NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG);
Wale Ogunwaleb7cf0632017-11-07 13:20:53 -0800328 final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG,
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800329 r.getTaskRecord().taskId, r.getStackId(), r.packageName);
330 msg.sendingUid = r.mUserId;
Yorke Lee13294072017-01-06 14:59:58 -0800331 forAllLocalListeners(mNotifyActivityPinned, msg);
332 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700333 }
334
Winson Chungc81c0ce2017-03-17 12:27:30 -0700335 /** Notifies all listeners when an Activity is unpinned. */
336 void notifyActivityUnpinned() {
337 mHandler.removeMessages(NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG);
338 final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG);
339 forAllLocalListeners(mNotifyActivityUnpinned, msg);
340 msg.sendToTarget();
341 }
342
Yorke Leebd54c2a2016-10-25 13:49:23 -0700343 /**
344 * Notifies all listeners when an attempt was made to start an an activity that is already
345 * running in the pinned stack and the activity was not actually started, but the task is
346 * either brought to the front or a new Intent is delivered to it.
347 */
Winson Chunge6385a22017-05-02 18:15:16 -0700348 void notifyPinnedActivityRestartAttempt(boolean clearedTask) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700349 mHandler.removeMessages(NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG);
Yorke Lee13294072017-01-06 14:59:58 -0800350 final Message msg =
Winson Chunge6385a22017-05-02 18:15:16 -0700351 mHandler.obtainMessage(NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG,
352 clearedTask ? 1 : 0, 0);
Yorke Lee13294072017-01-06 14:59:58 -0800353 forAllLocalListeners(mNotifyPinnedActivityRestartAttempt, msg);
354 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700355 }
356
Winson Chung85d39982017-02-24 15:21:25 -0800357 /** Notifies all listeners when the pinned stack animation starts. */
358 void notifyPinnedStackAnimationStarted() {
359 mHandler.removeMessages(NOTIFY_PINNED_STACK_ANIMATION_STARTED_LISTENERS_MSG);
360 final Message msg =
361 mHandler.obtainMessage(NOTIFY_PINNED_STACK_ANIMATION_STARTED_LISTENERS_MSG);
362 forAllLocalListeners(mNotifyPinnedStackAnimationStarted, msg);
363 msg.sendToTarget();
364 }
365
Yorke Leebd54c2a2016-10-25 13:49:23 -0700366 /** Notifies all listeners when the pinned stack animation ends. */
367 void notifyPinnedStackAnimationEnded() {
368 mHandler.removeMessages(NOTIFY_PINNED_STACK_ANIMATION_ENDED_LISTENERS_MSG);
Yorke Lee13294072017-01-06 14:59:58 -0800369 final Message msg =
370 mHandler.obtainMessage(NOTIFY_PINNED_STACK_ANIMATION_ENDED_LISTENERS_MSG);
371 forAllLocalListeners(mNotifyPinnedStackAnimationEnded, msg);
372 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700373 }
374
375 void notifyActivityDismissingDockedStack() {
376 mHandler.removeMessages(NOTIFY_ACTIVITY_DISMISSING_DOCKED_STACK_MSG);
Wale Ogunwalef1b2ec92017-06-05 07:09:35 -0700377 final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_DISMISSING_DOCKED_STACK_MSG);
378 forAllLocalListeners(mNotifyActivityDismissingDockedStack, msg);
379 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700380 }
381
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700382 void notifyActivityForcedResizable(int taskId, int reason, String packageName) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700383 mHandler.removeMessages(NOTIFY_FORCED_RESIZABLE_MSG);
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700384 final Message msg = mHandler.obtainMessage(NOTIFY_FORCED_RESIZABLE_MSG, taskId, reason,
385 packageName);
Yorke Lee13294072017-01-06 14:59:58 -0800386 forAllLocalListeners(mNotifyActivityForcedResizable, msg);
387 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700388 }
389
Mark Renoufc808f062019-02-07 15:20:37 -0500390 void notifyActivityLaunchOnSecondaryDisplayFailed(TaskInfo ti, int requestedDisplayId) {
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700391 mHandler.removeMessages(NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG);
392 final Message msg = mHandler.obtainMessage(
Mark Renoufc808f062019-02-07 15:20:37 -0500393 NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG, requestedDisplayId,
394 0 /* unused */, ti);
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700395 forAllLocalListeners(mNotifyActivityLaunchOnSecondaryDisplayFailed, msg);
396 msg.sendToTarget();
397 }
398
Jeff Changbf299862019-02-26 20:07:22 +0800399 void notifyActivityLaunchOnSecondaryDisplayRerouted(TaskInfo ti, int requestedDisplayId) {
400 mHandler.removeMessages(NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_REROUTED_MSG);
401 final Message msg = mHandler.obtainMessage(
402 NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_REROUTED_MSG, requestedDisplayId,
403 0 /* unused */, ti);
404 forAllLocalListeners(mNotifyActivityLaunchOnSecondaryDisplayRerouted, msg);
405 msg.sendToTarget();
406 }
407
Yorke Leebd54c2a2016-10-25 13:49:23 -0700408 void notifyTaskCreated(int taskId, ComponentName componentName) {
Yorke Lee13294072017-01-06 14:59:58 -0800409 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_ADDED_LISTENERS_MSG,
410 taskId, 0 /* unused */, componentName);
411 forAllLocalListeners(mNotifyTaskCreated, msg);
412 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700413 }
414
415 void notifyTaskRemoved(int taskId) {
Yorke Lee13294072017-01-06 14:59:58 -0800416 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_REMOVED_LISTENERS_MSG,
417 taskId, 0 /* unused */);
418 forAllLocalListeners(mNotifyTaskRemoved, msg);
419 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700420 }
421
Mark Renoufc808f062019-02-07 15:20:37 -0500422 void notifyTaskMovedToFront(TaskInfo ti) {
423 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_MOVED_TO_FRONT_LISTENERS_MSG, ti);
Yorke Lee13294072017-01-06 14:59:58 -0800424 forAllLocalListeners(mNotifyTaskMovedToFront, msg);
425 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700426 }
427
Mark Renoufc808f062019-02-07 15:20:37 -0500428 void notifyTaskDescriptionChanged(TaskInfo taskInfo) {
Yorke Lee13294072017-01-06 14:59:58 -0800429 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_DESCRIPTION_CHANGED_LISTENERS_MSG,
Mark Renoufc808f062019-02-07 15:20:37 -0500430 taskInfo);
Yorke Lee13294072017-01-06 14:59:58 -0800431 forAllLocalListeners(mNotifyTaskDescriptionChanged, msg);
432 msg.sendToTarget();
433
Yorke Leebd54c2a2016-10-25 13:49:23 -0700434 }
435
436 void notifyActivityRequestedOrientationChanged(int taskId, int orientation) {
Yorke Lee13294072017-01-06 14:59:58 -0800437 final Message msg = mHandler.obtainMessage(
438 NOTIFY_ACTIVITY_REQUESTED_ORIENTATION_CHANGED_LISTENERS, taskId, orientation);
439 forAllLocalListeners(mNotifyActivityRequestedOrientationChanged, msg);
440 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700441 }
442
443 /**
444 * Notify listeners that the task is about to be finished before its surfaces are removed from
445 * the window manager. This allows interested parties to perform relevant animations before
446 * the window disappears.
447 */
Mark Renoufc808f062019-02-07 15:20:37 -0500448 void notifyTaskRemovalStarted(ActivityManager.RunningTaskInfo taskInfo) {
449 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_REMOVAL_STARTED_LISTENERS, taskInfo);
Yorke Lee13294072017-01-06 14:59:58 -0800450 forAllLocalListeners(mNotifyTaskRemovalStarted, msg);
451 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700452 }
Robin Leec41f6ec2017-01-10 17:02:34 +0000453
454 /**
455 * Notify listeners that the task has been put in a locked state because one or more of the
456 * activities inside it belong to a managed profile user that has been locked.
457 */
458 void notifyTaskProfileLocked(int taskId, int userId) {
Yorke Lee13294072017-01-06 14:59:58 -0800459 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_PROFILE_LOCKED_LISTENERS_MSG, taskId,
460 userId);
461 forAllLocalListeners(mNotifyTaskProfileLocked, msg);
462 msg.sendToTarget();
Robin Leec41f6ec2017-01-10 17:02:34 +0000463 }
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100464
465 /**
466 * Notify listeners that the snapshot of a task has changed.
467 */
468 void notifyTaskSnapshotChanged(int taskId, TaskSnapshot snapshot) {
469 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_SNAPSHOT_CHANGED_LISTENERS_MSG,
470 taskId, 0, snapshot);
471 forAllLocalListeners(mNotifyTaskSnapshotChanged, msg);
472 msg.sendToTarget();
473 }
Riddle Hsu7b766fd2019-01-28 21:14:59 +0800474
475 /**
476 * Notify listeners that whether a size compatibility mode activity is using the override
477 * bounds which is not fit its parent.
478 */
479 void notifySizeCompatModeActivityChanged(int displayId, IBinder activityToken) {
480 final Message msg = mHandler.obtainMessage(NOTIFY_SIZE_COMPAT_MODE_ACTIVITY_CHANGED_MSG,
481 displayId, 0 /* unused */, activityToken);
482 forAllLocalListeners(mOnSizeCompatModeActivityChanged, msg);
483 msg.sendToTarget();
484 }
Mark Renouf446251d2019-04-26 10:22:41 -0400485
486 /**
487 * Notify listeners that an activity received a back press when there are no other activities
488 * in the back stack.
489 */
490 void notifyBackPressedOnTaskRoot(TaskInfo taskInfo) {
491 final Message msg = mHandler.obtainMessage(NOTIFY_BACK_PRESSED_ON_TASK_ROOT,
492 taskInfo);
493 forAllLocalListeners(mNotifyBackPressedOnTaskRoot, msg);
494 msg.sendToTarget();
495 }
Issei Suzukicac2a502019-04-16 16:52:50 +0200496
497 /**
498 * Notify listeners that contents are drawn for the first time on a single task display.
499 */
500 void notifySingleTaskDisplayDrawn(int displayId) {
501 final Message msg = mHandler.obtainMessage(NOTIFY_SINGLE_TASK_DISPLAY_DRAWN,
502 displayId, 0 /* unused */);
503 forAllLocalListeners(mNotifySingleTaskDisplayDrawn, msg);
504 msg.sendToTarget();
505 }
davidln1ceedb52019-05-30 14:25:01 -0700506
507 /**
508 * Notify listeners that a task is reparented to another display.
509 */
510 void notifyTaskDisplayChanged(int taskId, int newDisplayId) {
511 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_DISPLAY_CHANGED_LISTENERS_MSG,
512 taskId, newDisplayId);
513 forAllLocalListeners(mNotifyTaskStackChanged, msg);
514 msg.sendToTarget();
515 }
Yorke Leebd54c2a2016-10-25 13:49:23 -0700516}