diff options
-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, |