InvalidHandles_test.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #include <binder/Binder.h>
  17. #include <gtest/gtest.h>
  18. #include <gui/ISurfaceComposer.h>
  19. #include <gui/SurfaceComposerClient.h>
  20. #include <private/gui/ComposerService.h>
  21. #include <ui/Rect.h>
  22. namespace android {
  23. namespace {
  24. class NotALayer : public BBinder {};
  25. /**
  26. * For all of these tests we make a SurfaceControl with an invalid layer handle
  27. * and verify we aren't able to trick SurfaceFlinger.
  28. */
  29. class InvalidHandleTest : public ::testing::Test {
  30. protected:
  31. sp<SurfaceComposerClient> mScc;
  32. sp<SurfaceControl> mNotSc;
  33. void SetUp() override {
  34. mScc = new SurfaceComposerClient;
  35. ASSERT_EQ(NO_ERROR, mScc->initCheck());
  36. mNotSc = makeNotSurfaceControl();
  37. }
  38. sp<SurfaceControl> makeNotSurfaceControl() {
  39. return new SurfaceControl(mScc, new NotALayer(), nullptr, true);
  40. }
  41. };
  42. TEST_F(InvalidHandleTest, createSurfaceInvalidHandle) {
  43. auto notSc = makeNotSurfaceControl();
  44. ASSERT_EQ(nullptr,
  45. mScc->createSurface(String8("lolcats"), 19, 47, PIXEL_FORMAT_RGBA_8888, 0,
  46. notSc.get())
  47. .get());
  48. }
  49. TEST_F(InvalidHandleTest, captureLayersInvalidHandle) {
  50. sp<ISurfaceComposer> sf(ComposerService::getComposerService());
  51. sp<GraphicBuffer> outBuffer;
  52. ASSERT_EQ(NAME_NOT_FOUND,
  53. sf->captureLayers(mNotSc->getHandle(), &outBuffer, Rect::EMPTY_RECT, 1.0f));
  54. }
  55. } // namespace
  56. } // namespace android