Package xcrash

Class XCrash.InitParameters

  • Enclosing class:
    XCrash

    public static class XCrash.InitParameters
    extends java.lang.Object
    An initialization parameter set.
    • Constructor Detail

      • InitParameters

        public InitParameters()
    • Method Detail

      • setAppVersion

        public XCrash.InitParameters setAppVersion​(java.lang.String appVersion)
        Set App version. You can use this method to set an internal test/gray version number. (Default: PackageInfo.versionName)
        Parameters:
        appVersion - App version string.
        Returns:
        The InitParameters object.
      • setLogDir

        public XCrash.InitParameters setLogDir​(java.lang.String dir)
        Set the directory to save crash log files. (Default: Context.getFilesDir() + "/tombstones")
        Parameters:
        dir - Absolute path to the directory.
        Returns:
        The InitParameters object.
      • setLogFileMaintainDelayMs

        public XCrash.InitParameters setLogFileMaintainDelayMs​(int logFileMaintainDelayMs)
        Set delay in milliseconds before the log file maintain task is to be executed. (Default: 5000)
        Parameters:
        logFileMaintainDelayMs - Delay in milliseconds before the log file maintain task is to be executed.
        Returns:
        The InitParameters object.
      • setLogger

        public XCrash.InitParameters setLogger​(ILogger logger)
        Set a logger implementation for xCrash to log message and exception.
        Parameters:
        logger - An instance of ILogger.
        Returns:
        The InitParameters object.
      • setLibLoader

        public XCrash.InitParameters setLibLoader​(ILibLoader libLoader)
        Set a libLoader implementation for xCrash to load native library.
        Parameters:
        libLoader - An instance of ILibLoader.
        Returns:
        The InitParameters object.
      • setPlaceholderCountMax

        public XCrash.InitParameters setPlaceholderCountMax​(int countMax)
        Set the maximum number of placeholder files in the log directory. (Default: 0)

        Note: Set this value to 0 means disable the placeholder feature.

        Parameters:
        countMax - The maximum number of placeholder files.
        Returns:
        The InitParameters object.
      • setPlaceholderSizeKb

        public XCrash.InitParameters setPlaceholderSizeKb​(int sizeKb)
        Set the KB of each placeholder files in the log directory. (Default: 128)
        Parameters:
        sizeKb - The KB of each placeholder files.
        Returns:
        The InitParameters object.
      • enableJavaCrashHandler

        public XCrash.InitParameters enableJavaCrashHandler()
        Enable the Java exception capture feature. (Default: enable)
        Returns:
        The InitParameters object.
      • disableJavaCrashHandler

        public XCrash.InitParameters disableJavaCrashHandler()
        Disable the Java exception capture feature. (Default: enable)
        Returns:
        The InitParameters object.
      • setJavaRethrow

        public XCrash.InitParameters setJavaRethrow​(boolean rethrow)
        Set whether xCrash should rethrow the Java exception to system after it has been handled. (Default: true)
        Parameters:
        rethrow - If true, the Java exception will be rethrown to Android System.
        Returns:
        The InitParameters object.
      • setJavaLogCountMax

        public XCrash.InitParameters setJavaLogCountMax​(int countMax)
        Set the maximum number of Java crash log files to save in the log directory. (Default: 10)
        Parameters:
        countMax - The maximum number of Java crash log files.
        Returns:
        The InitParameters object.
      • setJavaLogcatSystemLines

        public XCrash.InitParameters setJavaLogcatSystemLines​(int logcatSystemLines)
        Set the maximum number of rows to get from "logcat -b system" when a Java exception occurred. (Default: 50)
        Parameters:
        logcatSystemLines - The maximum number of rows.
        Returns:
        The InitParameters object.
      • setJavaLogcatEventsLines

        public XCrash.InitParameters setJavaLogcatEventsLines​(int logcatEventsLines)
        Set the maximum number of rows to get from "logcat -b events" when a Java exception occurred. (Default: 50)
        Parameters:
        logcatEventsLines - The maximum number of rows.
        Returns:
        The InitParameters object.
      • setJavaLogcatMainLines

        public XCrash.InitParameters setJavaLogcatMainLines​(int logcatMainLines)
        Set the maximum number of rows to get from "logcat -b main" when a Java exception occurred. (Default: 200)
        Parameters:
        logcatMainLines - The maximum number of rows.
        Returns:
        The InitParameters object.
      • setJavaDumpFds

        public XCrash.InitParameters setJavaDumpFds​(boolean flag)
        Set if dumping FD list when a java crash occurred. (Default: enable)
        Parameters:
        flag - True or false.
        Returns:
        The InitParameters object.
      • setJavaDumpNetworkInfo

        public XCrash.InitParameters setJavaDumpNetworkInfo​(boolean flag)
        Set if dumping network info when a java crash occurred. (Default: enable)
        Parameters:
        flag - True or false.
        Returns:
        The InitParameters object.
      • setJavaDumpAllThreads

        public XCrash.InitParameters setJavaDumpAllThreads​(boolean flag)
        Set if dumping threads info (stacktrace) for all threads (not just the thread that has crashed) when a Java exception occurred. (Default: enable)
        Parameters:
        flag - True or false.
        Returns:
        The InitParameters object.
      • setJavaDumpAllThreadsCountMax

        public XCrash.InitParameters setJavaDumpAllThreadsCountMax​(int countMax)
        Set the maximum number of other threads to dump when a Java exception occurred. "0" means no limit. (Default: 0)

        Note: This option is only useful when "JavaDumpAllThreads" is enabled by calling setJavaDumpAllThreads(boolean).

        Parameters:
        countMax - The maximum number of other threads to dump.
        Returns:
        The InitParameters object.
      • setJavaDumpAllThreadsWhiteList

        public XCrash.InitParameters setJavaDumpAllThreadsWhiteList​(java.lang.String[] whiteList)
        Set a thread name (regular expression) whitelist to filter which threads need to be dumped when a Java exception occurred. "null" means no filtering. (Default: null)

        Note: This option is only useful when "JavaDumpAllThreads" is enabled by calling setJavaDumpAllThreads(boolean).

        Parameters:
        whiteList - A thread name (regular expression) whitelist.
        Returns:
        The InitParameters object.
      • setJavaCallback

        public XCrash.InitParameters setJavaCallback​(ICrashCallback callback)
        Set a callback to be executed when a Java exception occurred. (If not set, nothing will be happened.)
        Parameters:
        callback - An instance of ICrashCallback.
        Returns:
        The InitParameters object.
      • enableNativeCrashHandler

        public XCrash.InitParameters enableNativeCrashHandler()
        Enable the native crash capture feature. (Default: enable)
        Returns:
        The InitParameters object.
      • disableNativeCrashHandler

        public XCrash.InitParameters disableNativeCrashHandler()
        Disable the native crash capture feature. (Default: enable)
        Returns:
        The InitParameters object.
      • setNativeRethrow

        public XCrash.InitParameters setNativeRethrow​(boolean rethrow)
        Set whether xCrash should rethrow the crash native signal to system after it has been handled. (Default: true)
        Parameters:
        rethrow - If true, the native signal will be rethrown to Android System.
        Returns:
        The InitParameters object.
      • setNativeLogCountMax

        public XCrash.InitParameters setNativeLogCountMax​(int countMax)
        Set the maximum number of native crash log files to save in the log directory. (Default: 10)
        Parameters:
        countMax - The maximum number of native crash log files.
        Returns:
        The InitParameters object.
      • setNativeLogcatSystemLines

        public XCrash.InitParameters setNativeLogcatSystemLines​(int logcatSystemLines)
        Set the maximum number of rows to get from "logcat -b system" when a native crash occurred. (Default: 50)
        Parameters:
        logcatSystemLines - The maximum number of rows.
        Returns:
        The InitParameters object.
      • setNativeLogcatEventsLines

        public XCrash.InitParameters setNativeLogcatEventsLines​(int logcatEventsLines)
        Set the maximum number of rows to get from "logcat -b events" when a native crash occurred. (Default: 50)
        Parameters:
        logcatEventsLines - The maximum number of rows.
        Returns:
        The InitParameters object.
      • setNativeLogcatMainLines

        public XCrash.InitParameters setNativeLogcatMainLines​(int logcatMainLines)
        Set the maximum number of rows to get from "logcat -b main" when a native crash occurred. (Default: 200)
        Parameters:
        logcatMainLines - The maximum number of rows.
        Returns:
        The InitParameters object.
      • setNativeDumpElfHash

        public XCrash.InitParameters setNativeDumpElfHash​(boolean flag)
        Set if dumping ELF file's MD5 hash in Build-Id section when a native crash occurred. (Default: enable)
        Parameters:
        flag - True or false.
        Returns:
        The InitParameters object.
      • setNativeDumpMap

        public XCrash.InitParameters setNativeDumpMap​(boolean flag)
        Set if dumping memory map when a native crash occurred. (Default: enable)
        Parameters:
        flag - True or false.
        Returns:
        The InitParameters object.
      • setNativeDumpFds

        public XCrash.InitParameters setNativeDumpFds​(boolean flag)
        Set if dumping FD list when a native crash occurred. (Default: enable)
        Parameters:
        flag - True or false.
        Returns:
        The InitParameters object.
      • setNativeDumpNetwork

        public XCrash.InitParameters setNativeDumpNetwork​(boolean flag)
        Set if dumping network info when a native crash occurred. (Default: enable)
        Parameters:
        flag - True or false.
        Returns:
        The InitParameters object.
      • setNativeDumpAllThreads

        public XCrash.InitParameters setNativeDumpAllThreads​(boolean flag)
        Set if dumping threads info (registers, backtrace and stack) for all threads (not just the thread that has crashed) when a native crash occurred. (Default: enable)
        Parameters:
        flag - True or false.
        Returns:
        The InitParameters object.
      • setNativeDumpAllThreadsCountMax

        public XCrash.InitParameters setNativeDumpAllThreadsCountMax​(int countMax)
        Set the maximum number of other threads to dump when a native crash occurred. "0" means no limit. (Default: 0)

        Note: This option is only useful when "NativeDumpAllThreads" is enabled by calling setNativeDumpAllThreads(boolean).

        Parameters:
        countMax - The maximum number of other threads to dump.
        Returns:
        The InitParameters object.
      • setNativeDumpAllThreadsWhiteList

        public XCrash.InitParameters setNativeDumpAllThreadsWhiteList​(java.lang.String[] whiteList)
        Set a thread name (regular expression) whitelist to filter which threads need to be dumped when a native crash occurred. "null" means no filtering. (Default: null)

        Note: This option is only useful when "NativeDumpAllThreads" is enabled by calling setNativeDumpAllThreads(boolean).

        Warning: The regular expression used here only supports POSIX ERE (Extended Regular Expression). Android bionic's regular expression is different from Linux libc's regular expression. See: https://android.googlesource.com/platform/bionic/+/refs/heads/master/libc/include/regex.h .

        Parameters:
        whiteList - A thread name (regular expression) whitelist.
        Returns:
        The InitParameters object.
      • setNativeCallback

        public XCrash.InitParameters setNativeCallback​(ICrashCallback callback)
        Set a callback to be executed when a native crash occurred. (If not set, nothing will be happened.)
        Parameters:
        callback - An instance of ICrashCallback.
        Returns:
        The InitParameters object.
      • enableAnrCrashHandler

        public XCrash.InitParameters enableAnrCrashHandler()
        Enable the ANR capture feature. (Default: enable)
        Returns:
        The InitParameters object.
      • disableAnrCrashHandler

        public XCrash.InitParameters disableAnrCrashHandler()
        Disable the ANR capture feature. (Default: enable)
        Returns:
        The InitParameters object.
      • setAnrRethrow

        public XCrash.InitParameters setAnrRethrow​(boolean rethrow)
        Set whether xCrash should rethrow the ANR native signal to system after it has been handled. (Default: true)

        Note: This option is only valid if Android API level greater than or equal to 21.

        Warning: It is highly recommended NOT to modify the default value (true) in most cases unless you know that you are doing.

        Parameters:
        rethrow - If true, the native signal will be rethrown to Android System.
        Returns:
        The InitParameters object.
      • setAnrCheckProcessState

        public XCrash.InitParameters setAnrCheckProcessState​(boolean checkProcessState)
        Set whether the process error state (from "ActivityManager#getProcessesInErrorState()") is a necessary condition for ANR. (Default: true)

        Note: On some Android TV box devices and on most Oppo phones, the ANR is not reflected by process error state. In this case, set this option to false.

        Parameters:
        checkProcessState - If true, process state error will be a necessary condition for ANR.
        Returns:
        The InitParameters object.
      • setAnrLogCountMax

        public XCrash.InitParameters setAnrLogCountMax​(int countMax)
        Set the maximum number of ANR log files to save in the log directory. (Default: 10)
        Parameters:
        countMax - The maximum number of ANR log files.
        Returns:
        The InitParameters object.
      • setAnrLogcatSystemLines

        public XCrash.InitParameters setAnrLogcatSystemLines​(int logcatSystemLines)
        Set the maximum number of rows to get from "logcat -b system" when an ANR occurred. (Default: 50)
        Parameters:
        logcatSystemLines - The maximum number of rows.
        Returns:
        The InitParameters object.
      • setAnrLogcatEventsLines

        public XCrash.InitParameters setAnrLogcatEventsLines​(int logcatEventsLines)
        Set the maximum number of rows to get from "logcat -b events" when an ANR occurred. (Default: 50)
        Parameters:
        logcatEventsLines - The maximum number of rows.
        Returns:
        The InitParameters object.
      • setAnrLogcatMainLines

        public XCrash.InitParameters setAnrLogcatMainLines​(int logcatMainLines)
        Set the maximum number of rows to get from "logcat -b main" when an ANR occurred. (Default: 200)
        Parameters:
        logcatMainLines - The maximum number of rows.
        Returns:
        The InitParameters object.
      • setAnrDumpFds

        public XCrash.InitParameters setAnrDumpFds​(boolean flag)
        Set if dumping FD list when an ANR occurred. (Default: enable)
        Parameters:
        flag - True or false.
        Returns:
        The InitParameters object.
      • setAnrDumpNetwork

        public XCrash.InitParameters setAnrDumpNetwork​(boolean flag)
        Set if dumping network info when an ANR occurred. (Default: enable)
        Parameters:
        flag - True or false.
        Returns:
        The InitParameters object.
      • setAnrCallback

        public XCrash.InitParameters setAnrCallback​(ICrashCallback callback)
        Set a callback to be executed when an ANR occurred. (If not set, nothing will be happened.)
        Parameters:
        callback - An instance of ICrashCallback.
        Returns:
        The InitParameters object.
      • setAnrFastCallback

        public XCrash.InitParameters setAnrFastCallback​(ICrashCallback fastCallback)
        Set a fast callback to be executed when an ANR occurred. This callback is called before ANR trace dump (If not set, nothing will be happened.)
        Parameters:
        fastCallback - An instance of ICrashCallback.
        Returns:
        The InitParameters object.