From 8cb4374cd0f020338001f59de8e40281303961ee Mon Sep 17 00:00:00 2001 From: donghongyu Date: Thu, 9 Feb 2023 13:56:11 +0800 Subject: [PATCH] =?UTF-8?q?[dev=5Farch=5Fopt=5F3.0]=20[Change]=20[=201?= =?UTF-8?q?=E3=80=81=E5=A2=9E=E5=8A=A0=E8=AF=BB=E5=8F=96getprop=EF=BC=8C?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E8=AE=BE=E5=A4=87sn=E3=80=81=E5=9E=8B?= =?UTF-8?q?=E5=8F=B7=20]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: donghongyu --- .../location/MoGoLocationDispatcher.kt | 5 +- .../eagle/core/utilcode/util/DeviceUtils.java | 91 +++++++++++++++++-- 2 files changed, 83 insertions(+), 13 deletions(-) diff --git a/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/datacenter/location/MoGoLocationDispatcher.kt b/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/datacenter/location/MoGoLocationDispatcher.kt index 4b5444ccb2..1f8d1db634 100644 --- a/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/datacenter/location/MoGoLocationDispatcher.kt +++ b/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/datacenter/location/MoGoLocationDispatcher.kt @@ -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 diff --git a/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/util/DeviceUtils.java b/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/util/DeviceUtils.java index dcc8153dc9..8cf0c47008 100644 --- a/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/util/DeviceUtils.java +++ b/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/util/DeviceUtils.java @@ -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; } }