Don't disconnect the same device before connecting.

We Pair: Remote device sends incoming connection, we get connected.
We get BondingState change and we connect.
Settings app disconnects connected profiles and then connects
without checking whether we are disconnecting the same device itself.

How was it working before ? Settings app used to queue all
commands. The disconnect followed by the connect would work
but unnecessarily disconnect and then connect.
With the queuing moved to framework, the connect fails
since the disconnect status has not been broadcasted.

Settings app shouldn't be disconnecting connected profiles.
That logic should reside in the framework. There is an open bug
and when the new APIs get implemented this will get removed.

Change-Id: I32a7fa36ff3c3321691c55071498f985dcdcfe8e
This commit is contained in:
Jaikumar Ganesh
2010-09-16 18:24:42 -07:00
parent e714898a1a
commit 84905edb63

View File

@@ -242,7 +242,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); disconnectConnected(this, profile);
connectInt(this, profile); connectInt(this, profile);
} }
} }
@@ -265,7 +265,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); disconnectConnected(this, profile);
connectInt(this, profile); connectInt(this, profile);
} }
} }
@@ -275,19 +275,20 @@ 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); disconnectConnected(this, profile);
connectInt(this, profile); connectInt(this, profile);
} }
private void disconnectConnected(Profile profile) { private void disconnectConnected(CachedBluetoothDevice device, Profile profile) {
LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager profileManager =
LocalBluetoothProfileManager.getProfileManager(mLocalManager, profile); LocalBluetoothProfileManager.getProfileManager(mLocalManager, profile);
CachedBluetoothDeviceManager cachedDeviceManager = mLocalManager.getCachedDeviceManager(); CachedBluetoothDeviceManager cachedDeviceManager = mLocalManager.getCachedDeviceManager();
Set<BluetoothDevice> devices = profileManager.getConnectedDevices(); Set<BluetoothDevice> devices = profileManager.getConnectedDevices();
if (devices == null) return; if (devices == null) return;
for (BluetoothDevice device : devices) { for (BluetoothDevice btDevice : devices) {
CachedBluetoothDevice cachedDevice = cachedDeviceManager.findDevice(device); CachedBluetoothDevice cachedDevice = cachedDeviceManager.findDevice(btDevice);
if (cachedDevice != null) {
if (cachedDevice != null && !cachedDevice.equals(device)) {
disconnectInt(cachedDevice, profile); disconnectInt(cachedDevice, profile);
} }
} }