Skip to content

Commit

Permalink
Adjust debugging settings
Browse files Browse the repository at this point in the history
1. Set log buffer size for system
2. Increase buffer size to 128 Kb
3. Record also logs for APatch, KernelSU and SELinux
4. Add installation tasks for APatch
  • Loading branch information
JingMatrix committed Jan 3, 2025
1 parent 2ac24fa commit fba56a9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
37 changes: 22 additions & 15 deletions daemon/src/main/jni/logcat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using namespace std::string_view_literals;
using namespace std::chrono_literals;

constexpr size_t kMaxLogSize = 4 * 1024 * 1024;
constexpr long kLogBufferSize = 64 * 1024;
constexpr long kLogBufferSize = 128 * 1024;

namespace {
constexpr std::array<char, ANDROID_LOG_SILENT + 1> kLogChar = {
Expand Down Expand Up @@ -225,10 +225,11 @@ void Logcat::ProcessBuffer(struct log_msg *buf) {
modules_print_count_ += PrintLogLine(entry, modules_file_.get());
shortcut = true;
}
if (verbose_ &&
(shortcut || buf->id() == log_id::LOG_ID_CRASH || entry.pid == my_pid_ ||
tag == "Dobby"sv || tag == "Magisk"sv || tag == "LSPlant"sv || tag == "LSPlt"sv ||
tag.starts_with("LSPosed"sv) || tag.starts_with("zygisk"sv))) [[unlikely]] {
if (verbose_ && (shortcut || buf->id() == log_id::LOG_ID_CRASH || entry.pid == my_pid_ ||
tag == "APatchD"sv || tag == "Dobby"sv || tag == "KernelSU"sv ||
tag == "LSPlant"sv || tag == "LSPlt"sv || tag.starts_with("LSPosed"sv) ||
tag == "Magisk"sv || tag == "SELinux"sv || tag.starts_with("zygisk"sv)))
[[unlikely]] {
verbose_print_count_ += PrintLogLine(entry, verbose_file_.get());
}
if (entry.pid == my_pid_ && tag == "LSPosedLogcat"sv) [[unlikely]] {
Expand All @@ -250,8 +251,9 @@ void Logcat::ProcessBuffer(struct log_msg *buf) {
enable_watchdog = false;
enable_watchdog.notify_one();
std::system("resetprop -p --delete persist.logd.size");
std::system("resetprop -p --delete persist.logd.size.main");
std::system("resetprop -p --delete persist.logd.size.crash");
std::system("resetprop -p --delete persist.logd.size.main");
std::system("resetprop -p --delete persist.logd.size.system");

// Terminate the watchdog thread by exiting __system_property_wait firs firstt
std::system("setprop persist.log.tag V");
Expand All @@ -263,28 +265,33 @@ void Logcat::ProcessBuffer(struct log_msg *buf) {
void Logcat::StartLogWatchDog() {
constexpr static auto kLogdSizeProp = "persist.logd.size"sv;
constexpr static auto kLogdTagProp = "persist.log.tag"sv;
constexpr static auto kLogdMainSizeProp = "persist.logd.size.main"sv;
constexpr static auto kLogdCrashSizeProp = "persist.logd.size.crash"sv;
constexpr static auto kLogdMainSizeProp = "persist.logd.size.main"sv;
constexpr static auto kLogdSystemSizeProp = "persist.logd.size.system"sv;
constexpr static long kErr = -1;
std::thread watchdog([this] {
Log("[LogWatchDog started]\n");
while (true) {
enable_watchdog.wait(false); // Blocking current thread until enable_watchdog is true;
auto logd_size = GetByteProp(kLogdSizeProp);
auto logd_tag = GetStrProp(kLogdTagProp);
auto logd_main_size = GetByteProp(kLogdMainSizeProp);
auto logd_crash_size = GetByteProp(kLogdCrashSizeProp);
auto logd_main_size = GetByteProp(kLogdMainSizeProp);
auto logd_system_size = GetByteProp(kLogdSystemSizeProp);
Log("[LogWatchDog running] log.tag: " + logd_tag +
"; logd.[default, main, crash].size: [" + std::to_string(logd_size) + "," +
std::to_string(logd_main_size) + "," + std::to_string(logd_crash_size) + "]\n");
"; logd.[default, crash, main, system].size: [" + std::to_string(logd_size) + "," +
std::to_string(logd_crash_size) + "," + std::to_string(logd_main_size) + "," +
std::to_string(logd_system_size) + "]\n");
if (!logd_tag.empty() ||
!((logd_main_size == kErr && logd_crash_size == kErr && logd_size != kErr &&
logd_size >= kLogBufferSize) ||
(logd_main_size != kErr && logd_main_size >= kLogBufferSize &&
logd_crash_size != kErr && logd_crash_size >= kLogBufferSize))) {
!((logd_crash_size == kErr && logd_main_size == kErr && logd_system_size == kErr &&
logd_size != kErr && logd_size >= kLogBufferSize) ||
(logd_crash_size != kErr && logd_crash_size >= kLogBufferSize &&
logd_main_size != kErr && logd_main_size >= kLogBufferSize &&
logd_system_size != kErr && logd_system_size >= kLogBufferSize))) {
SetIntProp(kLogdSizeProp, std::max(kLogBufferSize, logd_size));
SetIntProp(kLogdMainSizeProp, std::max(kLogBufferSize, logd_main_size));
SetIntProp(kLogdCrashSizeProp, std::max(kLogBufferSize, logd_crash_size));
SetIntProp(kLogdMainSizeProp, std::max(kLogBufferSize, logd_main_size));
SetIntProp(kLogdSystemSizeProp, std::max(kLogBufferSize, logd_system_size));
SetStrProp(kLogdTagProp, "");
SetStrProp("ctl.start", "logd-reinit");
}
Expand Down
13 changes: 13 additions & 0 deletions magisk-loader/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,19 @@ fun afterEval() = android.applicationVariants.forEach { variant ->
dependsOn(flashKsuTask)
commandLine(adb, "shell", "su", "-c", "/system/bin/svc", "power", "reboot")
}
val flashAPatchTask = task<Exec>("flashAPatch${variantCapped}") {
group = "LSPosed"
dependsOn(pushTask)
commandLine(
adb, "shell", "su", "-c",
"apd module install /data/local/tmp/${zipFileName}"
)
}
task<Exec>("flashAPatchAndReboot${variantCapped}") {
group = "LSPosed"
dependsOn(flashAPatchTask)
commandLine(adb, "shell", "su", "-c", "/system/bin/svc", "power", "reboot")
}
}

afterEvaluate {
Expand Down

0 comments on commit fba56a9

Please sign in to comment.