widget: aggressively clamp bitmap size anyway

Just a test
This commit is contained in:
Alexander Capehart 2024-08-07 17:41:35 -06:00
parent c11e03b451
commit a33bbd9cec
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47

View file

@ -48,7 +48,7 @@ fun newRemoteViews(context: Context, @LayoutRes layoutRes: Int): RemoteViews {
return views return views
} }
const val MINIMUM_OBSERVED_MAX_SAFE_BITMAP_SIZE = 6912000 * 0.95f // 95% slack const val MINIMUM_OBSERVED_MAX_SAFE_BITMAP_SIZE = (6912000 * 0.95f).toInt() // 95% slack
/** /**
* Get an image size guaranteed to not exceed the [RemoteViews] bitmap memory limit, assuming that * Get an image size guaranteed to not exceed the [RemoteViews] bitmap memory limit, assuming that
@ -67,7 +67,8 @@ fun getSafeRemoteViewsImageSize(reduce: Float = 2f): Int {
// Cap memory usage at 1.5 times the size of the display // Cap memory usage at 1.5 times the size of the display
// 1.5 * 4 bytes/pixel * w * h ==> 6 * w * h // 1.5 * 4 bytes/pixel * w * h ==> 6 * w * h
// https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java // https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java
val maxWidgetBitmapMemory = 6 * sw * sh // Of course since OEMs randomly patch this check, we have to also end up just capping it.
val maxWidgetBitmapMemory = min(6 * sw * sh, MINIMUM_OBSERVED_MAX_SAFE_BITMAP_SIZE)
val maxBitmapArea = (maxWidgetBitmapMemory / 4) / reduce val maxBitmapArea = (maxWidgetBitmapMemory / 4) / reduce
val maxBitmapSize = sqrt(maxBitmapArea).toInt() val maxBitmapSize = sqrt(maxBitmapArea).toInt()
return maxBitmapSize; return maxBitmapSize;