[Android] Improve ML exception handler
Geoffrey Métais
git at videolan.org
Thu Oct 17 17:01:11 CEST 2019
vlc-android | branch: 3.2.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Oct 17 16:45:45 2019 +0200| [9dcc353d201c2f45d33fbd1ad4b5ac1c92c24e38] | committer: Geoffrey Métais
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 5fb016eab9fc846eb2d3437e02d09272ac4f47ee)
> https://code.videolan.org/videolan/vlc-android/commit/9dcc353d201c2f45d33fbd1ad4b5ac1c92c24e38
---
.../src/org/videolan/vlc/MediaParsingService.kt | 24 +++++++++++++---------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/MediaParsingService.kt b/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
index fcc6314a4..0275d4e35 100644
--- a/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
+++ b/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
@@ -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 at 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)
More information about the Android
mailing list