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

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

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

parents 73bef007 b9590fa1
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -88,8 +88,10 @@ import android.view.WindowManager.LayoutParams.SoftInputModeFlags;
import android.view.autofill.AutofillManager;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.inputmethod.Completable;
import com.android.internal.inputmethod.InputMethodDebug;
import com.android.internal.inputmethod.InputMethodPrivilegedOperationsRegistry;
import com.android.internal.inputmethod.ResultCallbacks;
import com.android.internal.inputmethod.StartInputFlags;
import com.android.internal.inputmethod.StartInputReason;
import com.android.internal.inputmethod.UnbindReason;
@@ -666,6 +668,7 @@ public final class InputMethodManager {
                    final int startInputReason =
                            nextFocusHasConnection ? WINDOW_FOCUS_GAIN_REPORT_WITH_CONNECTION
                                    : WINDOW_FOCUS_GAIN_REPORT_WITHOUT_CONNECTION;
                    final Completable.InputBindResult value = Completable.createInputBindResult();
                    mService.startInputOrWindowGainedFocus(
                            startInputReason, mClient,
                            focusedView.getWindowToken(), startInputFlags, softInputMode,
@@ -673,7 +676,9 @@ public final class InputMethodManager {
                            null,
                            null,
                            0 /* missingMethodFlags */,
                            mCurRootView.mContext.getApplicationInfo().targetSdkVersion);
                            mCurRootView.mContext.getApplicationInfo().targetSdkVersion,
                            ResultCallbacks.of(value));
                    Completable.getResult(value); // ignore the result
                } catch (RemoteException e) {
                    throw e.rethrowFromSystemServer();
                }
@@ -2039,10 +2044,13 @@ public final class InputMethodManager {
                if (DEBUG) Log.v(TAG, "START INPUT: view=" + dumpViewInfo(view) + " ic="
                        + ic + " tba=" + tba + " startInputFlags="
                        + InputMethodDebug.startInputFlagsToString(startInputFlags));
                res = mService.startInputOrWindowGainedFocus(
                final Completable.InputBindResult value = Completable.createInputBindResult();
                mService.startInputOrWindowGainedFocus(
                        startInputReason, mClient, windowGainingFocus, startInputFlags,
                        softInputMode, windowFlags, tba, servedContext, missingMethodFlags,
                        view.getContext().getApplicationInfo().targetSdkVersion);
                        view.getContext().getApplicationInfo().targetSdkVersion,
                        ResultCallbacks.of(value));
                res = Completable.getResult(value);
                if (DEBUG) Log.v(TAG, "Starting input: Bind result=" + res);
                if (res == null) {
                    Log.wtf(TAG, "startInputOrWindowGainedFocus must not return"
+52 −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 android.annotation.AnyThread;
import android.annotation.NonNull;
import android.os.RemoteException;

import com.android.internal.view.InputBindResult;

import java.util.function.Supplier;

/**
 * Defines a set of helper methods to callback corresponding results in {@link ResultCallbacks}.
 */
public final class CallbackUtils {

    /**
     * Not intended to be instantiated.
     */
    private CallbackUtils() {
    }

    /**
     * A utility method using given {@link IInputBindResultResultCallback} to callback the
     * {@link InputBindResult}.
     *
     * @param callback {@link IInputBindResultResultCallback} to be called back.
     * @param resultSupplier the supplier from which {@link InputBindResult} is provided.
     */
    @AnyThread
    public static void onResult(@NonNull IInputBindResultResultCallback callback,
            @NonNull Supplier<InputBindResult> resultSupplier) {
        try {
            callback.onResult(resultSupplier.get());
        } catch (RemoteException ignored) { }
    }
}
+29 −0
Original line number Diff line number Diff line
@@ -124,6 +124,16 @@ public final class Completable {
                return true;
            }
        }

        /**
         * Blocks the calling thread until this object becomes ready to return the value.
         */
        @AnyThread
        public void await() {
            try {
                mLatch.await();
            } catch (InterruptedException ignored) { }
        }
    }

    /**
@@ -249,6 +259,13 @@ public final class Completable {
        return new Completable.SurroundingText();
    }

    /**
     * @return an instance of {@link Completable.InputBindResult}.
     */
    public static Completable.InputBindResult createInputBindResult() {
        return new Completable.InputBindResult();
    }

    /**
     * Completable object of {@link java.lang.Boolean}.
     */
@@ -277,6 +294,18 @@ public final class Completable {
    public static final class InputBindResult
            extends Values<com.android.internal.view.InputBindResult> { }

    /**
     * Await the result by the {@link Completable.Values}.
     *
     * @return the result once {@link ValueBase#onComplete()}
     */
    @AnyThread
    @Nullable
    public static <T> T getResult(@NonNull Completable.Values<T> value) {
        value.await();
        return value.getValue();
    }

    /**
     * Await the result by the {@link Completable.Int}, and log it if there is no result after
     * given timeout.
+23 −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.view.InputBindResult;

oneway interface IInputBindResultResultCallback {
    void onResult(in InputBindResult result);
}
 No newline at end of file
+29 −0
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import android.annotation.BinderThread;
import android.annotation.NonNull;
import android.annotation.Nullable;

import com.android.internal.view.InputBindResult;

import java.lang.ref.WeakReference;
import java.util.concurrent.atomic.AtomicReference;

@@ -154,4 +156,31 @@ public final class ResultCallbacks {
            }
        };
    }

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

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