欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 旅游 > Android12 persist.sys.usb.config值更新

Android12 persist.sys.usb.config值更新

2024/10/24 2:00:37 来源:https://blog.csdn.net/wxd_csdn_2016/article/details/140402576  浏览:    关键词:Android12 persist.sys.usb.config值更新
adb的相关控制

在android 4.0 之后,adb 的控制统一使用了persist.sys.usb.config来控制,而这个persist.sys.usb.config 中的adb是根据ro.debuggable = 1 or 0 来设置,1 就是开启adb, 0 即关闭adb debug.
有两个地方影响

  • build/tools/post_process_props.py
def mangle_build_prop(prop_list):# If ro.debuggable is 1, then enable adb on USB by default# (this is for userdebug builds)if prop_list.get_value("ro.debuggable") == "1":val = prop_list.get_value("persist.sys.usb.config")if "adb" not in val:if val == "":val = "adb"else:val = val + ",adb"prop_list.put("persist.sys.usb.config", val)# UsbDeviceManager expects a value here.  If it doesn't get it, it will# default to "adb". That might not the right policy there, but it's better# to be explicit.if not prop_list.get_value("persist.sys.usb.config"):prop_list.put("persist.sys.usb.config", "none")

在system.prop中添加的会被post_process_props.py中的覆盖,build.prop中有显示

# Value overridden by post_process_props.py. Original value: mtp
persist.sys.usb.config=mtp,adb
  • system/core/init/property_service.cpp
static void update_sys_usb_config() {bool is_debuggable = android::base::GetBoolProperty("ro.debuggable", false);std::string config = android::base::GetProperty("persist.sys.usb.config", "");// b/150130503, add (config == "none") condition here to prevent appending// ",adb" if "none" is explicitly defined in default prop.if (config.empty() || config == "none") {InitPropertySet("persist.sys.usb.config", is_debuggable ? "adb" : "none");} else if (is_debuggable && config.find("adb") == std::string::npos &&config.length() + 4 < PROP_VALUE_MAX) {config.append(",adb");InitPropertySet("persist.sys.usb.config", config);}
}...void PropertyLoadBootDefaults() {...// Order matters here. The more the partition is specific to a product, the higher its// precedence is.LoadPropertiesFromSecondStageRes(&properties);load_properties_from_file("/system/build.prop", nullptr, &properties);load_properties_from_partition("system_ext", /* support_legacy_path_until */ 30);// TODO(b/117892318): uncomment the following condition when vendor.imgs for aosp_* targets are// all updated.// if (SelinuxGetVendorAndroidVersion() <= __ANDROID_API_R__) {load_properties_from_file("/vendor/default.prop", nullptr, &properties);// }load_properties_from_file("/vendor/build.prop", nullptr, &properties);load_properties_from_file("/vendor_dlkm/etc/build.prop", nullptr, &properties);load_properties_from_file("/odm_dlkm/etc/build.prop", nullptr, &properties);load_properties_from_partition("odm", /* support_legacy_path_until */ 28);load_properties_from_partition("product", /* support_legacy_path_until */ 30);if (access(kDebugRamdiskProp, R_OK) == 0) {LOG(INFO) << "Loading " << kDebugRamdiskProp;load_properties_from_file(kDebugRamdiskProp, nullptr, &properties);}for (const auto& [name, value] : properties) {std::string error;if (PropertySet(name, value, &error) != PROP_SUCCESS) {LOG(ERROR) << "Could not set '" << name << "' to '" << value<< "' while loading .prop files" << error;}}property_initialize_ro_product_props();property_initialize_build_id();property_derive_build_fingerprint();property_derive_legacy_build_fingerprint();property_initialize_ro_cpu_abilist();// 获取完所有默认属性值,再次更新update_sys_usb_config();
}

post_process_props.py中的值编译完是在/system/build.prop,所以也可能会在property_service.cpp中被修改。

保存persist.sys.usb.config属性值

update_sys_usb_config中更新属性值–>InitPropertySe()–>HandlePropertySet()–>PropertySet(),在PropertySet方法中将属性值写入磁盘中。

  • system/core/init/property_service.cpp
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;}
#ifdef MTK_LOGSnapshotPropertyFlowTraceLog("_spf");
#endifprop_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;}#ifdef MTK_LOGSnapshotPropertyFlowTraceLog("_spu");
#endif__system_property_update(pi, value.c_str(), valuelen);} else {
#ifdef MTK_LOGSnapshotPropertyFlowTraceLog("_spa");
#endifint 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) {
#ifdef MTK_LOGSnapshotPropertyFlowTraceLog("SPC");
#endif// 通知属性值变化PropertyChanged(name, value);}#ifdef MTK_LOGif (GetMTKLOGDISABLERATELIMIT()) // MTK add logPropSetLog(name, value, error);
#endifreturn PROP_SUCCESS;
}
属性值更新
  • system/core/init/init.cpp
void PropertyChanged(const std::string& name, const std::string& value) {
#ifdef G1122717if (!ActionManager::GetInstance().WatchingPropertyCount(name))return;
#endif// If the property is sys.powerctl, we bypass the event queue and immediately handle it.// This is to ensure that init will always and immediately shutdown/reboot, regardless of// if there are other pending events to process or if init is waiting on an exec service or// waiting on a property.// In non-thermal-shutdown case, 'shutdown' trigger will be fired to let device specific// commands to be executed.if (name == "sys.powerctl") {trigger_shutdown(value);}if (property_triggers_enabled) {ActionManager::GetInstance().QueuePropertyChange(name, value);WakeMainInitThread();}prop_waiter_state.CheckAndResetWait(name, value);
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com