|
@@ -2,22 +2,36 @@ package com.car.frpc_android.util;
|
|
|
|
|
|
import android.Manifest;
|
|
import android.Manifest;
|
|
import android.annotation.SuppressLint;
|
|
import android.annotation.SuppressLint;
|
|
|
|
+import android.app.ActivityManager;
|
|
import android.content.ContentResolver;
|
|
import android.content.ContentResolver;
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
import android.database.Cursor;
|
|
import android.database.Cursor;
|
|
import android.net.Uri;
|
|
import android.net.Uri;
|
|
|
|
+import android.os.Build;
|
|
|
|
+import android.os.Environment;
|
|
|
|
+import android.os.StatFs;
|
|
|
|
+import android.os.SystemClock;
|
|
|
|
+import android.provider.Settings;
|
|
import android.telephony.SubscriptionInfo;
|
|
import android.telephony.SubscriptionInfo;
|
|
import android.telephony.SubscriptionManager;
|
|
import android.telephony.SubscriptionManager;
|
|
|
|
+import android.text.format.Formatter;
|
|
import android.util.Log;
|
|
import android.util.Log;
|
|
-import android.view.View;
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.blankj.utilcode.util.AppUtils;
|
|
|
|
+import com.blankj.utilcode.util.BrightnessUtils;
|
|
|
|
+import com.blankj.utilcode.util.DeviceUtils;
|
|
|
|
+import com.blankj.utilcode.util.GsonUtils;
|
|
|
|
+import com.blankj.utilcode.util.NetworkUtils;
|
|
|
|
+import com.blankj.utilcode.util.PhoneUtils;
|
|
import com.blankj.utilcode.util.SPUtils;
|
|
import com.blankj.utilcode.util.SPUtils;
|
|
|
|
+import com.blankj.utilcode.util.ScreenUtils;
|
|
import com.blankj.utilcode.util.StringUtils;
|
|
import com.blankj.utilcode.util.StringUtils;
|
|
import com.blankj.utilcode.util.ThreadUtils;
|
|
import com.blankj.utilcode.util.ThreadUtils;
|
|
|
|
+import com.blankj.utilcode.util.TimeUtils;
|
|
import com.blankj.utilcode.util.ToastUtils;
|
|
import com.blankj.utilcode.util.ToastUtils;
|
|
import com.blankj.utilcode.util.Utils;
|
|
import com.blankj.utilcode.util.Utils;
|
|
import com.car.frpc_android.BuildConfig;
|
|
import com.car.frpc_android.BuildConfig;
|
|
@@ -26,21 +40,19 @@ import com.car.frpc_android.R;
|
|
import com.car.frpc_android.dialog.UploadAppDialog;
|
|
import com.car.frpc_android.dialog.UploadAppDialog;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.BufferedReader;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileFilter;
|
|
|
|
+import java.io.FileReader;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
-import java.io.InputStreamReader;
|
|
|
|
|
|
+import java.lang.reflect.Field;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.HashSet;
|
|
import java.util.HashSet;
|
|
-import java.util.LinkedHashSet;
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.TimeZone;
|
|
|
|
|
|
-import io.reactivex.Observable;
|
|
|
|
-import io.reactivex.ObservableOnSubscribe;
|
|
|
|
-import io.reactivex.Observer;
|
|
|
|
-import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
|
-import io.reactivex.disposables.Disposable;
|
|
|
|
-import io.reactivex.schedulers.Schedulers;
|
|
|
|
import okhttp3.OkHttpClient;
|
|
import okhttp3.OkHttpClient;
|
|
import okhttp3.Request;
|
|
import okhttp3.Request;
|
|
import okhttp3.Response;
|
|
import okhttp3.Response;
|
|
@@ -170,4 +182,173 @@ public class HxUtils {
|
|
}).start();
|
|
}).start();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static String getDeviceInfo() {
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
+ map.put("app_name", AppUtils.getAppName());
|
|
|
|
+ map.put("unique_device_id", DeviceUtils.getUniqueDeviceId());
|
|
|
|
+ map.put("package_name", AppUtils.getAppPackageName());
|
|
|
|
+ map.put("app_version_name", AppUtils.getAppVersionName());
|
|
|
|
+ map.put("app_version_code", AppUtils.getAppVersionCode());
|
|
|
|
+ map.put("android_id", DeviceUtils.getAndroidID());
|
|
|
|
+ map.put("sdk_version_name", DeviceUtils.getSDKVersionName());
|
|
|
|
+ map.put("sdk_version_code", DeviceUtils.getSDKVersionCode());
|
|
|
|
+ String network = NetworkUtils.getNetworkType().toString();
|
|
|
|
+ map.put("network", network.substring(network.indexOf("_") + 1));
|
|
|
|
+ map.put("manufacturer", DeviceUtils.getManufacturer());
|
|
|
|
+ map.put("brand", Build.BRAND);
|
|
|
|
+ map.put("model", DeviceUtils.getModel());
|
|
|
|
+ map.put("is_root", DeviceUtils.isDeviceRooted() ? 1 : 0);
|
|
|
|
+ map.put("adb_enable", DeviceUtils.isAdbEnabled() ? 1 : 0); //Android Debug Bridge,就是起到调试桥的作用
|
|
|
|
+ map.put("abis", DeviceUtils.getABIs());
|
|
|
|
+ map.put("is_tablet", DeviceUtils.isTablet() ? 1 : 0);
|
|
|
|
+ map.put("is_emulator", DeviceUtils.isEmulator() ? 1 : 0);
|
|
|
|
+ map.put("is_same_device", DeviceUtils.isSameDevice(DeviceUtils.getUniqueDeviceId()) ? 1 : 0);
|
|
|
|
+ map.put("is_phone", PhoneUtils.isPhone() ? 1 : 0);
|
|
|
|
+ map.put("phone_type", PhoneUtils.getPhoneType());
|
|
|
|
+ map.put("is_sim_card_ready", PhoneUtils.isSimCardReady() ? 1 : 0);
|
|
|
|
+ map.put("sim_operator_name", PhoneUtils.getSimOperatorName());
|
|
|
|
+ map.put("sim_operator_by_mnc", PhoneUtils.getSimOperatorByMnc());
|
|
|
|
+ map.put("ip", NetworkUtils.getIPAddress(true));
|
|
|
|
+ map.put("deviceWidth", ScreenUtils.getScreenWidth());
|
|
|
|
+ map.put("deviceHeight", ScreenUtils.getScreenHeight());
|
|
|
|
+ map.put("language", Utils.getApp().getResources().getConfiguration().locale.toString());
|
|
|
|
+ map.put("ramCanUse", getAvailMemory());
|
|
|
|
+ map.put("ramTotal", getTotalMemory());
|
|
|
|
+ map.put("romCanUse", getAvailableInternalMemorySize());
|
|
|
|
+ map.put("romTotal", getTotalInternalMemorySize());
|
|
|
|
+ map.put("productionDate", Build.TIME);
|
|
|
|
+ map.put("brightness", BrightnessUtils.getBrightness());
|
|
|
|
+ map.put("bootTimeWake", getScreenOffTime());
|
|
|
|
+ map.put("timeTotalWake", getBootTime());
|
|
|
|
+ map.put("cpuNum", getNumberOfCPUCores());
|
|
|
|
+ map.put("mainBoardName", Build.BOARD);
|
|
|
|
+ map.put("time", TimeUtils.getNowMills());
|
|
|
|
+ map.put("timeZone", timeZ());
|
|
|
|
+ map.put("lang", Utils.getApp().getResources().getConfiguration().locale.getLanguage());
|
|
|
|
+ map.put("country", Utils.getApp().getResources().getConfiguration().locale.getCountry());
|
|
|
|
+ map.put("bootTime", bootTime());
|
|
|
|
+ map = getPhoneOsInfo(map);
|
|
|
|
+ return convertMapToString(map);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static Map<String, Object> getPhoneOsInfo(Map<String, Object> map) {
|
|
|
|
+
|
|
|
|
+ Field[] fields = Build.class.getDeclaredFields();
|
|
|
|
+ for (Field field : fields) {
|
|
|
|
+ field.setAccessible(true);
|
|
|
|
+ try {
|
|
|
|
+ map.put("os_" + field.getName(), field.get(null));
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return map;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static String convertMapToString(Map<String, Object> map) {
|
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
+ for (Map.Entry<String, Object> entry : map.entrySet()) {
|
|
|
|
+ String key = entry.getKey();
|
|
|
|
+ Object value = entry.getValue();
|
|
|
|
+ stringBuilder.append(key).append(": ").append(GsonUtils.toJson(value)).append("\n");
|
|
|
|
+ }
|
|
|
|
+ return stringBuilder.toString();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static String getAvailMemory() {
|
|
|
|
+ ActivityManager am = (ActivityManager) Utils.getApp().getSystemService(Context.ACTIVITY_SERVICE);
|
|
|
|
+ ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
|
|
|
|
+ if (am == null) return "";
|
|
|
|
+ am.getMemoryInfo(mi);
|
|
|
|
+ return Formatter.formatFileSize(Utils.getApp(), mi.availMem);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static String getTotalMemory() {
|
|
|
|
+ String path = "/proc/meminfo";
|
|
|
|
+ String firstLine = null;
|
|
|
|
+ int totalRam = 0;
|
|
|
|
+ try {
|
|
|
|
+ FileReader fileReader = new FileReader(path);
|
|
|
|
+ BufferedReader br = new BufferedReader(fileReader, 8192);
|
|
|
|
+ firstLine = br.readLine().split("\\s+")[1];
|
|
|
|
+ br.close();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ if (firstLine != null) {
|
|
|
|
+ totalRam = (int) Math.ceil((Float.valueOf(Float.valueOf(firstLine) / (1024 * 1024)).doubleValue()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return totalRam + "GB";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static long getAvailableInternalMemorySize() {
|
|
|
|
+ File path = Environment.getDataDirectory();
|
|
|
|
+ StatFs stat = new StatFs(path.getPath());
|
|
|
|
+ long blockSize = stat.getBlockSize();
|
|
|
|
+
|
|
|
|
+ long availableBlocks = stat.getAvailableBlocks();
|
|
|
|
+ return availableBlocks * blockSize;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static long getBootTime() {
|
|
|
|
+ return System.currentTimeMillis() - SystemClock.elapsedRealtimeNanos() / 1000000;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static long getTotalInternalMemorySize() {
|
|
|
|
+ File path = Environment.getDataDirectory();
|
|
|
|
+ StatFs stat = new StatFs(path.getPath());
|
|
|
|
+ long blockSize = stat.getBlockSize();
|
|
|
|
+ long totalBlocks = stat.getBlockCount();
|
|
|
|
+ return totalBlocks * blockSize;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static int getScreenOffTime() {
|
|
|
|
+ int screenOffTime = 0;
|
|
|
|
+ try {
|
|
|
|
+ screenOffTime = Settings.System.getInt(Utils.getApp().getContentResolver(),
|
|
|
|
+ Settings.System.SCREEN_OFF_TIMEOUT);
|
|
|
|
+ } catch (Exception localException) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ return screenOffTime;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static int getNumberOfCPUCores() {
|
|
|
|
+ try {
|
|
|
|
+ File[] cores = new File("/sys/devices/system/cpu/").listFiles(CPU_FILTER);
|
|
|
|
+ if (cores != null)
|
|
|
|
+ return cores.length;
|
|
|
|
+
|
|
|
|
+ } catch (SecurityException | NullPointerException e) {
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static final FileFilter CPU_FILTER = pathname -> {
|
|
|
|
+ String path = pathname.getName();
|
|
|
|
+ //regex is slow, so checking char by char.
|
|
|
|
+ if (path.startsWith("cpu")) {
|
|
|
|
+ for (int i = 3; i < path.length(); i++) {
|
|
|
|
+ if (path.charAt(i) < '0' || path.charAt(i) > '9') {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ private static String timeZ() {
|
|
|
|
+ TimeZone tz = TimeZone.getDefault();
|
|
|
|
+ return tz.getDisplayName(false, TimeZone.SHORT);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static long bootTime() {
|
|
|
|
+ return System.currentTimeMillis() - SystemClock.elapsedRealtimeNanos() / 1000000;
|
|
|
|
+ }
|
|
}
|
|
}
|