diff options
Diffstat (limited to 'libinit/libinit_utils.cpp')
-rw-r--r-- | libinit/libinit_utils.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/libinit/libinit_utils.cpp b/libinit/libinit_utils.cpp new file mode 100644 index 0000000..50f5c35 --- /dev/null +++ b/libinit/libinit_utils.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (C) 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.", + "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); + } +} + +#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; +} |