Loading core/jni/android_hardware_input_InputApplicationHandle.cpp +2 −10 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #define LOG_TAG "InputApplicationHandle" #include <nativehelper/JNIHelp.h> #include "core_jni_helpers.h" #include "jni.h" #include <android_runtime/AndroidRuntime.h> #include <utils/threads.h> Loading Loading @@ -63,16 +64,7 @@ bool NativeInputApplicationHandle::updateInfo() { mInfo = new InputApplicationInfo(); } jstring nameObj = jstring(env->GetObjectField(obj, gInputApplicationHandleClassInfo.name)); if (nameObj) { const char* nameStr = env->GetStringUTFChars(nameObj, NULL); mInfo->name = nameStr; env->ReleaseStringUTFChars(nameObj, nameStr); env->DeleteLocalRef(nameObj); } else { mInfo->name = "<null>"; } mInfo->name = getStringField(env, obj, gInputApplicationHandleClassInfo.name, "<null>"); mInfo->dispatchingTimeout = env->GetLongField(obj, gInputApplicationHandleClassInfo.dispatchingTimeoutNanos); Loading core/jni/android_hardware_input_InputWindowHandle.cpp +4 −14 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #define LOG_TAG "InputWindowHandle" #include <nativehelper/JNIHelp.h> #include "core_jni_helpers.h" #include "jni.h" #include <android_runtime/AndroidRuntime.h> #include <utils/threads.h> Loading Loading @@ -86,24 +87,14 @@ bool NativeInputWindowHandle::updateInfo() { mInfo.touchableRegion.clear(); jobject tokenObj = env->GetObjectField(obj, gInputWindowHandleClassInfo.token); jobject tokenObj = env->GetObjectField(obj, gInputWindowHandleClassInfo.token); if (tokenObj) { mInfo.token = ibinderForJavaObject(env, tokenObj); } else { mInfo.token.clear(); } jstring nameObj = jstring(env->GetObjectField(obj, gInputWindowHandleClassInfo.name)); if (nameObj) { const char* nameStr = env->GetStringUTFChars(nameObj, NULL); mInfo.name = nameStr; env->ReleaseStringUTFChars(nameObj, nameStr); env->DeleteLocalRef(nameObj); } else { mInfo.name = "<null>"; } mInfo.name = getStringField(env, obj, gInputWindowHandleClassInfo.name, "<null>"); mInfo.layoutParamsFlags = env->GetIntField(obj, gInputWindowHandleClassInfo.layoutParamsFlags); Loading Loading @@ -241,8 +232,7 @@ int register_android_view_InputWindowHandle(JNIEnv* env) { GET_FIELD_ID(gInputWindowHandleClassInfo.ptr, clazz, "ptr", "J"); GET_FIELD_ID(gInputWindowHandleClassInfo.inputApplicationHandle, clazz, GET_FIELD_ID(gInputWindowHandleClassInfo.inputApplicationHandle, clazz, "inputApplicationHandle", "Landroid/view/InputApplicationHandle;"); GET_FIELD_ID(gInputWindowHandleClassInfo.token, clazz, Loading core/jni/android_view_InputChannel.cpp +3 −4 Original line number Diff line number Diff line Loading @@ -17,7 +17,7 @@ #define LOG_TAG "InputChannel-JNI" #include <nativehelper/JNIHelp.h> #include "nativehelper/scoped_utf_chars.h" #include <android_runtime/AndroidRuntime.h> #include <binder/Parcel.h> #include <utils/Log.h> Loading Loading @@ -123,9 +123,8 @@ static jobject android_view_InputChannel_createInputChannel(JNIEnv* env, static jobjectArray android_view_InputChannel_nativeOpenInputChannelPair(JNIEnv* env, jclass clazz, jstring nameObj) { const char* nameChars = env->GetStringUTFChars(nameObj, NULL); std::string name = nameChars; env->ReleaseStringUTFChars(nameObj, nameChars); ScopedUtfChars nameChars(env, nameObj); std::string name = nameChars.c_str(); sp<InputChannel> serverChannel; sp<InputChannel> clientChannel; Loading core/jni/core_jni_helpers.h +16 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ #define CORE_JNI_HELPERS #include <nativehelper/JNIHelp.h> #include <nativehelper/scoped_local_ref.h> #include <nativehelper/scoped_utf_chars.h> #include <android_runtime/AndroidRuntime.h> namespace android { Loading Loading @@ -72,6 +74,20 @@ static inline int RegisterMethodsOrDie(JNIEnv* env, const char* className, return res; } /** * Read the specified field from jobject, and convert to std::string. * If the field cannot be obtained, return defaultValue. */ static inline std::string getStringField(JNIEnv* env, jobject obj, jfieldID fieldId, const char* defaultValue) { ScopedLocalRef<jstring> strObj(env, jstring(env->GetObjectField(obj, fieldId))); if (strObj != nullptr) { ScopedUtfChars chars(env, strObj.get()); return std::string(chars.c_str()); } return std::string(defaultValue); } } // namespace android #endif // CORE_JNI_HELPERS Loading
core/jni/android_hardware_input_InputApplicationHandle.cpp +2 −10 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #define LOG_TAG "InputApplicationHandle" #include <nativehelper/JNIHelp.h> #include "core_jni_helpers.h" #include "jni.h" #include <android_runtime/AndroidRuntime.h> #include <utils/threads.h> Loading Loading @@ -63,16 +64,7 @@ bool NativeInputApplicationHandle::updateInfo() { mInfo = new InputApplicationInfo(); } jstring nameObj = jstring(env->GetObjectField(obj, gInputApplicationHandleClassInfo.name)); if (nameObj) { const char* nameStr = env->GetStringUTFChars(nameObj, NULL); mInfo->name = nameStr; env->ReleaseStringUTFChars(nameObj, nameStr); env->DeleteLocalRef(nameObj); } else { mInfo->name = "<null>"; } mInfo->name = getStringField(env, obj, gInputApplicationHandleClassInfo.name, "<null>"); mInfo->dispatchingTimeout = env->GetLongField(obj, gInputApplicationHandleClassInfo.dispatchingTimeoutNanos); Loading
core/jni/android_hardware_input_InputWindowHandle.cpp +4 −14 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #define LOG_TAG "InputWindowHandle" #include <nativehelper/JNIHelp.h> #include "core_jni_helpers.h" #include "jni.h" #include <android_runtime/AndroidRuntime.h> #include <utils/threads.h> Loading Loading @@ -86,24 +87,14 @@ bool NativeInputWindowHandle::updateInfo() { mInfo.touchableRegion.clear(); jobject tokenObj = env->GetObjectField(obj, gInputWindowHandleClassInfo.token); jobject tokenObj = env->GetObjectField(obj, gInputWindowHandleClassInfo.token); if (tokenObj) { mInfo.token = ibinderForJavaObject(env, tokenObj); } else { mInfo.token.clear(); } jstring nameObj = jstring(env->GetObjectField(obj, gInputWindowHandleClassInfo.name)); if (nameObj) { const char* nameStr = env->GetStringUTFChars(nameObj, NULL); mInfo.name = nameStr; env->ReleaseStringUTFChars(nameObj, nameStr); env->DeleteLocalRef(nameObj); } else { mInfo.name = "<null>"; } mInfo.name = getStringField(env, obj, gInputWindowHandleClassInfo.name, "<null>"); mInfo.layoutParamsFlags = env->GetIntField(obj, gInputWindowHandleClassInfo.layoutParamsFlags); Loading Loading @@ -241,8 +232,7 @@ int register_android_view_InputWindowHandle(JNIEnv* env) { GET_FIELD_ID(gInputWindowHandleClassInfo.ptr, clazz, "ptr", "J"); GET_FIELD_ID(gInputWindowHandleClassInfo.inputApplicationHandle, clazz, GET_FIELD_ID(gInputWindowHandleClassInfo.inputApplicationHandle, clazz, "inputApplicationHandle", "Landroid/view/InputApplicationHandle;"); GET_FIELD_ID(gInputWindowHandleClassInfo.token, clazz, Loading
core/jni/android_view_InputChannel.cpp +3 −4 Original line number Diff line number Diff line Loading @@ -17,7 +17,7 @@ #define LOG_TAG "InputChannel-JNI" #include <nativehelper/JNIHelp.h> #include "nativehelper/scoped_utf_chars.h" #include <android_runtime/AndroidRuntime.h> #include <binder/Parcel.h> #include <utils/Log.h> Loading Loading @@ -123,9 +123,8 @@ static jobject android_view_InputChannel_createInputChannel(JNIEnv* env, static jobjectArray android_view_InputChannel_nativeOpenInputChannelPair(JNIEnv* env, jclass clazz, jstring nameObj) { const char* nameChars = env->GetStringUTFChars(nameObj, NULL); std::string name = nameChars; env->ReleaseStringUTFChars(nameObj, nameChars); ScopedUtfChars nameChars(env, nameObj); std::string name = nameChars.c_str(); sp<InputChannel> serverChannel; sp<InputChannel> clientChannel; Loading
core/jni/core_jni_helpers.h +16 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ #define CORE_JNI_HELPERS #include <nativehelper/JNIHelp.h> #include <nativehelper/scoped_local_ref.h> #include <nativehelper/scoped_utf_chars.h> #include <android_runtime/AndroidRuntime.h> namespace android { Loading Loading @@ -72,6 +74,20 @@ static inline int RegisterMethodsOrDie(JNIEnv* env, const char* className, return res; } /** * Read the specified field from jobject, and convert to std::string. * If the field cannot be obtained, return defaultValue. */ static inline std::string getStringField(JNIEnv* env, jobject obj, jfieldID fieldId, const char* defaultValue) { ScopedLocalRef<jstring> strObj(env, jstring(env->GetObjectField(obj, fieldId))); if (strObj != nullptr) { ScopedUtfChars chars(env, strObj.get()); return std::string(chars.c_str()); } return std::string(defaultValue); } } // namespace android #endif // CORE_JNI_HELPERS