summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Chan <mchan@android.com>2009-09-30 12:18:51 -0700
committerMichael Chan <mchan@android.com>2009-09-30 12:34:32 -0700
commiteaf13a2c154a0c7bf7559b45d33fb589b5bcf3d4 (patch)
tree72461b0d2aee614c1b8571c39b9d0138d41e734a
parentcabb147ce57bdcbb6baa08686415ce03f97028d7 (diff)
downloadpackages_apps_settings-eaf13a2c154a0c7bf7559b45d33fb589b5bcf3d4.zip
packages_apps_settings-eaf13a2c154a0c7bf7559b45d33fb589b5bcf3d4.tar.gz
packages_apps_settings-eaf13a2c154a0c7bf7559b45d33fb589b5bcf3d4.tar.bz2
b/2154576 Fixed the problem were some BT profiles were not connected when first UUID notification of many didn't have all the UUIDs
Reset connect timer event if profile was non-empty. Clear profiles after unpair mConnectAttemptedWithoutUuid Change-Id: I5eab1270a755c6c87eb5be13a2f43dbbcd9a2f88
-rw-r--r--src/com/android/settings/bluetooth/BluetoothEventRedirector.java2
-rw-r--r--src/com/android/settings/bluetooth/CachedBluetoothDevice.java51
-rw-r--r--src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java8
3 files changed, 40 insertions, 21 deletions
diff --git a/src/com/android/settings/bluetooth/BluetoothEventRedirector.java b/src/com/android/settings/bluetooth/BluetoothEventRedirector.java
index 9aae8b1..6c40834 100644
--- a/src/com/android/settings/bluetooth/BluetoothEventRedirector.java
+++ b/src/com/android/settings/bluetooth/BluetoothEventRedirector.java
@@ -78,7 +78,7 @@ public class BluetoothEventRedirector {
mManager.getCachedDeviceManager().onBondingStateChanged(device, bondState);
if (bondState == BluetoothDevice.BOND_NONE) {
int reason = intent.getIntExtra(BluetoothDevice.EXTRA_REASON, BluetoothDevice.ERROR);
- mManager.getCachedDeviceManager().onBondingError(device, reason);
+ mManager.getCachedDeviceManager().showUnbondMessage(device, reason);
}
} else if (action.equals(BluetoothHeadset.ACTION_STATE_CHANGED)) {
diff --git a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
index 859cf67..b4e7a4c 100644
--- a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
+++ b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
@@ -79,14 +79,14 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
private boolean mIsConnectingErrorPossible;
/**
- * Last time a bt profile auto-connect was attempted without any profiles or
- * UUIDs. If an ACTION_UUID intent comes in within
+ * Last time a bt profile auto-connect was attempted.
+ * If an ACTION_UUID intent comes in within
* MAX_UUID_DELAY_FOR_AUTO_CONNECT milliseconds, we will try auto-connect
* again with the new UUIDs
*/
- private long mConnectAttemptedWithoutUuid;
+ private long mConnectAttempted;
- // See mConnectAttemptedWithoutUuid
+ // See mConnectAttempted
private static final long MAX_UUID_DELAY_FOR_AUTO_CONNECT = 5000;
// Max time to hold the work queue if we don't get or missed a response
@@ -375,12 +375,18 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
public void connect() {
if (!ensurePaired()) return;
+ mConnectAttempted = SystemClock.elapsedRealtime();
+
+ connectWithoutResettingTimer();
+ }
+
+ private void connectWithoutResettingTimer() {
// Try to initialize the profiles if there were not.
if (mProfiles.size() == 0) {
if (!updateProfiles()) {
// If UUIDs are not available yet, connect will be happen
// upon arrival of the ACTION_UUID intent.
- mConnectAttemptedWithoutUuid = SystemClock.elapsedRealtime();
+ if (DEBUG) Log.d(TAG, "No profiles. Maybe we will connect later");
return;
}
}
@@ -388,22 +394,23 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
// Reset the only-show-one-error-dialog tracking variable
mIsConnectingErrorPossible = true;
- boolean hasAtLeastOnePreferredProfile = false;
+ int preferredProfiles = 0;
for (Profile profile : mProfiles) {
LocalBluetoothProfileManager profileManager =
LocalBluetoothProfileManager.getProfileManager(mLocalManager, profile);
if (profileManager.isPreferred(mDevice)) {
- hasAtLeastOnePreferredProfile = true;
+ ++preferredProfiles;
queueCommand(new BluetoothJob(BluetoothCommand.CONNECT, this, profile));
}
}
+ if (DEBUG) Log.d(TAG, "Preferred profiles = " + preferredProfiles);
- if (!hasAtLeastOnePreferredProfile) {
- connectAndPreferAllProfiles();
+ if (preferredProfiles == 0) {
+ connectAllProfiles();
}
}
- private void connectAndPreferAllProfiles() {
+ private void connectAllProfiles() {
if (!ensurePaired()) return;
// Reset the only-show-one-error-dialog tracking variable
@@ -412,12 +419,13 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
for (Profile profile : mProfiles) {
LocalBluetoothProfileManager profileManager =
LocalBluetoothProfileManager.getProfileManager(mLocalManager, profile);
- profileManager.setPreferred(mDevice, true);
+ profileManager.setPreferred(mDevice, false);
queueCommand(new BluetoothJob(BluetoothCommand.CONNECT, this, profile));
}
}
public void connect(Profile profile) {
+ mConnectAttempted = SystemClock.elapsedRealtime();
// Reset the only-show-one-error-dialog tracking variable
mIsConnectingErrorPossible = true;
queueCommand(new BluetoothJob(BluetoothCommand.CONNECT, this, profile));
@@ -434,8 +442,9 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
return true;
}
Log.i(TAG, "Failed to connect " + profile.toString() + " to " + cachedDevice.mName);
+ } else {
+ Log.i(TAG, "Already connected");
}
- Log.i(TAG, "Not connected");
return false;
}
@@ -539,6 +548,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
if (TextUtils.isEmpty(mName)) {
mName = mDevice.getAddress();
+ if (DEBUG) Log.d(TAG, "Default to address. Device has no name (yet) " + mName);
}
}
@@ -691,21 +701,30 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
public void onUuidChanged() {
updateProfiles();
- if (DEBUG) Log.e(TAG, "onUuidChanged: Time since last connect w/ no uuid "
- + (SystemClock.elapsedRealtime() - mConnectAttemptedWithoutUuid));
+ if (DEBUG) {
+ Log.e(TAG, "onUuidChanged: Time since last connect"
+ + (SystemClock.elapsedRealtime() - mConnectAttempted));
+ }
/*
* If a connect was attempted earlier without any UUID, we will do the
* connect now.
*/
if (mProfiles.size() > 0
- && (mConnectAttemptedWithoutUuid + MAX_UUID_DELAY_FOR_AUTO_CONNECT) > SystemClock
+ && (mConnectAttempted + MAX_UUID_DELAY_FOR_AUTO_CONNECT) > SystemClock
.elapsedRealtime()) {
- connect();
+ connectWithoutResettingTimer();
}
dispatchAttributesChanged();
}
+ public void onBondingStateChanged(int bondState) {
+ if (bondState == BluetoothDevice.BOND_NONE) {
+ mProfiles.clear();
+ }
+ refresh();
+ }
+
public void setBtClass(BluetoothClass btClass) {
if (btClass != null && mBtClass != btClass) {
mBtClass = btClass;
diff --git a/src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java b/src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java
index b7cea23..a7f44ec 100644
--- a/src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java
+++ b/src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java
@@ -176,7 +176,7 @@ public class CachedBluetoothDeviceManager {
return;
}
- cachedDevice.refresh();
+ cachedDevice.onBondingStateChanged(bondState);
if (bondState == BluetoothDevice.BOND_BONDED) {
// Auto-connect after pairing
@@ -185,13 +185,13 @@ public class CachedBluetoothDeviceManager {
}
/**
- * Called when there is a bonding error.
+ * Called when we have reached the un-bond state.
*
* @param device The remote device.
* @param reason The reason, one of the error reasons from
* BluetoothDevice.UNBOND_REASON_*
*/
- public synchronized void onBondingError(BluetoothDevice device, int reason) {
+ public synchronized void showUnbondMessage(BluetoothDevice device, int reason) {
int errorMsg;
switch(reason) {
@@ -214,7 +214,7 @@ public class CachedBluetoothDeviceManager {
mLocalManager.showError(device, R.string.bluetooth_error_title, errorMsg);
break;
default:
- Log.w(TAG, "onBondingError: Not displaying any error message for reason:" + reason);
+ Log.w(TAG, "showUnbondMessage: Not displaying any message for reason:" + reason);
break;
}
}