Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 1 | /* |
| 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 Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 17 | package com.android.server.wm; |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 18 | |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 19 | import android.app.ActivityManager; |
| 20 | import android.app.ActivityManager.RunningTaskInfo; |
Jorim Jaggi | fb9d78a | 2017-01-05 18:57:12 +0100 | [diff] [blame] | 21 | import android.app.ActivityManager.TaskSnapshot; |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 22 | import android.app.ITaskStackListener; |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 23 | import android.app.TaskInfo; |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 24 | import android.content.ComponentName; |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 25 | import android.os.Binder; |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 26 | import android.os.Handler; |
| 27 | import android.os.Looper; |
| 28 | import android.os.Message; |
| 29 | import android.os.RemoteCallbackList; |
| 30 | import android.os.RemoteException; |
| 31 | |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 32 | import java.util.ArrayList; |
| 33 | |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 34 | class TaskChangeNotificationController { |
Wale Ogunwale | f1b2ec9 | 2017-06-05 07:09:35 -0700 | [diff] [blame] | 35 | 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 Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 53 | |
| 54 | // Delay in notifying task stack change listeners (in millis) |
Wale Ogunwale | f1b2ec9 | 2017-06-05 07:09:35 -0700 | [diff] [blame] | 55 | private static final int NOTIFY_TASK_STACK_CHANGE_LISTENERS_DELAY = 100; |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 56 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 57 | // Global lock used by the service the instantiate objects of this class. |
| 58 | private final Object mServiceLock; |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 59 | private final ActivityStackSupervisor mStackSupervisor; |
| 60 | private final Handler mHandler; |
| 61 | |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 62 | // 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 Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 85 | l.onTaskMovedToFront((RunningTaskInfo) m.obj); |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | private final TaskStackConsumer mNotifyTaskDescriptionChanged = (l, m) -> { |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 89 | l.onTaskDescriptionChanged((RunningTaskInfo) m.obj); |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 90 | }; |
| 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 Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 97 | l.onTaskRemovalStarted((RunningTaskInfo) m.obj); |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | private final TaskStackConsumer mNotifyActivityPinned = (l, m) -> { |
Wale Ogunwale | b7cf063 | 2017-11-07 13:20:53 -0800 | [diff] [blame] | 101 | l.onActivityPinned((String) m.obj /* packageName */, m.sendingUid /* userId */, |
| 102 | m.arg1 /* taskId */, m.arg2 /* stackId */); |
Winson Chung | c81c0ce | 2017-03-17 12:27:30 -0700 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | private final TaskStackConsumer mNotifyActivityUnpinned = (l, m) -> { |
| 106 | l.onActivityUnpinned(); |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | private final TaskStackConsumer mNotifyPinnedActivityRestartAttempt = (l, m) -> { |
Winson Chung | e6385a2 | 2017-05-02 18:15:16 -0700 | [diff] [blame] | 110 | l.onPinnedActivityRestartAttempt(m.arg1 != 0); |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 111 | }; |
| 112 | |
Winson Chung | 85d3998 | 2017-02-24 15:21:25 -0800 | [diff] [blame] | 113 | private final TaskStackConsumer mNotifyPinnedStackAnimationStarted = (l, m) -> { |
| 114 | l.onPinnedStackAnimationStarted(); |
| 115 | }; |
| 116 | |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 117 | private final TaskStackConsumer mNotifyPinnedStackAnimationEnded = (l, m) -> { |
| 118 | l.onPinnedStackAnimationEnded(); |
| 119 | }; |
| 120 | |
| 121 | private final TaskStackConsumer mNotifyActivityForcedResizable = (l, m) -> { |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 122 | l.onActivityForcedResizable((String) m.obj, m.arg1, m.arg2); |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | private final TaskStackConsumer mNotifyActivityDismissingDockedStack = (l, m) -> { |
| 126 | l.onActivityDismissingDockedStack(); |
| 127 | }; |
| 128 | |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 129 | private final TaskStackConsumer mNotifyActivityLaunchOnSecondaryDisplayFailed = (l, m) -> { |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 130 | l.onActivityLaunchOnSecondaryDisplayFailed((RunningTaskInfo) m.obj, m.arg1); |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 131 | }; |
| 132 | |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 133 | private final TaskStackConsumer mNotifyTaskProfileLocked = (l, m) -> { |
| 134 | l.onTaskProfileLocked(m.arg1, m.arg2); |
| 135 | }; |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 136 | |
Jorim Jaggi | fb9d78a | 2017-01-05 18:57:12 +0100 | [diff] [blame] | 137 | private final TaskStackConsumer mNotifyTaskSnapshotChanged = (l, m) -> { |
| 138 | l.onTaskSnapshotChanged(m.arg1, (TaskSnapshot) m.obj); |
| 139 | }; |
| 140 | |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 141 | @FunctionalInterface |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 142 | public interface TaskStackConsumer { |
| 143 | void accept(ITaskStackListener t, Message m) throws RemoteException; |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 144 | } |
| 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 Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 155 | synchronized (mServiceLock) { |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 156 | mStackSupervisor.logStackState(); |
| 157 | } |
| 158 | break; |
| 159 | } |
| 160 | case NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG: |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 161 | forAllRemoteListeners(mNotifyTaskStackChanged, msg); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 162 | break; |
| 163 | case NOTIFY_TASK_ADDED_LISTENERS_MSG: |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 164 | forAllRemoteListeners(mNotifyTaskCreated, msg); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 165 | break; |
| 166 | case NOTIFY_TASK_REMOVED_LISTENERS_MSG: |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 167 | forAllRemoteListeners(mNotifyTaskRemoved, msg); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 168 | break; |
| 169 | case NOTIFY_TASK_MOVED_TO_FRONT_LISTENERS_MSG: |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 170 | forAllRemoteListeners(mNotifyTaskMovedToFront, msg); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 171 | break; |
| 172 | case NOTIFY_TASK_DESCRIPTION_CHANGED_LISTENERS_MSG: |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 173 | forAllRemoteListeners(mNotifyTaskDescriptionChanged, msg); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 174 | break; |
| 175 | case NOTIFY_ACTIVITY_REQUESTED_ORIENTATION_CHANGED_LISTENERS: |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 176 | forAllRemoteListeners(mNotifyActivityRequestedOrientationChanged, msg); |
Yorke Lee | 64fd1ce | 2017-01-05 17:15:20 -0800 | [diff] [blame] | 177 | break; |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 178 | case NOTIFY_TASK_REMOVAL_STARTED_LISTENERS: |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 179 | forAllRemoteListeners(mNotifyTaskRemovalStarted, msg); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 180 | break; |
| 181 | case NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG: |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 182 | forAllRemoteListeners(mNotifyActivityPinned, msg); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 183 | break; |
Winson Chung | c81c0ce | 2017-03-17 12:27:30 -0700 | [diff] [blame] | 184 | case NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG: |
| 185 | forAllRemoteListeners(mNotifyActivityUnpinned, msg); |
| 186 | break; |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 187 | case NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG: |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 188 | forAllRemoteListeners(mNotifyPinnedActivityRestartAttempt, msg); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 189 | break; |
Winson Chung | 85d3998 | 2017-02-24 15:21:25 -0800 | [diff] [blame] | 190 | case NOTIFY_PINNED_STACK_ANIMATION_STARTED_LISTENERS_MSG: |
| 191 | forAllRemoteListeners(mNotifyPinnedStackAnimationStarted, msg); |
| 192 | break; |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 193 | case NOTIFY_PINNED_STACK_ANIMATION_ENDED_LISTENERS_MSG: |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 194 | forAllRemoteListeners(mNotifyPinnedStackAnimationEnded, msg); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 195 | break; |
| 196 | case NOTIFY_FORCED_RESIZABLE_MSG: |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 197 | forAllRemoteListeners(mNotifyActivityForcedResizable, msg); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 198 | break; |
| 199 | case NOTIFY_ACTIVITY_DISMISSING_DOCKED_STACK_MSG: |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 200 | forAllRemoteListeners(mNotifyActivityDismissingDockedStack, msg); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 201 | break; |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 202 | case NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG: |
| 203 | forAllRemoteListeners(mNotifyActivityLaunchOnSecondaryDisplayFailed, msg); |
| 204 | break; |
Robin Lee | c41f6ec | 2017-01-10 17:02:34 +0000 | [diff] [blame] | 205 | case NOTIFY_TASK_PROFILE_LOCKED_LISTENERS_MSG: |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 206 | forAllRemoteListeners(mNotifyTaskProfileLocked, msg); |
Jorim Jaggi | fb9d78a | 2017-01-05 18:57:12 +0100 | [diff] [blame] | 207 | break; |
| 208 | case NOTIFY_TASK_SNAPSHOT_CHANGED_LISTENERS_MSG: |
| 209 | forAllRemoteListeners(mNotifyTaskSnapshotChanged, msg); |
Robin Lee | c41f6ec | 2017-01-10 17:02:34 +0000 | [diff] [blame] | 210 | break; |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 211 | } |
| 212 | } |
| 213 | } |
| 214 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 215 | public TaskChangeNotificationController(Object serviceLock, |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 216 | ActivityStackSupervisor stackSupervisor, Handler handler) { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 217 | mServiceLock = serviceLock; |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 218 | mStackSupervisor = stackSupervisor; |
| 219 | mHandler = new MainHandler(handler.getLooper()); |
| 220 | } |
| 221 | |
| 222 | public void registerTaskStackListener(ITaskStackListener listener) { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 223 | synchronized (mServiceLock) { |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 224 | if (listener != null) { |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 225 | 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 Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | public void unregisterTaskStackListener(ITaskStackListener listener) { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 237 | synchronized (mServiceLock) { |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 238 | if (listener != null) { |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 239 | if (Binder.getCallingPid() == android.os.Process.myPid()) { |
| 240 | mLocalTaskStackListeners.remove(listener); |
| 241 | } else { |
| 242 | mRemoteTaskStackListeners.unregister(listener); |
| 243 | } |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | } |
| 247 | |
Wale Ogunwale | f1b2ec9 | 2017-06-05 07:09:35 -0700 | [diff] [blame] | 248 | private void forAllRemoteListeners(TaskStackConsumer callback, Message message) { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 249 | synchronized (mServiceLock) { |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 250 | for (int i = mRemoteTaskStackListeners.beginBroadcast() - 1; i >= 0; i--) { |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 251 | try { |
| 252 | // Make a one-way callback to the listener |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 253 | callback.accept(mRemoteTaskStackListeners.getBroadcastItem(i), message); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 254 | } catch (RemoteException e) { |
| 255 | // Handled by the RemoteCallbackList. |
| 256 | } |
| 257 | } |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 258 | mRemoteTaskStackListeners.finishBroadcast(); |
| 259 | } |
| 260 | } |
| 261 | |
Wale Ogunwale | f1b2ec9 | 2017-06-05 07:09:35 -0700 | [diff] [blame] | 262 | private void forAllLocalListeners(TaskStackConsumer callback, Message message) { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 263 | synchronized (mServiceLock) { |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 264 | 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 Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 273 | |
| 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 Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 278 | final Message msg = mHandler.obtainMessage(NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG); |
| 279 | forAllLocalListeners(mNotifyTaskStackChanged, msg); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 280 | // 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 Ogunwale | 89be576 | 2017-10-04 13:27:49 -0700 | [diff] [blame] | 285 | void notifyActivityPinned(ActivityRecord r) { |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 286 | mHandler.removeMessages(NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG); |
Wale Ogunwale | b7cf063 | 2017-11-07 13:20:53 -0800 | [diff] [blame] | 287 | final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 288 | r.getTaskRecord().taskId, r.getStackId(), r.packageName); |
| 289 | msg.sendingUid = r.mUserId; |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 290 | forAllLocalListeners(mNotifyActivityPinned, msg); |
| 291 | msg.sendToTarget(); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Winson Chung | c81c0ce | 2017-03-17 12:27:30 -0700 | [diff] [blame] | 294 | /** 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 Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 302 | /** |
| 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 Chung | e6385a2 | 2017-05-02 18:15:16 -0700 | [diff] [blame] | 307 | void notifyPinnedActivityRestartAttempt(boolean clearedTask) { |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 308 | mHandler.removeMessages(NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG); |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 309 | final Message msg = |
Winson Chung | e6385a2 | 2017-05-02 18:15:16 -0700 | [diff] [blame] | 310 | mHandler.obtainMessage(NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG, |
| 311 | clearedTask ? 1 : 0, 0); |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 312 | forAllLocalListeners(mNotifyPinnedActivityRestartAttempt, msg); |
| 313 | msg.sendToTarget(); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 314 | } |
| 315 | |
Winson Chung | 85d3998 | 2017-02-24 15:21:25 -0800 | [diff] [blame] | 316 | /** 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 Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 325 | /** Notifies all listeners when the pinned stack animation ends. */ |
| 326 | void notifyPinnedStackAnimationEnded() { |
| 327 | mHandler.removeMessages(NOTIFY_PINNED_STACK_ANIMATION_ENDED_LISTENERS_MSG); |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 328 | final Message msg = |
| 329 | mHandler.obtainMessage(NOTIFY_PINNED_STACK_ANIMATION_ENDED_LISTENERS_MSG); |
| 330 | forAllLocalListeners(mNotifyPinnedStackAnimationEnded, msg); |
| 331 | msg.sendToTarget(); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | void notifyActivityDismissingDockedStack() { |
| 335 | mHandler.removeMessages(NOTIFY_ACTIVITY_DISMISSING_DOCKED_STACK_MSG); |
Wale Ogunwale | f1b2ec9 | 2017-06-05 07:09:35 -0700 | [diff] [blame] | 336 | final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_DISMISSING_DOCKED_STACK_MSG); |
| 337 | forAllLocalListeners(mNotifyActivityDismissingDockedStack, msg); |
| 338 | msg.sendToTarget(); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 341 | void notifyActivityForcedResizable(int taskId, int reason, String packageName) { |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 342 | mHandler.removeMessages(NOTIFY_FORCED_RESIZABLE_MSG); |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 343 | final Message msg = mHandler.obtainMessage(NOTIFY_FORCED_RESIZABLE_MSG, taskId, reason, |
| 344 | packageName); |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 345 | forAllLocalListeners(mNotifyActivityForcedResizable, msg); |
| 346 | msg.sendToTarget(); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 349 | void notifyActivityLaunchOnSecondaryDisplayFailed(TaskInfo ti, int requestedDisplayId) { |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 350 | mHandler.removeMessages(NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG); |
| 351 | final Message msg = mHandler.obtainMessage( |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 352 | NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG, requestedDisplayId, |
| 353 | 0 /* unused */, ti); |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 354 | forAllLocalListeners(mNotifyActivityLaunchOnSecondaryDisplayFailed, msg); |
| 355 | msg.sendToTarget(); |
| 356 | } |
| 357 | |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 358 | void notifyTaskCreated(int taskId, ComponentName componentName) { |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 359 | final Message msg = mHandler.obtainMessage(NOTIFY_TASK_ADDED_LISTENERS_MSG, |
| 360 | taskId, 0 /* unused */, componentName); |
| 361 | forAllLocalListeners(mNotifyTaskCreated, msg); |
| 362 | msg.sendToTarget(); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | void notifyTaskRemoved(int taskId) { |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 366 | final Message msg = mHandler.obtainMessage(NOTIFY_TASK_REMOVED_LISTENERS_MSG, |
| 367 | taskId, 0 /* unused */); |
| 368 | forAllLocalListeners(mNotifyTaskRemoved, msg); |
| 369 | msg.sendToTarget(); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 370 | } |
| 371 | |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 372 | void notifyTaskMovedToFront(TaskInfo ti) { |
| 373 | final Message msg = mHandler.obtainMessage(NOTIFY_TASK_MOVED_TO_FRONT_LISTENERS_MSG, ti); |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 374 | forAllLocalListeners(mNotifyTaskMovedToFront, msg); |
| 375 | msg.sendToTarget(); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 376 | } |
| 377 | |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 378 | void notifyTaskDescriptionChanged(TaskInfo taskInfo) { |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 379 | final Message msg = mHandler.obtainMessage(NOTIFY_TASK_DESCRIPTION_CHANGED_LISTENERS_MSG, |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 380 | taskInfo); |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 381 | forAllLocalListeners(mNotifyTaskDescriptionChanged, msg); |
| 382 | msg.sendToTarget(); |
| 383 | |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | void notifyActivityRequestedOrientationChanged(int taskId, int orientation) { |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 387 | final Message msg = mHandler.obtainMessage( |
| 388 | NOTIFY_ACTIVITY_REQUESTED_ORIENTATION_CHANGED_LISTENERS, taskId, orientation); |
| 389 | forAllLocalListeners(mNotifyActivityRequestedOrientationChanged, msg); |
| 390 | msg.sendToTarget(); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 391 | } |
| 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 Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 398 | void notifyTaskRemovalStarted(ActivityManager.RunningTaskInfo taskInfo) { |
| 399 | final Message msg = mHandler.obtainMessage(NOTIFY_TASK_REMOVAL_STARTED_LISTENERS, taskInfo); |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 400 | forAllLocalListeners(mNotifyTaskRemovalStarted, msg); |
| 401 | msg.sendToTarget(); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 402 | } |
Robin Lee | c41f6ec | 2017-01-10 17:02:34 +0000 | [diff] [blame] | 403 | |
| 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 Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 409 | final Message msg = mHandler.obtainMessage(NOTIFY_TASK_PROFILE_LOCKED_LISTENERS_MSG, taskId, |
| 410 | userId); |
| 411 | forAllLocalListeners(mNotifyTaskProfileLocked, msg); |
| 412 | msg.sendToTarget(); |
Robin Lee | c41f6ec | 2017-01-10 17:02:34 +0000 | [diff] [blame] | 413 | } |
Jorim Jaggi | fb9d78a | 2017-01-05 18:57:12 +0100 | [diff] [blame] | 414 | |
| 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 Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 424 | } |