blob: 300e9c7fabaac4ff9c3f348d3fd1e0a90ea07ffe [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
17#include <binder/Binder.h>
18
19#include <gtest/gtest.h>
20
21#include <gui/ISurfaceComposer.h>
22#include <gui/SurfaceComposerClient.h>
23#include <private/gui/ComposerService.h>
24#include <ui/Rect.h>
25
26namespace android {
27namespace {
28
29class NotALayer : public BBinder {};
30
31/**
32 * For all of these tests we make a SurfaceControl with an invalid layer handle
33 * and verify we aren't able to trick SurfaceFlinger.
34 */
35class InvalidHandleTest : public ::testing::Test {
36protected:
37 sp<SurfaceComposerClient> mScc;
38 sp<SurfaceControl> mNotSc;
39 void SetUp() override {
40 mScc = new SurfaceComposerClient;
41 ASSERT_EQ(NO_ERROR, mScc->initCheck());
42 mNotSc = makeNotSurfaceControl();
43 }
44
45 sp<SurfaceControl> makeNotSurfaceControl() {
46 return new SurfaceControl(mScc, new NotALayer(), nullptr, true);
47 }
48};
49
50TEST_F(InvalidHandleTest, createSurfaceInvalidHandle) {
51 auto notSc = makeNotSurfaceControl();
52 ASSERT_EQ(nullptr,
53 mScc->createSurface(String8("lolcats"), 19, 47, PIXEL_FORMAT_RGBA_8888, 0,
54 notSc.get())
55 .get());
56}
57
58TEST_F(InvalidHandleTest, captureLayersInvalidHandle) {
59 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
Robert Carrc0df3122019-04-11 13:18:21 -070060
chaviw3efadb12020-07-27 10:07:15 -070061 LayerCaptureArgs args;
62 args.layerHandle = mNotSc->getHandle();
63
64 ScreenCaptureResults captureResults;
65 ASSERT_EQ(NAME_NOT_FOUND, sf->captureLayers(args, captureResults));
Robert Carrc0df3122019-04-11 13:18:21 -070066}
67
68} // namespace
69} // namespace android