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

Commit bd290f36 authored by Matthew DeVore's avatar Matthew DeVore
Browse files

DisplayTopology: fix NPE for empty topology

This fixes a bug introduced when refactoring calls of getAbsoluteBounds
to allNodesIdMap. The latter is more lightweight but does not handle
an empty topology like getAbsoluteBounds does. Return an empty map if
the topology is empty, rather then throw an NPE.

Bug: 416247314
Flag: EXEMPT bugfix
Test: SQ
Change-Id: I748dda801bb15a0546b731271dfe5567fdf14b34
parent 748126c8
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -834,10 +834,15 @@ public final class DisplayTopology implements Parcelable {
     */
    @NonNull
    public Map<Integer, TreeNode> allNodesIdMap() {
        var pend = new ArrayDeque<TreeNode>();
        var found = new HashMap<Integer, TreeNode>();

        if (mRoot == null) {
            return found;
        }

        var pend = new ArrayDeque<TreeNode>();
        pend.push(mRoot);

        do {
            TreeNode node = pend.pop();
            found.put(node.mDisplayId, node);
+13 −1
Original line number Diff line number Diff line
@@ -42,6 +42,9 @@ class DisplayTopologyTest {

        assertThat(topology.primaryDisplayId).isEqualTo(displayId)
        verifyDisplay(topology.root!!, displayId, width, height, density, noOfChildren = 0)

        assertThat(topology.allNodesIdMap())
            .isEqualTo(mapOf(displayId to topology.root!!))
    }

    @Test
@@ -62,9 +65,13 @@ class DisplayTopologyTest {
        assertThat(topology.primaryDisplayId).isEqualTo(displayId1)

        val display1 = topology.root!!
        val display2 = display1.children[0]
        verifyDisplay(display1, displayId1, width1, height1, density, noOfChildren = 1)
        verifyDisplay(display1.children[0], displayId2, width2, height2, density, POSITION_TOP,
        verifyDisplay(display2, displayId2, width2, height2, density, POSITION_TOP,
            offset = width1 / 2f - width2 / 2f, noOfChildren = 0)

        assertThat(topology.allNodesIdMap())
            .isEqualTo(mapOf(displayId1 to display1, displayId2 to display2))
    }

    @Test
@@ -1141,6 +1148,11 @@ class DisplayTopologyTest {
        }
    }

    @Test
    fun allNodesIdMap_nullRoot() {
        assertThat(topology.allNodesIdMap()).isEmpty()
    }

    data class DisplayArrangement(val logicalWidth: Int, val logicalHeight: Int,
            val logicalDensity: Int, val arrangeX: Float, val arrangeY: Float)