blob: 4c50527dd67cceda21035e12ccb5898ba290a6fd [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;
Issei Suzuki734bc942019-06-05 13:59:52 +020058 private static final int NOTIFY_SINGLE_TASK_DISPLAY_EMPTY = 23;
davidlneaeae182019-05-30 14:25:01 -070059 private static final int NOTIFY_TASK_DISPLAY_CHANGED_LISTENERS_MSG = 24;
Yorke Leebd54c2a2016-10-25 13:49:23 -070060
61 // Delay in notifying task stack change listeners (in millis)
Wale Ogunwalef1b2ec92017-06-05 07:09:35 -070062 private static final int NOTIFY_TASK_STACK_CHANGE_LISTENERS_DELAY = 100;
Yorke Leebd54c2a2016-10-25 13:49:23 -070063
Wale Ogunwalec9e57de2018-05-08 14:28:07 -070064 // Global lock used by the service the instantiate objects of this class.
65 private final Object mServiceLock;
Yorke Leebd54c2a2016-10-25 13:49:23 -070066 private final ActivityStackSupervisor mStackSupervisor;
67 private final Handler mHandler;
68
Yorke Lee13294072017-01-06 14:59:58 -080069 // Task stack change listeners in a remote process.
70 private final RemoteCallbackList<ITaskStackListener> mRemoteTaskStackListeners =
71 new RemoteCallbackList<>();
72
73 /*
74 * Task stack change listeners in a local process. Tracked separately so that they can be
75 * called on the same thread.
76 */
77 private final ArrayList<ITaskStackListener> mLocalTaskStackListeners = new ArrayList<>();
78
79 private final TaskStackConsumer mNotifyTaskStackChanged = (l, m) -> {
80 l.onTaskStackChanged();
81 };
82
83 private final TaskStackConsumer mNotifyTaskCreated = (l, m) -> {
84 l.onTaskCreated(m.arg1, (ComponentName) m.obj);
85 };
86
87 private final TaskStackConsumer mNotifyTaskRemoved = (l, m) -> {
88 l.onTaskRemoved(m.arg1);
89 };
90
91 private final TaskStackConsumer mNotifyTaskMovedToFront = (l, m) -> {
Mark Renoufc808f062019-02-07 15:20:37 -050092 l.onTaskMovedToFront((RunningTaskInfo) m.obj);
Yorke Lee13294072017-01-06 14:59:58 -080093 };
94
95 private final TaskStackConsumer mNotifyTaskDescriptionChanged = (l, m) -> {
Mark Renoufc808f062019-02-07 15:20:37 -050096 l.onTaskDescriptionChanged((RunningTaskInfo) m.obj);
Yorke Lee13294072017-01-06 14:59:58 -080097 };
98
Mark Renouf446251d2019-04-26 10:22:41 -040099 private final TaskStackConsumer mNotifyBackPressedOnTaskRoot = (l, m) -> {
100 l.onBackPressedOnTaskRoot((RunningTaskInfo) m.obj);
101 };
102
Yorke Lee13294072017-01-06 14:59:58 -0800103 private final TaskStackConsumer mNotifyActivityRequestedOrientationChanged = (l, m) -> {
104 l.onActivityRequestedOrientationChanged(m.arg1, m.arg2);
105 };
106
107 private final TaskStackConsumer mNotifyTaskRemovalStarted = (l, m) -> {
Mark Renoufc808f062019-02-07 15:20:37 -0500108 l.onTaskRemovalStarted((RunningTaskInfo) m.obj);
Yorke Lee13294072017-01-06 14:59:58 -0800109 };
110
111 private final TaskStackConsumer mNotifyActivityPinned = (l, m) -> {
Wale Ogunwaleb7cf0632017-11-07 13:20:53 -0800112 l.onActivityPinned((String) m.obj /* packageName */, m.sendingUid /* userId */,
113 m.arg1 /* taskId */, m.arg2 /* stackId */);
Winson Chungc81c0ce2017-03-17 12:27:30 -0700114 };
115
116 private final TaskStackConsumer mNotifyActivityUnpinned = (l, m) -> {
117 l.onActivityUnpinned();
Yorke Lee13294072017-01-06 14:59:58 -0800118 };
119
120 private final TaskStackConsumer mNotifyPinnedActivityRestartAttempt = (l, m) -> {
Winson Chunge6385a22017-05-02 18:15:16 -0700121 l.onPinnedActivityRestartAttempt(m.arg1 != 0);
Yorke Lee13294072017-01-06 14:59:58 -0800122 };
123
Winson Chung85d39982017-02-24 15:21:25 -0800124 private final TaskStackConsumer mNotifyPinnedStackAnimationStarted = (l, m) -> {
125 l.onPinnedStackAnimationStarted();
126 };
127
Yorke Lee13294072017-01-06 14:59:58 -0800128 private final TaskStackConsumer mNotifyPinnedStackAnimationEnded = (l, m) -> {
129 l.onPinnedStackAnimationEnded();
130 };
131
132 private final TaskStackConsumer mNotifyActivityForcedResizable = (l, m) -> {
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700133 l.onActivityForcedResizable((String) m.obj, m.arg1, m.arg2);
Yorke Lee13294072017-01-06 14:59:58 -0800134 };
135
136 private final TaskStackConsumer mNotifyActivityDismissingDockedStack = (l, m) -> {
137 l.onActivityDismissingDockedStack();
138 };
139
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700140 private final TaskStackConsumer mNotifyActivityLaunchOnSecondaryDisplayFailed = (l, m) -> {
Mark Renoufc808f062019-02-07 15:20:37 -0500141 l.onActivityLaunchOnSecondaryDisplayFailed((RunningTaskInfo) m.obj, m.arg1);
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700142 };
143
Jeff Changbf299862019-02-26 20:07:22 +0800144 private final TaskStackConsumer mNotifyActivityLaunchOnSecondaryDisplayRerouted = (l, m) -> {
145 l.onActivityLaunchOnSecondaryDisplayRerouted((RunningTaskInfo) m.obj, m.arg1);
146 };
147
Yorke Lee13294072017-01-06 14:59:58 -0800148 private final TaskStackConsumer mNotifyTaskProfileLocked = (l, m) -> {
149 l.onTaskProfileLocked(m.arg1, m.arg2);
150 };
Yorke Leebd54c2a2016-10-25 13:49:23 -0700151
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100152 private final TaskStackConsumer mNotifyTaskSnapshotChanged = (l, m) -> {
153 l.onTaskSnapshotChanged(m.arg1, (TaskSnapshot) m.obj);
154 };
155
Riddle Hsu7b766fd2019-01-28 21:14:59 +0800156 private final TaskStackConsumer mOnSizeCompatModeActivityChanged = (l, m) -> {
157 l.onSizeCompatModeActivityChanged(m.arg1, (IBinder) m.obj);
158 };
159
Issei Suzukicac2a502019-04-16 16:52:50 +0200160 private final TaskStackConsumer mNotifySingleTaskDisplayDrawn = (l, m) -> {
161 l.onSingleTaskDisplayDrawn(m.arg1);
162 };
163
Issei Suzuki734bc942019-06-05 13:59:52 +0200164 private final TaskStackConsumer mNotifySingleTaskDisplayEmpty = (l, m) -> {
165 l.onSingleTaskDisplayEmpty(m.arg1);
166 };
167
davidlneaeae182019-05-30 14:25:01 -0700168 private final TaskStackConsumer mNotifyTaskDisplayChanged = (l, m) -> {
169 l.onTaskDisplayChanged(m.arg1, m.arg2);
170 };
171
Yorke Leebd54c2a2016-10-25 13:49:23 -0700172 @FunctionalInterface
Yorke Lee13294072017-01-06 14:59:58 -0800173 public interface TaskStackConsumer {
174 void accept(ITaskStackListener t, Message m) throws RemoteException;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700175 }
176
177 private class MainHandler extends Handler {
178 public MainHandler(Looper looper) {
179 super(looper);
180 }
181
182 @Override
183 public void handleMessage(Message msg) {
184 switch (msg.what) {
185 case LOG_STACK_STATE_MSG: {
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700186 synchronized (mServiceLock) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700187 mStackSupervisor.logStackState();
188 }
189 break;
190 }
191 case NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800192 forAllRemoteListeners(mNotifyTaskStackChanged, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700193 break;
194 case NOTIFY_TASK_ADDED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800195 forAllRemoteListeners(mNotifyTaskCreated, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700196 break;
197 case NOTIFY_TASK_REMOVED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800198 forAllRemoteListeners(mNotifyTaskRemoved, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700199 break;
200 case NOTIFY_TASK_MOVED_TO_FRONT_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800201 forAllRemoteListeners(mNotifyTaskMovedToFront, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700202 break;
203 case NOTIFY_TASK_DESCRIPTION_CHANGED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800204 forAllRemoteListeners(mNotifyTaskDescriptionChanged, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700205 break;
206 case NOTIFY_ACTIVITY_REQUESTED_ORIENTATION_CHANGED_LISTENERS:
Yorke Lee13294072017-01-06 14:59:58 -0800207 forAllRemoteListeners(mNotifyActivityRequestedOrientationChanged, msg);
Yorke Lee64fd1ce2017-01-05 17:15:20 -0800208 break;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700209 case NOTIFY_TASK_REMOVAL_STARTED_LISTENERS:
Yorke Lee13294072017-01-06 14:59:58 -0800210 forAllRemoteListeners(mNotifyTaskRemovalStarted, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700211 break;
212 case NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800213 forAllRemoteListeners(mNotifyActivityPinned, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700214 break;
Winson Chungc81c0ce2017-03-17 12:27:30 -0700215 case NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG:
216 forAllRemoteListeners(mNotifyActivityUnpinned, msg);
217 break;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700218 case NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800219 forAllRemoteListeners(mNotifyPinnedActivityRestartAttempt, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700220 break;
Winson Chung85d39982017-02-24 15:21:25 -0800221 case NOTIFY_PINNED_STACK_ANIMATION_STARTED_LISTENERS_MSG:
222 forAllRemoteListeners(mNotifyPinnedStackAnimationStarted, msg);
223 break;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700224 case NOTIFY_PINNED_STACK_ANIMATION_ENDED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800225 forAllRemoteListeners(mNotifyPinnedStackAnimationEnded, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700226 break;
227 case NOTIFY_FORCED_RESIZABLE_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800228 forAllRemoteListeners(mNotifyActivityForcedResizable, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700229 break;
230 case NOTIFY_ACTIVITY_DISMISSING_DOCKED_STACK_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800231 forAllRemoteListeners(mNotifyActivityDismissingDockedStack, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700232 break;
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700233 case NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG:
234 forAllRemoteListeners(mNotifyActivityLaunchOnSecondaryDisplayFailed, msg);
235 break;
Jeff Changbf299862019-02-26 20:07:22 +0800236 case NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_REROUTED_MSG:
237 forAllRemoteListeners(mNotifyActivityLaunchOnSecondaryDisplayRerouted, msg);
238 break;
Robin Leec41f6ec2017-01-10 17:02:34 +0000239 case NOTIFY_TASK_PROFILE_LOCKED_LISTENERS_MSG:
Yorke Lee13294072017-01-06 14:59:58 -0800240 forAllRemoteListeners(mNotifyTaskProfileLocked, msg);
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100241 break;
242 case NOTIFY_TASK_SNAPSHOT_CHANGED_LISTENERS_MSG:
243 forAllRemoteListeners(mNotifyTaskSnapshotChanged, msg);
Robin Leec41f6ec2017-01-10 17:02:34 +0000244 break;
Riddle Hsu7b766fd2019-01-28 21:14:59 +0800245 case NOTIFY_SIZE_COMPAT_MODE_ACTIVITY_CHANGED_MSG:
246 forAllRemoteListeners(mOnSizeCompatModeActivityChanged, msg);
247 break;
Mark Renouf446251d2019-04-26 10:22:41 -0400248 case NOTIFY_BACK_PRESSED_ON_TASK_ROOT:
249 forAllRemoteListeners(mNotifyBackPressedOnTaskRoot, msg);
250 break;
Issei Suzukicac2a502019-04-16 16:52:50 +0200251 case NOTIFY_SINGLE_TASK_DISPLAY_DRAWN:
252 forAllRemoteListeners(mNotifySingleTaskDisplayDrawn, msg);
253 break;
Issei Suzuki734bc942019-06-05 13:59:52 +0200254 case NOTIFY_SINGLE_TASK_DISPLAY_EMPTY:
255 forAllRemoteListeners(mNotifySingleTaskDisplayEmpty, msg);
256 break;
davidlneaeae182019-05-30 14:25:01 -0700257 case NOTIFY_TASK_DISPLAY_CHANGED_LISTENERS_MSG:
258 forAllRemoteListeners(mNotifyTaskDisplayChanged, msg);
259 break;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700260 }
261 }
262 }
263
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700264 public TaskChangeNotificationController(Object serviceLock,
Yorke Leebd54c2a2016-10-25 13:49:23 -0700265 ActivityStackSupervisor stackSupervisor, Handler handler) {
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700266 mServiceLock = serviceLock;
Yorke Leebd54c2a2016-10-25 13:49:23 -0700267 mStackSupervisor = stackSupervisor;
268 mHandler = new MainHandler(handler.getLooper());
269 }
270
271 public void registerTaskStackListener(ITaskStackListener listener) {
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700272 synchronized (mServiceLock) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700273 if (listener != null) {
Yorke Lee13294072017-01-06 14:59:58 -0800274 if (Binder.getCallingPid() == android.os.Process.myPid()) {
275 if (!mLocalTaskStackListeners.contains(listener)) {
276 mLocalTaskStackListeners.add(listener);
277 }
278 } else {
279 mRemoteTaskStackListeners.register(listener);
280 }
Yorke Leebd54c2a2016-10-25 13:49:23 -0700281 }
282 }
283 }
284
285 public void unregisterTaskStackListener(ITaskStackListener listener) {
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700286 synchronized (mServiceLock) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700287 if (listener != null) {
Yorke Lee13294072017-01-06 14:59:58 -0800288 if (Binder.getCallingPid() == android.os.Process.myPid()) {
289 mLocalTaskStackListeners.remove(listener);
290 } else {
291 mRemoteTaskStackListeners.unregister(listener);
292 }
Yorke Leebd54c2a2016-10-25 13:49:23 -0700293 }
294 }
295 }
296
Wale Ogunwalef1b2ec92017-06-05 07:09:35 -0700297 private void forAllRemoteListeners(TaskStackConsumer callback, Message message) {
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700298 synchronized (mServiceLock) {
Yorke Lee13294072017-01-06 14:59:58 -0800299 for (int i = mRemoteTaskStackListeners.beginBroadcast() - 1; i >= 0; i--) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700300 try {
301 // Make a one-way callback to the listener
Yorke Lee13294072017-01-06 14:59:58 -0800302 callback.accept(mRemoteTaskStackListeners.getBroadcastItem(i), message);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700303 } catch (RemoteException e) {
304 // Handled by the RemoteCallbackList.
305 }
306 }
Yorke Lee13294072017-01-06 14:59:58 -0800307 mRemoteTaskStackListeners.finishBroadcast();
308 }
309 }
310
Wale Ogunwalef1b2ec92017-06-05 07:09:35 -0700311 private void forAllLocalListeners(TaskStackConsumer callback, Message message) {
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700312 synchronized (mServiceLock) {
Yorke Lee13294072017-01-06 14:59:58 -0800313 for (int i = mLocalTaskStackListeners.size() - 1; i >= 0; i--) {
314 try {
315 callback.accept(mLocalTaskStackListeners.get(i), message);
316 } catch (RemoteException e) {
317 // Never thrown since this is called locally.
318 }
319 }
320 }
321 }
Yorke Leebd54c2a2016-10-25 13:49:23 -0700322
323 /** Notifies all listeners when the task stack has changed. */
324 void notifyTaskStackChanged() {
325 mHandler.sendEmptyMessage(LOG_STACK_STATE_MSG);
326 mHandler.removeMessages(NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG);
Yorke Lee13294072017-01-06 14:59:58 -0800327 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG);
328 forAllLocalListeners(mNotifyTaskStackChanged, msg);
Yorke Leebd54c2a2016-10-25 13:49:23 -0700329 // Only the main task stack change notification requires a delay.
330 mHandler.sendMessageDelayed(msg, NOTIFY_TASK_STACK_CHANGE_LISTENERS_DELAY);
331 }
332
333 /** Notifies all listeners when an Activity is pinned. */
Wale Ogunwale89be5762017-10-04 13:27:49 -0700334 void notifyActivityPinned(ActivityRecord r) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700335 mHandler.removeMessages(NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG);
Wale Ogunwaleb7cf0632017-11-07 13:20:53 -0800336 final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG,
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800337 r.getTaskRecord().taskId, r.getStackId(), r.packageName);
338 msg.sendingUid = r.mUserId;
Yorke Lee13294072017-01-06 14:59:58 -0800339 forAllLocalListeners(mNotifyActivityPinned, msg);
340 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700341 }
342
Winson Chungc81c0ce2017-03-17 12:27:30 -0700343 /** Notifies all listeners when an Activity is unpinned. */
344 void notifyActivityUnpinned() {
345 mHandler.removeMessages(NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG);
346 final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG);
347 forAllLocalListeners(mNotifyActivityUnpinned, msg);
348 msg.sendToTarget();
349 }
350
Yorke Leebd54c2a2016-10-25 13:49:23 -0700351 /**
352 * Notifies all listeners when an attempt was made to start an an activity that is already
353 * running in the pinned stack and the activity was not actually started, but the task is
354 * either brought to the front or a new Intent is delivered to it.
355 */
Winson Chunge6385a22017-05-02 18:15:16 -0700356 void notifyPinnedActivityRestartAttempt(boolean clearedTask) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700357 mHandler.removeMessages(NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG);
Yorke Lee13294072017-01-06 14:59:58 -0800358 final Message msg =
Winson Chunge6385a22017-05-02 18:15:16 -0700359 mHandler.obtainMessage(NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG,
360 clearedTask ? 1 : 0, 0);
Yorke Lee13294072017-01-06 14:59:58 -0800361 forAllLocalListeners(mNotifyPinnedActivityRestartAttempt, msg);
362 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700363 }
364
Winson Chung85d39982017-02-24 15:21:25 -0800365 /** Notifies all listeners when the pinned stack animation starts. */
366 void notifyPinnedStackAnimationStarted() {
367 mHandler.removeMessages(NOTIFY_PINNED_STACK_ANIMATION_STARTED_LISTENERS_MSG);
368 final Message msg =
369 mHandler.obtainMessage(NOTIFY_PINNED_STACK_ANIMATION_STARTED_LISTENERS_MSG);
370 forAllLocalListeners(mNotifyPinnedStackAnimationStarted, msg);
371 msg.sendToTarget();
372 }
373
Yorke Leebd54c2a2016-10-25 13:49:23 -0700374 /** Notifies all listeners when the pinned stack animation ends. */
375 void notifyPinnedStackAnimationEnded() {
376 mHandler.removeMessages(NOTIFY_PINNED_STACK_ANIMATION_ENDED_LISTENERS_MSG);
Yorke Lee13294072017-01-06 14:59:58 -0800377 final Message msg =
378 mHandler.obtainMessage(NOTIFY_PINNED_STACK_ANIMATION_ENDED_LISTENERS_MSG);
379 forAllLocalListeners(mNotifyPinnedStackAnimationEnded, msg);
380 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700381 }
382
383 void notifyActivityDismissingDockedStack() {
384 mHandler.removeMessages(NOTIFY_ACTIVITY_DISMISSING_DOCKED_STACK_MSG);
Wale Ogunwalef1b2ec92017-06-05 07:09:35 -0700385 final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_DISMISSING_DOCKED_STACK_MSG);
386 forAllLocalListeners(mNotifyActivityDismissingDockedStack, msg);
387 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700388 }
389
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700390 void notifyActivityForcedResizable(int taskId, int reason, String packageName) {
Yorke Leebd54c2a2016-10-25 13:49:23 -0700391 mHandler.removeMessages(NOTIFY_FORCED_RESIZABLE_MSG);
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700392 final Message msg = mHandler.obtainMessage(NOTIFY_FORCED_RESIZABLE_MSG, taskId, reason,
393 packageName);
Yorke Lee13294072017-01-06 14:59:58 -0800394 forAllLocalListeners(mNotifyActivityForcedResizable, msg);
395 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700396 }
397
Mark Renoufc808f062019-02-07 15:20:37 -0500398 void notifyActivityLaunchOnSecondaryDisplayFailed(TaskInfo ti, int requestedDisplayId) {
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700399 mHandler.removeMessages(NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG);
400 final Message msg = mHandler.obtainMessage(
Mark Renoufc808f062019-02-07 15:20:37 -0500401 NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG, requestedDisplayId,
402 0 /* unused */, ti);
Andrii Kulian036e3ad2017-04-19 10:55:10 -0700403 forAllLocalListeners(mNotifyActivityLaunchOnSecondaryDisplayFailed, msg);
404 msg.sendToTarget();
405 }
406
Jeff Changbf299862019-02-26 20:07:22 +0800407 void notifyActivityLaunchOnSecondaryDisplayRerouted(TaskInfo ti, int requestedDisplayId) {
408 mHandler.removeMessages(NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_REROUTED_MSG);
409 final Message msg = mHandler.obtainMessage(
410 NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_REROUTED_MSG, requestedDisplayId,
411 0 /* unused */, ti);
412 forAllLocalListeners(mNotifyActivityLaunchOnSecondaryDisplayRerouted, msg);
413 msg.sendToTarget();
414 }
415
Yorke Leebd54c2a2016-10-25 13:49:23 -0700416 void notifyTaskCreated(int taskId, ComponentName componentName) {
Yorke Lee13294072017-01-06 14:59:58 -0800417 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_ADDED_LISTENERS_MSG,
418 taskId, 0 /* unused */, componentName);
419 forAllLocalListeners(mNotifyTaskCreated, msg);
420 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700421 }
422
423 void notifyTaskRemoved(int taskId) {
Yorke Lee13294072017-01-06 14:59:58 -0800424 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_REMOVED_LISTENERS_MSG,
425 taskId, 0 /* unused */);
426 forAllLocalListeners(mNotifyTaskRemoved, msg);
427 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700428 }
429
Mark Renoufc808f062019-02-07 15:20:37 -0500430 void notifyTaskMovedToFront(TaskInfo ti) {
431 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_MOVED_TO_FRONT_LISTENERS_MSG, ti);
Yorke Lee13294072017-01-06 14:59:58 -0800432 forAllLocalListeners(mNotifyTaskMovedToFront, msg);
433 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700434 }
435
Mark Renoufc808f062019-02-07 15:20:37 -0500436 void notifyTaskDescriptionChanged(TaskInfo taskInfo) {
Yorke Lee13294072017-01-06 14:59:58 -0800437 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_DESCRIPTION_CHANGED_LISTENERS_MSG,
Mark Renoufc808f062019-02-07 15:20:37 -0500438 taskInfo);
Yorke Lee13294072017-01-06 14:59:58 -0800439 forAllLocalListeners(mNotifyTaskDescriptionChanged, msg);
440 msg.sendToTarget();
441
Yorke Leebd54c2a2016-10-25 13:49:23 -0700442 }
443
444 void notifyActivityRequestedOrientationChanged(int taskId, int orientation) {
Yorke Lee13294072017-01-06 14:59:58 -0800445 final Message msg = mHandler.obtainMessage(
446 NOTIFY_ACTIVITY_REQUESTED_ORIENTATION_CHANGED_LISTENERS, taskId, orientation);
447 forAllLocalListeners(mNotifyActivityRequestedOrientationChanged, msg);
448 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700449 }
450
451 /**
452 * Notify listeners that the task is about to be finished before its surfaces are removed from
453 * the window manager. This allows interested parties to perform relevant animations before
454 * the window disappears.
455 */
Mark Renoufc808f062019-02-07 15:20:37 -0500456 void notifyTaskRemovalStarted(ActivityManager.RunningTaskInfo taskInfo) {
457 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_REMOVAL_STARTED_LISTENERS, taskInfo);
Yorke Lee13294072017-01-06 14:59:58 -0800458 forAllLocalListeners(mNotifyTaskRemovalStarted, msg);
459 msg.sendToTarget();
Yorke Leebd54c2a2016-10-25 13:49:23 -0700460 }
Robin Leec41f6ec2017-01-10 17:02:34 +0000461
462 /**
463 * Notify listeners that the task has been put in a locked state because one or more of the
464 * activities inside it belong to a managed profile user that has been locked.
465 */
466 void notifyTaskProfileLocked(int taskId, int userId) {
Yorke Lee13294072017-01-06 14:59:58 -0800467 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_PROFILE_LOCKED_LISTENERS_MSG, taskId,
468 userId);
469 forAllLocalListeners(mNotifyTaskProfileLocked, msg);
470 msg.sendToTarget();
Robin Leec41f6ec2017-01-10 17:02:34 +0000471 }
Jorim Jaggifb9d78a2017-01-05 18:57:12 +0100472
473 /**
474 * Notify listeners that the snapshot of a task has changed.
475 */
476 void notifyTaskSnapshotChanged(int taskId, TaskSnapshot snapshot) {
477 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_SNAPSHOT_CHANGED_LISTENERS_MSG,
478 taskId, 0, snapshot);
479 forAllLocalListeners(mNotifyTaskSnapshotChanged, msg);
480 msg.sendToTarget();
481 }
Riddle Hsu7b766fd2019-01-28 21:14:59 +0800482
483 /**
484 * Notify listeners that whether a size compatibility mode activity is using the override
485 * bounds which is not fit its parent.
486 */
487 void notifySizeCompatModeActivityChanged(int displayId, IBinder activityToken) {
488 final Message msg = mHandler.obtainMessage(NOTIFY_SIZE_COMPAT_MODE_ACTIVITY_CHANGED_MSG,
489 displayId, 0 /* unused */, activityToken);
490 forAllLocalListeners(mOnSizeCompatModeActivityChanged, msg);
491 msg.sendToTarget();
492 }
Mark Renouf446251d2019-04-26 10:22:41 -0400493
494 /**
495 * Notify listeners that an activity received a back press when there are no other activities
496 * in the back stack.
497 */
498 void notifyBackPressedOnTaskRoot(TaskInfo taskInfo) {
499 final Message msg = mHandler.obtainMessage(NOTIFY_BACK_PRESSED_ON_TASK_ROOT,
500 taskInfo);
501 forAllLocalListeners(mNotifyBackPressedOnTaskRoot, msg);
502 msg.sendToTarget();
503 }
Issei Suzukicac2a502019-04-16 16:52:50 +0200504
505 /**
506 * Notify listeners that contents are drawn for the first time on a single task display.
507 */
508 void notifySingleTaskDisplayDrawn(int displayId) {
509 final Message msg = mHandler.obtainMessage(NOTIFY_SINGLE_TASK_DISPLAY_DRAWN,
510 displayId, 0 /* unused */);
511 forAllLocalListeners(mNotifySingleTaskDisplayDrawn, msg);
512 msg.sendToTarget();
513 }
Issei Suzuki734bc942019-06-05 13:59:52 +0200514
515 /**
516 * Notify listeners that the last task is removed from a single task display.
517 */
518 void notifySingleTaskDisplayEmpty(int displayId) {
519 final Message msg = mHandler.obtainMessage(
520 NOTIFY_SINGLE_TASK_DISPLAY_EMPTY,
521 displayId, 0 /* unused */);
522 forAllLocalListeners(mNotifySingleTaskDisplayEmpty, msg);
523 msg.sendToTarget();
524 }
davidlneaeae182019-05-30 14:25:01 -0700525
526 /**
527 * Notify listeners that a task is reparented to another display.
528 */
529 void notifyTaskDisplayChanged(int taskId, int newDisplayId) {
530 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_DISPLAY_CHANGED_LISTENERS_MSG,
531 taskId, newDisplayId);
532 forAllLocalListeners(mNotifyTaskStackChanged, msg);
533 msg.sendToTarget();
534 }
Yorke Leebd54c2a2016-10-25 13:49:23 -0700535}