A cross platform Audiobookshelf client for Android and iOS
Dart
Stop the media widget from crashing the app on Android 17
Barnabasb20db5ccd280
diff --git a/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidget.kt b/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidget.ktindex 6d49a397..5b822409 100644--- a/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidget.kt+++ b/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidget.kt@@ -30,7 +30,12 @@ class NowPlayingWidget : AppWidgetProvider() {appWidgetIds: IntArray) {for (appWidgetId in appWidgetIds) {- updateWidget(context, appWidgetManager, appWidgetId)+ // Never let a widget render failure crash the whole app.+ try {+ updateWidget(context, appWidgetManager, appWidgetId)+ } catch (e: Exception) {+ android.util.Log.e("NowPlayingWidget", "updateWidget failed", e)+ }}}@@ -158,8 +163,12 @@ class NowPlayingWidget : AppWidgetProvider() {if (bitmap != null) {val rounded = roundBitmap(bitmap, 18f, context)views.setImageViewBitmap(R.id.widget_cover, rounded)+ // Recycle only the source. RemoteViews serialises+ // `rounded` later in updateAppWidget (Android 17 copies+ // it to shared memory at that point) - recycling it here+ // throws "Can't copy a recycled bitmap" and crashes the+ // whole app when the widget is on the home screen.bitmap.recycle()- rounded.recycle()} else {views.setImageViewResource(R.id.widget_cover, R.mipmap.ic_launcher)}diff --git a/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidgetCompact.kt b/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidgetCompact.ktindex 0c9a7c1f..8e118cec 100644--- a/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidgetCompact.kt+++ b/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidgetCompact.kt@@ -30,7 +30,12 @@ class NowPlayingWidgetCompact : AppWidgetProvider() {appWidgetIds: IntArray) {for (appWidgetId in appWidgetIds) {- updateWidget(context, appWidgetManager, appWidgetId)+ // Never let a widget render failure crash the whole app.+ try {+ updateWidget(context, appWidgetManager, appWidgetId)+ } catch (e: Exception) {+ android.util.Log.e("NowPlayingWidgetCompact", "updateWidget failed", e)+ }}}@@ -144,8 +149,12 @@ class NowPlayingWidgetCompact : AppWidgetProvider() {if (bitmap != null) {val rounded = roundBitmap(bitmap, 24f, context)views.setImageViewBitmap(R.id.widget_cover, rounded)+ // Recycle only the source. RemoteViews serialises+ // `rounded` later in updateAppWidget (Android 17 copies+ // it to shared memory at that point) - recycling it here+ // throws "Can't copy a recycled bitmap" and crashes the+ // whole app when the widget is on the home screen.bitmap.recycle()- rounded.recycle()} else {views.setImageViewResource(R.id.widget_cover, R.mipmap.ic_launcher)}