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.wm; 18 19 import android.app.ActivityManager; 20 import android.app.ActivityManager.RunningTaskInfo; 21 import android.app.ITaskStackListener; 22 import android.app.TaskInfo; 23 import android.content.ComponentName; 24 import android.os.Binder; 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 import android.window.TaskSnapshot; 31 32 import com.android.internal.os.SomeArgs; 33 34 import java.util.ArrayList; 35 36 class TaskChangeNotificationController { 37 private static final int LOG_TASK_STATE_MSG = 1; 38 private static final int NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG = 2; 39 private static final int NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG = 3; 40 private static final int NOTIFY_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG = 4; 41 private static final int NOTIFY_FORCED_RESIZABLE_MSG = 6; 42 private static final int NOTIFY_ACTIVITY_DISMISSING_DOCKED_ROOT_TASK_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_ACTIVITY_UNPINNED_LISTENERS_MSG = 17; 52 private static final int NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG = 18; 53 private static final int NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_REROUTED_MSG = 19; 54 private static final int NOTIFY_BACK_PRESSED_ON_TASK_ROOT = 20; 55 private static final int NOTIFY_TASK_DISPLAY_CHANGED_LISTENERS_MSG = 21; 56 private static final int NOTIFY_TASK_LIST_UPDATED_LISTENERS_MSG = 22; 57 private static final int NOTIFY_TASK_LIST_FROZEN_UNFROZEN_MSG = 23; 58 private static final int NOTIFY_TASK_FOCUS_CHANGED_MSG = 24; 59 private static final int NOTIFY_TASK_REQUESTED_ORIENTATION_CHANGED_MSG = 25; 60 private static final int NOTIFY_ACTIVITY_ROTATED_MSG = 26; 61 private static final int NOTIFY_TASK_MOVED_TO_BACK_LISTENERS_MSG = 27; 62 private static final int NOTIFY_LOCK_TASK_MODE_CHANGED_MSG = 28; 63 64 // Delay in notifying task stack change listeners (in millis) 65 private static final int NOTIFY_TASK_STACK_CHANGE_LISTENERS_DELAY = 100; 66 67 // Global lock used by the service the instantiate objects of this class. 68 private final Object mServiceLock; 69 private final ActivityTaskSupervisor mTaskSupervisor; 70 private final Handler mHandler; 71 72 // Task stack change listeners in a remote process. 73 private final RemoteCallbackList<ITaskStackListener> mRemoteTaskStackListeners = 74 new RemoteCallbackList<>(); 75 76 /* 77 * Task stack change listeners in a local process. Tracked separately so that they can be 78 * called on the same thread. 79 */ 80 private final ArrayList<ITaskStackListener> mLocalTaskStackListeners = new ArrayList<>(); 81 82 private final TaskStackConsumer mNotifyTaskStackChanged = (l, m) -> { 83 l.onTaskStackChanged(); 84 }; 85 86 private final TaskStackConsumer mNotifyTaskCreated = (l, m) -> { 87 l.onTaskCreated(m.arg1, (ComponentName) m.obj); 88 }; 89 90 private final TaskStackConsumer mNotifyTaskRemoved = (l, m) -> { 91 l.onTaskRemoved(m.arg1); 92 }; 93 94 private final TaskStackConsumer mNotifyTaskMovedToFront = (l, m) -> { 95 l.onTaskMovedToFront((RunningTaskInfo) m.obj); 96 }; 97 98 private final TaskStackConsumer mNotifyTaskDescriptionChanged = (l, m) -> { 99 l.onTaskDescriptionChanged((RunningTaskInfo) m.obj); 100 }; 101 102 private final TaskStackConsumer mNotifyBackPressedOnTaskRoot = (l, m) -> { 103 l.onBackPressedOnTaskRoot((RunningTaskInfo) m.obj); 104 }; 105 106 private final TaskStackConsumer mNotifyActivityRequestedOrientationChanged = (l, m) -> { 107 l.onActivityRequestedOrientationChanged(m.arg1, m.arg2); 108 }; 109 110 private final TaskStackConsumer mNotifyTaskRemovalStarted = (l, m) -> { 111 l.onTaskRemovalStarted((RunningTaskInfo) m.obj); 112 }; 113 114 private final TaskStackConsumer mNotifyActivityPinned = (l, m) -> { 115 l.onActivityPinned((String) m.obj /* packageName */, m.sendingUid /* userId */, 116 m.arg1 /* taskId */, m.arg2 /* stackId */); 117 }; 118 119 private final TaskStackConsumer mNotifyActivityUnpinned = (l, m) -> { 120 l.onActivityUnpinned(); 121 }; 122 123 private final TaskStackConsumer mNotifyActivityRestartAttempt = (l, m) -> { 124 SomeArgs args = (SomeArgs) m.obj; 125 l.onActivityRestartAttempt((RunningTaskInfo) args.arg1, args.argi1 != 0, 126 args.argi2 != 0, args.argi3 != 0); 127 }; 128 129 private final TaskStackConsumer mNotifyActivityForcedResizable = (l, m) -> { 130 l.onActivityForcedResizable((String) m.obj, m.arg1, m.arg2); 131 }; 132 133 private final TaskStackConsumer mNotifyActivityDismissingDockedTask = (l, m) -> { 134 l.onActivityDismissingDockedTask(); 135 }; 136 137 private final TaskStackConsumer mNotifyActivityLaunchOnSecondaryDisplayFailed = (l, m) -> { 138 l.onActivityLaunchOnSecondaryDisplayFailed((RunningTaskInfo) m.obj, m.arg1); 139 }; 140 141 private final TaskStackConsumer mNotifyActivityLaunchOnSecondaryDisplayRerouted = (l, m) -> { 142 l.onActivityLaunchOnSecondaryDisplayRerouted((RunningTaskInfo) m.obj, m.arg1); 143 }; 144 145 private final TaskStackConsumer mNotifyTaskProfileLocked = (l, m) -> { 146 l.onTaskProfileLocked(m.arg1, m.arg2); 147 }; 148 149 private final TaskStackConsumer mNotifyTaskSnapshotChanged = (l, m) -> { 150 l.onTaskSnapshotChanged(m.arg1, (TaskSnapshot) m.obj); 151 }; 152 153 private final TaskStackConsumer mNotifyTaskDisplayChanged = (l, m) -> { 154 l.onTaskDisplayChanged(m.arg1, m.arg2); 155 }; 156 157 private final TaskStackConsumer mNotifyTaskListUpdated = (l, m) -> { 158 l.onRecentTaskListUpdated(); 159 }; 160 161 private final TaskStackConsumer mNotifyTaskListFrozen = (l, m) -> { 162 l.onRecentTaskListFrozenChanged(m.arg1 != 0); 163 }; 164 165 private final TaskStackConsumer mNotifyTaskFocusChanged = (l, m) -> { 166 l.onTaskFocusChanged(m.arg1, m.arg2 != 0); 167 }; 168 169 private final TaskStackConsumer mNotifyTaskRequestedOrientationChanged = (l, m) -> { 170 l.onTaskRequestedOrientationChanged(m.arg1, m.arg2); 171 }; 172 173 private final TaskStackConsumer mNotifyOnActivityRotation = (l, m) -> { 174 l.onActivityRotation(m.arg1); 175 }; 176 177 private final TaskStackConsumer mNotifyTaskMovedToBack = (l, m) -> { 178 l.onTaskMovedToBack((RunningTaskInfo) m.obj); 179 }; 180 181 private final TaskStackConsumer mNotifyLockTaskModeChanged = (l, m) -> { 182 l.onLockTaskModeChanged(m.arg1); 183 }; 184 185 @FunctionalInterface 186 public interface TaskStackConsumer { accept(ITaskStackListener t, Message m)187 void accept(ITaskStackListener t, Message m) throws RemoteException; 188 } 189 190 private class MainHandler extends Handler { MainHandler(Looper looper)191 public MainHandler(Looper looper) { 192 super(looper); 193 } 194 195 @Override handleMessage(Message msg)196 public void handleMessage(Message msg) { 197 switch (msg.what) { 198 case LOG_TASK_STATE_MSG: { 199 synchronized (mServiceLock) { 200 mTaskSupervisor.logRootTaskState(); 201 } 202 break; 203 } 204 case NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG: 205 forAllRemoteListeners(mNotifyTaskStackChanged, msg); 206 break; 207 case NOTIFY_TASK_ADDED_LISTENERS_MSG: 208 forAllRemoteListeners(mNotifyTaskCreated, msg); 209 break; 210 case NOTIFY_TASK_REMOVED_LISTENERS_MSG: 211 forAllRemoteListeners(mNotifyTaskRemoved, msg); 212 break; 213 case NOTIFY_TASK_MOVED_TO_FRONT_LISTENERS_MSG: 214 forAllRemoteListeners(mNotifyTaskMovedToFront, msg); 215 break; 216 case NOTIFY_TASK_DESCRIPTION_CHANGED_LISTENERS_MSG: 217 forAllRemoteListeners(mNotifyTaskDescriptionChanged, msg); 218 break; 219 case NOTIFY_ACTIVITY_REQUESTED_ORIENTATION_CHANGED_LISTENERS: 220 forAllRemoteListeners(mNotifyActivityRequestedOrientationChanged, msg); 221 break; 222 case NOTIFY_TASK_REMOVAL_STARTED_LISTENERS: 223 forAllRemoteListeners(mNotifyTaskRemovalStarted, msg); 224 break; 225 case NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG: 226 forAllRemoteListeners(mNotifyActivityPinned, msg); 227 break; 228 case NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG: 229 forAllRemoteListeners(mNotifyActivityUnpinned, msg); 230 break; 231 case NOTIFY_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG: 232 forAllRemoteListeners(mNotifyActivityRestartAttempt, msg); 233 break; 234 case NOTIFY_FORCED_RESIZABLE_MSG: 235 forAllRemoteListeners(mNotifyActivityForcedResizable, msg); 236 break; 237 case NOTIFY_ACTIVITY_DISMISSING_DOCKED_ROOT_TASK_MSG: 238 forAllRemoteListeners(mNotifyActivityDismissingDockedTask, msg); 239 break; 240 case NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG: 241 forAllRemoteListeners(mNotifyActivityLaunchOnSecondaryDisplayFailed, msg); 242 break; 243 case NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_REROUTED_MSG: 244 forAllRemoteListeners(mNotifyActivityLaunchOnSecondaryDisplayRerouted, msg); 245 break; 246 case NOTIFY_TASK_PROFILE_LOCKED_LISTENERS_MSG: 247 forAllRemoteListeners(mNotifyTaskProfileLocked, msg); 248 break; 249 case NOTIFY_TASK_SNAPSHOT_CHANGED_LISTENERS_MSG: 250 forAllRemoteListeners(mNotifyTaskSnapshotChanged, msg); 251 break; 252 case NOTIFY_BACK_PRESSED_ON_TASK_ROOT: 253 forAllRemoteListeners(mNotifyBackPressedOnTaskRoot, msg); 254 break; 255 case NOTIFY_TASK_DISPLAY_CHANGED_LISTENERS_MSG: 256 forAllRemoteListeners(mNotifyTaskDisplayChanged, msg); 257 break; 258 case NOTIFY_TASK_LIST_UPDATED_LISTENERS_MSG: 259 forAllRemoteListeners(mNotifyTaskListUpdated, msg); 260 break; 261 case NOTIFY_TASK_LIST_FROZEN_UNFROZEN_MSG: 262 forAllRemoteListeners(mNotifyTaskListFrozen, msg); 263 break; 264 case NOTIFY_TASK_FOCUS_CHANGED_MSG: 265 forAllRemoteListeners(mNotifyTaskFocusChanged, msg); 266 break; 267 case NOTIFY_TASK_REQUESTED_ORIENTATION_CHANGED_MSG: 268 forAllRemoteListeners(mNotifyTaskRequestedOrientationChanged, msg); 269 break; 270 case NOTIFY_ACTIVITY_ROTATED_MSG: 271 forAllRemoteListeners(mNotifyOnActivityRotation, msg); 272 break; 273 case NOTIFY_TASK_MOVED_TO_BACK_LISTENERS_MSG: 274 forAllRemoteListeners(mNotifyTaskMovedToBack, msg); 275 break; 276 case NOTIFY_LOCK_TASK_MODE_CHANGED_MSG: 277 forAllRemoteListeners(mNotifyLockTaskModeChanged, msg); 278 break; 279 } 280 if (msg.obj instanceof SomeArgs) { 281 ((SomeArgs) msg.obj).recycle(); 282 } 283 } 284 } 285 TaskChangeNotificationController(Object serviceLock, ActivityTaskSupervisor taskSupervisor, Handler handler)286 public TaskChangeNotificationController(Object serviceLock, 287 ActivityTaskSupervisor taskSupervisor, Handler handler) { 288 mServiceLock = serviceLock; 289 mTaskSupervisor = taskSupervisor; 290 mHandler = new MainHandler(handler.getLooper()); 291 } 292 registerTaskStackListener(ITaskStackListener listener)293 public void registerTaskStackListener(ITaskStackListener listener) { 294 synchronized (mServiceLock) { 295 if (listener != null) { 296 if (Binder.getCallingPid() == android.os.Process.myPid()) { 297 if (!mLocalTaskStackListeners.contains(listener)) { 298 mLocalTaskStackListeners.add(listener); 299 } 300 } else { 301 mRemoteTaskStackListeners.register(listener); 302 } 303 } 304 } 305 } 306 unregisterTaskStackListener(ITaskStackListener listener)307 public void unregisterTaskStackListener(ITaskStackListener listener) { 308 synchronized (mServiceLock) { 309 if (listener != null) { 310 if (Binder.getCallingPid() == android.os.Process.myPid()) { 311 mLocalTaskStackListeners.remove(listener); 312 } else { 313 mRemoteTaskStackListeners.unregister(listener); 314 } 315 } 316 } 317 } 318 forAllRemoteListeners(TaskStackConsumer callback, Message message)319 private void forAllRemoteListeners(TaskStackConsumer callback, Message message) { 320 synchronized (mServiceLock) { 321 for (int i = mRemoteTaskStackListeners.beginBroadcast() - 1; i >= 0; i--) { 322 try { 323 // Make a one-way callback to the listener 324 callback.accept(mRemoteTaskStackListeners.getBroadcastItem(i), message); 325 } catch (RemoteException e) { 326 // Handled by the RemoteCallbackList. 327 } 328 } 329 mRemoteTaskStackListeners.finishBroadcast(); 330 } 331 } 332 forAllLocalListeners(TaskStackConsumer callback, Message message)333 private void forAllLocalListeners(TaskStackConsumer callback, Message message) { 334 synchronized (mServiceLock) { 335 for (int i = mLocalTaskStackListeners.size() - 1; i >= 0; i--) { 336 try { 337 callback.accept(mLocalTaskStackListeners.get(i), message); 338 } catch (RemoteException e) { 339 // Never thrown since this is called locally. 340 } 341 } 342 } 343 } 344 345 /** Notifies all listeners when the task stack has changed. */ notifyTaskStackChanged()346 void notifyTaskStackChanged() { 347 mHandler.sendEmptyMessage(LOG_TASK_STATE_MSG); 348 mHandler.removeMessages(NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG); 349 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG); 350 forAllLocalListeners(mNotifyTaskStackChanged, msg); 351 // Only the main task stack change notification requires a delay. 352 mHandler.sendMessageDelayed(msg, NOTIFY_TASK_STACK_CHANGE_LISTENERS_DELAY); 353 } 354 355 /** Notifies all listeners when an Activity is pinned. */ notifyActivityPinned(ActivityRecord r)356 void notifyActivityPinned(ActivityRecord r) { 357 mHandler.removeMessages(NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG); 358 final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG, 359 r.getTask().mTaskId, r.getRootTaskId(), r.packageName); 360 msg.sendingUid = r.mUserId; 361 forAllLocalListeners(mNotifyActivityPinned, msg); 362 msg.sendToTarget(); 363 } 364 365 /** Notifies all listeners when an Activity is unpinned. */ notifyActivityUnpinned()366 void notifyActivityUnpinned() { 367 mHandler.removeMessages(NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG); 368 final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG); 369 forAllLocalListeners(mNotifyActivityUnpinned, msg); 370 msg.sendToTarget(); 371 } 372 373 /** 374 * Notifies all listeners when an attempt was made to start an an activity that is already 375 * running, but the task is either brought to the front or a new Intent is delivered to it. 376 */ notifyActivityRestartAttempt(RunningTaskInfo task, boolean homeTaskVisible, boolean clearedTask, boolean wasVisible)377 void notifyActivityRestartAttempt(RunningTaskInfo task, boolean homeTaskVisible, 378 boolean clearedTask, boolean wasVisible) { 379 mHandler.removeMessages(NOTIFY_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG); 380 final SomeArgs args = SomeArgs.obtain(); 381 args.arg1 = task; 382 args.argi1 = homeTaskVisible ? 1 : 0; 383 args.argi2 = clearedTask ? 1 : 0; 384 args.argi3 = wasVisible ? 1 : 0; 385 final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG, 386 args); 387 forAllLocalListeners(mNotifyActivityRestartAttempt, msg); 388 msg.sendToTarget(); 389 } 390 notifyActivityDismissingDockedRootTask()391 void notifyActivityDismissingDockedRootTask() { 392 mHandler.removeMessages(NOTIFY_ACTIVITY_DISMISSING_DOCKED_ROOT_TASK_MSG); 393 final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_DISMISSING_DOCKED_ROOT_TASK_MSG); 394 forAllLocalListeners(mNotifyActivityDismissingDockedTask, msg); 395 msg.sendToTarget(); 396 } 397 notifyActivityForcedResizable(int taskId, int reason, String packageName)398 void notifyActivityForcedResizable(int taskId, int reason, String packageName) { 399 mHandler.removeMessages(NOTIFY_FORCED_RESIZABLE_MSG); 400 final Message msg = mHandler.obtainMessage(NOTIFY_FORCED_RESIZABLE_MSG, taskId, reason, 401 packageName); 402 forAllLocalListeners(mNotifyActivityForcedResizable, msg); 403 msg.sendToTarget(); 404 } 405 notifyActivityLaunchOnSecondaryDisplayFailed(TaskInfo ti, int requestedDisplayId)406 void notifyActivityLaunchOnSecondaryDisplayFailed(TaskInfo ti, int requestedDisplayId) { 407 mHandler.removeMessages(NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG); 408 final Message msg = mHandler.obtainMessage( 409 NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG, requestedDisplayId, 410 0 /* unused */, ti); 411 forAllLocalListeners(mNotifyActivityLaunchOnSecondaryDisplayFailed, msg); 412 msg.sendToTarget(); 413 } 414 notifyActivityLaunchOnSecondaryDisplayRerouted(TaskInfo ti, int requestedDisplayId)415 void notifyActivityLaunchOnSecondaryDisplayRerouted(TaskInfo ti, int requestedDisplayId) { 416 mHandler.removeMessages(NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_REROUTED_MSG); 417 final Message msg = mHandler.obtainMessage( 418 NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_REROUTED_MSG, requestedDisplayId, 419 0 /* unused */, ti); 420 forAllLocalListeners(mNotifyActivityLaunchOnSecondaryDisplayRerouted, msg); 421 msg.sendToTarget(); 422 } 423 notifyTaskCreated(int taskId, ComponentName componentName)424 void notifyTaskCreated(int taskId, ComponentName componentName) { 425 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_ADDED_LISTENERS_MSG, 426 taskId, 0 /* unused */, componentName); 427 forAllLocalListeners(mNotifyTaskCreated, msg); 428 msg.sendToTarget(); 429 } 430 notifyTaskRemoved(int taskId)431 void notifyTaskRemoved(int taskId) { 432 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_REMOVED_LISTENERS_MSG, 433 taskId, 0 /* unused */); 434 forAllLocalListeners(mNotifyTaskRemoved, msg); 435 msg.sendToTarget(); 436 } 437 notifyTaskMovedToFront(TaskInfo ti)438 void notifyTaskMovedToFront(TaskInfo ti) { 439 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_MOVED_TO_FRONT_LISTENERS_MSG, ti); 440 forAllLocalListeners(mNotifyTaskMovedToFront, msg); 441 msg.sendToTarget(); 442 } 443 notifyTaskDescriptionChanged(TaskInfo taskInfo)444 void notifyTaskDescriptionChanged(TaskInfo taskInfo) { 445 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_DESCRIPTION_CHANGED_LISTENERS_MSG, 446 taskInfo); 447 forAllLocalListeners(mNotifyTaskDescriptionChanged, msg); 448 msg.sendToTarget(); 449 450 } 451 notifyActivityRequestedOrientationChanged(int taskId, int orientation)452 void notifyActivityRequestedOrientationChanged(int taskId, int orientation) { 453 final Message msg = mHandler.obtainMessage( 454 NOTIFY_ACTIVITY_REQUESTED_ORIENTATION_CHANGED_LISTENERS, taskId, orientation); 455 forAllLocalListeners(mNotifyActivityRequestedOrientationChanged, msg); 456 msg.sendToTarget(); 457 } 458 459 /** 460 * Notify listeners that the task is about to be finished before its surfaces are removed from 461 * the window manager. This allows interested parties to perform relevant animations before 462 * the window disappears. 463 */ notifyTaskRemovalStarted(ActivityManager.RunningTaskInfo taskInfo)464 void notifyTaskRemovalStarted(ActivityManager.RunningTaskInfo taskInfo) { 465 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_REMOVAL_STARTED_LISTENERS, taskInfo); 466 forAllLocalListeners(mNotifyTaskRemovalStarted, msg); 467 msg.sendToTarget(); 468 } 469 470 /** 471 * Notify listeners that the task has been put in a locked state because one or more of the 472 * activities inside it belong to a managed profile user that has been locked. 473 */ notifyTaskProfileLocked(int taskId, int userId)474 void notifyTaskProfileLocked(int taskId, int userId) { 475 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_PROFILE_LOCKED_LISTENERS_MSG, taskId, 476 userId); 477 forAllLocalListeners(mNotifyTaskProfileLocked, msg); 478 msg.sendToTarget(); 479 } 480 481 /** 482 * Notify listeners that the snapshot of a task has changed. 483 */ notifyTaskSnapshotChanged(int taskId, TaskSnapshot snapshot)484 void notifyTaskSnapshotChanged(int taskId, TaskSnapshot snapshot) { 485 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_SNAPSHOT_CHANGED_LISTENERS_MSG, 486 taskId, 0, snapshot); 487 forAllLocalListeners(mNotifyTaskSnapshotChanged, msg); 488 msg.sendToTarget(); 489 } 490 491 /** 492 * Notify listeners that an activity received a back press when there are no other activities 493 * in the back stack. 494 */ notifyBackPressedOnTaskRoot(TaskInfo taskInfo)495 void notifyBackPressedOnTaskRoot(TaskInfo taskInfo) { 496 final Message msg = mHandler.obtainMessage(NOTIFY_BACK_PRESSED_ON_TASK_ROOT, 497 taskInfo); 498 forAllLocalListeners(mNotifyBackPressedOnTaskRoot, msg); 499 msg.sendToTarget(); 500 } 501 502 /** 503 * Notify listeners that a task is reparented to another display. 504 */ notifyTaskDisplayChanged(int taskId, int newDisplayId)505 void notifyTaskDisplayChanged(int taskId, int newDisplayId) { 506 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_DISPLAY_CHANGED_LISTENERS_MSG, 507 taskId, newDisplayId); 508 forAllLocalListeners(mNotifyTaskDisplayChanged, msg); 509 msg.sendToTarget(); 510 } 511 512 /** 513 * Called when any additions or deletions to the recent tasks list have been made. 514 */ notifyTaskListUpdated()515 void notifyTaskListUpdated() { 516 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_LIST_UPDATED_LISTENERS_MSG); 517 forAllLocalListeners(mNotifyTaskListUpdated, msg); 518 msg.sendToTarget(); 519 } 520 521 /** @see ITaskStackListener#onRecentTaskListFrozenChanged(boolean) */ notifyTaskListFrozen(boolean frozen)522 void notifyTaskListFrozen(boolean frozen) { 523 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_LIST_FROZEN_UNFROZEN_MSG, 524 frozen ? 1 : 0, 0 /* unused */); 525 forAllLocalListeners(mNotifyTaskListFrozen, msg); 526 msg.sendToTarget(); 527 } 528 529 /** @see ITaskStackListener#onTaskFocusChanged(int, boolean) */ notifyTaskFocusChanged(int taskId, boolean focused)530 void notifyTaskFocusChanged(int taskId, boolean focused) { 531 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_FOCUS_CHANGED_MSG, 532 taskId, focused ? 1 : 0); 533 forAllLocalListeners(mNotifyTaskFocusChanged, msg); 534 msg.sendToTarget(); 535 } 536 537 /** @see android.app.ITaskStackListener#onTaskRequestedOrientationChanged(int, int) */ notifyTaskRequestedOrientationChanged(int taskId, int requestedOrientation)538 void notifyTaskRequestedOrientationChanged(int taskId, int requestedOrientation) { 539 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_REQUESTED_ORIENTATION_CHANGED_MSG, 540 taskId, requestedOrientation); 541 forAllLocalListeners(mNotifyTaskRequestedOrientationChanged, msg); 542 msg.sendToTarget(); 543 } 544 545 /** @see android.app.ITaskStackListener#onActivityRotation(int) */ notifyOnActivityRotation(int displayId)546 void notifyOnActivityRotation(int displayId) { 547 final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_ROTATED_MSG, 548 displayId, 0 /* unused */); 549 forAllLocalListeners(mNotifyOnActivityRotation, msg); 550 msg.sendToTarget(); 551 } 552 553 /** 554 * Notify that a task is being moved behind home. 555 */ notifyTaskMovedToBack(TaskInfo ti)556 void notifyTaskMovedToBack(TaskInfo ti) { 557 final Message msg = mHandler.obtainMessage(NOTIFY_TASK_MOVED_TO_BACK_LISTENERS_MSG, ti); 558 forAllLocalListeners(mNotifyTaskMovedToBack, msg); 559 msg.sendToTarget(); 560 } 561 notifyLockTaskModeChanged(int lockTaskModeState)562 void notifyLockTaskModeChanged(int lockTaskModeState) { 563 final Message msg = mHandler.obtainMessage(NOTIFY_LOCK_TASK_MODE_CHANGED_MSG, 564 lockTaskModeState, 0 /* unused */); 565 forAllLocalListeners(mNotifyLockTaskModeChanged, msg); 566 msg.sendToTarget(); 567 } 568 } 569