mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-06 02:35:19 +08:00
Added: Add functions that can be used by non main threads to set CrashHandler
as the UncaughtExceptionHandler
This commit is contained in:
@@ -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)}.
|
||||
*
|
||||
|
@@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user