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

Commit 37893c20 authored by Kohsuke Yatoh's avatar Kohsuke Yatoh Committed by Android (Google) Code Review
Browse files

Merge changes from topic "kyatoh-b221483132-tm-dev" into tm-dev

* changes:
  Do not cleanup IME window if show is requested.
  Notify IMMS synchronously on IME insets hidden.
parents 26fa852f eae7ca81
Loading
Loading
Loading
Loading
+0 −10
Original line number Diff line number Diff line
@@ -53,7 +53,6 @@ class IInputMethodSessionWrapper extends IInputMethodSession.Stub
    private static final int DO_APP_PRIVATE_COMMAND = 100;
    private static final int DO_FINISH_SESSION = 110;
    private static final int DO_VIEW_CLICKED = 115;
    private static final int DO_NOTIFY_IME_HIDDEN = 120;
    private static final int DO_REMOVE_IME_SURFACE = 130;
    private static final int DO_FINISH_INPUT = 140;
    private static final int DO_INVALIDATE_INPUT = 150;
@@ -133,10 +132,6 @@ class IInputMethodSessionWrapper extends IInputMethodSession.Stub
                mInputMethodSession.viewClicked(msg.arg1 == 1);
                return;
            }
            case DO_NOTIFY_IME_HIDDEN: {
                mInputMethodSession.notifyImeHidden();
                return;
            }
            case DO_REMOVE_IME_SURFACE: {
                mInputMethodSession.removeImeSurface();
                return;
@@ -197,11 +192,6 @@ class IInputMethodSessionWrapper extends IInputMethodSession.Stub
                mCaller.obtainMessageI(DO_VIEW_CLICKED, focusChanged ? 1 : 0));
    }

    @Override
    public void notifyImeHidden() {
        mCaller.executeOrSendMessage(mCaller.obtainMessage(DO_NOTIFY_IME_HIDDEN));
    }

    @Override
    public void removeImeSurface() {
        mCaller.executeOrSendMessage(mCaller.obtainMessage(DO_REMOVE_IME_SURFACE));
+0 −12
Original line number Diff line number Diff line
@@ -1058,10 +1058,6 @@ public class InputMethodService extends AbstractInputMethodService {
        return viewRoot == null ? null : viewRoot.getInputToken();
    }

    private void notifyImeHidden() {
        requestHideSelf(0);
    }

    private void scheduleImeSurfaceRemoval() {
        if (mShowInputRequested || mWindowVisible || mWindow == null
                || mImeSurfaceScheduledForRemoval) {
@@ -1224,14 +1220,6 @@ public class InputMethodService extends AbstractInputMethodService {
            InputMethodService.this.onUpdateCursorAnchorInfo(info);
        }

        /**
         * Notify IME that window is hidden.
         * @hide
         */
        public final void notifyImeHidden() {
            InputMethodService.this.notifyImeHidden();
        }

        /**
         * Notify IME that surface can be now removed.
         * @hide
+44 −5
Original line number Diff line number Diff line
@@ -18,12 +18,13 @@ package android.view;

import static android.os.Trace.TRACE_TAG_VIEW;
import static android.view.ImeInsetsSourceConsumerProto.INSETS_SOURCE_CONSUMER;
import static android.view.ImeInsetsSourceConsumerProto.IS_HIDE_ANIMATION_RUNNING;
import static android.view.ImeInsetsSourceConsumerProto.IS_REQUESTED_VISIBLE_AWAITING_CONTROL;
import static android.view.ImeInsetsSourceConsumerProto.IS_SHOW_REQUESTED_DURING_HIDE_ANIMATION;
import static android.view.InsetsController.AnimationType;
import static android.view.InsetsState.ITYPE_IME;

import android.annotation.Nullable;
import android.inputmethodservice.InputMethodService;
import android.os.IBinder;
import android.os.Trace;
import android.util.proto.ProtoOutputStream;
@@ -44,6 +45,16 @@ public final class ImeInsetsSourceConsumer extends InsetsSourceConsumer {
     */
    private boolean mIsRequestedVisibleAwaitingControl;

    private boolean mIsHideAnimationRunning;

    /**
     * Tracks whether {@link WindowInsetsController#show(int)} or
     * {@link InputMethodManager#showSoftInput(View, int)} is called during IME hide animation.
     * If it was called, we should not call {@link InputMethodManager#notifyImeHidden(IBinder)},
     * because the IME is being shown.
     */
    private boolean mIsShowRequestedDuringHideAnimation;

    public ImeInsetsSourceConsumer(
            InsetsState state, Supplier<Transaction> transactionSupplier,
            InsetsController controller) {
@@ -63,6 +74,12 @@ public final class ImeInsetsSourceConsumer extends InsetsSourceConsumer {
        mIsRequestedVisibleAwaitingControl = false;
    }

    @Override
    public void show(boolean fromIme) {
        super.show(fromIme);
        onShowRequested();
    }

    @Override
    public void hide() {
        super.hide();
@@ -74,11 +91,21 @@ public final class ImeInsetsSourceConsumer extends InsetsSourceConsumer {
        hide();

        if (animationFinished) {
            // remove IME surface as IME has finished hide animation.
            // Remove IME surface as IME has finished hide animation, if there is no pending
            // show request.
            if (!mIsShowRequestedDuringHideAnimation) {
                notifyHidden();
                removeSurface();
            }
        }
        // This method is called
        // (1) before the hide animation starts.
        // (2) after the hide animation ends.
        // (3) if the IME is not controllable (animationFinished == true in this case).
        // We should reset mIsShowRequestedDuringHideAnimation in all cases.
        mIsHideAnimationRunning = !animationFinished;
        mIsShowRequestedDuringHideAnimation = false;
    }

    /**
     * Request {@link InputMethodManager} to show the IME.
@@ -104,7 +131,8 @@ public final class ImeInsetsSourceConsumer extends InsetsSourceConsumer {
    }

    /**
     * Notify {@link InputMethodService} that IME window is hidden.
     * Notify {@link com.android.server.inputmethod.InputMethodManagerService} that
     * IME insets are hidden.
     */
    @Override
    void notifyHidden() {
@@ -157,9 +185,20 @@ public final class ImeInsetsSourceConsumer extends InsetsSourceConsumer {
        final long token = proto.start(fieldId);
        super.dumpDebug(proto, INSETS_SOURCE_CONSUMER);
        proto.write(IS_REQUESTED_VISIBLE_AWAITING_CONTROL, mIsRequestedVisibleAwaitingControl);
        proto.write(IS_HIDE_ANIMATION_RUNNING, mIsHideAnimationRunning);
        proto.write(IS_SHOW_REQUESTED_DURING_HIDE_ANIMATION, mIsShowRequestedDuringHideAnimation);
        proto.end(token);
    }

    /**
     * Called when {@link #show} or {@link InputMethodManager#showSoftInput(View, int)} is called.
     */
    public void onShowRequested() {
        if (mIsHideAnimationRunning) {
            mIsShowRequestedDuringHideAnimation = true;
        }
    }

    private InputMethodManager getImm() {
        return mController.getHost().getInputMethodManager();
    }
+23 −2
Original line number Diff line number Diff line
@@ -543,6 +543,7 @@ public final class InputMethodManager {
    static final int MSG_BIND_ACCESSIBILITY_SERVICE = 11;
    static final int MSG_UNBIND_ACCESSIBILITY_SERVICE = 12;
    static final int MSG_UPDATE_VIRTUAL_DISPLAY_TO_SCREEN_MATRIX = 30;
    static final int MSG_ON_SHOW_REQUESTED = 31;

    private static boolean isAutofillUIShowing(View servedView) {
        AutofillManager afm = servedView.getContext().getSystemService(AutofillManager.class);
@@ -1117,6 +1118,14 @@ public final class InputMethodManager {
                    }
                    return;
                }
                case MSG_ON_SHOW_REQUESTED: {
                    synchronized (mH) {
                        if (mImeInsetsConsumer != null) {
                            mImeInsetsConsumer.onShowRequested();
                        }
                    }
                    return;
                }
            }
        }
    }
@@ -1834,6 +1843,9 @@ public final class InputMethodManager {
                return false;
            }

            // Makes sure to call ImeInsetsSourceConsumer#onShowRequested on the UI thread.
            // TODO(b/229426865): call WindowInsetsController#show instead.
            mH.executeOrSendMessage(Message.obtain(mH, MSG_ON_SHOW_REQUESTED));
            try {
                Log.d(TAG, "showSoftInput() view=" + view + " flags=" + flags + " reason="
                        + InputMethodDebug.softInputDisplayReasonToString(reason));
@@ -1869,6 +1881,9 @@ public final class InputMethodManager {
                    Log.w(TAG, "No current root view, ignoring showSoftInputUnchecked()");
                    return;
                }
                // Makes sure to call ImeInsetsSourceConsumer#onShowRequested on the UI thread.
                // TODO(b/229426865): call WindowInsetsController#show instead.
                mH.executeOrSendMessage(Message.obtain(mH, MSG_ON_SHOW_REQUESTED));
                mService.showSoftInput(
                        mClient,
                        mCurRootView.getView().getWindowToken(),
@@ -2521,7 +2536,7 @@ public final class InputMethodManager {
    }

    /**
     * Notify IME directly that it is no longer visible.
     * Notify IMMS that IME insets are no longer visible.
     *
     * @param windowToken the window from which this request originates. If this doesn't match the
     *                    currently served view, the request is ignored.
@@ -2533,7 +2548,13 @@ public final class InputMethodManager {
        synchronized (mH) {
            if (mCurrentInputMethodSession != null && mCurRootView != null
                    && mCurRootView.getWindowToken() == windowToken) {
                mCurrentInputMethodSession.notifyImeHidden();
                try {
                    mService.hideSoftInput(mClient, windowToken, 0 /* flags */,
                            null /* resultReceiver */,
                            SoftInputShowHideReason.HIDE_SOFT_INPUT);
                } catch (RemoteException e) {
                    throw e.rethrowFromSystemServer();
                }
            }
        }
    }
+0 −7
Original line number Diff line number Diff line
@@ -194,13 +194,6 @@ public interface InputMethodSession {
     */
    public void updateCursorAnchorInfo(CursorAnchorInfo cursorAnchorInfo);

    /**
     * Notifies {@link android.inputmethodservice.InputMethodService} that IME has been
     * hidden from user.
     * @hide
     */
    public void notifyImeHidden();

    /**
     * Notify IME directly to remove surface as it is no longer visible.
     * @hide
Loading