Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ac8f1fbd authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Logically revert previous attempts on Bug 139806621"

parents abe60fe3 08e91345
Loading
Loading
Loading
Loading
+35 −78
Original line number Diff line number Diff line
@@ -93,12 +93,7 @@ import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CancellationException;
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;

@@ -414,16 +409,6 @@ public final class InputMethodManager {
    int mCursorCandStart;
    int mCursorCandEnd;

    /**
     * Initial startInput with {@link StartInputReason.WINDOW_FOCUS_GAIN} is executed
     * in a background thread. Later, if there is an actual startInput it will wait on
     * main thread till the background thread completes.
     */
    private Future<?> mWindowFocusGainFuture;

    private ExecutorService mStartInputWorker = Executors.newSingleThreadExecutor(
            new ImeThreadFactory("StartInputWorker"));

    /**
     * The instance that has previously been sent to the input method.
     */
@@ -612,10 +597,6 @@ public final class InputMethodManager {
            final boolean forceNewFocus1 = forceNewFocus;
            final int startInputFlags = getStartInputFlags(focusedView, 0);

            if (mWindowFocusGainFuture != null) {
                mWindowFocusGainFuture.cancel(false /* mayInterruptIfRunning */);
            }
            mWindowFocusGainFuture = mStartInputWorker.submit(() -> {
            final ImeFocusController controller = getFocusController();
            if (controller == null) {
                return;
@@ -646,7 +627,6 @@ public final class InputMethodManager {
                    throw e.rethrowFromSystemServer();
                }
            }
            });
        }

        /**
@@ -664,10 +644,6 @@ public final class InputMethodManager {
         */
        @Override
        public void setCurrentRootView(ViewRootImpl rootView) {
            if (mWindowFocusGainFuture != null) {
                mWindowFocusGainFuture.cancel(false /* mayInterruptIfRunning */);
                mWindowFocusGainFuture = null;
            }
            synchronized (mH) {
                if (mCurRootView != null) {
                    // Reset the last served view and restart window focus state of the root view.
@@ -845,13 +821,9 @@ public final class InputMethodManager {
                            } catch (RemoteException e) {
                            }
                        }
                    }
                        // Check focus again in case that "onWindowFocus" is called before
                        // handling this message.
                    final View servedView;
                    synchronized (mH) {
                        servedView = getServedViewLocked();
                    }
                        final View servedView = getServedViewLocked();
                        if (servedView != null && canStartInput(servedView)) {
                            if (mCurRootView != null && mCurRootView.getImeFocusController()
                                    .checkFocus(mRestartOnNextWindowFocus, false)) {
@@ -860,6 +832,7 @@ public final class InputMethodManager {
                                mDelegate.startInput(reason, null, 0, 0, 0);
                            }
                        }
                    }
                    return;
                }
                case MSG_SEND_INPUT_EVENT: {
@@ -1430,10 +1403,6 @@ public final class InputMethodManager {
     */
    void clearBindingLocked() {
        if (DEBUG) Log.v(TAG, "Clearing binding!");
        if (mWindowFocusGainFuture != null) {
            mWindowFocusGainFuture.cancel(false /* mayInterruptIfRunning */);
            mWindowFocusGainFuture = null;
        }
        clearConnectionLocked();
        setInputChannelLocked(null);
        mBindSequence = -1;
@@ -1826,18 +1795,6 @@ public final class InputMethodManager {
    boolean startInputInner(@StartInputReason int startInputReason,
            @Nullable IBinder windowGainingFocus, @StartInputFlags int startInputFlags,
            @SoftInputModeFlags int softInputMode, int windowFlags) {
        if (startInputReason != StartInputReason.WINDOW_FOCUS_GAIN
                && mWindowFocusGainFuture != null) {
            try {
                mWindowFocusGainFuture.get();
            } catch (ExecutionException | InterruptedException e) {
                // do nothing
            } catch (CancellationException e) {
                // window no longer has focus.
                return true;
            }
        }

        final View view;
        synchronized (mH) {
            view = getServedViewLocked();