b/2293042 Fixed the problem where A2DP connections may fail if there's an existing connection to another device.
Change-Id: I1b4963a167b633c0905e2719ab3f651ff8be9f2c
This commit is contained in:
@@ -41,6 +41,7 @@ import java.util.Date;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CachedBluetoothDevice represents a remote Bluetooth device. It contains
|
* CachedBluetoothDevice represents a remote Bluetooth device. It contains
|
||||||
@@ -401,6 +402,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
.getProfileManager(mLocalManager, profile);
|
.getProfileManager(mLocalManager, profile);
|
||||||
if (profileManager.isPreferred(mDevice)) {
|
if (profileManager.isPreferred(mDevice)) {
|
||||||
++preferredProfiles;
|
++preferredProfiles;
|
||||||
|
disconnectConnected(profile);
|
||||||
queueCommand(new BluetoothJob(BluetoothCommand.CONNECT, this, profile));
|
queueCommand(new BluetoothJob(BluetoothCommand.CONNECT, this, profile));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -423,6 +425,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager
|
LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager
|
||||||
.getProfileManager(mLocalManager, profile);
|
.getProfileManager(mLocalManager, profile);
|
||||||
profileManager.setPreferred(mDevice, false);
|
profileManager.setPreferred(mDevice, false);
|
||||||
|
disconnectConnected(profile);
|
||||||
queueCommand(new BluetoothJob(BluetoothCommand.CONNECT, this, profile));
|
queueCommand(new BluetoothJob(BluetoothCommand.CONNECT, this, profile));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -432,9 +435,24 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
mConnectAttempted = SystemClock.elapsedRealtime();
|
mConnectAttempted = SystemClock.elapsedRealtime();
|
||||||
// Reset the only-show-one-error-dialog tracking variable
|
// Reset the only-show-one-error-dialog tracking variable
|
||||||
mIsConnectingErrorPossible = true;
|
mIsConnectingErrorPossible = true;
|
||||||
|
disconnectConnected(profile);
|
||||||
queueCommand(new BluetoothJob(BluetoothCommand.CONNECT, this, profile));
|
queueCommand(new BluetoothJob(BluetoothCommand.CONNECT, this, profile));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void disconnectConnected(Profile profile) {
|
||||||
|
LocalBluetoothProfileManager profileManager =
|
||||||
|
LocalBluetoothProfileManager.getProfileManager(mLocalManager, profile);
|
||||||
|
CachedBluetoothDeviceManager cachedDeviceManager = mLocalManager.getCachedDeviceManager();
|
||||||
|
Set<BluetoothDevice> devices = profileManager.getConnectedDevices();
|
||||||
|
if (devices == null) return;
|
||||||
|
for (BluetoothDevice device : devices) {
|
||||||
|
CachedBluetoothDevice cachedDevice = cachedDeviceManager.findDevice(device);
|
||||||
|
if (cachedDevice != null) {
|
||||||
|
queueCommand(new BluetoothJob(BluetoothCommand.DISCONNECT, cachedDevice, profile));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean connectInt(CachedBluetoothDevice cachedDevice, Profile profile) {
|
private boolean connectInt(CachedBluetoothDevice cachedDevice, Profile profile) {
|
||||||
if (!cachedDevice.ensurePaired()) return false;
|
if (!cachedDevice.ensurePaired()) return false;
|
||||||
|
|
||||||
|
@@ -16,17 +16,18 @@
|
|||||||
|
|
||||||
package com.android.settings.bluetooth;
|
package com.android.settings.bluetooth;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothA2dp;
|
import android.bluetooth.BluetoothA2dp;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.bluetooth.BluetoothHeadset;
|
import android.bluetooth.BluetoothHeadset;
|
||||||
import android.bluetooth.BluetoothUuid;
|
import android.bluetooth.BluetoothUuid;
|
||||||
import android.os.ParcelUuid;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.os.ParcelUuid;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -121,6 +122,8 @@ public abstract class LocalBluetoothProfileManager {
|
|||||||
mLocalManager = localManager;
|
mLocalManager = localManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract Set<BluetoothDevice> getConnectedDevices();
|
||||||
|
|
||||||
public abstract boolean connect(BluetoothDevice device);
|
public abstract boolean connect(BluetoothDevice device);
|
||||||
|
|
||||||
public abstract boolean disconnect(BluetoothDevice device);
|
public abstract boolean disconnect(BluetoothDevice device);
|
||||||
@@ -163,6 +166,11 @@ public abstract class LocalBluetoothProfileManager {
|
|||||||
mService = new BluetoothA2dp(localManager.getContext());
|
mService = new BluetoothA2dp(localManager.getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<BluetoothDevice> getConnectedDevices() {
|
||||||
|
return mService.getConnectedSinks();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean connect(BluetoothDevice device) {
|
public boolean connect(BluetoothDevice device) {
|
||||||
Set<BluetoothDevice> sinks = mService.getConnectedSinks();
|
Set<BluetoothDevice> sinks = mService.getConnectedSinks();
|
||||||
@@ -260,6 +268,17 @@ public abstract class LocalBluetoothProfileManager {
|
|||||||
public void onServiceDisconnected() {
|
public void onServiceDisconnected() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<BluetoothDevice> getConnectedDevices() {
|
||||||
|
Set<BluetoothDevice> devices = null;
|
||||||
|
BluetoothDevice device = mService.getCurrentHeadset();
|
||||||
|
if (device != null) {
|
||||||
|
devices = new HashSet<BluetoothDevice>();
|
||||||
|
devices.add(device);
|
||||||
|
}
|
||||||
|
return devices;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean connect(BluetoothDevice device) {
|
public boolean connect(BluetoothDevice device) {
|
||||||
// Since connectHeadset fails if already connected to a headset, we
|
// Since connectHeadset fails if already connected to a headset, we
|
||||||
@@ -333,6 +352,11 @@ public abstract class LocalBluetoothProfileManager {
|
|||||||
super(localManager);
|
super(localManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<BluetoothDevice> getConnectedDevices() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean connect(BluetoothDevice device) {
|
public boolean connect(BluetoothDevice device) {
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user