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 | |
| 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 | |
| 26 | namespace android { |
| 27 | namespace { |
| 28 | |
| 29 | class 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 | */ |
| 35 | class InvalidHandleTest : public ::testing::Test { |
| 36 | protected: |
| 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 | |
| 50 | TEST_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 | |
| 58 | TEST_F(InvalidHandleTest, captureLayersInvalidHandle) { |
| 59 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); |
| 60 | sp<GraphicBuffer> outBuffer; |
| 61 | |
| 62 | ASSERT_EQ(NAME_NOT_FOUND, |
| 63 | sf->captureLayers(mNotSc->getHandle(), &outBuffer, Rect::EMPTY_RECT, 1.0f)); |
| 64 | } |
| 65 | |
| 66 | } // namespace |
| 67 | } // namespace android |