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

Commit 0a32fd21 authored by Wilson Wu's avatar Wilson Wu
Browse files

Make IInputMethodManager to oneway (9/N)

Apply following methods to IVoidResultCallback to emulate
current behavior before we change them to one-way.

-. showInputMethodPickerFromClient
-. showInputMethodPickerFromSystem
-. showInputMethodAndSubtypeEnablerFromClient
-. reportActivityView

Bug: 163453493
Test: Manual test with keyboard
Test: atest CtsInputMethodTestCases
Test: atest CtsWindowManagerDeviceTestCases:ActivityViewTest
Change-Id: Id516fd1c961f43ac3e139c88d7ed004c188d458b
parent 4f4ec2fa
Loading
Loading
Loading
Loading
+16 −4
Original line number Diff line number Diff line
@@ -2926,7 +2926,10 @@ public final class InputMethodManager {
                ? SHOW_IM_PICKER_MODE_INCLUDE_AUXILIARY_SUBTYPES
                : SHOW_IM_PICKER_MODE_EXCLUDE_AUXILIARY_SUBTYPES;
        try {
            mService.showInputMethodPickerFromSystem(mClient, mode, displayId);
            final Completable.Void value = Completable.createVoid();
            mService.showInputMethodPickerFromSystem(
                    mClient, mode, displayId, ResultCallbacks.of(value));
            Completable.getResult(value);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -2934,7 +2937,10 @@ public final class InputMethodManager {

    private void showInputMethodPickerLocked() {
        try {
            mService.showInputMethodPickerFromClient(mClient, SHOW_IM_PICKER_MODE_AUTO);
            final Completable.Void value = Completable.createVoid();
            mService.showInputMethodPickerFromClient(
                    mClient, SHOW_IM_PICKER_MODE_AUTO, ResultCallbacks.of(value));
            Completable.getResult(value);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -2970,7 +2976,10 @@ public final class InputMethodManager {
     */
    public void showInputMethodAndSubtypeEnabler(String imiId) {
        try {
            mService.showInputMethodAndSubtypeEnablerFromClient(mClient, imiId);
            final Completable.Void value = Completable.createVoid();
            mService.showInputMethodAndSubtypeEnablerFromClient(
                    mClient, imiId, ResultCallbacks.of(value));
            Completable.getResult(value);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -3132,7 +3141,10 @@ public final class InputMethodManager {
                matrixValues = new float[9];
                matrix.getValues(matrixValues);
            }
            mService.reportActivityView(mClient, childDisplayId, matrixValues);
            final Completable.Void value = Completable.createVoid();
            mService.reportActivityView(
                    mClient, childDisplayId, matrixValues, ResultCallbacks.of(value));
            Completable.getResult(value);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+3 −3
Original line number Diff line number Diff line
@@ -205,14 +205,14 @@ public final class CallbackUtils {
     * A utility method using given {@link IVoidResultCallback} to callback the result.
     *
     * @param callback {@link IVoidResultCallback} to be called back.
     * @param resultSupplier the supplier from which the result is provided.
     * @param runnable to execute the given method
     */
    public static void onResult(@NonNull IVoidResultCallback callback,
            @NonNull Supplier<Void> resultSupplier) {
            @NonNull Runnable runnable) {
        Throwable exception = null;

        try {
            resultSupplier.get();
            runnable.run();
        } catch (Throwable throwable) {
            exception = throwable;
        }
+6 −4
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import com.android.internal.inputmethod.IInputMethodInfoListResultCallback;
import com.android.internal.inputmethod.IInputMethodSubtypeResultCallback;
import com.android.internal.inputmethod.IInputMethodSubtypeListResultCallback;
import com.android.internal.inputmethod.IIntResultCallback;
import com.android.internal.inputmethod.IVoidResultCallback;

/**
 * Public interface to the global input method manager, used by all client
@@ -66,10 +67,11 @@ interface IInputMethodManager {
            in IInputBindResultResultCallback inputBindResult);

    void showInputMethodPickerFromClient(in IInputMethodClient client,
            int auxiliarySubtypeMode);
            int auxiliarySubtypeMode, in IVoidResultCallback resultCallback);
    void showInputMethodPickerFromSystem(in IInputMethodClient client, int auxiliarySubtypeMode,
            int displayId);
    void showInputMethodAndSubtypeEnablerFromClient(in IInputMethodClient client, String topId);
            int displayId, in IVoidResultCallback resultCallback);
    void showInputMethodAndSubtypeEnablerFromClient(in IInputMethodClient client, String topId,
            in IVoidResultCallback resultCallback);
    void isInputMethodPickerShownForTest(in IBooleanResultCallback resultCallback);
    void getCurrentInputMethodSubtype(in IInputMethodSubtypeResultCallback resultCallback);
    void setAdditionalInputMethodSubtypes(String id, in InputMethodSubtype[] subtypes);
@@ -78,7 +80,7 @@ interface IInputMethodManager {
    void getInputMethodWindowVisibleHeight(IIntResultCallback resultCallback);

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

    oneway void reportPerceptible(in IBinder windowToken, boolean perceptible);
    /** Remove the IME surface. Requires INTERNAL_SYSTEM_WINDOW permission. */
+111 −100
Original line number Diff line number Diff line
@@ -167,6 +167,7 @@ import com.android.internal.inputmethod.IInputMethodPrivilegedOperations;
import com.android.internal.inputmethod.IInputMethodSubtypeListResultCallback;
import com.android.internal.inputmethod.IInputMethodSubtypeResultCallback;
import com.android.internal.inputmethod.IIntResultCallback;
import com.android.internal.inputmethod.IVoidResultCallback;
import com.android.internal.inputmethod.InputMethodDebug;
import com.android.internal.inputmethod.SoftInputShowHideReason;
import com.android.internal.inputmethod.StartInputFlags;
@@ -3720,8 +3721,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
    }

    @Override
    public void showInputMethodPickerFromClient(
            IInputMethodClient client, int auxiliarySubtypeMode) {
    public void showInputMethodPickerFromClient(IInputMethodClient client, int auxiliarySubtypeMode,
            IVoidResultCallback resultCallback) {
        CallbackUtils.onResult(resultCallback, () -> {
            synchronized (mMethodMap) {
                if (!calledFromValidUserLocked()) {
                    return;
@@ -3738,20 +3740,24 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                        MSG_SHOW_IM_SUBTYPE_PICKER, auxiliarySubtypeMode,
                        (mCurClient != null) ? mCurClient.selfReportedDisplayId : DEFAULT_DISPLAY));
            }
        });
    }

    @Override
    public void showInputMethodPickerFromSystem(IInputMethodClient client, int auxiliarySubtypeMode,
            int displayId) {
            int displayId, IVoidResultCallback resultCallback) {
        CallbackUtils.onResult(resultCallback, () -> {
            if (mContext.checkCallingPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS)
                    != PackageManager.PERMISSION_GRANTED) {
                throw new SecurityException(
                    "showInputMethodPickerFromSystem requires WRITE_SECURE_SETTINGS permission");
                        "showInputMethodPickerFromSystem requires WRITE_SECURE_SETTINGS "
                                + "permission");
            }
            // Always call subtype picker, because subtype picker is a superset of input method
            // picker.
            mHandler.sendMessage(mCaller.obtainMessageII(
                    MSG_SHOW_IM_SUBTYPE_PICKER, auxiliarySubtypeMode, displayId));
        });
    }

    /**
@@ -3795,7 +3801,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub

    @Override
    public void showInputMethodAndSubtypeEnablerFromClient(
            IInputMethodClient client, String inputMethodId) {
            IInputMethodClient client, String inputMethodId, IVoidResultCallback resultCallback) {
        CallbackUtils.onResult(resultCallback, () -> {
            synchronized (mMethodMap) {
                // TODO(yukawa): Should we verify the display ID?
                if (!calledFromValidUserLocked()) {
@@ -3804,6 +3811,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                executeOrSendMessage(mCurMethod, mCaller.obtainMessageO(
                        MSG_SHOW_IM_SUBTYPE_ENABLER, inputMethodId));
            }
        });
    }

    @BinderThread
@@ -4011,7 +4019,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub

    @Override
    public void reportActivityView(IInputMethodClient parentClient, int childDisplayId,
            float[] matrixValues) {
            float[] matrixValues, IVoidResultCallback resultCallback) {
        CallbackUtils.onResult(resultCallback, () -> {
            final DisplayInfo displayInfo = mDisplayManagerInternal.getDisplayInfo(childDisplayId);
            if (displayInfo == null) {
                throw new IllegalArgumentException(
@@ -4030,7 +4039,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub

                // null matrixValues means that the entry needs to be removed.
                if (matrixValues == null) {
                final ActivityViewInfo info = mActivityViewDisplayIdToParentMap.get(childDisplayId);
                    final ActivityViewInfo info =
                            mActivityViewDisplayIdToParentMap.get(childDisplayId);
                    if (info == null) {
                        return;
                    }
@@ -4089,6 +4099,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                    displayId = info.mParentClient.selfReportedDisplayId;
                }
            }
        });
    }

    @Override
+12 −7
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ import com.android.internal.inputmethod.IIntResultCallback;
import com.android.internal.inputmethod.IMultiClientInputMethod;
import com.android.internal.inputmethod.IMultiClientInputMethodPrivilegedOperations;
import com.android.internal.inputmethod.IMultiClientInputMethodSession;
import com.android.internal.inputmethod.IVoidResultCallback;
import com.android.internal.inputmethod.SoftInputShowHideReason;
import com.android.internal.inputmethod.StartInputFlags;
import com.android.internal.inputmethod.StartInputReason;
@@ -1776,23 +1777,26 @@ public final class MultiClientInputMethodManagerService {

        @BinderThread
        @Override
        public void showInputMethodPickerFromClient(
                IInputMethodClient client, int auxiliarySubtypeMode) {
        public void showInputMethodPickerFromClient(IInputMethodClient client,
                int auxiliarySubtypeMode, IVoidResultCallback resultCallback) {
            reportNotSupported();
            CallbackUtils.onResult(resultCallback, () -> { });
        }

        @BinderThread
        @Override
        public void showInputMethodPickerFromSystem(
                IInputMethodClient client, int auxiliarySubtypeMode, int displayId) {
        public void showInputMethodPickerFromSystem(IInputMethodClient client,
                int auxiliarySubtypeMode, int displayId, IVoidResultCallback resultCallback) {
            reportNotSupported();
            CallbackUtils.onResult(resultCallback, () -> { });
        }

        @BinderThread
        @Override
        public void showInputMethodAndSubtypeEnablerFromClient(
                IInputMethodClient client, String inputMethodId) {
        public void showInputMethodAndSubtypeEnablerFromClient(IInputMethodClient client,
                String inputMethodId, IVoidResultCallback resultCallback) {
            reportNotSupported();
            CallbackUtils.onResult(resultCallback, () -> { });
        }

        @BinderThread
@@ -1825,8 +1829,9 @@ public final class MultiClientInputMethodManagerService {
        @BinderThread
        @Override
        public void reportActivityView(IInputMethodClient parentClient, int childDisplayId,
                float[] matrixValues) {
                float[] matrixValues, IVoidResultCallback resultCallback) {
            reportNotSupported();
            CallbackUtils.onResult(resultCallback, () -> { });
        }

        @BinderThread