rosemary: libinit: Import changes from sm8250-common

Change-Id: I31f1083fba0bebe5c23fcb140225bf47bc1d1c6b
This commit is contained in:
Sebastiano Barezzi
2022-12-02 20:45:46 +02:00
committed by Matsvei Niaverau
parent a8855f132a
commit 4637c21025
11 changed files with 319 additions and 117 deletions

View File

@@ -83,8 +83,8 @@ ODM_MANIFEST_SKUS += nfc
ODM_MANIFEST_NFC_FILES := $(DEVICE_PATH)/manifest_nfc.xml
# Init
TARGET_INIT_VENDOR_LIB := //$(DEVICE_PATH):libinit_xiaomi_rosemary
TARGET_RECOVERY_DEVICE_MODULES := libinit_xiaomi_rosemary
TARGET_INIT_VENDOR_LIB := //$(DEVICE_PATH):init_rosemary
TARGET_RECOVERY_DEVICE_MODULES := init_rosemary
# Kernel
TARGET_KERNEL_ARCH := arm64

View File

@@ -1,30 +0,0 @@
//
// Copyright (C) 2020 The LineageOS Project
//
// 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_xiaomi_rosemary",
recovery_available: true,
srcs: [
"init.cpp"
],
include_dirs: [
"system/libbase/include",
"system/core/init"
],
shared_libs: [
"libbase",
]
}

View File

@@ -1,85 +0,0 @@
/*
* Copyright (C) 2020 The LineageOS Project
*
* 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.
*/
#include <cstring>
#include <sys/sysinfo.h>
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
#include <sys/_system_properties.h>
#include "property_service.h"
void property_override(char const prop[], char const value[])
{
auto pi = (prop_info *) __system_property_find(prop);
if (pi != nullptr) {
__system_property_update(pi, value, strlen(value));
} else {
__system_property_add(prop, strlen(prop), value, strlen(value));
}
}
void load_dalvik_properties()
{
char const *heapstartsize;
char const *heapgrowthlimit;
char const *heapsize;
char const *heapminfree;
char const *heapmaxfree;
char const *heaptargetutilization;
struct sysinfo sys;
sysinfo(&sys);
if (sys.totalram >= 5ull * 1024 * 1024 * 1024) {
// from - phone-xhdpi-6144-dalvik-heap.mk
heapstartsize = "16m";
heapgrowthlimit = "256m";
heapsize = "512m";
heaptargetutilization = "0.5";
heapminfree = "8m";
heapmaxfree = "32m";
} else if (sys.totalram >= 3ull * 1024 * 1024 * 1024) {
// from - phone-xhdpi-4096-dalvik-heap.mk
heapstartsize = "8m";
heapgrowthlimit = "192m";
heapsize = "512m";
heaptargetutilization = "0.6";
heapminfree = "8m";
heapmaxfree = "16m";
} else {
// from - phone-xhdpi-2048-dalvik-heap.mk
heapstartsize = "8m";
heapgrowthlimit = "192m";
heapsize = "512m";
heaptargetutilization = "0.75";
heapminfree = "512k";
heapmaxfree = "8m";
}
property_override("dalvik.vm.heapstartsize", heapstartsize);
property_override("dalvik.vm.heapgrowthlimit", heapgrowthlimit);
property_override("dalvik.vm.heapsize", heapsize);
property_override("dalvik.vm.heaptargetutilization", heaptargetutilization);
property_override("dalvik.vm.heapminfree", heapminfree);
property_override("dalvik.vm.heapmaxfree", heapmaxfree);
}
void vendor_load_properties()
{
load_dalvik_properties();
}

25
libinit/Android.bp Normal file
View File

@@ -0,0 +1,25 @@
//
// Copyright (C) 2021 The LineageOS Project
//
// SPDX-License-Identifier: Apache-2.0
//
cc_library_static {
name: "libinit_rosemary",
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_rosemary",
srcs: ["init_rosemary.cpp"],
whole_static_libs: ["libinit_rosemary"],
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 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,30 @@
/*
* 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 sku_value;
std::string brand;
std::string device;
std::string marketname;
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

34
libinit/init_rosemary.cpp Normal file
View File

@@ -0,0 +1,34 @@
/*
* Copyright (C) 2021 The LineageOS Project
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <libinit_dalvik_heap.h>
#include <libinit_variant.h>
#include "vendor_init.h"
static const variant_info_t rosemary_info = {
.hwc_value = "Global",
.sku_value = "",
.device = "rosemary",
.nfc = true,
};
static const variant_info_t secret_info = {
.hwc_value = "Global_PA",
.sku_value = "",
.device = "secret",
.nfc = false,
};
static const std::vector<variant_info_t> variants = {
rosemary_info,
secret_info,
};
void vendor_load_properties() {
search_variant(variants);
set_dalvik_heap();
}

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 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,45 @@
/*
* 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 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 sku_value = GetProperty(SKU_PROP, "");
for (const auto& variant : variants) {
if ((variant.hwc_value == "" || variant.hwc_value == hwc_value) &&
(variant.sku_value == "" || variant.sku_value == sku_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("marketname", variant.marketname, 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));
property_override("ro.boot.hardware.sku", variant.device);
if (variant.nfc)
property_override(SKU_PROP, "nfc");
}