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

Commit c4663ba6 authored by Wilson Wu's avatar Wilson Wu
Browse files

Make IInputMethodManager to oneway (10/N)

1. Comply following methods to IVoidResultCallback to
emulate current behavior.

-. setAdditionalInputMethodSubtypes
-. removeImeSurface
-. removeImeSurfaceFromWindow

2. Add "oneway" to all methods which we already apply them
to result-callback model.

Bug: 163453493
Test: Manual test with keyboard
Test: atest CtsInputMethodTestCases
Test: atest DisplayImeControllerTest
Change-Id: Icb396ae5d74060af69c4ecb16723b2e37b9f2067
parent 7e56827d
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -2307,7 +2307,9 @@ public final class InputMethodManager {
    public void removeImeSurface(IBinder windowToken) {
        synchronized (mH) {
            try {
                mService.removeImeSurfaceFromWindow(windowToken);
                final Completable.Void value = Completable.createVoid();
                mService.removeImeSurfaceFromWindow(windowToken, ResultCallbacks.of(value));
                Completable.getResult(value);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
@@ -3239,7 +3241,9 @@ public final class InputMethodManager {
    @Deprecated
    public void setAdditionalInputMethodSubtypes(String imiId, InputMethodSubtype[] subtypes) {
        try {
            mService.setAdditionalInputMethodSubtypes(imiId, subtypes);
            final Completable.Void value = Completable.createVoid();
            mService.setAdditionalInputMethodSubtypes(imiId, subtypes, ResultCallbacks.of(value));
            Completable.getResult(value);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+23 −19
Original line number Diff line number Diff line
@@ -41,22 +41,24 @@ interface IInputMethodManager {
            int untrustedDisplayId);

    // TODO: Use ParceledListSlice instead
    void getInputMethodList(int userId, in IInputMethodInfoListResultCallback resultCallback);
    oneway void getInputMethodList(int userId,
            in IInputMethodInfoListResultCallback resultCallback);
    // TODO: Use ParceledListSlice instead
    void getEnabledInputMethodList(int userId,
    oneway void getEnabledInputMethodList(int userId,
            in IInputMethodInfoListResultCallback resultCallback);
    void getEnabledInputMethodSubtypeList(in String imiId, boolean allowsImplicitlySelectedSubtypes,
    oneway void getEnabledInputMethodSubtypeList(in String imiId,
            boolean allowsImplicitlySelectedSubtypes,
            in IInputMethodSubtypeListResultCallback resultCallback);
    void getLastInputMethodSubtype(in IInputMethodSubtypeResultCallback resultCallback);
    oneway void getLastInputMethodSubtype(in IInputMethodSubtypeResultCallback resultCallback);

    void showSoftInput(in IInputMethodClient client, IBinder windowToken, int flags,
    oneway void showSoftInput(in IInputMethodClient client, IBinder windowToken, int flags,
            in ResultReceiver resultReceiver, in IBooleanResultCallback resultCallback);
    void hideSoftInput(in IInputMethodClient client, IBinder windowToken, int flags,
    oneway void hideSoftInput(in IInputMethodClient client, IBinder windowToken, int flags,
            in ResultReceiver resultReceiver, in IBooleanResultCallback resultCallback);
    // If windowToken is null, this just does startInput().  Otherwise this reports that a window
    // has gained focus, and if 'attribute' is non-null then also does startInput.
    // @NonNull
    void startInputOrWindowGainedFocus(
    oneway void startInputOrWindowGainedFocus(
            /* @StartInputReason */ int startInputReason,
            in IInputMethodClient client, in IBinder windowToken,
            /* @StartInputFlags */ int startInputFlags,
@@ -66,29 +68,31 @@ interface IInputMethodManager {
            int unverifiedTargetSdkVersion,
            in IInputBindResultResultCallback inputBindResult);

    void showInputMethodPickerFromClient(in IInputMethodClient client,
    oneway void showInputMethodPickerFromClient(in IInputMethodClient client,
            int auxiliarySubtypeMode, in IVoidResultCallback resultCallback);
    void showInputMethodPickerFromSystem(in IInputMethodClient client, int auxiliarySubtypeMode,
            int displayId, in IVoidResultCallback resultCallback);
    void showInputMethodAndSubtypeEnablerFromClient(in IInputMethodClient client, String topId,
    oneway void showInputMethodPickerFromSystem(in IInputMethodClient client,
            int auxiliarySubtypeMode, int displayId, in IVoidResultCallback resultCallback);
    oneway void showInputMethodAndSubtypeEnablerFromClient(in IInputMethodClient client,
            String topId, in IVoidResultCallback resultCallback);
    oneway void isInputMethodPickerShownForTest(in IBooleanResultCallback resultCallback);
    oneway void getCurrentInputMethodSubtype(in IInputMethodSubtypeResultCallback resultCallback);
    oneway void setAdditionalInputMethodSubtypes(String id, in InputMethodSubtype[] subtypes,
            in IVoidResultCallback resultCallback);
    void isInputMethodPickerShownForTest(in IBooleanResultCallback resultCallback);
    void getCurrentInputMethodSubtype(in IInputMethodSubtypeResultCallback resultCallback);
    void setAdditionalInputMethodSubtypes(String id, in InputMethodSubtype[] subtypes);
    // This is kept due to @UnsupportedAppUsage.
    // TODO(Bug 113914148): Consider removing this.
    void getInputMethodWindowVisibleHeight(IIntResultCallback resultCallback);
    oneway void getInputMethodWindowVisibleHeight(IIntResultCallback resultCallback);

    void reportActivityView(in IInputMethodClient parentClient, int childDisplayId,
    oneway void reportActivityView(in IInputMethodClient parentClient, int childDisplayId,
            in float[] matrixValues, in IVoidResultCallback resultCallback);

    oneway void reportPerceptible(in IBinder windowToken, boolean perceptible);
    /** Remove the IME surface. Requires INTERNAL_SYSTEM_WINDOW permission. */
    void removeImeSurface();
    oneway void removeImeSurface(in IVoidResultCallback resultCallback);
    /** Remove the IME surface. Requires passing the currently focused window. */
    void removeImeSurfaceFromWindow(in IBinder windowToken);
    oneway void removeImeSurfaceFromWindow(in IBinder windowToken,
            in IVoidResultCallback resultCallback);
    void startProtoDump(in byte[] protoDump, int source, String where);
    void isImeTraceEnabled(in IBooleanResultCallback resultCallback);
    oneway void isImeTraceEnabled(in IBooleanResultCallback resultCallback);

    // Starts an ime trace.
    void startImeTrace();
+5 −1
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@ import android.view.animation.PathInterpolator;
import androidx.annotation.BinderThread;
import androidx.annotation.VisibleForTesting;

import com.android.internal.inputmethod.Completable;
import com.android.internal.inputmethod.ResultCallbacks;
import com.android.internal.view.IInputMethodManager;

import java.util.ArrayList;
@@ -506,7 +508,9 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
            try {
                // Remove the IME surface to make the insets invisible for
                // non-client controlled insets.
                imms.removeImeSurface();
                final Completable.Void value = Completable.createVoid();
                imms.removeImeSurface(ResultCallbacks.of(value));
                Completable.getResult(value);
            } catch (RemoteException e) {
                Slog.e(TAG, "Failed to remove IME surface.", e);
            }
+2 −0
Original line number Diff line number Diff line
@@ -65,6 +65,8 @@ public class DisplayImeControllerTest {
            public IInputMethodManager getImms() {
                return mMock;
            }
            @Override
            void removeImeSurface() { }
        }.new PerDisplay(DEFAULT_DISPLAY, ROTATION_0);
    }

+62 −54
Original line number Diff line number Diff line
@@ -3947,7 +3947,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
    }

    @Override
    public void setAdditionalInputMethodSubtypes(String imiId, InputMethodSubtype[] subtypes) {
    public void setAdditionalInputMethodSubtypes(String imiId, InputMethodSubtype[] subtypes,
            IVoidResultCallback resultCallback) {
        CallbackUtils.onResult(resultCallback, () -> {
            // By this IPC call, only a process which shares the same uid with the IME can add
            // additional input method subtypes to the IME.
            if (TextUtils.isEmpty(imiId) || subtypes == null) return;
@@ -3999,6 +4001,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                }
            }
            return;
        });
    }

    /**
@@ -4103,16 +4106,21 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
    }

    @Override
    public void removeImeSurface() {
    public void removeImeSurface(IVoidResultCallback resultCallback) {
        CallbackUtils.onResult(resultCallback, () -> {
            mContext.enforceCallingPermission(Manifest.permission.INTERNAL_SYSTEM_WINDOW, null);
            mHandler.sendMessage(mHandler.obtainMessage(MSG_REMOVE_IME_SURFACE));
        });
    }

    @Override
    public void removeImeSurfaceFromWindow(IBinder windowToken) {
    public void removeImeSurfaceFromWindow(IBinder windowToken,
            IVoidResultCallback resultCallback) {
        CallbackUtils.onResult(resultCallback, () -> {
            // No permission check, because we'll only execute the request if the calling window is
            // also the current IME client.
            mHandler.obtainMessage(MSG_REMOVE_IME_SURFACE_FROM_WINDOW, windowToken).sendToTarget();
        });
    }

    /**
Loading