Merge "Do not click on TVs in PipKeyboardTest"
This commit is contained in:
committed by
Android (Google) Code Review
commit
eab713e351
@@ -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"
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
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()
|
||||
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() {
|
||||
uiDevice.pressBack()
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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"/>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user