version:2.1 MTK

fix:优化获取设备类型逻辑,优化获取设备版本号
update:打包更新
This commit is contained in:
2022-04-25 18:21:25 +08:00
parent 11bad35331
commit 7a1a4fe5a5
24 changed files with 1118 additions and 212 deletions

View File

@@ -172,11 +172,12 @@ public class Utils {
}
public static String getAndroid10MAC(Context context) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
return getMacAddress(context);
} else {
return getAndroid7MAC();
}
// if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
// return getMacAddress(context);
// } else {
// return getAndroid7MAC();
// }
return getAllMacAddress(context);
}
/**
@@ -284,6 +285,95 @@ public class Utils {
return builder.toString();
}
/**
* 获取MAC地址
*
* @param context
* @return
*/
public static String getAllMacAddress(Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return getMacDefault(context);
} else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
return getMacAddressM();
} else {
return getMacFromHardware();
}
}
/**
* Android 6.0 之前(不包括6.0)
*
* @param context
* @return
*/
private static String getMacDefault(Context context) {
String mac = "未获取到设备Mac地址";
if (context == null) {
return mac;
}
WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo info = null;
try {
info = wifi.getConnectionInfo();
} catch (Exception e) {
e.printStackTrace();
}
if (info == null) {
return mac;
}
mac = info.getMacAddress();
if (!TextUtils.isEmpty(mac)) {
mac = mac.toUpperCase(Locale.ENGLISH);
}
return mac;
}
/**
* Android 6.0(包括) - Android 7.0(不包括)
*
* @return
*/
private static String getMacAddressM() {
String mac = "未获取到设备Mac地址";
try {
mac = new BufferedReader(new FileReader("/sys/class/net/wlan0/address")).readLine();
} catch (IOException e) {
e.printStackTrace();
}
return mac;
}
/**
* 遍历循环所有的网络接口,找到接口是 wlan0
*
* @return
*/
private static String getMacFromHardware() {
try {
List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces());
for (NetworkInterface nif : all) {
if (!nif.getName().equalsIgnoreCase("wlan0")) {
continue;
}
byte[] macBytes = nif.getHardwareAddress();
StringBuilder res1 = new StringBuilder();
for (byte b : macBytes) {
res1.append(String.format("%02X:", b));
}
if (res1 != null) {
res1.deleteCharAt(res1.length() - 1);
}
return res1.toString();
}
} catch (Exception e) {
e.printStackTrace();
}
return "未获取到设备Mac地址";
}
// MD5 设备地址标识
public static String getMD5(Context context) {
@@ -1593,17 +1683,33 @@ public class Utils {
return Formatter.formatFileSize(context, availableSize);
}
/**
* 获取自定义版本号 或者版本号
* @return
*/
public static String getCustomVersion() {
if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.ZhanruiPlatform) {
return Utils.getProperty("ro.build.display.id", "获取失败");
} else if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.CubePlatform) {
return Utils.getProperty("ro.build.display.id", "获取失败");
} else if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.MTKPlatform) {
return Utils.getProperty("ro.build.display.id", "获取失败");
} else {
return Utils.getProperty("ro.custom.build.version", "获取失败");
}
}
/**
* 获取系统版本号
* @return
*/
public static String getRomVersion() {
if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.ZhanruiPlatform) {
return getProperty("ro.build.id", "获取失败");
}else if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.CubePlatform) {
return Utils.getProperty("ro.build.id", "获取失败");
} else if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.MTKPlatform) {
return Utils.getProperty("ro.build.id", "获取失败");
} else {
return getProperty("ro.build.display.id", "获取失败");
}
@@ -1719,6 +1825,69 @@ public class Utils {
}
}
/**
* 当前充电电流 mA
* <p>
* adb shell "cat /sys/class/power_supply/battery/BatteryAverageCurrent"
*/
public static int getCurrentChargingCurrent() {
int result = 0;
BufferedReader br = null;
try {
String line;
br = new BufferedReader(new FileReader("/sys/class/power_supply/battery/BatteryAverageCurrent"));
if ((line = br.readLine()) != null) {
result = Integer.parseInt(line);
}
br.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return result;
}
/**
* 当前充电电压 uV
* <p>
* adb shell "cat /sys/class/power_supply/battery/batt_vol"
*/
public static int getCurrentChargingVoltage() {
int result = 0;
BufferedReader br = null;
try {
String line;
br = new BufferedReader(new FileReader("/sys/class/power_supply/battery/batt_vol"));
if ((line = br.readLine()) != null) {
result = Integer.parseInt(line);
}
br.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return result;
}
}