OSDN Git Service

Adjust profile priorities when setting auto-connect
authorRavi Nagarajan <nravi@broadcom.com>
Wed, 29 Aug 2012 12:29:51 +0000 (05:29 -0700)
committerMatthew Xie <mattx@google.com>
Wed, 29 Aug 2012 19:40:27 +0000 (12:40 -0700)
At a given point only one device should be set to have
PRIORITY_AUTO_CONNECT per profile. When setting a device priority
adjust the other devices' priority to make sure auto-connect
is attempted with only one device
bug 7076087

Change-Id: I1e03945a06e7acc901b53f34429194b3c3e76cd7

src/com/android/bluetooth/btservice/AdapterService.java

index b7994e1..7f2d378 100755 (executable)
@@ -952,11 +952,32 @@ public class AdapterService extends Service {
         }
     }
 
+     private void adjustOtherHeadsetPriorities(HeadsetService  hsService,
+                                                    BluetoothDevice connectedDevice) {
+        for (BluetoothDevice device : getBondedDevices()) {
+           if (hsService.getPriority(device) >= BluetoothProfile.PRIORITY_AUTO_CONNECT &&
+               !device.equals(connectedDevice)) {
+               hsService.setPriority(device, BluetoothProfile.PRIORITY_ON);
+           }
+        }
+     }
+
+     private void adjustOtherSinkPriorities(A2dpService a2dpService,
+                                                BluetoothDevice connectedDevice) {
+         for (BluetoothDevice device : getBondedDevices()) {
+             if (a2dpService.getPriority(device) >= BluetoothProfile.PRIORITY_AUTO_CONNECT &&
+                 !device.equals(connectedDevice)) {
+                 a2dpService.setPriority(device, BluetoothProfile.PRIORITY_ON);
+             }
+         }
+     }
+
      void setProfileAutoConnectionPriority (BluetoothDevice device, int profileId){
          if (profileId == BluetoothProfile.HEADSET) {
              HeadsetService  hsService = HeadsetService.getHeadsetService();
              if ((hsService != null) &&
                 (BluetoothProfile.PRIORITY_AUTO_CONNECT != hsService.getPriority(device))){
+                 adjustOtherHeadsetPriorities(hsService, device);
                  hsService.setPriority(device,BluetoothProfile.PRIORITY_AUTO_CONNECT);
              }
          }
@@ -964,6 +985,7 @@ public class AdapterService extends Service {
              A2dpService a2dpService = A2dpService.getA2dpService();
              if ((a2dpService != null) &&
                 (BluetoothProfile.PRIORITY_AUTO_CONNECT != a2dpService.getPriority(device))){
+                 adjustOtherSinkPriorities(a2dpService, device);
                  a2dpService.setPriority(device,BluetoothProfile.PRIORITY_AUTO_CONNECT);
              }
          }