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

Commit d8d03a8e authored by Tarandeep Singh's avatar Tarandeep Singh
Browse files

Move IME related API methods from IMM to IMS.

InputMethodManager is public InputMethod API for apps. The methods
that take Window-token as parameter are restricted to system
and/or IME developers. Such methods should really live
in InputMethodService.
This CL deprecates such methods in IMM and moves them to IMS.

This is the first step towards simplifying IME APIs.

Bug: 70282603
Test: atest InputMethodManagerTest
Change-Id: I3163f3cbe557c85103ca287bee0874a3b4194032
parent 0fd35656
Loading
Loading
Loading
Loading
+16 −9
Original line number Diff line number Diff line
@@ -20558,6 +20558,7 @@ package android.inputmethodservice {
    method public int getMaxWidth();
    method public java.lang.CharSequence getTextForImeAction(int);
    method public android.app.Dialog getWindow();
    method public void hideSoftInputFromInputMethod(int);
    method public void hideStatusIcon();
    method public void hideWindow();
    method public boolean isExtractViewShown();
@@ -20613,10 +20614,16 @@ package android.inputmethodservice {
    method public void setCandidatesViewShown(boolean);
    method public void setExtractView(android.view.View);
    method public void setExtractViewShown(boolean);
    method public void setInputMethod(java.lang.String);
    method public void setInputMethodAndSubtype(java.lang.String, android.view.inputmethod.InputMethodSubtype);
    method public void setInputView(android.view.View);
    method public boolean shouldOfferSwitchingToNextInputMethod();
    method public void showSoftInputFromInputMethod(int);
    method public void showStatusIcon(int);
    method public void showWindow(boolean);
    method public void switchInputMethod(java.lang.String);
    method public boolean switchToLastInputMethod();
    method public boolean switchToNextInputMethod(boolean);
    method public void updateFullscreenMode();
    method public void updateInputViewShown();
    field public static final int BACK_DISPOSITION_DEFAULT = 0; // 0x0
@@ -49034,10 +49041,10 @@ package android.view.inputmethod {
    method public java.util.List<android.view.inputmethod.InputMethodInfo> getInputMethodList();
    method public android.view.inputmethod.InputMethodSubtype getLastInputMethodSubtype();
    method public java.util.Map<android.view.inputmethod.InputMethodInfo, java.util.List<android.view.inputmethod.InputMethodSubtype>> getShortcutInputMethodsAndSubtypes();
    method public void hideSoftInputFromInputMethod(android.os.IBinder, int);
    method public deprecated void hideSoftInputFromInputMethod(android.os.IBinder, int);
    method public boolean hideSoftInputFromWindow(android.os.IBinder, int);
    method public boolean hideSoftInputFromWindow(android.os.IBinder, int, android.os.ResultReceiver);
    method public void hideStatusIcon(android.os.IBinder);
    method public deprecated void hideStatusIcon(android.os.IBinder);
    method public boolean isAcceptingText();
    method public boolean isActive(android.view.View);
    method public boolean isActive();
@@ -49047,17 +49054,17 @@ package android.view.inputmethod {
    method public void sendAppPrivateCommand(android.view.View, java.lang.String, android.os.Bundle);
    method public void setAdditionalInputMethodSubtypes(java.lang.String, android.view.inputmethod.InputMethodSubtype[]);
    method public boolean setCurrentInputMethodSubtype(android.view.inputmethod.InputMethodSubtype);
    method public void setInputMethod(android.os.IBinder, java.lang.String);
    method public void setInputMethodAndSubtype(android.os.IBinder, java.lang.String, android.view.inputmethod.InputMethodSubtype);
    method public boolean shouldOfferSwitchingToNextInputMethod(android.os.IBinder);
    method public deprecated void setInputMethod(android.os.IBinder, java.lang.String);
    method public deprecated void setInputMethodAndSubtype(android.os.IBinder, java.lang.String, android.view.inputmethod.InputMethodSubtype);
    method public deprecated boolean shouldOfferSwitchingToNextInputMethod(android.os.IBinder);
    method public void showInputMethodAndSubtypeEnabler(java.lang.String);
    method public void showInputMethodPicker();
    method public boolean showSoftInput(android.view.View, int);
    method public boolean showSoftInput(android.view.View, int, android.os.ResultReceiver);
    method public void showSoftInputFromInputMethod(android.os.IBinder, int);
    method public void showStatusIcon(android.os.IBinder, java.lang.String, int);
    method public boolean switchToLastInputMethod(android.os.IBinder);
    method public boolean switchToNextInputMethod(android.os.IBinder, boolean);
    method public deprecated void showSoftInputFromInputMethod(android.os.IBinder, int);
    method public deprecated void showStatusIcon(android.os.IBinder, java.lang.String, int);
    method public deprecated boolean switchToLastInputMethod(android.os.IBinder);
    method public deprecated boolean switchToNextInputMethod(android.os.IBinder, boolean);
    method public void toggleSoftInput(int, int);
    method public void toggleSoftInputFromWindow(android.os.IBinder, int, int);
    method public deprecated void updateCursor(android.view.View, int, int, int, int);
+84 −2
Original line number Diff line number Diff line
@@ -1065,6 +1065,88 @@ public class InputMethodService extends AbstractInputMethodService {
        return mInputConnection;
    }

    /**
     * Force switch to a new input method component. This can only be called
     * from an application or a service which has a token of the currently active input method.
     * @param id The unique identifier for the new input method to be switched to.
     */
    public void setInputMethod(String id) {
        mImm.setInputMethodInternal(mToken, id);
    }

    /**
     * Force switch to a new input method and subtype. This can only be called
     * from an application or a service which has a token of the currently active input method.
     * @param id The unique identifier for the new input method to be switched to.
     * @param subtype The new subtype of the new input method to be switched to.
     */
    public void setInputMethodAndSubtype(String id, InputMethodSubtype subtype) {
        mImm.setInputMethodAndSubtypeInternal(mToken, id, subtype);
    }

    /**
     * Close/hide the input method's soft input area, so the user no longer
     * sees it or can interact with it.  This can only be called
     * from the currently active input method, as validated by the given token.
     *
     * @param flags Provides additional operating flags.  Currently may be
     * 0 or have the {@link InputMethodManager#HIDE_IMPLICIT_ONLY},
     * {@link InputMethodManager#HIDE_NOT_ALWAYS} bit set.
     */
    public void hideSoftInputFromInputMethod(int flags) {
        mImm.hideSoftInputFromInputMethodInternal(mToken, flags);
    }

    /**
     * Show the input method's soft input area, so the user
     * sees the input method window and can interact with it.
     * This can only be called from the currently active input method,
     * as validated by the given token.
     *
     * @param flags Provides additional operating flags.  Currently may be
     * 0 or have the {@link InputMethodManager#SHOW_IMPLICIT} or
     * {@link InputMethodManager#SHOW_FORCED} bit set.
     */
    public void showSoftInputFromInputMethod(int flags) {
        mImm.showSoftInputFromInputMethodInternal(mToken, flags);
    }

    /**
     * Force switch to the last used input method and subtype. If the last input method didn't have
     * any subtypes, the framework will simply switch to the last input method with no subtype
     * specified.
     * @return true if the current input method and subtype was successfully switched to the last
     * used input method and subtype.
     */
    public boolean switchToLastInputMethod() {
        return mImm.switchToLastInputMethodInternal(mToken);
    }

    /**
     * Force switch to the next input method and subtype. If there is no IME enabled except
     * current IME and subtype, do nothing.
     * @param onlyCurrentIme if true, the framework will find the next subtype which
     * belongs to the current IME
     * @return true if the current input method and subtype was successfully switched to the next
     * input method and subtype.
     */
    public boolean switchToNextInputMethod(boolean onlyCurrentIme) {
        return mImm.switchToNextInputMethodInternal(mToken, onlyCurrentIme);
    }

    /**
     * Returns true if the current IME needs to offer the users ways to switch to a next input
     * method (e.g. a globe key.).
     * When an IME sets supportsSwitchingToNextInputMethod and this method returns true,
     * the IME has to offer ways to to invoke {@link #switchToNextInputMethod} accordingly.
     * <p> Note that the system determines the most appropriate next input method
     * and subtype in order to provide the consistent user experience in switching
     * between IMEs and subtypes.
     */
    public boolean shouldOfferSwitchingToNextInputMethod() {
        return mImm.shouldOfferSwitchingToNextInputMethodInternal(mToken);
    }

    public boolean getCurrentInputStarted() {
        return mInputStarted;
    }
+106 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.annotation.RequiresPermission;
import android.annotation.SystemService;
import android.content.Context;
import android.graphics.Rect;
import android.inputmethodservice.InputMethodService;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
@@ -735,7 +736,20 @@ public final class InputMethodManager {
        }
    }

    /**
     * @deprecated Use {@link InputMethodService#showStatusIcon(int)} instead. This method was
     * intended for IME developers who should be accessing APIs through the service. APIs in this
     * class are intended for app developers interacting with the IME.
     */
    @Deprecated
    public void showStatusIcon(IBinder imeToken, String packageName, int iconId) {
        showStatusIconInternal(imeToken, packageName, iconId);
    }

    /**
     * @hide
     */
    public void showStatusIconInternal(IBinder imeToken, String packageName, int iconId) {
        try {
            mService.updateStatusIcon(imeToken, packageName, iconId);
        } catch (RemoteException e) {
@@ -743,7 +757,20 @@ public final class InputMethodManager {
        }
    }

    /**
     * @deprecated Use {@link InputMethodService#hideStatusIcon()} instead. This method was
     * intended for IME developers who should be accessing APIs through the service. APIs in
     * this class are intended for app developers interacting with the IME.
     */
    @Deprecated
    public void hideStatusIcon(IBinder imeToken) {
        hideStatusIconInternal(imeToken);
    }

    /**
     * @hide
     */
    public void hideStatusIconInternal(IBinder imeToken) {
        try {
            mService.updateStatusIcon(imeToken, null, 0);
        } catch (RemoteException e) {
@@ -1121,7 +1148,6 @@ public final class InputMethodManager {
        }
    }


    /**
     * This method toggles the input method window display.
     * If the input window is already displayed, it gets hidden.
@@ -1800,8 +1826,19 @@ public final class InputMethodManager {
     * when it was started, which allows it to perform this operation on
     * itself.
     * @param id The unique identifier for the new input method to be switched to.
     * @deprecated Use {@link InputMethodService#setInputMethod(String)} instead. This method
     * was intended for IME developers who should be accessing APIs through the service. APIs in
     * this class are intended for app developers interacting with the IME.
     */
    @Deprecated
    public void setInputMethod(IBinder token, String id) {
        setInputMethodInternal(token, id);
    }

    /**
     * @hide
     */
    public void setInputMethodInternal(IBinder token, String id) {
        try {
            mService.setInputMethod(token, id);
        } catch (RemoteException e) {
@@ -1817,8 +1854,21 @@ public final class InputMethodManager {
     * itself.
     * @param id The unique identifier for the new input method to be switched to.
     * @param subtype The new subtype of the new input method to be switched to.
     * @deprecated Use
     * {@link InputMethodService#setInputMethodAndSubtype(String, InputMethodSubtype)}
     * instead. This method was intended for IME developers who should be accessing APIs through
     * the service. APIs in this class are intended for app developers interacting with the IME.
     */
    @Deprecated
    public void setInputMethodAndSubtype(IBinder token, String id, InputMethodSubtype subtype) {
        setInputMethodAndSubtypeInternal(token, id, subtype);
    }

    /**
     * @hide
     */
    public void setInputMethodAndSubtypeInternal(
            IBinder token, String id, InputMethodSubtype subtype) {
        try {
            mService.setInputMethodAndSubtype(token, id, subtype);
        } catch (RemoteException e) {
@@ -1837,8 +1887,19 @@ public final class InputMethodManager {
     * @param flags Provides additional operating flags.  Currently may be
     * 0 or have the {@link #HIDE_IMPLICIT_ONLY},
     * {@link #HIDE_NOT_ALWAYS} bit set.
     * @deprecated Use {@link InputMethodService#hideSoftInputFromInputMethod(int)}
     * instead. This method was intended for IME developers who should be accessing APIs through
     * the service. APIs in this class are intended for app developers interacting with the IME.
     */
    @Deprecated
    public void hideSoftInputFromInputMethod(IBinder token, int flags) {
        hideSoftInputFromInputMethodInternal(token, flags);
    }

    /**
     * @hide
     */
    public void hideSoftInputFromInputMethodInternal(IBinder token, int flags) {
        try {
            mService.hideMySoftInput(token, flags);
        } catch (RemoteException e) {
@@ -1858,8 +1919,19 @@ public final class InputMethodManager {
     * @param flags Provides additional operating flags.  Currently may be
     * 0 or have the {@link #SHOW_IMPLICIT} or
     * {@link #SHOW_FORCED} bit set.
     * @deprecated Use {@link InputMethodService#showSoftInputFromInputMethod(int)}
     * instead. This method was intended for IME developers who should be accessing APIs through
     * the service. APIs in this class are intended for app developers interacting with the IME.
     */
    @Deprecated
    public void showSoftInputFromInputMethod(IBinder token, int flags) {
        showSoftInputFromInputMethodInternal(token, flags);
    }

    /**
     * @hide
     */
    public void showSoftInputFromInputMethodInternal(IBinder token, int flags) {
        try {
            mService.showMySoftInput(token, flags);
        } catch (RemoteException e) {
@@ -2239,8 +2311,19 @@ public final class InputMethodManager {
     * which allows it to perform this operation on itself.
     * @return true if the current input method and subtype was successfully switched to the last
     * used input method and subtype.
     * @deprecated Use {@link InputMethodService#switchToLastInputMethod()} instead. This method
     * was intended for IME developers who should be accessing APIs through the service. APIs in
     * this class are intended for app developers interacting with the IME.
     */
    @Deprecated
    public boolean switchToLastInputMethod(IBinder imeToken) {
        return switchToLastInputMethodInternal(imeToken);
    }

    /**
     * @hide
     */
    public boolean switchToLastInputMethodInternal(IBinder imeToken) {
        synchronized (mH) {
            try {
                return mService.switchToLastInputMethod(imeToken);
@@ -2259,8 +2342,19 @@ public final class InputMethodManager {
     * belongs to the current IME
     * @return true if the current input method and subtype was successfully switched to the next
     * input method and subtype.
     * @deprecated Use {@link InputMethodService#switchToNextInputMethod(boolean)} instead. This
     * method was intended for IME developers who should be accessing APIs through the service.
     * APIs in this class are intended for app developers interacting with the IME.
     */
    @Deprecated
    public boolean switchToNextInputMethod(IBinder imeToken, boolean onlyCurrentIme) {
        return switchToNextInputMethodInternal(imeToken, onlyCurrentIme);
    }

    /**
     * @hide
     */
    public boolean switchToNextInputMethodInternal(IBinder imeToken, boolean onlyCurrentIme) {
        synchronized (mH) {
            try {
                return mService.switchToNextInputMethod(imeToken, onlyCurrentIme);
@@ -2280,8 +2374,19 @@ public final class InputMethodManager {
     * between IMEs and subtypes.
     * @param imeToken Supplies the identifying token given to an input method when it was started,
     * which allows it to perform this operation on itself.
     * @deprecated Use {@link InputMethodService#shouldOfferSwitchingToNextInputMethod()}
     * instead. This method was intended for IME developers who should be accessing APIs through
     * the service. APIs in this class are intended for app developers interacting with the IME.
     */
    @Deprecated
    public boolean shouldOfferSwitchingToNextInputMethod(IBinder imeToken) {
        return shouldOfferSwitchingToNextInputMethodInternal(imeToken);
    }

    /**
     * @hide
     */
    public boolean shouldOfferSwitchingToNextInputMethodInternal(IBinder imeToken) {
        synchronized (mH) {
            try {
                return mService.shouldOfferSwitchingToNextInputMethod(imeToken);