Skip to content
Snippets Groups Projects
Commit 9dcc353d authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Improve ML exception handler

- Throw an esception in debug build
- Add a log line to help debugging
- Move it to the companion object for safety

(cherry picked from commit 5fb016ea)
parent fa8a38f9
No related branches found
Tags 3.0.12.1
No related merge requests found
......@@ -83,12 +83,22 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope, Lifec
private var discoverTriggered = false
internal val sb = StringBuilder()
private val notificationActor by lazy {
actor<Notification>(capacity = Channel.UNLIMITED) {
for (update in channel) when (update) {
Show -> showNotification()
Hide -> hideNotification()
}
}
}
private val exceptionHandler = if (BuildConfig.BETA) AbstractMedialibrary.MedialibraryExceptionHandler { context, errMsg, _ ->
val intent = Intent(applicationContext, SendCrashActivity::class.java).apply {
putExtra(CRASH_ML_CTX, context)
putExtra(CRASH_ML_MSG, errMsg)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
Log.wtf(TAG, "medialibrary reported unhandled exception: -----------------")
// Lock the Medialibrary thread during DB extraction.
runBlocking {
SendCrashActivity.job = Job()
......@@ -99,17 +109,10 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope, Lifec
SendCrashActivity.job = null
}
}
} else if (BuildConfig.DEBUG) AbstractMedialibrary.MedialibraryExceptionHandler { context, errMsg, _ ->
throw IllegalStateException("$context:\n$errMsg")
} else null
private val notificationActor by lazy {
actor<Notification>(capacity = Channel.UNLIMITED) {
for (update in channel) when (update) {
Show -> showNotification()
Hide -> hideNotification()
}
}
}
override fun attachBaseContext(newBase: Context?) {
super.attachBaseContext(newBase?.getContextWithLocale())
}
......@@ -139,6 +142,7 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope, Lifec
exitCommand()
}
})
medialibrary.exceptionHandler = exceptionHandler
}
override fun onBind(intent: Intent): IBinder? {
......@@ -391,6 +395,7 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope, Lifec
unregisterReceiver(receiver)
localBroadcastManager.unregisterReceiver(receiver)
if (wakeLock.isHeld) wakeLock.release()
medialibrary.exceptionHandler = null
super.onDestroy()
}
......@@ -419,7 +424,6 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope, Lifec
val context = this@MediaParsingService
var shouldInit = !dbExists()
val initCode = medialibrary.init(context)
medialibrary.exceptionHandler = exceptionHandler
if (initCode != AbstractMedialibrary.ML_INIT_ALREADY_INITIALIZED) {
shouldInit = shouldInit or (initCode == AbstractMedialibrary.ML_INIT_DB_RESET) or (initCode == AbstractMedialibrary.ML_INIT_DB_CORRUPTED)
if (initCode != AbstractMedialibrary.ML_INIT_FAILED) initMedialib(action.parse, context, shouldInit, action.upgrade)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment