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

Commit b95dfee3 authored by Minche Li's avatar Minche Li Committed by Android (Google) Code Review
Browse files

Merge "Add new switchToInputMethod API"

parents fb905f7e 850892b7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2925,6 +2925,7 @@ package android.accessibilityservice {
    method public int getShowMode();
    method public boolean removeOnShowModeChangedListener(@NonNull android.accessibilityservice.AccessibilityService.SoftKeyboardController.OnShowModeChangedListener);
    method public boolean setShowMode(int);
    method public boolean switchToInputMethod(@NonNull String);
  }
  public static interface AccessibilityService.SoftKeyboardController.OnShowModeChangedListener {
+28 −0
Original line number Diff line number Diff line
@@ -1547,6 +1547,34 @@ public abstract class AccessibilityService extends Service {
            void onShowModeChanged(@NonNull SoftKeyboardController controller,
                    @SoftKeyboardShowMode int showMode);
        }

        /**
         * Switches the current IME for the user for whom the service is enabled. The change will
         * persist until the current IME is explicitly changed again, and may persist beyond the
         * life cycle of the requesting service.
         *
         * @param imeId The ID of the input method to make current. This IME must be installed and
         *              enabled.
         * @return {@code true} if the current input method was successfully switched to the input
         *         method by {@code imeId},
         *         {@code false} if the input method specified is not installed, not enabled, or
         *         otherwise not available to become the current IME
         *
         * @see android.view.inputmethod.InputMethodInfo#getId()
         */
        public boolean switchToInputMethod(@NonNull String imeId) {
            final IAccessibilityServiceConnection connection =
                    AccessibilityInteractionClient.getInstance().getConnection(
                            mService.mConnectionId);
            if (connection != null) {
                try {
                    return connection.switchToInputMethod(imeId);
                } catch (RemoteException re) {
                    throw new RuntimeException(re);
                }
            }
            return false;
        }
    }

    /**
+2 −0
Original line number Diff line number Diff line
@@ -91,6 +91,8 @@ interface IAccessibilityServiceConnection {

    void setSoftKeyboardCallbackEnabled(boolean enabled);

    boolean switchToInputMethod(String imeId);

    boolean isAccessibilityButtonAvailable();

    void sendGesture(int sequence, in ParceledListSlice gestureSteps);
+4 −0
Original line number Diff line number Diff line
@@ -124,6 +124,10 @@ public class AccessibilityServiceConnectionImpl extends IAccessibilityServiceCon

    public void setSoftKeyboardCallbackEnabled(boolean enabled) {}

    public boolean switchToInputMethod(String imeId) {
        return false;
    }

    public boolean isAccessibilityButtonAvailable() {
        return false;
    }
+19 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.provider.Settings;
import android.util.Slog;
import android.view.Display;

import com.android.server.inputmethod.InputMethodManagerInternal;
import com.android.server.wm.ActivityTaskManagerInternal;
import com.android.server.wm.WindowManagerInternal;

@@ -263,6 +264,24 @@ class AccessibilityServiceConnection extends AbstractAccessibilityServiceConnect
        return (userState != null) ? userState.getSoftKeyboardShowModeLocked() : 0;
    }

    @Override
    public boolean switchToInputMethod(String imeId) {
        synchronized (mLock) {
            if (!hasRightsToCurrentUserLocked()) {
                return false;
            }
        }
        final boolean result;
        final int callingUserId = UserHandle.getCallingUserId();
        final long identity = Binder.clearCallingIdentity();
        try {
            result = InputMethodManagerInternal.get().switchToInputMethod(imeId, callingUserId);
        } finally {
            Binder.restoreCallingIdentity(identity);
        }
        return result;
    }

    @Override
    public boolean isAccessibilityButtonAvailable() {
        synchronized (mLock) {
Loading