Framework学习(三):Android系统属性

Android系统属性

Information about the current build, extracted from system properties.

从系统属性中提取有关当前的构建信息。

系统属性是什么?

​ 属性系统是android的一个重要特性。它作为一个服务运行,管理系统配置和状态。所有这些配置和状态都是属性。每个属性是一个键值对(key/value pair),其类型都是字符串。

​ 从功能上看,属性与windows系统的注册表非常相似。许多android应用程序和库直接或者间接地依赖此特性,以决定它们的运行时行为。例如,adbd进程查询属性服务已确认当前是否运行在模拟器环境中。另一个例子是java.io.File.pathSpearator,其返回存储于属性服务中的值。戳此

  创建与修改android属性用Systemproperties.set(name, value),获取android属性用Systemproperties.get(name),需要注意的是android属性的名称是有一定的格式要求的:

添加系统自定义属性:

PRODUCT_PROPERTY_OVERRIDES += \
    persist.xxxxx.authorize.disabled = false \


# Set lmkd options
PRODUCT_PRODUCT_PROPERTIES += \
    ro.config.xxxxx.disabled = false \

源码使用实例:

/**
 * If is user debug.
 */
public static final boolean IS_USERDEBUG = "userdebug".equals(TYPE);
/**
 * Read only system properties, the default value is false.
 */
public static final boolean IS_RO_CONFIG_FALSE = SystemProperties.getBoolean("ro.config.xxxxx.disabled", false);
/**
 * persist system properties, the default value is false.
 */
public static final boolean IS_PERSIST_CONFIG_FALSE = SystemProperties.getBoolean("persist.xxxxx.authorize.disabled",false);

adb使用实例

adb shell getprop ro.config.xxxxx.disabled
false
adb shell setprop persist.xxxxx.authorize.disabled true
true
posted @ 2022-02-11 16:36  AronJudge  阅读(472)  评论(1编辑  收藏  举报