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

Commit 6e1bc66f authored by Felix Stern's avatar Felix Stern
Browse files

Move remaining logic of ImeInsetsSourceConsumer to InsetsSourceConsumer

Also doing some minor adjustments for preparation of the ImeStatsToken
refactoring.

Test: atest CtsInputMethodTestCases
Flag: android.view.inputmethod.refactor_insets_controller
Bug: 298172246
Change-Id: I51fb25ad8f402dd0834778835008df03ae12ab88
parent 5094b476
Loading
Loading
Loading
Loading
+12 −6
Original line number Original line Diff line number Diff line
@@ -119,9 +119,11 @@ public final class ImeInsetsSourceConsumer extends InsetsSourceConsumer {


    @Override
    @Override
    public boolean applyLocalVisibilityOverride() {
    public boolean applyLocalVisibilityOverride() {
        if (!Flags.refactorInsetsController()) {
            ImeTracing.getInstance().triggerClientDump(
            ImeTracing.getInstance().triggerClientDump(
                    "ImeInsetsSourceConsumer#applyLocalVisibilityOverride",
                    "ImeInsetsSourceConsumer#applyLocalVisibilityOverride",
                    mController.getHost().getInputMethodManager(), null /* icProto */);
                    mController.getHost().getInputMethodManager(), null /* icProto */);
        }
        return super.applyLocalVisibilityOverride();
        return super.applyLocalVisibilityOverride();
    }
    }


@@ -205,11 +207,15 @@ public final class ImeInsetsSourceConsumer extends InsetsSourceConsumer {


    @Override
    @Override
    public void removeSurface() {
    public void removeSurface() {
        if (Flags.refactorInsetsController()) {
            super.removeSurface();
        } else {
            final IBinder window = mController.getHost().getWindowToken();
            final IBinder window = mController.getHost().getWindowToken();
            if (window != null) {
            if (window != null) {
                getImm().removeImeSurface(window);
                getImm().removeImeSurface(window);
            }
            }
        }
        }
    }


    @Override
    @Override
    public boolean setControl(@Nullable InsetsSourceControl control, int[] showTypes,
    public boolean setControl(@Nullable InsetsSourceControl control, int[] showTypes,
+1 −1
Original line number Original line Diff line number Diff line
@@ -765,7 +765,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation


    public InsetsController(Host host) {
    public InsetsController(Host host) {
        this(host, (controller, id, type) -> {
        this(host, (controller, id, type) -> {
            if (type == ime()) {
            if (!Flags.refactorInsetsController() &&  type == ime()) {
                return new ImeInsetsSourceConsumer(id, controller.mState,
                return new ImeInsetsSourceConsumer(id, controller.mState,
                        Transaction::new, controller);
                        Transaction::new, controller);
            } else {
            } else {
+16 −0
Original line number Original line Diff line number Diff line
@@ -43,6 +43,7 @@ import android.view.inputmethod.Flags;
import android.view.inputmethod.ImeTracker;
import android.view.inputmethod.ImeTracker;


import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.inputmethod.ImeTracing;


import java.lang.annotation.Retention;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.RetentionPolicy;
@@ -296,6 +297,13 @@ public class InsetsSourceConsumer {


    @VisibleForTesting(visibility = PACKAGE)
    @VisibleForTesting(visibility = PACKAGE)
    public boolean applyLocalVisibilityOverride() {
    public boolean applyLocalVisibilityOverride() {
        if (Flags.refactorInsetsController()) {
            if (mType == WindowInsets.Type.ime()) {
                ImeTracing.getInstance().triggerClientDump(
                        "ImeInsetsSourceConsumer#applyLocalVisibilityOverride",
                        mController.getHost().getInputMethodManager(), null /* icProto */);
            }
        }
        final InsetsSource source = mState.peekSource(mId);
        final InsetsSource source = mState.peekSource(mId);
        if (source == null) {
        if (source == null) {
            return false;
            return false;
@@ -396,6 +404,14 @@ public class InsetsSourceConsumer {
     */
     */
    public void removeSurface() {
    public void removeSurface() {
        // no-op for types that always return ShowResult#SHOW_IMMEDIATELY.
        // no-op for types that always return ShowResult#SHOW_IMMEDIATELY.
        if (Flags.refactorInsetsController()) {
            if (mType == WindowInsets.Type.ime()) {
                final IBinder window = mController.getHost().getWindowToken();
                if (window != null) {
                    mController.getHost().getInputMethodManager().removeImeSurface(window);
                }
            }
        }
    }
    }


    @VisibleForTesting(visibility = PACKAGE)
    @VisibleForTesting(visibility = PACKAGE)
+21 −12
Original line number Original line Diff line number Diff line
@@ -1352,12 +1352,16 @@ public final class InputMethodManager {
                case MSG_SET_VISIBILITY:
                case MSG_SET_VISIBILITY:
                    final boolean visible = msg.arg1 != 0;
                    final boolean visible = msg.arg1 != 0;
                    synchronized (mH) {
                    synchronized (mH) {
                        if (mCurRootView != null) {
                            final var insetsController = mCurRootView.getInsetsController();
                            if (insetsController != null) {
                                if (visible) {
                                if (visible) {
                            showSoftInput(mServedView, /* flags */ 0);
                                    insetsController.show(WindowInsets.Type.ime(),
                                            false /* fromIme */, null /* statsToken */);
                                } else {
                                } else {
                            if (mCurRootView != null
                                    insetsController.hide(WindowInsets.Type.ime(),
                                    && mCurRootView.getInsetsController() != null) {
                                            false /* fromIme */, null /* statsToken */);
                                mCurRootView.getInsetsController().hide(WindowInsets.Type.ime());
                                }
                            }
                            }
                        }
                        }
                    }
                    }
@@ -2334,16 +2338,18 @@ public final class InputMethodManager {
            ImeTracker.forLogging().onProgress(statsToken, ImeTracker.PHASE_CLIENT_VIEW_SERVED);
            ImeTracker.forLogging().onProgress(statsToken, ImeTracker.PHASE_CLIENT_VIEW_SERVED);


            if (Flags.refactorInsetsController()) {
            if (Flags.refactorInsetsController()) {
                final var viewRootImpl = view.getViewRootImpl();
                // In case of a running show IME animation, it should not be requested visible,
                // In case of a running show IME animation, it should not be requested visible,
                // otherwise the animation would jump and not be controlled by the user anymore
                // otherwise the animation would jump and not be controlled by the user anymore
                if ((mCurRootView.getInsetsController().computeUserAnimatingTypes()
                if (viewRootImpl != null
                        && (viewRootImpl.getInsetsController().computeUserAnimatingTypes()
                                & WindowInsets.Type.ime()) == 0) {
                                & WindowInsets.Type.ime()) == 0) {
                    // TODO(b/322992891) handle case of SHOW_IMPLICIT
                    // TODO(b/322992891) handle case of SHOW_IMPLICIT
                    view.getWindowInsetsController().show(WindowInsets.Type.ime());
                    viewRootImpl.getInsetsController().show(WindowInsets.Type.ime(),
                            false /* fromIme */, statsToken);
                    return true;
                    return true;
                } else {
                    return false;
                }
                }
                return false;
            } else {
            } else {
                // Makes sure to call ImeInsetsSourceConsumer#onShowRequested on the UI thread.
                // Makes sure to call ImeInsetsSourceConsumer#onShowRequested on the UI thread.
                // TODO(b/229426865): call WindowInsetsController#show instead.
                // TODO(b/229426865): call WindowInsetsController#show instead.
@@ -2497,7 +2503,10 @@ public final class InputMethodManager {


            if (Flags.refactorInsetsController()) {
            if (Flags.refactorInsetsController()) {
                // TODO(b/322992891) handle case of HIDE_IMPLICIT_ONLY
                // TODO(b/322992891) handle case of HIDE_IMPLICIT_ONLY
                servedView.getWindowInsetsController().hide(WindowInsets.Type.ime());
                final var viewRootImpl = servedView.getViewRootImpl();
                if (viewRootImpl != null) {
                    viewRootImpl.getInsetsController().hide(WindowInsets.Type.ime());
                }
                return true;
                return true;
            } else {
            } else {
                return IInputMethodManagerGlobalInvoker.hideSoftInput(mClient, windowToken,
                return IInputMethodManagerGlobalInvoker.hideSoftInput(mClient, windowToken,
+12 −0
Original line number Original line Diff line number Diff line
@@ -37,8 +37,12 @@ import android.graphics.Insets;
import android.graphics.Point;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.Rect;
import android.platform.test.annotations.Presubmit;
import android.platform.test.annotations.Presubmit;
import android.platform.test.annotations.RequiresFlagsDisabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.view.WindowManager.BadTokenException;
import android.view.WindowManager.BadTokenException;
import android.view.WindowManager.LayoutParams;
import android.view.WindowManager.LayoutParams;
import android.view.inputmethod.Flags;
import android.view.inputmethod.ImeTracker;
import android.view.inputmethod.ImeTracker;
import android.widget.TextView;
import android.widget.TextView;


@@ -46,6 +50,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.platform.app.InstrumentationRegistry;


import org.junit.Before;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.Mockito;
@@ -61,6 +66,9 @@ import org.mockito.Spy;
@RunWith(AndroidJUnit4.class)
@RunWith(AndroidJUnit4.class)
public class ImeInsetsSourceConsumerTest {
public class ImeInsetsSourceConsumerTest {


    @Rule
    public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();

    Context mContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
    Context mContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
    InsetsSourceConsumer mImeConsumer;
    InsetsSourceConsumer mImeConsumer;
    @Spy InsetsController mController;
    @Spy InsetsController mController;
@@ -112,6 +120,7 @@ public class ImeInsetsSourceConsumerTest {
    }
    }


    @Test
    @Test
    @RequiresFlagsDisabled(Flags.FLAG_REFACTOR_INSETS_CONTROLLER)
    public void testImeRequestedVisibleAwaitingControl() {
    public void testImeRequestedVisibleAwaitingControl() {
        // Set null control and then request show.
        // Set null control and then request show.
        mController.onControlsChanged(new InsetsSourceControl[] { null });
        mController.onControlsChanged(new InsetsSourceControl[] { null });
@@ -141,6 +150,7 @@ public class ImeInsetsSourceConsumerTest {
    }
    }


    @Test
    @Test
    @RequiresFlagsDisabled(Flags.FLAG_REFACTOR_INSETS_CONTROLLER)
    public void testImeRequestedVisibleAwaitingLeash() {
    public void testImeRequestedVisibleAwaitingLeash() {
        // Set null control, then request show.
        // Set null control, then request show.
        mController.onControlsChanged(new InsetsSourceControl[] { null });
        mController.onControlsChanged(new InsetsSourceControl[] { null });
@@ -185,6 +195,7 @@ public class ImeInsetsSourceConsumerTest {
    }
    }


    @Test
    @Test
    @RequiresFlagsDisabled(Flags.FLAG_REFACTOR_INSETS_CONTROLLER)
    public void testImeGetAndClearSkipAnimationOnce_expectSkip() {
    public void testImeGetAndClearSkipAnimationOnce_expectSkip() {
        // Expect IME animation will skipped when the IME is visible at first place.
        // Expect IME animation will skipped when the IME is visible at first place.
        verifyImeGetAndClearSkipAnimationOnce(true /* hasWindowFocus */, true /* hasViewFocus */,
        verifyImeGetAndClearSkipAnimationOnce(true /* hasWindowFocus */, true /* hasViewFocus */,
@@ -192,6 +203,7 @@ public class ImeInsetsSourceConsumerTest {
    }
    }


    @Test
    @Test
    @RequiresFlagsDisabled(Flags.FLAG_REFACTOR_INSETS_CONTROLLER)
    public void testImeGetAndClearSkipAnimationOnce_expectNoSkip() {
    public void testImeGetAndClearSkipAnimationOnce_expectNoSkip() {
        // Expect IME animation will not skipped if previously no view focused when gained the
        // Expect IME animation will not skipped if previously no view focused when gained the
        // window focus and requesting the IME visible next time.
        // window focus and requesting the IME visible next time.
Loading