blob: 9cf7c0909bf722e2dcac4968d2bf36bc9c3a67cc [file] [log] [blame]
Robert Carrc0df3122019-04-11 13:18:21 -07001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
chaviw8ffc7b82020-08-18 11:25:37 -070017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wconversion"
20
Robert Carrc0df3122019-04-11 13:18:21 -070021#include <binder/Binder.h>
22
23#include <gtest/gtest.h>
24
25#include <gui/ISurfaceComposer.h>
26#include <gui/SurfaceComposerClient.h>
27#include <private/gui/ComposerService.h>
28#include <ui/Rect.h>
chaviw8ffc7b82020-08-18 11:25:37 -070029#include "utils/ScreenshotUtils.h"
Robert Carrc0df3122019-04-11 13:18:21 -070030
31namespace android {
32namespace {
33
34class NotALayer : public BBinder {};
35
36/**
37 * For all of these tests we make a SurfaceControl with an invalid layer handle
38 * and verify we aren't able to trick SurfaceFlinger.
39 */
40class InvalidHandleTest : public ::testing::Test {
41protected:
42 sp<SurfaceComposerClient> mScc;
43 sp<SurfaceControl> mNotSc;
44 void SetUp() override {
45 mScc = new SurfaceComposerClient;
46 ASSERT_EQ(NO_ERROR, mScc->initCheck());
47 mNotSc = makeNotSurfaceControl();
48 }
49
50 sp<SurfaceControl> makeNotSurfaceControl() {
51 return new SurfaceControl(mScc, new NotALayer(), nullptr, true);
52 }
53};
54
arthurhungdba591c2021-02-08 17:28:49 +080055TEST_F(InvalidHandleTest, createSurfaceInvalidParentHandle) {
56 // The createSurface is scheduled now, we could still get a created surface from createSurface.
57 // Should verify if it actually added into current state by checking the screenshot.
58 auto notSc = mScc->createSurface(String8("lolcats"), 19, 47, PIXEL_FORMAT_RGBA_8888, 0,
59 mNotSc->getHandle());
60 LayerCaptureArgs args;
61 args.layerHandle = notSc->getHandle();
62 ScreenCaptureResults captureResults;
63 ASSERT_EQ(NAME_NOT_FOUND, ScreenCapture::captureLayers(args, captureResults));
Robert Carrc0df3122019-04-11 13:18:21 -070064}
65
66TEST_F(InvalidHandleTest, captureLayersInvalidHandle) {
chaviw3efadb12020-07-27 10:07:15 -070067 LayerCaptureArgs args;
68 args.layerHandle = mNotSc->getHandle();
69
70 ScreenCaptureResults captureResults;
chaviw8ffc7b82020-08-18 11:25:37 -070071 ASSERT_EQ(NAME_NOT_FOUND, ScreenCapture::captureLayers(args, captureResults));
Robert Carrc0df3122019-04-11 13:18:21 -070072}
73
74} // namespace
75} // namespace android
Marin Shalamanovbed7fd32020-12-21 20:02:20 +010076
77// TODO(b/129481165): remove the #pragma below and fix conversion issues
78#pragma clang diagnostic pop // ignored "-Wconversion"