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

Commit 265ab91a authored by Garfield Tan's avatar Garfield Tan
Browse files

Clear LastSurfacePosition when surface is cleared.

This is important for restoring freeform window from recents because
it's possible that the surface is removed but the last surface position
is still there, which stops the surface position being updated later
when the task is restored.

Bug: None
Test: 1) Launch an activity on default display;
2) Close the activity by pressing back button;
3) Go to recents;
4) Restore the activity into freeform by long pressing the icon and
select freeform;
5) The activity is shown at right location rather than (0, 0).
Test: atest WindowContainerTests

Change-Id: Ia5e28101b2343c2fe189da0a73351c72c32df5d3
parent 7a85df83
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -490,6 +490,7 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
            }

            mSurfaceControl = null;
            mLastSurfacePosition.set(0, 0);
            scheduleAnimation();
        }

+26 −0
Original line number Diff line number Diff line
@@ -220,6 +220,32 @@ public class WindowContainerTests extends WindowTestsBase {
        assertEquals(0, root.getChildrenCount());
    }

    @Test
    public void testRemoveImmediatelyClearsLastSurfacePosition() {
        reset(mTransaction);
        try (MockSurfaceBuildingContainer top = new MockSurfaceBuildingContainer(mWm)) {
            final WindowContainer<WindowContainer> child1 = new WindowContainer(mWm);
            child1.setBounds(1, 1, 10, 10);

            top.addChild(child1, 0);
            assertEquals(1, child1.getLastSurfacePosition().x);
            assertEquals(1, child1.getLastSurfacePosition().y);

            WindowContainer child11 = new WindowContainer(mWm);
            child1.addChild(child11, 0);

            child1.setBounds(2, 2, 20, 20);
            assertEquals(2, child1.getLastSurfacePosition().x);
            assertEquals(2, child1.getLastSurfacePosition().y);

            child1.removeImmediately();
            assertEquals(0, child1.getLastSurfacePosition().x);
            assertEquals(0, child1.getLastSurfacePosition().y);
            assertEquals(0, child11.getLastSurfacePosition().x);
            assertEquals(0, child11.getLastSurfacePosition().y);
        }
    }

    @Test
    public void testAddChildByIndex() {
        final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(mWm);