Class KeyStoreExceptionHandler

  • All Implemented Interfaces:
    java.lang.Thread.UncaughtExceptionHandler

    
    public final class KeyStoreExceptionHandler
     implements Thread.UncaughtExceptionHandler
                        

    A global exception handler to catch KeyStoreCorruptedException and clear the related shared preferences. This is necessary because when the Android KeyStore is corrupted, it can cause the app to crash repeatedly until the user clears the app data. By catching the exception and clearing the shared preferences, we can prevent the app from crashing and allow it to recover gracefully.

    Usage: val keyStoreExceptionHandler = KeyStoreExceptionHandler(application) { ex -> // Optional: Handle additional actions when KeyStore corruption is detected } keyStoreExceptionHandler.register()

    Don't forget to unregister the handler when it's no longer needed: keyStoreExceptionHandler.unregister()

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Unit register()
      final Unit unregister()
      Unit uncaughtException(Thread thread, Throwable throwable)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • KeyStoreExceptionHandler

        KeyStoreExceptionHandler(Application application, Function1<KeyStoreCorruptedException, Unit> onKeyStoreCorrupted)
        Parameters:
        application - The application context used to access shared preferences.
        onKeyStoreCorrupted - An optional callback that will be invoked when a KeyStoreCorruptedException is detected, allowing for additional handling such as deleting the related database.