Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b126897b authored by Saho Kobayashi's avatar Saho Kobayashi
Browse files

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
parent 11e9c08f
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -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;
        }

        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
+7 −1
Original line number Diff line number Diff line
@@ -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);
        }
        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));
    }
+42 −0
Original line number Diff line number Diff line
@@ -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(),