kernel_module_loader: Set a prop after completing

 * we can use this as a trigger in init rc, for any task
   that depend on kernel modules being loaded

Change-Id: I7623edc0b6dc799e911a087881f76e9642e005ee
diff --git a/twrp-functions.cpp b/twrp-functions.cpp
index 350d840..15d4bdd 100755
--- a/twrp-functions.cpp
+++ b/twrp-functions.cpp
@@ -38,8 +38,10 @@
 #include <cctype>
 #include <algorithm>
 #include <selinux/label.h>
+#include <thread>
 
 #include <android-base/strings.h>
+#include <android-base/chrono_utils.h>
 
 #include "twrp-functions.hpp"
 #include "twcommon.h"
@@ -407,6 +409,30 @@
 			((start.tv_sec * 1000) + start.tv_nsec/1000000);
 }
 
+bool TWFunc::Wait_For_File(const string& path, std::chrono::nanoseconds timeout) {
+    android::base::Timer t;
+    while (t.duration() < timeout) {
+        struct stat sb;
+        if (stat(path.c_str(), &sb) != -1) {
+            return true;
+        }
+        std::this_thread::sleep_for(10ms);
+    }
+	return false;
+}
+
+bool TWFunc::Wait_For_Battery(std::chrono::nanoseconds timeout) {
+	std::string battery_path;
+#ifdef TW_CUSTOM_BATTERY_PATH
+	battery_path = EXPAND(TW_CUSTOM_BATTERY_PATH);
+#else
+	battery_path = "/sys/class/power_supply/battery";
+#endif
+	if (!battery_path.empty()) return TWFunc::Wait_For_File(battery_path, timeout);
+
+	return false;
+}
+
 #ifndef BUILD_TWRPTAR_MAIN
 
 // Returns "/path" from a full /path/to/file.name