Commit 6f830481 by Fear1ess

4/2

parent 14ce6561
......@@ -14,6 +14,10 @@ android {
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a'
}
}
buildTypes {
......@@ -27,6 +31,12 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
externalNativeBuild {
cmake {
path file('src/main/cpp/CMakeLists.txt')
}
}
}
dependencies {
......
cmake_minimum_required(VERSION 3.10.2)
project(Demo)
add_library(
demo
SHARED
main.c
)
target_link_libraries(demo)
\ No newline at end of file
//
// Created by Fear1ess on 2021/4/2.
//
int xx(int a, int b) {
return a + b;
}
\ No newline at end of file
......@@ -7,16 +7,12 @@ import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
// Used to load the 'native-lib' library on application startup.
static {
System.loadLibrary("native-lib");
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Example of a call to a native method
TextView tv = findViewById(R.id.sample_text);
tv.setText("hello world!");
......
......@@ -13,17 +13,23 @@ elseif (${CMAKE_ANDROID_ARCH_ABI} STREQUAL "armeabi-v7a")
wd_syscall32.s)
endif()
set(CMAKE_CXX_FLAGS_RELEASE "-fvisibility=hidden -O3 -fno-unwind-tables -flto")
add_library(
wdun
SHARED
core.c
collect.c
utils.c
wd_syscall.c
jni_helper.c
${ARCH_DEPENDED_SRC}
)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} \
-fvisibility=hidden \
-fno-unwind-tables \
-Wl,--exclude-libs,ALL \
-Wl,--gc-sections")
add_library(cJson SHARED IMPORTED)
set_target_properties(
cJson
......
//
// Created by Fear1ess on 2021/4/2.
//
#include "collect.h"
#include "jni_helper.h"
#include "utils.h"
extern jobject g_app_context;
cJSON *collect_init() {
return cJSON_CreateObject();
}
void do_collect(JNIEnv* env) {
cJSON* json = collect_init();
collect_app_info(env, json);
}
void collect_app_info(JNIEnv* env, cJSON *json) {
//package_name
jobject pkgName = wdCallObjectMethod(env, g_app_context, "getPackageName", "()Ljava/lang/String;");
addJniStringToJson(env, json, "package_name", pkgName);
//get packagemanager and pkginfo
jobject pkgManager = wdCallObjectMethod(env, g_app_context, "getPackageManager", "()Landroid/content/pm/PackageManager;");
jobject pkgInfo = wdCallObjectMethod(env, pkgManager, "getPackageInfo", "(Ljava/lang/String;I)Landroid/content/pm/PackageInfo;", pkgName, 0);
//last update time
jlong lastUpdateTime = wdGetLongField(env, pkgInfo, "lastUpdateTime", "J");
cJSON_AddNumberToObject(json, "last_update_time", lastUpdateTime);
const char* info = cJSON_Print(json);
(*env)->DeleteLocalRef(env, pkgName);
return;
}
......@@ -6,6 +6,8 @@
#include <syscall.h>
#include "wdun.h"
#include "cJSON.h"
#include "jni_helper.h"
#include "collect.h"
//import asm symbol
IMPORTWDSYSCALL
......@@ -13,18 +15,30 @@ IMPORTWDSYSCALL
#define WDMAIN_CLASS_NAME "com/reyun/wandun/WdMain"
#define WDMAIN_GETWDID_METHOD_NAME "getWdIdNative"
#define WDMAIN_GETWDID_METHOD_SIG "()Ljava/lang/String;"
#define WDMAIN_INIT_METHOD_NAME "initNative"
#define WDMAIN_INIT_METHOD_SIG "(Landroid/content/Context;)V"
jstring jni_get_wdid(JNIEnv* env, jobject thiz) {
jobject g_app_context = NULL;
JNIEXPORT jstring jni_get_wdid(JNIEnv* env, jobject thiz) {
do_collect(env);
}
JNIEXPORT void jni_init(JNIEnv* env, jobject thiz, jobject context) {
if(!g_app_context) {
g_app_context = (*env)->NewGlobalRef(env, context);
}
}
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
int pid = WDSYSCALL(SYS_getpid);
JNIEnv* env = NULL;
if((*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6) == JNI_TRUE) {
if((*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6) == JNI_OK) {
jclass cls = (*env)->FindClass(env, WDMAIN_CLASS_NAME);
JNINativeMethod methods[] = {{WDMAIN_GETWDID_METHOD_NAME, WDMAIN_GETWDID_METHOD_SIG, (void*)jni_get_wdid}};
JNINativeMethod methods[] = {{WDMAIN_GETWDID_METHOD_NAME, WDMAIN_GETWDID_METHOD_SIG, (void*)jni_get_wdid},
{WDMAIN_INIT_METHOD_NAME, WDMAIN_INIT_METHOD_SIG, (void*)jni_init}};
(*env)->RegisterNatives(env, cls, methods, sizeof(methods)/sizeof(JNINativeMethod));
(*env)->DeleteLocalRef(env, cls);
}
cJSON* json = cJSON_CreateObject();
cJSON_AddStringToObject(json, "name", "zhanglei");
......
//
// Created by Fear1ess on 2021/4/2.
//
#ifndef REYUNSDK_COLLECT_H
#define REYUNSDK_COLLECT_H
#include <jni.h>
#include "cJSON.h"
void do_collect(JNIEnv* env);
cJSON* collect_init();
void collect_app_info(JNIEnv* env, cJSON* json);
#endif //REYUNSDK_COLLECT_H
......@@ -9,7 +9,7 @@
void wdCheckException(JNIEnv* env);
char wdGetMethodRetType(const char* sig);
char wdGetFieldType(const char* sig) { return *sig; }
char wdGetFieldType(const char* sig);
jvalue wdGetStaticField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig);
jvalue wdGetField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig);
void wdSetStaticField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jvalue value);
......@@ -25,6 +25,7 @@ jint wdCallStaticIntMethod(JNIEnv* env, const char* clsName, const char* methodN
jlong wdCallStaticLongMethod(JNIEnv* env, const char* clsName, const char* methodName, const char* methodSig, ...);
jfloat wdCallStaticFloatMethod(JNIEnv* env, const char* clsName, const char* methodName, const char* methodSig, ...);
jdouble wdCallStaticDoubleMethod(JNIEnv* env, const char* clsName, const char* methodName, const char* methodSig, ...);
jobject wdCallStaticObjectMethod(JNIEnv* env, const char* clsName, const char* methodName, const char* methodSig, ...);
void wdCallStaticVoidMethod(JNIEnv* env, const char* clsName, const char* methodName, const char* methodSig, ...);
jboolean wdCallBooleanMethod(JNIEnv* env, jobject obj, const char* methodName, const char* methodSig, ...);
jbyte wdCallByteMethod(JNIEnv* env, jobject obj, const char* methodName, const char* methodSig, ...);
......@@ -34,139 +35,44 @@ jint wdCallIntMethod(JNIEnv* env, jobject obj, const char* methodName, const cha
jlong wdCallLongMethod(JNIEnv* env, jobject obj, const char* methodName, const char* methodSig, ...);
jfloat wdCallFloatMethod(JNIEnv* env, jobject obj, const char* methodName, const char* methodSig, ...);
jdouble wdCallDoubleMethod(JNIEnv* env, jobject obj, const char* methodName, const char* methodSig, ...);
jobject wdCallObjectMethod(JNIEnv* env, jobject obj, const char* methodName, const char* methodSig, ...);
void wdCallVoidMethod(JNIEnv* env, jobject obj, const char* methodName, const char* methodSig, ...);
inline jboolean wdGetStaticBooleanField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig) {
return wdGetStaticField(env, clsName, fieldName, fieldSig).z;
}
inline jbyte wdGetStaticByteField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig) {
return wdGetStaticField(env, clsName, fieldName, fieldSig).b;
}
inline jchar wdGetStaticCharField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig) {
return wdGetStaticField(env, clsName, fieldName, fieldSig).c;
}
inline jshort wdGetStaticShortField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig) {
return wdGetStaticField(env, clsName, fieldName, fieldSig).s;
}
inline jint wdGetStaticIntField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig) {
return wdGetStaticField(env, clsName, fieldName, fieldSig).i;
}
inline jlong wdGetStaticLongField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig) {
return wdGetStaticField(env, clsName, fieldName, fieldSig).j;
}
inline jfloat wdGetStaticFloatField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig) {
return wdGetStaticField(env, clsName, fieldName, fieldSig).f;
}
inline jdouble wdGetStaticDoubleField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig) {
return wdGetStaticField(env, clsName, fieldName, fieldSig).d;
}
inline jobject wdGetStaticObjectField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig) {
return wdGetStaticField(env, clsName, fieldName, fieldSig).l;
}
inline jboolean wdGetBooleanField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig) {
return wdGetField(env, obj, fieldName, fieldSig).z;
}
inline jbyte wdGetByteField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig) {
return wdGetField(env, obj, fieldName, fieldSig).b;
}
inline jchar wdGetCharField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig) {
return wdGetField(env, obj, fieldName, fieldSig).c;
}
inline jshort wdGetShortField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig) {
return wdGetField(env, obj, fieldName, fieldSig).s;
}
inline jint wdGetIntField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig) {
return wdGetField(env, obj, fieldName, fieldSig).i;
}
inline jlong wdGetLongField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig) {
return wdGetField(env, obj, fieldName, fieldSig).j;
}
inline jfloat wdGetFloatField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig) {
return wdGetField(env, obj, fieldName, fieldSig).f;
}
inline jdouble wdGetDoubleField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig) {
return wdGetField(env, obj, fieldName, fieldSig).d;
}
inline jobject wdGetObjectField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig) {
return wdGetField(env, obj, fieldName, fieldSig).l;
}
inline void wdSetStaticBooleanField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jboolean value) {
jvalue j = {.z = value};
wdSetStaticField(env, clsName, fieldName, fieldSig, j);
}
inline void wdSetStaticByteField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jbyte value) {
jvalue j = {.b = value};
wdSetStaticField(env, clsName, fieldName, fieldSig, j);
}
inline void wdSetStaticCharField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jchar value) {
jvalue j = {.c = value};
wdSetStaticField(env, clsName, fieldName, fieldSig, j);
}
inline void wdSetStaticShortField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jshort value) {
jvalue j = {.s = value};
wdSetStaticField(env, clsName, fieldName, fieldSig, j);
}
inline void wdSetStaticIntField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jint value) {
jvalue j = {.i = value};
wdSetStaticField(env, clsName, fieldName, fieldSig, j);
}
inline void wdSetStaticLongField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jlong value) {
jvalue j = {.j = value};
wdSetStaticField(env, clsName, fieldName, fieldSig, j);
}
inline void wdSetStaticFloatField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jfloat value) {
jvalue j = {.f = value};
wdSetStaticField(env, clsName, fieldName, fieldSig, j);
}
inline void wdSetStaticDoubleField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jdouble value) {
jvalue j = {.d = value};
wdSetStaticField(env, clsName, fieldName, fieldSig, j);
}
inline void wdSetStaticObjectField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jobject value) {
jvalue j = {.l = value};
wdSetStaticField(env, clsName, fieldName, fieldSig, j);
}
inline void wdSetBooleanField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jboolean value) {
jvalue j = {.z = value};
wdSetField(env, obj, fieldName, fieldSig, j);
}
inline void wdSetByteField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jbyte value) {
jvalue j = {.b = value};
wdSetField(env, obj, fieldName, fieldSig, j);
}
inline void wdSetCharField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jchar value) {
jvalue j = {.c = value};
wdSetField(env, obj, fieldName, fieldSig, j);
}
inline void wdSetShortField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jshort value) {
jvalue j = {.s = value};
wdSetField(env, obj, fieldName, fieldSig, j);
}
inline void wdSetIntField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jint value) {
jvalue j = {.i = value};
wdSetField(env, obj, fieldName, fieldSig, j);
}
inline void wdSetLongField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jlong value) {
jvalue j = {.j = value};
wdSetField(env, obj, fieldName, fieldSig, j);
}
inline void wdSetFloatField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jfloat value) {
jvalue j = {.f = value};
wdSetField(env, obj, fieldName, fieldSig, j);
}
inline void wdSetDoubleField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jdouble value) {
jvalue j = {.d = value};
wdSetField(env, obj, fieldName, fieldSig, j);
}
inline void wdSetObjectField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jobject value) {
jvalue j = {.l = value};
wdSetField(env, obj, fieldName, fieldSig, j);
}
jboolean wdGetStaticBooleanField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig);
jbyte wdGetStaticByteField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig);
jchar wdGetStaticCharField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig);
jshort wdGetStaticShortField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig);
jint wdGetStaticIntField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig);
jlong wdGetStaticLongField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig);
jfloat wdGetStaticFloatField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig);
jdouble wdGetStaticDoubleField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig);
jobject wdGetStaticObjectField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig);
jboolean wdGetBooleanField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig);
jbyte wdGetByteField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig);
jchar wdGetCharField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig);
jshort wdGetShortField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig);
jint wdGetIntField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig);
jlong wdGetLongField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig);
jfloat wdGetFloatField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig);
jdouble wdGetDoubleField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig);
jobject wdGetObjectField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig);
void wdSetStaticBooleanField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jboolean value);
void wdSetStaticByteField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jbyte value);
void wdSetStaticCharField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jchar value);
void wdSetStaticShortField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jshort value);
void wdSetStaticIntField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jint value);
void wdSetStaticLongField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jlong value);
void wdSetStaticFloatField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jfloat value);
void wdSetStaticDoubleField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jdouble value);
void wdSetStaticObjectField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jobject value);
void wdSetBooleanField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jboolean value);
void wdSetByteField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jbyte value);
void wdSetCharField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jchar value);
void wdSetShortField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jshort value);
void wdSetIntField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jint value);
void wdSetLongField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jlong value);
void wdSetFloatField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jfloat value);
void wdSetDoubleField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jdouble value);
void wdSetObjectField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jobject value);
......
//
// Created by Fear1ess on 2021/4/2.
//
#ifndef REYUNSDK_UTILS_H
#define REYUNSDK_UTILS_H
#include "cJSON.h"
void addJniStringToJson(JNIEnv* env, cJSON* json, const char* key, jobject jstr);
#endif //REYUNSDK_UTILS_H
......@@ -69,31 +69,31 @@ jvalue wdGetField(JNIEnv* env, jobject obj, const char* fieldName, const char* f
switch(wdGetFieldType(fieldSig)) {
case '[':
case 'L':
value.l = (*env)->GetObjectField(env, cls, fieldId);
value.l = (*env)->GetObjectField(env, obj, fieldId);
break;
case 'Z':
value.z = (*env)->GetBooleanField(env, cls, fieldId);
value.z = (*env)->GetBooleanField(env, obj, fieldId);
break;
case 'B':
value.b = (*env)->GetByteField(env, cls, fieldId);
value.b = (*env)->GetByteField(env, obj, fieldId);
break;
case 'C':
value.c = (*env)->GetCharField(env, cls, fieldId);
value.c = (*env)->GetCharField(env, obj, fieldId);
break;
case 'S':
value.s = (*env)->GetShortField(env, cls, fieldId);
value.s = (*env)->GetShortField(env, obj, fieldId);
break;
case 'I':
value.i = (*env)->GetIntField(env, cls, fieldId);
value.i = (*env)->GetIntField(env, obj, fieldId);
break;
case 'J':
value.j = (*env)->GetLongField(env, cls, fieldId);
value.j = (*env)->GetLongField(env, obj, fieldId);
break;
case 'F':
value.f = (*env)->GetFloatField(env, cls, fieldId);
value.f = (*env)->GetFloatField(env, obj, fieldId);
break;
case 'D':
value.d = (*env)->GetDoubleField(env, cls, fieldId);
value.d = (*env)->GetDoubleField(env, obj, fieldId);
break;
default: break;
}
......@@ -149,28 +149,28 @@ void wdSetField(JNIEnv* env, jobject obj, const char* fieldName, const char* fie
(*env)->SetObjectField(env, obj, fieldId, value.l);
break;
case 'Z':
(*env)->SetBooleanField(env, cls, fieldId, value.z);
(*env)->SetBooleanField(env, obj, fieldId, value.z);
break;
case 'B':
(*env)->SetByteField(env, cls, fieldId, value.b);
(*env)->SetByteField(env, obj, fieldId, value.b);
break;
case 'C':
(*env)->SetCharField(env, cls, fieldId, value.c);
(*env)->SetCharField(env, obj, fieldId, value.c);
break;
case 'S':
(*env)->SetShortField(env, cls, fieldId, value.s);
(*env)->SetShortField(env, obj, fieldId, value.s);
break;
case 'I':
(*env)->SetIntField(env, cls, fieldId, value.i);
(*env)->SetIntField(env, obj, fieldId, value.i);
break;
case 'J':
(*env)->SetLongField(env, cls, fieldId, value.j);
(*env)->SetLongField(env, obj, fieldId, value.j);
break;
case 'F':
(*env)->SetFloatField(env, cls, fieldId, value.f);
(*env)->SetFloatField(env, obj, fieldId, value.f);
break;
case 'D':
(*env)->SetDoubleField(env, cls, fieldId, value.d);
(*env)->SetDoubleField(env, obj, fieldId, value.d);
break;
default: break;
}
......@@ -436,6 +436,140 @@ void wdCallVoidMethod(JNIEnv* env, jobject obj, const char* methodName, const ch
va_end(args);
}
jboolean wdGetStaticBooleanField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig) {
return wdGetStaticField(env, clsName, fieldName, fieldSig).z;
}
jbyte wdGetStaticByteField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig) {
return wdGetStaticField(env, clsName, fieldName, fieldSig).b;
}
jchar wdGetStaticCharField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig) {
return wdGetStaticField(env, clsName, fieldName, fieldSig).c;
}
jshort wdGetStaticShortField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig) {
return wdGetStaticField(env, clsName, fieldName, fieldSig).s;
}
jint wdGetStaticIntField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig) {
return wdGetStaticField(env, clsName, fieldName, fieldSig).i;
}
jlong wdGetStaticLongField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig) {
return wdGetStaticField(env, clsName, fieldName, fieldSig).j;
}
jfloat wdGetStaticFloatField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig) {
return wdGetStaticField(env, clsName, fieldName, fieldSig).f;
}
jdouble wdGetStaticDoubleField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig) {
return wdGetStaticField(env, clsName, fieldName, fieldSig).d;
}
jobject wdGetStaticObjectField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig) {
return wdGetStaticField(env, clsName, fieldName, fieldSig).l;
}
jboolean wdGetBooleanField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig) {
return wdGetField(env, obj, fieldName, fieldSig).z;
}
jbyte wdGetByteField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig) {
return wdGetField(env, obj, fieldName, fieldSig).b;
}
jchar wdGetCharField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig) {
return wdGetField(env, obj, fieldName, fieldSig).c;
}
jshort wdGetShortField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig) {
return wdGetField(env, obj, fieldName, fieldSig).s;
}
jint wdGetIntField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig) {
return wdGetField(env, obj, fieldName, fieldSig).i;
}
jlong wdGetLongField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig) {
return wdGetField(env, obj, fieldName, fieldSig).j;
}
jfloat wdGetFloatField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig) {
return wdGetField(env, obj, fieldName, fieldSig).f;
}
jdouble wdGetDoubleField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig) {
return wdGetField(env, obj, fieldName, fieldSig).d;
}
jobject wdGetObjectField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig) {
return wdGetField(env, obj, fieldName, fieldSig).l;
}
void wdSetStaticBooleanField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jboolean value) {
jvalue j = {.z = value};
wdSetStaticField(env, clsName, fieldName, fieldSig, j);
}
void wdSetStaticByteField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jbyte value) {
jvalue j = {.b = value};
wdSetStaticField(env, clsName, fieldName, fieldSig, j);
}
void wdSetStaticCharField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jchar value) {
jvalue j = {.c = value};
wdSetStaticField(env, clsName, fieldName, fieldSig, j);
}
void wdSetStaticShortField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jshort value) {
jvalue j = {.s = value};
wdSetStaticField(env, clsName, fieldName, fieldSig, j);
}
void wdSetStaticIntField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jint value) {
jvalue j = {.i = value};
wdSetStaticField(env, clsName, fieldName, fieldSig, j);
}
void wdSetStaticLongField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jlong value) {
jvalue j = {.j = value};
wdSetStaticField(env, clsName, fieldName, fieldSig, j);
}
void wdSetStaticFloatField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jfloat value) {
jvalue j = {.f = value};
wdSetStaticField(env, clsName, fieldName, fieldSig, j);
}
void wdSetStaticDoubleField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jdouble value) {
jvalue j = {.d = value};
wdSetStaticField(env, clsName, fieldName, fieldSig, j);
}
void wdSetStaticObjectField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig, jobject value) {
jvalue j = {.l = value};
wdSetStaticField(env, clsName, fieldName, fieldSig, j);
}
void wdSetBooleanField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jboolean value) {
jvalue j = {.z = value};
wdSetField(env, obj, fieldName, fieldSig, j);
}
void wdSetByteField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jbyte value) {
jvalue j = {.b = value};
wdSetField(env, obj, fieldName, fieldSig, j);
}
void wdSetCharField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jchar value) {
jvalue j = {.c = value};
wdSetField(env, obj, fieldName, fieldSig, j);
}
void wdSetShortField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jshort value) {
jvalue j = {.s = value};
wdSetField(env, obj, fieldName, fieldSig, j);
}
void wdSetIntField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jint value) {
jvalue j = {.i = value};
wdSetField(env, obj, fieldName, fieldSig, j);
}
void wdSetLongField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jlong value) {
jvalue j = {.j = value};
wdSetField(env, obj, fieldName, fieldSig, j);
}
void wdSetFloatField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jfloat value) {
jvalue j = {.f = value};
wdSetField(env, obj, fieldName, fieldSig, j);
}
void wdSetDoubleField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jdouble value) {
jvalue j = {.d = value};
wdSetField(env, obj, fieldName, fieldSig, j);
}
void wdSetObjectField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jobject value) {
jvalue j = {.l = value};
wdSetField(env, obj, fieldName, fieldSig, j);
}
char wdGetFieldType(const char* sig) { return *sig; }
......
//
// Created by Fear1ess on 2021/4/2.
//
#include <jni.h>
#include "cJSON.h"
#include "utils.h"
void addJniStringToJson(JNIEnv *env, cJSON *json, const char *key, jobject jstr) {
jboolean value = 0;
const char* package_name = (*env)->GetStringUTFChars(env, jstr, &value);
cJSON_AddStringToObject(json, key, package_name);
(*env)->ReleaseStringUTFChars(env, jstr, package_name);
}
......@@ -26,6 +26,7 @@ public class WdMain {
//load native lib
System.loadLibrary("wdun");
initNative(context);
//todo 监控传感器数据变化
//todo 监控手机信号强度变化
......@@ -44,6 +45,10 @@ public class WdMain {
cb.onWdId(wdId);
}
public native void initNative(Context context);
//native层获取wdId
public native String getWdIdNative();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment