[dev_arch_opt_3.0]
[Change] [ 1、关闭一些狂刷的日志 2、增加EB5获取SN的方法,但系统有限制,需要先adb root ;setenforce 0 ,需要等系统厂商修改下 ] Signed-off-by: donghongyu <donghongyu@zhidaoauto.com>
This commit is contained in:
@@ -15,26 +15,26 @@ import java.lang.reflect.Method;
|
||||
public class DevicesUtils {
|
||||
|
||||
private static final String PROPERTIES = "android.os.SystemProperties";
|
||||
private static final String GSM_SERIAL = "gsm.serial";
|
||||
private static final String GSM_SERIAL = "persist.device.sn";
|
||||
private static final String GET = "get";
|
||||
|
||||
public static String getSn(){
|
||||
public static String getSn() {
|
||||
return getSystemProperties(GSM_SERIAL);
|
||||
}
|
||||
|
||||
public static String getSystemProperties(String name ) {
|
||||
public static String getSystemProperties(String name) {
|
||||
String value = "";
|
||||
try {
|
||||
Class< ? > c = Class.forName( PROPERTIES );
|
||||
Method get = c.getMethod( GET, String.class );
|
||||
value = (String) get.invoke( c, name );
|
||||
} catch ( ClassNotFoundException var3 ) {
|
||||
Class<?> c = Class.forName(PROPERTIES);
|
||||
Method get = c.getMethod(GET, String.class);
|
||||
value = (String) get.invoke(c, name);
|
||||
} catch (ClassNotFoundException var3) {
|
||||
var3.printStackTrace();
|
||||
} catch ( NoSuchMethodException var4 ) {
|
||||
} catch (NoSuchMethodException var4) {
|
||||
var4.printStackTrace();
|
||||
} catch ( InvocationTargetException var5 ) {
|
||||
} catch (InvocationTargetException var5) {
|
||||
var5.printStackTrace();
|
||||
} catch ( IllegalAccessException var6 ) {
|
||||
} catch (IllegalAccessException var6) {
|
||||
var6.printStackTrace();
|
||||
}
|
||||
return value;
|
||||
|
||||
@@ -8,7 +8,6 @@ import android.os.Build;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@@ -154,6 +153,10 @@ public class TelephoneUtil {
|
||||
if (TextUtils.isEmpty(serial)) {
|
||||
serial = (String) get.invoke(c, "ro.serialno");
|
||||
}
|
||||
if (TextUtils.isEmpty(serial)) {
|
||||
serial = (String) get.invoke(c, "persist.device.sn");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -554,7 +554,7 @@ public final class DeviceUtils {
|
||||
* @return 当前EB5设备SN
|
||||
*/
|
||||
public static String getEB5DevicesSN() {
|
||||
ShellUtils.CommandResult result = UtilsBridge.execCmd("getprop persist.device.sn", false);
|
||||
ShellUtils.CommandResult result = UtilsBridge.execCmd("adb shell getprop persist.device.sn", false);
|
||||
if (result.result == 0) {
|
||||
LogUtils.d("", result.toString());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.mogo.eagle.core.utilcode.util;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Android API从21后开始,不再直接支持通过SystemProperties.get/set方式来获取/设置系统属性。
|
||||
* 通过反射方式来进行系统属性操作,代码如下:
|
||||
*/
|
||||
public final class SystemPropertiesUtils {
|
||||
private static final String CLASS_NAME = "android.os.SystemProperties";
|
||||
|
||||
public static String getProperty(String key, String defaultValue) {
|
||||
String value = defaultValue;
|
||||
|
||||
try {
|
||||
Class<?> c = Class.forName(CLASS_NAME);
|
||||
Method get = c.getMethod("get", String.class, String.class);
|
||||
value = (String) (get.invoke(c, key, defaultValue));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setProperty(String key, String value) {
|
||||
try {
|
||||
Class<?> c = Class.forName(CLASS_NAME);
|
||||
Method set = c.getMethod("set", String.class, String.class);
|
||||
set.invoke(c, key, value);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user