Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2878422d authored by Rob Carr's avatar Rob Carr Committed by Android (Google) Code Review
Browse files

Merge "SurfaceFlinger: Ensure relatives are not detached with children."

parents 8d7cb208 7f619b23
Loading
Loading
Loading
Loading
+4 −7
Original line number Diff line number Diff line
@@ -1573,17 +1573,14 @@ bool Layer::reparent(const sp<IBinder>& newParentHandle) {
}

bool Layer::detachChildren() {
    traverseInZOrder(LayerVector::StateSet::Drawing, [this](Layer* child) {
        if (child == this) {
            return;
        }

    for (const sp<Layer>& child : mCurrentChildren) {
        sp<Client> parentClient = mClientRef.promote();
        sp<Client> client(child->mClientRef.promote());
        if (client != nullptr && parentClient != client) {
            client->detachLayer(child);
            client->detachLayer(child.get());
            child->detachChildren();
        }
    }
    });

    return true;
}
+37 −0
Original line number Diff line number Diff line
@@ -258,6 +258,43 @@ protected:
    sp<SurfaceControl> mSyncSurfaceControl;
};

TEST_F(LayerUpdateTest, RelativesAreNotDetached) {
    sp<ScreenCapture> sc;

    sp<SurfaceControl> relative = mComposerClient->createSurface(
            String8("relativeTestSurface"), 10, 10, PIXEL_FORMAT_RGBA_8888, 0);
    fillSurfaceRGBA8(relative, 10, 10, 10);
    waitForPostedBuffers();

    Transaction{}.setRelativeLayer(relative, mFGSurfaceControl->getHandle(), 1)
            .setPosition(relative, 64, 64)
            .apply();

    {
        // The relative should be on top of the FG control.
        ScreenCapture::captureScreen(&sc);
        sc->checkPixel(64, 64, 10, 10, 10);
    }
    Transaction{}.detachChildren(mFGSurfaceControl)
            .apply();

    {
        // Nothing should change at this point.
        ScreenCapture::captureScreen(&sc);
        sc->checkPixel(64, 64, 10, 10, 10);
    }

    Transaction{}.hide(relative)
            .apply();

    {
        // Ensure that the relative was actually hidden, rather than
        // being left in the detached but visible state.
        ScreenCapture::captureScreen(&sc);
        sc->expectFGColor(64, 64);
    }
}

TEST_F(LayerUpdateTest, LayerMoveWorks) {
    sp<ScreenCapture> sc;
    {