summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Hamby <jhamby@google.com>2010-10-13 16:28:34 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2010-10-13 16:28:34 -0700
commit8028cea196968a4744ac4b095f6fe6bc32467375 (patch)
treed6137ff521527c947c21ecaba8126e05aca48b0a
parentda08f31f791f77be6d0fa2aa67096c3f6e1d8a1c (diff)
parent8021537ffea45d1a36274217610a314b3a0ac774 (diff)
downloadpackages_apps_settings-8028cea196968a4744ac4b095f6fe6bc32467375.zip
packages_apps_settings-8028cea196968a4744ac4b095f6fe6bc32467375.tar.gz
packages_apps_settings-8028cea196968a4744ac4b095f6fe6bc32467375.tar.bz2
am 8021537f: BT settings wait for HS service before connect. DO NOT MERGE
Merge commit '8021537ffea45d1a36274217610a314b3a0ac774' into gingerbread-plus-aosp * commit '8021537ffea45d1a36274217610a314b3a0ac774': BT settings wait for HS service before connect. DO NOT MERGE
-rw-r--r--src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java62
1 files changed, 54 insertions, 8 deletions
diff --git a/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java b/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java
index 5fcddf0..8d29428 100644
--- a/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java
+++ b/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java
@@ -309,6 +309,8 @@ public abstract class LocalBluetoothProfileManager {
private BluetoothHeadset mService;
private Handler mUiHandler = new Handler();
private boolean profileReady = false;
+ private BluetoothDevice mDelayedConnectDevice = null;
+ private BluetoothDevice mDelayedDisconnectDevice = null;
public HeadsetProfileManager(LocalBluetoothManager localManager) {
super(localManager);
@@ -318,19 +320,43 @@ public abstract class LocalBluetoothProfileManager {
public void onServiceConnected() {
profileReady = true;
// This could be called on a non-UI thread, funnel to UI thread.
- mUiHandler.post(new Runnable() {
+ // Delay for a few seconds to allow other proxies to connect.
+ mUiHandler.postDelayed(new Runnable() {
public void run() {
- /*
- * We just bound to the service, so refresh the UI of the
- * headset device.
- */
BluetoothDevice device = mService.getCurrentHeadset();
- if (device == null) return;
- mLocalManager.getCachedDeviceManager()
+
+ if (mDelayedConnectDevice != null) {
+ Log.i(TAG, "service ready: connecting...");
+ BluetoothDevice newDevice = mDelayedConnectDevice;
+ mDelayedConnectDevice = null;
+
+ if (!newDevice.equals(device)) {
+ if (device != null) {
+ Log.i(TAG, "disconnecting old headset");
+ mService.disconnectHeadset(device);
+ }
+ Log.i(TAG, "connecting to pending headset");
+ mService.connectHeadset(newDevice);
+ }
+ } else if (mDelayedDisconnectDevice != null) {
+ Log.i(TAG, "service ready: disconnecting...");
+ if (mDelayedDisconnectDevice.equals(device)) {
+ Log.i(TAG, "disconnecting headset");
+ mService.disconnectHeadset(device);
+ }
+ mDelayedDisconnectDevice = null;
+ } else {
+ /*
+ * We just bound to the service, so refresh the UI of the
+ * headset device.
+ */
+ if (device == null) return;
+ mLocalManager.getCachedDeviceManager()
.onProfileStateChanged(device, Profile.HEADSET,
BluetoothHeadset.STATE_CONNECTED);
+ }
}
- });
+ }, 2000); // wait 2 seconds for other proxies to connect
if (mServiceListeners.size() > 0) {
Iterator<ServiceListener> it = mServiceListeners.iterator();
@@ -368,6 +394,16 @@ public abstract class LocalBluetoothProfileManager {
@Override
public boolean connect(BluetoothDevice device) {
+ // Delay connection until onServiceConnected() if the
+ // manager isn't ready
+ if (!isManagerReady()) {
+ Log.w(TAG, "HeadsetProfileManager delaying connect, "
+ + "manager not ready");
+ mDelayedConnectDevice = device;
+ mDelayedDisconnectDevice = null;
+ return true; // hopefully it will succeed
+ }
+
// Since connectHeadset fails if already connected to a headset, we
// disconnect from any headset first
BluetoothDevice currDevice = mService.getCurrentHeadset();
@@ -379,6 +415,16 @@ public abstract class LocalBluetoothProfileManager {
@Override
public boolean disconnect(BluetoothDevice device) {
+ // Delay connection until onServiceConnected() if the
+ // manager isn't ready
+ if (!isManagerReady()) {
+ Log.w(TAG, "HeadsetProfileManager delaying disconnect, "
+ + "manager not ready");
+ mDelayedConnectDevice = null;
+ mDelayedDisconnectDevice = device;
+ return true; // hopefully it will succeed
+ }
+
BluetoothDevice currDevice = mService.getCurrentHeadset();
if (currDevice != null && currDevice.equals(device)) {
// Downgrade prority as user is disconnecting the headset.