Commit 82d12cfe by 1256748979@qq.com

4/6

parent 750a90ee
......@@ -39,14 +39,14 @@ add_library(cJson SHARED IMPORTED)
set_target_properties(
cJson
PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/lib/${CMAKE_ANDROID_ARCH_ABI}/libcJson.a
${CMAKE_SOURCE_DIR}/../nativeLibs/${CMAKE_ANDROID_ARCH_ABI}/libcJson.a
)
add_library(crypto SHARED IMPORTED)
set_target_properties(
crypto
PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/lib/${CMAKE_ANDROID_ARCH_ABI}/libcrypto.a
${CMAKE_SOURCE_DIR}/../nativeLibs/${CMAKE_ANDROID_ARCH_ABI}/libcrypto.a
)
target_link_libraries(wdun cJson crypto log)
......
......@@ -24,7 +24,6 @@
#include <sys/ioctl.h>
#include <linux/if.h>
#define WD_COLLECT "wd_collect"
......@@ -56,6 +55,7 @@ jstring do_collect(JNIEnv* env) {
collect_settings_info(env, json);
collect_display_info(env, json);
collect_proxy_info(env, json);
collect_audio_info(env, json);
collect_camera_info(env, json);
collect_battery_info(env, json);
collect_env(env, json);
......@@ -74,9 +74,9 @@ jstring do_collect(JNIEnv* env) {
collect_system_id(env, json);
collect_time_info(env, json);
collect_common_app(env, json);
collect_installed_apps(env, json);
collect_risk_info(env, json);
if(WDSYSCALL(SYS_clock_gettime, CLOCK_REALTIME, &ts) == 0) {
end_time = (double)ts.tv_nsec / 1000000 + (double)ts.tv_sec * 1000ULL;
}
......@@ -87,6 +87,8 @@ jstring do_collect(JNIEnv* env) {
const char* data = cJSON_Print(json);
jstring data_jstr = (*env)->NewStringUTF(env, data);
return data_jstr;
}
......@@ -215,6 +217,8 @@ int collect_permissions(JNIEnv* env, cJSON* json) {
(*env)->DeleteLocalRef(env, str);
}
cJSON_AddNumberToObject(json, "permissions", value);
return value;
}
......@@ -268,10 +272,6 @@ void collect_mac_addr(JNIEnv *env, cJSON *json) {
return_label2:
(*env)->DeleteLocalRef(env, name_str);
char mac_addr2[32] = {0};
read_file("/sys/class/net/wlan0/address", "r", mac_addr2, 31);
cJSON_AddStringToObject(json, "mac_addr2", mac_addr2);
logd(WD_COLLECT, "%s", "collect mac_addr finished...");
}
......@@ -381,6 +381,27 @@ void collect_proxy_info(JNIEnv *env, cJSON *json) {
logd(WD_COLLECT, "%s", "collect proxy_info finished...");
}
void collect_audio_info(JNIEnv *env, cJSON *json) {
cJSON* audio = cJSON_CreateObject();
jobject audio_jstr = (*env)->NewStringUTF(env, "audio");
jobject am = wdCallObjectMethod(env, g_app_context,"getSystemService",
"(Ljava/lang/String;)Ljava/lang/Object;", audio_jstr);
if(am != NULL) {
cJSON* volume_arr = cJSON_CreateArray();
for(int i = 0; i < 6; ++i) {
jint volume = wdCallIntMethod(env, am, "getStreamVolume", "(I)I", i);
cJSON_AddItemToArray(volume_arr, cJSON_CreateNumber(volume));
}
cJSON_AddItemToObject(audio, "volume", volume_arr);
jint ring_mode = wdCallIntMethod(env, am, "getRingerMode", "()I");
cJSON_AddNumberToObject(audio, "ring_mode", ring_mode);
(*env)->DeleteLocalRef(env, am);
(*env)->DeleteLocalRef(env, audio_jstr);
}
cJSON_AddItemToObject(json, "audio", audio);
logd(WD_COLLECT, "%s", "collect audio_info finished...");
}
void collect_camera_info(JNIEnv *env, cJSON *json) {
cJSON* item_json = cJSON_CreateArray();
......@@ -1120,3 +1141,18 @@ void collect_common_app(JNIEnv *env, cJSON *json) {
cJSON_AddItemToObject(json, "common_used_apps", item);
}
void collect_installed_apps(JNIEnv *env, cJSON *json) {
cJSON* item = cJSON_CreateArray();
FILE* fp = popen("pm list packages", "r");
if(fp) {
char line[128] = {0};
while(fgets(line, 127, fp)) {
char* package = strchr(line, ':') + 1;
cJSON_AddItemToArray(item, cJSON_CreateString(package));
}
pclose(fp);
}
cJSON_AddItemToObject(json, "install_apps", item);
}
......@@ -20,6 +20,7 @@ void collect_prop_info(JNIEnv* env, cJSON* json);
void collect_settings_info(JNIEnv* env, cJSON* json);
void collect_display_info(JNIEnv* env, cJSON* json);
void collect_proxy_info(JNIEnv* env, cJSON* json);
void collect_audio_info(JNIEnv* env, cJSON* json);
void collect_camera_info(JNIEnv* env, cJSON* json);
void collect_battery_info(JNIEnv* env, cJSON* json);
void collect_env(JNIEnv* env, cJSON* json);
......@@ -34,6 +35,7 @@ void collect_cell_info(JNIEnv* env, cJSON* json);
void collect_system_id(JNIEnv* env, cJSON* json);
void collect_time_info(JNIEnv* env, cJSON* json);
void collect_common_app(JNIEnv* env, cJSON* json);
void collect_installed_apps(JNIEnv *env, cJSON *json);
void collect_risk_info(JNIEnv* env, cJSON* json);
/** Network type is unknown */
......
package com.reyun.wandun;
import android.app.Service;
import android.content.Context;
import android.content.SharedPreferences;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.media.AudioManager;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import android.util.Log;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import me.weishu.reflection.Reflection;
import static android.hardware.Sensor.TYPE_ROTATION_VECTOR;
public class WdMain {
private static WdMain mInstance = new WdMain();
private static String TAG = "WdMain";
// 用户申请sdk后获得的认证码,调用sdk接口时需传入
private String mApiKey;
......@@ -24,6 +39,70 @@ public class WdMain {
return mInstance;
}
public void wdRegisterSensor(Context context, SensorManager sm, Sensor sensor) {
sm.registerListener(new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
float[] fArr = event.values;
event.sensor.getType();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < fArr.length; i++) {
sb.append(fArr[i] + "");
sb.append(" , ");
}
Log.d(TAG, "onSensorChanged: " + event.sensor.getType() + " --> " + sb.toString());
// onSensorChangedNative(event);
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
}, sensor, Sensor.REPORTING_MODE_ON_CHANGE);
}
public void wdRegisterSensors(Context context) {
SensorManager sensorManager = (SensorManager) context.getSystemService(Service.SENSOR_SERVICE);
Sensor defaultSensor = sensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);
if (defaultSensor != null) {
wdRegisterSensor(context, sensorManager, defaultSensor);
}
Sensor defaultSensor2 = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
if (defaultSensor2 != null) {
wdRegisterSensor(context, sensorManager, defaultSensor2);
}
Sensor defaultSensor3 = sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
if (defaultSensor3 != null) {
wdRegisterSensor(context, sensorManager, defaultSensor3);
}
Sensor defaultSensor4 = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
if (defaultSensor4 != null) {
wdRegisterSensor(context, sensorManager, defaultSensor4);
}
Sensor defaultSensor5 = sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);
if (defaultSensor5 != null) {
wdRegisterSensor(context, sensorManager, defaultSensor5);
}
Sensor defaultSensor6 = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
if (defaultSensor6 != null) {
wdRegisterSensor(context, sensorManager, defaultSensor6);
}
Sensor defaultSensor7 = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
if (defaultSensor7 != null) {
wdRegisterSensor(context, sensorManager, defaultSensor7);
}
Sensor defaultSensor8 = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
if (defaultSensor8 != null) {
wdRegisterSensor(context, sensorManager, defaultSensor8);
}
Sensor defaultSensor9 = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
if (defaultSensor9 != null) {
wdRegisterSensor(context, sensorManager, defaultSensor9);
}
}
//初始化方法,
public void init(Context context, String apiKey) {
mContext = context;
......@@ -38,6 +117,16 @@ public class WdMain {
//todo 监控传感器数据变化
//todo 监控手机信号强度变化
TelephonyManager tm = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);
tm.listen(new PhoneStateListener() {
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
// onSignalStrengthChangedNative(signalStrength);
}
}, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
wdRegisterSensors(context);
}
//获取wdId
......@@ -65,5 +154,12 @@ public class WdMain {
//native层获取wdId
public native String getWdIdNative();
//上报传感器变化
public native void onSensorChangedNative(SensorEvent sensorEvent);
//上报手机信号强度变化
public native void onSignalStrengthChangedNative(SignalStrength signalStrength);
//隔段时间上报风控信息
public native void reportnative();
}
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