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

Commit 215929b6 authored by Tarandeep Singh's avatar Tarandeep Singh
Browse files

Send IME control to client

Sends the IME control to the client by calling
InsetsStateController.onImeTargetChanged.

Furthermore, since the frame we use to calculate the insets isn't
necessarily the surface frame, we also need to pass down the
surface position such that the client can calculate the final
leash position correctly.

Test: Open IME
Bug: 111084606
Change-Id: Ifed8351b12d47f698efde504205bd7b77032d36b
parent bdda90fc
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -180,9 +180,10 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
        for (int i = items.size() - 1; i >= 0; i--) {
            final InsetsSourceConsumer consumer = items.valueAt(i);
            final InsetsSource source = mInitialInsetsState.getSource(consumer.getType());
            final InsetsSourceControl control = consumer.getControl();
            final SurfaceControl leash = consumer.getControl().getLeash();
            mTmpMatrix.setTranslate(source.getFrame().left, source.getFrame().top);

            mTmpMatrix.setTranslate(control.getSurfacePosition().x, control.getSurfacePosition().y);
            mTmpFrame.set(source.getFrame());
            addTranslationToMatrix(side, offset, mTmpMatrix, mTmpFrame);

+18 −1
Original line number Diff line number Diff line
@@ -29,10 +29,13 @@ public class InsetsSourceControl implements Parcelable {

    private final @InternalInsetType int mType;
    private final SurfaceControl mLeash;
    private final Point mSurfacePosition;

    public InsetsSourceControl(@InternalInsetType int type, SurfaceControl leash) {
    public InsetsSourceControl(@InternalInsetType int type, SurfaceControl leash,
            Point surfacePosition) {
        mType = type;
        mLeash = leash;
        mSurfacePosition = surfacePosition;
    }

    public int getType() {
@@ -46,6 +49,19 @@ public class InsetsSourceControl implements Parcelable {
    public InsetsSourceControl(Parcel in) {
        mType = in.readInt();
        mLeash = in.readParcelable(null /* loader */);
        mSurfacePosition = in.readParcelable(null /* loader */);
    }

    public boolean setSurfacePosition(int left, int top) {
        if (mSurfacePosition.equals(left, top)) {
            return false;
        }
        mSurfacePosition.set(left, top);
        return true;
    }

    public Point getSurfacePosition() {
        return mSurfacePosition;
    }

    @Override
@@ -57,6 +73,7 @@ public class InsetsSourceControl implements Parcelable {
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(mType);
        dest.writeParcelable(mLeash, 0 /* flags*/);
        dest.writeParcelable(mSurfacePosition, 0 /* flags*/);
    }

    public static final Creator<InsetsSourceControl> CREATOR
+1 −1
Original line number Diff line number Diff line
@@ -180,7 +180,7 @@ public final class ViewRootImpl implements ViewParent,
     * @see #USE_NEW_INSETS_PROPERTY
     * @hide
     */
    public static final int sNewInsetsMode =
    public static int sNewInsetsMode =
            SystemProperties.getInt(USE_NEW_INSETS_PROPERTY, 0);

    /**
+2 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static junit.framework.Assert.assertTrue;

import android.content.Context;
import android.graphics.Insets;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.Bundle;
import android.platform.test.annotations.Presubmit;
@@ -80,7 +81,7 @@ public class ImeInsetsSourceConsumerTest {

    @Test
    public void testImeVisibility() {
        final InsetsSourceControl ime = new InsetsSourceControl(TYPE_IME, mLeash);
        final InsetsSourceControl ime = new InsetsSourceControl(TYPE_IME, mLeash, new Point());
        mController.onControlsChanged(new InsetsSourceControl[] { ime });

        InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
+24 −11
Original line number Diff line number Diff line
@@ -19,13 +19,23 @@ package android.view;
import static android.view.InsetsState.TYPE_NAVIGATION_BAR;
import static android.view.InsetsState.TYPE_TOP_BAR;

import static android.view.ViewRootImpl.NEW_INSETS_MODE_FULL;
import static android.view.WindowInsets.Type.sideBars;
import static android.view.WindowInsets.Type.systemBars;
import static android.view.WindowInsets.Type.topBar;
import static junit.framework.Assert.assertEquals;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.graphics.Insets;
import android.graphics.Matrix;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.RectF;
import android.platform.test.annotations.Presubmit;
@@ -55,6 +65,7 @@ public class InsetsAnimationControlImplTest {
    private SurfaceSession mSession = new SurfaceSession();
    private SurfaceControl mTopLeash;
    private SurfaceControl mNavLeash;
    private InsetsState mInsetsState;

    @Mock Transaction mMockTransaction;
    @Mock InsetsController mMockController;
@@ -63,6 +74,7 @@ public class InsetsAnimationControlImplTest {

    @Before
    public void setup() {
        ViewRootImpl.sNewInsetsMode = NEW_INSETS_MODE_FULL;
        MockitoAnnotations.initMocks(this);
        mTopLeash = new SurfaceControl.Builder(mSession)
                .setName("testSurface")
@@ -70,24 +82,25 @@ public class InsetsAnimationControlImplTest {
        mNavLeash = new SurfaceControl.Builder(mSession)
                .setName("testSurface")
                .build();
        InsetsState state = new InsetsState();
        state.getSource(TYPE_TOP_BAR).setFrame(new Rect(0, 0, 500, 100));
        state.getSource(TYPE_NAVIGATION_BAR).setFrame(new Rect(400, 0, 500, 500));
        InsetsSourceConsumer topConsumer = new InsetsSourceConsumer(TYPE_TOP_BAR, state,
        mInsetsState = new InsetsState();
        mInsetsState.getSource(TYPE_TOP_BAR).setFrame(new Rect(0, 0, 500, 100));
        mInsetsState.getSource(TYPE_NAVIGATION_BAR).setFrame(new Rect(400, 0, 500, 500));
        InsetsSourceConsumer topConsumer = new InsetsSourceConsumer(TYPE_TOP_BAR, mInsetsState,
                () -> mMockTransaction, mMockController);
        topConsumer.setControl(new InsetsSourceControl(TYPE_TOP_BAR, mTopLeash));
        topConsumer.setControl(new InsetsSourceControl(TYPE_TOP_BAR, mTopLeash, new Point(0, 0)));

        InsetsSourceConsumer navConsumer = new InsetsSourceConsumer(TYPE_NAVIGATION_BAR, state,
                () -> mMockTransaction, mMockController);
        InsetsSourceConsumer navConsumer = new InsetsSourceConsumer(TYPE_NAVIGATION_BAR,
                mInsetsState, () -> mMockTransaction, mMockController);
        navConsumer.hide();
        navConsumer.setControl(new InsetsSourceControl(TYPE_NAVIGATION_BAR, mNavLeash));
        navConsumer.setControl(new InsetsSourceControl(TYPE_NAVIGATION_BAR, mNavLeash,
                new Point(400, 0)));

        SparseArray<InsetsSourceConsumer> consumers = new SparseArray<>();
        consumers.put(TYPE_TOP_BAR, topConsumer);
        consumers.put(TYPE_NAVIGATION_BAR, navConsumer);
        mController = new InsetsAnimationControlImpl(consumers,
                new Rect(0, 0, 500, 500), state, mMockListener, WindowInsets.Type.systemBars(),
                () -> mMockTransactionApplier, mock(InsetsController.class));
                new Rect(0, 0, 500, 500), mInsetsState, mMockListener, systemBars(),
                () -> mMockTransactionApplier, mMockController);
    }

    @Test
@@ -95,7 +108,7 @@ public class InsetsAnimationControlImplTest {
        assertEquals(Insets.of(0, 100, 100, 0), mController.getShownStateInsets());
        assertEquals(Insets.of(0, 0, 0, 0), mController.getHiddenStateInsets());
        assertEquals(Insets.of(0, 100, 0, 0), mController.getCurrentInsets());
        assertEquals(WindowInsets.Type.systemBars(), mController.getTypes());
        assertEquals(systemBars(), mController.getTypes());
    }

    @Test
Loading