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 Diff line number Diff line
@@ -119,9 +119,11 @@ public final class ImeInsetsSourceConsumer extends InsetsSourceConsumer {

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

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

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

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

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

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

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

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

            if (Flags.refactorInsetsController()) {
                final var viewRootImpl = view.getViewRootImpl();
                // 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
                if ((mCurRootView.getInsetsController().computeUserAnimatingTypes()
                if (viewRootImpl != null
                        && (viewRootImpl.getInsetsController().computeUserAnimatingTypes()
                                & WindowInsets.Type.ime()) == 0) {
                    // 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;
                } else {
                    return false;
                }
                return false;
            } else {
                // Makes sure to call ImeInsetsSourceConsumer#onShowRequested on the UI thread.
                // TODO(b/229426865): call WindowInsetsController#show instead.
@@ -2497,7 +2503,10 @@ public final class InputMethodManager {

            if (Flags.refactorInsetsController()) {
                // 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;
            } else {
                return IInputMethodManagerGlobalInvoker.hideSoftInput(mClient, windowToken,
+12 −0
Original line number Diff line number Diff line
@@ -37,8 +37,12 @@ import android.graphics.Insets;
import android.graphics.Point;
import android.graphics.Rect;
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.LayoutParams;
import android.view.inputmethod.Flags;
import android.view.inputmethod.ImeTracker;
import android.widget.TextView;

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

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

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

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

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

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

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

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