From ad25fd64270b2c3dc9fbce5e97c2eb75d63f015b Mon Sep 17 00:00:00 2001 From: Pierre-Hugues Husson Date: Thu, 19 Jan 2023 16:44:01 -0500 Subject: [PATCH 2/2] Rework property overriding - Support property read with callback in addition to previous constant-size property_get - Add another class of redirect "keymaster", to redirect to AOSP/GSI props + SPL based on boot.img --- libc/system_properties/system_properties.cpp | 77 +++++++++++++++----- 1 file changed, 58 insertions(+), 19 deletions(-) diff --git a/libc/system_properties/system_properties.cpp b/libc/system_properties/system_properties.cpp index d6e7e3e68..40ff48bad 100644 --- a/libc/system_properties/system_properties.cpp +++ b/libc/system_properties/system_properties.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -60,23 +61,70 @@ static void read_self() { if(self_ok) return; self_ok = true; - int fd = open("/proc/self/comm", O_RDONLY); + char cmdline[128]; + int fd = open("/proc/self/cmdline", O_RDONLY); if(fd<0) return; - read(fd, comm, sizeof(comm)-1); - for(unsigned i=0; iGetPropAreaForName(name); + prop_area* pa = contexts_->GetPropAreaForName(newName); if (!pa) { async_safe_format_log(ANDROID_LOG_WARN, "libc", "Access denied finding property \"%s\"", name); return nullptr; } - return pa->find(name); + return pa->find(newName); } static bool is_read_only(const char* name) { @@ -243,17 +293,6 @@ void SystemProperties::ReadCallback(const prop_info* pi, } int SystemProperties::Get(const char* name, char* value) { - read_self(); - if(strcmp(comm_override, "vendor") == 0) { - if(strcmp(name, "ro.product.device") == 0) { - int r = Get("ro.product.vendor.device", value); - if(r>0) return r; - } - if(strcmp(name, "ro.product.manufacturer") == 0) { - int r = Get("ro.product.vendor.manufacturer", value); - if(r>0) return r; - } - } const prop_info* pi = Find(name); if (pi != nullptr) { -- 2.34.1