Update persist.sys.usb.config on runtime
persist.sys.usb.config values can't be combined on build-time when
property files are split into each partition.
So we need to apply the same rule of
build/make/tools/post_process_props.py on runtime.
Test: building succeeded and tested on sailfish.
Bug: 37617113
Bug: 37648659
Merged-In: If1e4279f05d74eccf5ce23eef41a466b7d8e3bde
Merged-In: I1e5ad9da360bfb3cb4970e12a76522fd0a5126b8
Change-Id: I78cdffee446d3ae6a89f138faed5f3149e4b507d
(cherry picked from commit 0cf3a07e143c1ed4348d1181e9e1453590eed1b3)
diff --git a/init/property_service.cpp b/init/property_service.cpp
index a44df42..bbe353f 100644
--- a/init/property_service.cpp
+++ b/init/property_service.cpp
@@ -44,10 +44,11 @@
#include <selinux/selinux.h>
#include <selinux/label.h>
-#include <fs_mgr.h>
#include <android-base/file.h>
+#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
+#include <fs_mgr.h>
#include "bootimg.h"
#include "property_service.h"
@@ -574,10 +575,28 @@
}
}
+// persist.sys.usb.config values can't be combined on build-time when property
+// files are split into each partition.
+// So we need to apply the same rule of build/make/tools/post_process_props.py
+// on runtime.
+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", "");
+ if (config.empty()) {
+ property_set("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");
+ property_set("persist.sys.usb.config", config);
+ }
+}
+
void property_load_boot_defaults() {
load_properties_from_file("/default.prop", NULL);
load_properties_from_file("/odm/default.prop", NULL);
load_properties_from_file("/vendor/default.prop", NULL);
+
+ update_sys_usb_config();
}
static void load_override_properties() {