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

Commit 79ddf80e authored by Cosmin Băieș's avatar Cosmin Băieș Committed by Android (Google) Code Review
Browse files

Merge "Include inputViewShown in verifyInputViewStatus" into main

parents 97d186ef ed465be2
Loading
Loading
Loading
Loading
+122 −265

File changed.

Preview size limit exceeded, changes collapsed.

+34 −33
Original line number Original line Diff line number Diff line
@@ -27,6 +27,7 @@ import androidx.annotation.Nullable;


import java.lang.annotation.Retention;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.RetentionPolicy;
import java.lang.ref.WeakReference;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CountDownLatch;


/** Wrapper of {@link InputMethodService} to expose interfaces for testing purpose. */
/** Wrapper of {@link InputMethodService} to expose interfaces for testing purpose. */
@@ -35,8 +36,8 @@ public class InputMethodServiceWrapper extends InputMethodService {
    private static final String TAG = "InputMethodServiceWrapper";
    private static final String TAG = "InputMethodServiceWrapper";


    /** Last created instance of this wrapper. */
    /** Last created instance of this wrapper. */
    @Nullable
    @NonNull
    private static InputMethodServiceWrapper sInstance;
    private static WeakReference<InputMethodServiceWrapper> sInstance = new WeakReference<>(null);


    /** IME show event ({@link #onStartInputView}). */
    /** IME show event ({@link #onStartInputView}). */
    public static final int EVENT_SHOW = 0;
    public static final int EVENT_SHOW = 0;
@@ -68,32 +69,11 @@ public class InputMethodServiceWrapper extends InputMethodService {
    @Nullable
    @Nullable
    private CountDownLatch mCountDownLatch;
    private CountDownLatch mCountDownLatch;


    /** Gets the last created instance of this wrapper, if available. */
    @Nullable
    public static InputMethodServiceWrapper getInstance() {
        return sInstance;
    }

    public boolean getCurrentInputViewStarted() {
        return mInputViewStarted;
    }

    /**
     * Sets the latch used to wait for the IME event.
     *
     * @param latch      the latch to wait on.
     * @param latchEvent the event to set the latch on.
     */
    public void setCountDownLatchForTesting(@Nullable CountDownLatch latch, @Event int latchEvent) {
        mCountDownLatch = latch;
        mLatchEvent = latchEvent;
    }

    @Override
    @Override
    public void onCreate() {
    public void onCreate() {
        Log.i(TAG, "onCreate()");
        Log.i(TAG, "onCreate()");
        super.onCreate();
        super.onCreate();
        sInstance = this;
        sInstance = new WeakReference<>(this);
    }
    }


    @Override
    @Override
@@ -102,6 +82,12 @@ public class InputMethodServiceWrapper extends InputMethodService {
        super.onStartInput(info, restarting);
        super.onStartInput(info, restarting);
    }
    }


    @Override
    public void onFinishInput() {
        Log.i(TAG, "onFinishInput()");
        super.onFinishInput();
    }

    @Override
    @Override
    public void onStartInputView(EditorInfo info, boolean restarting) {
    public void onStartInputView(EditorInfo info, boolean restarting) {
        Log.i(TAG, "onStartInputView() editor=" + dumpEditorInfo(info)
        Log.i(TAG, "onStartInputView() editor=" + dumpEditorInfo(info)
@@ -113,12 +99,6 @@ public class InputMethodServiceWrapper extends InputMethodService {
        }
        }
    }
    }


    @Override
    public void onFinishInput() {
        Log.i(TAG, "onFinishInput()");
        super.onFinishInput();
    }

    @Override
    @Override
    public void onFinishInputView(boolean finishingInput) {
    public void onFinishInputView(boolean finishingInput) {
        Log.i(TAG, "onFinishInputView()");
        Log.i(TAG, "onFinishInputView()");
@@ -146,14 +126,35 @@ public class InputMethodServiceWrapper extends InputMethodService {
        }
        }
    }
    }


    public boolean getCurrentInputViewStarted() {
        return mInputViewStarted;
    }

    /**
     * Sets the latch used to wait for the IME event.
     *
     * @param latch      the latch to wait on.
     * @param latchEvent the event to set the latch on.
     */
    public void setCountDownLatchForTesting(@Nullable CountDownLatch latch, @Event int latchEvent) {
        mCountDownLatch = latch;
        mLatchEvent = latchEvent;
    }

    /** Gets the last created instance of this wrapper, if available. */
    @Nullable
    public static InputMethodServiceWrapper getInstance() {
        return sInstance.get();
    }

    /**
    /**
     * Gets the string representation of the IME event that is being waited on.
     * Gets the string representation of the IME event that is being waited on.
     *
     *
     * @param event the IME event.
     * @param eventType the IME event type.
     */
     */
    @NonNull
    @NonNull
    public static String eventToString(@Event int event) {
    public static String eventToString(@Event int eventType) {
        return switch (event) {
        return switch (eventType) {
            case EVENT_SHOW -> "onStartInputView";
            case EVENT_SHOW -> "onStartInputView";
            case EVENT_HIDE -> "onFinishInputView";
            case EVENT_HIDE -> "onFinishInputView";
            case EVENT_CONFIG -> "onConfigurationChanged";
            case EVENT_CONFIG -> "onConfigurationChanged";
+27 −24
Original line number Original line Diff line number Diff line
@@ -45,30 +45,13 @@ import java.lang.ref.WeakReference;
public final class TestActivity extends Activity {
public final class TestActivity extends Activity {


    private static final String TAG = "TestActivity";
    private static final String TAG = "TestActivity";
    private static WeakReference<TestActivity> sLastCreatedInstance = new WeakReference<>(null);


    /**
    /** Last created instance of this activity. */
     * Start a new test activity with an editor and wait for it to begin running before returning.
     *
     * @param instrumentation application instrumentation
     * @return the newly started activity
     */
    @NonNull
    @NonNull
    public static TestActivity startSync(@NonNull Instrumentation instrumentation) {
    private static WeakReference<TestActivity> sInstance = new WeakReference<>(null);
        final var intent = new Intent()
                .setAction(Intent.ACTION_MAIN)
                .setClass(instrumentation.getTargetContext(), TestActivity.class)
                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        return (TestActivity) instrumentation.startActivitySync(intent);
    }


    private EditText mEditText;
    private EditText mEditText;


    public EditText getEditText() {
        return mEditText;
    }

    @Override
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.onCreate(savedInstanceState);
@@ -80,13 +63,11 @@ public final class TestActivity extends Activity {
        rootView.setFitsSystemWindows(true);
        rootView.setFitsSystemWindows(true);
        setContentView(rootView);
        setContentView(rootView);
        mEditText.requestFocus();
        mEditText.requestFocus();
        sLastCreatedInstance = new WeakReference<>(this);
        sInstance = new WeakReference<>(this);
    }
    }


    /** Get the last created TestActivity instance, if available. */
    public EditText getEditText() {
    @Nullable
        return mEditText;
    public static TestActivity getLastCreatedInstance() {
        return sLastCreatedInstance.get();
    }
    }


    /** Shows soft keyboard via InputMethodManager. */
    /** Shows soft keyboard via InputMethodManager. */
@@ -118,4 +99,26 @@ public final class TestActivity extends Activity {
        controller.hide(WindowInsets.Type.ime());
        controller.hide(WindowInsets.Type.ime());
        Log.i(TAG, "hideIme() via WindowInsetsController");
        Log.i(TAG, "hideIme() via WindowInsetsController");
    }
    }

    /** Gets the last created instance of this activity, if available. */
    @Nullable
    public static TestActivity getInstance() {
        return sInstance.get();
    }

    /**
     * Start a new test activity with an editor and wait for it to begin running before returning.
     *
     * @param instrumentation application instrumentation.
     * @return the newly started activity.
     */
    @NonNull
    public static TestActivity startSync(@NonNull Instrumentation instrumentation) {
        final var intent = new Intent()
                .setAction(Intent.ACTION_MAIN)
                .setClass(instrumentation.getTargetContext(), TestActivity.class)
                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        return (TestActivity) instrumentation.startActivitySync(intent);
    }
}
}