From 61fa52d8266417ecc12c7c4cedee14c469147af8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 24 Oct 2026 02:02:44 +0200 Subject: [PATCH] Android: Scale down the shortcut icon to fit the result intent The icon was padded to a full-width ARGB square, so a big ICON0 made the result too large for the binder transaction. finish() threw, we caught it, and the next finish (the back gesture) crashed with "Could not copy bitmap to parcel blob". Scale it to launcher icon size, and if finishing still fails, retry without the icon. Co-Authored-By: Claude Opus 5.5 (1M context) --- .../org/ppsspp/ppsspp/ShortcutActivity.java | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/android/src/org/ppsspp/ppsspp/ShortcutActivity.java b/android/src/org/ppsspp/ppsspp/ShortcutActivity.java index 7d59bb0fba..932fcffff1 100644 --- a/android/src/org/ppsspp/ppsspp/ShortcutActivity.java +++ b/android/src/org/ppsspp/ppsspp/ShortcutActivity.java @@ -7,6 +7,7 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Paint; +import android.graphics.Rect; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -26,6 +27,8 @@ public class ShortcutActivity extends Activity { private static final String TAG = "PPSSPP"; private static final int RESULT_OPEN_DOCUMENT = 2; + // xxxhdpi launcher icon size. + private static final int MAX_ICON_SIZE = 192; @Override protected void onCreate(Bundle savedInstanceState) { @@ -133,19 +136,21 @@ public class ShortcutActivity extends Activity { // Try to create a PNG from the iconData. Bitmap bmp = BitmapFactory.decodeByteArray(iconData, 0, iconData.length); if (bmp != null) { - // Pad the bitmap into a square, to keep it a nice 2:1 aspect ratio. - Bitmap paddedBitmap = Bitmap.createBitmap( - bmp.getWidth(), bmp.getWidth(), - Bitmap.Config.ARGB_8888); + // Pad the bitmap into a square, to keep it a nice 2:1 aspect ratio. The icon travels + // in the result intent, which has to fit in a binder transaction (1MB, shared), so + // scale big ones down to launcher icon size. + int size = Math.min(bmp.getWidth(), MAX_ICON_SIZE); + float scale = (float)size / bmp.getWidth(); + Bitmap paddedBitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(paddedBitmap); canvas.drawARGB(0, 0, 0, 0); - int y = (bmp.getWidth() - bmp.getHeight()) / 2; + int height = Math.round(bmp.getHeight() * scale); + int y = (size - height) / 2; if (y < 0) { // To be safe from wacky-aspect-ratio bitmaps. y = 0; } - canvas.drawBitmap(bmp, 0, y, new Paint(Paint.FILTER_BITMAP_FLAG)); - // Bitmap scaledBitmap = Bitmap.createScaledBitmap(bmp, 144, 72, true); + canvas.drawBitmap(bmp, null, new Rect(0, y, size, y + height), new Paint(Paint.FILTER_BITMAP_FLAG)); responseIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, paddedBitmap); bmp.recycle(); } @@ -172,6 +177,16 @@ public class ShortcutActivity extends Activity { finish(); } catch (Exception e) { NativeApp.reportException(e, "Error finishing respondToShortcutRequest"); + // Most likely the icon didn't fit in the transaction. Without this the result stays set, and + // the next finish (like from the back gesture) throws the same thing, uncaught. + responseIntent.removeExtra(Intent.EXTRA_SHORTCUT_ICON); + setResult(RESULT_OK, responseIntent); + try { + finish(); + } catch (Exception e2) { + NativeApp.reportException(e2, "Error finishing respondToShortcutRequest without the icon"); + setResult(RESULT_CANCELED); + } } Log.i(TAG, "End of respondToShortcutRequest"); }