From ebc00c51bf573661cbe9ed43ee9ca19ee6560ba2 Mon Sep 17 00:00:00 2001 From: chaviw Date: Thu, 30 Jul 2020 14:08:48 -0700 Subject: [PATCH] Capture secure layers in SurfaceFreezer Allow SurfaceFreezer to capture secure layers and then place the buffer into a secure SurfaceControl if something captured was secure Test: Maximize secure freeform window Bug: 156890155 Change-Id: I4dc493516b87582cb6f0a7b3c1312e9baf895e6b --- core/java/android/view/SurfaceControl.java | 7 ++++++ .../com/android/server/wm/SurfaceFreezer.java | 25 +++++++++++-------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java index 50ed00cd0aa77..2ce993dfedca7 100644 --- a/core/java/android/view/SurfaceControl.java +++ b/core/java/android/view/SurfaceControl.java @@ -2389,6 +2389,13 @@ public final class SurfaceControl implements Parcelable { return nativeCaptureLayers(captureArgs); } + /** + * @hide + */ + public static ScreenshotHardwareBuffer captureLayers(LayerCaptureArgs captureArgs) { + return nativeCaptureLayers(captureArgs); + } + /** * Like {@link #captureLayers(SurfaceControl, Rect, float, int)} but with an array of layer * handles to exclude. diff --git a/services/core/java/com/android/server/wm/SurfaceFreezer.java b/services/core/java/com/android/server/wm/SurfaceFreezer.java index 5cea786c3367a..1c9743041923e 100644 --- a/services/core/java/com/android/server/wm/SurfaceFreezer.java +++ b/services/core/java/com/android/server/wm/SurfaceFreezer.java @@ -22,7 +22,6 @@ import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_SCREEN_ROTATI import android.annotation.NonNull; import android.annotation.Nullable; -import android.graphics.ColorSpace; import android.graphics.PixelFormat; import android.graphics.Rect; import android.hardware.HardwareBuffer; @@ -89,8 +88,7 @@ class SurfaceFreezer { if (buffer == null || buffer.getWidth() <= 1 || buffer.getHeight() <= 1) { return; } - mSnapshot = new Snapshot(mWmService.mSurfaceFactory, t, buffer, - screenshotBuffer.getColorSpace(), mLeash); + mSnapshot = new Snapshot(mWmService.mSurfaceFactory, t, screenshotBuffer, mLeash); } } @@ -135,8 +133,12 @@ class SurfaceFreezer { cropBounds = new Rect(bounds); cropBounds.offsetTo(0, 0); } - return SurfaceControl.captureLayers(target, cropBounds, 1.f /* frameScale */, - PixelFormat.RGBA_8888); + SurfaceControl.LayerCaptureArgs captureArgs = + new SurfaceControl.LayerCaptureArgs.Builder(target) + .setSourceCrop(cropBounds) + .setCaptureSecureLayers(true) + .build(); + return SurfaceControl.captureLayers(captureArgs); } class Snapshot { @@ -146,21 +148,23 @@ class SurfaceFreezer { /** * @param t Transaction to create the thumbnail in. - * @param thumbnailHeader A thumbnail or placeholder for thumbnail to initialize with. + * @param screenshotBuffer A thumbnail or placeholder for thumbnail to initialize with. */ Snapshot(Supplier surfaceFactory, SurfaceControl.Transaction t, - HardwareBuffer thumbnailHeader, ColorSpace colorSpace, SurfaceControl parent) { + SurfaceControl.ScreenshotHardwareBuffer screenshotBuffer, SurfaceControl parent) { Surface drawSurface = surfaceFactory.get(); // We can't use a delegating constructor since we need to // reference this::onAnimationFinished - final int width = thumbnailHeader.getWidth(); - final int height = thumbnailHeader.getHeight(); + HardwareBuffer hardwareBuffer = screenshotBuffer.getHardwareBuffer(); + final int width = hardwareBuffer.getWidth(); + final int height = hardwareBuffer.getHeight(); mSurfaceControl = mAnimatable.makeAnimationLeash() .setName("snapshot anim: " + mAnimatable.toString()) .setBufferSize(width, height) .setFormat(PixelFormat.TRANSLUCENT) .setParent(parent) + .setSecure(screenshotBuffer.containsSecureLayers()) .setCallsite("SurfaceFreezer.Snapshot") .build(); @@ -168,7 +172,8 @@ class SurfaceFreezer { // Transfer the thumbnail to the surface drawSurface.copyFrom(mSurfaceControl); - drawSurface.attachAndQueueBufferWithColorSpace(thumbnailHeader, colorSpace); + drawSurface.attachAndQueueBufferWithColorSpace(hardwareBuffer, + screenshotBuffer.getColorSpace()); drawSurface.release(); t.show(mSurfaceControl);