Update the how we propogate parent type and appId
SurfaceFlinger sends each layer's metadata (i.e. type and appId) to
the hardware composer. The feature was introduced in Android Q for
the 2D-in-VR feature that Daydream uses. The logic was introduced in
ag/3738015.
When sending layer information to hal, layers also inherit type and
app id from parent node when parent node has valid type/appId.
However, there are some descendents about what is the invalid type and
appId. The original CL ag/3738015 assumes -1 is invalid, while newer
CLs ag/6072974 and unittests assumes 0 as default value.
Actually, the current unittests is correct, for two reasons:
1/ window type comes from WindowManager.LayoutParams and all values
defined here are non-zero.
2/ appId is basically app's UID, which should not be zero (i.e. app
never runs under root).
Thus, I now have enough reason to conclude that the parent type and
appId should be tested with "type > 0 && appId > 0". In another word,
the parent is only valid when the type and appId are both non-zero.
Bug: 133452166
Test: Inspect the output of
"adb shell lshal debug
android.hardware.graphics.composer@2.1::IComposer/vr"
and verify that each layer's type and app_id are correctly
populated.
Test: atest libsurfaceflinger_unittest
Change-Id: Ib039a54bba241839f49e0be6d87c021001b470e9
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 3ca6ef5..832067b 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -415,7 +415,7 @@
auto& parentState = parent->getDrawingState();
const int parentType = parentState.metadata.getInt32(METADATA_WINDOW_TYPE, 0);
const int parentAppId = parentState.metadata.getInt32(METADATA_OWNER_UID, 0);
- if (parentType >= 0 || parentAppId >= 0) {
+ if (parentType > 0 && parentAppId > 0) {
type = parentType;
appId = parentAppId;
}