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

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

Remove RemoteException handlings from AutofillSuggestionsController

This is a follow up CL to our previous CL [1], which introduced

  InlineSuggestionsRequestCallbackDecorator

that wraps

  InlineSuggestionsRequestCallbackImpl

to intercept IPC calls then inject special logic.

The problem is that when forwarding IPC calls within system_server
process, the AIDL-generated method stub forces us to handle
RemoteException, which actually never happen if the target Binder
object is in the same process. To clarify this nuance, this CL
introduces a plain Java interface

  com.android.internal.inputmethod.InlineSuggestionsRequestCallback

as a mirror of IInlineSuggestionsRequestCallback.

As you can see in this CL, doing so eliminates many RemoteException.

This is a mechanical code change with no observable behavior.

 [1]: I3d81b1d56989e46f65f9b9fc6e497952486335b5
      16b2de5a

Bug: 339358344
Test: atest CtsAutoFillServiceTestCases
Test: atest CtsInputMethodTestCases
Change-Id: I25a75b47aaed29a42b153a7874e5bf26ca89df98
parent c9cb114c
Loading
Loading
Loading
Loading
+81 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.inputmethod;

import android.annotation.BinderThread;
import android.view.autofill.AutofillId;
import android.view.inputmethod.InlineSuggestionsRequest;

/**
 * An internal interface that mirrors {@link IInlineSuggestionsRequestCallback}.
 *
 * <p>This interface is used to forward incoming IPCs from
 * {@link com.android.server.inputmethod.AutofillSuggestionsController} to
 * {@link com.android.server.autofill.AutofillInlineSuggestionsRequestSession}.</p>
 */
public interface InlineSuggestionsRequestCallback {

    /**
     * Forwards {@link IInlineSuggestionsRequestCallback#onInlineSuggestionsUnsupported()}.
     */
    @BinderThread
    void onInlineSuggestionsUnsupported();

    /**
     * Forwards {@link IInlineSuggestionsRequestCallback#onInlineSuggestionsRequest(
     * InlineSuggestionsRequest, IInlineSuggestionsResponseCallback)}.
     */
    @BinderThread
    void onInlineSuggestionsRequest(InlineSuggestionsRequest request,
            IInlineSuggestionsResponseCallback callback);

    /**
     * Forwards {@link IInlineSuggestionsRequestCallback#onInputMethodStartInput(AutofillId)}.
     */
    @BinderThread
    void onInputMethodStartInput(AutofillId imeFieldId);

    /**
     * Forwards {@link IInlineSuggestionsRequestCallback#onInputMethodShowInputRequested(boolean)}.
     */
    @BinderThread
    void onInputMethodShowInputRequested(boolean requestResult);

    /**
     * Forwards {@link IInlineSuggestionsRequestCallback#onInputMethodStartInputView()}.
     */
    @BinderThread
    void onInputMethodStartInputView();

    /**
     * Forwards {@link IInlineSuggestionsRequestCallback#onInputMethodFinishInputView()}.
     */
    @BinderThread
    void onInputMethodFinishInputView();

    /**
     * Forwards {@link IInlineSuggestionsRequestCallback#onInputMethodFinishInput()}.
     */
    @BinderThread
    void onInputMethodFinishInput();

    /**
     * Forwards {@link IInlineSuggestionsRequestCallback#onInlineSuggestionsSessionInvalidated()}.
     */
    @BinderThread
    void onInlineSuggestionsSessionInvalidated();
}
+8 −7
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.view.inputmethod.InlineSuggestionsResponse;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.inputmethod.IInlineSuggestionsRequestCallback;
import com.android.internal.inputmethod.IInlineSuggestionsResponseCallback;
import com.android.internal.inputmethod.InlineSuggestionsRequestCallback;
import com.android.internal.inputmethod.InlineSuggestionsRequestInfo;
import com.android.server.autofill.ui.InlineFillUi;
import com.android.server.inputmethod.InputMethodManagerInternal;
@@ -376,8 +377,8 @@ final class AutofillInlineSuggestionsRequestSession {
    /**
     * Internal implementation of {@link IInlineSuggestionsRequestCallback}.
     */
    private static final class InlineSuggestionsRequestCallbackImpl extends
            IInlineSuggestionsRequestCallback.Stub {
    private static final class InlineSuggestionsRequestCallbackImpl
            implements InlineSuggestionsRequestCallback {

        private final WeakReference<AutofillInlineSuggestionsRequestSession> mSession;

@@ -388,7 +389,7 @@ final class AutofillInlineSuggestionsRequestSession {

        @BinderThread
        @Override
        public void onInlineSuggestionsUnsupported() throws RemoteException {
        public void onInlineSuggestionsUnsupported() {
            if (sDebug) Slog.d(TAG, "onInlineSuggestionsUnsupported() called.");
            final AutofillInlineSuggestionsRequestSession session = mSession.get();
            if (session != null) {
@@ -412,7 +413,7 @@ final class AutofillInlineSuggestionsRequestSession {
        }

        @Override
        public void onInputMethodStartInput(AutofillId imeFieldId) throws RemoteException {
        public void onInputMethodStartInput(AutofillId imeFieldId) {
            if (sVerbose) Slog.v(TAG, "onInputMethodStartInput() received on " + imeFieldId);
            final AutofillInlineSuggestionsRequestSession session = mSession.get();
            if (session != null) {
@@ -423,7 +424,7 @@ final class AutofillInlineSuggestionsRequestSession {
        }

        @Override
        public void onInputMethodShowInputRequested(boolean requestResult) throws RemoteException {
        public void onInputMethodShowInputRequested(boolean requestResult) {
            if (sVerbose) {
                Slog.v(TAG, "onInputMethodShowInputRequested() received: " + requestResult);
            }
@@ -454,7 +455,7 @@ final class AutofillInlineSuggestionsRequestSession {
        }

        @Override
        public void onInputMethodFinishInput() throws RemoteException {
        public void onInputMethodFinishInput() {
            if (sVerbose) Slog.v(TAG, "onInputMethodFinishInput() received");
            final AutofillInlineSuggestionsRequestSession session = mSession.get();
            if (session != null) {
@@ -466,7 +467,7 @@ final class AutofillInlineSuggestionsRequestSession {

        @BinderThread
        @Override
        public void onInlineSuggestionsSessionInvalidated() throws RemoteException {
        public void onInlineSuggestionsSessionInvalidated() {
            if (sDebug) Slog.d(TAG, "onInlineSuggestionsSessionInvalidated() called.");
            final AutofillInlineSuggestionsRequestSession session = mSession.get();
            if (session != null) {
+31 −37
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.view.inputmethod.InputMethodInfo;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.inputmethod.IInlineSuggestionsRequestCallback;
import com.android.internal.inputmethod.IInlineSuggestionsResponseCallback;
import com.android.internal.inputmethod.InlineSuggestionsRequestCallback;
import com.android.internal.inputmethod.InlineSuggestionsRequestInfo;

/**
@@ -49,12 +50,12 @@ final class AutofillSuggestionsController {

    private static final class CreateInlineSuggestionsRequest {
        @NonNull final InlineSuggestionsRequestInfo mRequestInfo;
        @NonNull final IInlineSuggestionsRequestCallback mCallback;
        @NonNull final InlineSuggestionsRequestCallback mCallback;
        @NonNull final String mPackageName;

        CreateInlineSuggestionsRequest(
                @NonNull InlineSuggestionsRequestInfo requestInfo,
                @NonNull IInlineSuggestionsRequestCallback callback,
                @NonNull InlineSuggestionsRequestCallback callback,
                @NonNull String packageName) {
            mRequestInfo = requestInfo;
            mCallback = callback;
@@ -78,7 +79,7 @@ final class AutofillSuggestionsController {
     */
    @GuardedBy("ImfLock.class")
    @Nullable
    private IInlineSuggestionsRequestCallback mInlineSuggestionsRequestCallback;
    private InlineSuggestionsRequestCallback mInlineSuggestionsRequestCallback;

    AutofillSuggestionsController(@NonNull InputMethodManagerService service) {
        mService = service;
@@ -97,13 +98,13 @@ final class AutofillSuggestionsController {

    @GuardedBy("ImfLock.class")
    void onCreateInlineSuggestionsRequest(@UserIdInt int userId,
            InlineSuggestionsRequestInfo requestInfo, IInlineSuggestionsRequestCallback callback,
            InlineSuggestionsRequestInfo requestInfo, InlineSuggestionsRequestCallback callback,
            boolean touchExplorationEnabled) {
        clearPendingInlineSuggestionsRequest();
        mInlineSuggestionsRequestCallback = callback;
        final InputMethodInfo imi = mService.queryInputMethodForCurrentUserLocked(
                mService.getSelectedMethodIdLocked());
        try {

        if (userId == mService.getCurrentImeUserIdLocked()
                && imi != null && isInlineSuggestionsEnabled(imi, touchExplorationEnabled)) {
            mPendingInlineSuggestionsRequest = new CreateInlineSuggestionsRequest(
@@ -122,9 +123,6 @@ final class AutofillSuggestionsController {
        } else {
            callback.onInlineSuggestionsUnsupported();
        }
        } catch (RemoteException e) {
            Slog.w(TAG, "RemoteException calling onCreateInlineSuggestionsRequest(): " + e);
        }
    }

    @GuardedBy("ImfLock.class")
@@ -166,11 +164,7 @@ final class AutofillSuggestionsController {
    @GuardedBy("ImfLock.class")
    void invalidateAutofillSession() {
        if (mInlineSuggestionsRequestCallback != null) {
            try {
            mInlineSuggestionsRequestCallback.onInlineSuggestionsSessionInvalidated();
            } catch (RemoteException e) {
                Slog.e(TAG, "Cannot invalidate autofill session.", e);
            }
        }
    }

@@ -180,13 +174,13 @@ final class AutofillSuggestionsController {
     */
    private final class InlineSuggestionsRequestCallbackDecorator
            extends IInlineSuggestionsRequestCallback.Stub {
        @NonNull private final IInlineSuggestionsRequestCallback mCallback;
        @NonNull private final InlineSuggestionsRequestCallback mCallback;
        @NonNull private final String mImePackageName;
        private final int mImeDisplayId;
        @NonNull private final IBinder mImeToken;

        InlineSuggestionsRequestCallbackDecorator(
                @NonNull IInlineSuggestionsRequestCallback callback, @NonNull String imePackageName,
                @NonNull InlineSuggestionsRequestCallback callback, @NonNull String imePackageName,
                int displayId, @NonNull IBinder imeToken) {
            mCallback = callback;
            mImePackageName = imePackageName;
@@ -195,7 +189,7 @@ final class AutofillSuggestionsController {
        }

        @Override
        public void onInlineSuggestionsUnsupported() throws RemoteException {
        public void onInlineSuggestionsUnsupported() {
            mCallback.onInlineSuggestionsUnsupported();
        }

@@ -220,32 +214,32 @@ final class AutofillSuggestionsController {
        }

        @Override
        public void onInputMethodStartInput(AutofillId imeFieldId) throws RemoteException {
        public void onInputMethodStartInput(AutofillId imeFieldId) {
            mCallback.onInputMethodStartInput(imeFieldId);
        }

        @Override
        public void onInputMethodShowInputRequested(boolean requestResult) throws RemoteException {
        public void onInputMethodShowInputRequested(boolean requestResult) {
            mCallback.onInputMethodShowInputRequested(requestResult);
        }

        @Override
        public void onInputMethodStartInputView() throws RemoteException {
        public void onInputMethodStartInputView() {
            mCallback.onInputMethodStartInputView();
        }

        @Override
        public void onInputMethodFinishInputView() throws RemoteException {
        public void onInputMethodFinishInputView() {
            mCallback.onInputMethodFinishInputView();
        }

        @Override
        public void onInputMethodFinishInput() throws RemoteException {
        public void onInputMethodFinishInput() {
            mCallback.onInputMethodFinishInput();
        }

        @Override
        public void onInlineSuggestionsSessionInvalidated() throws RemoteException {
        public void onInlineSuggestionsSessionInvalidated() {
            mCallback.onInlineSuggestionsSessionInvalidated();
        }
    }
+4 −4
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ import android.view.inputmethod.InlineSuggestionsRequest;
import android.view.inputmethod.InputMethodInfo;

import com.android.internal.inputmethod.IAccessibilityInputMethodSession;
import com.android.internal.inputmethod.IInlineSuggestionsRequestCallback;
import com.android.internal.inputmethod.InlineSuggestionsRequestCallback;
import com.android.internal.inputmethod.InlineSuggestionsRequestInfo;
import com.android.internal.inputmethod.SoftInputShowHideReason;
import com.android.server.LocalServices;
@@ -86,11 +86,11 @@ public abstract class InputMethodManagerInternal {
     *
     * @param userId      the user ID to be queried
     * @param requestInfo information needed to create an {@link InlineSuggestionsRequest}.
     * @param cb          {@link IInlineSuggestionsRequestCallback} used to pass back the request
     * @param cb          {@link InlineSuggestionsRequestCallback} used to pass back the request
     *                    object
     */
    public abstract void onCreateInlineSuggestionsRequest(@UserIdInt int userId,
            InlineSuggestionsRequestInfo requestInfo, IInlineSuggestionsRequestCallback cb);
            InlineSuggestionsRequestInfo requestInfo, InlineSuggestionsRequestCallback cb);

    /**
     * Force switch to the enabled input method by {@code imeId} for current user. If the input
@@ -263,7 +263,7 @@ public abstract class InputMethodManagerInternal {
                @Override
                public void onCreateInlineSuggestionsRequest(@UserIdInt int userId,
                        InlineSuggestionsRequestInfo requestInfo,
                        IInlineSuggestionsRequestCallback cb) {
                        InlineSuggestionsRequestCallback cb) {
                }

                @Override
+2 −2
Original line number Diff line number Diff line
@@ -147,7 +147,6 @@ import com.android.internal.inputmethod.IAccessibilityInputMethodSession;
import com.android.internal.inputmethod.IBooleanListener;
import com.android.internal.inputmethod.IConnectionlessHandwritingCallback;
import com.android.internal.inputmethod.IImeTracker;
import com.android.internal.inputmethod.IInlineSuggestionsRequestCallback;
import com.android.internal.inputmethod.IInputContentUriToken;
import com.android.internal.inputmethod.IInputMethod;
import com.android.internal.inputmethod.IInputMethodClient;
@@ -157,6 +156,7 @@ import com.android.internal.inputmethod.IInputMethodSessionCallback;
import com.android.internal.inputmethod.IRemoteAccessibilityInputConnection;
import com.android.internal.inputmethod.IRemoteInputConnection;
import com.android.internal.inputmethod.ImeTracing;
import com.android.internal.inputmethod.InlineSuggestionsRequestCallback;
import com.android.internal.inputmethod.InlineSuggestionsRequestInfo;
import com.android.internal.inputmethod.InputBindResult;
import com.android.internal.inputmethod.InputMethodDebug;
@@ -5521,7 +5521,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.

        @Override
        public void onCreateInlineSuggestionsRequest(@UserIdInt int userId,
                InlineSuggestionsRequestInfo requestInfo, IInlineSuggestionsRequestCallback cb) {
                InlineSuggestionsRequestInfo requestInfo, InlineSuggestionsRequestCallback cb) {
            // Get the device global touch exploration state before lock to avoid deadlock.
            final boolean touchExplorationEnabled = AccessibilityManagerInternal.get()
                    .isTouchExplorationEnabled(userId);