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

Commit d8437b68 authored by Arpit Singh's avatar Arpit Singh
Browse files

Use the static topology validator

This is a follow up from ag/32211998.

Test: atest DisplayTopologyGraphTest/DisplayTopologyGraphTestFixture
Bug: 401219231
Flag: com.android.input.flags.enable_display_topology_validation
Change-Id: Id1c6ae6ba02271a65b410475e697508b3979db90
parent bf37af00
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -96,10 +96,12 @@ status_t android_hardware_display_DisplayTopologyGraphNode_toNative(
    return OK;
}

DisplayTopologyGraph android_hardware_display_DisplayTopologyGraph_toNative(JNIEnv* env,
                                                                            jobject topologyObj) {
    DisplayTopologyGraph topology;
    topology.primaryDisplayId = ui::LogicalDisplayId{
base::Result<const DisplayTopologyGraph> android_hardware_display_DisplayTopologyGraph_toNative(
        JNIEnv* env, jobject topologyObj) {
    std::unordered_map<ui::LogicalDisplayId, std::vector<DisplayTopologyAdjacentDisplay>>
            topologyGraph;
    std::unordered_map<ui::LogicalDisplayId, int> displaysDensity;
    ui::LogicalDisplayId primaryDisplayId = ui::LogicalDisplayId{
            env->GetIntField(topologyObj, gDisplayTopologyGraphClassInfo.primaryDisplayId)};

    jobjectArray nodesArray = static_cast<jobjectArray>(
@@ -114,11 +116,12 @@ DisplayTopologyGraph android_hardware_display_DisplayTopologyGraph_toNative(JNIE
            }

            android_hardware_display_DisplayTopologyGraphNode_toNative(env, nodeObj.get(),
                                                                       topology.graph,
                                                                       topology.displaysDensity);
                                                                       /*byRef*/ topologyGraph,
                                                                       /*byRef*/ displaysDensity);
        }
    }
    return topology;
    return DisplayTopologyGraph::create(primaryDisplayId, std::move(topologyGraph),
                                        std::move(displaysDensity));
}

// ----------------------------------------------------------------------------
+3 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

#pragma once

#include <android-base/result.h>
#include <input/DisplayTopologyGraph.h>

#include "jni.h"
@@ -26,7 +27,7 @@ namespace android {
 * Copies the contents of a DVM DisplayTopology object to a new native DisplayTopology instance.
 * Returns DisplayTopology.
 */
extern DisplayTopologyGraph android_hardware_display_DisplayTopologyGraph_toNative(
        JNIEnv* env, jobject eventObj);
extern base::Result<const DisplayTopologyGraph>
android_hardware_display_DisplayTopologyGraph_toNative(JNIEnv* env, jobject eventObj);

} // namespace android
+4 −3
Original line number Diff line number Diff line
@@ -671,13 +671,14 @@ void NativeInputManager::setDisplayTopology(JNIEnv* env, jobject topologyGraph)
        return;
    }

    const DisplayTopologyGraph displayTopology =
    const base::Result<DisplayTopologyGraph> result =
            android_hardware_display_DisplayTopologyGraph_toNative(env, topologyGraph);
    if (input_flags::enable_display_topology_validation() && !displayTopology.isValid()) {
        LOG(ERROR) << "Ignoring Invalid DisplayTopology";
    if (!result.ok()) {
        LOG(ERROR) << "Ignoring Invalid DisplayTopology" << result.error();
        return;
    }

    const DisplayTopologyGraph& displayTopology = result.value();
    mInputManager->getDispatcher().setDisplayTopology(displayTopology);
    mInputManager->getChoreographer().setDisplayTopology(displayTopology);
}