summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Vaibhav Devmurari <vdevmurari@google.com> 2022-12-01 15:08:27 +0000
committer Vaibhav Devmurari <vdevmurari@google.com> 2022-12-02 16:20:03 +0000
commit66f08f8cfe62183bad36f2cda90ac60ec104a51a (patch)
treecfc163d4ccb0dea6a6450e5924947b992f438faa
parentdabb70585057463db96fe8327fa20ba0891995ed (diff)
Add new Keyboard layout APIs to manage layout based on IME info
Adding empty interface for the APIs in this CL. Implementation to follow DD: go/pk_layout_selection Test: manual Bug: 259530132 Change-Id: I9e15fe4a99bd2a783d43404cd411d2f8f66b6aca
-rw-r--r--core/java/android/hardware/input/IInputManager.aidl16
-rw-r--r--core/java/android/hardware/input/InputManager.java88
-rw-r--r--services/core/java/com/android/server/input/InputManagerService.java28
-rw-r--r--services/core/java/com/android/server/input/KeyboardLayoutManager.java32
4 files changed, 164 insertions, 0 deletions
diff --git a/core/java/android/hardware/input/IInputManager.aidl b/core/java/android/hardware/input/IInputManager.aidl
index bdcbcaacfae4..b26c0a289c21 100644
--- a/core/java/android/hardware/input/IInputManager.aidl
+++ b/core/java/android/hardware/input/IInputManager.aidl
@@ -32,6 +32,8 @@ import android.hardware.lights.LightState;
import android.os.IBinder;
import android.os.IVibratorStateListener;
import android.os.VibrationEffect;
+import android.view.inputmethod.InputMethodInfo;
+import android.view.inputmethod.InputMethodSubtype;
import android.view.InputDevice;
import android.view.InputEvent;
import android.view.InputMonitor;
@@ -107,6 +109,20 @@ interface IInputManager {
void removeKeyboardLayoutForInputDevice(in InputDeviceIdentifier identifier,
String keyboardLayoutDescriptor);
+ // New Keyboard layout config APIs
+ String getKeyboardLayoutForInputDevice(in InputDeviceIdentifier identifier, int userId,
+ in InputMethodInfo imeInfo, in InputMethodSubtype imeSubtype);
+
+ @EnforcePermission("SET_KEYBOARD_LAYOUT")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
+ + "android.Manifest.permission.SET_KEYBOARD_LAYOUT)")
+ void setKeyboardLayoutForInputDevice(in InputDeviceIdentifier identifier, int userId,
+ in InputMethodInfo imeInfo, in InputMethodSubtype imeSubtype,
+ String keyboardLayoutDescriptor);
+
+ String[] getKeyboardLayoutListForInputDevice(in InputDeviceIdentifier identifier, int userId,
+ in InputMethodInfo imeInfo, in InputMethodSubtype imeSubtype);
+
// Registers an input devices changed listener.
void registerInputDevicesChangedListener(IInputDevicesChangedListener listener);
diff --git a/core/java/android/hardware/input/InputManager.java b/core/java/android/hardware/input/InputManager.java
index a157a8f6c6d7..cea3fa1a7fb0 100644
--- a/core/java/android/hardware/input/InputManager.java
+++ b/core/java/android/hardware/input/InputManager.java
@@ -26,6 +26,7 @@ import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SystemService;
import android.annotation.TestApi;
+import android.annotation.UserIdInt;
import android.app.ActivityThread;
import android.compat.annotation.ChangeId;
import android.compat.annotation.UnsupportedAppUsage;
@@ -66,6 +67,8 @@ import android.view.MotionEvent;
import android.view.PointerIcon;
import android.view.VerifiedInputEvent;
import android.view.WindowManager.LayoutParams;
+import android.view.inputmethod.InputMethodInfo;
+import android.view.inputmethod.InputMethodSubtype;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
@@ -889,6 +892,91 @@ public final class InputManager {
}
/**
+ * Gets the keyboard layout descriptor for the specified input device, userId, imeInfo and
+ * imeSubtype.
+ *
+ * @param identifier Identifier for the input device
+ * @param userId user profile ID
+ * @param imeInfo contains IME information like imeId, etc.
+ * @param imeSubtype contains IME subtype information like input languageTag, layoutType, etc.
+ * @return The keyboard layout descriptor, or null if no keyboard layout has been set.
+ *
+ * @hide
+ */
+ @Nullable
+ public String getKeyboardLayoutForInputDevice(@NonNull InputDeviceIdentifier identifier,
+ @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
+ @NonNull InputMethodSubtype imeSubtype) {
+ try {
+ return mIm.getKeyboardLayoutForInputDevice(identifier, userId, imeInfo, imeSubtype);
+ } catch (RemoteException ex) {
+ throw ex.rethrowFromSystemServer();
+ }
+ }
+
+ /**
+ * Sets the keyboard layout descriptor for the specified input device, userId, imeInfo and
+ * imeSubtype.
+ *
+ * <p>
+ * This method may have the side-effect of causing the input device in question to be
+ * reconfigured.
+ * </p>
+ *
+ * @param identifier The identifier for the input device.
+ * @param userId user profile ID
+ * @param imeInfo contains IME information like imeId, etc.
+ * @param imeSubtype contains IME subtype information like input languageTag, layoutType, etc.
+ * @param keyboardLayoutDescriptor The keyboard layout descriptor to use, must not be null.
+ *
+ * @hide
+ */
+ @RequiresPermission(Manifest.permission.SET_KEYBOARD_LAYOUT)
+ public void setKeyboardLayoutForInputDevice(@NonNull InputDeviceIdentifier identifier,
+ @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
+ @NonNull InputMethodSubtype imeSubtype, @NonNull String keyboardLayoutDescriptor) {
+ if (identifier == null) {
+ throw new IllegalArgumentException("identifier must not be null");
+ }
+ if (keyboardLayoutDescriptor == null) {
+ throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null");
+ }
+
+ try {
+ mIm.setKeyboardLayoutForInputDevice(identifier, userId, imeInfo, imeSubtype,
+ keyboardLayoutDescriptor);
+ } catch (RemoteException ex) {
+ throw ex.rethrowFromSystemServer();
+ }
+ }
+
+ /**
+ * Gets all keyboard layout descriptors that are enabled for the specified input device, userId,
+ * imeInfo and imeSubtype.
+ *
+ * @param identifier The identifier for the input device.
+ * @param userId user profile ID
+ * @param imeInfo contains IME information like imeId, etc.
+ * @param imeSubtype contains IME subtype information like input languageTag, layoutType, etc.
+ * @return The keyboard layout descriptors.
+ *
+ * @hide
+ */
+ public String[] getKeyboardLayoutListForInputDevice(InputDeviceIdentifier identifier,
+ @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
+ @NonNull InputMethodSubtype imeSubtype) {
+ if (identifier == null) {
+ throw new IllegalArgumentException("inputDeviceDescriptor must not be null");
+ }
+
+ try {
+ return mIm.getKeyboardLayoutListForInputDevice(identifier, userId, imeInfo, imeSubtype);
+ } catch (RemoteException ex) {
+ throw ex.rethrowFromSystemServer();
+ }
+ }
+
+ /**
* Gets the mouse pointer speed.
* <p>
* Only returns the permanent mouse pointer speed. Ignores any temporary pointer
diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java
index 199519c19785..81d782e9b863 100644
--- a/services/core/java/com/android/server/input/InputManagerService.java
+++ b/services/core/java/com/android/server/input/InputManagerService.java
@@ -98,6 +98,7 @@ import android.view.Surface;
import android.view.SurfaceControl;
import android.view.VerifiedInputEvent;
import android.view.ViewConfiguration;
+import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype;
import com.android.internal.R;
@@ -1184,6 +1185,33 @@ public class InputManagerService extends IInputManager.Stub
keyboardLayoutDescriptor);
}
+ @Override // Binder call
+ public String getKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier,
+ @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
+ @NonNull InputMethodSubtype imeSubtype) {
+ return mKeyboardLayoutManager.getKeyboardLayoutForInputDevice(identifier, userId,
+ imeInfo, imeSubtype);
+ }
+
+ @EnforcePermission(Manifest.permission.SET_KEYBOARD_LAYOUT)
+ @Override // Binder call
+ public void setKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier,
+ @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
+ @NonNull InputMethodSubtype imeSubtype, String keyboardLayoutDescriptor) {
+ super.setKeyboardLayoutForInputDevice_enforcePermission();
+ mKeyboardLayoutManager.setKeyboardLayoutForInputDevice(identifier, userId, imeInfo,
+ imeSubtype, keyboardLayoutDescriptor);
+ }
+
+ @Override // Binder call
+ public String[] getKeyboardLayoutListForInputDevice(InputDeviceIdentifier identifier,
+ @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
+ @NonNull InputMethodSubtype imeSubtype) {
+ return mKeyboardLayoutManager.getKeyboardLayoutListForInputDevice(identifier, userId,
+ imeInfo, imeSubtype);
+ }
+
+
public void switchKeyboardLayout(int deviceId, int direction) {
mKeyboardLayoutManager.switchKeyboardLayout(deviceId, direction);
}
diff --git a/services/core/java/com/android/server/input/KeyboardLayoutManager.java b/services/core/java/com/android/server/input/KeyboardLayoutManager.java
index fac001e7828f..ef1736e57961 100644
--- a/services/core/java/com/android/server/input/KeyboardLayoutManager.java
+++ b/services/core/java/com/android/server/input/KeyboardLayoutManager.java
@@ -17,6 +17,7 @@
package com.android.server.input;
import android.annotation.NonNull;
+import android.annotation.UserIdInt;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
@@ -46,6 +47,8 @@ import android.text.TextUtils;
import android.util.Log;
import android.util.Slog;
import android.view.InputDevice;
+import android.view.inputmethod.InputMethodInfo;
+import android.view.inputmethod.InputMethodSubtype;
import android.widget.Toast;
import com.android.internal.R;
@@ -544,6 +547,35 @@ final class KeyboardLayoutManager implements InputManager.InputDeviceListener {
}
}
+ public String getKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier,
+ @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
+ @NonNull InputMethodSubtype imeSubtype) {
+ // TODO(b/259530132): Implement the new keyboard layout API: Returning non-IME specific
+ // layout for now.
+ return getCurrentKeyboardLayoutForInputDevice(identifier);
+ }
+
+ public void setKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier,
+ @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
+ @NonNull InputMethodSubtype imeSubtype, String keyboardLayoutDescriptor) {
+ // TODO(b/259530132): Implement the new keyboard layout API: setting non-IME specific
+ // layout for now.
+ setCurrentKeyboardLayoutForInputDevice(identifier, keyboardLayoutDescriptor);
+ }
+
+ public String[] getKeyboardLayoutListForInputDevice(InputDeviceIdentifier identifier,
+ @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
+ @NonNull InputMethodSubtype imeSubtype) {
+ // TODO(b/259530132): Implement the new keyboard layout API: Returning list of all
+ // layouts for now.
+ KeyboardLayout[] allLayouts = getKeyboardLayouts();
+ String[] allLayoutDesc = new String[allLayouts.length];
+ for (int i = 0; i < allLayouts.length; i++) {
+ allLayoutDesc[i] = allLayouts[i].getDescriptor();
+ }
+ return allLayoutDesc;
+ }
+
public void switchKeyboardLayout(int deviceId, int direction) {
mHandler.obtainMessage(MSG_SWITCH_KEYBOARD_LAYOUT, deviceId, direction).sendToTarget();
}