mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 08:20:32 +05:30
fix: don't crash app when cronet thread fails
This commit is contained in:
parent
7ac50280fd
commit
0670bbf656
@ -1,11 +1,17 @@
|
|||||||
package com.github.libretube.util
|
package com.github.libretube.util
|
||||||
|
|
||||||
|
import android.os.Looper
|
||||||
import com.github.libretube.helpers.PreferenceHelper
|
import com.github.libretube.helpers.PreferenceHelper
|
||||||
|
|
||||||
class ExceptionHandler(
|
class ExceptionHandler(
|
||||||
private val defaultExceptionHandler: Thread.UncaughtExceptionHandler?
|
private val defaultExceptionHandler: Thread.UncaughtExceptionHandler?
|
||||||
) : Thread.UncaughtExceptionHandler {
|
) : Thread.UncaughtExceptionHandler {
|
||||||
override fun uncaughtException(thread: Thread, exc: Throwable) {
|
override fun uncaughtException(thread: Thread, exc: Throwable) {
|
||||||
|
// if the exception is not on the main thread, the app is still functional and responsive
|
||||||
|
// hence the app doesn't have to be quit fully
|
||||||
|
// work around for Cronet spawning different threads with uncaught Exception when used with Coil
|
||||||
|
if (thread.id != Looper.getMainLooper().thread.id) return
|
||||||
|
|
||||||
// save the error log
|
// save the error log
|
||||||
PreferenceHelper.saveErrorLog(exc.stackTraceToString())
|
PreferenceHelper.saveErrorLog(exc.stackTraceToString())
|
||||||
// throw the exception with the default exception handler to make the app crash
|
// throw the exception with the default exception handler to make the app crash
|
||||||
|
Loading…
x
Reference in New Issue
Block a user