Class KeyStoreExceptionHandler
-
- All Implemented Interfaces:
-
java.lang.Thread.UncaughtExceptionHandler
public final class KeyStoreExceptionHandler implements Thread.UncaughtExceptionHandlerA 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()
-
-
Constructor Summary
Constructors Constructor Description KeyStoreExceptionHandler(Application application, Function1<KeyStoreCorruptedException, Unit> onKeyStoreCorrupted)
-
Method Summary
Modifier and Type Method Description final Unitregister()final Unitunregister()UnituncaughtException(Thread thread, Throwable throwable)-
-
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.
-
-
Method Detail
-
register
final Unit register()
-
unregister
final Unit unregister()
-
uncaughtException
Unit uncaughtException(Thread thread, Throwable throwable)
-
-
-
-