version:4.3

fix:安装应用时不清除桌面缓存,锁定状态改变时不恢复出厂设置
update:在获取sn没有刷写的状态时,获取IMEI作为别名
This commit is contained in:
2022-04-19 09:24:45 +08:00
parent 2339e1484d
commit 69a8934bd4
24 changed files with 514 additions and 263 deletions

View File

@@ -56,6 +56,7 @@ import com.aoleyun.sn.comm.CommonConfig;
import com.aoleyun.sn.network.NetInterfaceManager;
import com.arialyy.aria.core.Aria;
import com.blankj.utilcode.util.FileUtils;
import com.google.gson.JsonObject;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
@@ -73,6 +74,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.Reader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.Inet4Address;
import java.net.InetAddress;
@@ -688,12 +690,41 @@ public class Utils {
return t1;
}
public static String NOSN = "012345679ABCDEF";
/**
* 获取设备序列号
*
* @return
*/
@SuppressLint("MissingPermission")
@SuppressLint({"MissingPermission", "HardwareIds"})
public static String getSerial(Context context) {
String serial = "unknow";
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {//9.0+
serial = Build.getSerial();
} else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N) {//8.0+
serial = Build.SERIAL;
} else {//8.0-
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class);
serial = (String) get.invoke(c, "ro.serialno");
}
} catch (Exception e) {
e.printStackTrace();
Log.e("getSerial", "读取设备序列号异常:" + e.toString());
}
if (BuildConfig.DEBUG) {
// return "QNG2DKB00463";
// serial = "012345679ABCDEF";
}
if (NOSN.equalsIgnoreCase(serial)) {
return getIMEI(context);
}
return serial;
}
@SuppressLint({"MissingPermission", "HardwareIds"})
public static String getSerial() {
String serial = "unknow";
try {
@@ -928,7 +959,7 @@ public class Utils {
}
}
/**
/**
* 更新应用白名单禁止升级
*
* @param context
@@ -1163,7 +1194,7 @@ public class Utils {
try {
interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
for (NetworkInterface networkInterface : interfaces) {
if (networkInterface != null && TextUtils.isEmpty(networkInterface.getName()) == false) {
if (networkInterface != null && !TextUtils.isEmpty(networkInterface.getName())) {
if ("wlan0".equalsIgnoreCase(networkInterface.getName())) {
byte[] macBytes = networkInterface.getHardwareAddress();
if (macBytes != null && macBytes.length > 0) {
@@ -1185,16 +1216,25 @@ public class Utils {
return "unknown";
}
@SuppressLint("HardwareIds")
public static String getIMEI(Context context, int slotIndex) {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
return tm.getImei(slotIndex);
} else {
return tm.getDeviceId(slotIndex);
}
}
@SuppressLint("HardwareIds")
public static String getIMEI(Context context) {
String IMEI = "unknow";
String IMEI1, IMEI2, IMEI3;
//获取手机设备号
TelephonyManager TelephonyMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
//8.0及以后版本获取
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
IMEI = TelephonyMgr.getDeviceId();
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// try {
// Method method = TelephonyMgr.getClass().getMethod("getImei");
// IMEI = (String) method.invoke(TelephonyMgr);
@@ -1205,7 +1245,7 @@ public class Utils {
// IMEI = TelephonyMgr.getDeviceId();
// } else {//9.0到10.0获取
IMEI = Settings.System.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
// IMEI = Settings.System.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
}
Log.e("IMEI:", "IMEI: " + IMEI);
if (null == IMEI) {
@@ -1213,9 +1253,40 @@ public class Utils {
} else {
return IMEI.toUpperCase();
}
}
/**
* IMEI 1号
*
* @param context
* @return
*/
// public static String getIMEI_1(Context context) {
// TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
// return tm != null ? tm.getDeviceId() : "";
// }
/**
* IMEI 2号
*
* @param context
* @return
*/
// public static String getIMEI_2(Context context) {
// TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
// Class clazz = tm.getClass();
// try {
// Method getImei = clazz.getDeclaredMethod("getImei", int.class);
// return getImei.invoke(tm, 1).toString();
// } catch (NoSuchMethodException e) {
// e.printStackTrace();
// } catch (InvocationTargetException e) {
// e.printStackTrace();
// } catch (IllegalAccessException e) {
// e.printStackTrace();
// }
// return "";
// }
public static String getMachine(Context context) {
String device = Build.MODEL;//机型
String imei = getIMEI(context);
@@ -1259,6 +1330,21 @@ public class Utils {
return jsonString;
}
public static String getAddressJsonString(Context context) {
String address = String.valueOf(SPUtils.get(context, "AmapAddress", "-"));
if ("-".equals(address)) {
address = "定位失败";
}
String longitude = String.valueOf(SPUtils.get(context, "longitude", "0"));
String latitude = String.valueOf(SPUtils.get(context, "latitude", "0"));
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("address", address);
jsonObject.addProperty("longitude", longitude);
jsonObject.addProperty("latitude", latitude);
String jsonString = jsonObject.toString();
return jsonString;
}
private static int getNumCores() {
// Private Class to display only CPU devices in the directory listing
class CpuFilter implements FileFilter {