Class CrashHandler

Object
org.mozilla.geckoview.CrashHandler
All Implemented Interfaces:
Thread.UncaughtExceptionHandler

public class CrashHandler extends Object implements Thread.UncaughtExceptionHandler
  • Constructor Details

    • CrashHandler

      public CrashHandler(@Nullable Class<? extends Service> handlerService)
      Create and register a CrashHandler for all threads and thread groups.
      Parameters:
      handlerService - Service receiving native code crashes
    • CrashHandler

      public CrashHandler(@Nullable Context aAppContext, @Nullable Class<? extends Service> aHandlerService)
      Create and register a CrashHandler for all threads and thread groups.
      Parameters:
      aAppContext - A Context for retrieving application information.
      aHandlerService - Service receiving native code crashes
    • CrashHandler

      public CrashHandler(Thread thread, Class<? extends Service> handlerService)
      Create and register a CrashHandler for a particular thread.
      Parameters:
      thread - A thread to register the CrashHandler
      handlerService - Service receiving native code crashes
    • CrashHandler

      public CrashHandler(@Nullable Thread thread, Context aAppContext, Class<? extends Service> aHandlerService)
      Create and register a CrashHandler for a particular thread.
      Parameters:
      thread - A thread to register the CrashHandler
      aAppContext - A Context for retrieving application information.
      aHandlerService - Service receiving native code crashes
  • Method Details

    • getRootException

      @AnyThread @NonNull public static Throwable getRootException(@NonNull Throwable exc)
      Get the root exception from the 'cause' chain of an exception.
      Parameters:
      exc - An exception
      Returns:
      The root exception
    • getExceptionStackTrace

      @AnyThread @NonNull public static String getExceptionStackTrace(@NonNull Throwable exc)
      Get the standard stack trace string of an exception.
      Parameters:
      exc - An exception
      Returns:
      The exception stack trace.
    • terminateProcess

      @AnyThread public static void terminateProcess()
      Terminate the current process.
    • unregister

      @AnyThread public void unregister()
      Unregister this CrashHandler for exception handling.
    • logException

      @AnyThread public static void logException(@NonNull Thread thread, @NonNull Throwable exc)
      Record an exception stack in logs.
      Parameters:
      thread - The exception thread
      exc - An exception
    • getAppPackageName

      @Nullable @AnyThread public String getAppPackageName()
      Returns:
      the application package name. if context is not null; if context is null, CrashHandler's package name will be returned.
    • getAppContext

      @AnyThread @Nullable public Context getAppContext()
      Returns:
      application context.
    • getCrashExtras

      @AnyThread @NonNull public Bundle getCrashExtras(@NonNull Thread thread, @NonNull Throwable exc)
      Get the crash "extras" to be reported.
      Parameters:
      thread - The exception thread
      exc - An exception
      Returns:
      "Extras" in the from of a Bundle
    • getCrashDump

      @NonNull @AnyThread public byte[] getCrashDump(@Nullable Thread thread, @Nullable Throwable exc)
      Get the crash minidump content to be reported.
      Parameters:
      thread - The exception thread
      exc - An exception
      Returns:
      Minidump content
    • getServerUrl

      @NonNull @AnyThread public String getServerUrl(@NonNull Bundle extras)
      Get the server URL to send the crash report to.
      Parameters:
      extras - The crash extras Bundle
      Returns:
      the URL that the crash reporter will submit reports to.
    • launchCrashReporter

      @AnyThread public boolean launchCrashReporter(@NonNull String dumpFile, @NonNull String extraFile)
      Launch the crash reporter activity that sends the crash report to the server.
      Parameters:
      dumpFile - Path for the minidump file
      extraFile - Path for the crash extra file
      Returns:
      Whether the crash reporter was successfully launched
    • reportException

      @AnyThread public boolean reportException(@NonNull Thread thread, @NonNull Throwable exc)
      Report an exception to Socorro.
      Parameters:
      thread - The exception thread
      exc - An exception
      Returns:
      Whether the exception was successfully reported
    • uncaughtException

      public void uncaughtException(@Nullable Thread thread, @NonNull Throwable exc)
      Implements the default behavior for handling uncaught exceptions.
      Specified by:
      uncaughtException in interface Thread.UncaughtExceptionHandler
      Parameters:
      thread - The exception thread
      exc - An uncaught exception
    • createDefaultCrashHandler

      @AnyThread @NonNull public static CrashHandler createDefaultCrashHandler(@NonNull Context context)
      Return a default CrashHandler object for all threads and thread groups.
      Parameters:
      context - application context
      Returns:
      a default CrashHandler object