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 | |
| 17 | package com.android.server.am; |
| 18 | |
Jorim Jaggi | fb9d78a | 2017-01-05 18:57:12 +0100 | [diff] [blame] | 19 | import android.app.ActivityManager.TaskSnapshot; |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 20 | import android.app.ITaskStackListener; |
| 21 | import android.app.ActivityManager.TaskDescription; |
| 22 | import android.content.ComponentName; |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 23 | import android.os.Binder; |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 24 | import android.os.Handler; |
| 25 | import android.os.Looper; |
| 26 | import android.os.Message; |
| 27 | import android.os.RemoteCallbackList; |
| 28 | import android.os.RemoteException; |
| 29 | |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 30 | import java.util.ArrayList; |
| 31 | |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 32 | class TaskChangeNotificationController { |
Wale Ogunwale | f1b2ec9 | 2017-06-05 07:09:35 -0700 | [diff] [blame] | 33 | private static final int LOG_STACK_STATE_MSG = 1; |
| 34 | private static final int NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG = 2; |
| 35 | private static final int NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG = 3; |
| 36 | private static final int NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG = 4; |
| 37 | private static final int NOTIFY_PINNED_STACK_ANIMATION_ENDED_LISTENERS_MSG = 5; |
| 38 | private static final int NOTIFY_FORCED_RESIZABLE_MSG = 6; |
| 39 | private static final int NOTIFY_ACTIVITY_DISMISSING_DOCKED_STACK_MSG = 7; |
| 40 | private static final int NOTIFY_TASK_ADDED_LISTENERS_MSG = 8; |
| 41 | private static final int NOTIFY_TASK_REMOVED_LISTENERS_MSG = 9; |
| 42 | private static final int NOTIFY_TASK_MOVED_TO_FRONT_LISTENERS_MSG = 10; |
| 43 | private static final int NOTIFY_TASK_DESCRIPTION_CHANGED_LISTENERS_MSG = 11; |
| 44 | private static final int NOTIFY_ACTIVITY_REQUESTED_ORIENTATION_CHANGED_LISTENERS = 12; |
| 45 | private static final int NOTIFY_TASK_REMOVAL_STARTED_LISTENERS = 13; |
| 46 | private static final int NOTIFY_TASK_PROFILE_LOCKED_LISTENERS_MSG = 14; |
| 47 | private static final int NOTIFY_TASK_SNAPSHOT_CHANGED_LISTENERS_MSG = 15; |
| 48 | private static final int NOTIFY_PINNED_STACK_ANIMATION_STARTED_LISTENERS_MSG = 16; |
| 49 | private static final int NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG = 17; |
| 50 | 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] | 51 | |
| 52 | // Delay in notifying task stack change listeners (in millis) |
Wale Ogunwale | f1b2ec9 | 2017-06-05 07:09:35 -0700 | [diff] [blame] | 53 | private static final int NOTIFY_TASK_STACK_CHANGE_LISTENERS_DELAY = 100; |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 54 | |
| 55 | private final ActivityManagerService mService; |
| 56 | private final ActivityStackSupervisor mStackSupervisor; |
| 57 | private final Handler mHandler; |
| 58 | |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 59 | // Task stack change listeners in a remote process. |
| 60 | private final RemoteCallbackList<ITaskStackListener> mRemoteTaskStackListeners = |
| 61 | new RemoteCallbackList<>(); |
| 62 | |
| 63 | /* |
| 64 | * Task stack change listeners in a local process. Tracked separately so that they can be |
| 65 | * called on the same thread. |
| 66 | */ |
| 67 | private final ArrayList<ITaskStackListener> mLocalTaskStackListeners = new ArrayList<>(); |
| 68 | |
| 69 | private final TaskStackConsumer mNotifyTaskStackChanged = (l, m) -> { |
| 70 | l.onTaskStackChanged(); |
| 71 | }; |
| 72 | |
| 73 | private final TaskStackConsumer mNotifyTaskCreated = (l, m) -> { |
| 74 | l.onTaskCreated(m.arg1, (ComponentName) m.obj); |
| 75 | }; |
| 76 | |
| 77 | private final TaskStackConsumer mNotifyTaskRemoved = (l, m) -> { |
| 78 | l.onTaskRemoved(m.arg1); |
| 79 | }; |
| 80 | |
| 81 | private final TaskStackConsumer mNotifyTaskMovedToFront = (l, m) -> { |
| 82 | l.onTaskMovedToFront(m.arg1); |
| 83 | }; |
| 84 | |
| 85 | private final TaskStackConsumer mNotifyTaskDescriptionChanged = (l, m) -> { |
| 86 | l.onTaskDescriptionChanged(m.arg1, (TaskDescription) m.obj); |
| 87 | }; |
| 88 | |
| 89 | private final TaskStackConsumer mNotifyActivityRequestedOrientationChanged = (l, m) -> { |
| 90 | l.onActivityRequestedOrientationChanged(m.arg1, m.arg2); |
| 91 | }; |
| 92 | |
| 93 | private final TaskStackConsumer mNotifyTaskRemovalStarted = (l, m) -> { |
| 94 | l.onTaskRemovalStarted(m.arg1); |
| 95 | }; |
| 96 | |
| 97 | private final TaskStackConsumer mNotifyActivityPinned = (l, m) -> { |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 98 | l.onActivityPinned((String) m.obj, m.arg1); |
Winson Chung | c81c0ce | 2017-03-17 12:27:30 -0700 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | private final TaskStackConsumer mNotifyActivityUnpinned = (l, m) -> { |
| 102 | l.onActivityUnpinned(); |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | private final TaskStackConsumer mNotifyPinnedActivityRestartAttempt = (l, m) -> { |
Winson Chung | e6385a2 | 2017-05-02 18:15:16 -0700 | [diff] [blame] | 106 | l.onPinnedActivityRestartAttempt(m.arg1 != 0); |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 107 | }; |
| 108 | |
Winson Chung | 85d3998 | 2017-02-24 15:21:25 -0800 | [diff] [blame] | 109 | private final TaskStackConsumer mNotifyPinnedStackAnimationStarted = (l, m) -> { |
| 110 | l.onPinnedStackAnimationStarted(); |
| 111 | }; |
| 112 | |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 113 | private final TaskStackConsumer mNotifyPinnedStackAnimationEnded = (l, m) -> { |
| 114 | l.onPinnedStackAnimationEnded(); |
| 115 | }; |
| 116 | |
| 117 | private final TaskStackConsumer mNotifyActivityForcedResizable = (l, m) -> { |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 118 | l.onActivityForcedResizable((String) m.obj, m.arg1, m.arg2); |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | private final TaskStackConsumer mNotifyActivityDismissingDockedStack = (l, m) -> { |
| 122 | l.onActivityDismissingDockedStack(); |
| 123 | }; |
| 124 | |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 125 | private final TaskStackConsumer mNotifyActivityLaunchOnSecondaryDisplayFailed = (l, m) -> { |
| 126 | l.onActivityLaunchOnSecondaryDisplayFailed(); |
| 127 | }; |
| 128 | |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 129 | private final TaskStackConsumer mNotifyTaskProfileLocked = (l, m) -> { |
| 130 | l.onTaskProfileLocked(m.arg1, m.arg2); |
| 131 | }; |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 132 | |
Jorim Jaggi | fb9d78a | 2017-01-05 18:57:12 +0100 | [diff] [blame] | 133 | private final TaskStackConsumer mNotifyTaskSnapshotChanged = (l, m) -> { |
| 134 | l.onTaskSnapshotChanged(m.arg1, (TaskSnapshot) m.obj); |
| 135 | }; |
| 136 | |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 137 | @FunctionalInterface |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 138 | public interface TaskStackConsumer { |
| 139 | void accept(ITaskStackListener t, Message m) throws RemoteException; |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | private class MainHandler extends Handler { |
| 143 | public MainHandler(Looper looper) { |
| 144 | super(looper); |
| 145 | } |
| 146 | |
| 147 | @Override |
| 148 | public void handleMessage(Message msg) { |
| 149 | switch (msg.what) { |
| 150 | case LOG_STACK_STATE_MSG: { |
| 151 | synchronized (mService) { |
| 152 | mStackSupervisor.logStackState(); |
| 153 | } |
| 154 | break; |
| 155 | } |
| 156 | case NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG: |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 157 | forAllRemoteListeners(mNotifyTaskStackChanged, msg); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 158 | break; |
| 159 | case NOTIFY_TASK_ADDED_LISTENERS_MSG: |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 160 | forAllRemoteListeners(mNotifyTaskCreated, msg); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 161 | break; |
| 162 | case NOTIFY_TASK_REMOVED_LISTENERS_MSG: |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 163 | forAllRemoteListeners(mNotifyTaskRemoved, msg); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 164 | break; |
| 165 | case NOTIFY_TASK_MOVED_TO_FRONT_LISTENERS_MSG: |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 166 | forAllRemoteListeners(mNotifyTaskMovedToFront, msg); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 167 | break; |
| 168 | case NOTIFY_TASK_DESCRIPTION_CHANGED_LISTENERS_MSG: |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 169 | forAllRemoteListeners(mNotifyTaskDescriptionChanged, msg); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 170 | break; |
| 171 | case NOTIFY_ACTIVITY_REQUESTED_ORIENTATION_CHANGED_LISTENERS: |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 172 | forAllRemoteListeners(mNotifyActivityRequestedOrientationChanged, msg); |
Yorke Lee | 64fd1ce | 2017-01-05 17:15:20 -0800 | [diff] [blame] | 173 | break; |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 174 | case NOTIFY_TASK_REMOVAL_STARTED_LISTENERS: |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 175 | forAllRemoteListeners(mNotifyTaskRemovalStarted, msg); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 176 | break; |
| 177 | case NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG: |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 178 | forAllRemoteListeners(mNotifyActivityPinned, msg); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 179 | break; |
Winson Chung | c81c0ce | 2017-03-17 12:27:30 -0700 | [diff] [blame] | 180 | case NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG: |
| 181 | forAllRemoteListeners(mNotifyActivityUnpinned, msg); |
| 182 | break; |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 183 | case NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG: |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 184 | forAllRemoteListeners(mNotifyPinnedActivityRestartAttempt, msg); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 185 | break; |
Winson Chung | 85d3998 | 2017-02-24 15:21:25 -0800 | [diff] [blame] | 186 | case NOTIFY_PINNED_STACK_ANIMATION_STARTED_LISTENERS_MSG: |
| 187 | forAllRemoteListeners(mNotifyPinnedStackAnimationStarted, msg); |
| 188 | break; |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 189 | case NOTIFY_PINNED_STACK_ANIMATION_ENDED_LISTENERS_MSG: |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 190 | forAllRemoteListeners(mNotifyPinnedStackAnimationEnded, msg); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 191 | break; |
| 192 | case NOTIFY_FORCED_RESIZABLE_MSG: |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 193 | forAllRemoteListeners(mNotifyActivityForcedResizable, msg); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 194 | break; |
| 195 | case NOTIFY_ACTIVITY_DISMISSING_DOCKED_STACK_MSG: |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 196 | forAllRemoteListeners(mNotifyActivityDismissingDockedStack, msg); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 197 | break; |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 198 | case NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG: |
| 199 | forAllRemoteListeners(mNotifyActivityLaunchOnSecondaryDisplayFailed, msg); |
| 200 | break; |
Robin Lee | c41f6ec | 2017-01-10 17:02:34 +0000 | [diff] [blame] | 201 | case NOTIFY_TASK_PROFILE_LOCKED_LISTENERS_MSG: |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 202 | forAllRemoteListeners(mNotifyTaskProfileLocked, msg); |
Jorim Jaggi | fb9d78a | 2017-01-05 18:57:12 +0100 | [diff] [blame] | 203 | break; |
| 204 | case NOTIFY_TASK_SNAPSHOT_CHANGED_LISTENERS_MSG: |
| 205 | forAllRemoteListeners(mNotifyTaskSnapshotChanged, msg); |
Robin Lee | c41f6ec | 2017-01-10 17:02:34 +0000 | [diff] [blame] | 206 | break; |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 207 | } |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | public TaskChangeNotificationController(ActivityManagerService service, |
| 212 | ActivityStackSupervisor stackSupervisor, Handler handler) { |
| 213 | mService = service; |
| 214 | mStackSupervisor = stackSupervisor; |
| 215 | mHandler = new MainHandler(handler.getLooper()); |
| 216 | } |
| 217 | |
| 218 | public void registerTaskStackListener(ITaskStackListener listener) { |
| 219 | synchronized (mService) { |
| 220 | if (listener != null) { |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 221 | if (Binder.getCallingPid() == android.os.Process.myPid()) { |
| 222 | if (!mLocalTaskStackListeners.contains(listener)) { |
| 223 | mLocalTaskStackListeners.add(listener); |
| 224 | } |
| 225 | } else { |
| 226 | mRemoteTaskStackListeners.register(listener); |
| 227 | } |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 228 | } |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | public void unregisterTaskStackListener(ITaskStackListener listener) { |
| 233 | synchronized (mService) { |
| 234 | if (listener != null) { |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 235 | if (Binder.getCallingPid() == android.os.Process.myPid()) { |
| 236 | mLocalTaskStackListeners.remove(listener); |
| 237 | } else { |
| 238 | mRemoteTaskStackListeners.unregister(listener); |
| 239 | } |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 240 | } |
| 241 | } |
| 242 | } |
| 243 | |
Wale Ogunwale | f1b2ec9 | 2017-06-05 07:09:35 -0700 | [diff] [blame] | 244 | private void forAllRemoteListeners(TaskStackConsumer callback, Message message) { |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 245 | synchronized (mService) { |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 246 | for (int i = mRemoteTaskStackListeners.beginBroadcast() - 1; i >= 0; i--) { |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 247 | try { |
| 248 | // Make a one-way callback to the listener |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 249 | callback.accept(mRemoteTaskStackListeners.getBroadcastItem(i), message); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 250 | } catch (RemoteException e) { |
| 251 | // Handled by the RemoteCallbackList. |
| 252 | } |
| 253 | } |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 254 | mRemoteTaskStackListeners.finishBroadcast(); |
| 255 | } |
| 256 | } |
| 257 | |
Wale Ogunwale | f1b2ec9 | 2017-06-05 07:09:35 -0700 | [diff] [blame] | 258 | private void forAllLocalListeners(TaskStackConsumer callback, Message message) { |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 259 | synchronized (mService) { |
| 260 | for (int i = mLocalTaskStackListeners.size() - 1; i >= 0; i--) { |
| 261 | try { |
| 262 | callback.accept(mLocalTaskStackListeners.get(i), message); |
| 263 | } catch (RemoteException e) { |
| 264 | // Never thrown since this is called locally. |
| 265 | } |
| 266 | } |
| 267 | } |
| 268 | } |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 269 | |
| 270 | /** Notifies all listeners when the task stack has changed. */ |
| 271 | void notifyTaskStackChanged() { |
| 272 | mHandler.sendEmptyMessage(LOG_STACK_STATE_MSG); |
| 273 | mHandler.removeMessages(NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG); |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 274 | final Message msg = mHandler.obtainMessage(NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG); |
| 275 | forAllLocalListeners(mNotifyTaskStackChanged, msg); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 276 | // Only the main task stack change notification requires a delay. |
| 277 | mHandler.sendMessageDelayed(msg, NOTIFY_TASK_STACK_CHANGE_LISTENERS_DELAY); |
| 278 | } |
| 279 | |
| 280 | /** Notifies all listeners when an Activity is pinned. */ |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 281 | void notifyActivityPinned(String packageName, int taskId) { |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 282 | mHandler.removeMessages(NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG); |
Winson Chung | c81c0ce | 2017-03-17 12:27:30 -0700 | [diff] [blame] | 283 | final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG, |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 284 | taskId, 0, packageName); |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 285 | forAllLocalListeners(mNotifyActivityPinned, msg); |
| 286 | msg.sendToTarget(); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Winson Chung | c81c0ce | 2017-03-17 12:27:30 -0700 | [diff] [blame] | 289 | /** Notifies all listeners when an Activity is unpinned. */ |
| 290 | void notifyActivityUnpinned() { |
| 291 | mHandler.removeMessages(NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG); |
| 292 | final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG); |
| 293 | forAllLocalListeners(mNotifyActivityUnpinned, msg); |
| 294 | msg.sendToTarget(); |
| 295 | } |
| 296 | |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 297 | /** |
| 298 | * Notifies all listeners when an attempt was made to start an an activity that is already |
| 299 | * running in the pinned stack and the activity was not actually started, but the task is |
| 300 | * either brought to the front or a new Intent is delivered to it. |
| 301 | */ |
Winson Chung | e6385a2 | 2017-05-02 18:15:16 -0700 | [diff] [blame] | 302 | void notifyPinnedActivityRestartAttempt(boolean clearedTask) { |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 303 | mHandler.removeMessages(NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG); |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 304 | final Message msg = |
Winson Chung | e6385a2 | 2017-05-02 18:15:16 -0700 | [diff] [blame] | 305 | mHandler.obtainMessage(NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG, |
| 306 | clearedTask ? 1 : 0, 0); |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 307 | forAllLocalListeners(mNotifyPinnedActivityRestartAttempt, msg); |
| 308 | msg.sendToTarget(); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Winson Chung | 85d3998 | 2017-02-24 15:21:25 -0800 | [diff] [blame] | 311 | /** Notifies all listeners when the pinned stack animation starts. */ |
| 312 | void notifyPinnedStackAnimationStarted() { |
| 313 | mHandler.removeMessages(NOTIFY_PINNED_STACK_ANIMATION_STARTED_LISTENERS_MSG); |
| 314 | final Message msg = |
| 315 | mHandler.obtainMessage(NOTIFY_PINNED_STACK_ANIMATION_STARTED_LISTENERS_MSG); |
| 316 | forAllLocalListeners(mNotifyPinnedStackAnimationStarted, msg); |
| 317 | msg.sendToTarget(); |
| 318 | } |
| 319 | |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 320 | /** Notifies all listeners when the pinned stack animation ends. */ |
| 321 | void notifyPinnedStackAnimationEnded() { |
| 322 | mHandler.removeMessages(NOTIFY_PINNED_STACK_ANIMATION_ENDED_LISTENERS_MSG); |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 323 | final Message msg = |
| 324 | mHandler.obtainMessage(NOTIFY_PINNED_STACK_ANIMATION_ENDED_LISTENERS_MSG); |
| 325 | forAllLocalListeners(mNotifyPinnedStackAnimationEnded, msg); |
| 326 | msg.sendToTarget(); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | void notifyActivityDismissingDockedStack() { |
| 330 | mHandler.removeMessages(NOTIFY_ACTIVITY_DISMISSING_DOCKED_STACK_MSG); |
Wale Ogunwale | f1b2ec9 | 2017-06-05 07:09:35 -0700 | [diff] [blame] | 331 | final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_DISMISSING_DOCKED_STACK_MSG); |
| 332 | forAllLocalListeners(mNotifyActivityDismissingDockedStack, msg); |
| 333 | msg.sendToTarget(); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 336 | void notifyActivityForcedResizable(int taskId, int reason, String packageName) { |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 337 | mHandler.removeMessages(NOTIFY_FORCED_RESIZABLE_MSG); |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 338 | final Message msg = mHandler.obtainMessage(NOTIFY_FORCED_RESIZABLE_MSG, taskId, reason, |
| 339 | packageName); |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 340 | forAllLocalListeners(mNotifyActivityForcedResizable, msg); |
| 341 | msg.sendToTarget(); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 342 | } |
| 343 | |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 344 | void notifyActivityLaunchOnSecondaryDisplayFailed() { |
| 345 | mHandler.removeMessages(NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG); |
| 346 | final Message msg = mHandler.obtainMessage( |
| 347 | NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG); |
| 348 | forAllLocalListeners(mNotifyActivityLaunchOnSecondaryDisplayFailed, msg); |
| 349 | msg.sendToTarget(); |
| 350 | } |
| 351 | |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 352 | void notifyTaskCreated(int taskId, ComponentName componentName) { |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 353 | final Message msg = mHandler.obtainMessage(NOTIFY_TASK_ADDED_LISTENERS_MSG, |
| 354 | taskId, 0 /* unused */, componentName); |
| 355 | forAllLocalListeners(mNotifyTaskCreated, msg); |
| 356 | msg.sendToTarget(); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | void notifyTaskRemoved(int taskId) { |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 360 | final Message msg = mHandler.obtainMessage(NOTIFY_TASK_REMOVED_LISTENERS_MSG, |
| 361 | taskId, 0 /* unused */); |
| 362 | forAllLocalListeners(mNotifyTaskRemoved, msg); |
| 363 | msg.sendToTarget(); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | void notifyTaskMovedToFront(int taskId) { |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 367 | final Message msg = mHandler.obtainMessage(NOTIFY_TASK_MOVED_TO_FRONT_LISTENERS_MSG, |
| 368 | taskId, 0 /* unused */); |
| 369 | forAllLocalListeners(mNotifyTaskMovedToFront, msg); |
| 370 | msg.sendToTarget(); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | void notifyTaskDescriptionChanged(int taskId, TaskDescription taskDescription) { |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 374 | final Message msg = mHandler.obtainMessage(NOTIFY_TASK_DESCRIPTION_CHANGED_LISTENERS_MSG, |
| 375 | taskId, 0 /* unused */, taskDescription); |
| 376 | forAllLocalListeners(mNotifyTaskDescriptionChanged, msg); |
| 377 | msg.sendToTarget(); |
| 378 | |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | void notifyActivityRequestedOrientationChanged(int taskId, int orientation) { |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 382 | final Message msg = mHandler.obtainMessage( |
| 383 | NOTIFY_ACTIVITY_REQUESTED_ORIENTATION_CHANGED_LISTENERS, taskId, orientation); |
| 384 | forAllLocalListeners(mNotifyActivityRequestedOrientationChanged, msg); |
| 385 | msg.sendToTarget(); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | /** |
| 389 | * Notify listeners that the task is about to be finished before its surfaces are removed from |
| 390 | * the window manager. This allows interested parties to perform relevant animations before |
| 391 | * the window disappears. |
| 392 | */ |
| 393 | void notifyTaskRemovalStarted(int taskId) { |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 394 | final Message msg = mHandler.obtainMessage(NOTIFY_TASK_REMOVAL_STARTED_LISTENERS, taskId, |
| 395 | 0 /* unused */); |
| 396 | forAllLocalListeners(mNotifyTaskRemovalStarted, msg); |
| 397 | msg.sendToTarget(); |
| 398 | |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 399 | } |
Robin Lee | c41f6ec | 2017-01-10 17:02:34 +0000 | [diff] [blame] | 400 | |
| 401 | /** |
| 402 | * Notify listeners that the task has been put in a locked state because one or more of the |
| 403 | * activities inside it belong to a managed profile user that has been locked. |
| 404 | */ |
| 405 | void notifyTaskProfileLocked(int taskId, int userId) { |
Yorke Lee | 1329407 | 2017-01-06 14:59:58 -0800 | [diff] [blame] | 406 | final Message msg = mHandler.obtainMessage(NOTIFY_TASK_PROFILE_LOCKED_LISTENERS_MSG, taskId, |
| 407 | userId); |
| 408 | forAllLocalListeners(mNotifyTaskProfileLocked, msg); |
| 409 | msg.sendToTarget(); |
Robin Lee | c41f6ec | 2017-01-10 17:02:34 +0000 | [diff] [blame] | 410 | } |
Jorim Jaggi | fb9d78a | 2017-01-05 18:57:12 +0100 | [diff] [blame] | 411 | |
| 412 | /** |
| 413 | * Notify listeners that the snapshot of a task has changed. |
| 414 | */ |
| 415 | void notifyTaskSnapshotChanged(int taskId, TaskSnapshot snapshot) { |
| 416 | final Message msg = mHandler.obtainMessage(NOTIFY_TASK_SNAPSHOT_CHANGED_LISTENERS_MSG, |
| 417 | taskId, 0, snapshot); |
| 418 | forAllLocalListeners(mNotifyTaskSnapshotChanged, msg); |
| 419 | msg.sendToTarget(); |
| 420 | } |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 421 | } |