@@ -80,43 +80,47 @@ abstract class LockedActivity<T : ViewBinding> : AppCompatActivity() {
8080 }
8181
8282 private fun setupGlobalExceptionHandler () {
83- Thread .setDefaultUncaughtExceptionHandler { _, throwable ->
84- lifecycleScope.launch {
85- EXCEPTION_HANDLER_MUTEX .withLock {
86- val time = System .currentTimeMillis()
87- if (
88- isExceptionAlreadyBeingHandled(time) &&
89- (throwable is SQLiteBlobTooBigException ||
90- throwable.cause is SQLiteBlobTooBigException )
91- ) {
92- EXCEPTION_HANDLER_MUTEX_LAST_TIMESTAMP = time
93- val migrationProgress =
94- MutableLiveData <MigrationProgress >().apply {
95- setupProgressDialog(this @LockedActivity)
96- postValue(
97- MigrationProgress (
98- R .string.migration_splitting_notes,
99- indeterminate = true ,
83+ val previousHandler = Thread .getDefaultUncaughtExceptionHandler()
84+ Thread .setDefaultUncaughtExceptionHandler { thread, throwable ->
85+ if (
86+ throwable is SQLiteBlobTooBigException ||
87+ throwable.cause is SQLiteBlobTooBigException
88+ ) {
89+ lifecycleScope.launch {
90+ EXCEPTION_HANDLER_MUTEX .withLock {
91+ val time = System .currentTimeMillis()
92+ if (! isExceptionAlreadyBeingHandled(time)) {
93+ EXCEPTION_HANDLER_MUTEX_LAST_TIMESTAMP = time
94+ val migrationProgress =
95+ MutableLiveData <MigrationProgress >().apply {
96+ setupProgressDialog(this @LockedActivity)
97+ postValue(
98+ MigrationProgress (
99+ R .string.migration_splitting_notes,
100+ indeterminate = true ,
101+ )
100102 )
101- )
102- }
103- log(
104- TAG ,
105- msg =
106- " SQLiteBlobTooBigException occurred, trying to fix broken notes... " ,
107- )
108- withContext( Dispatchers . IO ) { application.splitOversizedNotes() }
109- migrationProgress.postValue(
110- MigrationProgress ( R .string.migrating_data, inProgress = false )
111- )
103+ }
104+ log(
105+ TAG ,
106+ msg =
107+ " SQLiteBlobTooBigException occurred, trying to fix broken notes... " ,
108+ )
109+ withContext( Dispatchers . IO ) { application.splitOversizedNotes() }
110+ migrationProgress.postValue(
111+ MigrationProgress ( R .string.migrating_data, inProgress = false )
112+ )
113+ }
112114 }
113115 }
116+ } else {
117+ previousHandler?.uncaughtException(thread, throwable)
114118 }
115119 }
116120 }
117121
118122 private fun isExceptionAlreadyBeingHandled (time : Long ): Boolean =
119- EXCEPTION_HANDLER_MUTEX_LAST_TIMESTAMP ?.let { it.secondsBetween(time) > 20 } ? : true
123+ EXCEPTION_HANDLER_MUTEX_LAST_TIMESTAMP ?.let { it.secondsBetween(time) < 20 } ? : false
120124
121125 override fun onResume () {
122126 if (preferences.isLockEnabled) {
0 commit comments