Added: Add functions that can be used by non main threads to set CrashHandler as the UncaughtExceptionHandler

This commit is contained in:
agnostic-apollo
2022-04-17 05:56:35 +05:00
parent 6b60adc079
commit 9c7ec0cebd
2 changed files with 27 additions and 1 deletions

View File

@@ -50,6 +50,20 @@ public class CrashHandler implements Thread.UncaughtExceptionHandler {
}
}
/**
* Set uncaught crash handler of current non-main thread to {@link CrashHandler}.
*/
public static void setCrashHandler(@NonNull final Context context, @NonNull final CrashHandlerClient crashHandlerClient) {
Thread.currentThread().setUncaughtExceptionHandler(new CrashHandler(context, crashHandlerClient, false));
}
/**
* Get {@link CrashHandler} instance that can be set as uncaught crash handler of a non-main thread.
*/
public static CrashHandler getCrashHandler(@NonNull final Context context, @NonNull final CrashHandlerClient crashHandlerClient) {
return new CrashHandler(context, crashHandlerClient, false);
}
/**
* Log a crash in the crash log file at path returned by {@link CrashHandlerClient#getCrashLogFilePath(Context)}.
*

View File

@@ -54,9 +54,21 @@ public class TermuxCrashUtils implements CrashHandler.CrashHandlerClient {
public static void setDefaultCrashHandler(@NonNull final Context context) {
CrashHandler.setDefaultCrashHandler(context, new TermuxCrashUtils(TYPE.UNCAUGHT_EXCEPTION));
}
/**
* Set uncaught crash handler of current non-main thread to {@link CrashHandler} for Termux app
* and its plugins to log crashes at {@link TermuxConstants#TERMUX_CRASH_LOG_FILE_PATH}.
*/
public static void setCrashHandler(@NonNull final Context context) {
CrashHandler.setCrashHandler(context, new TermuxCrashUtils(TYPE.UNCAUGHT_EXCEPTION));
CrashHandler.setCrashHandler(context, new TermuxCrashUtils(TYPE.CAUGHT_EXCEPTION));
}
/**
* Get {@link CrashHandler} for Termux app and its plugins that can be set as the uncaught
* crash handler of a non-main thread to log crashes at {@link TermuxConstants#TERMUX_CRASH_LOG_FILE_PATH}.
*/
public static CrashHandler getCrashHandler(@NonNull final Context context) {
return CrashHandler.getCrashHandler(context, new TermuxCrashUtils(TYPE.CAUGHT_EXCEPTION));
}
/**