From 7e05eef02941deb5ccacbeba3d4f58db2ac52178 Mon Sep 17 00:00:00 2001 From: Alexander Koskovich Date: Thu, 12 May 2022 01:06:04 -0700 Subject: [PATCH] dre: init: Set model based on project codename Co-authored-by: dianlujitao Change-Id: I06f9acda3fe77f57a1bc24ee5a802db0ab3b8d60 --- BoardConfig.mk | 3 +++ init/Android.bp | 7 +++++++ init/init_oplus.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 init/init_oplus.cpp diff --git a/BoardConfig.mk b/BoardConfig.mk index c255f1a..7fcb981 100644 --- a/BoardConfig.mk +++ b/BoardConfig.mk @@ -93,6 +93,9 @@ DEVICE_MATRIX_FILE := $(DEVICE_PATH)/compatibility_matrix.xml DEVICE_MANIFEST_FILE := $(DEVICE_PATH)/manifest.xml ODM_MANIFEST_FILES := $(DEVICE_PATH)/manifest_odm.xml +# Init +TARGET_INIT_VENDOR_LIB := //$(DEVICE_PATH):libinit_oplus + # Kernel BOARD_BOOT_HEADER_VERSION := 3 BOARD_KERNEL_BASE := 0x00000000 diff --git a/init/Android.bp b/init/Android.bp index 553f3ed..da48949 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: "fstab.qcom", src: "fstab.qcom", diff --git a/init/init_oplus.cpp b/init/init_oplus.cpp new file mode 100644 index 0000000..09fb8cf --- /dev/null +++ b/init/init_oplus.cpp @@ -0,0 +1,46 @@ +/* + * 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 prj_codename = GetProperty("ro.boot.project_codename", ""); + + if (prj_codename == "dre9") // Unlocked + OverrideProperty("ro.product.product.model", "DE2117"); + else { // T-Mobile (dre8t) or Metro by T-Mobile (dre8m) + OverrideProperty("ro.product.product.model", "DE2118"); + OverrideProperty("ro.product.product.device", "OnePlusN200TMO"); + OverrideProperty("ro.product.product.name", "OnePlusN200TMO"); + } +}