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

Commit d4d895e2 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Remove a special optimization for a quite rare scenario

This CL effectively reverts the following 3 CLs.

 * Reduce window resizing during IME transition
   I5723f627ce323b0d12bd7b93f5b35fc4d342b50c
   792faa2c

 * Clear the inset of previous IME when necessary
   Ib04967f39b2529251e4835c42e9f99dba2cf43f2
   2977eb7b

 * Make IMS#clearInsetOfPreviousIme() reliable
   Ib567daa009c1139858dccadcfc6a04465ebecf36
   833bdced

The main idea behind the first CL is that the target application can
skil avoid layout resizing if the following two conditions are met.

 A. WindowManagerService (WMS) can remember the last IME's inset until
    the next IME's window is fully shown.
 B. Both the last IME and the new IME have the same inset.

Basically the first CL implements the above A part with an assumption
that some IMEs would do the B part.  However, in reality it is quite
unlikely that two random IMEs have the same inset size.  At the same
time, maintaining this kind of special optimization is getting harder
and harder as more and more use cases and form factors need to be
supported.

Let's remove this optimization given that no one is benefited by it.

Fix: 116492038
Test: atest CtsInputMethodTestCases CtsInputMethodServiceHostTestCases
Test: do not see any noticeable visual difference
Change-Id: I8ffbf9bf7c3a8be54df0ca8eac1a1f041ef7d3c9
parent 21ba5d4f
Loading
Loading
Loading
Loading
+0 −43
Original line number Diff line number Diff line
@@ -410,14 +410,6 @@ public class InputMethodService extends AbstractInputMethodService {
    @GuardedBy("mLock")
    private boolean mNotifyUserActionSent;

    /**
     * {@code true} when the previous IME had non-empty inset at the bottom of the screen and we
     * have not shown our own window yet.  In this situation, the previous inset continues to be
     * shown as an empty region until it is explicitly updated. Basically we can trigger the update
     * by calling 1) {@code mWindow.show()} or 2) {@link #clearInsetOfPreviousIme()}.
     */
    boolean mShouldClearInsetOfPreviousIme;

    @UnsupportedAppUsage
    final Insets mTmpInsets = new Insets();
    final int[] mTmpLocation = new int[2];
@@ -581,7 +573,6 @@ public class InputMethodService extends AbstractInputMethodService {
            mShowInputFlags = 0;
            mShowInputRequested = false;
            doHideWindow();
            clearInsetOfPreviousIme();
            if (resultReceiver != null) {
                resultReceiver.send(wasVis != isInputViewShown()
                        ? InputMethodManager.RESULT_HIDDEN
@@ -601,7 +592,6 @@ public class InputMethodService extends AbstractInputMethodService {
            if (dispatchOnShowInputRequested(flags, false)) {
                showWindow(true);
            }
            clearInsetOfPreviousIme();
            // If user uses hard keyboard, IME button should always be shown.
            setImeWindowStatus(mapToImeWindowStatus(isInputViewShown()), mBackDisposition);

@@ -946,9 +936,6 @@ public class InputMethodService extends AbstractInputMethodService {
        super.onCreate();
        mImm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
        mSettingsObserver = SettingsObserver.createAndRegister(this);
        // If the previous IME has occupied non-empty inset in the screen, we need to decide whether
        // we continue to use the same size of the inset or update it
        mShouldClearInsetOfPreviousIme = (mImm.getInputMethodWindowVisibleHeight() > 0);
        // TODO(b/111364446) Need to address context lifecycle issue if need to re-create
        // for update resources & configuration correctly when show soft input
        // in non-default display.
@@ -1882,9 +1869,6 @@ public class InputMethodService extends AbstractInputMethodService {
            if (DEBUG) Log.v(TAG, "showWindow: showing!");
            onWindowShown();
            mWindow.show();
            // Put here rather than in onWindowShown() in case people forget to call
            // super.onWindowShown().
            mShouldClearInsetOfPreviousIme = false;
        }
    }

@@ -1933,32 +1917,6 @@ public class InputMethodService extends AbstractInputMethodService {
        // Intentionally empty
    }

    /**
     * Reset the inset occupied the previous IME when and only when
     * {@link #mShouldClearInsetOfPreviousIme} is {@code true}.
     */
    private void clearInsetOfPreviousIme() {
        if (DEBUG) Log.v(TAG, "clearInsetOfPreviousIme() "
                + " mShouldClearInsetOfPreviousIme=" + mShouldClearInsetOfPreviousIme);
        if (!mShouldClearInsetOfPreviousIme) return;

        clearLastInputMethodWindowForTransition();
        mShouldClearInsetOfPreviousIme = false;
    }

    /**
     * Tells the system that the IME decided to not show a window and the system no longer needs to
     * use the previous IME's inset.
     *
     * <p>Caveat: {@link android.inputmethodservice.InputMethodService#clearInsetOfPreviousIme()}
     * is the only expected caller of this method.  Do not depend on this anywhere else.</p>
     *
     * <p>TODO: We probably need to reconsider how IME should be handled.</p>
     */
    private void clearLastInputMethodWindowForTransition() {
        mPrivOps.clearLastInputMethodWindowForTransition();
    }

    /**
     * Called when a new client has bound to the input method.  This
     * may be followed by a series of {@link #onStartInput(EditorInfo, boolean)}
@@ -2980,7 +2938,6 @@ public class InputMethodService extends AbstractInputMethodService {
                + " visibleTopInsets=" + mTmpInsets.visibleTopInsets
                + " touchableInsets=" + mTmpInsets.touchableInsets
                + " touchableRegion=" + mTmpInsets.touchableRegion);
        p.println(" mShouldClearInsetOfPreviousIme=" + mShouldClearInsetOfPreviousIme);
        p.println(" mSettingsObserver=" + mSettingsObserver);
    }
}
+0 −1
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import com.android.internal.inputmethod.IInputContentUriToken;
interface IInputMethodPrivilegedOperations {
    void setImeWindowStatus(int vis, int backDisposition);
    void reportStartInput(in IBinder startInputToken);
    void clearLastInputMethodWindowForTransition();
    IInputContentUriToken createInputContentUriToken(in Uri contentUri, in String packageName);
    void reportFullscreenMode(boolean fullscreen);
    void setInputMethod(String id);
+0 −16
Original line number Diff line number Diff line
@@ -134,22 +134,6 @@ public final class InputMethodPrivilegedOperations {
        }
    }

    /**
     * Calls {@link IInputMethodPrivilegedOperations#clearLastInputMethodWindowForTransition()}.
     */
    @AnyThread
    public void clearLastInputMethodWindowForTransition() {
        final IInputMethodPrivilegedOperations ops = mOps.getAndWarnIfNull();
        if (ops == null) {
            return;
        }
        try {
            ops.clearLastInputMethodWindowForTransition();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Calls {@link IInputMethodPrivilegedOperations#createInputContentUriToken(Uri, String)}.
     *
+6 −29
Original line number Diff line number Diff line
@@ -1976,7 +1976,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            throw new IllegalArgumentException("Unknown id: " + mCurMethodId);
        }

        unbindCurrentMethodLocked(true);
        unbindCurrentMethodLocked();

        mCurIntent = new Intent(InputMethod.SERVICE_INTERFACE);
        mCurIntent.setComponent(info.getComponent());
@@ -2020,7 +2020,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                mCurMethod = IInputMethod.Stub.asInterface(service);
                if (mCurToken == null) {
                    Slog.w(TAG, "Service connected without a token!");
                    unbindCurrentMethodLocked(false);
                    unbindCurrentMethodLocked();
                    return;
                }
                if (DEBUG) Slog.v(TAG, "Initiating attach with token: " + mCurToken);
@@ -2059,7 +2059,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        channel.dispose();
    }

    void unbindCurrentMethodLocked(boolean savePosition) {
    void unbindCurrentMethodLocked() {
        if (mVisibleBound) {
            mContext.unbindService(mVisibleConnection);
            mVisibleBound = false;
@@ -2076,10 +2076,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                    Slog.v(TAG, "Removing window token: " + mCurToken + " for display: "
                            + mCurTokenDisplayId);
                }
                if ((mImeWindowVis & InputMethodService.IME_ACTIVE) != 0 && savePosition) {
                    // The current IME is shown. Hence an IME switch (transition) is happening.
                    mWindowManagerInternal.saveLastInputMethodWindowForTransition();
                }
                mIWindowManager.removeWindowToken(mCurToken, mCurTokenDisplayId);
            } catch (RemoteException e) {
            }
@@ -2094,7 +2090,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
    void resetCurrentMethodAndClient(
            /* @InputMethodClient.UnbindReason */ final int unbindClientReason) {
        mCurMethodId = null;
        unbindCurrentMethodLocked(false);
        unbindCurrentMethodLocked();
        unbindCurrentClientLocked(unbindClientReason);
    }

@@ -2865,7 +2861,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                                final int newFocusDisplayId =
                                        mWindowManagerInternal.getDisplayIdForWindow(windowToken);
                                if (newFocusDisplayId != mCurTokenDisplayId) {
                                    unbindCurrentMethodLocked(false);
                                    unbindCurrentMethodLocked();
                                }
                            }
                        } else if (isTextEditor && doAutoShow && (softInputMode &
@@ -3236,19 +3232,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        return mWindowManagerInternal.getInputMethodWindowVisibleHeight(mCurTokenDisplayId);
    }

    @BinderThread
    private void clearLastInputMethodWindowForTransition(IBinder token) {
        if (!calledFromValidUser()) {
            return;
        }
        synchronized (mMethodMap) {
            if (!calledWithValidToken(token)) {
                return;
            }
        }
        mWindowManagerInternal.clearLastInputMethodWindowForTransition();
    }

    @BinderThread
    private void notifyUserAction(@NonNull IBinder token) {
        if (DEBUG) {
@@ -4957,7 +4940,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            try {
                synchronized (mMethodMap) {
                    hideCurrentInputLocked(0, null);
                    unbindCurrentMethodLocked(false);
                    unbindCurrentMethodLocked();
                    // Reset the current IME
                    resetSelectedInputMethodAndSubtypeLocked(null);
                    // Also reset the settings of the current IME
@@ -5028,12 +5011,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            mImms.reportStartInput(mToken, startInputToken);
        }

        @BinderThread
        @Override
        public void clearLastInputMethodWindowForTransition() {
            mImms.clearLastInputMethodWindowForTransition(mToken);
        }

        @BinderThread
        @Override
        public IInputContentUriToken createInputContentUriToken(Uri contentUri,
+0 −24
Original line number Diff line number Diff line
@@ -533,8 +533,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {

    GlobalActions mGlobalActions;
    Handler mHandler;
    WindowState mLastInputMethodWindow = null;
    WindowState mLastInputMethodTargetWindow = null;

    // FIXME This state is shared between the input reader and handler thread.
    // Technically it's broken and buggy but it has been like this for many years
@@ -4732,12 +4730,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
        final WindowManager.LayoutParams attrs = win.getAttrs();
        final boolean isDefaultDisplay = win.isDefaultDisplay();
        final boolean needsToOffsetInputMethodTarget =
                (win == mLastInputMethodTargetWindow) && (mLastInputMethodWindow != null);
        if (needsToOffsetInputMethodTarget) {
            if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
            offsetInputMethodWindowLw(mLastInputMethodWindow, displayFrames);
        }

        final int type = attrs.type;
        final int fl = PolicyControl.getWindowFlags(win, attrs);
@@ -5191,7 +5183,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        // can't appear underneath them.
        if (type == TYPE_INPUT_METHOD && win.isVisibleLw()
                && !win.getGivenInsetsPendingLw()) {
            setLastInputMethodWindowLw(null, null);
            offsetInputMethodWindowLw(win, displayFrames);
        }
        if (type == TYPE_VOICE_INTERACTION && win.isVisibleLw()
@@ -7821,12 +7812,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        return mDefaultDisplayPolicy.hasNavigationBar();
    }

    @Override
    public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
        mLastInputMethodWindow = ime;
        mLastInputMethodTargetWindow = target;
    }

    @Override
    public void setDismissImeOnBackKeyPressed(boolean newValue) {
        mDismissImeOnBackKeyPressed = newValue;
@@ -7845,7 +7830,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        if (statusBar != null) {
            statusBar.setCurrentUser(newUserId);
        }
        setLastInputMethodWindowLw(null, null);
    }

    @Override
@@ -8020,14 +8004,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        pw.print(prefix); pw.print("mShowingDream="); pw.print(mShowingDream);
                pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
                pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
        if (mLastInputMethodWindow != null) {
            pw.print(prefix); pw.print("mLastInputMethodWindow=");
                    pw.println(mLastInputMethodWindow);
        }
        if (mLastInputMethodTargetWindow != null) {
            pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
                    pw.println(mLastInputMethodTargetWindow);
        }
        if (mStatusBar != null) {
            pw.print(prefix); pw.print("mStatusBar=");
                    pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
Loading