| 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 |  | 
 | 55 | TEST_F(InvalidHandleTest, createSurfaceInvalidHandle) { | 
 | 56 |     auto notSc = makeNotSurfaceControl(); | 
 | 57 |     ASSERT_EQ(nullptr, | 
 | 58 |               mScc->createSurface(String8("lolcats"), 19, 47, PIXEL_FORMAT_RGBA_8888, 0, | 
 | 59 |                                   notSc.get()) | 
 | 60 |                       .get()); | 
 | 61 | } | 
 | 62 |  | 
 | 63 | TEST_F(InvalidHandleTest, captureLayersInvalidHandle) { | 
| chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 64 |     LayerCaptureArgs args; | 
 | 65 |     args.layerHandle = mNotSc->getHandle(); | 
 | 66 |  | 
 | 67 |     ScreenCaptureResults captureResults; | 
| chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 68 |     ASSERT_EQ(NAME_NOT_FOUND, ScreenCapture::captureLayers(args, captureResults)); | 
| Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 69 | } | 
 | 70 |  | 
 | 71 | } // namespace | 
 | 72 | } // namespace android |