public boolean disconnect(BluetoothDevice device) {
   if (mService == null) return false;
   // Downgrade priority as user is disconnecting the headset.
   if (mService.getPriority(device) > BluetoothProfile.PRIORITY_ON) {
     mService.setPriority(device, BluetoothProfile.PRIORITY_ON);
   }
   return mService.disconnect(device);
 }
 boolean isA2dpPlaying() {
   if (mService == null) return false;
   List<BluetoothDevice> sinks = mService.getConnectedDevices();
   if (!sinks.isEmpty()) {
     if (mService.isA2dpPlaying(sinks.get(0))) {
       return true;
     }
   }
   return false;
 }
 public void setPreferred(BluetoothDevice device, boolean preferred) {
   if (mService == null) return;
   if (preferred) {
     if (mService.getPriority(device) < BluetoothProfile.PRIORITY_ON) {
       mService.setPriority(device, BluetoothProfile.PRIORITY_ON);
     }
   } else {
     mService.setPriority(device, BluetoothProfile.PRIORITY_OFF);
   }
 }
 public boolean connect(BluetoothDevice device) {
   if (mService == null) return false;
   List<BluetoothDevice> sinks = getConnectedDevices();
   if (sinks != null) {
     if (sinks.contains(device)) {
       Log.d(
           TAG,
           "The attempt connecting device is the already in the connected device list, do not need disconnect, connect, just return true");
       return true;
     }
     for (BluetoothDevice sink : sinks) {
       mService.disconnect(sink);
     }
   }
   return mService.connect(device);
 }
 public List<BluetoothDevice> getConnectedDevices() {
   if (mService == null) return new ArrayList<BluetoothDevice>(0);
   return mService.getDevicesMatchingConnectionStates(
       new int[] {
         BluetoothProfile.STATE_CONNECTED,
         BluetoothProfile.STATE_CONNECTING,
         BluetoothProfile.STATE_DISCONNECTING
       });
 }
 public int getPreferred(BluetoothDevice device) {
   if (mService == null) return BluetoothProfile.PRIORITY_OFF;
   return mService.getPriority(device);
 }
 public boolean isPreferred(BluetoothDevice device) {
   if (mService == null) return false;
   return mService.getPriority(device) > BluetoothProfile.PRIORITY_OFF;
 }
 public int getConnectionStatus(BluetoothDevice device) {
   if (mService == null) {
     return BluetoothProfile.STATE_DISCONNECTED;
   }
   return mService.getConnectionState(device);
 }