[dev_arch_opt_3.0]

[Change]
[
1、增加读取getprop,获取设备sn、型号
]

Signed-off-by: donghongyu <donghongyu@zhidaoauto.com>
This commit is contained in:
donghongyu
2023-02-09 13:56:11 +08:00
parent b032c79777
commit 8cb4374cd0
2 changed files with 83 additions and 13 deletions

View File

@@ -16,10 +16,7 @@ import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationGCJ02Lis
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager
import com.mogo.eagle.core.function.call.obu.CallerObuLocationWGS84ListenerManager
import com.mogo.eagle.core.utilcode.mogo.storage.SharedPrefsMgr
import com.mogo.eagle.core.utilcode.util.CoordinateTransform
import com.mogo.eagle.core.utilcode.util.FileUtils
import com.mogo.eagle.core.utilcode.util.TimeUtils
import com.mogo.eagle.core.utilcode.util.Utils
import com.mogo.eagle.core.utilcode.util.*
import com.mogo.support.obu.model.MogoObuHvBasicsData
import mogo.telematics.pad.MessagePad

View File

@@ -17,11 +17,16 @@ import android.os.Build;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.RequiresApi;
import androidx.annotation.RequiresPermission;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
@@ -547,17 +552,85 @@ public final class DeviceUtils {
/**
* 中科创达 EB5获取SN的方法
* getprop persist.device.sn
* ZTS46S10009S
* 获取设备SN的方法
*
* @return 当前EB5设备SN
* @return 通过读取 getprop 的方式
*/
public static String getEB5DevicesSN() {
ShellUtils.CommandResult result = UtilsBridge.execCmd("adb shell getprop persist.device.sn", false);
if (result.result == 0) {
LogUtils.d("", result.toString());
public static String getSerialNumber() {
String serial = "";
try {
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class);
// 获取序列号大多数机器在不root情况下获取不到
serial = (String) get.invoke(c, "ro.serialno");
if (TextUtils.isEmpty(serial)) {
serial = (String) get.invoke(c, "ro.boot.serialno");
}
if (TextUtils.isEmpty(serial)) {
// 分体机 SN
serial = (String) get.invoke(c, "gsm.serial");
}
if (TextUtils.isEmpty(serial)) {
// 中科创达 EB5获取SN
serial = (String) get.invoke(c, "persist.device.sn");
}
if (TextUtils.isEmpty(serial)) {
// 联想PAD 获取SN
serial = (String) get.invoke(c, "ro.odm.lenovo.gsn");
}
} catch (Exception e) {
e.printStackTrace();
}
return "02:00:00:00:00:00";
return serial;
}
/**
* 获取 机器型号
*
* @return 机器型号
*/
public static String getProductModel() {
String productModel = "null";
try {
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class);
// 获取序列号大多数机器在不root情况下获取不到
productModel = (String) get.invoke(c, "ro.product.model");
if (TextUtils.isEmpty(productModel)) {
productModel = (String) get.invoke(c, "ro.product.odm.model");
}
if (TextUtils.isEmpty(productModel)) {
productModel = (String) get.invoke(c, "ro.product.vendor.model");
}
} catch (Exception e) {
e.printStackTrace();
}
return productModel;
}
private static String getSerialnoNumbers() {
final String serialnoStr = "[ro.boot.serialno]";
try {
Process p = Runtime.getRuntime().exec("getprop");
p.waitFor();
BufferedReader stdInput = new BufferedReader(new InputStreamReader(
p.getInputStream()));
String temp = "";
while ((temp = stdInput.readLine()) != null) {
Log.i("getSerialnoNumbers", temp);
if (temp.contains(serialnoStr)) {
temp.replaceAll(" ", "");
int index = temp.indexOf(serialnoStr);
temp = temp.substring(index + 20);
temp = temp.substring(1, temp.length() - 1);
Log.d("getSerialnoNumbers", temp);
return temp;
}
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
return serialnoStr;
}
}