summaryrefslogtreecommitdiffstats
path: root/services/jni
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2012-04-10 14:30:49 -0700
committerJeff Brown <jeffbrown@google.com>2012-04-10 18:23:58 -0700
commit9f25b7fdf216c9ef0bd2322cd223eeaf0d60f77f (patch)
treeb0b509a261874435cab3f5f1a727c02b399bd91c /services/jni
parent54ae14749bc7f9e73cfda35a8b49f9efa80a77fb (diff)
downloadframeworks_base-9f25b7fdf216c9ef0bd2322cd223eeaf0d60f77f.zip
frameworks_base-9f25b7fdf216c9ef0bd2322cd223eeaf0d60f77f.tar.gz
frameworks_base-9f25b7fdf216c9ef0bd2322cd223eeaf0d60f77f.tar.bz2
Request key maps from input manager service.
Instead of each application loading the KeyCharacterMap from the file system, get them from the input manager service as part of the InputDevice object. Refactored InputManager to be a proper singleton instead of having a bunch of static methods. InputManager now maintains a cache of all InputDevice objects that it has loaded. Currently we never invalidate the cache which can cause InputDevice to return stale motion ranges if the device is reconfigured. This will be fixed in a future change. Added a fake InputDevice with ID -1 to represent the virtual keyboard. Change-Id: If7a695839ad0972317a5aab89e9d1e42ace28eb7
Diffstat (limited to 'services/jni')
-rw-r--r--services/jni/com_android_server_input_InputManagerService.cpp83
1 files changed, 2 insertions, 81 deletions
diff --git a/services/jni/com_android_server_input_InputManagerService.cpp b/services/jni/com_android_server_input_InputManagerService.cpp
index c137a78..85d6e11 100644
--- a/services/jni/com_android_server_input_InputManagerService.cpp
+++ b/services/jni/com_android_server_input_InputManagerService.cpp
@@ -39,6 +39,7 @@
#include <input/SpriteController.h>
#include <android_os_MessageQueue.h>
+#include <android_view_InputDevice.h>
#include <android_view_KeyEvent.h>
#include <android_view_MotionEvent.h>
#include <android_view_InputChannel.h>
@@ -88,20 +89,6 @@ static struct {
} gMotionEventClassInfo;
static struct {
- jclass clazz;
-
- jmethodID ctor;
- jmethodID addMotionRange;
-
- jfieldID mId;
- jfieldID mName;
- jfieldID mDescriptor;
- jfieldID mSources;
- jfieldID mKeyboardType;
- jfieldID mKeyCharacterMapFile;
-} gInputDeviceClassInfo;
-
-static struct {
jfieldID touchscreen;
jfieldID keyboard;
jfieldID navigation;
@@ -1171,44 +1158,7 @@ static jobject nativeGetInputDevice(JNIEnv* env,
return NULL;
}
- jobject deviceObj = env->NewObject(gInputDeviceClassInfo.clazz, gInputDeviceClassInfo.ctor);
- if (!deviceObj) {
- return NULL;
- }
-
- jstring deviceNameObj = env->NewStringUTF(deviceInfo.getName().string());
- if (!deviceNameObj) {
- return NULL;
- }
-
- jstring deviceDescriptorObj = env->NewStringUTF(deviceInfo.getDescriptor().string());
- if (!deviceDescriptorObj) {
- 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->SetObjectField(deviceObj, gInputDeviceClassInfo.mDescriptor, deviceDescriptorObj);
- 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++) {
- const InputDeviceInfo::MotionRange& range = ranges.itemAt(i);
- env->CallVoidMethod(deviceObj, gInputDeviceClassInfo.addMotionRange,
- range.axis, range.source, range.min, range.max, range.flat, range.fuzz);
- if (env->ExceptionCheck()) {
- return NULL;
- }
- }
-
- return deviceObj;
+ return android_view_InputDevice_create(env, deviceInfo);
}
static jintArray nativeGetInputDeviceIds(JNIEnv* env,
@@ -1437,35 +1387,6 @@ int register_android_server_InputManager(JNIEnv* env) {
FIND_CLASS(gMotionEventClassInfo.clazz, "android/view/MotionEvent");
gMotionEventClassInfo.clazz = jclass(env->NewGlobalRef(gMotionEventClassInfo.clazz));
- // InputDevice
-
- FIND_CLASS(gInputDeviceClassInfo.clazz, "android/view/InputDevice");
- gInputDeviceClassInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceClassInfo.clazz));
-
- GET_METHOD_ID(gInputDeviceClassInfo.ctor, gInputDeviceClassInfo.clazz,
- "<init>", "()V");
-
- GET_METHOD_ID(gInputDeviceClassInfo.addMotionRange, gInputDeviceClassInfo.clazz,
- "addMotionRange", "(IIFFFF)V");
-
- GET_FIELD_ID(gInputDeviceClassInfo.mId, gInputDeviceClassInfo.clazz,
- "mId", "I");
-
- GET_FIELD_ID(gInputDeviceClassInfo.mName, gInputDeviceClassInfo.clazz,
- "mName", "Ljava/lang/String;");
-
- GET_FIELD_ID(gInputDeviceClassInfo.mDescriptor, gInputDeviceClassInfo.clazz,
- "mDescriptor", "Ljava/lang/String;");
-
- GET_FIELD_ID(gInputDeviceClassInfo.mSources, gInputDeviceClassInfo.clazz,
- "mSources", "I");
-
- 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");