From a0d39a39c2f53ebe858685c75c756b51dfac49da Mon Sep 17 00:00:00 2001 From: Jake Hamby Date: Mon, 10 Jan 2011 17:02:26 -0800 Subject: [PATCH] Allow multiple simultaneous connections for BT input devices. Move responsibility for disconnecting devices before connecting a new profile from CachedBluetoothDevice to LocalBluetoothProfileManager. The ProfileManager subclasses of LocalBluetoothProfileManager will handle disconnecting the previously connected device, if necessary, as part of connect(). The HID profile allows multiple simultaneous connected devices, while the other supported profiles do not. Bug: 3333975 Change-Id: Id51b26e64f7c3ee7d54af3a03ca82a669f305b52 --- .../bluetooth/CachedBluetoothDevice.java | 20 +------------------ .../LocalBluetoothProfileManager.java | 12 +++++++++++ 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java index 46391d38712..88964e094d5 100644 --- a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java +++ b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java @@ -279,7 +279,7 @@ class CachedBluetoothDevice implements Comparable { } 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 { .getProfileManager(mLocalManager, profile); if (profileManager.isPreferred(mDevice)) { ++preferredProfiles; - disconnectConnected(this, profile); connectInt(this, profile); } } @@ -322,7 +321,6 @@ class CachedBluetoothDevice implements Comparable { LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager .getProfileManager(mLocalManager, profile); profileManager.setPreferred(mDevice, true); - disconnectConnected(this, profile); connectInt(this, profile); } } @@ -332,25 +330,9 @@ class CachedBluetoothDevice implements Comparable { 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 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; diff --git a/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java b/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java index 5c8d868178c..a2ac743a052 100644 --- a/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java +++ b/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java @@ -471,6 +471,12 @@ abstract class LocalBluetoothProfileManager { @Override public boolean connect(BluetoothDevice device) { + List 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 sinks = getConnectedDevices(); + if (sinks != null) { + for (BluetoothDevice sink : sinks) { + mService.disconnect(sink); + } + } return mService.connect(device); }