blob: 9b83713f50277786b4e9f60b89712c41f54a0a5c [file] [log] [blame]
chaviw8ffc7b82020-08-18 11:25:37 -07001/*
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 Luo05539a12022-02-23 10:29:40 -080021#include <android/gui/ISurfaceComposer.h>
Ana Krulec13be8ad2018-08-21 02:43:56 +000022#include <gtest/gtest.h>
Huihong Luo3bdef862022-03-03 11:57:19 -080023#include <gui/AidlStatusUtil.h>
Ana Krulec13be8ad2018-08-21 02:43:56 +000024#include <gui/LayerDebugInfo.h>
25#include <gui/Surface.h>
26#include <gui/SurfaceComposerClient.h>
Ana Krulec13be8ad2018-08-21 02:43:56 +000027#include <private/android_filesystem_config.h>
Huihong Luo05539a12022-02-23 10:29:40 -080028#include <private/gui/ComposerServiceAIDL.h>
Marin Shalamanova7fe3042021-01-29 21:02:08 +010029#include <ui/DisplayMode.h>
Marin Shalamanov228f46b2021-01-28 21:11:45 +010030#include <ui/DynamicDisplayInfo.h>
Ana Krulec13be8ad2018-08-21 02:43:56 +000031#include <utils/String8.h>
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080032#include <functional>
chaviw8ffc7b82020-08-18 11:25:37 -070033#include "utils/ScreenshotUtils.h"
Chavi Weingartenc78f53c2023-04-14 18:50:53 +000034#include "utils/WindowInfosListenerUtils.h"
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080035
Ana Krulec13be8ad2018-08-21 02:43:56 +000036namespace android {
37
38using Transaction = SurfaceComposerClient::Transaction;
Huihong Luo05539a12022-02-23 10:29:40 -080039using gui::LayerDebugInfo;
Huihong Luo3bdef862022-03-03 11:57:19 -080040using gui::aidl_utils::statusTFromBinderStatus;
Peiyong Lin4f3fddf2019-01-24 17:21:24 -080041using ui::ColorMode;
Ana Krulec13be8ad2018-08-21 02:43:56 +000042
43namespace {
44const String8 DISPLAY_NAME("Credentials Display Test");
45const String8 SURFACE_NAME("Test Surface Name");
Ana Krulec13be8ad2018-08-21 02:43:56 +000046} // namespace
47
48/**
49 * This class tests the CheckCredentials method in SurfaceFlinger.
50 * Methods like EnableVsyncInjections and InjectVsync are not tested since they do not
51 * return anything meaningful.
52 */
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080053
54// TODO(b/129481165): remove the #pragma below and fix conversion issues
55#pragma clang diagnostic push
56#pragma clang diagnostic ignored "-Wconversion"
Ana Krulec13be8ad2018-08-21 02:43:56 +000057class CredentialsTest : public ::testing::Test {
58protected:
Chavi Weingartenc73be482022-08-31 16:55:07 +000059 void SetUp() override { ASSERT_NO_FATAL_FAILURE(initClient()); }
Ana Krulec13be8ad2018-08-21 02:43:56 +000060
61 void TearDown() override {
62 mComposerClient->dispose();
63 mBGSurfaceControl.clear();
64 mComposerClient.clear();
Ana Krulec13be8ad2018-08-21 02:43:56 +000065 }
66
67 sp<IBinder> mDisplay;
68 sp<IBinder> mVirtualDisplay;
69 sp<SurfaceComposerClient> mComposerClient;
70 sp<SurfaceControl> mBGSurfaceControl;
71 sp<SurfaceControl> mVirtualSurfaceControl;
72
73 void initClient() {
Ady Abrahamd11bade2022-08-01 16:18:03 -070074 mComposerClient = sp<SurfaceComposerClient>::make();
Ana Krulec13be8ad2018-08-21 02:43:56 +000075 ASSERT_EQ(NO_ERROR, mComposerClient->initCheck());
76 }
77
Huihong Luo31b5ac22022-08-15 20:38:10 -070078 static sp<IBinder> getFirstDisplayToken() {
79 const auto ids = SurfaceComposerClient::getPhysicalDisplayIds();
80 if (ids.empty()) {
81 return nullptr;
82 }
83
84 return SurfaceComposerClient::getPhysicalDisplayToken(ids.front());
85 }
86
Sally Qi6bb12822022-10-05 11:42:30 -070087 static std::optional<uint64_t> getFirstDisplayId() {
88 const auto ids = SurfaceComposerClient::getPhysicalDisplayIds();
89 if (ids.empty()) {
90 return std::nullopt;
91 }
92
93 return ids.front().value;
94 }
95
Ana Krulec13be8ad2018-08-21 02:43:56 +000096 void setupBackgroundSurface() {
Huihong Luo31b5ac22022-08-15 20:38:10 -070097 mDisplay = getFirstDisplayToken();
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -080098 ASSERT_FALSE(mDisplay == nullptr);
99
Marin Shalamanova7fe3042021-01-29 21:02:08 +0100100 ui::DisplayMode mode;
101 ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(mDisplay, &mode));
Ana Krulec13be8ad2018-08-21 02:43:56 +0000102
103 // Background surface
Marin Shalamanova7fe3042021-01-29 21:02:08 +0100104 mBGSurfaceControl = mComposerClient->createSurface(SURFACE_NAME, mode.resolution.getWidth(),
105 mode.resolution.getHeight(),
106 PIXEL_FORMAT_RGBA_8888, 0);
Ana Krulec13be8ad2018-08-21 02:43:56 +0000107 ASSERT_TRUE(mBGSurfaceControl != nullptr);
108 ASSERT_TRUE(mBGSurfaceControl->isValid());
109
110 Transaction t;
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700111 t.setDisplayLayerStack(mDisplay, ui::DEFAULT_LAYER_STACK);
Ana Krulec13be8ad2018-08-21 02:43:56 +0000112 ASSERT_EQ(NO_ERROR,
113 t.setLayer(mBGSurfaceControl, INT_MAX - 3).show(mBGSurfaceControl).apply());
114 }
115
Ana Krulec13be8ad2018-08-21 02:43:56 +0000116 /**
Ana Krulec13be8ad2018-08-21 02:43:56 +0000117 * Template function the check a condition for different types of users: root
118 * graphics, system, and non-supported user. Root, graphics, and system should
119 * always equal privilegedValue, and non-supported user should equal unprivilegedValue.
120 */
121 template <typename T>
122 void checkWithPrivileges(std::function<T()> condition, T privilegedValue, T unprivilegedValue) {
123 // Check with root.
Chavi Weingartenc73be482022-08-31 16:55:07 +0000124 {
125 UIDFaker f(AID_SYSTEM);
126 ASSERT_EQ(privilegedValue, condition());
127 }
Ana Krulec13be8ad2018-08-21 02:43:56 +0000128
129 // Check as a Graphics user.
Chavi Weingartenc73be482022-08-31 16:55:07 +0000130 {
131 UIDFaker f(AID_GRAPHICS);
132 ASSERT_EQ(privilegedValue, condition());
133 }
Ana Krulec13be8ad2018-08-21 02:43:56 +0000134
135 // Check as a system user.
Chavi Weingartenc73be482022-08-31 16:55:07 +0000136 {
137 UIDFaker f(AID_SYSTEM);
138 ASSERT_EQ(privilegedValue, condition());
139 }
Ana Krulec13be8ad2018-08-21 02:43:56 +0000140
141 // Check as a non-supported user.
Chavi Weingartenc73be482022-08-31 16:55:07 +0000142 {
143 UIDFaker f(AID_BIN);
144 ASSERT_EQ(unprivilegedValue, condition());
145 }
chaviwd4a61642020-09-01 14:53:46 -0700146
147 // Check as shell since shell has some additional permissions
Chavi Weingartenc73be482022-08-31 16:55:07 +0000148 {
149 UIDFaker f(AID_SHELL);
150 ASSERT_EQ(privilegedValue, condition());
151 }
Ana Krulec13be8ad2018-08-21 02:43:56 +0000152 }
153};
154
155TEST_F(CredentialsTest, ClientInitTest) {
156 // Root can init can init the client.
157 ASSERT_NO_FATAL_FAILURE(initClient());
158
159 // Graphics can init the client.
Chavi Weingartenc73be482022-08-31 16:55:07 +0000160 {
161 UIDFaker f(AID_GRAPHICS);
162 ASSERT_NO_FATAL_FAILURE(initClient());
163 }
Ana Krulec13be8ad2018-08-21 02:43:56 +0000164
165 // System can init the client.
Chavi Weingartenc73be482022-08-31 16:55:07 +0000166 {
167 UIDFaker f(AID_SYSTEM);
168 ASSERT_NO_FATAL_FAILURE(initClient());
169 }
Ana Krulec13be8ad2018-08-21 02:43:56 +0000170
Robert Carrb89ea9d2018-12-10 13:01:14 -0800171 // Anyone else can init the client.
Chavi Weingartenc73be482022-08-31 16:55:07 +0000172 {
173 UIDFaker f(AID_BIN);
174 mComposerClient = sp<SurfaceComposerClient>::make();
175 ASSERT_NO_FATAL_FAILURE(initClient());
176 }
Ana Krulec13be8ad2018-08-21 02:43:56 +0000177}
178
179TEST_F(CredentialsTest, GetBuiltInDisplayAccessTest) {
Huihong Luo31b5ac22022-08-15 20:38:10 -0700180 std::function<bool()> condition = [] { return getFirstDisplayToken() != nullptr; };
Ana Krulec13be8ad2018-08-21 02:43:56 +0000181 // Anyone can access display information.
Sally Qi6bb12822022-10-05 11:42:30 -0700182 ASSERT_NO_FATAL_FAILURE(checkWithPrivileges(condition, true, false));
Ana Krulec13be8ad2018-08-21 02:43:56 +0000183}
184
185TEST_F(CredentialsTest, AllowedGetterMethodsTest) {
186 // The following methods are tested with a UID that is not root, graphics,
187 // or system, to show that anyone can access them.
Chavi Weingartenc73be482022-08-31 16:55:07 +0000188 UIDFaker f(AID_BIN);
Sally Qi6bb12822022-10-05 11:42:30 -0700189 const auto id = getFirstDisplayId();
190 ASSERT_TRUE(id);
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100191 ui::DynamicDisplayInfo info;
Sally Qi6bb12822022-10-05 11:42:30 -0700192 ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getDynamicDisplayInfoFromId(*id, &info));
Ana Krulec13be8ad2018-08-21 02:43:56 +0000193}
194
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100195TEST_F(CredentialsTest, GetDynamicDisplayInfoTest) {
Sally Qi6bb12822022-10-05 11:42:30 -0700196 const auto id = getFirstDisplayId();
197 ASSERT_TRUE(id);
Ana Krulec13be8ad2018-08-21 02:43:56 +0000198 std::function<status_t()> condition = [=]() {
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100199 ui::DynamicDisplayInfo info;
Sally Qi6bb12822022-10-05 11:42:30 -0700200 return SurfaceComposerClient::getDynamicDisplayInfoFromId(*id, &info);
Ana Krulec13be8ad2018-08-21 02:43:56 +0000201 };
202 ASSERT_NO_FATAL_FAILURE(checkWithPrivileges<status_t>(condition, NO_ERROR, NO_ERROR));
203}
204
Daniel Solomon42d04562019-01-20 21:03:19 -0800205TEST_F(CredentialsTest, GetDisplayNativePrimariesTest) {
Huihong Luo31b5ac22022-08-15 20:38:10 -0700206 const auto display = getFirstDisplayToken();
Daniel Solomon42d04562019-01-20 21:03:19 -0800207 std::function<status_t()> condition = [=]() {
208 ui::DisplayPrimaries primaries;
209 return SurfaceComposerClient::getDisplayNativePrimaries(display, primaries);
210 };
211 ASSERT_NO_FATAL_FAILURE(checkWithPrivileges<status_t>(condition, NO_ERROR, NO_ERROR));
212}
213
Steven Thomasa87ed452020-01-03 16:10:05 -0800214TEST_F(CredentialsTest, SetDesiredDisplayConfigsTest) {
Huihong Luo31b5ac22022-08-15 20:38:10 -0700215 const auto display = getFirstDisplayToken();
Ady Abraham285f8c12022-10-11 17:12:14 -0700216 gui::DisplayModeSpecs specs;
217 status_t res = SurfaceComposerClient::getDesiredDisplayModeSpecs(display, &specs);
Steven Thomasa87ed452020-01-03 16:10:05 -0800218 ASSERT_EQ(res, NO_ERROR);
Ady Abraham285f8c12022-10-11 17:12:14 -0700219 gui::DisplayModeSpecs setSpecs;
Ana Krulec13be8ad2018-08-21 02:43:56 +0000220 std::function<status_t()> condition = [=]() {
Ady Abraham285f8c12022-10-11 17:12:14 -0700221 return SurfaceComposerClient::setDesiredDisplayModeSpecs(display, specs);
Ana Krulec13be8ad2018-08-21 02:43:56 +0000222 };
223 ASSERT_NO_FATAL_FAILURE(checkWithPrivileges<status_t>(condition, NO_ERROR, PERMISSION_DENIED));
224}
225
226TEST_F(CredentialsTest, SetActiveColorModeTest) {
Huihong Luo31b5ac22022-08-15 20:38:10 -0700227 const auto display = getFirstDisplayToken();
Ana Krulec13be8ad2018-08-21 02:43:56 +0000228 std::function<status_t()> condition = [=]() {
229 return SurfaceComposerClient::setActiveColorMode(display, ui::ColorMode::NATIVE);
230 };
231 ASSERT_NO_FATAL_FAILURE(checkWithPrivileges<status_t>(condition, NO_ERROR, PERMISSION_DENIED));
232}
233
Ana Krulec13be8ad2018-08-21 02:43:56 +0000234TEST_F(CredentialsTest, CreateDisplayTest) {
chaviwd4a61642020-09-01 14:53:46 -0700235 // Only graphics and system processes can create a secure display.
Ana Krulec13be8ad2018-08-21 02:43:56 +0000236 std::function<bool()> condition = [=]() {
237 sp<IBinder> testDisplay = SurfaceComposerClient::createDisplay(DISPLAY_NAME, true);
238 return testDisplay.get() != nullptr;
239 };
chaviwd4a61642020-09-01 14:53:46 -0700240
241 // Check with root.
Chavi Weingartenc73be482022-08-31 16:55:07 +0000242 {
243 UIDFaker f(AID_ROOT);
Patrick Williamse58a92b2024-02-29 14:52:25 -0600244 ASSERT_TRUE(condition());
Chavi Weingartenc73be482022-08-31 16:55:07 +0000245 }
chaviwd4a61642020-09-01 14:53:46 -0700246
247 // Check as a Graphics user.
Chavi Weingartenc73be482022-08-31 16:55:07 +0000248 {
249 UIDFaker f(AID_GRAPHICS);
250 ASSERT_TRUE(condition());
251 }
chaviwd4a61642020-09-01 14:53:46 -0700252
253 // Check as a system user.
Chavi Weingartenc73be482022-08-31 16:55:07 +0000254 {
255 UIDFaker f(AID_SYSTEM);
256 ASSERT_TRUE(condition());
257 }
chaviwd4a61642020-09-01 14:53:46 -0700258
259 // Check as a non-supported user.
Chavi Weingartenc73be482022-08-31 16:55:07 +0000260 {
261 UIDFaker f(AID_BIN);
262 ASSERT_FALSE(condition());
263 }
chaviwd4a61642020-09-01 14:53:46 -0700264
265 // Check as shell since shell has some additional permissions
Chavi Weingartenc73be482022-08-31 16:55:07 +0000266 {
267 UIDFaker f(AID_SHELL);
268 ASSERT_FALSE(condition());
269 }
Ana Krulec13be8ad2018-08-21 02:43:56 +0000270
271 condition = [=]() {
272 sp<IBinder> testDisplay = SurfaceComposerClient::createDisplay(DISPLAY_NAME, false);
273 return testDisplay.get() != nullptr;
274 };
275 ASSERT_NO_FATAL_FAILURE(checkWithPrivileges(condition, true, false));
276}
277
Ana Krulec13be8ad2018-08-21 02:43:56 +0000278TEST_F(CredentialsTest, CaptureLayersTest) {
279 setupBackgroundSurface();
280 sp<GraphicBuffer> outBuffer;
281 std::function<status_t()> condition = [=]() {
chaviw26c52482020-07-28 16:25:52 -0700282 LayerCaptureArgs captureArgs;
283 captureArgs.layerHandle = mBGSurfaceControl->getHandle();
284 captureArgs.sourceCrop = {0, 0, 1, 1};
285
286 ScreenCaptureResults captureResults;
chaviw8ffc7b82020-08-18 11:25:37 -0700287 return ScreenCapture::captureLayers(captureArgs, captureResults);
Ana Krulec13be8ad2018-08-21 02:43:56 +0000288 };
289 ASSERT_NO_FATAL_FAILURE(checkWithPrivileges<status_t>(condition, NO_ERROR, PERMISSION_DENIED));
290}
291
292/**
293 * The following tests are for methods accessible directly through SurfaceFlinger.
294 */
Ana Krulec13be8ad2018-08-21 02:43:56 +0000295TEST_F(CredentialsTest, GetLayerDebugInfo) {
296 setupBackgroundSurface();
Huihong Luo05539a12022-02-23 10:29:40 -0800297 sp<gui::ISurfaceComposer> sf(ComposerServiceAIDL::getComposerService());
Ana Krulec13be8ad2018-08-21 02:43:56 +0000298
299 // Historically, only root and shell can access the getLayerDebugInfo which
300 // is called when we call dumpsys. I don't see a reason why we should change this.
301 std::vector<LayerDebugInfo> outLayers;
Chavi Weingartenc73be482022-08-31 16:55:07 +0000302 binder::Status status = binder::Status::ok();
Ana Krulec13be8ad2018-08-21 02:43:56 +0000303 // Check with root.
Chavi Weingartenc73be482022-08-31 16:55:07 +0000304 {
305 UIDFaker f(AID_ROOT);
306 status = sf->getLayerDebugInfo(&outLayers);
307 ASSERT_EQ(NO_ERROR, statusTFromBinderStatus(status));
308 }
Ana Krulec13be8ad2018-08-21 02:43:56 +0000309
310 // Check as a shell.
Chavi Weingartenc73be482022-08-31 16:55:07 +0000311 {
312 UIDFaker f(AID_SHELL);
313 status = sf->getLayerDebugInfo(&outLayers);
314 ASSERT_EQ(NO_ERROR, statusTFromBinderStatus(status));
315 }
Ana Krulec13be8ad2018-08-21 02:43:56 +0000316
317 // Check as anyone else.
Chavi Weingartenc73be482022-08-31 16:55:07 +0000318 {
319 UIDFaker f(AID_BIN);
320 status = sf->getLayerDebugInfo(&outLayers);
321 ASSERT_EQ(PERMISSION_DENIED, statusTFromBinderStatus(status));
322 }
Ana Krulec13be8ad2018-08-21 02:43:56 +0000323}
Peiyong Lin4f3fddf2019-01-24 17:21:24 -0800324
325TEST_F(CredentialsTest, IsWideColorDisplayBasicCorrectness) {
Huihong Luo31b5ac22022-08-15 20:38:10 -0700326 const auto display = getFirstDisplayToken();
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800327 ASSERT_FALSE(display == nullptr);
Peiyong Lin4f3fddf2019-01-24 17:21:24 -0800328 bool result = false;
329 status_t error = SurfaceComposerClient::isWideColorDisplay(display, &result);
330 ASSERT_EQ(NO_ERROR, error);
331 bool hasWideColorMode = false;
Sally Qi6bb12822022-10-05 11:42:30 -0700332 const auto id = getFirstDisplayId();
333 ASSERT_TRUE(id);
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100334 ui::DynamicDisplayInfo info;
Sally Qi6bb12822022-10-05 11:42:30 -0700335 SurfaceComposerClient::getDynamicDisplayInfoFromId(*id, &info);
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100336 const auto& colorModes = info.supportedColorModes;
Peiyong Lin4f3fddf2019-01-24 17:21:24 -0800337 for (ColorMode colorMode : colorModes) {
338 switch (colorMode) {
339 case ColorMode::DISPLAY_P3:
340 case ColorMode::ADOBE_RGB:
341 case ColorMode::DCI_P3:
342 hasWideColorMode = true;
343 break;
344 default:
345 break;
346 }
347 }
348 ASSERT_EQ(hasWideColorMode, result);
349}
350
351TEST_F(CredentialsTest, IsWideColorDisplayWithPrivileges) {
Huihong Luo31b5ac22022-08-15 20:38:10 -0700352 const auto display = getFirstDisplayToken();
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800353 ASSERT_FALSE(display == nullptr);
Peiyong Lin4f3fddf2019-01-24 17:21:24 -0800354 std::function<status_t()> condition = [=]() {
355 bool result = false;
356 return SurfaceComposerClient::isWideColorDisplay(display, &result);
357 };
358 ASSERT_NO_FATAL_FAILURE(checkWithPrivileges<status_t>(condition, NO_ERROR, NO_ERROR));
359}
360
Peiyong Lind1fedb42019-03-11 17:48:41 -0700361TEST_F(CredentialsTest, GetActiveColorModeBasicCorrectness) {
Sally Qi6bb12822022-10-05 11:42:30 -0700362 const auto id = getFirstDisplayId();
363 ASSERT_TRUE(id);
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100364 ui::DynamicDisplayInfo info;
Sally Qi6bb12822022-10-05 11:42:30 -0700365 SurfaceComposerClient::getDynamicDisplayInfoFromId(*id, &info);
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100366 ColorMode colorMode = info.activeColorMode;
Peiyong Lind1fedb42019-03-11 17:48:41 -0700367 ASSERT_NE(static_cast<ColorMode>(BAD_VALUE), colorMode);
368}
369
Chavi Weingartenc78f53c2023-04-14 18:50:53 +0000370TEST_F(CredentialsTest, TransactionPermissionTest) {
371 WindowInfosListenerUtils windowInfosListenerUtils;
372 std::string name = "Test Layer";
373 sp<IBinder> token = sp<BBinder>::make();
374 WindowInfo windowInfo;
375 windowInfo.name = name;
376 windowInfo.token = token;
377 sp<SurfaceControl> surfaceControl =
378 mComposerClient->createSurface(String8(name.c_str()), 100, 100, PIXEL_FORMAT_RGBA_8888,
379 ISurfaceComposerClient::eFXSurfaceBufferState);
380 const Rect crop(0, 0, 100, 100);
381 {
382 UIDFaker f(AID_SYSTEM);
383 Transaction()
384 .setLayerStack(surfaceControl, ui::DEFAULT_LAYER_STACK)
385 .show(surfaceControl)
386 .setLayer(surfaceControl, INT32_MAX - 1)
387 .setCrop(surfaceControl, crop)
388 .setInputWindowInfo(surfaceControl, windowInfo)
389 .apply();
390 }
391
392 // Called from non privileged process
393 Transaction().setTrustedOverlay(surfaceControl, true);
394 {
395 UIDFaker f(AID_SYSTEM);
396 auto windowIsPresentAndNotTrusted = [&](const std::vector<WindowInfo>& windowInfos) {
397 auto foundWindowInfo =
398 WindowInfosListenerUtils::findMatchingWindowInfo(windowInfo, windowInfos);
399 if (!foundWindowInfo) {
400 return false;
401 }
402 return !foundWindowInfo->inputConfig.test(WindowInfo::InputConfig::TRUSTED_OVERLAY);
403 };
404 windowInfosListenerUtils.waitForWindowInfosPredicate(windowIsPresentAndNotTrusted);
405 }
406
407 {
408 UIDFaker f(AID_SYSTEM);
409 Transaction().setTrustedOverlay(surfaceControl, true);
410 auto windowIsPresentAndTrusted = [&](const std::vector<WindowInfo>& windowInfos) {
411 auto foundWindowInfo =
412 WindowInfosListenerUtils::findMatchingWindowInfo(windowInfo, windowInfos);
413 if (!foundWindowInfo) {
414 return false;
415 }
416 return foundWindowInfo->inputConfig.test(WindowInfo::InputConfig::TRUSTED_OVERLAY);
417 };
418 windowInfosListenerUtils.waitForWindowInfosPredicate(windowIsPresentAndTrusted);
419 }
420}
421
Ana Krulec13be8ad2018-08-21 02:43:56 +0000422} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -0800423
424// TODO(b/129481165): remove the #pragma below and fix conversion issues
425#pragma clang diagnostic pop // ignored "-Wconversion"