Commit 63e0f769 by leiguo1029

4/1

parent 00db59d1
...@@ -39,6 +39,7 @@ void do_collect(JNIEnv* env) { ...@@ -39,6 +39,7 @@ void do_collect(JNIEnv* env) {
start_time = ts.tv_nsec / 1000000 + ts.tv_sec * 1000ULL; start_time = ts.tv_nsec / 1000000 + ts.tv_sec * 1000ULL;
} }
collect_app_info(env, json); collect_app_info(env, json);
int permissions = collect_permissions(env, json);
collect_imei(env, json); collect_imei(env, json);
collect_android_id(env, json); collect_android_id(env, json);
collect_mac_addr(env, json); collect_mac_addr(env, json);
...@@ -56,7 +57,10 @@ void do_collect(JNIEnv* env) { ...@@ -56,7 +57,10 @@ void do_collect(JNIEnv* env) {
collect_mem_info(env, json); collect_mem_info(env, json);
collect_network_info(env, json); collect_network_info(env, json);
collect_user_agent(env, json); collect_user_agent(env, json);
collect_location_info(env, json); if((permissions & PERMISSION_ACCESS_FINE_LOCATION) && (permissions & PERMISSION_ACCESS_COARSE_LOCATION)) {
collect_location_info(env, json);
}
if(WDSYSCALL(SYS_clock_gettime, CLOCK_MONOTONIC, &ts) == 0) { if(WDSYSCALL(SYS_clock_gettime, CLOCK_MONOTONIC, &ts) == 0) {
end_time = (double)ts.tv_nsec / 1000000 + (double)ts.tv_sec * 1000ULL; end_time = (double)ts.tv_nsec / 1000000 + (double)ts.tv_sec * 1000ULL;
...@@ -127,6 +131,29 @@ void collect_app_info(JNIEnv* env, cJSON *json) { ...@@ -127,6 +131,29 @@ void collect_app_info(JNIEnv* env, cJSON *json) {
(*env)->PopLocalFrame(env, NULL); (*env)->PopLocalFrame(env, NULL);
} }
int collect_permissions(JNIEnv* env, cJSON* json) {
int value = 0;
const char* permissions[] = {
"android.permission.READ_EXTERNAL_STORAGE",
"android.permission.WRITE_EXTERNAL_STORAGE",
"android.permission.READ_PHONE_STATE",
"android.permission.ACCESS_NETWORK_STATE",
"android.permission.ACCESS_WIFI_STATE",
"android.permission.ACCESS_COARSE_LOCATION",
"android.permission.ACCESS_FINE_LOCATION"
};
for(int i = 0; i < sizeof(permissions)/sizeof(const char*); ++i) {
jstring str = (*env)->NewStringUTF(env, permissions[i]);
if(wdCallIntMethod(env, g_app_context, "checkSelfPermission", "(Ljava/lang/String;)I", str) == 0) {
value |= (2 << i);
}
(*env)->DeleteLocalRef(env, str);
}
return value;
}
void collect_imei(JNIEnv *env, cJSON *json) { void collect_imei(JNIEnv *env, cJSON *json) {
//get imei from telephonymanager //get imei from telephonymanager
jstring phone_str = (*env)->NewStringUTF(env, "phone"); jstring phone_str = (*env)->NewStringUTF(env, "phone");
...@@ -515,26 +542,12 @@ void collect_user_agent(JNIEnv *env, cJSON *json) { ...@@ -515,26 +542,12 @@ void collect_user_agent(JNIEnv *env, cJSON *json) {
void collect_location_info(JNIEnv *env, cJSON *json) { void collect_location_info(JNIEnv *env, cJSON *json) {
//get location info need ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION permission. //get location info need ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION permission.
cJSON* item = cJSON_CreateObject(); cJSON* item = cJSON_CreateObject();
const char* permissions[] = {"android.permission.ACCESS_COARSE_LOCATION",
"android.permission.ACCESS_FINE_LOCATION"};
int get_permissions = 1;
for(int i = 0; i < sizeof(permissions)/sizeof(const char*); ++i) {
jstring str = (*env)->NewStringUTF(env, permissions[i]);
if(wdCallIntMethod(env, g_app_context, "checkSelfPermission", "(Ljava/lang/String;)I", str) != 0) {
get_permissions = 0;
(*env)->DeleteLocalRef(env, str);
break;
}
(*env)->DeleteLocalRef(env, str);
}
if(!get_permissions) goto return_label;
jstring loc_jstr = (*env)->NewStringUTF(env, "location"); jstring loc_jstr = (*env)->NewStringUTF(env, "location");
jobject lm = wdCallObjectMethod(env, g_app_context, "getSystemService", jobject lm = wdCallObjectMethod(env, g_app_context, "getSystemService",
"(Ljava/lang/String;)Ljava/lang/Object;", loc_jstr); "(Ljava/lang/String;)Ljava/lang/Object;", loc_jstr);
jobject providers = wdCallObjectMethod(env, lm, "getAllProviders", "()Ljava/util/List;"); jobject providers = wdCallObjectMethod(env, lm, "getAllProviders", "()Ljava/util/List;");
if(providers == NULL) goto return_label2; if(providers == NULL) goto return_label;
jint size = wdCallIntMethod(env, providers, "size", "()I"); jint size = wdCallIntMethod(env, providers, "size", "()I");
int get_loc = 0; int get_loc = 0;
for(int i = 0; i < size; ++i) { for(int i = 0; i < size; ++i) {
...@@ -556,15 +569,15 @@ void collect_location_info(JNIEnv *env, cJSON *json) { ...@@ -556,15 +569,15 @@ void collect_location_info(JNIEnv *env, cJSON *json) {
if(get_loc) break; if(get_loc) break;
} }
(*env)->DeleteLocalRef(env, providers); (*env)->DeleteLocalRef(env, providers);
return_label2: return_label:
(*env)->DeleteLocalRef(env, lm); (*env)->DeleteLocalRef(env, lm);
(*env)->DeleteLocalRef(env, loc_jstr); (*env)->DeleteLocalRef(env, loc_jstr);
return_label:
cJSON_AddItemToObject(json, "location", item); cJSON_AddItemToObject(json, "location", item);
logd(WD_COLLECT, "%s", "collect location info finished..."); logd(WD_COLLECT, "%s", "collect location info finished...");
} }
void collect_cell_info(JNIEnv *env, cJSON *json) { void collect_cell_info(JNIEnv *env, cJSON *json) {
//cell info need ACCESSS_COARSE_LOCATION permission
cJSON* item = cJSON_CreateObject();
} }
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
void do_collect(JNIEnv* env); void do_collect(JNIEnv* env);
cJSON* collect_init(); cJSON* collect_init();
void collect_app_info(JNIEnv* env, cJSON* json); void collect_app_info(JNIEnv* env, cJSON* json);
int collect_permissions(JNIEnv* env, cJSON* json);
void collect_imei(JNIEnv* env, cJSON* json); void collect_imei(JNIEnv* env, cJSON* json);
void collect_android_id(JNIEnv* env, cJSON* json); void collect_android_id(JNIEnv* env, cJSON* json);
void collect_mac_addr(JNIEnv* env, cJSON* json); void collect_mac_addr(JNIEnv* env, cJSON* json);
...@@ -74,5 +75,13 @@ void collect_cell_info(JNIEnv* env, cJSON* json); ...@@ -74,5 +75,13 @@ void collect_cell_info(JNIEnv* env, cJSON* json);
/** Current network is NR(New Radio) 5G. */ /** Current network is NR(New Radio) 5G. */
#define NETWORK_TYPE_NR 20 #define NETWORK_TYPE_NR 20
#define PERMISSION_READ_EXTERNAL_STORAGE 0x1
#define PERMISSION_WRITE_EXTERNAL_STORAGE 0x2
#define PERMISSION_READ_PHONE_STATE 0x4
#define PERMISSION_ACCESS_NETWORK_STATE 0x8
#define PERMISSION_ACCESS_WIFI_STATE 0x10
#define PERMISSION_ACCESS_COARSE_LOCATION 0x20
#define PERMISSION_ACCESS_FINE_LOCATION 0x40
#endif //REYUNSDK_COLLECT_H #endif //REYUNSDK_COLLECT_H
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