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
diff --git a/services/surfaceflinger/tests/unittests/SurfaceFlinger_CreateDisplayTest.cpp b/services/surfaceflinger/tests/unittests/SurfaceFlinger_CreateDisplayTest.cpp
index 28162f4..bf5ae21 100644
--- a/services/surfaceflinger/tests/unittests/SurfaceFlinger_CreateDisplayTest.cpp
+++ b/services/surfaceflinger/tests/unittests/SurfaceFlinger_CreateDisplayTest.cpp
@@ -132,6 +132,36 @@
EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame()).Times(1);
}
+TEST_F(CreateDisplayTest, createDisplaySetsCurrentStateForUniqueId) {
+ const String8 name("virtual.test");
+ const std::string uniqueId = "virtual:package:id";
+
+ // --------------------------------------------------------------------
+ // Call Expectations
+
+ // --------------------------------------------------------------------
+ // Invocation
+
+ sp<IBinder> displayToken = mFlinger.createDisplay(name, false, uniqueId);
+
+ // --------------------------------------------------------------------
+ // Postconditions
+
+ // The display should have been added to the current state
+ ASSERT_TRUE(hasCurrentDisplayState(displayToken));
+ const auto& display = getCurrentDisplayState(displayToken);
+ EXPECT_TRUE(display.isVirtual());
+ EXPECT_FALSE(display.isSecure);
+ EXPECT_EQ(display.uniqueId, "virtual:package:id");
+ EXPECT_EQ(name.c_str(), display.displayName);
+
+ // --------------------------------------------------------------------
+ // Cleanup conditions
+
+ // Creating the display commits a display transaction.
+ EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame()).Times(1);
+}
+
// Requesting 0 tells SF not to do anything, i.e., default to refresh as physical displays
TEST_F(CreateDisplayTest, createDisplayWithRequestedRefreshRate0) {
const String8 displayName("virtual.test");
diff --git a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
index 82023b0..3b03f92 100644
--- a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
+++ b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
@@ -411,8 +411,15 @@
commit(kComposite);
}
- auto createDisplay(const String8& displayName, bool secure, float requestedRefreshRate = 0.0f) {
- return mFlinger->createDisplay(displayName, secure, requestedRefreshRate);
+ auto createDisplay(const String8& displayName, bool isSecure,
+ float requestedRefreshRate = 0.0f) {
+ const std::string testId = "virtual:libsurfaceflinger_unittest:TestableSurfaceFlinger";
+ return mFlinger->createDisplay(displayName, isSecure, testId, requestedRefreshRate);
+ }
+
+ auto createDisplay(const String8& displayName, bool isSecure, const std::string& uniqueId,
+ float requestedRefreshRate = 0.0f) {
+ return mFlinger->createDisplay(displayName, isSecure, uniqueId, requestedRefreshRate);
}
auto destroyDisplay(const sp<IBinder>& displayToken) {