Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 18 | #pragma clang diagnostic push |
| 19 | #pragma clang diagnostic ignored "-Wconversion" |
| 20 | |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 21 | #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> |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 29 | #include "utils/ScreenshotUtils.h" |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 30 | |
| 31 | namespace android { |
| 32 | namespace { |
| 33 | |
| 34 | class 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 | */ |
| 40 | class InvalidHandleTest : public ::testing::Test { |
| 41 | protected: |
| 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 | |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 55 | TEST_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 Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | TEST_F(InvalidHandleTest, captureLayersInvalidHandle) { |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 67 | LayerCaptureArgs args; |
| 68 | args.layerHandle = mNotSc->getHandle(); |
| 69 | |
| 70 | ScreenCaptureResults captureResults; |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 71 | ASSERT_EQ(NAME_NOT_FOUND, ScreenCapture::captureLayers(args, captureResults)); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | } // namespace |
| 75 | } // namespace android |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 76 | |
| 77 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 78 | #pragma clang diagnostic pop // ignored "-Wconversion" |