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

Commit ebbe3194 authored by Yinglei Wang's avatar Yinglei Wang Committed by Android (Google) Code Review
Browse files

Merge "Add new setInputMethodEnabled API"

parents 3d10fb4b b5f3d34d
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -3148,8 +3148,12 @@ package android.accessibilityservice {
    method public void addOnShowModeChangedListener(@NonNull android.accessibilityservice.AccessibilityService.SoftKeyboardController.OnShowModeChangedListener, @Nullable android.os.Handler);
    method public int getShowMode();
    method public boolean removeOnShowModeChangedListener(@NonNull android.accessibilityservice.AccessibilityService.SoftKeyboardController.OnShowModeChangedListener);
    method @CheckResult public int setInputMethodEnabled(@NonNull String, boolean) throws java.lang.SecurityException;
    method public boolean setShowMode(int);
    method public boolean switchToInputMethod(@NonNull String);
    field public static final int ENABLE_IME_FAIL_BY_ADMIN = 1; // 0x1
    field public static final int ENABLE_IME_FAIL_UNKNOWN = 2; // 0x2
    field public static final int ENABLE_IME_SUCCESS = 0; // 0x0
  }
  public static interface AccessibilityService.SoftKeyboardController.OnShowModeChangedListener {
+57 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY

import android.accessibilityservice.GestureDescription.MotionEventGenerator;
import android.annotation.CallbackExecutor;
import android.annotation.CheckResult;
import android.annotation.ColorInt;
import android.annotation.IntDef;
import android.annotation.NonNull;
@@ -1733,6 +1734,29 @@ public abstract class AccessibilityService extends Service {
        private ArrayMap<OnShowModeChangedListener, Handler> mListeners;
        private final Object mLock;

        /** @hide */
        @Retention(RetentionPolicy.SOURCE)
        @IntDef({
                ENABLE_IME_SUCCESS,
                ENABLE_IME_FAIL_BY_ADMIN,
                ENABLE_IME_FAIL_UNKNOWN
        })
        public @interface EnableImeResult {}
        /**
         * Return value for {@link #setInputMethodEnabled(String, boolean)}. The action succeeded.
         */
        public static final int ENABLE_IME_SUCCESS = 0;
        /**
         * Return value for {@link #setInputMethodEnabled(String, boolean)}. The action failed
         * because the InputMethod is not permitted by device policy manager.
         */
        public static final int ENABLE_IME_FAIL_BY_ADMIN = 1;
        /**
         * Return value for {@link #setInputMethodEnabled(String, boolean)}. The action failed
         * and the reason is unknown.
         */
        public static final int ENABLE_IME_FAIL_UNKNOWN = 2;

        SoftKeyboardController(@NonNull AccessibilityService service, @NonNull Object lock) {
            mService = service;
            mLock = lock;
@@ -1961,6 +1985,39 @@ public abstract class AccessibilityService extends Service {
            }
            return false;
        }

        /**
         * Enable or disable the specified IME for the user for whom the service is activated. The
         * IME needs to be in the same package as the service and needs to be allowed by device
         * policy, if there is one. The change will persist until the specified IME is next
         * explicitly enabled or disabled by whatever means, such as user choice, and may persist
         * beyond the life cycle of the requesting service.
         *
         * @param imeId The ID of the input method to enable or disable. This IME must be installed.
         * @param enabled {@code true} if the input method associated with {@code imeId} should be
         *                enabled.
         * @return status code for the result of enabling/disabling the input method associated
         *         with {@code imeId}.
         * @throws SecurityException if the input method is not in the same package as the service.
         *
         * @see android.view.inputmethod.InputMethodInfo#getId()
         */
        @CheckResult
        @EnableImeResult
        public int setInputMethodEnabled(@NonNull String imeId, boolean enabled)
                throws SecurityException {
            final IAccessibilityServiceConnection connection =
                    AccessibilityInteractionClient.getInstance(mService).getConnection(
                            mService.mConnectionId);
            if (connection != null) {
                try {
                    return connection.setInputMethodEnabled(imeId, enabled);
                } catch (RemoteException re) {
                    throw new RuntimeException(re);
                }
            }
            return ENABLE_IME_FAIL_UNKNOWN;
        }
    }

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

    boolean switchToInputMethod(String imeId);

    int setInputMethodEnabled(String imeId, boolean enabled);

    boolean isAccessibilityButtonAvailable();

    void sendGesture(int sequence, in ParceledListSlice gestureSteps);
+5 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.view.accessibility;

import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.accessibilityservice.IAccessibilityServiceConnection;
import android.accessibilityservice.MagnificationConfig;
@@ -144,6 +145,10 @@ public class AccessibilityServiceConnectionImpl extends IAccessibilityServiceCon
        return false;
    }

    public int setInputMethodEnabled(String imeId, boolean enabled) {
        return AccessibilityService.SoftKeyboardController.ENABLE_IME_FAIL_UNKNOWN;
    }

    public boolean isAccessibilityButtonAvailable() {
        return false;
    }
+6 −0
Original line number Diff line number Diff line
@@ -7,6 +7,12 @@ package {
    default_applicable_licenses: ["frameworks_base_license"],
}

filegroup {
    name: "SettingsLibRestrictedLockUtilsSrc",
    srcs: ["src/**/*.java"],
    visibility: ["//frameworks/base/services/accessibility"],
}

android_library {
    name: "SettingsLibRestrictedLockUtils",

Loading