From b126897bda5e8d9dbb8e17b961f9e5bb93ef9c87 Mon Sep 17 00:00:00 2001 From: Saho Kobayashi Date: Thu, 31 Oct 2024 15:36:42 +0900 Subject: Update the global focus state on onTaskInfoChanged without flag decoration.mHasGlobalFocus is updated through ShellTransitions before onTaskInfoChanged when the enableDisplayFocusInShellTransitions flag is on, but not without the flag. We need to update the mHasGlobalFocus when the flag is off on onTaskInfoChanged. Bug: 374159712 Flag: com.android.window.flags.enable_display_focus_in_shell_transitions Test: atest DesktopModelWindowDecorViewModelTests Change-Id: I64bf847bd15cc29b9714ca60ae5a8766e9f350b7 --- .../windowdecor/CaptionWindowDecorViewModel.java | 11 ++++-- .../DesktopModeWindowDecorViewModel.java | 8 ++++- .../DesktopModeWindowDecorViewModelTests.kt | 42 ++++++++++++++++++++++ 3 files changed, 58 insertions(+), 3 deletions(-) (limited to 'libs') diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecorViewModel.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecorViewModel.java index be4fd7c5eeec..7265fb8f8027 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecorViewModel.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecorViewModel.java @@ -24,6 +24,8 @@ import static android.content.pm.PackageManager.FEATURE_PC; import static android.provider.Settings.Global.DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS; import static android.view.WindowManager.TRANSIT_CHANGE; +import static com.android.window.flags.Flags.enableDisplayFocusInShellTransitions; + import android.app.ActivityManager.RunningTaskInfo; import android.content.ContentResolver; import android.content.Context; @@ -195,7 +197,12 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel, FocusT return; } - decoration.relayout(taskInfo, decoration.mHasGlobalFocus); + if (enableDisplayFocusInShellTransitions()) { + // Pass the current global focus status to avoid updates outside of a ShellTransition. + decoration.relayout(taskInfo, decoration.mHasGlobalFocus); + } else { + decoration.relayout(taskInfo, taskInfo.isFocused); + } } @Override @@ -496,4 +503,4 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel, FocusT return Settings.Global.getInt(resolver, DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS, 0) != 0; } -} \ No newline at end of file +} 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 29b8ddd03970..89ff43aae093 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 @@ -31,6 +31,7 @@ import static android.view.MotionEvent.ACTION_UP; import static android.view.WindowInsets.Type.statusBars; import static com.android.internal.jank.Cuj.CUJ_DESKTOP_MODE_ENTER_MODE_APP_HANDLE_MENU; +import static com.android.window.flags.Flags.enableDisplayFocusInShellTransitions; import static com.android.wm.shell.compatui.AppCompatUtils.isTopActivityExemptFromDesktopWindowing; import static com.android.wm.shell.desktopmode.DesktopModeEventLogger.Companion.ResizeTrigger; import static com.android.wm.shell.desktopmode.DesktopModeVisualIndicator.IndicatorType.TO_FULLSCREEN_INDICATOR; @@ -474,7 +475,12 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel, removeTaskFromEventReceiver(oldTaskInfo.displayId); incrementEventReceiverTasks(taskInfo.displayId); } - decoration.relayout(taskInfo, decoration.mHasGlobalFocus); + if (enableDisplayFocusInShellTransitions()) { + // Pass the current global focus status to avoid updates outside of a ShellTransition. + decoration.relayout(taskInfo, decoration.mHasGlobalFocus); + } else { + decoration.relayout(taskInfo, taskInfo.isFocused); + } mActivityOrientationChangeHandler.ifPresent(handler -> handler.handleActivityOrientationChange(oldTaskInfo, taskInfo)); } diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModelTests.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModelTests.kt index 36c5be1d7191..1267b7c967a0 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModelTests.kt +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModelTests.kt @@ -1318,6 +1318,48 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() { verify(decor).closeMaximizeMenu() } + @Test + @EnableFlags(Flags.FLAG_ENABLE_DISPLAY_FOCUS_IN_SHELL_TRANSITIONS) + fun testOnTaskInfoChanged_enableShellTransitionsFlag() { + val task = createTask( + windowingMode = WINDOWING_MODE_FREEFORM + ) + val taskSurface = SurfaceControl() + val decoration = setUpMockDecorationForTask(task) + + onTaskOpening(task, taskSurface) + assertTrue(windowDecorByTaskIdSpy.contains(task.taskId)) + + decoration.mHasGlobalFocus = true + desktopModeWindowDecorViewModel.onTaskInfoChanged(task) + verify(decoration).relayout(task, true) + + decoration.mHasGlobalFocus = false + desktopModeWindowDecorViewModel.onTaskInfoChanged(task) + verify(decoration).relayout(task, false) + } + + @Test + @DisableFlags(Flags.FLAG_ENABLE_DISPLAY_FOCUS_IN_SHELL_TRANSITIONS) + fun testOnTaskInfoChanged_disableShellTransitionsFlag() { + val task = createTask( + windowingMode = WINDOWING_MODE_FREEFORM + ) + val taskSurface = SurfaceControl() + val decoration = setUpMockDecorationForTask(task) + + onTaskOpening(task, taskSurface) + assertTrue(windowDecorByTaskIdSpy.contains(task.taskId)) + + task.isFocused = true + desktopModeWindowDecorViewModel.onTaskInfoChanged(task) + verify(decoration).relayout(task, true) + + task.isFocused = false + desktopModeWindowDecorViewModel.onTaskInfoChanged(task) + verify(decoration).relayout(task, false) + } + private fun createOpenTaskDecoration( @WindowingMode windowingMode: Int, taskSurface: SurfaceControl = SurfaceControl(), -- cgit v1.2.3-59-g8ed1b