Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit aab6a84f authored by Ravi Nagarajan's avatar Ravi Nagarajan Committed by Matthew Xie
Browse files

Adjust profile priorities when setting auto-connect

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
parent f2052acb
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -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);
             }
         }