Commit e714b640 by 1256748979@qq.com

Merge remote-tracking branch 'origin/master'

parents dc159a00 4ce0efb1
......@@ -37,7 +37,6 @@ android {
path file('src/main/cpp/CMakeLists.txt')
}
}
ndkVersion '22.0.7026061'
}
dependencies {
......
......@@ -32,6 +32,7 @@ import android.os.Bundle;
import android.provider.Settings;
import android.provider.Telephony;
import android.telephony.CellInfo;
import android.telephony.CellLocation;
import android.telephony.NeighboringCellInfo;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
......@@ -115,6 +116,7 @@ public class MainActivity extends AppCompatActivity {
TelephonyManager tm = (TelephonyManager) getApplicationContext().getSystemService(Service.TELEPHONY_SERVICE);
List<CellInfo> cellInfos = tm.getAllCellInfo();
CellLocation cl = tm.getCellLocation();
......
......@@ -35,7 +35,6 @@ android {
path file('src/main/cpp/CMakeLists.txt')
}
}
ndkVersion '22.0.7026061'
}
dependencies {
......
......@@ -18,6 +18,7 @@
#include "openssl/md5.h"
#include <arpa/inet.h>
#include <sys/syscall.h>
#include <linux/prctl.h>
#define WD_COLLECT "wd_collect"
......@@ -39,6 +40,7 @@ void do_collect(JNIEnv* env) {
start_time = ts.tv_nsec / 1000000 + ts.tv_sec * 1000ULL;
}
collect_app_info(env, json);
int permissions = collect_permissions(env, json);
collect_imei(env, json);
collect_android_id(env, json);
collect_mac_addr(env, json);
......@@ -56,7 +58,12 @@ void do_collect(JNIEnv* env) {
collect_mem_info(env, json);
collect_network_info(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((permissions & PERMISSION_READ_PHONE_STATE) && (permissions & PERMISSION_ACCESS_COARSE_LOCATION)) {
collect_cell_info(env, json);
}
if(WDSYSCALL(SYS_clock_gettime, CLOCK_MONOTONIC, &ts) == 0) {
end_time = (double)ts.tv_nsec / 1000000 + (double)ts.tv_sec * 1000ULL;
......@@ -127,6 +134,29 @@ void collect_app_info(JNIEnv* env, cJSON *json) {
(*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 |= (1 << i);
}
(*env)->DeleteLocalRef(env, str);
}
return value;
}
void collect_imei(JNIEnv *env, cJSON *json) {
//get imei from telephonymanager
jstring phone_str = (*env)->NewStringUTF(env, "phone");
......@@ -140,6 +170,8 @@ void collect_imei(JNIEnv *env, cJSON *json) {
logd(WD_COLLECT, "%s", "collect imei finished...");
}
void collect_android_id(JNIEnv* env, cJSON* json) {
jstring key_str = (*env)->NewStringUTF(env, "android_id");
jobject cr = wdCallObjectMethod(env, g_app_context, "getContentResolver", "()Landroid/content/ContentResolver;");
......@@ -515,26 +547,12 @@ void collect_user_agent(JNIEnv *env, cJSON *json) {
void collect_location_info(JNIEnv *env, cJSON *json) {
//get location info need ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION permission.
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");
jobject lm = wdCallObjectMethod(env, g_app_context, "getSystemService",
"(Ljava/lang/String;)Ljava/lang/Object;", loc_jstr);
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");
int get_loc = 0;
for(int i = 0; i < size; ++i) {
......@@ -556,15 +574,38 @@ void collect_location_info(JNIEnv *env, cJSON *json) {
if(get_loc) break;
}
(*env)->DeleteLocalRef(env, providers);
return_label2:
return_label:
(*env)->DeleteLocalRef(env, lm);
(*env)->DeleteLocalRef(env, loc_jstr);
return_label:
cJSON_AddItemToObject(json, "location", item);
logd(WD_COLLECT, "%s", "collect location info finished...");
}
void collect_cell_info(JNIEnv *env, cJSON *json) {
//cell info need ACCESSS_COARSE_LOCATION permission
cJSON* item = cJSON_CreateObject();
jstring phone_jstr = (*env)->NewStringUTF(env, "phone");
jobject tm = wdCallObjectMethod(env, g_app_context, "getSystemService",
"(Ljava/lang/String;)Ljava/lang/Object;", phone_jstr);
jobject cl = wdCallObjectMethod(env, tm, "getCellLocation", "()Landroid/telephony/CellLocation;");
if(cl == NULL) goto return_label;
jclass gsm_cls = (*env)->FindClass(env, "android/telephony/gsm/GsmCellLocation");
if((*env)->IsInstanceOf(env, cl, gsm_cls) == JNI_TRUE) {
jint cid = wdCallIntMethod(env, cl, "getCid", "()I");
jint lac = wdCallIntMethod(env, cl, "getLac", "()I");
jint psc = wdCallIntMethod(env, cl, "getPsc", "()I");
cJSON_AddNumberToObject(item, "cid", cid);
cJSON_AddNumberToObject(item, "lac", lac);
cJSON_AddNumberToObject(item, "psc", psc);
}
(*env)->DeleteLocalRef(env, gsm_cls);
return_label:
(*env)->DeleteLocalRef(env, cl);
(*env)->DeleteLocalRef(env, tm);
(*env)->DeleteLocalRef(env, phone_jstr);
cJSON_AddItemToObject(json, "cell", item);
logd(WD_COLLECT, "%s", "collect cell info finished...");
}
......@@ -11,6 +11,7 @@
void do_collect(JNIEnv* env);
cJSON* collect_init();
void collect_app_info(JNIEnv* env, cJSON* json);
int collect_permissions(JNIEnv* env, cJSON* json);
void collect_imei(JNIEnv* env, cJSON* json);
void collect_android_id(JNIEnv* env, cJSON* json);
void collect_mac_addr(JNIEnv* env, cJSON* json);
......@@ -74,5 +75,13 @@ void collect_cell_info(JNIEnv* env, cJSON* json);
/** Current network is NR(New Radio) 5G. */
#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
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