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

Commit 9e91e83d authored by Matthew DeVore's avatar Matthew DeVore Committed by Android (Google) Code Review
Browse files

Merge "DisplayTopology: fix NPE for empty topology" into main

parents 9133df32 bd290f36
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -835,10 +835,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)