Fix strictmode error logs due to task snapshot hw buffer not being closed

- Wrapping the buffer into a bitmap will add a reference so we can
  close the buffer once we convert the TaskSnapshot into a
  ThumbnailData
- Also probably shouldn't be creating a new ThumbnailData for each
  local task stack listener (most of whom don't actually handle this
  method)

Fixes: 165825625
Test: Check logs
Change-Id: I4d881721692a960ac40be848e49188afddbbc9c3
This commit is contained in:
Winson Chung
2021-06-23 23:49:42 -07:00
parent 146efcb572
commit 1f770ee834
2 changed files with 5 additions and 5 deletions

View File

@@ -62,16 +62,15 @@ public class ThumbnailData {
}
private static Bitmap makeThumbnail(TaskSnapshot snapshot) {
final HardwareBuffer buffer = snapshot.getHardwareBuffer();
Bitmap thumbnail = null;
try {
try (final HardwareBuffer buffer = snapshot.getHardwareBuffer()) {
if (buffer != null) {
thumbnail = Bitmap.wrapHardwareBuffer(buffer, snapshot.getColorSpace());
}
} catch (IllegalArgumentException ex) {
// 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: "
+ buffer, ex);
+ snapshot.getHardwareBuffer(), ex);
}
if (thumbnail == null) {
Point taskSize = snapshot.getTaskSize();

View File

@@ -292,9 +292,10 @@ public class TaskStackChangeListeners {
}
case ON_TASK_SNAPSHOT_CHANGED: {
Trace.beginSection("onTaskSnapshotChanged");
final TaskSnapshot snapshot = (TaskSnapshot) msg.obj;
final ThumbnailData thumbnail = new ThumbnailData(snapshot);
for (int i = mTaskStackListeners.size() - 1; i >= 0; i--) {
mTaskStackListeners.get(i).onTaskSnapshotChanged(msg.arg1,
new ThumbnailData((TaskSnapshot) msg.obj));
mTaskStackListeners.get(i).onTaskSnapshotChanged(msg.arg1, thumbnail);
}
Trace.endSection();
break;