Merge sm6250-common into miatoll

Change-Id: I870ee30f1c9b8e612ec4acf1e33654ec2f6eb9fd
This commit is contained in:
Alexander Winkowski
2022-11-13 11:42:10 +00:00
124 changed files with 20091 additions and 42 deletions

View File

@ -4,10 +4,23 @@
// SPDX-License-Identifier: Apache-2.0
//
cc_library_static {
name: "libinit_xiaomi_miatoll",
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_miatoll",
srcs: ["init_xiaomi_miatoll.cpp"],
whole_static_libs: ["//device/xiaomi/sm6250-common:libinit_xiaomi_atoll"],
whole_static_libs: ["libinit_xiaomi_miatoll"],
include_dirs: ["system/core/init"],
recovery_available: true,
}

View File

@ -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 <string>
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

View File

@ -0,0 +1,18 @@
/*
* Copyright (C) 2021-2022 The LineageOS Project
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef LIBINIT_UTILS_H
#define LIBINIT_UTILS_H
#include <string>
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);
std::string fingerprint_to_description(std::string fingerprint);
#endif // LIBINIT_UTILS_H

View File

@ -0,0 +1,28 @@
/*
* Copyright (C) 2021-2022 The LineageOS Project
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef LIBINIT_VARIANT_H
#define LIBINIT_VARIANT_H
#include <string>
#include <vector>
typedef struct variant_info {
std::string hwc_value;
std::string brand;
std::string device;
std::string model;
std::string build_fingerprint;
bool nfc;
} variant_info_t;
void search_variant(const std::vector<variant_info_t> variants);
void set_variant_props(const variant_info_t variant);
#endif // LIBINIT_VARIANT_H

View File

@ -0,0 +1,67 @@
/*
* Copyright (C) 2021 The LineageOS Project
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <sys/sysinfo.h>
#include <libinit_utils.h>
#include <libinit_dalvik_heap.h>
#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);
}

75
libinit/libinit_utils.cpp Normal file
View File

@ -0,0 +1,75 @@
/*
* Copyright (C) 2021-2022 The LineageOS Project
*
* SPDX-License-Identifier: Apache-2.0
*/
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
#include <sys/_system_properties.h>
#include <vector>
#include <libinit_utils.h>
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<std::string> ro_props_default_source_order = {
"odm.",
"odm_dlkm.",
"product.",
"system.",
"system_ext.",
"vendor.",
"vendor_dlkm.",
"",
};
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);
}
}
#define FIND_AND_REMOVE(s, delimiter, variable_name) \
std::string variable_name = s.substr(0, s.find(delimiter)); \
s.erase(0, s.find(delimiter) + delimiter.length());
#define APPEND_STRING(s, to_append) \
s.append(" "); \
s.append(to_append);
std::string fingerprint_to_description(std::string fingerprint) {
std::string delimiter = "/";
std::string delimiter2 = ":";
std::string build_fingerprint_copy = fingerprint;
FIND_AND_REMOVE(build_fingerprint_copy, delimiter, brand)
FIND_AND_REMOVE(build_fingerprint_copy, delimiter, product)
FIND_AND_REMOVE(build_fingerprint_copy, delimiter2, device)
FIND_AND_REMOVE(build_fingerprint_copy, delimiter, platform_version)
FIND_AND_REMOVE(build_fingerprint_copy, delimiter, build_id)
FIND_AND_REMOVE(build_fingerprint_copy, delimiter2, build_number)
FIND_AND_REMOVE(build_fingerprint_copy, delimiter, build_variant)
std::string build_version_tags = build_fingerprint_copy;
std::string description = product + "-" + build_variant;
APPEND_STRING(description, platform_version)
APPEND_STRING(description, build_id)
APPEND_STRING(description, build_number)
APPEND_STRING(description, build_version_tags)
return description;
}

View File

@ -0,0 +1,42 @@
/*
* Copyright (C) 2021-2022 The LineageOS Project
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <android-base/properties.h>
#include <libinit_utils.h>
#include <libinit_variant.h>
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<variant_info_t> 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", fingerprint_to_description(variant.build_fingerprint));
if (variant.nfc)
property_override(SKU_PROP, "nfc");
}