Add TWFunc::Property_Override(name, value) to override properties
using libresetprop
Change-Id: Ic49e187698c714f8a629d20ceddc40e823555477
diff --git a/Android.mk b/Android.mk
index 31a697d..4dc7908 100755
--- a/Android.mk
+++ b/Android.mk
@@ -398,6 +398,16 @@
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 872deaa..788068d 100644
--- a/prebuilt/Android.mk
+++ b/prebuilt/Android.mk
@@ -577,7 +577,7 @@
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 a3e5a07..40d0549 100755
--- a/twrp-functions.cpp
+++ b/twrp-functions.cpp
@@ -59,6 +59,10 @@
#include "libcrecovery/common.h"
}
+#ifdef TW_INCLUDE_LIBRESETPROP
+ #include <resetprop.h>
+#endif
+
struct selabel_handle *selinux_handle;
/* Execute a command */
@@ -1315,4 +1319,13 @@
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 8cea321..3e4e807 100755
--- a/twrp-functions.hpp
+++ b/twrp-functions.hpp
@@ -107,6 +107,7 @@
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);