From a5274666922fd70e64142f73122fcb3c622c7c16 Mon Sep 17 00:00:00 2001 From: mattsziklay Date: Tue, 3 Jan 2023 15:25:04 -0800 Subject: [PATCH] Change onTaskInfoChanged to only use display id from task info. Fixes a potential NPE where task appears before display and does not have a valid Display object to reference. Bug: b/264218571 Test: atest MultiWindowTests#testDisallowReparentOperationWhenInLockedTask Change-Id: I9191a1ee85842873bedede9745c9f9b11ea42b99 --- .../android/wm/shell/freeform/FreeformTaskListener.java | 6 +++--- .../wm/shell/fullscreen/FullscreenTaskListener.java | 5 +++-- .../shell/windowdecor/DesktopModeWindowDecorViewModel.java | 7 +++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/freeform/FreeformTaskListener.java b/libs/WindowManager/Shell/src/com/android/wm/shell/freeform/FreeformTaskListener.java index 793bad86d873d..48487bc4a3d60 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/freeform/FreeformTaskListener.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/freeform/FreeformTaskListener.java @@ -129,11 +129,11 @@ public class FreeformTaskListener implements ShellTaskOrganizer.TaskListener, @Override public void onTaskInfoChanged(RunningTaskInfo taskInfo) { final State state = mTasks.get(taskInfo.taskId); - state.mTaskInfo = taskInfo; + ProtoLog.v(ShellProtoLogGroup.WM_SHELL_TASK_ORG, "Freeform Task Info Changed: #%d", taskInfo.taskId); - mWindowDecorationViewModel.onTaskInfoChanged(state.mTaskInfo); - + mWindowDecorationViewModel.onTaskInfoChanged(taskInfo); + state.mTaskInfo = taskInfo; if (DesktopModeStatus.isAnyEnabled()) { mDesktopModeTaskRepository.ifPresent(repository -> { if (taskInfo.isVisible) { diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/fullscreen/FullscreenTaskListener.java b/libs/WindowManager/Shell/src/com/android/wm/shell/fullscreen/FullscreenTaskListener.java index 6623f5ca84eef..b9caf62012a61 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/fullscreen/FullscreenTaskListener.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/fullscreen/FullscreenTaskListener.java @@ -123,10 +123,11 @@ public class FullscreenTaskListener implements ShellTaskOrganizer.TaskListener { public void onTaskInfoChanged(RunningTaskInfo taskInfo) { final State state = mTasks.get(taskInfo.taskId); final Point oldPositionInParent = state.mTaskInfo.positionInParent; - state.mTaskInfo = taskInfo; + if (mWindowDecorViewModelOptional.isPresent()) { - mWindowDecorViewModelOptional.get().onTaskInfoChanged(state.mTaskInfo); + mWindowDecorViewModelOptional.get().onTaskInfoChanged(taskInfo); } + state.mTaskInfo = taskInfo; if (Transitions.ENABLE_SHELL_TRANSITIONS) return; updateRecentsForVisibleFullscreenTask(taskInfo); diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java index b500f5fb01550..4f7a7522e1bec 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java @@ -153,12 +153,11 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel { @Override public void onTaskInfoChanged(RunningTaskInfo taskInfo) { final DesktopModeWindowDecoration decoration = mWindowDecorByTaskId.get(taskInfo.taskId); - if (decoration == null) return; + final RunningTaskInfo oldTaskInfo = decoration.mTaskInfo; - int oldDisplayId = decoration.mDisplay.getDisplayId(); - if (taskInfo.displayId != oldDisplayId) { - removeTaskFromEventReceiver(oldDisplayId); + if (taskInfo.displayId != oldTaskInfo.displayId) { + removeTaskFromEventReceiver(oldTaskInfo.displayId); incrementEventReceiverTasks(taskInfo.displayId); }