Use ExecutorService to replace CompletableFuture

CL[1] introduced starting input with CompletableFuture for improving IME
performance.

Since CompletableFuture is not recommanded way to use in system server side for
memory usage concern, we use java ExecutorService and Future to remove
this dependency.

[1]: I6aa4a664cfd0c86f75cee2457715317194bbe5e2
      e0172102b9c9a9640209e3223bb6c60fe1d5cabb

Fix: 147331480
Test: atest CtsInputMethodTestCases

Change-Id: I10391b834c33458c3e0ac846ab738e805d235c26
diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java
index 67ce8d2..f3007a7 100644
--- a/core/java/android/view/inputmethod/InputMethodManager.java
+++ b/core/java/android/view/inputmethod/InputMethodManager.java
@@ -93,9 +93,12 @@
 import java.util.Map;
 import java.util.Objects;
 import java.util.concurrent.CancellationException;
-import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
 
 /**
@@ -429,7 +432,10 @@
      * in a background thread. Later, if there is an actual startInput it will wait on
      * main thread till the background thread completes.
      */
-    private CompletableFuture<Void> mWindowFocusGainFuture;
+    private Future<?> mWindowFocusGainFuture;
+
+    private ExecutorService mStartInputWorker = Executors.newSingleThreadExecutor(
+            new ImeThreadFactory("StartInputWorker"));
 
     /**
      * The instance that has previously been sent to the input method.
@@ -790,6 +796,19 @@
         }
     }
 
+    private static class ImeThreadFactory implements ThreadFactory {
+        private final String mThreadName;
+
+        ImeThreadFactory(String name) {
+            mThreadName = name;
+        }
+
+        @Override
+        public Thread newThread(Runnable r) {
+            return new Thread(r, mThreadName);
+        }
+    }
+
     final IInputMethodClient.Stub mClient = new IInputMethodClient.Stub() {
         @Override
         protected void dump(FileDescriptor fd, PrintWriter fout, String[] args) {
@@ -1978,7 +1997,7 @@
         if (mWindowFocusGainFuture != null) {
             mWindowFocusGainFuture.cancel(false/* mayInterruptIfRunning */);
         }
-        mWindowFocusGainFuture = CompletableFuture.runAsync(() -> {
+        mWindowFocusGainFuture = mStartInputWorker.submit(() -> {
             if (checkFocusNoStartInput(forceNewFocus1)) {
                 // We need to restart input on the current focus view.  This
                 // should be done in conjunction with telling the system service