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