Do not draw snapshot starting window if allocate graphic buffer fail.

Preventing NPE crash.

Bug: 271472871
Test: simulate GraphicBuffer#create fail in SnapshotDrawer, and verify
no crash.

Change-Id: If3f9ad38a9b256f59bfd96258e43decb896a3604
This commit is contained in:
wilsonshih
2023-03-13 08:56:17 +00:00
parent 35b0657cbb
commit f4309a7b2a

View File

@@ -223,6 +223,11 @@ public class SnapshotDrawerUtils {
PixelFormat.RGBA_8888,
GraphicBuffer.USAGE_HW_TEXTURE | GraphicBuffer.USAGE_HW_COMPOSER
| GraphicBuffer.USAGE_SW_WRITE_RARELY);
if (background == null) {
Log.e(TAG, "Unable to draw snapshot: failed to allocate graphic buffer for "
+ mTitle);
return;
}
// TODO: Support this on HardwareBuffer
final Canvas c = background.lockCanvas();
drawBackgroundAndBars(c, frame);