A small icon can have a large source image
A launcher draws icons, shortcuts, and widget previews from other apps. A crash record examined on September 23, 2026 pointed to Android’s drawing code, RecordingCanvas, rejecting a Bitmap above its byte-size limit. We checked the recorded line against the Android 34 SDK source.
Separate visual scaling from resizing image data
Reducing UI width and height does not reduce memory occupied by the source image. Resize when creating the image used for drawing.
We preserve the aspect ratio and limit the longer side to 1024 px without enlarging smaller images. This is an app-specific choice, not an Android-wide limit.
Provide fallback dimensions when size information is unavailable and prevent integer overflow in dimension multiplication. A 1024×1024 ARGB_8888 pixel buffer is about 4 MiB. The source image and extra drawing allocations need memory separately.
Use the same limit wherever images are received
Fixing icons alone leaves shortcuts and previews exposed to the same problem. We shared image conversion across those paths, including pin-confirmation screens.
Do not assume the size is safe because of its source. Normalize external images to the receiving app’s needs. Photo and thumbnail applications can use the same principle.
Code from the Fix
The following excerpts illustrate the fix; some examples omit surrounding code.
fun Drawable.toBoundedBitmap(maxDimension: Int = 1024): Bitmap {
val (width, height) = boundedBitmapSize(
intrinsicWidth, intrinsicHeight, maxDimension,
)
return toBitmap(width, height, Bitmap.Config.ARGB_8888)
}
Follow conversion through to drawing
Passing the converted image into actual drawing, rather than checking size arithmetic alone, helps establish whether the intervention is in the right place. Separate large, tall, wide, and invalid-dimension inputs to investigate missing boundary handling.
Trace image creation instead of stopping at visual scaling. This limits the converted image; it does not eliminate memory consumed when loading the source itself.
No comments:
Post a Comment