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

Commit 62f93a5c authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Merge WINDOW_FOCUS_GAIN_REPORT_WITH{,OUT}_CONNECTION again

This is the 5th CL after our CLs [1][2][3][4] for IME visibility
issues.

While the last CL [4] logically reverted most of changes made in
previous CLs [1][2][3], there remain some unintentional changes around
WINDOW_FOCUS_GAIN*.  The biggest issue is the invocation of

  IMM#mServedInputConnectionWrapper.isActive(),

from startInputOnWindowFocusGain() added in the 3rd CL [3].  This is
really problematic because it internally

  IMM#checkFocus(),

which is not intended to be called from startInputOnWindowFocusGain().

This CL addresses that problem by effectively removing the call path.

App compat risk is supposed to be low because IMM#checkFocus() was not
called before the 3rd CL [3], which was introduced in Android R.

There are CTS tests to verify that related issues are not regressed
again [5][6][7].

 [1]: I45a9814d812ad906f417c24200fd4219959e2423
      6ecbf087
 [2]: I2da99ae67b9ce4051dec0c0f0e975ebe6e1ab118
      48bfc316
 [3]: I1ef3d341af9d473d94d52fd1890deafbae2bc9e1
      d43b75cf
 [4]: I022ad658844142ff4a4cf3b91953013f2bfbb58a
      a24622cf
 [5]: Ie029c109e257be81a1ad6327a706bb6bc1e8316c
      3045df602f061a185f6fff18e81f5af1a2c51270
 [6]: Id48eedc1a2d5597bbba5f1d3fc01540e2f6de4c5
      3ed79ab2de600bce312b4ce59b319da0ad9a8dac
 [7]: I022ad658844142ff4a4cf3b91953013f2bfbb58a
      a24622cf

Bug: 152373385
Bug: 155781821
Bug: 160391516
Bug: 161273049
Bug: 182259171
Test: presubmit
Change-Id: I64412e87c4881018ea67140f9472e10ea41836e4
parent 79420036
Loading
Loading
Loading
Loading
+2 −10
Original line number Original line Diff line number Diff line
@@ -33,8 +33,6 @@ import static android.view.inputmethod.InputMethodManagerProto.FULLSCREEN_MODE;
import static android.view.inputmethod.InputMethodManagerProto.SERVED_CONNECTING;
import static android.view.inputmethod.InputMethodManagerProto.SERVED_CONNECTING;


import static com.android.internal.inputmethod.StartInputReason.BOUND_TO_IMMS;
import static com.android.internal.inputmethod.StartInputReason.BOUND_TO_IMMS;
import static com.android.internal.inputmethod.StartInputReason.WINDOW_FOCUS_GAIN_REPORT_WITHOUT_CONNECTION;
import static com.android.internal.inputmethod.StartInputReason.WINDOW_FOCUS_GAIN_REPORT_WITH_CONNECTION;


import android.Manifest;
import android.Manifest;
import android.annotation.DisplayContext;
import android.annotation.DisplayContext;
@@ -822,19 +820,13 @@ public final class InputMethodManager {
            synchronized (mH) {
            synchronized (mH) {
                // For some reason we didn't do a startInput + windowFocusGain, so
                // For some reason we didn't do a startInput + windowFocusGain, so
                // we'll just do a window focus gain and call it a day.
                // we'll just do a window focus gain and call it a day.
                boolean nextFocusHasConnection = mServedView != null && mServedView == focusedView
                        && hasActiveInputConnectionInternal(focusedView);
                if (DEBUG) {
                if (DEBUG) {
                    Log.v(TAG, "Reporting focus gain, without startInput"
                    Log.v(TAG, "Reporting focus gain, without startInput");
                            + ", nextFocusIsServedView=" + nextFocusHasConnection);
                }
                }


                final int startInputReason = nextFocusHasConnection
                        ? WINDOW_FOCUS_GAIN_REPORT_WITH_CONNECTION
                        : WINDOW_FOCUS_GAIN_REPORT_WITHOUT_CONNECTION;
                // ignore the result
                // ignore the result
                mServiceInvoker.startInputOrWindowGainedFocus(
                mServiceInvoker.startInputOrWindowGainedFocus(
                        startInputReason, mClient,
                        StartInputReason.WINDOW_FOCUS_GAIN_REPORT_ONLY, mClient,
                        focusedView.getWindowToken(), startInputFlags, softInputMode,
                        focusedView.getWindowToken(), startInputFlags, softInputMode,
                        windowFlags,
                        windowFlags,
                        null,
                        null,
+2 −4
Original line number Original line Diff line number Diff line
@@ -47,10 +47,8 @@ public final class InputMethodDebug {
                return "UNSPECIFIED";
                return "UNSPECIFIED";
            case StartInputReason.WINDOW_FOCUS_GAIN:
            case StartInputReason.WINDOW_FOCUS_GAIN:
                return "WINDOW_FOCUS_GAIN";
                return "WINDOW_FOCUS_GAIN";
            case StartInputReason.WINDOW_FOCUS_GAIN_REPORT_WITH_CONNECTION:
            case StartInputReason.WINDOW_FOCUS_GAIN_REPORT_ONLY:
                return "WINDOW_FOCUS_GAIN_REPORT_WITH_CONNECTION";
                return "WINDOW_FOCUS_GAIN_REPORT_ONLY";
            case StartInputReason.WINDOW_FOCUS_GAIN_REPORT_WITHOUT_CONNECTION:
                return "WINDOW_FOCUS_GAIN_REPORT_WITHOUT_CONNECTION";
            case StartInputReason.APP_CALLED_RESTART_INPUT_API:
            case StartInputReason.APP_CALLED_RESTART_INPUT_API:
                return "APP_CALLED_RESTART_INPUT_API";
                return "APP_CALLED_RESTART_INPUT_API";
            case StartInputReason.CHECK_FOCUS:
            case StartInputReason.CHECK_FOCUS:
+5 −11
Original line number Original line Diff line number Diff line
@@ -30,8 +30,7 @@ import java.lang.annotation.Retention;
@IntDef(value = {
@IntDef(value = {
        StartInputReason.UNSPECIFIED,
        StartInputReason.UNSPECIFIED,
        StartInputReason.WINDOW_FOCUS_GAIN,
        StartInputReason.WINDOW_FOCUS_GAIN,
        StartInputReason.WINDOW_FOCUS_GAIN_REPORT_WITH_CONNECTION,
        StartInputReason.WINDOW_FOCUS_GAIN_REPORT_ONLY,
        StartInputReason.WINDOW_FOCUS_GAIN_REPORT_WITHOUT_CONNECTION,
        StartInputReason.APP_CALLED_RESTART_INPUT_API,
        StartInputReason.APP_CALLED_RESTART_INPUT_API,
        StartInputReason.CHECK_FOCUS,
        StartInputReason.CHECK_FOCUS,
        StartInputReason.BOUND_TO_IMMS,
        StartInputReason.BOUND_TO_IMMS,
@@ -51,18 +50,13 @@ public @interface StartInputReason {
     * to (re)start a new connection.
     * to (re)start a new connection.
     */
     */
    int WINDOW_FOCUS_GAIN = 1;
    int WINDOW_FOCUS_GAIN = 1;
    /**
     * {@link android.view.Window} gained focus and the focused view is same as current served
     * view and its input connection remains. {@link android.view.inputmethod.InputMethodManager}
     * just reports this window focus change event to sync IME input target for system.
     */
    int WINDOW_FOCUS_GAIN_REPORT_WITH_CONNECTION = 2;
    /**
    /**
     * {@link android.view.Window} gained focus but there is no {@link android.view.View} that is
     * {@link android.view.Window} gained focus but there is no {@link android.view.View} that is
     * eligible to have IME focus. {@link android.view.inputmethod.InputMethodManager} just reports
     * eligible to have IME focus, or the focused view is same as current served view and its
     * this window focus change event for logging.
     * input connection remains. {@link android.view.inputmethod.InputMethodManager} just reports
     * this window focus change event to sync IME input target for system.
     */
     */
    int WINDOW_FOCUS_GAIN_REPORT_WITHOUT_CONNECTION = 3;
    int WINDOW_FOCUS_GAIN_REPORT_ONLY = 2;
    /**
    /**
     * {@link android.view.inputmethod.InputMethodManager#restartInput(android.view.View)} is
     * {@link android.view.inputmethod.InputMethodManager#restartInput(android.view.View)} is
     * either explicitly called by the application or indirectly called by some Framework class
     * either explicitly called by the application or indirectly called by some Framework class