From c8ba260b4d3201fb05fa4ed553cc7b6e7fed9d06 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Wed, 17 Jun 2020 17:16:01 -0700 Subject: [PATCH] Workaround for crash from invalid snapshot - wrapHardwareBuffer will throw an illegal argument exception when the buffer doesn't have this flag, but it's not clear how this happens yet because all the buffers should be from surface flinger snapshots... Bug: 157562905 Test: Manual Change-Id: I48be367d8aafb3e17f11a73a73432617a247c0dd Merged-In: I48be367d8aafb3e17f11a73a73432617a247c0dd --- .../shared/recents/model/ThumbnailData.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/recents/model/ThumbnailData.java b/packages/SystemUI/shared/src/com/android/systemui/shared/recents/model/ThumbnailData.java index eca6ebf7f8e5d..279a200949a54 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/recents/model/ThumbnailData.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/recents/model/ThumbnailData.java @@ -18,12 +18,17 @@ package com.android.systemui.shared.recents.model; import static android.app.WindowConfiguration.ROTATION_UNDEFINED; import static android.content.res.Configuration.ORIENTATION_UNDEFINED; +import static android.graphics.Bitmap.Config.ARGB_8888; import static com.android.systemui.shared.system.WindowManagerWrapper.WINDOWING_MODE_UNDEFINED; import android.app.ActivityManager.TaskSnapshot; import android.graphics.Bitmap; +import android.graphics.Color; +import android.graphics.GraphicBuffer; import android.graphics.Rect; +import android.hardware.HardwareBuffer; +import android.util.Log; /** * Data for a single thumbnail. @@ -57,7 +62,15 @@ public class ThumbnailData { } public ThumbnailData(TaskSnapshot snapshot) { - thumbnail = Bitmap.wrapHardwareBuffer(snapshot.getSnapshot(), snapshot.getColorSpace()); + final GraphicBuffer buffer = snapshot.getSnapshot(); + if (buffer != null && (buffer.getUsage() & HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE) == 0) { + // TODO(b/157562905): Workaround for a crash when we get a snapshot without this state + Log.e("ThumbnailData", "Unexpected snapshot without USAGE_GPU_SAMPLED_IMAGE"); + thumbnail = Bitmap.createBitmap(buffer.getWidth(), buffer.getHeight(), ARGB_8888); + thumbnail.eraseColor(Color.BLACK); + } else { + thumbnail = Bitmap.wrapHardwareBuffer(buffer, snapshot.getColorSpace()); + } insets = new Rect(snapshot.getContentInsets()); orientation = snapshot.getOrientation(); rotation = snapshot.getRotation();