0
点赞
收藏
分享

微信扫一扫

Android adb 设置和获取系统属性

天使魔鬼 2022-04-29 阅读 55
android

/system/build.prop 为系统属性默认值。

安卓系统属性由特殊的property_service管理, /system/build.prop是只读文件,

其中包含property_service在启动期间用于填充其内部内存数据库的默认值。

因此,在运行时对文件的更改不会在重新引导之后传播。

setprop和getprop命令用于访问该数据库中的数据.

除非属性名称以persist开头. 属性值将存储在/data/property/persistent_properties文件中

如果是非 persist 开头,属性仅存在于内存中,重启后属性消失。


设置属性例子 :

adb shell setprop oemapi.log.enable true  // 设置属性到内存中,重启后消失

adb shell getprop persist.oemapi.debug true // 设置属性到 /data/property/persistent_properties 文件中,如果  /system/build.prop 存在同名属性会覆盖为新值

adb shell getprop oemapi.log.enable  // 获取属性值


读取属性的方法,测试安卓版本 API 28

public static StringgetPlatformProperty(String key) {

String platform =null;

    try {

Class classType = Class.forName("android.os.SystemProperties");

        Method getMethod = classType.getDeclaredMethod("get", new Class[]{String.class});

        platform = (String) getMethod.invoke(classType, new Object[]{key});

    }catch (Exception e) {

e.printStackTrace();

    }

return platform;

}

</code>

举报

相关推荐

0 条评论