Skip to content

Commit

Permalink
kernel_module_loader: Set a prop after completing
Browse files Browse the repository at this point in the history
 * we can use this as a trigger in init rc, for any task
   that depend on kernel modules being loaded

Change-Id: I7623edc0b6dc799e911a087881f76e9642e005ee
  • Loading branch information
adithya2306 authored and bigbiff committed Jan 15, 2022
1 parent 0df7c9e commit 3a59df5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions kernel_module_loader.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "kernel_module_loader.hpp"
#include "common.h"

const std::vector<std::string> kernel_modules_requested = TWFunc::split_string(EXPAND(TW_LOAD_VENDOR_MODULES), ' ', true);

Expand Down Expand Up @@ -58,6 +59,10 @@ bool KernelModuleLoader::Load_Vendor_Modules() {
if (ven)
ven->UnMount(false);

android::base::SetProperty("twrp.modules.loaded", "true");

TWFunc::Wait_For_Battery(3s);

return true;
}

Expand Down
26 changes: 26 additions & 0 deletions twrp-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -407,6 +409,30 @@ int32_t TWFunc::timespec_diff_ms(timespec& start, timespec& end)
((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
Expand Down
2 changes: 2 additions & 0 deletions twrp-functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class TWFunc
static vector<string> split_string(const string &in, char del, bool skip_empty);
static timespec timespec_diff(timespec& start, timespec& end); // Return a diff for 2 times
static int32_t timespec_diff_ms(timespec& start, timespec& end); // Returns diff in ms
static bool Wait_For_File(const string& path, std::chrono::nanoseconds timeout); // Wait For File, True is success, False is timeout;
static bool Wait_For_Battery(std::chrono::nanoseconds timeout); // Wait For /sys/class/power_supply/battery or TW_CUSTOM_BATTERY_PATH, True is success, False is timeout;

#ifndef BUILD_TWRPTAR_MAIN
static void install_htc_dumlock(void); // Installs HTC Dumlock
Expand Down

0 comments on commit 3a59df5

Please sign in to comment.