Commit 1f12ec23 authored by Gang Wu's avatar Gang Wu Committed by Commit Bot

Add Build.Config to Bitmap if missing

There are crashes for gfx::CreateSkBitmapFromJavaBitmap(JavaBitmap) if
the JavaBitmap does not have Build#Config info. On Android O and before,
MediaStore.Images.Media.getBitmap will return a bitmap without the info
if the source image is gif.
This CL will regenerate a new bitmap if the bitmap has no info.

Bug: 1086990
Change-Id: Icb87d78a079c981270cbe57647c579f181bec5dc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2222548Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Reviewed-by: default avatarSami Kyöstilä <skyostil@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Commit-Queue: Gang Wu <gangwu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774307}
parent 94a21f41
......@@ -237,8 +237,15 @@ public class Clipboard implements ClipboardManager.OnPrimaryClipChangedListener
if (uri == null) return null;
// TODO(crbug.com/1065914): Use ImageDecoder.decodeBitmap for API level 29 and up.
return MediaStore.Images.Media.getBitmap(
Bitmap bitmap = MediaStore.Images.Media.getBitmap(
ContextUtils.getApplicationContext().getContentResolver(), uri);
if (bitmap != null && bitmap.getConfig() == null) {
// If bitmap do not have the config info, gfx::CreateSkBitmapFromJavaBitmap cannot
// handle it on native side.
return bitmap.copy(Bitmap.Config.ARGB_8888, /*mutable=*/false);
}
return bitmap;
} catch (IOException | SecurityException e) {
return null;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment