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

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

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

parents 80401a0a 4a820ccc
Loading
Loading
Loading
Loading
+15 −5
Original line number Diff line number Diff line
@@ -1361,7 +1361,9 @@ public final class InputMethodManager {
            // We intentionally do not use UserHandle.getCallingUserId() here because for system
            // services InputMethodManagerInternal.getInputMethodListAsUser() should be used
            // instead.
            return mService.getInputMethodList(UserHandle.myUserId());
            final Completable.InputMethodInfoList value = Completable.createInputMethodInfoList();
            mService.getInputMethodList(UserHandle.myUserId(), ResultCallbacks.of(value));
            return Completable.getResult(value);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -1377,7 +1379,9 @@ public final class InputMethodManager {
    @RequiresPermission(INTERACT_ACROSS_USERS_FULL)
    public List<InputMethodInfo> getInputMethodListAsUser(@UserIdInt int userId) {
        try {
            return mService.getInputMethodList(userId);
            final Completable.InputMethodInfoList value = Completable.createInputMethodInfoList();
            mService.getInputMethodList(userId,  ResultCallbacks.of(value));
            return Completable.getResult(value);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -1395,7 +1399,9 @@ public final class InputMethodManager {
            // We intentionally do not use UserHandle.getCallingUserId() here because for system
            // services InputMethodManagerInternal.getEnabledInputMethodListAsUser() should be used
            // instead.
            return mService.getEnabledInputMethodList(UserHandle.myUserId());
            final Completable.InputMethodInfoList value = Completable.createInputMethodInfoList();
            mService.getEnabledInputMethodList(UserHandle.myUserId(), ResultCallbacks.of(value));
            return Completable.getResult(value);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -1411,7 +1417,9 @@ public final class InputMethodManager {
    @RequiresPermission(INTERACT_ACROSS_USERS_FULL)
    public List<InputMethodInfo> getEnabledInputMethodListAsUser(@UserIdInt int userId) {
        try {
            return mService.getEnabledInputMethodList(userId);
            final Completable.InputMethodInfoList value = Completable.createInputMethodInfoList();
            mService.getEnabledInputMethodList(userId, ResultCallbacks.of(value));
            return Completable.getResult(value);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -3098,7 +3106,9 @@ public final class InputMethodManager {
    @UnsupportedAppUsage
    public int getInputMethodWindowVisibleHeight() {
        try {
            return mService.getInputMethodWindowVisibleHeight();
            final Completable.Int value = Completable.createInt();
            mService.getInputMethodWindowVisibleHeight(ResultCallbacks.of(value));
            return Completable.getIntResult(value);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+55 −0
Original line number Diff line number Diff line
@@ -19,12 +19,14 @@ package com.android.internal.inputmethod;
import android.annotation.AnyThread;
import android.annotation.NonNull;
import android.os.RemoteException;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype;

import com.android.internal.view.InputBindResult;

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

/**
@@ -145,4 +147,57 @@ public final class CallbackUtils {
            callback.onResult(result);
        } catch (RemoteException ignored) { }
    }

    /**
     * A utility method using given {@link IInputMethodInfoListResultCallback} to callback the
     * result.
     *
     * @param callback {@link IInputMethodInfoListResultCallback} to be called back.
     * @param resultSupplier the supplier from which the result is provided.
     */
    public static void onResult(@NonNull IInputMethodInfoListResultCallback callback,
            @NonNull Supplier<List<InputMethodInfo>> resultSupplier) {
        List<InputMethodInfo> result = null;
        Throwable exception = null;

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

        try {
            if (exception != null) {
                callback.onError(ThrowableHolder.of(exception));
                return;
            }
            callback.onResult(result);
        } catch (RemoteException ignored) { }
    }

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

        try {
            result = resultSupplier.getAsInt();
        } 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
@@ -388,6 +388,13 @@ public final class Completable {
        return new Completable.InputMethodSubtypeList();
    }

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

    /**
     * Completable object of {@link java.lang.Boolean}.
     */
@@ -428,6 +435,12 @@ public final class Completable {
    public static final class InputMethodSubtypeList
            extends Values<List<android.view.inputmethod.InputMethodSubtype>> { }

    /**
     * Completable object of {@link List<android.view.inputmethod.InputMethodInfo>}.
     */
    public static final class InputMethodInfoList
            extends Values<List<android.view.inputmethod.InputMethodInfo>> { }

    /**
     * Await the result by the {@link Completable.Values}.
     *
@@ -440,6 +453,17 @@ public final class Completable {
        return value.getValue();
    }

    /**
     * Await the int result by the {@link Completable.Int}.
     *
     * @return the result once {@link ValueBase#onComplete()}
     */
    @AnyThread
    public static int getIntResult(@NonNull Completable.Int 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.
+25 −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.view.inputmethod.InputMethodInfo;
import com.android.internal.inputmethod.ThrowableHolder;

oneway interface IInputMethodInfoListResultCallback {
    void onResult(in List<InputMethodInfo> result);
    void onError(in ThrowableHolder exception);
}
 No newline at end of file
+3 −0
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package com.android.internal.inputmethod;

import com.android.internal.inputmethod.ThrowableHolder;

oneway interface IIntResultCallback {
    void onResult(int result);
    void onError(in ThrowableHolder exception);
}
Loading