Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e3c540ad authored by Jordan Demeulenaere's avatar Jordan Demeulenaere
Browse files

Prevent NPE when placing fading elements

This CL fixes an NPE that can happen since http://ag/27685078: the
placeWithLayer block can still run even if an element is removed from
composition.

Bug: 290930950
Test: Manual. Unfortunately it's impossible to add tests for this
 because the timings solely depend on the invalidation of the graphics
 layer by the Compose runtime. I have not observed the NPE with this
 change, but I also didn't have manual reproduction steps.
Flag: com.android.systemui.scene_container
Change-Id: Ic8bd91b3d6fd3f8b3d697c72a42bb5f278f5d207
parent 906dad1c
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -381,11 +381,15 @@ internal class ElementNode(
            } else {
                placeable.placeWithLayer(offset) {
                    // This layer might still run on its own (outside of the placement phase) even
                    // if this element is not placed anymore, so we need to double check again here
                    // before calling [elementAlpha] (which will update [SceneState.lastAlpha]). We
                    // also need to recompute the current transition to make sure that we are using
                    // the current transition and not a reference to an old one. See b/343138966 for
                    // details.
                    // if this element is not placed or composed anymore, so we need to double check
                    // again here before calling [elementAlpha] (which will update
                    // [SceneState.lastAlpha]). We also need to recompute the current transition to
                    // make sure that we are using the current transition and not a reference to an
                    // old one. See b/343138966 for details.
                    if (_element == null) {
                        return@placeWithLayer
                    }

                    val transition = elementTransition(layoutImpl, element, currentTransitions)
                    if (!shouldPlaceElement(layoutImpl, scene.key, element, transition)) {
                        return@placeWithLayer