chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 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 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 18 | #pragma clang diagnostic push |
| 19 | #pragma clang diagnostic ignored "-Wconversion" |
| 20 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame^] | 21 | #include <android/gui/ISurfaceComposer.h> |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 22 | #include <gtest/gtest.h> |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 23 | #include <gui/LayerDebugInfo.h> |
| 24 | #include <gui/Surface.h> |
| 25 | #include <gui/SurfaceComposerClient.h> |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 26 | #include <private/android_filesystem_config.h> |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame^] | 27 | #include <private/gui/ComposerServiceAIDL.h> |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 28 | #include <ui/DisplayMode.h> |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 29 | #include <ui/DynamicDisplayInfo.h> |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 30 | #include <utils/String8.h> |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 31 | #include <functional> |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 32 | #include "utils/ScreenshotUtils.h" |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 33 | |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 34 | namespace android { |
| 35 | |
| 36 | using Transaction = SurfaceComposerClient::Transaction; |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame^] | 37 | using gui::LayerDebugInfo; |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 38 | using ui::ColorMode; |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 39 | |
| 40 | namespace { |
| 41 | const String8 DISPLAY_NAME("Credentials Display Test"); |
| 42 | const String8 SURFACE_NAME("Test Surface Name"); |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 43 | } // namespace |
| 44 | |
| 45 | /** |
| 46 | * This class tests the CheckCredentials method in SurfaceFlinger. |
| 47 | * Methods like EnableVsyncInjections and InjectVsync are not tested since they do not |
| 48 | * return anything meaningful. |
| 49 | */ |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 50 | |
| 51 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 52 | #pragma clang diagnostic push |
| 53 | #pragma clang diagnostic ignored "-Wconversion" |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 54 | class CredentialsTest : public ::testing::Test { |
| 55 | protected: |
| 56 | void SetUp() override { |
| 57 | // Start the tests as root. |
| 58 | seteuid(AID_ROOT); |
| 59 | |
| 60 | ASSERT_NO_FATAL_FAILURE(initClient()); |
| 61 | } |
| 62 | |
| 63 | void TearDown() override { |
| 64 | mComposerClient->dispose(); |
| 65 | mBGSurfaceControl.clear(); |
| 66 | mComposerClient.clear(); |
| 67 | // Finish the tests as root. |
| 68 | seteuid(AID_ROOT); |
| 69 | } |
| 70 | |
| 71 | sp<IBinder> mDisplay; |
| 72 | sp<IBinder> mVirtualDisplay; |
| 73 | sp<SurfaceComposerClient> mComposerClient; |
| 74 | sp<SurfaceControl> mBGSurfaceControl; |
| 75 | sp<SurfaceControl> mVirtualSurfaceControl; |
| 76 | |
| 77 | void initClient() { |
| 78 | mComposerClient = new SurfaceComposerClient; |
| 79 | ASSERT_EQ(NO_ERROR, mComposerClient->initCheck()); |
| 80 | } |
| 81 | |
| 82 | void setupBackgroundSurface() { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 83 | mDisplay = SurfaceComposerClient::getInternalDisplayToken(); |
| 84 | ASSERT_FALSE(mDisplay == nullptr); |
| 85 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 86 | ui::DisplayMode mode; |
| 87 | ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(mDisplay, &mode)); |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 88 | |
| 89 | // Background surface |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 90 | mBGSurfaceControl = mComposerClient->createSurface(SURFACE_NAME, mode.resolution.getWidth(), |
| 91 | mode.resolution.getHeight(), |
| 92 | PIXEL_FORMAT_RGBA_8888, 0); |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 93 | ASSERT_TRUE(mBGSurfaceControl != nullptr); |
| 94 | ASSERT_TRUE(mBGSurfaceControl->isValid()); |
| 95 | |
| 96 | Transaction t; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 97 | t.setDisplayLayerStack(mDisplay, ui::DEFAULT_LAYER_STACK); |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 98 | ASSERT_EQ(NO_ERROR, |
| 99 | t.setLayer(mBGSurfaceControl, INT_MAX - 3).show(mBGSurfaceControl).apply()); |
| 100 | } |
| 101 | |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 102 | /** |
| 103 | * Sets UID to imitate Graphic's process. |
| 104 | */ |
| 105 | void setGraphicsUID() { |
| 106 | seteuid(AID_ROOT); |
| 107 | seteuid(AID_GRAPHICS); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Sets UID to imitate System's process. |
| 112 | */ |
| 113 | void setSystemUID() { |
| 114 | seteuid(AID_ROOT); |
| 115 | seteuid(AID_SYSTEM); |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Sets UID to imitate a process that doesn't have any special privileges in |
| 120 | * our code. |
| 121 | */ |
| 122 | void setBinUID() { |
| 123 | seteuid(AID_ROOT); |
| 124 | seteuid(AID_BIN); |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Template function the check a condition for different types of users: root |
| 129 | * graphics, system, and non-supported user. Root, graphics, and system should |
| 130 | * always equal privilegedValue, and non-supported user should equal unprivilegedValue. |
| 131 | */ |
| 132 | template <typename T> |
| 133 | void checkWithPrivileges(std::function<T()> condition, T privilegedValue, T unprivilegedValue) { |
| 134 | // Check with root. |
| 135 | seteuid(AID_ROOT); |
| 136 | ASSERT_EQ(privilegedValue, condition()); |
| 137 | |
| 138 | // Check as a Graphics user. |
| 139 | setGraphicsUID(); |
| 140 | ASSERT_EQ(privilegedValue, condition()); |
| 141 | |
| 142 | // Check as a system user. |
| 143 | setSystemUID(); |
| 144 | ASSERT_EQ(privilegedValue, condition()); |
| 145 | |
| 146 | // Check as a non-supported user. |
| 147 | setBinUID(); |
| 148 | ASSERT_EQ(unprivilegedValue, condition()); |
chaviw | d4a6164 | 2020-09-01 14:53:46 -0700 | [diff] [blame] | 149 | |
| 150 | // Check as shell since shell has some additional permissions |
| 151 | seteuid(AID_SHELL); |
| 152 | ASSERT_EQ(unprivilegedValue, condition()); |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 153 | } |
| 154 | }; |
| 155 | |
| 156 | TEST_F(CredentialsTest, ClientInitTest) { |
| 157 | // Root can init can init the client. |
| 158 | ASSERT_NO_FATAL_FAILURE(initClient()); |
| 159 | |
| 160 | // Graphics can init the client. |
| 161 | setGraphicsUID(); |
| 162 | ASSERT_NO_FATAL_FAILURE(initClient()); |
| 163 | |
| 164 | // System can init the client. |
| 165 | setSystemUID(); |
| 166 | ASSERT_NO_FATAL_FAILURE(initClient()); |
| 167 | |
Robert Carr | b89ea9d | 2018-12-10 13:01:14 -0800 | [diff] [blame] | 168 | // Anyone else can init the client. |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 169 | setBinUID(); |
| 170 | mComposerClient = new SurfaceComposerClient; |
Robert Carr | b89ea9d | 2018-12-10 13:01:14 -0800 | [diff] [blame] | 171 | ASSERT_NO_FATAL_FAILURE(initClient()); |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | TEST_F(CredentialsTest, GetBuiltInDisplayAccessTest) { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 175 | std::function<bool()> condition = [] { |
| 176 | return SurfaceComposerClient::getInternalDisplayToken() != nullptr; |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 177 | }; |
| 178 | // Anyone can access display information. |
| 179 | ASSERT_NO_FATAL_FAILURE(checkWithPrivileges(condition, true, true)); |
| 180 | } |
| 181 | |
| 182 | TEST_F(CredentialsTest, AllowedGetterMethodsTest) { |
| 183 | // The following methods are tested with a UID that is not root, graphics, |
| 184 | // or system, to show that anyone can access them. |
| 185 | setBinUID(); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 186 | const auto display = SurfaceComposerClient::getInternalDisplayToken(); |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 187 | ASSERT_TRUE(display != nullptr); |
| 188 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 189 | ui::DisplayMode mode; |
| 190 | ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode)); |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 191 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 192 | Vector<ui::DisplayMode> modes; |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 193 | ui::DynamicDisplayInfo info; |
| 194 | ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getDynamicDisplayInfo(display, &info)); |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 197 | TEST_F(CredentialsTest, GetDynamicDisplayInfoTest) { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 198 | const auto display = SurfaceComposerClient::getInternalDisplayToken(); |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 199 | std::function<status_t()> condition = [=]() { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 200 | ui::DynamicDisplayInfo info; |
| 201 | return SurfaceComposerClient::getDynamicDisplayInfo(display, &info); |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 202 | }; |
| 203 | ASSERT_NO_FATAL_FAILURE(checkWithPrivileges<status_t>(condition, NO_ERROR, NO_ERROR)); |
| 204 | } |
| 205 | |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 206 | TEST_F(CredentialsTest, GetDisplayNativePrimariesTest) { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 207 | const auto display = SurfaceComposerClient::getInternalDisplayToken(); |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 208 | std::function<status_t()> condition = [=]() { |
| 209 | ui::DisplayPrimaries primaries; |
| 210 | return SurfaceComposerClient::getDisplayNativePrimaries(display, primaries); |
| 211 | }; |
| 212 | ASSERT_NO_FATAL_FAILURE(checkWithPrivileges<status_t>(condition, NO_ERROR, NO_ERROR)); |
| 213 | } |
| 214 | |
Steven Thomas | a87ed45 | 2020-01-03 16:10:05 -0800 | [diff] [blame] | 215 | TEST_F(CredentialsTest, SetDesiredDisplayConfigsTest) { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 216 | const auto display = SurfaceComposerClient::getInternalDisplayToken(); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 217 | ui::DisplayModeId defaultMode; |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 218 | bool allowGroupSwitching; |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 219 | float primaryFpsMin; |
| 220 | float primaryFpsMax; |
| 221 | float appRequestFpsMin; |
| 222 | float appRequestFpsMax; |
| 223 | status_t res = |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 224 | SurfaceComposerClient::getDesiredDisplayModeSpecs(display, &defaultMode, |
| 225 | &allowGroupSwitching, &primaryFpsMin, |
| 226 | &primaryFpsMax, &appRequestFpsMin, |
| 227 | &appRequestFpsMax); |
Steven Thomas | a87ed45 | 2020-01-03 16:10:05 -0800 | [diff] [blame] | 228 | ASSERT_EQ(res, NO_ERROR); |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 229 | std::function<status_t()> condition = [=]() { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 230 | return SurfaceComposerClient::setDesiredDisplayModeSpecs(display, defaultMode, |
| 231 | allowGroupSwitching, primaryFpsMin, |
| 232 | primaryFpsMax, appRequestFpsMin, |
| 233 | appRequestFpsMax); |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 234 | }; |
| 235 | ASSERT_NO_FATAL_FAILURE(checkWithPrivileges<status_t>(condition, NO_ERROR, PERMISSION_DENIED)); |
| 236 | } |
| 237 | |
| 238 | TEST_F(CredentialsTest, SetActiveColorModeTest) { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 239 | const auto display = SurfaceComposerClient::getInternalDisplayToken(); |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 240 | std::function<status_t()> condition = [=]() { |
| 241 | return SurfaceComposerClient::setActiveColorMode(display, ui::ColorMode::NATIVE); |
| 242 | }; |
| 243 | ASSERT_NO_FATAL_FAILURE(checkWithPrivileges<status_t>(condition, NO_ERROR, PERMISSION_DENIED)); |
| 244 | } |
| 245 | |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 246 | TEST_F(CredentialsTest, CreateDisplayTest) { |
chaviw | d4a6164 | 2020-09-01 14:53:46 -0700 | [diff] [blame] | 247 | // Only graphics and system processes can create a secure display. |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 248 | std::function<bool()> condition = [=]() { |
| 249 | sp<IBinder> testDisplay = SurfaceComposerClient::createDisplay(DISPLAY_NAME, true); |
| 250 | return testDisplay.get() != nullptr; |
| 251 | }; |
chaviw | d4a6164 | 2020-09-01 14:53:46 -0700 | [diff] [blame] | 252 | |
| 253 | // Check with root. |
| 254 | seteuid(AID_ROOT); |
| 255 | ASSERT_FALSE(condition()); |
| 256 | |
| 257 | // Check as a Graphics user. |
| 258 | setGraphicsUID(); |
| 259 | ASSERT_TRUE(condition()); |
| 260 | |
| 261 | // Check as a system user. |
| 262 | setSystemUID(); |
| 263 | ASSERT_TRUE(condition()); |
| 264 | |
| 265 | // Check as a non-supported user. |
| 266 | setBinUID(); |
| 267 | ASSERT_FALSE(condition()); |
| 268 | |
| 269 | // Check as shell since shell has some additional permissions |
| 270 | seteuid(AID_SHELL); |
| 271 | ASSERT_FALSE(condition()); |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 272 | |
| 273 | condition = [=]() { |
| 274 | sp<IBinder> testDisplay = SurfaceComposerClient::createDisplay(DISPLAY_NAME, false); |
| 275 | return testDisplay.get() != nullptr; |
| 276 | }; |
| 277 | ASSERT_NO_FATAL_FAILURE(checkWithPrivileges(condition, true, false)); |
| 278 | } |
| 279 | |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 280 | TEST_F(CredentialsTest, CaptureTest) { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 281 | const auto display = SurfaceComposerClient::getInternalDisplayToken(); |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 282 | std::function<status_t()> condition = [=]() { |
| 283 | sp<GraphicBuffer> outBuffer; |
chaviw | 690db38 | 2020-07-27 16:46:46 -0700 | [diff] [blame] | 284 | DisplayCaptureArgs captureArgs; |
| 285 | captureArgs.displayToken = display; |
| 286 | ScreenCaptureResults captureResults; |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 287 | return ScreenCapture::captureDisplay(captureArgs, captureResults); |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 288 | }; |
| 289 | ASSERT_NO_FATAL_FAILURE(checkWithPrivileges<status_t>(condition, NO_ERROR, PERMISSION_DENIED)); |
| 290 | } |
| 291 | |
| 292 | TEST_F(CredentialsTest, CaptureLayersTest) { |
| 293 | setupBackgroundSurface(); |
| 294 | sp<GraphicBuffer> outBuffer; |
| 295 | std::function<status_t()> condition = [=]() { |
chaviw | 26c5248 | 2020-07-28 16:25:52 -0700 | [diff] [blame] | 296 | LayerCaptureArgs captureArgs; |
| 297 | captureArgs.layerHandle = mBGSurfaceControl->getHandle(); |
| 298 | captureArgs.sourceCrop = {0, 0, 1, 1}; |
| 299 | |
| 300 | ScreenCaptureResults captureResults; |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 301 | return ScreenCapture::captureLayers(captureArgs, captureResults); |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 302 | }; |
| 303 | ASSERT_NO_FATAL_FAILURE(checkWithPrivileges<status_t>(condition, NO_ERROR, PERMISSION_DENIED)); |
| 304 | } |
| 305 | |
| 306 | /** |
| 307 | * The following tests are for methods accessible directly through SurfaceFlinger. |
| 308 | */ |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 309 | TEST_F(CredentialsTest, GetLayerDebugInfo) { |
| 310 | setupBackgroundSurface(); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame^] | 311 | sp<gui::ISurfaceComposer> sf(ComposerServiceAIDL::getComposerService()); |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 312 | |
| 313 | // Historically, only root and shell can access the getLayerDebugInfo which |
| 314 | // is called when we call dumpsys. I don't see a reason why we should change this. |
| 315 | std::vector<LayerDebugInfo> outLayers; |
| 316 | // Check with root. |
| 317 | seteuid(AID_ROOT); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame^] | 318 | binder::Status status = sf->getLayerDebugInfo(&outLayers); |
| 319 | ASSERT_EQ(NO_ERROR, status.transactionError()); |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 320 | |
| 321 | // Check as a shell. |
| 322 | seteuid(AID_SHELL); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame^] | 323 | status = sf->getLayerDebugInfo(&outLayers); |
| 324 | ASSERT_EQ(NO_ERROR, status.transactionError()); |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 325 | |
| 326 | // Check as anyone else. |
| 327 | seteuid(AID_ROOT); |
| 328 | seteuid(AID_BIN); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame^] | 329 | status = sf->getLayerDebugInfo(&outLayers); |
| 330 | ASSERT_EQ(PERMISSION_DENIED, status.transactionError()); |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 331 | } |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 332 | |
| 333 | TEST_F(CredentialsTest, IsWideColorDisplayBasicCorrectness) { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 334 | const auto display = SurfaceComposerClient::getInternalDisplayToken(); |
| 335 | ASSERT_FALSE(display == nullptr); |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 336 | bool result = false; |
| 337 | status_t error = SurfaceComposerClient::isWideColorDisplay(display, &result); |
| 338 | ASSERT_EQ(NO_ERROR, error); |
| 339 | bool hasWideColorMode = false; |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 340 | ui::DynamicDisplayInfo info; |
| 341 | SurfaceComposerClient::getDynamicDisplayInfo(display, &info); |
| 342 | const auto& colorModes = info.supportedColorModes; |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 343 | for (ColorMode colorMode : colorModes) { |
| 344 | switch (colorMode) { |
| 345 | case ColorMode::DISPLAY_P3: |
| 346 | case ColorMode::ADOBE_RGB: |
| 347 | case ColorMode::DCI_P3: |
| 348 | hasWideColorMode = true; |
| 349 | break; |
| 350 | default: |
| 351 | break; |
| 352 | } |
| 353 | } |
| 354 | ASSERT_EQ(hasWideColorMode, result); |
| 355 | } |
| 356 | |
| 357 | TEST_F(CredentialsTest, IsWideColorDisplayWithPrivileges) { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 358 | const auto display = SurfaceComposerClient::getInternalDisplayToken(); |
| 359 | ASSERT_FALSE(display == nullptr); |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 360 | std::function<status_t()> condition = [=]() { |
| 361 | bool result = false; |
| 362 | return SurfaceComposerClient::isWideColorDisplay(display, &result); |
| 363 | }; |
| 364 | ASSERT_NO_FATAL_FAILURE(checkWithPrivileges<status_t>(condition, NO_ERROR, NO_ERROR)); |
| 365 | } |
| 366 | |
Peiyong Lin | d1fedb4 | 2019-03-11 17:48:41 -0700 | [diff] [blame] | 367 | TEST_F(CredentialsTest, GetActiveColorModeBasicCorrectness) { |
| 368 | const auto display = SurfaceComposerClient::getInternalDisplayToken(); |
| 369 | ASSERT_FALSE(display == nullptr); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 370 | ui::DynamicDisplayInfo info; |
| 371 | SurfaceComposerClient::getDynamicDisplayInfo(display, &info); |
| 372 | ColorMode colorMode = info.activeColorMode; |
Peiyong Lin | d1fedb4 | 2019-03-11 17:48:41 -0700 | [diff] [blame] | 373 | ASSERT_NE(static_cast<ColorMode>(BAD_VALUE), colorMode); |
| 374 | } |
| 375 | |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 376 | } // namespace android |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 377 | |
| 378 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 379 | #pragma clang diagnostic pop // ignored "-Wconversion" |