From 753ea1bf83c8f899fb68d44267da3ebe5f0dc7cd Mon Sep 17 00:00:00 2001 From: sebaubuntu Date: Tue, 7 Mar 2023 16:11:37 +0530 Subject: [PATCH] RMX3031: libinit: Fix adb in recovery mode Signed-off-by: Nishant Kumar --- BoardConfig.mk | 4 ++++ libinit/Android.bp | 23 ++++++++++++++++++ libinit/include/libinit_utils.h | 16 +++++++++++++ libinit/init_RMX3031.cpp | 18 ++++++++++++++ libinit/libinit_utils.cpp | 42 +++++++++++++++++++++++++++++++++ 5 files changed, 103 insertions(+) create mode 100644 libinit/Android.bp create mode 100644 libinit/include/libinit_utils.h create mode 100644 libinit/init_RMX3031.cpp create mode 100644 libinit/libinit_utils.cpp diff --git a/BoardConfig.mk b/BoardConfig.mk index c1cede4..96892cf 100644 --- a/BoardConfig.mk +++ b/BoardConfig.mk @@ -165,6 +165,10 @@ TARGET_USERIMAGES_USE_F2FS := true # HWUI TARGET_USES_VULKAN := true +# Init +TARGET_INIT_VENDOR_LIB ?= //$(DEVICE_PATH):init_RMX3031 +TARGET_RECOVERY_DEVICE_MODULES ?= init_RMX3031 + # Ril ENABLE_VENDOR_RIL_SERVICE := true diff --git a/libinit/Android.bp b/libinit/Android.bp new file mode 100644 index 0000000..1b3bbfd --- /dev/null +++ b/libinit/Android.bp @@ -0,0 +1,23 @@ +// +// Copyright (C) 2021 The LineageOS Project +// +// SPDX-License-Identifier: Apache-2.0 +// + +cc_library_static { + name: "libinit_RMX3031", + srcs: [ + "libinit_utils.cpp", + ], + whole_static_libs: ["libbase"], + export_include_dirs: ["include"], + recovery_available: true, +} + +cc_library_static { + name: "init_RMX3031", + srcs: ["init_RMX3031.cpp"], + whole_static_libs: ["libinit_RMX3031"], + include_dirs: ["system/core/init"], + recovery_available: true, +} \ No newline at end of file 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/init_RMX3031.cpp b/libinit/init_RMX3031.cpp new file mode 100644 index 0000000..94ab395 --- /dev/null +++ b/libinit/init_RMX3031.cpp @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2021 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include "vendor_init.h" + +void vendor_load_properties() { + if (access("/system/bin/recovery", F_OK) == 0) { + property_override("ro.adb.secure", "0"); + property_override("ro.debuggable", "1"); + property_override("ro.adb.secure.recovery", "0"); + property_override("persist.sys.usb.config", "adb"); + } +} 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); + } +}