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

Commit dc9e9e4c authored by Orhan Uysal's avatar Orhan Uysal
Browse files

Fix app moving when screen is unlocked.

Fix the app moving to bottom right when the screen is unlocked
during desktop mode. This is fixed by blocking the relayout during
keyguard transition. Although this fix works, there is an underlying
problem with relayout that needs to be addressed. This can be found in
detail on  b/274674365.

Test: Manual
Test: atest DesktopModeWindowDecorViewModelTests
Bug: 296919650
Change-Id: I605bf7005c4a71d4a22193e25c7964b59e0db356
parent fc5aebdb
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;
import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
import static android.view.WindowInsets.Type.statusBars;
import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY;

import static com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSITION_BOTTOM_OR_RIGHT;
import static com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSITION_TOP_OR_LEFT;
@@ -221,7 +222,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
        mRecentsTransitionHandler.addTransitionStateListener(new RecentsTransitionStateListener() {
            @Override
            public void onTransitionStarted(IBinder transition) {
                onRecentsTransitionStarted(transition);
                blockRelayoutOnTransitionStarted(transition);
            }
        });
        mShellCommandHandler.addDumpCallback(this::dump, this);
@@ -281,6 +282,10 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
            if (decor != null) {
                decor.addTransitionPausingRelayout(transition);
            }
        } else if (change.getMode() == WindowManager.TRANSIT_TO_FRONT
                && ((info.getFlags() & TRANSIT_FLAG_KEYGUARD_GOING_AWAY) != 0)
                && change.getTaskInfo() != null) {
            blockRelayoutOnTransitionStarted(transition);
        }
    }

@@ -358,7 +363,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
        }
    }

    private void onRecentsTransitionStarted(IBinder transition) {
    private void blockRelayoutOnTransitionStarted(IBinder transition) {
        // Block relayout on window decorations originating from #onTaskInfoChanges until the
        // animation completes to avoid interfering with the transition animation.
        for (int i = 0; i < mWindowDecorByTaskId.size(); i++) {
+29 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED
import android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM
import android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN
import android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED
import android.content.Context
import android.graphics.Rect
import android.hardware.display.DisplayManager
import android.hardware.display.VirtualDisplay
@@ -39,7 +40,8 @@ import android.view.SurfaceControl
import android.view.SurfaceView
import android.view.WindowInsets.Type.navigationBars
import android.view.WindowInsets.Type.statusBars
import androidx.core.content.getSystemService
import android.view.WindowManager
import android.window.TransitionInfo
import androidx.test.filters.SmallTest
import com.android.wm.shell.RootTaskDisplayAreaOrganizer
import com.android.wm.shell.ShellTaskOrganizer
@@ -290,6 +292,30 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() {
        verify(decoration).addTransitionPausingRelayout(transition)
    }

    @Test
    fun testRelayoutBlockedDuringKeyguardTransition() {
        val transition = mock(IBinder::class.java)
        val task = createTask(windowingMode = WINDOWING_MODE_FREEFORM)
        val decoration = setUpMockDecorationForTask(task)
        val transitionInfo = mock(TransitionInfo::class.java)
        val transitionChange = mock(TransitionInfo.Change::class.java)
        val taskInfo = mock(RunningTaskInfo()::class.java)

        // Replicate a keyguard going away transition for a task
        whenever(transitionInfo.getFlags())
                .thenReturn(WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY)
        whenever(transitionChange.getMode()).thenReturn(WindowManager.TRANSIT_TO_FRONT)
        whenever(transitionChange.getTaskInfo()).thenReturn(taskInfo)

        // Make sure a window decorations exists first by launching a freeform task.
        onTaskOpening(task)
        // OnTransition ready is called when a keyguard going away transition happens
        desktopModeWindowDecorViewModel
                .onTransitionReady(transition, transitionInfo, transitionChange)

        verify(decoration).incrementRelayoutBlock()
        verify(decoration).addTransitionPausingRelayout(transition)
    }
    @Test
    fun testRelayoutRunsWhenStatusBarsInsetsSourceVisibilityChanges() {
        val task = createTask(windowingMode = WINDOWING_MODE_FREEFORM, focused = true)
@@ -401,7 +427,8 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() {

    private fun createVirtualDisplay(): VirtualDisplay? {
        val surfaceView = SurfaceView(mContext)
        return mContext.getSystemService<DisplayManager>()?.createVirtualDisplay(
        val dm = mContext.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
        return dm.createVirtualDisplay(
                "testEventReceiversOnMultipleDisplays",
                /*width=*/ 400,
                /*height=*/ 400,