From 46ac35d09b0a1ba7af7eb4c14293a7978edcd2ab Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Wed, 20 Apr 2016 16:59:45 -0700 Subject: [PATCH] Accept null subtype in InputMethodSubtypeHandle. There are two types of IMEs: A. IMEs that have one or more subtypes B. IMEs that have no subtype The initial implementation to update hardware keyboard layout per subtype change of layout (See Bug 25752812) has supported IMEs in the category A only, and IMEs in the category B are just ignored in both system and Settings app. In order to support IMEs in the category B, InputMethodSubtypeHandle and related methods need to accept null InputMethodSubtype. Technically this is a straightforward change, because in InputMethodManagerService we have already used InputMethodUtils.NOT_A_SUBTYPE_ID for those IMEs in the category B. We also need to update Setting App, which will be done by a different CL [1]. [1]: I46b9c5b018f08e3eaa4614a0893db0be91652f3c Bug: 28182650 Change-Id: Ia013784a594ad3beaf30976d047f5ac0fa8185be --- core/java/android/hardware/input/InputManager.java | 11 +++++++---- .../internal/inputmethod/InputMethodSubtypeHandle.java | 5 +++-- .../java/com/android/server/input/InputManagerService.java | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/core/java/android/hardware/input/InputManager.java b/core/java/android/hardware/input/InputManager.java index f810fecb6427..8a43acb59100 100644 --- a/core/java/android/hardware/input/InputManager.java +++ b/core/java/android/hardware/input/InputManager.java @@ -19,6 +19,7 @@ package android.hardware.input; import com.android.internal.os.SomeArgs; import android.annotation.IntDef; +import android.annotation.Nullable; import android.annotation.SdkConstant; import android.annotation.SdkConstant.SdkConstantType; import android.content.Context; @@ -644,14 +645,16 @@ public final class InputManager { * * @param identifier The identifier for the input device. * @param inputMethodInfo The input method. - * @param inputMethodSubtype The input method subtype. + * @param inputMethodSubtype The input method subtype. {@code null} if this input method does + * not support any subtype. * * @return The associated {@link KeyboardLayout}, or null if one has not been set. * * @hide */ + @Nullable public KeyboardLayout getKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier, - InputMethodInfo inputMethodInfo, InputMethodSubtype inputMethodSubtype) { + InputMethodInfo inputMethodInfo, @Nullable InputMethodSubtype inputMethodSubtype) { try { return mIm.getKeyboardLayoutForInputDevice( identifier, inputMethodInfo, inputMethodSubtype); @@ -666,13 +669,13 @@ public final class InputManager { * @param identifier The identifier for the input device. * @param inputMethodInfo The input method with which to associate the keyboard layout. * @param inputMethodSubtype The input method subtype which which to associate the keyboard - * layout. + * layout. {@code null} if this input method does not support any subtype. * @param keyboardLayoutDescriptor The descriptor of the keyboard layout to set * * @hide */ public void setKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier, - InputMethodInfo inputMethodInfo, InputMethodSubtype inputMethodSubtype, + InputMethodInfo inputMethodInfo, @Nullable InputMethodSubtype inputMethodSubtype, String keyboardLayoutDescriptor) { try { mIm.setKeyboardLayoutForInputDevice(identifier, inputMethodInfo, diff --git a/core/java/com/android/internal/inputmethod/InputMethodSubtypeHandle.java b/core/java/com/android/internal/inputmethod/InputMethodSubtypeHandle.java index 975021e85cce..04d7f9b2c9c0 100644 --- a/core/java/com/android/internal/inputmethod/InputMethodSubtypeHandle.java +++ b/core/java/com/android/internal/inputmethod/InputMethodSubtypeHandle.java @@ -16,6 +16,7 @@ package com.android.internal.inputmethod; +import android.annotation.Nullable; import android.text.TextUtils; import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodSubtype; @@ -26,12 +27,12 @@ public class InputMethodSubtypeHandle { private final String mInputMethodId; private final int mSubtypeId; - public InputMethodSubtypeHandle(InputMethodInfo info, InputMethodSubtype subtype) { + public InputMethodSubtypeHandle(InputMethodInfo info, @Nullable InputMethodSubtype subtype) { mInputMethodId = info.getId(); if (subtype != null) { mSubtypeId = subtype.hashCode(); } else { - mSubtypeId = 0; + mSubtypeId = InputMethodUtils.NOT_A_SUBTYPE_ID; } } diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java index c7c765bb431e..c64901235ebc 100644 --- a/services/core/java/com/android/server/input/InputManagerService.java +++ b/services/core/java/com/android/server/input/InputManagerService.java @@ -1349,8 +1349,8 @@ public class InputManagerService extends IInputManager.Stub if (keyboardLayoutDescriptor == null) { throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null"); } - if (imeInfo == null || imeSubtype == null) { - throw new IllegalArgumentException("imeInfo and imeSubtype must not be null"); + if (imeInfo == null) { + throw new IllegalArgumentException("imeInfo must not be null"); } InputMethodSubtypeHandle handle = new InputMethodSubtypeHandle(imeInfo, imeSubtype); setKeyboardLayoutForInputDeviceInner(identifier, handle, keyboardLayoutDescriptor); -- 2.11.0