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

Commit a3e93fad authored by Wilson Wu's avatar Wilson Wu Committed by Automerger Merge Worker
Browse files

Merge "Make IInputMethodPrivilegedOperations to oneway" into sc-dev am: 70c6ea46

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13738526

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I259f127a13e9a977008b6797b5f38dda0c59936e
parents 1f37e676 70c6ea46
Loading
Loading
Loading
Loading
+27 −0
Original line number Original line Diff line number Diff line
@@ -225,4 +225,31 @@ public final class CallbackUtils {
            callback.onResult();
            callback.onResult();
        } catch (RemoteException ignored) { }
        } catch (RemoteException ignored) { }
    }
    }

    /**
     * A utility method using given {@link IIInputContentUriTokenResultCallback} to callback the
     * result.
     *
     * @param callback {@link IIInputContentUriTokenResultCallback} to be called back.
     * @param resultSupplier the supplier from which the result is provided.
     */
    public static void onResult(@NonNull IIInputContentUriTokenResultCallback callback,
            @NonNull Supplier<IInputContentUriToken> resultSupplier) {
        IInputContentUriToken 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) { }
    }
}
}
+13 −0
Original line number Original line Diff line number Diff line
@@ -443,6 +443,13 @@ public final class Completable {
        return new Completable.InputMethodInfoList();
        return new Completable.InputMethodInfoList();
    }
    }


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

    /**
    /**
     * @return an instance of {@link Completable.Void}.
     * @return an instance of {@link Completable.Void}.
     */
     */
@@ -496,6 +503,12 @@ public final class Completable {
    public static final class InputMethodInfoList
    public static final class InputMethodInfoList
            extends Values<List<android.view.inputmethod.InputMethodInfo>> { }
            extends Values<List<android.view.inputmethod.InputMethodInfo>> { }


    /**
     * Completable object of {@link IInputContentUriToken>}.
     */
    public static final class IInputContentUriToken
            extends Values<com.android.internal.inputmethod.IInputContentUriToken> { }

    /**
    /**
     * Await the result by the {@link Completable.Values}.
     * Await the result by the {@link Completable.Values}.
     *
     *
+25 −0
Original line number Original line 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.IInputContentUriToken;
import com.android.internal.inputmethod.ThrowableHolder;

oneway interface IIInputContentUriTokenResultCallback {
    void onResult(in IInputContentUriToken result);
    void onError(in ThrowableHolder exception);
}
 No newline at end of file
+21 −15
Original line number Original line Diff line number Diff line
@@ -19,25 +19,31 @@ package com.android.internal.inputmethod;
import android.net.Uri;
import android.net.Uri;
import android.view.inputmethod.InputMethodSubtype;
import android.view.inputmethod.InputMethodSubtype;


import com.android.internal.inputmethod.IBooleanResultCallback;
import com.android.internal.inputmethod.IInputContentUriToken;
import com.android.internal.inputmethod.IInputContentUriToken;
import com.android.internal.inputmethod.IIInputContentUriTokenResultCallback;
import com.android.internal.inputmethod.IVoidResultCallback;


/**
/**
 * Defines priviledged operations that only the current IME is allowed to call.
 * Defines priviledged operations that only the current IME is allowed to call.
 * Actual operations are implemented and handled by InputMethodManagerService.
 * Actual operations are implemented and handled by InputMethodManagerService.
 */
 */
interface IInputMethodPrivilegedOperations {
oneway interface IInputMethodPrivilegedOperations {
    void setImeWindowStatus(int vis, int backDisposition);
    void setImeWindowStatus(int vis, int backDisposition, in IVoidResultCallback resultCallback);
    void reportStartInput(in IBinder startInputToken);
    void reportStartInput(in IBinder startInputToken, in IVoidResultCallback resultCallback);
    IInputContentUriToken createInputContentUriToken(in Uri contentUri, in String packageName);
    void createInputContentUriToken(in Uri contentUri, in String packageName,
    void reportFullscreenMode(boolean fullscreen);
            in IIInputContentUriTokenResultCallback resultCallback);
    void setInputMethod(String id);
    void reportFullscreenMode(boolean fullscreen, in IVoidResultCallback resultCallback);
    void setInputMethodAndSubtype(String id, in InputMethodSubtype subtype);
    void setInputMethod(String id, in IVoidResultCallback resultCallback);
    void hideMySoftInput(int flags);
    void setInputMethodAndSubtype(String id, in InputMethodSubtype subtype,
    void showMySoftInput(int flags);
            in IVoidResultCallback resultCallback);
    void updateStatusIcon(String packageName, int iconId);
    void hideMySoftInput(int flags, in IVoidResultCallback resultCallback);
    boolean switchToPreviousInputMethod();
    void showMySoftInput(int flags, in IVoidResultCallback resultCallback);
    boolean switchToNextInputMethod(boolean onlyCurrentIme);
    void updateStatusIcon(String packageName, int iconId, in IVoidResultCallback resultCallback);
    boolean shouldOfferSwitchingToNextInputMethod();
    void switchToPreviousInputMethod(in IBooleanResultCallback resultCallback);
    void notifyUserAction();
    void switchToNextInputMethod(boolean onlyCurrentIme, in IBooleanResultCallback resultCallback);
    void applyImeVisibility(IBinder showOrHideInputToken, boolean setVisible);
    void shouldOfferSwitchingToNextInputMethod(in IBooleanResultCallback resultCallback);
    void notifyUserAction(in IVoidResultCallback resultCallback);
    void applyImeVisibility(IBinder showOrHideInputToken, boolean setVisible,
            in IVoidResultCallback resultCallback);
}
}
+66 −28
Original line number Original line Diff line number Diff line
@@ -95,7 +95,8 @@ public final class InputMethodPrivilegedOperations {
    }
    }


    /**
    /**
     * Calls {@link IInputMethodPrivilegedOperations#setImeWindowStatus(int, int)}.
     * Calls {@link IInputMethodPrivilegedOperations#setImeWindowStatus(int, int,
     * IVoidResultCallback)}.
     *
     *
     * @param vis visibility flags
     * @param vis visibility flags
     * @param backDisposition disposition flags
     * @param backDisposition disposition flags
@@ -112,14 +113,17 @@ public final class InputMethodPrivilegedOperations {
            return;
            return;
        }
        }
        try {
        try {
            ops.setImeWindowStatus(vis, backDisposition);
            final Completable.Void value = Completable.createVoid();
            ops.setImeWindowStatus(vis, backDisposition, ResultCallbacks.of(value));
            Completable.getResult(value);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
    }
    }


    /**
    /**
     * Calls {@link IInputMethodPrivilegedOperations#reportStartInput(IBinder)}.
     * Calls {@link IInputMethodPrivilegedOperations#reportStartInput(IBinder,
     * IVoidResultCallback)}.
     *
     *
     * @param startInputToken {@link IBinder} token to distinguish startInput session
     * @param startInputToken {@link IBinder} token to distinguish startInput session
     */
     */
@@ -130,14 +134,17 @@ public final class InputMethodPrivilegedOperations {
            return;
            return;
        }
        }
        try {
        try {
            ops.reportStartInput(startInputToken);
            final Completable.Void value = Completable.createVoid();
            ops.reportStartInput(startInputToken, ResultCallbacks.of(value));
            Completable.getResult(value);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
    }
    }


    /**
    /**
     * Calls {@link IInputMethodPrivilegedOperations#createInputContentUriToken(Uri, String)}.
     * Calls {@link IInputMethodPrivilegedOperations#createInputContentUriToken(Uri, String,
     * IIInputContentUriTokenResultCallback)}.
     *
     *
     * @param contentUri Content URI to which a temporary read permission should be granted
     * @param contentUri Content URI to which a temporary read permission should be granted
     * @param packageName Indicates what package needs to have a temporary read permission
     * @param packageName Indicates what package needs to have a temporary read permission
@@ -151,7 +158,10 @@ public final class InputMethodPrivilegedOperations {
            return null;
            return null;
        }
        }
        try {
        try {
            return ops.createInputContentUriToken(contentUri, packageName);
            final Completable.IInputContentUriToken value =
                    Completable.createIInputContentUriToken();
            ops.createInputContentUriToken(contentUri, packageName, ResultCallbacks.of(value));
            return Completable.getResult(value);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            // For historical reasons, this error was silently ignored.
            // For historical reasons, this error was silently ignored.
            // Note that the caller already logs error so we do not need additional Log.e() here.
            // Note that the caller already logs error so we do not need additional Log.e() here.
@@ -161,7 +171,8 @@ public final class InputMethodPrivilegedOperations {
    }
    }


    /**
    /**
     * Calls {@link IInputMethodPrivilegedOperations#reportFullscreenMode(boolean)}.
     * Calls {@link IInputMethodPrivilegedOperations#reportFullscreenMode(boolean,
     * IVoidResultCallback)}.
     *
     *
     * @param fullscreen {@code true} if the IME enters full screen mode
     * @param fullscreen {@code true} if the IME enters full screen mode
     */
     */
@@ -172,14 +183,17 @@ public final class InputMethodPrivilegedOperations {
            return;
            return;
        }
        }
        try {
        try {
            ops.reportFullscreenMode(fullscreen);
            final Completable.Void value = Completable.createVoid();
            ops.reportFullscreenMode(fullscreen, ResultCallbacks.of(value));
            Completable.getResult(value);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
    }
    }


    /**
    /**
     * Calls {@link IInputMethodPrivilegedOperations#updateStatusIcon(String, int)}.
     * Calls {@link IInputMethodPrivilegedOperations#updateStatusIcon(String, int,
     * IVoidResultCallback)}.
     *
     *
     * @param packageName package name from which the status icon should be loaded
     * @param packageName package name from which the status icon should be loaded
     * @param iconResId resource ID of the icon to be loaded
     * @param iconResId resource ID of the icon to be loaded
@@ -191,14 +205,16 @@ public final class InputMethodPrivilegedOperations {
            return;
            return;
        }
        }
        try {
        try {
            ops.updateStatusIcon(packageName, iconResId);
            final Completable.Void value = Completable.createVoid();
            ops.updateStatusIcon(packageName, iconResId, ResultCallbacks.of(value));
            Completable.getResult(value);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
    }
    }


    /**
    /**
     * Calls {@link IInputMethodPrivilegedOperations#setInputMethod(String)}.
     * Calls {@link IInputMethodPrivilegedOperations#setInputMethod(String, IVoidResultCallback)}.
     *
     *
     * @param id IME ID of the IME to switch to
     * @param id IME ID of the IME to switch to
     * @see android.view.inputmethod.InputMethodInfo#getId()
     * @see android.view.inputmethod.InputMethodInfo#getId()
@@ -210,7 +226,9 @@ public final class InputMethodPrivilegedOperations {
            return;
            return;
        }
        }
        try {
        try {
            ops.setInputMethod(id);
            final Completable.Void value = Completable.createVoid();
            ops.setInputMethod(id, ResultCallbacks.of(value));
            Completable.getResult(value);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
@@ -218,7 +236,7 @@ public final class InputMethodPrivilegedOperations {


    /**
    /**
     * Calls {@link IInputMethodPrivilegedOperations#setInputMethodAndSubtype(String,
     * Calls {@link IInputMethodPrivilegedOperations#setInputMethodAndSubtype(String,
     * InputMethodSubtype)}
     * InputMethodSubtype, IVoidResultCallback)}
     *
     *
     * @param id IME ID of the IME to switch to
     * @param id IME ID of the IME to switch to
     * @param subtype {@link InputMethodSubtype} to switch to
     * @param subtype {@link InputMethodSubtype} to switch to
@@ -231,14 +249,16 @@ public final class InputMethodPrivilegedOperations {
            return;
            return;
        }
        }
        try {
        try {
            ops.setInputMethodAndSubtype(id, subtype);
            final Completable.Void value = Completable.createVoid();
            ops.setInputMethodAndSubtype(id, subtype, ResultCallbacks.of(value));
            Completable.getResult(value);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
    }
    }


    /**
    /**
     * Calls {@link IInputMethodPrivilegedOperations#hideMySoftInput(int)}
     * Calls {@link IInputMethodPrivilegedOperations#hideMySoftInput(int, IVoidResultCallback)}
     *
     *
     * @param flags additional operating flags
     * @param flags additional operating flags
     * @see android.view.inputmethod.InputMethodManager#HIDE_IMPLICIT_ONLY
     * @see android.view.inputmethod.InputMethodManager#HIDE_IMPLICIT_ONLY
@@ -251,14 +271,16 @@ public final class InputMethodPrivilegedOperations {
            return;
            return;
        }
        }
        try {
        try {
            ops.hideMySoftInput(flags);
            final Completable.Void value = Completable.createVoid();
            ops.hideMySoftInput(flags, ResultCallbacks.of(value));
            Completable.getResult(value);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
    }
    }


    /**
    /**
     * Calls {@link IInputMethodPrivilegedOperations#showMySoftInput(int)}
     * Calls {@link IInputMethodPrivilegedOperations#showMySoftInput(int, IVoidResultCallback)}
     *
     *
     * @param flags additional operating flags
     * @param flags additional operating flags
     * @see android.view.inputmethod.InputMethodManager#SHOW_IMPLICIT
     * @see android.view.inputmethod.InputMethodManager#SHOW_IMPLICIT
@@ -271,14 +293,17 @@ public final class InputMethodPrivilegedOperations {
            return;
            return;
        }
        }
        try {
        try {
            ops.showMySoftInput(flags);
            final Completable.Void value = Completable.createVoid();
            ops.showMySoftInput(flags, ResultCallbacks.of(value));
            Completable.getResult(value);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
    }
    }


    /**
    /**
     * Calls {@link IInputMethodPrivilegedOperations#switchToPreviousInputMethod()}
     * Calls {@link IInputMethodPrivilegedOperations#switchToPreviousInputMethod(
     * IBooleanResultCallback)}
     *
     *
     * @return {@code true} if handled
     * @return {@code true} if handled
     */
     */
@@ -289,14 +314,17 @@ public final class InputMethodPrivilegedOperations {
            return false;
            return false;
        }
        }
        try {
        try {
            return ops.switchToPreviousInputMethod();
            final Completable.Boolean value = Completable.createBoolean();
            ops.switchToPreviousInputMethod(ResultCallbacks.of(value));
            return Completable.getResult(value);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
    }
    }


    /**
    /**
     * Calls {@link IInputMethodPrivilegedOperations#switchToNextInputMethod(boolean)}
     * Calls {@link IInputMethodPrivilegedOperations#switchToNextInputMethod(boolean,
     * IBooleanResultCallback)}
     *
     *
     * @param onlyCurrentIme {@code true} to switch to a {@link InputMethodSubtype} within the same
     * @param onlyCurrentIme {@code true} to switch to a {@link InputMethodSubtype} within the same
     *                       IME
     *                       IME
@@ -309,14 +337,17 @@ public final class InputMethodPrivilegedOperations {
            return false;
            return false;
        }
        }
        try {
        try {
            return ops.switchToNextInputMethod(onlyCurrentIme);
            final Completable.Boolean value = Completable.createBoolean();
            ops.switchToNextInputMethod(onlyCurrentIme, ResultCallbacks.of(value));
            return Completable.getResult(value);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
    }
    }


    /**
    /**
     * Calls {@link IInputMethodPrivilegedOperations#shouldOfferSwitchingToNextInputMethod()}
     * Calls {@link IInputMethodPrivilegedOperations#shouldOfferSwitchingToNextInputMethod(
     * IBooleanResultCallback)}
     *
     *
     * @return {@code true} if the IEM should offer a way to globally switch IME
     * @return {@code true} if the IEM should offer a way to globally switch IME
     */
     */
@@ -327,14 +358,16 @@ public final class InputMethodPrivilegedOperations {
            return false;
            return false;
        }
        }
        try {
        try {
            return ops.shouldOfferSwitchingToNextInputMethod();
            final Completable.Boolean value = Completable.createBoolean();
            ops.shouldOfferSwitchingToNextInputMethod(ResultCallbacks.of(value));
            return Completable.getResult(value);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
    }
    }


    /**
    /**
     * Calls {@link IInputMethodPrivilegedOperations#notifyUserAction()}
     * Calls {@link IInputMethodPrivilegedOperations#notifyUserAction(IVoidResultCallback)}
     */
     */
    @AnyThread
    @AnyThread
    public void notifyUserAction() {
    public void notifyUserAction() {
@@ -343,14 +376,17 @@ public final class InputMethodPrivilegedOperations {
            return;
            return;
        }
        }
        try {
        try {
            ops.notifyUserAction();
            final Completable.Void value = Completable.createVoid();
            ops.notifyUserAction(ResultCallbacks.of(value));
            Completable.getResult(value);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
    }
    }


    /**
    /**
     * Calls {@link IInputMethodPrivilegedOperations#applyImeVisibility(IBinder, boolean)}.
     * Calls {@link IInputMethodPrivilegedOperations#applyImeVisibility(IBinder, boolean,
     * IVoidResultCallback)}.
     *
     *
     * @param showOrHideInputToken placeholder token that maps to window requesting
     * @param showOrHideInputToken placeholder token that maps to window requesting
     *        {@link android.view.inputmethod.InputMethodManager#showSoftInput(View, int)} or
     *        {@link android.view.inputmethod.InputMethodManager#showSoftInput(View, int)} or
@@ -365,7 +401,9 @@ public final class InputMethodPrivilegedOperations {
            return;
            return;
        }
        }
        try {
        try {
            ops.applyImeVisibility(showOrHideInputToken, setVisible);
            final Completable.Void value = Completable.createVoid();
            ops.applyImeVisibility(showOrHideInputToken, setVisible, ResultCallbacks.of(value));
            Completable.getResult(value);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
Loading