From f44374600de8fb4f7e844c6441dfc2c7426055db Mon Sep 17 00:00:00 2001 From: Tyler Lacey Date: Wed, 2 Mar 2022 15:52:58 +0000 Subject: [PATCH] Fix captureTaskBitmap for tasks not positioned at top-left of screen. Bug: 221442494 Test: Manual testing Change-Id: I4c570d7f62293f22b60b981120888e9638a14654 --- .../java/com/android/server/wm/WindowManagerService.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 04f135e3e1b96..c0c11ae108878 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -3920,7 +3920,13 @@ public class WindowManagerService extends IWindowManager.Stub return null; } + // The bounds returned by the task represent the task's position on the screen. However, + // we need to specify a crop relative to the task's surface control. Therefore, shift + // the task's bounds to 0,0 so that we have the correct size and position within the + // task's surface control. task.getBounds(mTmpRect); + mTmpRect.offsetTo(0, 0); + final SurfaceControl sc = task.getSurfaceControl(); final SurfaceControl.ScreenshotHardwareBuffer buffer = SurfaceControl.captureLayers( layerCaptureArgsBuilder.setLayer(sc).setSourceCrop(mTmpRect).build());