重启Android后SystemProperties属性变化
- 1、SystemProperties属性加载
- 2、PropertySet条件限制
- 3、SystemProperties属性变化
android12-release
1、SystemProperties属性加载
查看 SystemProperties属性加载 属性映射区域LoadPath("/dev/__properties__/property_info")
;在PropertyLoadBootDefaults()
加载如下配置文件等属性,最终设置PropertySet()
- /system/build.prop
/system_ext/
etc/build.prop
/system_ext/
default.prop
/system_ext/
build.prop- /vendor/default.prop
- /vendor/build.prop
- /vendor_dlkm/etc/build.prop
- /odm_dlkm/etc/build.prop
/odm/
etc/build.prop
/odm/
default.prop
/odm/
build.prop/product/
etc/build.prop
/product/
default.prop
/product/
build.prop
2、PropertySet条件限制
查看 SystemProperties属性加载 条件限制IsLegalPropertyName
、IsLegalPropertyValue()
static uint32_t PropertySet(const std::string& name, const std::string& value, std::string* error) {size_t valuelen = value.size();if (!IsLegalPropertyName(name)) {*error = "Illegal property name";return PROP_ERROR_INVALID_NAME;}if (auto result = IsLegalPropertyValue(name, value); !result.ok()) {*error = result.error().message();return PROP_ERROR_INVALID_VALUE;}prop_info* pi = (prop_info*) __system_property_find(name.c_str());if (pi != nullptr) {// ro.* properties are actually "write-once".if (StartsWith(name, "ro.")) {*error = "Read-only property was already set";return PROP_ERROR_READ_ONLY_PROPERTY;}__system_property_update(pi, value.c_str(), valuelen);} else {int rc = __system_property_add(name.c_str(), name.size(), value.c_str(), valuelen);if (rc < 0) {*error = "__system_property_add failed";return PROP_ERROR_SET_FAILED;}}// Don't write properties to disk until after we have read all default// properties to prevent them from being overwritten by default values.if (persistent_properties_loaded && StartsWith(name, "persist.")) {WritePersistentProperty(name, value);}// If init hasn't started its main loop, then it won't be handling property changed messages// anyway, so there's no need to try to send them.auto lock = std::lock_guard{accept_messages_lock};if (accept_messages) {PropertyChanged(name, value);}return PROP_SUCCESS;
}
3、SystemProperties属性变化
PropertySet条件限制
关注"ro."
、"persist."
开头属性:
"ro."
属性实际上是“一次写入”,只能设置一次"persist."
在我们读取所有默认属性之前,不要将persist
开头属性写入磁盘,以防止它们被默认值覆盖。,所以只有persist
开头的系统属性在重启后保持不变persistent_properties_loaded
表示StartPropertyService(&property_fd)
服务启动完成,即ro.persistent_properties.ready=true
。PropertyService在PropertyInit()
之后启动。WritePersistentProperty(name, value)
其中persist
开头属性位置std::string persistent_property_filename = "/data/property/persistent_properties"
system/core/init/persistent_properties.cpp