Skip to content

Commit 0fffc9c

Browse files
committed
Keep default DefaultUncaughtExceptionHandler
1 parent ac390b2 commit 0fffc9c

File tree

2 files changed

+36
-32
lines changed

2 files changed

+36
-32
lines changed

app/src/main/java/com/philkes/notallyx/presentation/activity/LockedActivity.kt

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {

app/src/main/java/com/philkes/notallyx/presentation/viewmodel/BaseNoteModel.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ class BaseNoteModel(private val app: Application) : AndroidViewModel(app) {
114114
var reminders: LiveData<List<NoteReminder>> = NotNullLiveData(mutableListOf())
115115
private var allNotes: LiveData<List<BaseNote>>? = NotNullLiveData(mutableListOf())
116116
private var allNotesObserver: Observer<List<BaseNote>>? = null
117-
var baseNotes: Content? = Content(MutableLiveData(), { t -> t })
118-
var deletedNotes: Content? = Content(MutableLiveData(), { t -> t })
119-
var archivedNotes: Content? = Content(MutableLiveData(), { t -> t })
117+
var baseNotes: Content? = Content(MutableLiveData(), ::transform)
118+
var deletedNotes: Content? = Content(MutableLiveData(), ::transform)
119+
var archivedNotes: Content? = Content(MutableLiveData(), ::transform)
120120

121121
val folder = NotNullLiveData(Folder.NOTES)
122122

0 commit comments

Comments
 (0)