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
e0172102b9
Fix: 147331480
Test: atest CtsInputMethodTestCases
Change-Id: I10391b834c33458c3e0ac846ab738e805d235c26
This commit is contained in:
@@ -93,9 +93,12 @@ import java.util.List;
|
||||
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 @@ public final class InputMethodManager {
|
||||
* 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 @@ public final class InputMethodManager {
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ public final class InputMethodManager {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user