am e3b59f19
: Merge change I5eab1270 into eclair
Merge commit 'e3b59f193e0df1a2643c367f7f1f4f7b6817a5f8' into eclair-plus-aosp * commit 'e3b59f193e0df1a2643c367f7f1f4f7b6817a5f8': b/2154576 Fixed the problem were some BT profiles were not connected when first UUID notification of many didn't have all the UUIDs
This commit is contained in:
@@ -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)) {
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user