mirror of
https://github.com/PixelExperience-Devices/device_xiaomi_sm6250-common.git
synced 2025-05-20 20:37:18 +09:00
sm6250-common: Initial variant handler libinit
* This libinit has been made to commonize device variants props handling [dereference23: Adapt for Xiaomi SM6250] Signed-off-by: Alexander Winkowski <dereference23@outlook.com> Change-Id: Iab68ff451ab1d6e861fb4cda4ef07fad3123ecde
This commit is contained in:
parent
223d20e8cd
commit
27c7899680
@ -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
|
||||
|
25
libinit/Android.bp
Normal file
25
libinit/Android.bp
Normal file
@ -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,
|
||||
}
|
23
libinit/include/libinit_dalvik_heap.h
Normal file
23
libinit/include/libinit_dalvik_heap.h
Normal 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
|
16
libinit/include/libinit_utils.h
Normal file
16
libinit/include/libinit_utils.h
Normal file
@ -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 <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);
|
||||
|
||||
#endif // LIBINIT_UTILS_H
|
29
libinit/include/libinit_variant.h
Normal file
29
libinit/include/libinit_variant.h
Normal file
@ -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 <string>
|
||||
#include <vector>
|
||||
|
||||
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<variant_info_t> variants);
|
||||
|
||||
void set_variant_props(const variant_info_t variant);
|
||||
|
||||
#endif // LIBINIT_VARIANT_H
|
13
libinit/init_xiaomi_atoll.cpp
Normal file
13
libinit/init_xiaomi_atoll.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <libinit_dalvik_heap.h>
|
||||
|
||||
#include "vendor_init.h"
|
||||
|
||||
void vendor_load_properties() {
|
||||
set_dalvik_heap();
|
||||
}
|
67
libinit/libinit_dalvik_heap.cpp
Normal file
67
libinit/libinit_dalvik_heap.cpp
Normal 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);
|
||||
}
|
42
libinit/libinit_utils.cpp
Normal file
42
libinit/libinit_utils.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.",
|
||||
"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);
|
||||
}
|
||||
}
|
41
libinit/libinit_variant.cpp
Normal file
41
libinit/libinit_variant.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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", variant.build_description);
|
||||
|
||||
if (variant.nfc)
|
||||
property_override(SKU_PROP, "nfc");
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user