Merge branch 'master' of ssh://android-git.corp.google.com:29418/platform/frameworks/base
diff --git a/core/java/android/bluetooth/BluetoothUuid.java b/core/java/android/bluetooth/BluetoothUuid.java
index 96b93f9..f8316a5 100644
--- a/core/java/android/bluetooth/BluetoothUuid.java
+++ b/core/java/android/bluetooth/BluetoothUuid.java
@@ -52,7 +52,7 @@
     }
 
     public static boolean isHandsfree(UUID uuid) {
-        return uuid.equals(Handsfree) || uuid.equals(HandsfreeAudioGateway);
+        return uuid.equals(Handsfree);
     }
 
     public static boolean isHeadset(UUID uuid) {
diff --git a/core/java/android/server/BluetoothA2dpService.java b/core/java/android/server/BluetoothA2dpService.java
index 1cf7be9..722a7cc 100644
--- a/core/java/android/server/BluetoothA2dpService.java
+++ b/core/java/android/server/BluetoothA2dpService.java
@@ -104,7 +104,8 @@
                     break;
                 }
             } else if (action.equals(BluetoothIntent.REMOTE_DEVICE_CONNECTED_ACTION)) {
-                if (getSinkPriority(address) > BluetoothA2dp.PRIORITY_OFF) {
+                if (getSinkPriority(address) > BluetoothA2dp.PRIORITY_OFF &&
+                        isSinkDevice(address)) {
                     // This device is a preferred sink. Make an A2DP connection
                     // after a delay. We delay to avoid connection collisions,
                     // and to give other profiles such as HFP a chance to
@@ -185,6 +186,18 @@
         return -1;
     }
 
+    private boolean isSinkDevice(String address) {
+        String uuids[] = mBluetoothService.getRemoteUuids(address);
+        UUID uuid;
+        for (String deviceUuid: uuids) {
+            uuid = UUID.fromString(deviceUuid);
+            if (BluetoothUuid.isAudioSink(uuid)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     private synchronized boolean addAudioSink (String address) {
         String path = mBluetoothService.getObjectPathFromAddress(address);
         String propValues[] = (String []) getSinkPropertiesNative(path);
diff --git a/core/java/android/server/BluetoothEventLoop.java b/core/java/android/server/BluetoothEventLoop.java
index 38eb4d7..76906b6 100644
--- a/core/java/android/server/BluetoothEventLoop.java
+++ b/core/java/android/server/BluetoothEventLoop.java
@@ -371,9 +371,7 @@
 
         boolean authorized = false;
         UUID uuid = UUID.fromString(deviceUuid);
-        if (mBluetoothService.isEnabled() && (BluetoothUuid.isAudioSink(uuid) ||
-                                              BluetoothUuid.isAudioSource(uuid) ||
-                                              BluetoothUuid.isAdvAudioDist(uuid))) {
+        if (mBluetoothService.isEnabled() && BluetoothUuid.isAudioSink(uuid)) {
             BluetoothA2dp a2dp = new BluetoothA2dp(mContext);
             authorized = a2dp.getSinkPriority(address) > BluetoothA2dp.PRIORITY_OFF;
             if (authorized) {