From 461e39fe89753edba18cc9c3b1571a1ec13c6790 Mon Sep 17 00:00:00 2001 From: Chaosmaster Date: Fri, 7 Feb 2020 01:48:13 +0100 Subject: [PATCH] Add TWFunc::Property_Override(name, value) to override properties using libresetprop Change-Id: Ic49e187698c714f8a629d20ceddc40e823555477 --- Android.mk | 10 ++++++++++ prebuilt/Android.mk | 2 +- twrp-functions.cpp | 13 +++++++++++++ twrp-functions.hpp | 1 + 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Android.mk b/Android.mk index 31a697d8..4dc79081 100755 --- a/Android.mk +++ b/Android.mk @@ -398,6 +398,16 @@ endif ifneq ($(TW_CLOCK_OFFSET),) LOCAL_CFLAGS += -DTW_CLOCK_OFFSET=$(TW_CLOCK_OFFSET) endif +ifneq ($(TW_OVERRIDE_SYSTEM_PROPS),) + TW_INCLUDE_LIBRESETPROP := true + LOCAL_CFLAGS += -DTW_OVERRIDE_SYSTEM_PROPS=$(TW_OVERRIDE_SYSTEM_PROPS) +endif +ifneq ($(TW_INCLUDE_LIBRESETPROP),) + LOCAL_SHARED_LIBRARIES += libresetprop + LOCAL_C_INCLUDES += external/magisk-prebuilt/include + LOCAL_CFLAGS += -DTW_INCLUDE_LIBRESETPROP +endif + TWRP_REQUIRED_MODULES += \ dump_image \ erase_image \ diff --git a/prebuilt/Android.mk b/prebuilt/Android.mk index 872deaa6..788068d8 100644 --- a/prebuilt/Android.mk +++ b/prebuilt/Android.mk @@ -577,7 +577,7 @@ ifeq ($(TW_INCLUDE_CRYPTO), true) endif endif -ifneq (,$(filter $(TW_INCLUDE_REPACKTOOLS) $(TW_INCLUDE_RESETPROP), true)) +ifneq (,$(filter $(TW_INCLUDE_REPACKTOOLS) $(TW_INCLUDE_RESETPROP) $(TW_INCLUDE_LIBRESETPROP), true)) ifeq ($(wildcard external/magisk-prebuilt/Android.mk),) $(warning Magisk prebuilt tools not found!) $(warning Please place https://github.com/TeamWin/external_magisk-prebuilt) diff --git a/twrp-functions.cpp b/twrp-functions.cpp index a3e5a073..40d0549c 100755 --- a/twrp-functions.cpp +++ b/twrp-functions.cpp @@ -59,6 +59,10 @@ extern "C" { #include "libcrecovery/common.h" } +#ifdef TW_INCLUDE_LIBRESETPROP + #include +#endif + struct selabel_handle *selinux_handle; /* Execute a command */ @@ -1315,4 +1319,13 @@ bool TWFunc::Is_TWRP_App_In_System() { DataManager::SetValue("tw_app_installed_in_system", 0); return false; } + +int TWFunc::Property_Override(string Prop_Name, string Prop_Value) { +#ifdef TW_INCLUDE_LIBRESETPROP + return setprop(Prop_Name.c_str(), Prop_Value.c_str(), false); +#else + return -2; +#endif +} + #endif // ndef BUILD_TWRPTAR_MAIN diff --git a/twrp-functions.hpp b/twrp-functions.hpp index 8cea321b..3e4e8079 100755 --- a/twrp-functions.hpp +++ b/twrp-functions.hpp @@ -107,6 +107,7 @@ public: static std::string get_cache_dir(); // return the cache partition existence static void check_selinux_support(); // print whether selinux support is enabled to console static bool Is_TWRP_App_In_System(); // Check if the TWRP app is installed in the system partition + static int Property_Override(string Prop_Name, string Prop_Value); // Override properties (including ro. properties) private: static void Copy_Log(string Source, string Destination);