diff options
author | Yohei Yukawa <yukawa@google.com> | 2018-12-24 20:15:08 -0800 |
---|---|---|
committer | Yohei Yukawa <yukawa@google.com> | 2018-12-24 20:15:08 -0800 |
commit | dc1c5157ae01ee6bb52d30da8279e4474871ab2c (patch) | |
tree | 3502444039025ba723f586b3f81c05733a2f8456 | |
parent | 2232e861862566418da649290d86f7d2734fffb7 (diff) |
Directly update DEFAULT_INPUT_METHOD in UiAutomatorTestCase
This CL updates UiAutomatorTestCase so as not to rely on a special
undocumented rule that
IInputMethodManager#setInputMethod(IBinder token, String id)
can accept null token when the caller has WRITE_SECURE_SETTINGS is
going to be deprecated.
Fix: 114481043
Test: make -j uiautomator.core
Change-Id: If338da51b2c9d62ca4528e6ead16ea711639b775
-rw-r--r-- | cmds/uiautomator/library/testrunner-src/com/android/uiautomator/testrunner/UiAutomatorTestCase.java | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/cmds/uiautomator/library/testrunner-src/com/android/uiautomator/testrunner/UiAutomatorTestCase.java b/cmds/uiautomator/library/testrunner-src/com/android/uiautomator/testrunner/UiAutomatorTestCase.java index 3d5476d04701..d862e1c2babb 100644 --- a/cmds/uiautomator/library/testrunner-src/com/android/uiautomator/testrunner/UiAutomatorTestCase.java +++ b/cmds/uiautomator/library/testrunner-src/com/android/uiautomator/testrunner/UiAutomatorTestCase.java @@ -16,14 +16,16 @@ package com.android.uiautomator.testrunner; +import android.app.ActivityThread; +import android.content.ContentResolver; import android.content.Context; +import android.content.pm.PackageManager; import android.os.Bundle; -import android.os.RemoteException; -import android.os.ServiceManager; import android.os.SystemClock; +import android.provider.Settings; import android.view.inputmethod.InputMethodInfo; +import android.view.inputmethod.InputMethodManager; -import com.android.internal.view.IInputMethodManager; import com.android.uiautomator.core.UiDevice; import junit.framework.TestCase; @@ -44,6 +46,8 @@ public class UiAutomatorTestCase extends TestCase { private static final String DISABLE_IME = "disable_ime"; private static final String DUMMY_IME_PACKAGE = "com.android.testing.dummyime"; + private static final int NOT_A_SUBTYPE_ID = -1; + private UiDevice mUiDevice; private Bundle mParams; private IAutomationSupport mAutomationSupport; @@ -124,9 +128,13 @@ public class UiAutomatorTestCase extends TestCase { SystemClock.sleep(ms); } - private void setDummyIme() throws RemoteException { - IInputMethodManager im = IInputMethodManager.Stub.asInterface(ServiceManager - .getService(Context.INPUT_METHOD_SERVICE)); + private void setDummyIme() { + Context context = ActivityThread.currentApplication(); + if (context == null) { + throw new RuntimeException("ActivityThread.currentApplication() is null."); + } + InputMethodManager im = (InputMethodManager) context.getSystemService( + Context.INPUT_METHOD_SERVICE); List<InputMethodInfo> infos = im.getInputMethodList(); String id = null; for (InputMethodInfo info : infos) { @@ -138,10 +146,17 @@ public class UiAutomatorTestCase extends TestCase { throw new RuntimeException(String.format( "Required testing fixture missing: IME package (%s)", DUMMY_IME_PACKAGE)); } - im.setInputMethod(null, id); + if (context.checkSelfPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) + != PackageManager.PERMISSION_GRANTED) { + return; + } + ContentResolver resolver = context.getContentResolver(); + Settings.Secure.putInt(resolver, Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE, + NOT_A_SUBTYPE_ID); + Settings.Secure.putString(resolver, Settings.Secure.DEFAULT_INPUT_METHOD, id); } - private void restoreActiveIme() throws RemoteException { + private void restoreActiveIme() { // TODO: figure out a way to restore active IME // Currently retrieving active IME requires querying secure settings provider, which is hard // to do without a Context; so the caveat here is that to make the post test device usable, |