From fcbf34d741d16ff625963d546a4313e7865af955 Mon Sep 17 00:00:00 2001 From: Alexander Koskovich Date: Thu, 12 May 2022 01:06:04 -0700 Subject: [PATCH] sm8250-common: init: Set model based on RF version Co-authored-by: dianlujitao Change-Id: I06f9acda3fe77f57a1bc24ee5a802db0ab3b8d60 --- BoardConfigCommon.mk | 3 ++ init/Android.bp | 7 ++++ init/init_oplus.cpp | 88 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 init/init_oplus.cpp diff --git a/BoardConfigCommon.mk b/BoardConfigCommon.mk index 6d24e72..cf9f6e9 100644 --- a/BoardConfigCommon.mk +++ b/BoardConfigCommon.mk @@ -102,6 +102,9 @@ DEVICE_FRAMEWORK_COMPATIBILITY_MATRIX_FILE := \ DEVICE_MATRIX_FILE := $(COMMON_PATH)/compatibility_matrix.xml DEVICE_MANIFEST_FILE := $(COMMON_PATH)/manifest.xml +# Init +TARGET_INIT_VENDOR_LIB := //$(COMMON_PATH):libinit_oplus + # Kernel BOARD_BOOT_HEADER_VERSION := 2 BOARD_KERNEL_BASE := 0x00000000 diff --git a/init/Android.bp b/init/Android.bp index ed69f41..ab0d50f 100644 --- a/init/Android.bp +++ b/init/Android.bp @@ -3,6 +3,13 @@ // SPDX-License-Identifier: Apache-2.0 // +cc_library_static { + name: "libinit_oplus", + recovery_available: true, + shared_libs: ["libbase"], + srcs: ["init_oplus.cpp"], +} + prebuilt_etc { name: "init.qcom.rc", src: "init.qcom.rc", diff --git a/init/init_oplus.cpp b/init/init_oplus.cpp new file mode 100644 index 0000000..43a2f7c --- /dev/null +++ b/init/init_oplus.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2022 The LineageOS Project + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ +#include + +using android::base::GetProperty; + +/* + * SetProperty does not allow updating read only properties and as a result + * does not work for our use case. Write "OverrideProperty" to do practically + * the same thing as "SetProperty" without this restriction. + */ +void OverrideProperty(const char* name, const char* value) { + size_t valuelen = strlen(value); + + prop_info* pi = (prop_info*)__system_property_find(name); + if (pi != nullptr) { + __system_property_update(pi, value, valuelen); + } else { + __system_property_add(name, strlen(name), value, valuelen); + } +} + +/* + * Only for read-only properties. Properties that can be wrote to more + * than once should be set in a typical init script (e.g. init.oplus.hw.rc) + * after the original property has been set. + */ +void vendor_load_properties() { + auto device = GetProperty("ro.product.product.device", ""); + auto rf_version = std::stoi(GetProperty("ro.boot.rf_version", "0")); + + switch (rf_version) { + case 11: // CN + if (device == "OnePlus8") { + OverrideProperty("ro.product.product.model", "IN2010"); + } else if (device == "OnePlus8T") { + OverrideProperty("ro.product.product.model", "KB2000"); + } else if (device == "OnePlus8Pro") { + OverrideProperty("ro.product.product.model", "IN2020"); + } + break; + case 12: // TMO + if (device == "OnePlus8") { + OverrideProperty("ro.product.product.model", "IN2017"); + } else if (device == "OnePlus8T") { + OverrideProperty("ro.product.product.model", "KB2007"); + } else if (device == "OnePlus8Pro") { + OverrideProperty("ro.product.product.model", "IN2027"); + } + break; + case 13: // IN + if (device == "OnePlus8") { + OverrideProperty("ro.product.product.model", "IN2011"); + } else if (device == "OnePlus8T") { + OverrideProperty("ro.product.product.model", "KB2001"); + } else if (device == "OnePlus8Pro") { + OverrideProperty("ro.product.product.model", "IN2021"); + } + break; + case 14: // EU + if (device == "OnePlus8") { + OverrideProperty("ro.product.product.model", "IN2013"); + } else if (device == "OnePlus8T") { + OverrideProperty("ro.product.product.model", "KB2003"); + } else if (device == "OnePlus8Pro") { + OverrideProperty("ro.product.product.model", "IN2023"); + } + break; + case 15: // NA + if (device == "OnePlus8") { + OverrideProperty("ro.product.product.model", "IN2015"); + } else if (device == "OnePlus8T") { + OverrideProperty("ro.product.product.model", "KB2005"); + } else if (device == "OnePlus8Pro") { + OverrideProperty("ro.product.product.model", "IN2025"); + } + break; + default: + LOG(ERROR) << "Unexpected RF version: " << rf_version; + } +}