widget: more logging

This commit is contained in:
Alexander Capehart 2024-08-06 19:02:24 -06:00
parent b185914ba1
commit 3e4b27d76b
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47

View file

@ -121,26 +121,20 @@ class WidgetProvider : AppWidgetProvider() {
awm.updateAppWidgetCompat(context, component, views) awm.updateAppWidgetCompat(context, component, views)
logD("Successfully updated RemoteViews layout") logD("Successfully updated RemoteViews layout")
return return
} catch (e: IllegalArgumentException) { } catch (e: Exception) {
val msg = e.message ?: return logW("Encountered widget error: $e")
if (!msg.startsWith( logW("Widget message: ${e.message}")
"RemoteViews for widget update exceeds maximum bitmap memory usage")) {
throw e
}
// Some android devices on Android 12-14 suffer from a bug where the maximum bitmap // Some android devices on Android 12-14 suffer from a bug where the maximum bitmap
// size calculation does not factor in bitmaps shared across multiple RemoteView // size calculation does not factor in bitmaps shared across multiple RemoteView
// forms. // forms.
// To mitigate an outright crash, progressively disable layouts that contain cover // To mitigate an outright crash, progressively disable layouts that contain cover
// art // art
// in order of least to most commonly used until it actually works. // in order of least to most commonly used until it actually works.
logW("Killing layout: ${victims.first()}, remaining: ${victims.size - 1}")
val victim = victims.first() val victim = victims.first()
val view = views.entries.find { it.value.layoutId == victim } ?: continue val view = views.entries.find { it.value.layoutId == victim } ?: continue
view.value.setImageViewBitmap(R.id.widget_cover, null) view.value.setImageViewBitmap(R.id.widget_cover, null)
victims.remove(victim) victims.remove(victim)
} catch (e: Exception) {
// Layout update failed, gracefully degrade to the default widget.
logW("Unable to update widget: $e")
reset(context, uiSettings)
} }
} }
// We flat-out cannot fit the bitmap into the widget. Weird. // We flat-out cannot fit the bitmap into the widget. Weird.