am 3327f788: b/2293042 Fixed the problem where A2DP connections may fail if there\'s an existing connection to another device.

Merge commit '3327f7887328c55ef2d837a8e2a07cea2070c744' into eclair-mr2

* commit '3327f7887328c55ef2d837a8e2a07cea2070c744':
  b/2293042 Fixed the problem where A2DP connections may fail if there's an existing connection to another device.
This commit is contained in:
Michael Chan
2009-12-03 12:23:17 -08:00
committed by Android Git Automerger
2 changed files with 45 additions and 3 deletions

View File

@@ -41,6 +41,7 @@ import java.util.Date;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
/**
* CachedBluetoothDevice represents a remote Bluetooth device. It contains
@@ -401,6 +402,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
.getProfileManager(mLocalManager, profile);
if (profileManager.isPreferred(mDevice)) {
++preferredProfiles;
disconnectConnected(profile);
queueCommand(new BluetoothJob(BluetoothCommand.CONNECT, this, profile));
}
}
@@ -423,6 +425,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager
.getProfileManager(mLocalManager, profile);
profileManager.setPreferred(mDevice, false);
disconnectConnected(profile);
queueCommand(new BluetoothJob(BluetoothCommand.CONNECT, this, profile));
}
}
@@ -432,9 +435,24 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
mConnectAttempted = SystemClock.elapsedRealtime();
// Reset the only-show-one-error-dialog tracking variable
mIsConnectingErrorPossible = true;
disconnectConnected(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) {
if (!cachedDevice.ensurePaired()) return false;