diff options
author | 2020-07-30 13:57:36 -0700 | |
---|---|---|
committer | 2020-08-06 13:44:39 -0700 | |
commit | 70cb6a4c74231865b8ecff558ecb11df066fff8a (patch) | |
tree | 10ff03affa23c6fe60e38fcebf829835ccfa246a | |
parent | e80116fe4ad4f7a971aa0c431911c516ad711bb3 (diff) |
Added ability to capture secure layers in captureLayers
Bug: 156890155
Test: Maximize secure freeform window
Test: ScreenCaptureTest
Change-Id: I05fdd145ece6840192895822cf1a8ee34cf7871b
-rw-r--r-- | libs/gui/include/gui/LayerState.h | 2 | ||||
-rw-r--r-- | services/surfaceflinger/DisplayRenderArea.cpp | 5 | ||||
-rw-r--r-- | services/surfaceflinger/DisplayRenderArea.h | 1 | ||||
-rw-r--r-- | services/surfaceflinger/LayerRenderArea.cpp | 6 | ||||
-rw-r--r-- | services/surfaceflinger/LayerRenderArea.h | 3 | ||||
-rw-r--r-- | services/surfaceflinger/RenderArea.h | 9 | ||||
-rw-r--r-- | services/surfaceflinger/SurfaceFlinger.cpp | 6 | ||||
-rw-r--r-- | services/surfaceflinger/tests/LayerTypeTransaction_test.cpp | 6 | ||||
-rw-r--r-- | services/surfaceflinger/tests/ScreenCapture_test.cpp | 151 | ||||
-rw-r--r-- | services/surfaceflinger/tests/utils/ScreenshotUtils.h | 47 |
10 files changed, 133 insertions, 103 deletions
diff --git a/libs/gui/include/gui/LayerState.h b/libs/gui/include/gui/LayerState.h index de3a9a7b29..5e1066ba68 100644 --- a/libs/gui/include/gui/LayerState.h +++ b/libs/gui/include/gui/LayerState.h @@ -339,7 +339,7 @@ struct DisplayCaptureArgs : CaptureArgs { struct LayerCaptureArgs : CaptureArgs { sp<IBinder> layerHandle; std::unordered_set<sp<IBinder>, ISurfaceComposer::SpHash<IBinder>> excludeHandles; - bool childrenOnly{true}; + bool childrenOnly{false}; status_t write(Parcel& output) const override; status_t read(const Parcel& input) override; diff --git a/services/surfaceflinger/DisplayRenderArea.cpp b/services/surfaceflinger/DisplayRenderArea.cpp index bcebf232dc..4bae669d7c 100644 --- a/services/surfaceflinger/DisplayRenderArea.cpp +++ b/services/surfaceflinger/DisplayRenderArea.cpp @@ -85,10 +85,9 @@ DisplayRenderArea::DisplayRenderArea(sp<const DisplayDevice> display, const Rect ui::Size reqSize, ui::Dataspace reqDataSpace, RotationFlags rotation, bool allowSecureLayers) : RenderArea(reqSize, CaptureFill::OPAQUE, reqDataSpace, display->getViewport(), - applyDeviceOrientation(rotation, *display)), + allowSecureLayers, applyDeviceOrientation(rotation, *display)), mDisplay(std::move(display)), - mSourceCrop(sourceCrop), - mAllowSecureLayers(allowSecureLayers) {} + mSourceCrop(sourceCrop) {} const ui::Transform& DisplayRenderArea::getTransform() const { return mTransform; diff --git a/services/surfaceflinger/DisplayRenderArea.h b/services/surfaceflinger/DisplayRenderArea.h index 340efb566f..8840973a5a 100644 --- a/services/surfaceflinger/DisplayRenderArea.h +++ b/services/surfaceflinger/DisplayRenderArea.h @@ -47,7 +47,6 @@ private: const sp<const DisplayDevice> mDisplay; const Rect mSourceCrop; - const bool mAllowSecureLayers; const ui::Transform mTransform; }; diff --git a/services/surfaceflinger/LayerRenderArea.cpp b/services/surfaceflinger/LayerRenderArea.cpp index c4f8666de5..555e61d4ef 100644 --- a/services/surfaceflinger/LayerRenderArea.cpp +++ b/services/surfaceflinger/LayerRenderArea.cpp @@ -44,8 +44,8 @@ struct ReparentForDrawing { LayerRenderArea::LayerRenderArea(SurfaceFlinger& flinger, sp<Layer> layer, const Rect& crop, ui::Size reqSize, ui::Dataspace reqDataSpace, bool childrenOnly, - const Rect& displayViewport) - : RenderArea(reqSize, CaptureFill::CLEAR, reqDataSpace, displayViewport), + const Rect& displayViewport, bool allowSecureLayers) + : RenderArea(reqSize, CaptureFill::CLEAR, reqDataSpace, displayViewport, allowSecureLayers), mLayer(std::move(layer)), mCrop(crop), mFlinger(flinger), @@ -68,7 +68,7 @@ int LayerRenderArea::getWidth() const { } bool LayerRenderArea::isSecure() const { - return false; + return mAllowSecureLayers; } bool LayerRenderArea::needsFiltering() const { diff --git a/services/surfaceflinger/LayerRenderArea.h b/services/surfaceflinger/LayerRenderArea.h index 81690b9a7e..71ff1ce957 100644 --- a/services/surfaceflinger/LayerRenderArea.h +++ b/services/surfaceflinger/LayerRenderArea.h @@ -33,7 +33,8 @@ class SurfaceFlinger; class LayerRenderArea : public RenderArea { public: LayerRenderArea(SurfaceFlinger& flinger, sp<Layer> layer, const Rect& crop, ui::Size reqSize, - ui::Dataspace reqDataSpace, bool childrenOnly, const Rect& displayViewport); + ui::Dataspace reqDataSpace, bool childrenOnly, const Rect& displayViewport, + bool allowSecureLayers); const ui::Transform& getTransform() const override; Rect getBounds() const override; diff --git a/services/surfaceflinger/RenderArea.h b/services/surfaceflinger/RenderArea.h index a6246d9a6a..b4bddacba4 100644 --- a/services/surfaceflinger/RenderArea.h +++ b/services/surfaceflinger/RenderArea.h @@ -24,8 +24,10 @@ public: static float getCaptureFillValue(CaptureFill captureFill); RenderArea(ui::Size reqSize, CaptureFill captureFill, ui::Dataspace reqDataSpace, - const Rect& displayViewport, RotationFlags rotation = ui::Transform::ROT_0) - : mReqSize(reqSize), + const Rect& displayViewport, bool allowSecureLayers = false, + RotationFlags rotation = ui::Transform::ROT_0) + : mAllowSecureLayers(allowSecureLayers), + mReqSize(reqSize), mReqDataSpace(reqDataSpace), mCaptureFill(captureFill), mRotationFlags(rotation), @@ -83,6 +85,9 @@ public: // Returns the source display viewport. const Rect& getDisplayViewport() const { return mDisplayViewport; } +protected: + const bool mAllowSecureLayers; + private: const ui::Size mReqSize; const ui::Dataspace mReqDataSpace; diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 0d9080d60d..4c973e250e 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -5592,6 +5592,7 @@ status_t SurfaceFlinger::captureLayers(const LayerCaptureArgs& args, std::unordered_set<sp<Layer>, ISurfaceComposer::SpHash<Layer>> excludeLayers; Rect displayViewport; ui::Dataspace dataspace; + bool captureSecureLayers; { Mutex::Autolock lock(mStateLock); @@ -5645,6 +5646,8 @@ status_t SurfaceFlinger::captureLayers(const LayerCaptureArgs& args, const ui::ColorMode colorMode = display->getCompositionDisplay()->getState().colorMode; dataspace = pickDataspaceFromColorMode(colorMode); + + captureSecureLayers = args.captureSecureLayers && display->isSecure(); } // mStateLock // really small crop or frameScale @@ -5659,7 +5662,8 @@ status_t SurfaceFlinger::captureLayers(const LayerCaptureArgs& args, RenderAreaFuture renderAreaFuture = promise::defer([=]() -> std::unique_ptr<RenderArea> { return std::make_unique<LayerRenderArea>(*this, parent, crop, reqSize, dataspace, - childrenOnly, displayViewport); + childrenOnly, displayViewport, + captureSecureLayers); }); auto traverseLayers = [parent, childrenOnly, diff --git a/services/surfaceflinger/tests/LayerTypeTransaction_test.cpp b/services/surfaceflinger/tests/LayerTypeTransaction_test.cpp index 2ec4ea48a3..e3b9489c6e 100644 --- a/services/surfaceflinger/tests/LayerTypeTransaction_test.cpp +++ b/services/surfaceflinger/tests/LayerTypeTransaction_test.cpp @@ -61,8 +61,10 @@ TEST_P(LayerTypeTransactionTest, SetRelativeZNegative) { std::unique_ptr<ScreenCapture> screenshot; // only layerB is in this range - sp<IBinder> parentHandle = parent->getHandle(); - ScreenCapture::captureLayers(&screenshot, parentHandle, Rect(0, 0, 32, 32)); + LayerCaptureArgs captureArgs; + captureArgs.layerHandle = parent->getHandle(); + captureArgs.sourceCrop = {0, 0, 32, 32}; + ScreenCapture::captureLayers(&screenshot, captureArgs); screenshot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); } diff --git a/services/surfaceflinger/tests/ScreenCapture_test.cpp b/services/surfaceflinger/tests/ScreenCapture_test.cpp index 2a250ff52e..149e4d7f78 100644 --- a/services/surfaceflinger/tests/ScreenCapture_test.cpp +++ b/services/surfaceflinger/tests/ScreenCapture_test.cpp @@ -18,6 +18,8 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wconversion" +#include <private/android_filesystem_config.h> + #include "LayerTransactionTest.h" namespace android { @@ -73,16 +75,15 @@ protected: }; TEST_F(ScreenCaptureTest, CaptureSingleLayer) { - auto bgHandle = mBGSurfaceControl->getHandle(); - ScreenCapture::captureLayers(&mCapture, bgHandle); + LayerCaptureArgs captureArgs; + captureArgs.layerHandle = mBGSurfaceControl->getHandle(); + ScreenCapture::captureLayers(&mCapture, captureArgs); mCapture->expectBGColor(0, 0); // Doesn't capture FG layer which is at 64, 64 mCapture->expectBGColor(64, 64); } TEST_F(ScreenCaptureTest, CaptureLayerWithChild) { - auto fgHandle = mFGSurfaceControl->getHandle(); - sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); TransactionUtils::fillSurfaceRGBA8(child, 200, 200, 200); @@ -90,7 +91,9 @@ TEST_F(ScreenCaptureTest, CaptureLayerWithChild) { SurfaceComposerClient::Transaction().show(child).apply(true); // Captures mFGSurfaceControl layer and its child. - ScreenCapture::captureLayers(&mCapture, fgHandle); + LayerCaptureArgs captureArgs; + captureArgs.layerHandle = mFGSurfaceControl->getHandle(); + ScreenCapture::captureLayers(&mCapture, captureArgs); mCapture->expectFGColor(10, 10); mCapture->expectChildColor(0, 0); } @@ -105,7 +108,10 @@ TEST_F(ScreenCaptureTest, CaptureLayerChildOnly) { SurfaceComposerClient::Transaction().show(child).apply(true); // Captures mFGSurfaceControl's child - ScreenCapture::captureChildLayers(&mCapture, fgHandle); + LayerCaptureArgs captureArgs; + captureArgs.layerHandle = fgHandle; + captureArgs.childrenOnly = true; + ScreenCapture::captureLayers(&mCapture, captureArgs); mCapture->checkPixel(10, 10, 0, 0, 0); mCapture->expectChildColor(0, 0); } @@ -128,7 +134,11 @@ TEST_F(ScreenCaptureTest, CaptureLayerExclude) { .apply(true); // Child2 would be visible but its excluded, so we should see child1 color instead. - ScreenCapture::captureChildLayersExcluding(&mCapture, fgHandle, {child2->getHandle()}); + LayerCaptureArgs captureArgs; + captureArgs.layerHandle = fgHandle; + captureArgs.childrenOnly = true; + captureArgs.excludeHandles = {child2->getHandle()}; + ScreenCapture::captureLayers(&mCapture, captureArgs); mCapture->checkPixel(10, 10, 0, 0, 0); mCapture->checkPixel(0, 0, 200, 200, 200); } @@ -156,7 +166,11 @@ TEST_F(ScreenCaptureTest, CaptureLayerExcludeTree) { .apply(true); // Child2 would be visible but its excluded, so we should see child1 color instead. - ScreenCapture::captureChildLayersExcluding(&mCapture, fgHandle, {child2->getHandle()}); + LayerCaptureArgs captureArgs; + captureArgs.layerHandle = fgHandle; + captureArgs.childrenOnly = true; + captureArgs.excludeHandles = {child2->getHandle()}; + ScreenCapture::captureLayers(&mCapture, captureArgs); mCapture->checkPixel(10, 10, 0, 0, 0); mCapture->checkPixel(0, 0, 200, 200, 200); } @@ -169,18 +183,17 @@ TEST_F(ScreenCaptureTest, CaptureTransparent) { SurfaceComposerClient::Transaction().show(child).apply(true); - auto childHandle = child->getHandle(); - // Captures child - ScreenCapture::captureLayers(&mCapture, childHandle, {0, 0, 10, 20}); + LayerCaptureArgs captureArgs; + captureArgs.layerHandle = child->getHandle(); + captureArgs.sourceCrop = {0, 0, 10, 20}; + ScreenCapture::captureLayers(&mCapture, captureArgs); mCapture->expectColor(Rect(0, 0, 9, 9), {200, 200, 200, 255}); // Area outside of child's bounds is transparent. mCapture->expectColor(Rect(0, 10, 9, 19), {0, 0, 0, 0}); } TEST_F(ScreenCaptureTest, DontCaptureRelativeOutsideTree) { - auto fgHandle = mFGSurfaceControl->getHandle(); - sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); ASSERT_NE(nullptr, child.get()) << "failed to create surface"; @@ -191,19 +204,19 @@ TEST_F(ScreenCaptureTest, DontCaptureRelativeOutsideTree) { SurfaceComposerClient::Transaction() .show(child) // Set relative layer above fg layer so should be shown above when computing all layers. - .setRelativeLayer(relative, fgHandle, 1) + .setRelativeLayer(relative, mFGSurfaceControl->getHandle(), 1) .show(relative) .apply(true); // Captures mFGSurfaceControl layer and its child. Relative layer shouldn't be captured. - ScreenCapture::captureLayers(&mCapture, fgHandle); + LayerCaptureArgs captureArgs; + captureArgs.layerHandle = mFGSurfaceControl->getHandle(); + ScreenCapture::captureLayers(&mCapture, captureArgs); mCapture->expectFGColor(10, 10); mCapture->expectChildColor(0, 0); } TEST_F(ScreenCaptureTest, CaptureRelativeInTree) { - auto fgHandle = mFGSurfaceControl->getHandle(); - sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); sp<SurfaceControl> relative = createSurface(mClient, "Relative surface", 10, 10, @@ -222,7 +235,9 @@ TEST_F(ScreenCaptureTest, CaptureRelativeInTree) { // Captures mFGSurfaceControl layer and its children. Relative layer is a child of fg so its // relative value should be taken into account, placing it above child layer. - ScreenCapture::captureLayers(&mCapture, fgHandle); + LayerCaptureArgs captureArgs; + captureArgs.layerHandle = mFGSurfaceControl->getHandle(); + ScreenCapture::captureLayers(&mCapture, captureArgs); mCapture->expectFGColor(10, 10); // Relative layer is showing on top of child layer mCapture->expectColor(Rect(0, 0, 9, 9), {100, 100, 100, 255}); @@ -232,10 +247,10 @@ TEST_F(ScreenCaptureTest, CaptureBoundlessLayerWithSourceCrop) { sp<SurfaceControl> child = createColorLayer("Child layer", Color::RED, mFGSurfaceControl.get()); SurfaceComposerClient::Transaction().show(child).apply(true); - sp<ISurfaceComposer> sf(ComposerService::getComposerService()); - Rect sourceCrop(0, 0, 10, 10); - sp<IBinder> childHandle = child->getHandle(); - ScreenCapture::captureLayers(&mCapture, childHandle, sourceCrop); + LayerCaptureArgs captureArgs; + captureArgs.layerHandle = child->getHandle(); + captureArgs.sourceCrop = {0, 0, 10, 10}; + ScreenCapture::captureLayers(&mCapture, captureArgs); mCapture->expectColor(Rect(0, 0, 9, 9), Color::RED); } @@ -245,10 +260,9 @@ TEST_F(ScreenCaptureTest, CaptureBoundedLayerWithoutSourceCrop) { Rect layerCrop(0, 0, 10, 10); SurfaceComposerClient::Transaction().setCrop_legacy(child, layerCrop).show(child).apply(true); - sp<ISurfaceComposer> sf(ComposerService::getComposerService()); - sp<GraphicBuffer> outBuffer; - sp<IBinder> childHandle = child->getHandle(); - ScreenCapture::captureLayers(&mCapture, childHandle); + LayerCaptureArgs captureArgs; + captureArgs.layerHandle = child->getHandle(); + ScreenCapture::captureLayers(&mCapture, captureArgs); mCapture->expectColor(Rect(0, 0, 9, 9), Color::RED); } @@ -289,8 +303,6 @@ TEST_F(ScreenCaptureTest, CaptureBufferLayerWithoutBufferFails) { } TEST_F(ScreenCaptureTest, CaptureLayerWithGrandchild) { - auto fgHandle = mFGSurfaceControl->getHandle(); - sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); TransactionUtils::fillSurfaceRGBA8(child, 200, 200, 200); @@ -306,7 +318,9 @@ TEST_F(ScreenCaptureTest, CaptureLayerWithGrandchild) { .apply(true); // Captures mFGSurfaceControl, its child, and the grandchild. - ScreenCapture::captureLayers(&mCapture, fgHandle); + LayerCaptureArgs captureArgs; + captureArgs.layerHandle = mFGSurfaceControl->getHandle(); + ScreenCapture::captureLayers(&mCapture, captureArgs); mCapture->expectFGColor(10, 10); mCapture->expectChildColor(0, 0); mCapture->checkPixel(5, 5, 50, 50, 50); @@ -316,12 +330,13 @@ TEST_F(ScreenCaptureTest, CaptureChildOnly) { sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); TransactionUtils::fillSurfaceRGBA8(child, 200, 200, 200); - auto childHandle = child->getHandle(); SurfaceComposerClient::Transaction().setPosition(child, 5, 5).show(child).apply(true); // Captures only the child layer, and not the parent. - ScreenCapture::captureLayers(&mCapture, childHandle); + LayerCaptureArgs captureArgs; + captureArgs.layerHandle = child->getHandle(); + ScreenCapture::captureLayers(&mCapture, captureArgs); mCapture->expectChildColor(0, 0); mCapture->expectChildColor(9, 9); } @@ -342,10 +357,10 @@ TEST_F(ScreenCaptureTest, CaptureGrandchildOnly) { .show(grandchild) .apply(true); - auto grandchildHandle = grandchild->getHandle(); - // Captures only the grandchild. - ScreenCapture::captureLayers(&mCapture, grandchildHandle); + LayerCaptureArgs captureArgs; + captureArgs.layerHandle = grandchild->getHandle(); + ScreenCapture::captureLayers(&mCapture, captureArgs); mCapture->checkPixel(0, 0, 50, 50, 50); mCapture->checkPixel(4, 4, 50, 50, 50); } @@ -364,18 +379,18 @@ TEST_F(ScreenCaptureTest, CaptureCrop) { .show(blueLayer) .apply(true); - auto redLayerHandle = redLayer->getHandle(); - // Capturing full screen should have both red and blue are visible. - ScreenCapture::captureLayers(&mCapture, redLayerHandle); + LayerCaptureArgs captureArgs; + captureArgs.layerHandle = redLayer->getHandle(); + ScreenCapture::captureLayers(&mCapture, captureArgs); mCapture->expectColor(Rect(0, 0, 29, 29), Color::BLUE); // red area below the blue area mCapture->expectColor(Rect(0, 30, 59, 59), Color::RED); // red area to the right of the blue area mCapture->expectColor(Rect(30, 0, 59, 59), Color::RED); - const Rect crop = Rect(0, 0, 30, 30); - ScreenCapture::captureLayers(&mCapture, redLayerHandle, crop); + captureArgs.sourceCrop = {0, 0, 30, 30}; + ScreenCapture::captureLayers(&mCapture, captureArgs); // Capturing the cropped screen, cropping out the shown red area, should leave only the blue // area visible. mCapture->expectColor(Rect(0, 0, 29, 29), Color::BLUE); @@ -396,17 +411,18 @@ TEST_F(ScreenCaptureTest, CaptureSize) { .show(blueLayer) .apply(true); - auto redLayerHandle = redLayer->getHandle(); - // Capturing full screen should have both red and blue are visible. - ScreenCapture::captureLayers(&mCapture, redLayerHandle); + LayerCaptureArgs captureArgs; + captureArgs.layerHandle = redLayer->getHandle(); + ScreenCapture::captureLayers(&mCapture, captureArgs); mCapture->expectColor(Rect(0, 0, 29, 29), Color::BLUE); // red area below the blue area mCapture->expectColor(Rect(0, 30, 59, 59), Color::RED); // red area to the right of the blue area mCapture->expectColor(Rect(30, 0, 59, 59), Color::RED); - ScreenCapture::captureLayers(&mCapture, redLayerHandle, Rect::EMPTY_RECT, 0.5); + captureArgs.frameScale = 0.5f; + ScreenCapture::captureLayers(&mCapture, captureArgs); // Capturing the downsized area (30x30) should leave both red and blue but in a smaller area. mCapture->expectColor(Rect(0, 0, 14, 14), Color::BLUE); // red area below the blue area @@ -435,6 +451,49 @@ TEST_F(ScreenCaptureTest, CaptureInvalidLayer) { ASSERT_EQ(NAME_NOT_FOUND, sf->captureLayers(args, captureResults)); } +TEST_F(ScreenCaptureTest, CaputureSecureLayer) { + sp<SurfaceControl> redLayer = createLayer(String8("Red surface"), 60, 60, 0); + sp<SurfaceControl> secureLayer = + createLayer(String8("Secure surface"), 30, 30, + ISurfaceComposerClient::eSecure | + ISurfaceComposerClient::eFXSurfaceBufferQueue, + redLayer.get()); + ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(redLayer, Color::RED, 60, 60)); + ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(secureLayer, Color::BLUE, 30, 30)); + + auto redLayerHandle = redLayer->getHandle(); + Transaction() + .show(redLayer) + .show(secureLayer) + .setLayerStack(redLayer, 0) + .setLayer(redLayer, INT32_MAX) + .apply(); + + sp<ISurfaceComposer> sf(ComposerService::getComposerService()); + + LayerCaptureArgs args; + args.layerHandle = redLayerHandle; + args.childrenOnly = false; + ScreenCaptureResults captureResults; + + // Call from outside system with secure layers will result in permission denied + ASSERT_EQ(PERMISSION_DENIED, sf->captureLayers(args, captureResults)); + + UIDFaker f(AID_SYSTEM); + + // From system request, only red layer will be screenshot since the blue layer is secure. + // Black will be present where the secure layer is. + ScreenCapture::captureLayers(&mCapture, args); + mCapture->expectColor(Rect(0, 0, 30, 30), Color::BLACK); + mCapture->expectColor(Rect(30, 30, 60, 60), Color::RED); + + // Passing flag secure so the blue layer should be screenshot too. + args.captureSecureLayers = true; + ScreenCapture::captureLayers(&mCapture, args); + mCapture->expectColor(Rect(0, 0, 30, 30), Color::BLUE); + mCapture->expectColor(Rect(30, 30, 60, 60), Color::RED); +} + // In the following tests we verify successful skipping of a parent layer, // so we use the same verification logic and only change how we mutate // the parent layer to verify that various properties are ignored. @@ -456,8 +515,10 @@ public: // Verify child layer does not inherit any of the properties of its // parent when its screenshot is captured. - auto fgHandle = mFGSurfaceControl->getHandle(); - ScreenCapture::captureChildLayers(&mCapture, fgHandle); + LayerCaptureArgs captureArgs; + captureArgs.layerHandle = mFGSurfaceControl->getHandle(); + captureArgs.childrenOnly = true; + ScreenCapture::captureLayers(&mCapture, captureArgs); mCapture->checkPixel(10, 10, 0, 0, 0); mCapture->expectChildColor(0, 0); diff --git a/services/surfaceflinger/tests/utils/ScreenshotUtils.h b/services/surfaceflinger/tests/utils/ScreenshotUtils.h index d73506b86f..56628f88bc 100644 --- a/services/surfaceflinger/tests/utils/ScreenshotUtils.h +++ b/services/surfaceflinger/tests/utils/ScreenshotUtils.h @@ -43,54 +43,13 @@ public: *sc = std::make_unique<ScreenCapture>(captureResults.buffer); } - static void captureLayers(std::unique_ptr<ScreenCapture>* sc, sp<IBinder>& parentHandle, - Rect crop = Rect::EMPTY_RECT, float frameScale = 1.0) { + static void captureLayers(std::unique_ptr<ScreenCapture>* sc, + const LayerCaptureArgs& captureArgs) { sp<ISurfaceComposer> sf(ComposerService::getComposerService()); SurfaceComposerClient::Transaction().apply(true); - LayerCaptureArgs args; - args.layerHandle = parentHandle; - args.sourceCrop = crop; - args.frameScale = frameScale; - args.childrenOnly = false; - - ScreenCaptureResults captureResults; - ASSERT_EQ(NO_ERROR, sf->captureLayers(args, captureResults)); - *sc = std::make_unique<ScreenCapture>(captureResults.buffer); - } - - static void captureChildLayers(std::unique_ptr<ScreenCapture>* sc, sp<IBinder>& parentHandle, - Rect crop = Rect::EMPTY_RECT, float frameScale = 1.0) { - sp<ISurfaceComposer> sf(ComposerService::getComposerService()); - SurfaceComposerClient::Transaction().apply(true); - - LayerCaptureArgs args; - args.layerHandle = parentHandle; - args.sourceCrop = crop; - args.frameScale = frameScale; - args.childrenOnly = true; - - ScreenCaptureResults captureResults; - ASSERT_EQ(NO_ERROR, sf->captureLayers(args, captureResults)); - *sc = std::make_unique<ScreenCapture>(captureResults.buffer); - } - - static void captureChildLayersExcluding( - std::unique_ptr<ScreenCapture>* sc, sp<IBinder>& parentHandle, - std::unordered_set<sp<IBinder>, ISurfaceComposer::SpHash<IBinder>> excludeLayers) { - sp<ISurfaceComposer> sf(ComposerService::getComposerService()); - SurfaceComposerClient::Transaction().apply(true); - - LayerCaptureArgs args; - args.layerHandle = parentHandle; - args.pixelFormat = ui::PixelFormat::RGBA_8888; - args.sourceCrop = Rect::EMPTY_RECT; - args.excludeHandles = excludeLayers; - args.frameScale = 1.0f; - args.childrenOnly = true; - ScreenCaptureResults captureResults; - ASSERT_EQ(NO_ERROR, sf->captureLayers(args, captureResults)); + ASSERT_EQ(NO_ERROR, sf->captureLayers(captureArgs, captureResults)); *sc = std::make_unique<ScreenCapture>(captureResults.buffer); } |