Add display topology to input dump

Add display topology to dump in Dispatcher and Choreographer for
debugging.

Bug: 245989146
Test: dumpsys input
Flag: EXEMPT log only update
Change-Id: I8e9eb4d5c3c88e1cb6aeaa35db07006b003aad93
diff --git a/include/input/DisplayTopologyGraph.h b/include/input/DisplayTopologyGraph.h
index ce7259e..9fc080d 100644
--- a/include/input/DisplayTopologyGraph.h
+++ b/include/input/DisplayTopologyGraph.h
@@ -46,6 +46,8 @@
     DisplayTopologyPosition position;
     // The offset in DP of the adjacent display, relative to the source display.
     float offsetDp;
+
+    std::string dump() const;
 };
 
 /**
@@ -57,6 +59,7 @@
     std::unordered_map<ui::LogicalDisplayId, int> displaysDensity;
 
     bool isValid() const;
+    std::string dump() const;
 };
 
 } // namespace android
diff --git a/libs/input/DisplayTopologyGraph.cpp b/libs/input/DisplayTopologyGraph.cpp
index 7ad9f16..934f2e8 100644
--- a/libs/input/DisplayTopologyGraph.cpp
+++ b/libs/input/DisplayTopologyGraph.cpp
@@ -17,15 +17,20 @@
 #define LOG_TAG "DisplayTopologyValidator"
 
 #include <android-base/logging.h>
+#include <android-base/stringprintf.h>
 #include <ftl/enum.h>
 #include <input/DisplayTopologyGraph.h>
+#include <input/PrintTools.h>
 #include <ui/LogicalDisplayId.h>
 
 #include <algorithm>
 
+#define INDENT "  "
+
 namespace android {
 
 namespace {
+
 DisplayTopologyPosition getOppositePosition(DisplayTopologyPosition position) {
     switch (position) {
         case DisplayTopologyPosition::LEFT:
@@ -95,11 +100,45 @@
     return true;
 }
 
+std::string logicalDisplayIdToString(const ui::LogicalDisplayId& displayId) {
+    return base::StringPrintf("displayId(%d)", displayId.val());
+}
+
+std::string adjacentDisplayToString(const DisplayTopologyAdjacentDisplay& adjacentDisplay) {
+    return adjacentDisplay.dump();
+}
+
+std::string adjacentDisplayVectorToString(
+        const std::vector<DisplayTopologyAdjacentDisplay>& adjacentDisplays) {
+    return dumpVector(adjacentDisplays, adjacentDisplayToString);
+}
+
 } // namespace
 
+std::string DisplayTopologyAdjacentDisplay::dump() const {
+    std::string dump;
+    dump += base::StringPrintf("DisplayTopologyAdjacentDisplay: {displayId: %d, position: %s, "
+                               "offsetDp: %f}",
+                               displayId.val(), ftl::enum_string(position).c_str(), offsetDp);
+    return dump;
+}
+
 bool DisplayTopologyGraph::isValid() const {
     return validatePrimaryDisplay(*this) && validateTopologyGraph(*this) &&
             validateDensities(*this);
 }
 
+std::string DisplayTopologyGraph::dump() const {
+    std::string dump;
+    dump += base::StringPrintf("PrimaryDisplayId: %d\n", primaryDisplayId.val());
+    dump += base::StringPrintf("TopologyGraph:\n");
+    dump += addLinePrefix(dumpMap(graph, logicalDisplayIdToString, adjacentDisplayVectorToString),
+                          INDENT);
+    dump += "\n";
+    dump += base::StringPrintf("DisplaysDensity:\n");
+    dump += addLinePrefix(dumpMap(displaysDensity, logicalDisplayIdToString), INDENT);
+    dump += "\n";
+    return dump;
+}
+
 } // namespace android
diff --git a/services/inputflinger/PointerChoreographer.cpp b/services/inputflinger/PointerChoreographer.cpp
index f8ab830..98f0f34 100644
--- a/services/inputflinger/PointerChoreographer.cpp
+++ b/services/inputflinger/PointerChoreographer.cpp
@@ -31,6 +31,7 @@
 #include "PointerChoreographer.h"
 
 #define INDENT "  "
+#define INDENT2 "    "
 
 namespace android {
 
@@ -647,6 +648,8 @@
         std::string pointerControllerDump = addLinePrefix(drawingTabletController->dump(), INDENT);
         dump += INDENT + std::to_string(deviceId) + " : " + pointerControllerDump;
     }
+    dump += INDENT "DisplayTopologyGraph:\n";
+    dump += addLinePrefix(mTopology.dump(), INDENT2);
     dump += "\n";
 }
 
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index ef50fc0..1fa0426 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -5222,6 +5222,9 @@
     } else {
         dump += "Displays: <none>\n";
     }
+    dump += "DisplayTopologyGraph:\n";
+    dump += addLinePrefix(mTopology.dump(), INDENT);
+    dump += "\n";
     return dump;
 }