Changed getViewport strategy

If a uniqueId is specified, then it must match. If it is not specified,
then return the first display view port that has the requested type.
This means that if an internal or external viewport does not have any
uniqueId specified, there should only be 1 of each of these. Otherwise,
there will be confusion, and the viewports are not kept in any specific
order.

Test: atest -a libinput_tests inputflinger_tests
Bug: 111108021
Change-Id: I2437104ad98fa24334f2a8e19f1ca330bd873c93
diff --git a/services/inputflinger/InputReader.cpp b/services/inputflinger/InputReader.cpp
index 528e937..57fc17f 100644
--- a/services/inputflinger/InputReader.cpp
+++ b/services/inputflinger/InputReader.cpp
@@ -259,17 +259,12 @@
 bool InputReaderConfiguration::getDisplayViewport(ViewportType viewportType,
         const std::string& uniqueDisplayId, DisplayViewport* outViewport) const {
     for (const DisplayViewport& currentViewport : mDisplays) {
-        // for virtual displays, uniqueId must match
-        if (viewportType == ViewportType::VIEWPORT_VIRTUAL) {
-            if (currentViewport.type == ViewportType::VIEWPORT_VIRTUAL
-                    && currentViewport.uniqueId == uniqueDisplayId) {
+        if (currentViewport.type == viewportType) {
+            if (uniqueDisplayId.empty() ||
+                    (!uniqueDisplayId.empty() && uniqueDisplayId == currentViewport.uniqueId)) {
                 *outViewport = currentViewport;
                 return true;
             }
-        } else if (viewportType == currentViewport.type) {
-            // there can only be 1 internal or external viewport, for now
-            *outViewport = currentViewport;
-            return true;
         }
     }
     return false;