Skip to content

Commit

Permalink
add the logcat writer
Browse files Browse the repository at this point in the history
  • Loading branch information
altalk23 committed Oct 15, 2023
1 parent cd012df commit 57a475b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion loader/src/internal/crashlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using namespace geode::prelude;

static std::string getDateString(bool filesafe) {
std::string crashlog::getDateString(bool filesafe) {
auto const now = std::time(nullptr);
auto const tm = *std::localtime(&now);
std::ostringstream oss;
Expand Down
2 changes: 2 additions & 0 deletions loader/src/internal/crashlog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ namespace crashlog {
ghc::filesystem::path GEODE_DLL getCrashLogDirectory();

std::string GEODE_DLL writeCrashlog(geode::Mod* faultyMod, std::string const& info, std::string const& stacktrace, std::string const& registers);

std::string getDateString(bool filesafe);
}
17 changes: 17 additions & 0 deletions loader/src/platform/android/crashlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ using namespace geode::prelude;
#include <link.h>
#include <unwind.h>


#include <jni.h>
#include <Geode/cocos/platform/android/jni/JniHelper.h>

#include "backtrace/execinfo.hpp"

static constexpr size_t FRAME_SIZE = 64;
Expand Down Expand Up @@ -413,6 +417,19 @@ ghc::filesystem::path crashlog::getCrashLogDirectory() {
}

bool crashlog::setupPlatformHandler() {
auto path = crashlog::getCrashLogDirectory() / (getDateString(true) + ".log");

JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, "com/geode/launcher/utils/GeodeUtils", "writeLogcatCrashBuffer", "(Ljava/lang/String;)Z")) {
jstring stringArg1 = t.env->NewStringUTF(path.string().c_str());

jboolean result = t.env->CallStaticBooleanMethod(t.classID, t.methodID, stringArg1);

t.env->DeleteLocalRef(stringArg1);
t.env->DeleteLocalRef(t.classID);
return result;
}

return false;
}

Expand Down

0 comments on commit 57a475b

Please sign in to comment.