diff options
-rwxr-xr-x | core/java/android/view/InputDevice.java | 10 | ||||
-rw-r--r-- | core/java/android/view/KeyCharacterMap.java | 15 | ||||
-rw-r--r-- | core/jni/android_view_KeyCharacterMap.cpp | 21 | ||||
-rw-r--r-- | include/ui/Input.h | 4 | ||||
-rw-r--r-- | include/ui/KeyCharacterMap.h | 1 | ||||
-rw-r--r-- | include/ui/Keyboard.h | 18 | ||||
-rw-r--r-- | libs/ui/KeyCharacterMap.cpp | 11 | ||||
-rw-r--r-- | libs/ui/Keyboard.cpp | 44 | ||||
-rw-r--r-- | services/input/EventHub.cpp | 26 | ||||
-rw-r--r-- | services/input/EventHub.h | 6 | ||||
-rw-r--r-- | services/input/InputReader.cpp | 1 | ||||
-rw-r--r-- | services/input/tests/InputReader_test.cpp | 4 | ||||
-rw-r--r-- | services/jni/com_android_server_InputManager.cpp | 10 |
13 files changed, 67 insertions, 104 deletions
diff --git a/core/java/android/view/InputDevice.java b/core/java/android/view/InputDevice.java index bfc7c31e5a82..8115b362680e 100755 --- a/core/java/android/view/InputDevice.java +++ b/core/java/android/view/InputDevice.java @@ -19,7 +19,6 @@ package android.view; import android.os.Parcel; import android.os.Parcelable; import android.os.RemoteException; -import android.os.ServiceManager; import java.util.ArrayList; import java.util.List; @@ -44,6 +43,7 @@ public final class InputDevice implements Parcelable { private String mName; private int mSources; private int mKeyboardType; + private String mKeyCharacterMapFile; private final ArrayList<MotionRange> mMotionRanges = new ArrayList<MotionRange>(); @@ -360,6 +360,10 @@ public final class InputDevice implements Parcelable { return KeyCharacterMap.load(mId); } + String getKeyCharacterMapFile() { + return mKeyCharacterMapFile; + } + /** * Gets information about the range of values for a particular {@link MotionEvent} axis. * If the device supports multiple sources, the same axis may have different meanings @@ -532,6 +536,7 @@ public final class InputDevice implements Parcelable { mName = in.readString(); mSources = in.readInt(); mKeyboardType = in.readInt(); + mKeyCharacterMapFile = in.readString(); for (;;) { int axis = in.readInt(); @@ -549,6 +554,7 @@ public final class InputDevice implements Parcelable { out.writeString(mName); out.writeInt(mSources); out.writeInt(mKeyboardType); + out.writeString(mKeyCharacterMapFile); final int numRanges = mMotionRanges.size(); for (int i = 0; i < numRanges; i++) { @@ -587,6 +593,8 @@ public final class InputDevice implements Parcelable { } description.append("\n"); + description.append(" Key Character Map: ").append(mKeyCharacterMapFile).append("\n"); + description.append(" Sources: 0x").append(Integer.toHexString(mSources)).append(" ("); appendSourceDescriptionIfApplicable(description, SOURCE_KEYBOARD, "keyboard"); appendSourceDescriptionIfApplicable(description, SOURCE_DPAD, "dpad"); diff --git a/core/java/android/view/KeyCharacterMap.java b/core/java/android/view/KeyCharacterMap.java index 885a75f64168..575af3bc10e7 100644 --- a/core/java/android/view/KeyCharacterMap.java +++ b/core/java/android/view/KeyCharacterMap.java @@ -20,7 +20,6 @@ import android.text.method.MetaKeyKeyListener; import android.util.AndroidRuntimeException; import android.util.SparseIntArray; import android.os.RemoteException; -import android.os.ServiceManager; import android.util.SparseArray; import java.lang.Character; @@ -140,7 +139,7 @@ public class KeyCharacterMap { private final int mDeviceId; private int mPtr; - private static native int nativeLoad(int id); + private static native int nativeLoad(String file); private static native void nativeDispose(int ptr); private static native char nativeGetCharacter(int ptr, int keyCode, int metaState); @@ -178,7 +177,17 @@ public class KeyCharacterMap { synchronized (sInstances) { KeyCharacterMap map = sInstances.get(deviceId); if (map == null) { - int ptr = nativeLoad(deviceId); // might throw + String kcm = null; + if (deviceId != VIRTUAL_KEYBOARD) { + InputDevice device = InputDevice.getDevice(deviceId); + if (device != null) { + kcm = device.getKeyCharacterMapFile(); + } + } + if (kcm == null || kcm.length() == 0) { + kcm = "/system/usr/keychars/Virtual.kcm"; + } + int ptr = nativeLoad(kcm); // might throw map = new KeyCharacterMap(deviceId, ptr); sInstances.put(deviceId, map); } diff --git a/core/jni/android_view_KeyCharacterMap.cpp b/core/jni/android_view_KeyCharacterMap.cpp index aba3a72d8b6f..b9f373882440 100644 --- a/core/jni/android_view_KeyCharacterMap.cpp +++ b/core/jni/android_view_KeyCharacterMap.cpp @@ -35,18 +35,25 @@ static struct { } gFallbackActionClassInfo; -static jint nativeLoad(JNIEnv *env, jobject clazz, jint deviceId) { +static jint nativeLoad(JNIEnv *env, jobject clazz, jstring fileStr) { + const char* file = env->GetStringUTFChars(fileStr, NULL); + KeyCharacterMap* map; - status_t status = KeyCharacterMap::loadByDeviceId(deviceId, &map); + status_t status = KeyCharacterMap::load(String8(file), &map); + jint result; if (status) { String8 msg; - msg.appendFormat("Could not load key character map for device %d due to error %d. " - "Refer to the log for details.", deviceId, status); + msg.appendFormat("Could not load key character map '%s' due to error %d. " + "Refer to the log for details.", file, status); jniThrowException(env, "android/view/KeyCharacterMap$KeyCharacterMapUnavailableException", msg.string()); - return 0; + result = 0; + } else { + result = reinterpret_cast<jint>(map); } - return reinterpret_cast<jint>(map); + + env->ReleaseStringUTFChars(fileStr, file); + return result; } static void nativeDispose(JNIEnv *env, jobject clazz, jint ptr) { @@ -141,7 +148,7 @@ static jobjectArray nativeGetEvents(JNIEnv *env, jobject clazz, jint ptr, jint d static JNINativeMethod g_methods[] = { /* name, signature, funcPtr */ - { "nativeLoad", "(I)I", + { "nativeLoad", "(Ljava/lang/String;)I", (void*)nativeLoad }, { "nativeDispose", "(I)V", (void*)nativeDispose }, diff --git a/include/ui/Input.h b/include/ui/Input.h index 438a1a0351b2..c2cbe1d6e871 100644 --- a/include/ui/Input.h +++ b/include/ui/Input.h @@ -826,6 +826,9 @@ public: inline void setKeyboardType(int32_t keyboardType) { mKeyboardType = keyboardType; } inline int32_t getKeyboardType() const { return mKeyboardType; } + inline void setKeyCharacterMapFile(const String8& value) { mKeyCharacterMapFile = value; } + inline const String8& getKeyCharacterMapFile() const { return mKeyCharacterMapFile; } + inline const Vector<MotionRange>& getMotionRanges() const { return mMotionRanges; } @@ -835,6 +838,7 @@ private: String8 mName; uint32_t mSources; int32_t mKeyboardType; + String8 mKeyCharacterMapFile; Vector<MotionRange> mMotionRanges; }; diff --git a/include/ui/KeyCharacterMap.h b/include/ui/KeyCharacterMap.h index 10a38109d553..be14432ae59b 100644 --- a/include/ui/KeyCharacterMap.h +++ b/include/ui/KeyCharacterMap.h @@ -53,7 +53,6 @@ public: ~KeyCharacterMap(); static status_t load(const String8& filename, KeyCharacterMap** outMap); - static status_t loadByDeviceId(int32_t deviceId, KeyCharacterMap** outMap); /* Gets the keyboard type. */ int32_t getKeyboardType() const; diff --git a/include/ui/Keyboard.h b/include/ui/Keyboard.h index 609f31991393..274f5264f463 100644 --- a/include/ui/Keyboard.h +++ b/include/ui/Keyboard.h @@ -81,24 +81,6 @@ extern bool isEligibleBuiltInKeyboard(const InputDeviceIdentifier& deviceIdentif const PropertyMap* deviceConfiguration, const KeyMap* keyMap); /** - * Sets keyboard system properties. - */ -extern void setKeyboardProperties(int32_t deviceId, const InputDeviceIdentifier& deviceIdentifier, - const String8& keyLayoutFile, const String8& keyCharacterMapFile); - -/** - * Clears keyboard system properties. - */ -extern void clearKeyboardProperties(int32_t deviceId); - -/** - * Gets the key character map filename for a device using inspecting system properties - * and then falling back on a default key character map if necessary. - * Returns a NAME_NOT_FOUND if none found. - */ -extern status_t getKeyCharacterMapFile(int32_t deviceId, String8& outKeyCharacterMapFile); - -/** * Gets a key code by its short form label, eg. "HOME". * Returns 0 if unknown. */ diff --git a/libs/ui/KeyCharacterMap.cpp b/libs/ui/KeyCharacterMap.cpp index 2decfe93215a..77f18dec5c9f 100644 --- a/libs/ui/KeyCharacterMap.cpp +++ b/libs/ui/KeyCharacterMap.cpp @@ -124,17 +124,6 @@ status_t KeyCharacterMap::load(const String8& filename, KeyCharacterMap** outMap return status; } -status_t KeyCharacterMap::loadByDeviceId(int32_t deviceId, KeyCharacterMap** outMap) { - *outMap = NULL; - - String8 filename; - status_t result = getKeyCharacterMapFile(deviceId, filename); - if (!result) { - result = load(filename, outMap); - } - return result; -} - int32_t KeyCharacterMap::getKeyboardType() const { return mType; } diff --git a/libs/ui/Keyboard.cpp b/libs/ui/Keyboard.cpp index 600a951d5f90..10bb39c57518 100644 --- a/libs/ui/Keyboard.cpp +++ b/libs/ui/Keyboard.cpp @@ -173,50 +173,6 @@ bool isEligibleBuiltInKeyboard(const InputDeviceIdentifier& deviceIdentifier, return strstr(deviceIdentifier.name.string(), "-keypad"); } -void setKeyboardProperties(int32_t deviceId, - const InputDeviceIdentifier& deviceIdentifier, - const String8& keyLayoutFile, const String8& keyCharacterMapFile) { - char propName[PROPERTY_KEY_MAX]; - snprintf(propName, sizeof(propName), "hw.keyboards.%u.devname", deviceId); - property_set(propName, deviceIdentifier.name.string()); - snprintf(propName, sizeof(propName), "hw.keyboards.%u.klfile", deviceId); - property_set(propName, keyLayoutFile.string()); - snprintf(propName, sizeof(propName), "hw.keyboards.%u.kcmfile", deviceId); - property_set(propName, keyCharacterMapFile.string()); -} - -void clearKeyboardProperties(int32_t deviceId) { - char propName[PROPERTY_KEY_MAX]; - snprintf(propName, sizeof(propName), "hw.keyboards.%u.devname", deviceId); - property_set(propName, ""); - snprintf(propName, sizeof(propName), "hw.keyboards.%u.klfile", deviceId); - property_set(propName, ""); - snprintf(propName, sizeof(propName), "hw.keyboards.%u.kcmfile", deviceId); - property_set(propName, ""); -} - -status_t getKeyCharacterMapFile(int32_t deviceId, String8& outKeyCharacterMapFile) { - if (deviceId != DEVICE_ID_VIRTUAL_KEYBOARD) { - char propName[PROPERTY_KEY_MAX]; - char fn[PROPERTY_VALUE_MAX]; - snprintf(propName, sizeof(propName), "hw.keyboards.%u.kcmfile", deviceId); - if (property_get(propName, fn, "") > 0) { - outKeyCharacterMapFile.setTo(fn); - return OK; - } - } - - // Default to Virtual since the keyboard does not appear to be installed. - outKeyCharacterMapFile.setTo(getInputDeviceConfigurationFilePathByName(String8("Virtual"), - INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_CHARACTER_MAP)); - if (!outKeyCharacterMapFile.isEmpty()) { - return OK; - } - - LOGE("Can't find any key character map files including the Virtual key map!"); - return NAME_NOT_FOUND; -} - static int lookupValueByLabel(const char* literal, const KeycodeLabel *list) { while (list->literal) { if (strcmp(literal, list->literal) == 0) { diff --git a/services/input/EventHub.cpp b/services/input/EventHub.cpp index 790b395c7b41..52897417596c 100644 --- a/services/input/EventHub.cpp +++ b/services/input/EventHub.cpp @@ -507,6 +507,15 @@ void EventHub::getVirtualKeyDefinitions(int32_t deviceId, } } +String8 EventHub::getKeyCharacterMapFile(int32_t deviceId) const { + AutoMutex _l(mLock); + Device* device = getDeviceLocked(deviceId); + if (device) { + return device->keyMap.keyCharacterMapFile; + } + return String8(); +} + EventHub::Device* EventHub::getDeviceLocked(int32_t deviceId) const { if (deviceId == 0) { deviceId = mBuiltInKeyboardId; @@ -1013,16 +1022,12 @@ status_t EventHub::openDeviceLocked(const char *devicePath) { // Configure the keyboard, gamepad or virtual keyboard. if (device->classes & INPUT_DEVICE_CLASS_KEYBOARD) { - // Set system properties for the keyboard. - setKeyboardPropertiesLocked(device, false); - // Register the keyboard as a built-in keyboard if it is eligible. if (!keyMapStatus && mBuiltInKeyboardId == -1 && isEligibleBuiltInKeyboard(device->identifier, device->configuration, &device->keyMap)) { mBuiltInKeyboardId = device->id; - setKeyboardPropertiesLocked(device, true); } // 'Q' key support = cheap test of whether this is an alpha-capable kbd @@ -1120,17 +1125,6 @@ status_t EventHub::loadKeyMapLocked(Device* device) { return device->keyMap.load(device->identifier, device->configuration); } -void EventHub::setKeyboardPropertiesLocked(Device* device, bool builtInKeyboard) { - int32_t id = builtInKeyboard ? 0 : device->id; - android::setKeyboardProperties(id, device->identifier, - device->keyMap.keyLayoutFile, device->keyMap.keyCharacterMapFile); -} - -void EventHub::clearKeyboardPropertiesLocked(Device* device, bool builtInKeyboard) { - int32_t id = builtInKeyboard ? 0 : device->id; - android::clearKeyboardProperties(id); -} - bool EventHub::isExternalDeviceLocked(Device* device) { if (device->configuration) { bool value; @@ -1184,9 +1178,7 @@ void EventHub::closeDeviceLocked(Device* device) { LOGW("built-in keyboard device %s (id=%d) is closing! the apps will not like this", device->path.string(), mBuiltInKeyboardId); mBuiltInKeyboardId = -1; - clearKeyboardPropertiesLocked(device, true); } - clearKeyboardPropertiesLocked(device, false); if (epoll_ctl(mEpollFd, EPOLL_CTL_DEL, device->fd, NULL)) { LOGW("Could not remove device fd from epoll instance. errno=%d", errno); diff --git a/services/input/EventHub.h b/services/input/EventHub.h index d37549a849e7..9d8252ed4763 100644 --- a/services/input/EventHub.h +++ b/services/input/EventHub.h @@ -208,6 +208,8 @@ public: virtual void getVirtualKeyDefinitions(int32_t deviceId, Vector<VirtualKeyDefinition>& outVirtualKeys) const = 0; + virtual String8 getKeyCharacterMapFile(int32_t deviceId) const = 0; + /* Requests the EventHub to reopen all input devices on the next call to getEvents(). */ virtual void requestReopenDevices() = 0; @@ -264,6 +266,8 @@ public: virtual void getVirtualKeyDefinitions(int32_t deviceId, Vector<VirtualKeyDefinition>& outVirtualKeys) const; + virtual String8 getKeyCharacterMapFile(int32_t deviceId) const; + virtual void requestReopenDevices(); virtual void wake(); @@ -321,8 +325,6 @@ private: void loadConfigurationLocked(Device* device); status_t loadVirtualKeyMapLocked(Device* device); status_t loadKeyMapLocked(Device* device); - void setKeyboardPropertiesLocked(Device* device, bool builtInKeyboard); - void clearKeyboardPropertiesLocked(Device* device, bool builtInKeyboard); bool isExternalDeviceLocked(Device* device); diff --git a/services/input/InputReader.cpp b/services/input/InputReader.cpp index 88c19a417f8a..b34ff2551f61 100644 --- a/services/input/InputReader.cpp +++ b/services/input/InputReader.cpp @@ -1775,6 +1775,7 @@ void KeyboardInputMapper::populateDeviceInfo(InputDeviceInfo* info) { InputMapper::populateDeviceInfo(info); info->setKeyboardType(mKeyboardType); + info->setKeyCharacterMapFile(getEventHub()->getKeyCharacterMapFile(getDeviceId())); } void KeyboardInputMapper::dump(String8& dump) { diff --git a/services/input/tests/InputReader_test.cpp b/services/input/tests/InputReader_test.cpp index a0862082f208..08efe7dcdd92 100644 --- a/services/input/tests/InputReader_test.cpp +++ b/services/input/tests/InputReader_test.cpp @@ -609,6 +609,10 @@ private: } } + virtual String8 getKeyCharacterMapFile(int32_t deviceId) const { + return String8(); + } + virtual bool isExternal(int32_t deviceId) const { return false; } diff --git a/services/jni/com_android_server_InputManager.cpp b/services/jni/com_android_server_InputManager.cpp index 7e9fba891946..f25988339a4d 100644 --- a/services/jni/com_android_server_InputManager.cpp +++ b/services/jni/com_android_server_InputManager.cpp @@ -98,6 +98,7 @@ static struct { jfieldID mName; jfieldID mSources; jfieldID mKeyboardType; + jfieldID mKeyCharacterMapFile; } gInputDeviceClassInfo; static struct { @@ -1231,10 +1232,16 @@ static jobject android_server_InputManager_nativeGetInputDevice(JNIEnv* env, return NULL; } + jstring fileStr = env->NewStringUTF(deviceInfo.getKeyCharacterMapFile()); + if (!fileStr) { + return NULL; + } + env->SetIntField(deviceObj, gInputDeviceClassInfo.mId, deviceInfo.getId()); env->SetObjectField(deviceObj, gInputDeviceClassInfo.mName, deviceNameObj); env->SetIntField(deviceObj, gInputDeviceClassInfo.mSources, deviceInfo.getSources()); env->SetIntField(deviceObj, gInputDeviceClassInfo.mKeyboardType, deviceInfo.getKeyboardType()); + env->SetObjectField(deviceObj, gInputDeviceClassInfo.mKeyCharacterMapFile, fileStr); const Vector<InputDeviceInfo::MotionRange>& ranges = deviceInfo.getMotionRanges(); for (size_t i = 0; i < ranges.size(); i++) { @@ -1516,6 +1523,9 @@ int register_android_server_InputManager(JNIEnv* env) { GET_FIELD_ID(gInputDeviceClassInfo.mKeyboardType, gInputDeviceClassInfo.clazz, "mKeyboardType", "I"); + GET_FIELD_ID(gInputDeviceClassInfo.mKeyCharacterMapFile, gInputDeviceClassInfo.clazz, + "mKeyCharacterMapFile", "Ljava/lang/String;"); + // Configuration FIND_CLASS(clazz, "android/content/res/Configuration"); |