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

Commit 13758c1c authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Merge cherrypicks of [10484934, 10484473, 10472987, 10481068] into qt-qpr2-release

Change-Id: I3ba00e16f09289a9368e55b59b0a527bc55bb3f3
parents b8da4a2c e823c54a
Loading
Loading
Loading
Loading
+30 −67
Original line number Original line Diff line number Diff line
@@ -92,10 +92,7 @@ import java.util.Comparator;
import java.util.List;
import java.util.List;
import java.util.Map;
import java.util.Map;
import java.util.Objects;
import java.util.Objects;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeUnit;


/**
/**
@@ -424,13 +421,6 @@ public final class InputMethodManager {
    int mCursorCandStart;
    int mCursorCandStart;
    int mCursorCandEnd;
    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 CompletableFuture<Void> mWindowFocusGainFuture;

    /**
    /**
     * The instance that has previously been sent to the input method.
     * The instance that has previously been sent to the input method.
     */
     */
@@ -655,7 +645,6 @@ public final class InputMethodManager {
                            } catch (RemoteException e) {
                            } catch (RemoteException e) {
                            }
                            }
                        }
                        }
                    }
                        // Check focus again in case that "onWindowFocus" is called before
                        // Check focus again in case that "onWindowFocus" is called before
                        // handling this message.
                        // handling this message.
                        if (mServedView != null && canStartInput(mServedView)) {
                        if (mServedView != null && canStartInput(mServedView)) {
@@ -665,6 +654,7 @@ public final class InputMethodManager {
                                startInputInner(reason, null, 0, 0, 0);
                                startInputInner(reason, null, 0, 0, 0);
                            }
                            }
                        }
                        }
                    }
                    return;
                    return;
                }
                }
                case MSG_SEND_INPUT_EVENT: {
                case MSG_SEND_INPUT_EVENT: {
@@ -1225,10 +1215,6 @@ public final class InputMethodManager {
     */
     */
    void clearBindingLocked() {
    void clearBindingLocked() {
        if (DEBUG) Log.v(TAG, "Clearing binding!");
        if (DEBUG) Log.v(TAG, "Clearing binding!");
        if (mWindowFocusGainFuture != null) {
            mWindowFocusGainFuture.cancel(false /* mayInterruptIfRunning */);
            mWindowFocusGainFuture = null;
        }
        clearConnectionLocked();
        clearConnectionLocked();
        setInputChannelLocked(null);
        setInputChannelLocked(null);
        mBindSequence = -1;
        mBindSequence = -1;
@@ -1612,18 +1598,6 @@ public final class InputMethodManager {
    boolean startInputInner(@StartInputReason int startInputReason,
    boolean startInputInner(@StartInputReason int startInputReason,
            @Nullable IBinder windowGainingFocus, @StartInputFlags int startInputFlags,
            @Nullable IBinder windowGainingFocus, @StartInputFlags int startInputFlags,
            @SoftInputModeFlags int softInputMode, int windowFlags) {
            @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;
        final View view;
        synchronized (mH) {
        synchronized (mH) {
            view = mServedView;
            view = mServedView;
@@ -1977,19 +1951,13 @@ public final class InputMethodManager {
            startInputFlags |= StartInputFlags.FIRST_WINDOW_FOCUS_GAIN;
            startInputFlags |= StartInputFlags.FIRST_WINDOW_FOCUS_GAIN;
        }
        }


        final boolean forceNewFocus1 = forceNewFocus;
        if (checkFocusNoStartInput(forceNewFocus)) {
        final int startInputFlags1 = startInputFlags;
        if (mWindowFocusGainFuture != null) {
            mWindowFocusGainFuture.cancel(false/* mayInterruptIfRunning */);
        }
        mWindowFocusGainFuture = CompletableFuture.runAsync(() -> {
            if (checkFocusNoStartInput(forceNewFocus1)) {
            // We need to restart input on the current focus view.  This
            // We need to restart input on the current focus view.  This
            // should be done in conjunction with telling the system service
            // should be done in conjunction with telling the system service
            // about the window gaining focus, to help make the transition
            // about the window gaining focus, to help make the transition
            // smooth.
            // smooth.
            if (startInputInner(StartInputReason.WINDOW_FOCUS_GAIN, rootView.getWindowToken(),
            if (startInputInner(StartInputReason.WINDOW_FOCUS_GAIN, rootView.getWindowToken(),
                        startInputFlags1, softInputMode, windowFlags)) {
                    startInputFlags, softInputMode, windowFlags)) {
                return;
                return;
            }
            }
        }
        }
@@ -2001,14 +1969,13 @@ public final class InputMethodManager {
                if (DEBUG) Log.v(TAG, "Reporting focus gain, without startInput");
                if (DEBUG) Log.v(TAG, "Reporting focus gain, without startInput");
                mService.startInputOrWindowGainedFocus(
                mService.startInputOrWindowGainedFocus(
                        StartInputReason.WINDOW_FOCUS_GAIN_REPORT_ONLY, mClient,
                        StartInputReason.WINDOW_FOCUS_GAIN_REPORT_ONLY, mClient,
                            rootView.getWindowToken(), startInputFlags1, softInputMode, windowFlags,
                        rootView.getWindowToken(), startInputFlags, softInputMode, windowFlags,
                        null, null, 0 /* missingMethodFlags */,
                        null, null, 0 /* missingMethodFlags */,
                        rootView.getContext().getApplicationInfo().targetSdkVersion);
                        rootView.getContext().getApplicationInfo().targetSdkVersion);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
                throw e.rethrowFromSystemServer();
            }
            }
        }
        }
        });
    }
    }


    /** @hide */
    /** @hide */
@@ -2023,10 +1990,6 @@ public final class InputMethodManager {
                // If the mCurRootView is losing window focus, release the strong reference to it
                // If the mCurRootView is losing window focus, release the strong reference to it
                // so as not to prevent it from being garbage-collected.
                // so as not to prevent it from being garbage-collected.
                mCurRootView = null;
                mCurRootView = null;
                if (mWindowFocusGainFuture != null) {
                    mWindowFocusGainFuture.cancel(false /* mayInterruptIfRunning */);
                    mWindowFocusGainFuture = null;
                }
            } else {
            } else {
                if (DEBUG) {
                if (DEBUG) {
                    Log.v(TAG, "Ignoring onPreWindowFocus()."
                    Log.v(TAG, "Ignoring onPreWindowFocus()."