Disable IME before running DocumentsUI related tests.

GBoard setup instruction obscures the edit text and part of our button
so some of our tests failed.

Test: Related tests pass on angler, marlin & ryu OC-DR/master.
Bug: 62192538
Change-Id: Ibf01809787ebb85ac3499e2224354d340f250211
diff --git a/hostsidetests/appsecurity/src/android/appsecurity/cts/DocumentsTestCase.java b/hostsidetests/appsecurity/src/android/appsecurity/cts/DocumentsTestCase.java
index 7bdd128..6e03cdf 100644
--- a/hostsidetests/appsecurity/src/android/appsecurity/cts/DocumentsTestCase.java
+++ b/hostsidetests/appsecurity/src/android/appsecurity/cts/DocumentsTestCase.java
@@ -27,7 +27,7 @@
 /**
  * Base class for {@link android.provider.DocumentsContract} and related test cases.
  */
-abstract  class DocumentsTestCase extends DeviceTestCase implements IAbiReceiver, IBuildReceiver {
+abstract class DocumentsTestCase extends DeviceTestCase implements IAbiReceiver, IBuildReceiver {
     protected static final String CLIENT_PKG = "com.android.cts.documentclient";
     protected static final String CLIENT_APK = "CtsDocumentClient.apk";
 
diff --git a/hostsidetests/appsecurity/test-apps/DocumentClient/src/com/android/cts/documentclient/DocumentsClientTestCase.java b/hostsidetests/appsecurity/test-apps/DocumentClient/src/com/android/cts/documentclient/DocumentsClientTestCase.java
index be5efe6..68e554d 100644
--- a/hostsidetests/appsecurity/test-apps/DocumentClient/src/com/android/cts/documentclient/DocumentsClientTestCase.java
+++ b/hostsidetests/appsecurity/test-apps/DocumentClient/src/com/android/cts/documentclient/DocumentsClientTestCase.java
@@ -44,15 +44,17 @@
  * Base class for DocumentsUI test cases.
  */
 abstract class DocumentsClientTestCase extends InstrumentationTestCase {
-    private static final String TAG = "DocumentsClientTestCase";
+    protected static final long TIMEOUT = 30 * DateUtils.SECOND_IN_MILLIS;
+    protected static final int REQUEST_CODE = 42;
 
     static final String PROVIDER_PACKAGE = "com.android.cts.documentprovider";
 
+    private static final String TAG = "DocumentsClientTestCase";
+
     protected UiDevice mDevice;
     protected MyActivity mActivity;
 
-    protected static final long TIMEOUT = 30 * DateUtils.SECOND_IN_MILLIS;
-    protected static final int REQUEST_CODE = 42;
+    private String[] mDisabledImes;
 
     @Override
     public void setUp() throws Exception {
@@ -60,6 +62,11 @@
 
         Configurator.getInstance().setToolType(MotionEvent.TOOL_TYPE_FINGER);
 
+        // Disable IME's to avoid virtual keyboards from showing up. Occasionally IME draws some UI
+        // controls out of its boundary for some first time setup that obscures the text edit and/or
+        // save/select button. This will constantly fail some of our tests.
+        disableImes();
+
         mDevice = UiDevice.getInstance(getInstrumentation());
         mActivity = launchActivity(getInstrumentation().getTargetContext().getPackageName(),
                 MyActivity.class, null);
@@ -70,6 +77,8 @@
     public void tearDown() throws Exception {
         super.tearDown();
         mActivity.finish();
+
+        enableImes();
     }
 
     protected String getColumn(Uri uri, String column) {
@@ -163,4 +172,17 @@
         }
         executeShellCommand("pm clear com.android.documentsui");
     }
+
+    private void disableImes() throws Exception {
+        mDisabledImes = executeShellCommand("ime list -s").split("\n");
+        for (String ime : mDisabledImes) {
+            executeShellCommand("ime disable " + ime);
+        }
+    }
+
+    private void enableImes() throws Exception {
+        for (String ime : mDisabledImes) {
+            executeShellCommand("ime enable " + ime);
+        }
+    }
 }