Redirect connected USB device to AOAP handler

If connected USB device switched to AOAP mode and it has only one AOAP
handler (app), then rediect it automatically to that app.
Currently it shows disambiguation dialog which doesn't make sense.

Bug:127853410
Test: manually verified that projection starts w/o disambiguation dialog
Change-Id: Idc3b7e2948a59c6fea668fe35c4f040ba0028a61
(cherry picked from commit ce58672361e9be36e33193f6f43a1b3b8bab252d)
diff --git a/car-usb-handler/src/android/car/usb/handler/UsbHostController.java b/car-usb-handler/src/android/car/usb/handler/UsbHostController.java
index e4b6df3..ec9a89a 100644
--- a/car-usb-handler/src/android/car/usb/handler/UsbHostController.java
+++ b/car-usb-handler/src/android/car/usb/handler/UsbHostController.java
@@ -199,6 +199,15 @@
             } else if (handlers.size() == 1) {
                 applyDeviceSettings(handlers.get(0));
             } else {
+                if (AoapInterface.isDeviceInAoapMode(device)) {
+                    // Device is in AOAP mode, if we have just single AOAP handler then use it
+                    // instead of showing disambiguation dialog to the user.
+                    UsbDeviceSettings aoapHandler = getSingleAoapDeviceHandlerOrNull(handlers);
+                    if (aoapHandler != null) {
+                        applyDeviceSettings(aoapHandler);
+                        return;
+                    }
+                }
                 mCallback.optionsUpdated(handlers);
             }
         } else {
@@ -206,6 +215,19 @@
         }
     }
 
+    private UsbDeviceSettings getSingleAoapDeviceHandlerOrNull(List<UsbDeviceSettings> handlers) {
+        UsbDeviceSettings aoapHandler = null;
+        for (UsbDeviceSettings handler : handlers) {
+            if (handler.getAoap()) {
+                if (aoapHandler != null) { // Found multiple AOAP handlers.
+                    return null;
+                }
+                aoapHandler = handler;
+            }
+        }
+        return aoapHandler;
+    }
+
     @Override
     public void onDeviceDispatched() {
         stopDeviceProcessing();