SystemProperties修改属性流程

设置属性

// frameworks/base/core/java/android/os/SystemProperties.java
	native_set(String key, String def);
	
// frameworks/base/core/jni/android_os_SystemProperties.cpp
	void SystemProperties_set(JNIEnv *env, jobject clazz, jstring keyJ,jstring valJ)
	
	android::base::SetProperty(key, val)
	
	
// system/core/base/properties.cpp
bool SetProperty(const std::string& key, const std::string& value) {
  return (__system_property_set(key.c_str(), value.c_str()) == 0);
}


// bionic/libc/bionic/system_property_set.cpp
SocketWriter writer(&connection);
if (!writer.WriteUint32(PROP_MSG_SETPROP2).WriteString(key).WriteString(value).Send()) {
  errno = connection.GetLastError();
  async_safe_format_log(ANDROID_LOG_WARN, "libc",
						"Unable to set property \"%s\" to \"%s\": write failed; errno=%d (%s)",
						key, value, errno, strerror(errno));
  return -1;
}

// system/core/init/property_service.cp
case PROP_MSG_SETPROP2: {
		...
		uint32_t result = HandlePropertySet(name, value, socket.source_context(), cr, &error);
		...
    break;
}

PropertySet(name, value, error);

获取属性

// bionic/libc/bionic/system_property_api.cpp
__BIONIC_WEAK_FOR_NATIVE_BRIDGE
int __system_property_get(const char* name, char* value) {
  return system_properties.Get(name, value);
}



// bionic/libc/system_properties/system_properties.cpp
int SystemProperties::Get(const char* name, char* value) {
  const prop_info* pi = Find(name);

  if (pi != nullptr) {
    return Read(pi, nullptr, value);
  } else {
    value[0] = 0;
    return 0;
  }
}
posted @   梦过无声  阅读(55)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效
点击右上角即可分享
微信分享提示