Merge "Allow multiple simultaneous connections for BT input devices." into honeycomb

This commit is contained in:
Jake Hamby
2011-01-11 18:44:57 -08:00
committed by Android (Google) Code Review
2 changed files with 13 additions and 19 deletions

View File

@@ -279,7 +279,7 @@ class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
}
private void connectWithoutResettingTimer(boolean connectAllProfiles) {
// Try to initialize the profiles if there were not.
// Try to initialize the profiles if they were not.
if (mProfiles.size() == 0) {
if (!updateProfiles()) {
// If UUIDs are not available yet, connect will be happen
@@ -299,7 +299,6 @@ class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
.getProfileManager(mLocalManager, profile);
if (profileManager.isPreferred(mDevice)) {
++preferredProfiles;
disconnectConnected(this, profile);
connectInt(this, profile);
}
}
@@ -322,7 +321,6 @@ class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager
.getProfileManager(mLocalManager, profile);
profileManager.setPreferred(mDevice, true);
disconnectConnected(this, profile);
connectInt(this, profile);
}
}
@@ -332,25 +330,9 @@ class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
mConnectAttempted = SystemClock.elapsedRealtime();
// Reset the only-show-one-error-dialog tracking variable
mIsConnectingErrorPossible = true;
disconnectConnected(this, profile);
connectInt(this, profile);
}
private void disconnectConnected(CachedBluetoothDevice device, Profile profile) {
LocalBluetoothProfileManager profileManager =
LocalBluetoothProfileManager.getProfileManager(mLocalManager, profile);
CachedBluetoothDeviceManager cachedDeviceManager = mLocalManager.getCachedDeviceManager();
List<BluetoothDevice> devices = profileManager.getConnectedDevices();
if (devices == null) return;
for (BluetoothDevice btDevice : devices) {
CachedBluetoothDevice cachedDevice = cachedDeviceManager.findDevice(btDevice);
if (cachedDevice != null && !cachedDevice.equals(device)) {
cachedDevice.disconnect(profile);
}
}
}
private boolean connectInt(CachedBluetoothDevice cachedDevice, Profile profile) {
if (!cachedDevice.ensurePaired()) return false;

View File

@@ -471,6 +471,12 @@ abstract class LocalBluetoothProfileManager {
@Override
public boolean connect(BluetoothDevice device) {
List<BluetoothDevice> sinks = getConnectedDevices();
if (sinks != null) {
for (BluetoothDevice sink : sinks) {
mService.disconnect(sink);
}
}
return mService.connect(device);
}
@@ -727,6 +733,12 @@ abstract class LocalBluetoothProfileManager {
@Override
public boolean connect(BluetoothDevice device) {
List<BluetoothDevice> sinks = getConnectedDevices();
if (sinks != null) {
for (BluetoothDevice sink : sinks) {
mService.disconnect(sink);
}
}
return mService.connect(device);
}