Merge "Fix CarUsbHandler to resolve all AOAP devices immediately." into qt-dev am: 0ef5b5e777
am: 6435aff567

Change-Id: I8ce0f46e0d732140441151c42dbcd1da584a4ac3
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 7af4f22..3fcb67b 100644
--- a/car-usb-handler/src/android/car/usb/handler/UsbHostController.java
+++ b/car-usb-handler/src/android/car/usb/handler/UsbHostController.java
@@ -20,6 +20,7 @@
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.hardware.usb.UsbDevice;
+import android.hardware.usb.UsbDeviceConnection;
 import android.hardware.usb.UsbManager;
 import android.os.Handler;
 import android.os.Looper;
@@ -198,6 +199,19 @@
         mUsbResolver.release();
     }
 
+    private boolean isDeviceAoapPossible(UsbDevice device) {
+        if (AoapInterface.isDeviceInAoapMode(device)) {
+            return true;
+        }
+
+        UsbManager usbManager = mContext.getSystemService(UsbManager.class);
+        UsbDeviceConnection connection = UsbUtil.openConnection(usbManager, device);
+        boolean aoapSupported = AoapInterface.isSupported(mContext, device, connection);
+        connection.close();
+
+        return aoapSupported;
+    }
+
     @Override
     public void onHandlersResolveCompleted(
             UsbDevice device, List<UsbDeviceSettings> handlers) {
@@ -210,8 +224,8 @@
             } 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
+                if (isDeviceAoapPossible(device)) {
+                    // Device supports 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) {