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

Commit ba8f3ba6 authored by Johannes Gallmann's avatar Johannes Gallmann Committed by Android (Google) Code Review
Browse files

Merge "Split ImeOnBackInvokedDispatcher into two classes" into main

parents db592019 f4644c1d
Loading
Loading
Loading
Loading
+11 −16
Original line number Diff line number Diff line
@@ -58,8 +58,6 @@ import static android.view.inputmethod.Flags.FLAG_CONNECTIONLESS_HANDWRITING;
import static android.view.inputmethod.Flags.FLAG_VERIFY_KEY_EVENT;
import static android.view.inputmethod.Flags.ctrlShiftShortcut;

import static com.android.window.flags.Flags.imeBackCallbackLeakPrevention;

import android.annotation.CallSuper;
import android.annotation.DrawableRes;
import android.annotation.DurationMillisLong;
@@ -152,7 +150,7 @@ import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.window.CompatOnBackInvokedCallback;
import android.window.ImeOnBackInvokedDispatcher;
import android.window.ImeBackCallbackSender;
import android.window.OnBackInvokedCallback;
import android.window.OnBackInvokedDispatcher;
import android.window.WindowMetricsHelper;
@@ -371,7 +369,7 @@ public class InputMethodService extends AbstractInputMethodService {
     * A circular buffer of size MAX_EVENTS_BUFFER in case IME is taking too long to add ink view.
     **/
    private RingBuffer<MotionEvent> mPendingEvents;
    private ImeOnBackInvokedDispatcher mImeDispatcher;
    private ImeBackCallbackSender mImeBackCallbackSender;
    private boolean mBackCallbackRegistered = false;
    private final CompatOnBackInvokedCallback mCompatBackCallback = this::compatHandleBack;
    private Runnable mImeSurfaceRemoverRunnable;
@@ -839,14 +837,11 @@ public class InputMethodService extends AbstractInputMethodService {
            // (if any) can be unregistered using the old dispatcher if {@link #doFinishInput()}
            // is called from {@link #startInput(InputConnection, EditorInfo)} or
            // {@link #restartInput(InputConnection, EditorInfo)}.
            final ImeOnBackInvokedDispatcher oldDispatcher = mImeDispatcher;
            mImeDispatcher = params.imeDispatcher;
            if (imeBackCallbackLeakPrevention() && oldDispatcher != null && mImeDispatcher != null
                    && oldDispatcher != mImeDispatcher) {
                mImeDispatcher.transferNonSystemCallbacksFrom(oldDispatcher);
            }
            mImeBackCallbackSender.setTargetAppPackageName(params.editorInfo.packageName);
            mImeBackCallbackSender.setResultReceiver(params.imeBackCallbackReceiver);
            if (mWindow != null) {
                mWindow.getOnBackInvokedDispatcher().setImeOnBackInvokedDispatcher(mImeDispatcher);
                mWindow.getOnBackInvokedDispatcher().setImeBackCallbackSender(
                        mImeBackCallbackSender);
                if (mDecorViewVisible && mShowInputRequested) {
                    // Back callback is typically registered in {@link #showWindow()}, but it's
                    // possible for {@link #doStartInput()} to be called without
@@ -1725,10 +1720,9 @@ public class InputMethodService extends AbstractInputMethodService {
                Context.LAYOUT_INFLATER_SERVICE);
        Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMS.initSoftInputWindow");
        mWindow = new SoftInputWindow(this, mTheme, mDispatcherState);
        if (mImeDispatcher != null) {
            mWindow.getOnBackInvokedDispatcher()
                    .setImeOnBackInvokedDispatcher(mImeDispatcher);
        }
        mImeBackCallbackSender = new ImeBackCallbackSender();
        mWindow.getOnBackInvokedDispatcher().setImeBackCallbackSender(mImeBackCallbackSender);

        mNavigationBarController.onSoftInputWindowCreated(mWindow);
        {
            final Window window = mWindow.getWindow();
@@ -1871,7 +1865,8 @@ public class InputMethodService extends AbstractInputMethodService {
            // when IME developers are doing something unsupported.
            InputMethodPrivilegedOperationsRegistry.remove(mToken);
        }
        mImeDispatcher = null;
        mImeBackCallbackSender.clear();
        mImeBackCallbackSender = null;
    }

    /**
+1 −1
Original line number Diff line number Diff line
@@ -152,7 +152,7 @@ public class ImeBackAnimationController implements OnBackAnimationCallback {
        }
        // Unregister all IME back callbacks so that back events are sent to the next callback
        // even while the hide animation is playing
        mInsetsController.getHost().getInputMethodManager().getImeOnBackInvokedDispatcher()
        mInsetsController.getHost().getInputMethodManager().getImeBackCallbackProxy()
                .preliminaryClear();
    }

+2 −2
Original line number Diff line number Diff line
@@ -1375,7 +1375,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        if (!fromPredictiveBack && !visible && (types & ime()) != 0
                && (mRequestedVisibleTypes & ime()) != 0) {
            // Clear IME back callbacks if a IME hide animation is requested
            mHost.getInputMethodManager().getImeOnBackInvokedDispatcher().preliminaryClear();
            mHost.getInputMethodManager().getImeBackCallbackProxy().preliminaryClear();
        }
        // Basically, we accept the requested visibilities from the upstream callers...
        setRequestedVisibleTypes(visible ? types : 0, types);
@@ -1834,7 +1834,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
                // In case the IME back callbacks have been preliminarily cleared before, let's
                // reregister them. This can happen if an IME hide animation was interrupted and the
                // IME is requested to be shown again.
                getHost().getInputMethodManager().getImeOnBackInvokedDispatcher()
                getHost().getInputMethodManager().getImeBackCallbackProxy()
                        .undoPreliminaryClear();
            }
            ProtoLog.d(IME_INSETS_CONTROLLER, "Setting requestedVisibleTypes to %d (was %d)",
+1 −1
Original line number Diff line number Diff line
@@ -12949,7 +12949,7 @@ public final class ViewRootImpl implements ViewParent,
        mCompatOnBackInvokedCallback = () -> {
            injectBackKeyEvents(/* preImeOnly */ false);
        };
        if (mOnBackInvokedDispatcher.hasImeOnBackInvokedDispatcher()) {
        if (mOnBackInvokedDispatcher.hasImeBackCallbackSender()) {
            Log.d(TAG, "Skip registering CompatOnBackInvokedCallback on IME dispatcher");
            return;
        }
+4 −3
Original line number Diff line number Diff line
@@ -29,10 +29,10 @@ import android.annotation.UserIdInt;
import android.content.Context;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.os.ServiceManager;
import android.util.ExceptionUtils;
import android.view.WindowManager;
import android.window.ImeOnBackInvokedDispatcher;

import com.android.internal.infra.AndroidFuture;
import com.android.internal.inputmethod.DirectBootAwareness;
@@ -299,7 +299,7 @@ final class IInputMethodManagerGlobalInvoker {
            @Nullable IRemoteInputConnection remoteInputConnection,
            @Nullable IRemoteAccessibilityInputConnection remoteAccessibilityInputConnection,
            int unverifiedTargetSdkVersion, @UserIdInt int userId,
            @NonNull ImeOnBackInvokedDispatcher imeDispatcher, boolean imeRequestedVisible) {
            @NonNull ResultReceiver imeBackCallbackReceiver, boolean imeRequestedVisible) {
        final IInputMethodManager service = getService();
        if (service == null) {
            return -1;
@@ -308,7 +308,8 @@ final class IInputMethodManagerGlobalInvoker {
            service.startInputOrWindowGainedFocus(startInputReason, client, windowToken,
                    startInputFlags, softInputMode, windowFlags, editorInfo, remoteInputConnection,
                    remoteAccessibilityInputConnection, unverifiedTargetSdkVersion, userId,
                    imeDispatcher, imeRequestedVisible, advanceAngGetStartInputSequenceNumber());
                    imeBackCallbackReceiver, imeRequestedVisible,
                    advanceAngGetStartInputSequenceNumber());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
Loading