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

Commit 54988195 authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "Merge "Insets: Fix stuck mPendingFrame" into rvc-dev am: 88e86e64 am:...

Merge "Merge "Insets: Fix stuck mPendingFrame" into rvc-dev am: 88e86e64 am: a50aa34d am: 35d0385f" into rvc-qpr-dev-plus-aosp am: 6d9feee2

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11744899

Change-Id: I0733095872ff932a161b3db88670a50169c66b7f
parents b39fc3ce 6d9feee2
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import static android.view.InsetsState.getDefaultVisibility;
import static android.view.InsetsController.DEBUG;
import static android.view.InsetsState.toPublicType;

import static com.android.internal.annotations.VisibleForTesting.Visibility.PACKAGE;

import android.annotation.IntDef;
import android.annotation.Nullable;
import android.graphics.Rect;
@@ -271,10 +273,13 @@ public class InsetsSourceConsumer {
        // no-op for types that always return ShowResult#SHOW_IMMEDIATELY.
    }

    void updateSource(InsetsSource newSource) {
    @VisibleForTesting(visibility = PACKAGE)
    public void updateSource(InsetsSource newSource) {
        InsetsSource source = mState.peekSource(mType);
        if (source == null || mController.getAnimationType(mType) == ANIMATION_TYPE_NONE
                || source.getFrame().equals(newSource.getFrame())) {
            mPendingFrame = null;
            mPendingVisibleFrame = null;
            mState.addSource(newSource);
            return;
        }
@@ -292,7 +297,8 @@ public class InsetsSourceConsumer {
        if (DEBUG) Log.d(TAG, "updateSource: " + newSource);
    }

    boolean notifyAnimationFinished() {
    @VisibleForTesting(visibility = PACKAGE)
    public boolean notifyAnimationFinished() {
        if (mPendingFrame != null) {
            InsetsSource source = mState.getSource(mType);
            source.setFrame(mPendingFrame);
+49 −0
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package android.view;

import static android.view.InsetsController.ANIMATION_TYPE_NONE;
import static android.view.InsetsController.ANIMATION_TYPE_USER;
import static android.view.InsetsState.ITYPE_IME;
import static android.view.InsetsState.ITYPE_STATUS_BAR;
import static android.view.WindowInsets.Type.statusBars;

@@ -23,14 +26,18 @@ import static junit.framework.Assert.assertEquals;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertTrue;

import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;

import android.app.Instrumentation;
import android.content.Context;
import android.graphics.Point;
import android.graphics.Rect;
import android.platform.test.annotations.Presubmit;
import android.view.SurfaceControl.Transaction;
import android.view.WindowManager.BadTokenException;
@@ -121,6 +128,48 @@ public class InsetsSourceConsumerTest {

    }

    @Test
    public void testPendingStates() {
        InsetsState state = new InsetsState();
        InsetsController controller = mock(InsetsController.class);
        InsetsSourceConsumer consumer = new InsetsSourceConsumer(
                ITYPE_IME, state, null, controller);

        when(controller.getAnimationType(anyInt())).thenReturn(ANIMATION_TYPE_NONE);

        InsetsSource source = new InsetsSource(ITYPE_IME);
        source.setFrame(0, 1, 2, 3);
        consumer.updateSource(new InsetsSource(source));

        when(controller.getAnimationType(anyInt())).thenReturn(ANIMATION_TYPE_USER);

        // While we're animating, updates are delayed
        source.setFrame(4, 5, 6, 7);
        consumer.updateSource(new InsetsSource(source));
        assertEquals(new Rect(0, 1, 2, 3), state.peekSource(ITYPE_IME).getFrame());

        // Finish the animation, now the pending frame should be applied
        when(controller.getAnimationType(anyInt())).thenReturn(ANIMATION_TYPE_NONE);
        assertTrue(consumer.notifyAnimationFinished());
        assertEquals(new Rect(4, 5, 6, 7), state.peekSource(ITYPE_IME).getFrame());

        when(controller.getAnimationType(anyInt())).thenReturn(ANIMATION_TYPE_USER);

        // Animating again, updates are delayed
        source.setFrame(8, 9, 10, 11);
        consumer.updateSource(new InsetsSource(source));
        assertEquals(new Rect(4, 5, 6, 7), state.peekSource(ITYPE_IME).getFrame());

        // Updating with the current frame triggers a different code path, verify this clears
        // the pending 8, 9, 10, 11 frame:
        source.setFrame(4, 5, 6, 7);
        consumer.updateSource(new InsetsSource(source));

        when(controller.getAnimationType(anyInt())).thenReturn(ANIMATION_TYPE_NONE);
        assertFalse(consumer.notifyAnimationFinished());
        assertEquals(new Rect(4, 5, 6, 7), state.peekSource(ITYPE_IME).getFrame());
    }

    @Test
    public void testRestore() {
        InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {