From bdcceb25afd63435cd1f2ddda9bab20961fe4a67 Mon Sep 17 00:00:00 2001 From: danielml Date: Thu, 12 May 2022 01:06:04 -0700 Subject: [PATCH] porsche: libinit: Set model based on ro.boot.prjname Change-Id: I06f9acda3fe77f57a1bc24ee5a802db0ab3b8d60 --- BoardConfig.mk | 3 ++ libinit/Android.bp | 20 +++++++++++++ libinit/init_porsche.cpp | 61 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 libinit/Android.bp create mode 100644 libinit/init_porsche.cpp diff --git a/BoardConfig.mk b/BoardConfig.mk index a5ac078..92d166a 100644 --- a/BoardConfig.mk +++ b/BoardConfig.mk @@ -69,6 +69,9 @@ BOARD_INCLUDE_RECOVERY_DTBO := true # GPS LOC_HIDL_VERSION = 4.0 +# Init +TARGET_INIT_VENDOR_LIB := //$(DEVICE_PATH):libinit_porsche + # Kernel BOARD_KERNEL_BASE := 0x00000000 BOARD_KERNEL_CMDLINE := \ diff --git a/libinit/Android.bp b/libinit/Android.bp new file mode 100644 index 0000000..1e085a3 --- /dev/null +++ b/libinit/Android.bp @@ -0,0 +1,20 @@ +// Copyright (C) 2023 Paranoid Android +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +cc_library_static { + name: "libinit_porsche", + recovery_available: true, + shared_libs: ["libbase"], + srcs: ["init_porsche.cpp"], +} diff --git a/libinit/init_porsche.cpp b/libinit/init_porsche.cpp new file mode 100644 index 0000000..f76a314 --- /dev/null +++ b/libinit/init_porsche.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2023 Paranoid Android + * 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 prjname = std::stoi(GetProperty("ro.boot.prjname", "0")); + char* build_desc; + char* build_fingerprint; + char* product_model; + char* product_name; + + switch (prjname) { + case 136882: + product_name = "RMX3312"; + product_model = "RMX3312"; + build_desc = "qssi-user 13 TP1A.220905.001 1673407054945 release-keys"; + build_fingerprint = "realme/RMX3312/RE58B2L1:13/TP1A.220905.001/S.d7a144-1-3cc75:user/release-keys"; + break; + default: + product_name = "RMX3311EEA"; + product_model = "RMX3311"; + build_desc = "qssi-user 13 TP1A.220905.001 1682070307948 release-keys"; + build_fingerprint = "realme/RMX3311EEA/RE58B2L1:13/TP1A.220905.001/S.fe5caa-da01-3c05a:user/release-keys"; + break; + } + + OverrideProperty("ro.product.model", product_model); + OverrideProperty("ro.product.name", product_name); + OverrideProperty("ro.build.fingerprint", build_fingerprint); + OverrideProperty("ro.build.description", build_desc); +}