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

Commit 75b51f31 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Use IBooleanResultCallback when appropriate in IInputContext"

parents 53e843c4 14add1cb
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -361,9 +361,9 @@ final class RemoteInputConnection implements InputConnection {
            // This method is not implemented.
            return false;
        }
        final Completable.Int value = mInvoker.requestCursorUpdates(cursorUpdateMode);
        return Completable.getResultOrZero(value, TAG, "requestCursorUpdates()",
                mCancellationGroup, MAX_WAIT_TIME_MILLIS) != 0;
        final Completable.Boolean value = mInvoker.requestCursorUpdates(cursorUpdateMode);
        return Completable.getResultOrFalse(value, TAG, "requestCursorUpdates()",
                mCancellationGroup, MAX_WAIT_TIME_MILLIS);
    }

    @AnyThread
@@ -397,9 +397,9 @@ final class RemoteInputConnection implements InputConnection {
            inputMethodService.exposeContent(inputContentInfo, this);
        }

        final Completable.Int value = mInvoker.commitContent(inputContentInfo, flags, opts);
        return Completable.getResultOrZero(
                value, TAG, "commitContent()", mCancellationGroup, MAX_WAIT_TIME_MILLIS) != 0;
        final Completable.Boolean value = mInvoker.commitContent(inputContentInfo, flags, opts);
        return Completable.getResultOrFalse(
                value, TAG, "commitContent()", mCancellationGroup, MAX_WAIT_TIME_MILLIS);
    }

    /**
+18 −0
Original line number Diff line number Diff line
@@ -543,6 +543,24 @@ public final class Completable {
        value.getValue();
    }

    /**
     * Await the result by the {@link Completable.Boolean}, and log it if there is no result after
     * given timeout.
     *
     * @return the result once {@link ValueBase#onComplete()}
     */
    @AnyThread
    public static boolean getResultOrFalse(@NonNull Completable.Boolean value, String tag,
            @NonNull String methodName, @Nullable CancellationGroup cancellationGroup,
            int maxWaitTime) {
        final boolean timedOut = value.await(maxWaitTime, TimeUnit.MILLISECONDS, cancellationGroup);
        if (value.hasValue()) {
            return value.getValue();
        }
        logInternal(tag, methodName, timedOut, maxWaitTime, 0);
        return false;
    }

    /**
     * Await the result by the {@link Completable.Int}, and log it if there is no result after
     * given timeout.
+6 −6
Original line number Diff line number Diff line
@@ -474,13 +474,13 @@ public final class IInputContextInvoker {
     * Invokes {@link IInputContext#requestCursorUpdates(int, IIntResultCallback)}.
     *
     * @param cursorUpdateMode {@code cursorUpdateMode} parameter to be passed.
     * @return {@link Completable.Int} that can be used to retrieve the invocation result.
     * @return {@link Completable.Boolean} that can be used to retrieve the invocation result.
     *         {@link RemoteException} will be treated as an error.
     */
    @AnyThread
    @NonNull
    public Completable.Int requestCursorUpdates(int cursorUpdateMode) {
        final Completable.Int value = Completable.createInt();
    public Completable.Boolean requestCursorUpdates(int cursorUpdateMode) {
        final Completable.Boolean value = Completable.createBoolean();
        try {
            mIInputContext.requestCursorUpdates(cursorUpdateMode, ResultCallbacks.of(value));
        } catch (RemoteException e) {
@@ -496,14 +496,14 @@ public final class IInputContextInvoker {
     * @param inputContentInfo {@code inputContentInfo} parameter to be passed.
     * @param flags {@code flags} parameter to be passed.
     * @param opts {@code opts} parameter to be passed.
     * @return {@link Completable.Int} that can be used to retrieve the invocation result.
     * @return {@link Completable.Boolean} that can be used to retrieve the invocation result.
     *         {@link RemoteException} will be treated as an error.
     */
    @AnyThread
    @NonNull
    public Completable.Int commitContent(InputContentInfo inputContentInfo, int flags,
    public Completable.Boolean commitContent(InputContentInfo inputContentInfo, int flags,
            Bundle opts) {
        final Completable.Int value = Completable.createInt();
        final Completable.Boolean value = Completable.createBoolean();
        try {
            mIInputContext.commitContent(inputContentInfo, flags, opts, ResultCallbacks.of(value));
        } catch (RemoteException e) {
+7 −6
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.SurroundingText;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.inputmethod.IBooleanResultCallback;
import com.android.internal.inputmethod.ICharSequenceResultCallback;
import com.android.internal.inputmethod.IExtractedTextResultCallback;
import com.android.internal.inputmethod.IIntResultCallback;
@@ -309,7 +310,7 @@ public final class IInputConnectionWrapper extends IInputContext.Stub {
        dispatchMessage(obtainMessageOO(DO_PERFORM_PRIVATE_COMMAND, action, data));
    }

    public void requestCursorUpdates(int cursorUpdateMode, IIntResultCallback callback) {
    public void requestCursorUpdates(int cursorUpdateMode, IBooleanResultCallback callback) {
        dispatchMessage(mH.obtainMessage(DO_REQUEST_CURSOR_UPDATES, cursorUpdateMode,
                0 /* unused */, callback));
    }
@@ -319,7 +320,7 @@ public final class IInputConnectionWrapper extends IInputContext.Stub {
    }

    public void commitContent(InputContentInfo inputContentInfo, int flags, Bundle opts,
            IIntResultCallback callback) {
            IBooleanResultCallback callback) {
        final SomeArgs args = SomeArgs.obtain();
        args.arg1 = inputContentInfo;
        args.arg2 = opts;
@@ -797,7 +798,7 @@ public final class IInputConnectionWrapper extends IInputContext.Stub {
            case DO_REQUEST_CURSOR_UPDATES: {
                Trace.traceBegin(Trace.TRACE_TAG_INPUT, "InputConnection#requestCursorUpdates");
                try {
                    final IIntResultCallback callback = (IIntResultCallback) msg.obj;
                    final IBooleanResultCallback callback = (IBooleanResultCallback) msg.obj;
                    final InputConnection ic = getInputConnection();
                    final boolean result;
                    if (ic == null || !isActive()) {
@@ -807,7 +808,7 @@ public final class IInputConnectionWrapper extends IInputContext.Stub {
                        result = ic.requestCursorUpdates(msg.arg1);
                    }
                    try {
                        callback.onResult(result ? 1 : 0);
                        callback.onResult(result);
                    } catch (RemoteException e) {
                        Log.w(TAG, "Failed to return the result to requestCursorUpdates()."
                                + " result=" + result, e);
@@ -854,7 +855,7 @@ public final class IInputConnectionWrapper extends IInputContext.Stub {
                SomeArgs args = (SomeArgs) msg.obj;
                Trace.traceBegin(Trace.TRACE_TAG_INPUT, "InputConnection#commitContent");
                try {
                    final IIntResultCallback callback = (IIntResultCallback) args.arg3;
                    final IBooleanResultCallback callback = (IBooleanResultCallback) args.arg3;
                    final InputConnection ic = getInputConnection();
                    final boolean result;
                    if (ic == null || !isActive()) {
@@ -871,7 +872,7 @@ public final class IInputConnectionWrapper extends IInputContext.Stub {
                        }
                    }
                    try {
                        callback.onResult(result ? 1 : 0);
                        callback.onResult(result);
                    } catch (RemoteException e) {
                        Log.w(TAG, "Failed to return the result to commitContent()."
                                + " result=" + result, e);
+3 −2
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.view.inputmethod.CorrectionInfo;
import android.view.inputmethod.ExtractedTextRequest;
import android.view.inputmethod.InputContentInfo;

import com.android.internal.inputmethod.IBooleanResultCallback;
import com.android.internal.inputmethod.ICharSequenceResultCallback;
import com.android.internal.inputmethod.IExtractedTextResultCallback;
import com.android.internal.inputmethod.IIntResultCallback;
@@ -78,10 +79,10 @@ import com.android.internal.inputmethod.ISurroundingTextResultCallback;

    void getSelectedText(int flags, ICharSequenceResultCallback callback);

    void requestCursorUpdates(int cursorUpdateMode, IIntResultCallback callback);
    void requestCursorUpdates(int cursorUpdateMode, IBooleanResultCallback callback);

    void commitContent(in InputContentInfo inputContentInfo, int flags, in Bundle opts,
            IIntResultCallback callback);
            IBooleanResultCallback callback);

    void getSurroundingText(int beforeLength, int afterLength, int flags,
            ISurroundingTextResultCallback callback);