diff --git a/BoardConfigCommon.mk b/BoardConfigCommon.mk index b8c65ac..46f9fca 100644 --- a/BoardConfigCommon.mk +++ b/BoardConfigCommon.mk @@ -29,3 +29,7 @@ TARGET_NO_BOOTLOADER := true DEVICE_FRAMEWORK_COMPATIBILITY_MATRIX_FILE := $(COMMON_PATH)/device_framework_matrix.xml DEVICE_MATRIX_FILE := $(COMMON_PATH)/compatibility_matrix.xml DEVICE_MANIFEST_FILE := $(COMMON_PATH)/manifest.xml + +# Init +TARGET_INIT_VENDOR_LIB ?= //$(COMMON_PATH):init_xiaomi_atoll +TARGET_RECOVERY_DEVICE_MODULES ?= init_xiaomi_atoll diff --git a/libinit/Android.bp b/libinit/Android.bp new file mode 100644 index 0000000..3585b5b --- /dev/null +++ b/libinit/Android.bp @@ -0,0 +1,25 @@ +// +// Copyright (C) 2021 The LineageOS Project +// +// SPDX-License-Identifier: Apache-2.0 +// + +cc_library_static { + name: "libinit_xiaomi_atoll", + srcs: [ + "libinit_dalvik_heap.cpp", + "libinit_variant.cpp", + "libinit_utils.cpp", + ], + whole_static_libs: ["libbase"], + export_include_dirs: ["include"], + recovery_available: true, +} + +cc_library_static { + name: "init_xiaomi_atoll", + srcs: ["init_xiaomi_atoll.cpp"], + whole_static_libs: ["libinit_xiaomi_atoll"], + include_dirs: ["system/core/init"], + recovery_available: true, +} diff --git a/libinit/include/libinit_dalvik_heap.h b/libinit/include/libinit_dalvik_heap.h new file mode 100644 index 0000000..75144b2 --- /dev/null +++ b/libinit/include/libinit_dalvik_heap.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2021 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef LIBINIT_DALVIK_HEAP_H +#define LIBINIT_DALVIK_HEAP_H + +#include + +typedef struct dalvik_heap_info { + std::string heapstartsize; + std::string heapgrowthlimit; + std::string heapsize; + std::string heapminfree; + std::string heapmaxfree; + std::string heaptargetutilization; +} dalvik_heap_info_t; + +void set_dalvik_heap(void); + +#endif // LIBINIT_DALVIK_HEAP_H diff --git a/libinit/include/libinit_utils.h b/libinit/include/libinit_utils.h new file mode 100644 index 0000000..ac2d673 --- /dev/null +++ b/libinit/include/libinit_utils.h @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2021 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef LIBINIT_UTILS_H +#define LIBINIT_UTILS_H + +#include + +void property_override(std::string prop, std::string value, bool add = true); + +void set_ro_build_prop(const std::string &prop, const std::string &value, bool product = false); + +#endif // LIBINIT_UTILS_H diff --git a/libinit/include/libinit_variant.h b/libinit/include/libinit_variant.h new file mode 100644 index 0000000..1607c4a --- /dev/null +++ b/libinit/include/libinit_variant.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2021 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef LIBINIT_VARIANT_H +#define LIBINIT_VARIANT_H + +#include +#include + +typedef struct variant_info { + std::string hwc_value; + + std::string brand; + std::string device; + std::string model; + std::string build_description; + std::string build_fingerprint; + + bool nfc; +} variant_info_t; + +void search_variant(const std::vector variants); + +void set_variant_props(const variant_info_t variant); + +#endif // LIBINIT_VARIANT_H diff --git a/libinit/init_xiaomi_atoll.cpp b/libinit/init_xiaomi_atoll.cpp new file mode 100644 index 0000000..623cd71 --- /dev/null +++ b/libinit/init_xiaomi_atoll.cpp @@ -0,0 +1,13 @@ +/* + * Copyright (C) 2021 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include "vendor_init.h" + +void vendor_load_properties() { + set_dalvik_heap(); +} diff --git a/libinit/libinit_dalvik_heap.cpp b/libinit/libinit_dalvik_heap.cpp new file mode 100644 index 0000000..ba5992e --- /dev/null +++ b/libinit/libinit_dalvik_heap.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2021 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include + +#define HEAPSTARTSIZE_PROP "dalvik.vm.heapstartsize" +#define HEAPGROWTHLIMIT_PROP "dalvik.vm.heapgrowthlimit" +#define HEAPSIZE_PROP "dalvik.vm.heapsize" +#define HEAPMINFREE_PROP "dalvik.vm.heapminfree" +#define HEAPMAXFREE_PROP "dalvik.vm.heapmaxfree" +#define HEAPTARGETUTILIZATION_PROP "dalvik.vm.heaptargetutilization" + +#define GB(b) (b * 1024ull * 1024 * 1024) + +static const dalvik_heap_info_t dalvik_heap_info_6144 = { + .heapstartsize = "16m", + .heapgrowthlimit = "256m", + .heapsize = "512m", + .heapminfree = "8m", + .heapmaxfree = "32m", + .heaptargetutilization = "0.5", +}; + +static const dalvik_heap_info_t dalvik_heap_info_4096 = { + .heapstartsize = "8m", + .heapgrowthlimit = "256m", + .heapsize = "512m", + .heapminfree = "8m", + .heapmaxfree = "16m", + .heaptargetutilization = "0.6", +}; + +static const dalvik_heap_info_t dalvik_heap_info_2048 = { + .heapstartsize = "8m", + .heapgrowthlimit = "192m", + .heapsize = "512m", + .heapminfree = "512k", + .heapmaxfree = "8m", + .heaptargetutilization = "0.75", +}; + +void set_dalvik_heap() { + struct sysinfo sys; + const dalvik_heap_info_t *dhi; + + sysinfo(&sys); + + if (sys.totalram > GB(5)) + dhi = &dalvik_heap_info_6144; + else if (sys.totalram > GB(3)) + dhi = &dalvik_heap_info_4096; + else + dhi = &dalvik_heap_info_2048; + + property_override(HEAPSTARTSIZE_PROP, dhi->heapstartsize); + property_override(HEAPGROWTHLIMIT_PROP, dhi->heapgrowthlimit); + property_override(HEAPSIZE_PROP, dhi->heapsize); + property_override(HEAPTARGETUTILIZATION_PROP, dhi->heaptargetutilization); + property_override(HEAPMINFREE_PROP, dhi->heapminfree); + property_override(HEAPMAXFREE_PROP, dhi->heapmaxfree); +} diff --git a/libinit/libinit_utils.cpp b/libinit/libinit_utils.cpp new file mode 100644 index 0000000..b2e3aad --- /dev/null +++ b/libinit/libinit_utils.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2021 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ +#include +#include + +#include + +void property_override(std::string prop, std::string value, bool add) { + auto pi = (prop_info *) __system_property_find(prop.c_str()); + if (pi != nullptr) { + __system_property_update(pi, value.c_str(), value.length()); + } else if (add) { + __system_property_add(prop.c_str(), prop.length(), value.c_str(), value.length()); + } +} + +std::vector ro_props_default_source_order = { + "odm.", + "product.", + "system.", + "system_ext.", + "vendor.", + "", +}; + +void set_ro_build_prop(const std::string &prop, const std::string &value, bool product) { + std::string prop_name; + + for (const auto &source : ro_props_default_source_order) { + if (product) + prop_name = "ro.product." + source + prop; + else + prop_name = "ro." + source + "build." + prop; + + property_override(prop_name, value, true); + } +} diff --git a/libinit/libinit_variant.cpp b/libinit/libinit_variant.cpp new file mode 100644 index 0000000..456edc5 --- /dev/null +++ b/libinit/libinit_variant.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2021 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include + +using android::base::GetProperty; + +#define HWC_PROP "ro.boot.hwc" +#define HWNAME_PROP "ro.boot.hwname" +#define SKU_PROP "ro.boot.product.hardware.sku" + +void search_variant(const std::vector variants) { + std::string hwc_value = GetProperty(HWC_PROP, ""); + std::string hwname_value = GetProperty(HWNAME_PROP, ""); + + for (const auto& variant : variants) { + if ((variant.hwc_value == "" || variant.hwc_value == hwc_value) && (variant.device == hwname_value)) { + set_variant_props(variant); + break; + } + } +} + +void set_variant_props(const variant_info_t variant) { + set_ro_build_prop("brand", variant.brand, true); + set_ro_build_prop("device", variant.device, true); + set_ro_build_prop("model", variant.model, true); + + set_ro_build_prop("fingerprint", variant.build_fingerprint); + property_override("ro.bootimage.build.fingerprint", variant.build_fingerprint); + property_override("ro.build.description", variant.build_description); + + if (variant.nfc) + property_override(SKU_PROP, "nfc"); +}