From ac39cb00a04c571699df695ce0d144d8cb386f35 Mon Sep 17 00:00:00 2001 From: Pierre-Hugues Husson Date: Sat, 19 Feb 2022 08:20:25 -0500 Subject: [PATCH] Add new mechanism to fake vendor props on a per-process basis This reads debug.phh.props.. If its value is "vendor", then ro.product.device/ro.product.manufacturer is read from vendor --- libc/system_properties/system_properties.cpp | 87 +++++++++++++++++++- 1 file changed, 85 insertions(+), 2 deletions(-) diff --git a/libc/system_properties/system_properties.cpp b/libc/system_properties/system_properties.cpp index 9dd5e35ce..886bef127 100644 --- a/libc/system_properties/system_properties.cpp +++ b/libc/system_properties/system_properties.cpp @@ -36,6 +36,8 @@ #include #include #include +#include +#include #include @@ -53,6 +55,85 @@ #define SERIAL_VALUE_LEN(serial) ((serial) >> 24) #define APPCOMPAT_PREFIX "ro.appcompat_override." +static char comm[128]; +static bool self_ok = false; +static char comm_override[PROP_VALUE_MAX]; + +static void read_self() { + //NB: Not atomic, but should be good enough, there is no possible corruption from concurrency + if(self_ok) return; + self_ok = true; + + char cmdline[128]; + int fd = open("/proc/self/cmdline", O_RDONLY); + if(fd<0) return; + read(fd, cmdline, sizeof(cmdline)-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_appcompat_override(const char* name) { -- 2.34.1