summaryrefslogtreecommitdiffstats
path: root/core/jni
diff options
context:
space:
mode:
Diffstat (limited to 'core/jni')
-rw-r--r--core/jni/Android.mk1
-rw-r--r--core/jni/AndroidRuntime.cpp6
-rw-r--r--core/jni/android_view_InputDevice.cpp97
-rw-r--r--core/jni/android_view_InputDevice.h31
-rw-r--r--core/jni/android_view_KeyCharacterMap.cpp139
-rw-r--r--core/jni/android_view_KeyCharacterMap.h32
6 files changed, 266 insertions, 40 deletions
diff --git a/core/jni/Android.mk b/core/jni/Android.mk
index ec0fe00..523b2d5 100644
--- a/core/jni/Android.mk
+++ b/core/jni/Android.mk
@@ -48,6 +48,7 @@ LOCAL_SRC_FILES:= \
android_view_Surface.cpp \
android_view_TextureView.cpp \
android_view_InputChannel.cpp \
+ android_view_InputDevice.cpp \
android_view_InputEventReceiver.cpp \
android_view_KeyEvent.cpp \
android_view_KeyCharacterMap.cpp \
diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp
index e705c47..879b9d2 100644
--- a/core/jni/AndroidRuntime.cpp
+++ b/core/jni/AndroidRuntime.cpp
@@ -148,7 +148,6 @@ extern int register_android_net_TrafficStats(JNIEnv* env);
extern int register_android_net_wifi_WifiManager(JNIEnv* env);
extern int register_android_text_AndroidCharacter(JNIEnv *env);
extern int register_android_text_AndroidBidi(JNIEnv *env);
-extern int register_android_text_KeyCharacterMap(JNIEnv *env);
extern int register_android_opengl_classes(JNIEnv *env);
extern int register_android_bluetooth_HeadsetBase(JNIEnv* env);
extern int register_android_bluetooth_BluetoothAudioGateway(JNIEnv* env);
@@ -168,7 +167,9 @@ extern int register_android_app_backup_FullBackup(JNIEnv *env);
extern int register_android_app_ActivityThread(JNIEnv *env);
extern int register_android_app_NativeActivity(JNIEnv *env);
extern int register_android_view_InputChannel(JNIEnv* env);
+extern int register_android_view_InputDevice(JNIEnv* env);
extern int register_android_view_InputEventReceiver(JNIEnv* env);
+extern int register_android_view_KeyCharacterMap(JNIEnv *env);
extern int register_android_view_KeyEvent(JNIEnv* env);
extern int register_android_view_MotionEvent(JNIEnv* env);
extern int register_android_view_PointerIcon(JNIEnv* env);
@@ -1082,7 +1083,8 @@ static const RegJNIRec gRegJNI[] = {
REG_JNI(register_android_emoji_EmojiFactory),
REG_JNI(register_android_text_AndroidCharacter),
REG_JNI(register_android_text_AndroidBidi),
- REG_JNI(register_android_text_KeyCharacterMap),
+ REG_JNI(register_android_view_InputDevice),
+ REG_JNI(register_android_view_KeyCharacterMap),
REG_JNI(register_android_os_Process),
REG_JNI(register_android_os_SystemProperties),
REG_JNI(register_android_os_Binder),
diff --git a/core/jni/android_view_InputDevice.cpp b/core/jni/android_view_InputDevice.cpp
new file mode 100644
index 0000000..d7d476a
--- /dev/null
+++ b/core/jni/android_view_InputDevice.cpp
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <androidfw/Input.h>
+
+#include <android_runtime/AndroidRuntime.h>
+#include <nativehelper/jni.h>
+#include <nativehelper/JNIHelp.h>
+
+#include <ScopedLocalRef.h>
+
+#include "android_view_InputDevice.h"
+#include "android_view_KeyCharacterMap.h"
+
+namespace android {
+
+static struct {
+ jclass clazz;
+
+ jmethodID ctor;
+ jmethodID addMotionRange;
+} gInputDeviceClassInfo;
+
+jobject android_view_InputDevice_create(JNIEnv* env, const InputDeviceInfo& deviceInfo) {
+ ScopedLocalRef<jstring> nameObj(env, env->NewStringUTF(deviceInfo.getName().string()));
+ if (!nameObj.get()) {
+ return NULL;
+ }
+
+ ScopedLocalRef<jstring> descriptorObj(env,
+ env->NewStringUTF(deviceInfo.getDescriptor().string()));
+ if (!descriptorObj.get()) {
+ return NULL;
+ }
+
+ ScopedLocalRef<jobject> kcmObj(env,
+ android_view_KeyCharacterMap_create(env, deviceInfo.getId(),
+ deviceInfo.getKeyCharacterMap()));
+ if (!kcmObj.get()) {
+ return NULL;
+ }
+
+ ScopedLocalRef<jobject> inputDeviceObj(env, env->NewObject(gInputDeviceClassInfo.clazz,
+ gInputDeviceClassInfo.ctor, deviceInfo.getId(), nameObj.get(),
+ descriptorObj.get(), deviceInfo.getSources(), deviceInfo.getKeyboardType(),
+ kcmObj.get()));
+
+ 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(inputDeviceObj.get(), gInputDeviceClassInfo.addMotionRange,
+ range.axis, range.source, range.min, range.max, range.flat, range.fuzz);
+ if (env->ExceptionCheck()) {
+ return NULL;
+ }
+ }
+
+ return env->NewLocalRef(inputDeviceObj.get());
+}
+
+
+#define FIND_CLASS(var, className) \
+ var = env->FindClass(className); \
+ LOG_FATAL_IF(! var, "Unable to find class " className);
+
+#define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \
+ var = env->GetMethodID(clazz, methodName, methodDescriptor); \
+ LOG_FATAL_IF(! var, "Unable to find method " methodName);
+
+int register_android_view_InputDevice(JNIEnv* env)
+{
+ FIND_CLASS(gInputDeviceClassInfo.clazz, "android/view/InputDevice");
+ gInputDeviceClassInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceClassInfo.clazz));
+
+ GET_METHOD_ID(gInputDeviceClassInfo.ctor, gInputDeviceClassInfo.clazz,
+ "<init>", "(ILjava/lang/String;Ljava/lang/String;IILandroid/view/KeyCharacterMap;)V");
+
+ GET_METHOD_ID(gInputDeviceClassInfo.addMotionRange, gInputDeviceClassInfo.clazz,
+ "addMotionRange", "(IIFFFF)V");
+
+ return 0;
+}
+
+}; // namespace android
diff --git a/core/jni/android_view_InputDevice.h b/core/jni/android_view_InputDevice.h
new file mode 100644
index 0000000..78651ba
--- /dev/null
+++ b/core/jni/android_view_InputDevice.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _ANDROID_VIEW_INPUTDEVICE_H
+#define _ANDROID_VIEW_INPUTDEVICE_H
+
+#include "jni.h"
+
+#include <androidfw/InputDevice.h>
+
+namespace android {
+
+/* Creates an InputDevice object from the given information. */
+extern jobject android_view_InputDevice_create(JNIEnv* env, const InputDeviceInfo& deviceInfo);
+
+} // namespace android
+
+#endif // _ANDROID_VIEW_INPUTDEVICE_H
diff --git a/core/jni/android_view_KeyCharacterMap.cpp b/core/jni/android_view_KeyCharacterMap.cpp
index 7245d9d..3e56a89 100644
--- a/core/jni/android_view_KeyCharacterMap.cpp
+++ b/core/jni/android_view_KeyCharacterMap.cpp
@@ -14,19 +14,27 @@
* limitations under the License.
*/
+#include <android_runtime/AndroidRuntime.h>
+
#include <androidfw/KeyCharacterMap.h>
#include <androidfw/Input.h>
+#include <binder/Parcel.h>
-#include <android_runtime/AndroidRuntime.h>
#include <nativehelper/jni.h>
#include <nativehelper/JNIHelp.h>
+#include "android_os_Parcel.h"
#include "android_view_KeyEvent.h"
namespace android {
static struct {
jclass clazz;
+ jmethodID ctor;
+} gKeyCharacterMapClassInfo;
+
+static struct {
+ jclass clazz;
} gKeyEventClassInfo;
static struct {
@@ -35,44 +43,87 @@ static struct {
} gFallbackActionClassInfo;
-static jint nativeLoad(JNIEnv *env, jobject clazz, jstring fileStr) {
- const char* file = env->GetStringUTFChars(fileStr, NULL);
-
- KeyCharacterMap* map;
- status_t status = KeyCharacterMap::load(String8(file), &map);
- jint result;
- if (status) {
- String8 msg;
- 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());
- result = 0;
- } else {
- result = reinterpret_cast<jint>(map);
+class NativeKeyCharacterMap {
+public:
+ NativeKeyCharacterMap(int32_t deviceId, const sp<KeyCharacterMap>& map) :
+ mDeviceId(deviceId), mMap(map) {
}
- env->ReleaseStringUTFChars(fileStr, file);
- return result;
+ ~NativeKeyCharacterMap() {
+ }
+
+ inline int32_t getDeviceId() const {
+ return mDeviceId;
+ }
+
+ inline const sp<KeyCharacterMap>& getMap() const {
+ return mMap;
+ }
+
+private:
+ int32_t mDeviceId;
+ sp<KeyCharacterMap> mMap;
+};
+
+
+jobject android_view_KeyCharacterMap_create(JNIEnv* env, int32_t deviceId,
+ const sp<KeyCharacterMap>& kcm) {
+ NativeKeyCharacterMap* map = new NativeKeyCharacterMap(deviceId,
+ kcm.get() ? kcm : KeyCharacterMap::empty());
+ if (!map) {
+ return NULL;
+ }
+
+ return env->NewObject(gKeyCharacterMapClassInfo.clazz, gKeyCharacterMapClassInfo.ctor,
+ reinterpret_cast<jint>(map));
+}
+
+static jint nativeReadFromParcel(JNIEnv *env, jobject clazz, jobject parcelObj) {
+ Parcel* parcel = parcelForJavaObject(env, parcelObj);
+ if (!parcel) {
+ return 0;
+ }
+
+ int32_t deviceId = parcel->readInt32();
+ if (parcel->errorCheck()) {
+ return 0;
+ }
+
+ sp<KeyCharacterMap> kcm = KeyCharacterMap::readFromParcel(parcel);
+ if (!kcm.get()) {
+ return 0;
+ }
+
+ NativeKeyCharacterMap* map = new NativeKeyCharacterMap(deviceId, kcm);
+ return reinterpret_cast<jint>(map);
+}
+
+static void nativeWriteToParcel(JNIEnv* env, jobject clazz, jint ptr, jobject parcelObj) {
+ NativeKeyCharacterMap* map = reinterpret_cast<NativeKeyCharacterMap*>(ptr);
+ Parcel* parcel = parcelForJavaObject(env, parcelObj);
+ if (parcel) {
+ parcel->writeInt32(map->getDeviceId());
+ map->getMap()->writeToParcel(parcel);
+ }
}
static void nativeDispose(JNIEnv *env, jobject clazz, jint ptr) {
- KeyCharacterMap* map = reinterpret_cast<KeyCharacterMap*>(ptr);
+ NativeKeyCharacterMap* map = reinterpret_cast<NativeKeyCharacterMap*>(ptr);
delete map;
}
static jchar nativeGetCharacter(JNIEnv *env, jobject clazz, jint ptr,
jint keyCode, jint metaState) {
- KeyCharacterMap* map = reinterpret_cast<KeyCharacterMap*>(ptr);
- return map->getCharacter(keyCode, metaState);
+ NativeKeyCharacterMap* map = reinterpret_cast<NativeKeyCharacterMap*>(ptr);
+ return map->getMap()->getCharacter(keyCode, metaState);
}
static jboolean nativeGetFallbackAction(JNIEnv *env, jobject clazz, jint ptr, jint keyCode,
jint metaState, jobject fallbackActionObj) {
- KeyCharacterMap* map = reinterpret_cast<KeyCharacterMap*>(ptr);
+ NativeKeyCharacterMap* map = reinterpret_cast<NativeKeyCharacterMap*>(ptr);
KeyCharacterMap::FallbackAction fallbackAction;
- bool result = map->getFallbackAction(keyCode, metaState, &fallbackAction);
+ bool result = map->getMap()->getFallbackAction(keyCode, metaState, &fallbackAction);
if (result) {
env->SetIntField(fallbackActionObj, gFallbackActionClassInfo.keyCode,
fallbackAction.keyCode);
@@ -83,13 +134,13 @@ static jboolean nativeGetFallbackAction(JNIEnv *env, jobject clazz, jint ptr, ji
}
static jchar nativeGetNumber(JNIEnv *env, jobject clazz, jint ptr, jint keyCode) {
- KeyCharacterMap* map = reinterpret_cast<KeyCharacterMap*>(ptr);
- return map->getNumber(keyCode);
+ NativeKeyCharacterMap* map = reinterpret_cast<NativeKeyCharacterMap*>(ptr);
+ return map->getMap()->getNumber(keyCode);
}
static jchar nativeGetMatch(JNIEnv *env, jobject clazz, jint ptr, jint keyCode,
jcharArray charsArray, jint metaState) {
- KeyCharacterMap* map = reinterpret_cast<KeyCharacterMap*>(ptr);
+ NativeKeyCharacterMap* map = reinterpret_cast<NativeKeyCharacterMap*>(ptr);
jsize numChars = env->GetArrayLength(charsArray);
jchar* chars = static_cast<jchar*>(env->GetPrimitiveArrayCritical(charsArray, NULL));
@@ -97,25 +148,25 @@ static jchar nativeGetMatch(JNIEnv *env, jobject clazz, jint ptr, jint keyCode,
return 0;
}
- char16_t result = map->getMatch(keyCode, chars, size_t(numChars), metaState);
+ char16_t result = map->getMap()->getMatch(keyCode, chars, size_t(numChars), metaState);
env->ReleasePrimitiveArrayCritical(charsArray, chars, JNI_ABORT);
return result;
}
static jchar nativeGetDisplayLabel(JNIEnv *env, jobject clazz, jint ptr, jint keyCode) {
- KeyCharacterMap* map = reinterpret_cast<KeyCharacterMap*>(ptr);
- return map->getDisplayLabel(keyCode);
+ NativeKeyCharacterMap* map = reinterpret_cast<NativeKeyCharacterMap*>(ptr);
+ return map->getMap()->getDisplayLabel(keyCode);
}
static jint nativeGetKeyboardType(JNIEnv *env, jobject clazz, jint ptr) {
- KeyCharacterMap* map = reinterpret_cast<KeyCharacterMap*>(ptr);
- return map->getKeyboardType();
+ NativeKeyCharacterMap* map = reinterpret_cast<NativeKeyCharacterMap*>(ptr);
+ return map->getMap()->getKeyboardType();
}
-static jobjectArray nativeGetEvents(JNIEnv *env, jobject clazz, jint ptr, jint deviceId,
+static jobjectArray nativeGetEvents(JNIEnv *env, jobject clazz, jint ptr,
jcharArray charsArray) {
- KeyCharacterMap* map = reinterpret_cast<KeyCharacterMap*>(ptr);
+ NativeKeyCharacterMap* map = reinterpret_cast<NativeKeyCharacterMap*>(ptr);
jchar* chars = env->GetCharArrayElements(charsArray, NULL);
if (!chars) {
@@ -125,7 +176,7 @@ static jobjectArray nativeGetEvents(JNIEnv *env, jobject clazz, jint ptr, jint d
Vector<KeyEvent> events;
jobjectArray result = NULL;
- if (map->getEvents(deviceId, chars, size_t(numChars), events)) {
+ if (map->getMap()->getEvents(map->getDeviceId(), chars, size_t(numChars), events)) {
result = env->NewObjectArray(jsize(events.size()), gKeyEventClassInfo.clazz, NULL);
if (result) {
for (size_t i = 0; i < events.size(); i++) {
@@ -148,8 +199,10 @@ static jobjectArray nativeGetEvents(JNIEnv *env, jobject clazz, jint ptr, jint d
static JNINativeMethod g_methods[] = {
/* name, signature, funcPtr */
- { "nativeLoad", "(Ljava/lang/String;)I",
- (void*)nativeLoad },
+ { "nativeReadFromParcel", "(Landroid/os/Parcel;)I",
+ (void*)nativeReadFromParcel },
+ { "nativeWriteToParcel", "(ILandroid/os/Parcel;)V",
+ (void*)nativeWriteToParcel },
{ "nativeDispose", "(I)V",
(void*)nativeDispose },
{ "nativeGetCharacter", "(III)C",
@@ -164,7 +217,7 @@ static JNINativeMethod g_methods[] = {
(void*)nativeGetDisplayLabel },
{ "nativeGetKeyboardType", "(I)I",
(void*)nativeGetKeyboardType },
- { "nativeGetEvents", "(II[C)[Landroid/view/KeyEvent;",
+ { "nativeGetEvents", "(I[C)[Landroid/view/KeyEvent;",
(void*)nativeGetEvents },
};
@@ -172,12 +225,22 @@ static JNINativeMethod g_methods[] = {
var = env->FindClass(className); \
LOG_FATAL_IF(! var, "Unable to find class " className);
+#define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \
+ var = env->GetMethodID(clazz, methodName, methodDescriptor); \
+ LOG_FATAL_IF(! var, "Unable to find method " methodName);
+
#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
LOG_FATAL_IF(! var, "Unable to find field " fieldName);
-int register_android_text_KeyCharacterMap(JNIEnv* env)
+int register_android_view_KeyCharacterMap(JNIEnv* env)
{
+ FIND_CLASS(gKeyCharacterMapClassInfo.clazz, "android/view/KeyCharacterMap");
+ gKeyCharacterMapClassInfo.clazz = jclass(env->NewGlobalRef(gKeyCharacterMapClassInfo.clazz));
+
+ GET_METHOD_ID(gKeyCharacterMapClassInfo.ctor, gKeyCharacterMapClassInfo.clazz,
+ "<init>", "(I)V");
+
FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent");
gKeyEventClassInfo.clazz = jclass(env->NewGlobalRef(gKeyEventClassInfo.clazz));
diff --git a/core/jni/android_view_KeyCharacterMap.h b/core/jni/android_view_KeyCharacterMap.h
new file mode 100644
index 0000000..04024f6
--- /dev/null
+++ b/core/jni/android_view_KeyCharacterMap.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _ANDROID_VIEW_KEY_CHARACTER_MAP_H
+#define _ANDROID_VIEW_KEY_CHARACTER_MAP_H
+
+#include "jni.h"
+
+#include <androidfw/KeyCharacterMap.h>
+
+namespace android {
+
+/* Creates a KeyCharacterMap object from the given information. */
+extern jobject android_view_KeyCharacterMap_create(JNIEnv* env, int32_t deviceId,
+ const sp<KeyCharacterMap>& map);
+
+} // namespace android
+
+#endif // _ANDROID_VIEW_KEY_CHARACTER_MAP_H