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

Commit bfc66041 authored by Sergey Nikolaienkov's avatar Sergey Nikolaienkov
Browse files

Do not click on TVs in PipKeyboardTest

Implement an alternative way of showing/hiding IME in PipKeyboardTest on
TV - via "re-launching" the ImeActivity with a particular action. The
original way - calling UiObject2.click() on the EditText does not work
well on TVs, because the touch events injected by the Instrumentation to
emulate the click force TV into the touch mode.

Bug: 176413558
Test: atest WMShellFlickerTests:PipKeyboardTest
Change-Id: Id3462eba548c8ed639ba44437db573928348c1e6
parent 8bf124b0
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -31,6 +31,10 @@ const val TEST_APP_PIP_MENU_ACTION_CLEAR = "Clear"

// Test App > Ime Activity
const val TEST_APP_IME_ACTIVITY_LABEL = "ImeApp"
const val TEST_APP_IME_ACTIVITY_ACTION_OPEN_IME =
        "com.android.wm.shell.flicker.testapp.action.OPEN_IME"
const val TEST_APP_IME_ACTIVITY_ACTION_CLOSE_IME =
        "com.android.wm.shell.flicker.testapp.action.CLOSE_IME"
// Test App > Test Activity
const val TEST_APP_FIXED_ACTIVITY_LABEL = "FixedApp"

+2 −1
Original line number Diff line number Diff line
@@ -62,8 +62,9 @@ abstract class BaseAppHelper(
    val ui: UiObject2?
        get() = uiDevice.findObject(appSelector)

    fun launchViaIntent(stringExtras: Map<String, String> = mapOf()) {
    fun launchViaIntent(action: String? = null, stringExtras: Map<String, String> = mapOf()) {
        val intent = openAppIntent
        intent.action = action
        stringExtras.forEach() {
            intent.putExtra(it.key, it.value)
        }
+21 −7
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import android.app.Instrumentation
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Until
import com.android.server.wm.flicker.helpers.FIND_TIMEOUT
import com.android.wm.shell.flicker.TEST_APP_IME_ACTIVITY_ACTION_CLOSE_IME
import com.android.wm.shell.flicker.TEST_APP_IME_ACTIVITY_ACTION_OPEN_IME
import com.android.wm.shell.flicker.TEST_APP_IME_ACTIVITY_LABEL
import com.android.wm.shell.flicker.testapp.Components
import org.junit.Assert
@@ -32,15 +34,27 @@ open class ImeAppHelper(
        Components.ImeActivity()
) {
    fun openIME() {
        if (!isTelevision) {
            val editText = uiDevice.wait(
                    Until.findObject(By.res(getPackage(), "plain_text_input")),
                    FIND_TIMEOUT)
            Assert.assertNotNull("Text field not found, this usually happens when the device " +
                    "was left in an unknown state (e.g. in split screen)", editText)
            editText.click()
        } else {
            // If we do the same thing as above - editText.click() - on TV, that's going to force TV
            // into the touch mode. We really don't want that.
            launchViaIntent(action = TEST_APP_IME_ACTIVITY_ACTION_OPEN_IME)
        }
    }

    fun closeIME() {
        if (!isTelevision) {
            uiDevice.pressBack()
        } else {
            // While pressing the back button should close the IME on TV as well, it may also lead
            // to the app closing. So let's instead just ask the app to close the IME.
            launchViaIntent(action = TEST_APP_IME_ACTIVITY_ACTION_CLOSE_IME)
        }
    }
}
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@
        <activity android:name=".ImeActivity"
                 android:taskAffinity="com.android.wm.shell.flicker.testapp.ImeActivity"
                 android:label="ImeApp"
                 android:launchMode="singleTop"
                 android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
+33 −0
Original line number Diff line number Diff line
@@ -17,10 +17,21 @@
package com.android.wm.shell.flicker.testapp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;

public class ImeActivity extends Activity {
    private static final String ACTION_OPEN_IME =
            "com.android.wm.shell.flicker.testapp.action.OPEN_IME";
    private static final String ACTION_CLOSE_IME =
            "com.android.wm.shell.flicker.testapp.action.CLOSE_IME";

    private InputMethodManager mImm;
    private View mEditText;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
@@ -29,5 +40,27 @@ public class ImeActivity extends Activity {
                .LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
        getWindow().setAttributes(p);
        setContentView(R.layout.activity_ime);

        mEditText = findViewById(R.id.plain_text_input);
        mImm = getSystemService(InputMethodManager.class);

        handleIntent(getIntent());
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        handleIntent(intent);
    }

    private void handleIntent(Intent intent) {
        final String action = intent.getAction();
        if (ACTION_OPEN_IME.equals(action)) {
            mEditText.requestFocus();
            mImm.showSoftInput(mEditText, InputMethodManager.SHOW_FORCED);
        } else if (ACTION_CLOSE_IME.equals(action)) {
            mImm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
            mEditText.clearFocus();
        }
    }
}