@@ -2189,4 +2189,138 @@ TEST_F(LayerSnapshotTest, shouldUpdatePictureProfilePriorityFromAppContentPriori
21892189 }
21902190}
21912191
2192+ // Test that child layers of the stop layer are hidden.
2193+ TEST_F (LayerSnapshotTest, stopLayer_hidesChildren) {
2194+ SET_FLAG_FOR_TEST (com::android::graphics::surfaceflinger::flags::stop_layer, true );
2195+ setStopLayer (1 , 122 );
2196+
2197+ std::vector<uint32_t > expected = {1 , 11 , 111 , 12 , 121 , 2 };
2198+ UPDATE_AND_VERIFY (mSnapshotBuilder , expected);
2199+ }
2200+
2201+ // Test that if a layer specifies itself as a stop layer, then it is hidden.
2202+ TEST_F (LayerSnapshotTest, stopLayer_hidesSelf) {
2203+ SET_FLAG_FOR_TEST (com::android::graphics::surfaceflinger::flags::stop_layer, true );
2204+ setStopLayer (122 , 122 );
2205+
2206+ std::vector<uint32_t > expected = {1 , 11 , 111 , 12 , 121 , 13 , 2 };
2207+ UPDATE_AND_VERIFY (mSnapshotBuilder , expected);
2208+ }
2209+
2210+ // Test that siblings z-ordered above a stop layer are hidden.
2211+ TEST_F (LayerSnapshotTest, stopLayer_hidesSiblings) {
2212+ SET_FLAG_FOR_TEST (com::android::graphics::surfaceflinger::flags::stop_layer, true );
2213+ setStopLayer (1 , 121 );
2214+
2215+ std::vector<uint32_t > expected = {1 , 11 , 111 , 12 , 2 };
2216+ UPDATE_AND_VERIFY (mSnapshotBuilder , expected);
2217+ }
2218+
2219+ // Test that children z-ordered below the stop layer aren't hidden.
2220+ TEST_F (LayerSnapshotTest, stopLayer_doesntHideZOrderedBelowChildren) {
2221+ SET_FLAG_FOR_TEST (com::android::graphics::surfaceflinger::flags::stop_layer, true );
2222+ setZ (121 , -1 );
2223+ setStopLayer (1 , 12 );
2224+
2225+ std::vector<uint32_t > expected = {1 , 11 , 111 , 121 , 2 };
2226+ UPDATE_AND_VERIFY (mSnapshotBuilder , expected);
2227+ }
2228+
2229+ // Test that relative children are hidden by the stop layer.
2230+ TEST_F (LayerSnapshotTest, stopLayer_hidesRelativeChild) {
2231+ SET_FLAG_FOR_TEST (com::android::graphics::surfaceflinger::flags::stop_layer, true );
2232+ reparentRelativeLayer (111 , 12 );
2233+ setStopLayer (1 , 12 );
2234+
2235+ std::vector<uint32_t > expected = {1 , 11 , 2 };
2236+ UPDATE_AND_VERIFY (mSnapshotBuilder , expected);
2237+ }
2238+
2239+ // Test that detached children aren't hidden by the stop layer.
2240+ TEST_F (LayerSnapshotTest, stopLayer_doesntHideDetachedChildren) {
2241+ SET_FLAG_FOR_TEST (com::android::graphics::surfaceflinger::flags::stop_layer, true );
2242+ reparentRelativeLayer (121 , 11 );
2243+ setStopLayer (1 , 12 );
2244+
2245+ std::vector<uint32_t > expected = {1 , 11 , 111 , 121 , 2 };
2246+ UPDATE_AND_VERIFY (mSnapshotBuilder , expected);
2247+ }
2248+
2249+ // Test that stop layers work on hierarchies with a single root layer.
2250+ TEST_F (LayerSnapshotTest, stopLayer_singleRoot) {
2251+ SET_FLAG_FOR_TEST (com::android::graphics::surfaceflinger::flags::stop_layer, true );
2252+ setStopLayer (1 , 11 );
2253+
2254+ LayerHierarchy root = mHierarchyBuilder .getPartialHierarchy (1 , /* childrenOnly=*/ false );
2255+ LayerSnapshotBuilder::Args args{.root = root,
2256+ .layerLifecycleManager = mLifecycleManager ,
2257+ .includeMetadata = false ,
2258+ .displays = mFrontEndDisplayInfos ,
2259+ .displayChanges = false ,
2260+ .globalShadowSettings = globalShadowSettings,
2261+ .supportsBlur = true ,
2262+ .supportedLayerGenericMetadata = {},
2263+ .genericLayerMetadataKeyMap = {}};
2264+ mSnapshotBuilder .update (args);
2265+
2266+ std::vector<uint32_t > expectedVisibleLayers = {1 };
2267+ std::vector<uint32_t > actualVisibleLayers;
2268+ mSnapshotBuilder .forEachVisibleSnapshot ([&actualVisibleLayers](const LayerSnapshot& snapshot) {
2269+ actualVisibleLayers.push_back (snapshot.path .id );
2270+ });
2271+ EXPECT_EQ (expectedVisibleLayers, actualVisibleLayers);
2272+ }
2273+
2274+ // Test two stop layers where there's no interaction between the two stop layers.
2275+ TEST_F (LayerSnapshotTest, stopLayer_multipleStopLayers_parentAfterChild) {
2276+ SET_FLAG_FOR_TEST (com::android::graphics::surfaceflinger::flags::stop_layer, true );
2277+ setStopLayer (1 , 13 );
2278+ setStopLayer (11 , 111 );
2279+
2280+ std::vector<uint32_t > expected = {1 , 11 , 12 , 121 , 122 , 1221 , 2 };
2281+ UPDATE_AND_VERIFY (mSnapshotBuilder , expected);
2282+ }
2283+
2284+ // Test two stop layers where the hierarchy containing the second stop layer is hidden.
2285+ TEST_F (LayerSnapshotTest, stopLayer_multipleStopLayers_childHidden) {
2286+ SET_FLAG_FOR_TEST (com::android::graphics::surfaceflinger::flags::stop_layer, true );
2287+ setStopLayer (1 , 12 );
2288+ setStopLayer (12 , 122 );
2289+
2290+ std::vector<uint32_t > expected = {1 , 11 , 111 , 2 };
2291+ UPDATE_AND_VERIFY (mSnapshotBuilder , expected);
2292+ }
2293+
2294+ // Test two stop layers where the stop layer specified lower in the hierarchy overrides
2295+ // the stop layer specified higher in the hierarchy.
2296+ TEST_F (LayerSnapshotTest, stopLayer_multipleStopLayers_childStopLayerOverridden) {
2297+ SET_FLAG_FOR_TEST (com::android::graphics::surfaceflinger::flags::stop_layer, true );
2298+ setStopLayer (1 , 121 );
2299+ setStopLayer (12 , 122 );
2300+
2301+ std::vector<uint32_t > expected = {1 , 11 , 111 , 12 , 2 };
2302+ UPDATE_AND_VERIFY (mSnapshotBuilder , expected);
2303+ }
2304+
2305+ // Test two stop layers where the stop layer specified higher in the hierarchy applies because
2306+ // it appears before the stop layer applied lower in the hierarchy.
2307+ TEST_F (LayerSnapshotTest, stopLayer_multipleStopLayers_childApplied) {
2308+ SET_FLAG_FOR_TEST (com::android::graphics::surfaceflinger::flags::stop_layer, true );
2309+ setStopLayer (1 , 13 );
2310+ setStopLayer (11 , 111 );
2311+
2312+ std::vector<uint32_t > expected = {1 , 11 , 12 , 121 , 122 , 1221 , 2 };
2313+ UPDATE_AND_VERIFY (mSnapshotBuilder , expected);
2314+ }
2315+
2316+ // Test that the stop layer works on mirrored hierarchies.
2317+ TEST_F (LayerSnapshotTest, stopLayer_mirrorHierarchy) {
2318+ SET_FLAG_FOR_TEST (com::android::graphics::surfaceflinger::flags::stop_layer, true );
2319+ createDisplayMirrorLayer (3 , ui::LayerStack::fromValue (0 ), 121 );
2320+ setLayerStack (3 , 1 );
2321+
2322+ std::vector<uint32_t > expected = {1 , 11 , 111 , 12 , 121 , 122 , 1221 , 13 , 2 , 3 , 1 , 11 , 111 , 12 };
2323+ UPDATE_AND_VERIFY (mSnapshotBuilder , expected);
2324+ }
2325+
21922326} // namespace android::surfaceflinger::frontend
0 commit comments