From 69bcdf185552b2c6d52893ad3ccb0b094402f932 Mon Sep 17 00:00:00 2001 From: LuK1337 Date: Tue, 6 Jul 2021 14:51:11 +0200 Subject: [PATCH] satsuki: read model from lta-label --- init_satsuki/init_satsuki.cpp | 45 +++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/init_satsuki/init_satsuki.cpp b/init_satsuki/init_satsuki.cpp index 49c16ae..61d62b1 100644 --- a/init_satsuki/init_satsuki.cpp +++ b/init_satsuki/init_satsuki.cpp @@ -21,8 +21,10 @@ #include #include +#include #include #include +#include #include #include #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ @@ -34,17 +36,18 @@ #include "util.h" using android::init::import_kernel_cmdline; -using android::init::property_set; -void property_override(char const prop[], char const value[]) +constexpr auto LTALABEL_PATH = "/dev/block/platform/soc.0/f9824900.sdhci/by-name/LTALabel"; + +void property_override(char const prop[], char const value[], bool add = true) { - prop_info *pi; + auto pi = (prop_info *) __system_property_find(prop); - pi = (prop_info*) __system_property_find(prop); - if (pi) + if (pi != nullptr) { __system_property_update(pi, value, strlen(value)); - else + } else if (add) { __system_property_add(prop, strlen(prop), value, strlen(value)); + } } void property_override_dual(char const system_prop[], char const vendor_prop[], char const value[]) @@ -65,25 +68,31 @@ static void import_kernel_nv(const std::string& key, { if (key.empty()) return; + if (std::ifstream file = std::ifstream(LTALABEL_PATH, std::ios::binary)) { + std::string str((std::istreambuf_iterator(file)), std::istreambuf_iterator()); + size_t offset = str.find("Model: "); + + if (offset != std::string::npos) { + std::string model = str.substr(offset + strlen("Model: "), 5); + property_override("ro.semc.product.model", model.c_str()); + property_override_triple("ro.product.model", "ro.product.system.model", "ro.product.vendor.model", model.c_str()); + property_override_triple("ro.product.name", "ro.product.system.name", "ro.product.vendor.name", model.c_str()); + } + } + if (key == "oemandroidboot.phoneid") { // Dual Sim variant contains two IMEIs separated by comma. if ((count(value.begin(), value.end(),',')) > 0) { - property_set("persist.multisim.config", "dsds"); - property_set("persist.radio.multisim.config", "dsds"); - property_set("ro.telephony.default_network", "9,1"); - property_set("ro.semc.product.model", "E6883"); - property_set("ro.semc.product.name", "Xperia Z5 Premium Dual"); - property_override_triple("ro.product.model", "ro.product.system.model", "ro.product.vendor.model", "E6883"); - property_override_dual("ro.product.name", "ro.vendor.product.name", "satsuki_dsds"); + property_override("persist.multisim.config", "dsds"); + property_override("persist.radio.multisim.config", "dsds"); + property_override("ro.telephony.default_network", "9,1"); + property_override("ro.semc.product.name", "Xperia Z5 Premium Dual"); property_override_triple("ro.product.device", "ro.product.system.device", "ro.product.vendor.device", "satsuki_dsds"); property_override("ro.build.description", "E6883-user 7.1.1 32.4.A.1.54 3761073091 release-keys"); property_override_triple("ro.build.fingerprint", "ro.system.build.fingerprint", "ro.vendor.build.fingerprint", "Sony/E6883/E6883:7.1.1/32.4.A.1.54/3761073091:user/release-keys"); } else { - property_set("ro.telephony.default_network", "9"); - property_set("ro.semc.product.model", "E6853"); - property_set("ro.semc.product.name", "Xperia Z5 Premium"); - property_override_triple("ro.product.model", "ro.product.system.model", "ro.product.vendor.model", "E6853"); - property_override_dual("ro.product.name", "ro.vendor.product.name", "satsuki"); + property_override("ro.telephony.default_network", "9"); + property_override("ro.semc.product.name", "Xperia Z5 Premium"); property_override_triple("ro.product.device", "ro.product.system.device", "ro.product.vendor.device", "satsuki"); property_override("ro.build.description", "E6853-user 7.1.1 32.4.A.1.54 3761073091 release-keys"); property_override_triple("ro.build.fingerprint", "ro.system.build.fingerprint", "ro.vendor.build.fingerprint", "Sony/E6853/E6853:7.1.1/32.4.A.1.54/3761073091:user/release-keys");