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

Commit 0e75d9e4 authored by Wilson Wu's avatar Wilson Wu Committed by Android (Google) Code Review
Browse files

Merge "Make IInputMethodManager to oneway (5/N)"

parents 312aae75 d833f0da
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -25,6 +25,9 @@ import android.util.Log;
import android.util.proto.ProtoOutputStream;
import android.view.inputmethod.InputMethodManager;

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

import java.io.PrintWriter;

/**
@@ -32,7 +35,9 @@ import java.io.PrintWriter;
 */
class ImeTracingClientImpl extends ImeTracing {
    ImeTracingClientImpl() throws ServiceNotFoundException, RemoteException {
        sEnabled = mService.isImeTraceEnabled();
        final Completable.Boolean value = Completable.createBoolean();
        mService.isImeTraceEnabled(ResultCallbacks.of(value));
        sEnabled = Completable.getResult(value);
    }

    @Override
+29 −6
Original line number Diff line number Diff line
@@ -1747,8 +1747,14 @@ public final class InputMethodManager {

            try {
                Log.d(TAG, "showSoftInput() view=" + view + " flags=" + flags);
                return mService.showSoftInput(
                        mClient, view.getWindowToken(), flags, resultReceiver);
                final Completable.Boolean value = Completable.createBoolean();
                mService.showSoftInput(
                        mClient,
                        view.getWindowToken(),
                        flags,
                        resultReceiver,
                        ResultCallbacks.of(value));
                return Completable.getResult(value);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
@@ -1775,8 +1781,14 @@ public final class InputMethodManager {
                    Log.w(TAG, "No current root view, ignoring showSoftInputUnchecked()");
                    return;
                }
                final Completable.Boolean value = Completable.createBoolean();
                mService.showSoftInput(
                        mClient, mCurRootView.getView().getWindowToken(), flags, resultReceiver);
                        mClient,
                        mCurRootView.getView().getWindowToken(),
                        flags,
                        resultReceiver,
                        ResultCallbacks.of(value));
                Completable.getResult(value); // ignore the result
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
@@ -1849,7 +1861,10 @@ public final class InputMethodManager {
            }

            try {
                return mService.hideSoftInput(mClient, windowToken, flags, resultReceiver);
                final Completable.Boolean value = Completable.createBoolean();
                mService.hideSoftInput(
                        mClient, windowToken, flags, resultReceiver, ResultCallbacks.of(value));
                return Completable.getResult(value);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
@@ -2184,8 +2199,14 @@ public final class InputMethodManager {
                return;
            }
            try {
                final Completable.Boolean value = Completable.createBoolean();
                mService.hideSoftInput(
                        mClient, mCurRootView.getView().getWindowToken(), HIDE_NOT_ALWAYS, null);
                        mClient,
                        mCurRootView.getView().getWindowToken(),
                        HIDE_NOT_ALWAYS,
                        null,
                        ResultCallbacks.of(value));
                Completable.getResult(value); // ignore the result
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
@@ -2920,7 +2941,9 @@ public final class InputMethodManager {
    @TestApi
    public boolean isInputMethodPickerShown() {
        try {
            return mService.isInputMethodPickerShownForTest();
            final Completable.Boolean value = Completable.createBoolean();
            mService.isInputMethodPickerShownForTest(ResultCallbacks.of(value));
            return Completable.getResult(value);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+27 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.os.RemoteException;

import com.android.internal.view.InputBindResult;

import java.util.function.BooleanSupplier;
import java.util.function.Supplier;

/**
@@ -62,4 +63,30 @@ public final class CallbackUtils {
            callback.onResult(result);
        } catch (RemoteException ignored) { }
    }

    /**
     * A utility method using given {@link IBooleanResultCallback} to callback the result.
     *
     * @param callback {@link IInputBindResultResultCallback} to be called back.
     * @param resultSupplier the supplier from which the result is provided.
     */
    public static void onResult(@NonNull IBooleanResultCallback callback,
            @NonNull BooleanSupplier resultSupplier) {
        boolean result = false;
        Throwable exception = null;

        try {
            result = resultSupplier.getAsBoolean();
        } catch (Throwable throwable) {
            exception = throwable;
        }

        try {
            if (exception != null) {
                callback.onError(ThrowableHolder.of(exception));
                return;
            }
            callback.onResult(result);
        } catch (RemoteException ignored) { }
    }
}
+24 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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 com.android.internal.inputmethod.ThrowableHolder;

oneway interface IBooleanResultCallback {
    void onResult(boolean result);
    void onError(in ThrowableHolder exception);
}
 No newline at end of file
+35 −0
Original line number Diff line number Diff line
@@ -193,4 +193,39 @@ public final class ResultCallbacks {
            }
        };
    }

    /**
     * Creates {@link IBooleanResultCallback.Stub} that is to set {@link Completable.Boolean} when
     * receiving the result.
     *
     * @param value {@link Completable.Boolean} to be set when receiving the result.
     * @return {@link IBooleanResultCallback.Stub} that can be passed as a binder IPC parameter.
     */
    @AnyThread
    public static IBooleanResultCallback.Stub of(@NonNull Completable.Boolean value) {
        final AtomicReference<WeakReference<Completable.Boolean>>
                atomicRef = new AtomicReference<>(new WeakReference<>(value));

        return new IBooleanResultCallback.Stub() {
            @BinderThread
            @Override
            public void onResult(boolean result) {
                final Completable.Boolean value = unwrap(atomicRef);
                if (value == null) {
                    return;
                }
                value.onComplete(result);
            }

            @BinderThread
            @Override
            public void onError(ThrowableHolder throwableHolder) {
                final Completable.Boolean value = unwrap(atomicRef);
                if (value == null) {
                    return;
                }
                value.onError(throwableHolder);
            }
        };
    }
}
Loading