From fc6eab5d5b3c6372118ba5193bcf5ea7e73a0a67 Mon Sep 17 00:00:00 2001 From: Alan Ding Date: Thu, 2 May 2024 18:28:45 -0700 Subject: SF: Propagate uniqueID when creating virtual displays This is part of Trunk Stable effort to upstream SF-ARC screen record capabiliy (undiverging http://ag/20003031) which requires mirroring virtual displays to be associated with screen capture sessions using the package name within the unique ID. Creating virtual display with unique ID specified is optional such that it doesn't affect existing consumers who don't need it (i.e. av). Bug: 137375833 Bug: 194863377 Test: libsurfaceflinger_unittest Change-Id: Ia3cd13df07f701593ddc94c196df0b04844cf502 --- services/surfaceflinger/SurfaceFlinger.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'services/surfaceflinger/SurfaceFlinger.cpp') diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 3ec5f213e0..6b117b8a17 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -577,13 +577,13 @@ void SurfaceFlinger::run() { mScheduler->run(); } -sp SurfaceFlinger::createDisplay(const String8& displayName, bool secure, - float requestedRefreshRate) { +sp SurfaceFlinger::createDisplay(const String8& displayName, bool isSecure, + const std::string& uniqueId, float requestedRefreshRate) { // SurfaceComposerAIDL checks for some permissions, but adding an additional check here. // This is to ensure that only root, system, and graphics can request to create a secure // display. Secure displays can show secure content so we add an additional restriction on it. - const int uid = IPCThreadState::self()->getCallingUid(); - if (secure && uid != AID_ROOT && uid != AID_GRAPHICS && uid != AID_SYSTEM) { + const uid_t uid = IPCThreadState::self()->getCallingUid(); + if (isSecure && uid != AID_ROOT && uid != AID_GRAPHICS && uid != AID_SYSTEM) { ALOGE("Only privileged processes can create a secure display"); return nullptr; } @@ -607,11 +607,12 @@ sp SurfaceFlinger::createDisplay(const String8& displayName, bool secur Mutex::Autolock _l(mStateLock); // Display ID is assigned when virtual display is allocated by HWC. DisplayDeviceState state; - state.isSecure = secure; + state.isSecure = isSecure; // Set display as protected when marked as secure to ensure no behavior change // TODO (b/314820005): separate as a different arg when creating the display. - state.isProtected = secure; + state.isProtected = isSecure; state.displayName = displayName; + state.uniqueId = uniqueId; state.requestedRefreshRate = Fps::fromValue(requestedRefreshRate); mCurrentState.displays.add(token, state); return token; @@ -9530,7 +9531,8 @@ binder::Status SurfaceComposerAIDL::createConnection(sp* outDisplay) { status_t status = checkAccessPermission(); @@ -9538,7 +9540,7 @@ binder::Status SurfaceComposerAIDL::createDisplay(const std::string& displayName return binderStatusFromStatusT(status); } String8 displayName8 = String8::format("%s", displayName.c_str()); - *outDisplay = mFlinger->createDisplay(displayName8, secure, requestedRefreshRate); + *outDisplay = mFlinger->createDisplay(displayName8, isSecure, uniqueId, requestedRefreshRate); return binder::Status::ok(); } @@ -9555,10 +9557,10 @@ binder::Status SurfaceComposerAIDL::getPhysicalDisplayIds(std::vector* std::vector physicalDisplayIds = mFlinger->getPhysicalDisplayIds(); std::vector displayIds; displayIds.reserve(physicalDisplayIds.size()); - for (auto item : physicalDisplayIds) { - displayIds.push_back(static_cast(item.value)); + for (const auto id : physicalDisplayIds) { + displayIds.push_back(static_cast(id.value)); } - *outDisplayIds = displayIds; + *outDisplayIds = std::move(displayIds); return binder::Status::ok(); } -- cgit v1.2.3-59-g8ed1b