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

Commit 5a49974b authored by Arpit Singh's avatar Arpit Singh
Browse files

[CD Cursor] Switch to using real topology from DM

In this CL we:
1. Remove the hardcoded fake topology and switch to the real topology
   supplied by DM.
2. Fix a small bug in JNI code that translates Java topology objects to
   native.

Test: manual and presubmit
Bug: 362719483
Bug: 367661489
Flag: com.android.input.flags.connected_displays_cursor
Change-Id: I002e3329809e28054eecc6518f1c9bdce57777f2
parent 4a45579f
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -81,7 +81,7 @@ status_t android_hardware_display_DisplayTopologyGraphNode_toNative(
        for (jsize i = 0; i < length; i++) {
            ScopedLocalRef<jobject>
                    adjacentDisplayObj(env, env->GetObjectArrayElement(adjacentDisplaysArray, i));
            if (NULL != adjacentDisplayObj.get()) {
            if (NULL == adjacentDisplayObj.get()) {
                break; // found null element indicating end of used portion of the array
            }

@@ -109,7 +109,7 @@ DisplayTopologyGraph android_hardware_display_DisplayTopologyGraph_toNative(JNIE
        jsize length = env->GetArrayLength(nodesArray);
        for (jsize i = 0; i < length; i++) {
            ScopedLocalRef<jobject> nodeObj(env, env->GetObjectArrayElement(nodesArray, i));
            if (NULL != nodeObj.get()) {
            if (NULL == nodeObj.get()) {
                break; // found null element indicating end of used portion of the array
            }

+4 −45
Original line number Diff line number Diff line
@@ -571,9 +571,6 @@ private:
    PointerIcon loadPointerIcon(JNIEnv* env, ui::LogicalDisplayId displayId, PointerIconStyle type);
    bool isDisplayInteractive(ui::LogicalDisplayId displayId);

    // TODO(b/362719483) remove when the real topology is available
    void populateFakeDisplayTopology(const std::vector<DisplayViewport>& viewports);

    static inline JNIEnv* jniEnv() { return AndroidRuntime::getJNIEnv(); }
};

@@ -663,54 +660,16 @@ void NativeInputManager::setDisplayViewports(JNIEnv* env, jobjectArray viewportO
    mInputManager->getChoreographer().setDisplayViewports(viewports);
    mInputManager->getReader().requestRefreshConfiguration(
            InputReaderConfiguration::Change::DISPLAY_INFO);

    // TODO(b/362719483) remove when the real topology is available
    populateFakeDisplayTopology(viewports);
}

void NativeInputManager::populateFakeDisplayTopology(
        const std::vector<DisplayViewport>& viewports) {
void NativeInputManager::setDisplayTopology(JNIEnv* env, jobject topologyGraph) {
    if (!com::android::input::flags::connected_displays_cursor()) {
        return;
    }

    // create a fake topology assuming following order
    // default-display (top-edge) -> next-display (right-edge) -> next-display (right-edge) ...
    // This also adds a 100px offset on corresponding edge for better manual testing
    //   ┌────────┐
    //   │ next   ├─────────┐
    // ┌─└───────┐┤ next 2  │ ...
    // │ default │└─────────┘
    // └─────────┘
    DisplayTopologyGraph displaytopology;
    displaytopology.primaryDisplayId = ui::LogicalDisplayId::DEFAULT;

    // treat default display as base, in real topology it should be the primary-display
    ui::LogicalDisplayId previousDisplay = ui::LogicalDisplayId::DEFAULT;
    for (const auto& viewport : viewports) {
        if (viewport.displayId == ui::LogicalDisplayId::DEFAULT) {
            continue;
        }
        if (previousDisplay == ui::LogicalDisplayId::DEFAULT) {
            displaytopology.graph[previousDisplay].push_back(
                    {viewport.displayId, DisplayTopologyPosition::TOP, 100});
            displaytopology.graph[viewport.displayId].push_back(
                    {previousDisplay, DisplayTopologyPosition::BOTTOM, -100});
        } else {
            displaytopology.graph[previousDisplay].push_back(
                    {viewport.displayId, DisplayTopologyPosition::RIGHT, 100});
            displaytopology.graph[viewport.displayId].push_back(
                    {previousDisplay, DisplayTopologyPosition::LEFT, -100});
        }
        previousDisplay = viewport.displayId;
    }

    mInputManager->getChoreographer().setDisplayTopology(displaytopology);
}

void NativeInputManager::setDisplayTopology(JNIEnv* env, jobject topologyGraph) {
    android_hardware_display_DisplayTopologyGraph_toNative(env, topologyGraph);
    // TODO(b/367661489): Use the topology
    // TODO(b/383092013): Add topology validation
    mInputManager->getChoreographer().setDisplayTopology(
            android_hardware_display_DisplayTopologyGraph_toNative(env, topologyGraph));
}

base::Result<std::unique_ptr<InputChannel>> NativeInputManager::createInputChannel(