Try harder to connect to bluetooth

When BluetoothRouteManager is told to connect with a null device or with
a device that doesn't match anything in the availablity list, and the
active device as reported by the BT stack is null, don't just give up.
Try connecting to just any other device.

Bug: 112018166
Test: unit, manual
Change-Id: Iaf6c570e715311c6b263c0373a7ac70e157aaf7b
Merged-In: Iaf6c570e715311c6b263c0373a7ac70e157aaf7b
diff --git a/src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java b/src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java
index ba56145..f72c342 100644
--- a/src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java
+++ b/src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java
@@ -597,14 +597,20 @@
 
         String actualAddress = matchingDevice.isPresent()
                 ? address : getActiveDeviceAddress();
+        if (actualAddress == null) {
+            Log.i(this, "No device specified and BT stack has no active device."
+                    + " Using arbitrary device");
+            if (deviceList.size() > 0) {
+                actualAddress = deviceList.iterator().next().getAddress();
+            } else {
+                Log.i(this, "No devices available at all. Not connecting.");
+                return null;
+            }
+        }
         if (!matchingDevice.isPresent()) {
             Log.i(this, "No device with address %s available. Using %s instead.",
                     address, actualAddress);
         }
-        if (actualAddress == null) {
-            Log.i(this, "No device specified and BT stack has no active device. Not connecting.");
-            return null;
-        }
         if (!connectAudio(actualAddress)) {
             boolean shouldRetry = retryCount < MAX_CONNECTION_RETRIES;
             Log.w(LOG_TAG, "Could not connect to %s. Will %s", actualAddress,