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);
|
mManager.getCachedDeviceManager().onBondingStateChanged(device, bondState);
|
||||||
if (bondState == BluetoothDevice.BOND_NONE) {
|
if (bondState == BluetoothDevice.BOND_NONE) {
|
||||||
int reason = intent.getIntExtra(BluetoothDevice.EXTRA_REASON, BluetoothDevice.ERROR);
|
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)) {
|
} else if (action.equals(BluetoothHeadset.ACTION_STATE_CHANGED)) {
|
||||||
|
@@ -79,14 +79,14 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
private boolean mIsConnectingErrorPossible;
|
private boolean mIsConnectingErrorPossible;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Last time a bt profile auto-connect was attempted without any profiles or
|
* Last time a bt profile auto-connect was attempted.
|
||||||
* UUIDs. If an ACTION_UUID intent comes in within
|
* If an ACTION_UUID intent comes in within
|
||||||
* MAX_UUID_DELAY_FOR_AUTO_CONNECT milliseconds, we will try auto-connect
|
* MAX_UUID_DELAY_FOR_AUTO_CONNECT milliseconds, we will try auto-connect
|
||||||
* again with the new UUIDs
|
* 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;
|
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
|
// 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() {
|
public void connect() {
|
||||||
if (!ensurePaired()) return;
|
if (!ensurePaired()) return;
|
||||||
|
|
||||||
|
mConnectAttempted = SystemClock.elapsedRealtime();
|
||||||
|
|
||||||
|
connectWithoutResettingTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void connectWithoutResettingTimer() {
|
||||||
// Try to initialize the profiles if there were not.
|
// Try to initialize the profiles if there were not.
|
||||||
if (mProfiles.size() == 0) {
|
if (mProfiles.size() == 0) {
|
||||||
if (!updateProfiles()) {
|
if (!updateProfiles()) {
|
||||||
// If UUIDs are not available yet, connect will be happen
|
// If UUIDs are not available yet, connect will be happen
|
||||||
// upon arrival of the ACTION_UUID intent.
|
// upon arrival of the ACTION_UUID intent.
|
||||||
mConnectAttemptedWithoutUuid = SystemClock.elapsedRealtime();
|
if (DEBUG) Log.d(TAG, "No profiles. Maybe we will connect later");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -388,22 +394,23 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
// Reset the only-show-one-error-dialog tracking variable
|
// Reset the only-show-one-error-dialog tracking variable
|
||||||
mIsConnectingErrorPossible = true;
|
mIsConnectingErrorPossible = true;
|
||||||
|
|
||||||
boolean hasAtLeastOnePreferredProfile = false;
|
int preferredProfiles = 0;
|
||||||
for (Profile profile : mProfiles) {
|
for (Profile profile : mProfiles) {
|
||||||
LocalBluetoothProfileManager profileManager =
|
LocalBluetoothProfileManager profileManager =
|
||||||
LocalBluetoothProfileManager.getProfileManager(mLocalManager, profile);
|
LocalBluetoothProfileManager.getProfileManager(mLocalManager, profile);
|
||||||
if (profileManager.isPreferred(mDevice)) {
|
if (profileManager.isPreferred(mDevice)) {
|
||||||
hasAtLeastOnePreferredProfile = true;
|
++preferredProfiles;
|
||||||
queueCommand(new BluetoothJob(BluetoothCommand.CONNECT, this, profile));
|
queueCommand(new BluetoothJob(BluetoothCommand.CONNECT, this, profile));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (DEBUG) Log.d(TAG, "Preferred profiles = " + preferredProfiles);
|
||||||
|
|
||||||
if (!hasAtLeastOnePreferredProfile) {
|
if (preferredProfiles == 0) {
|
||||||
connectAndPreferAllProfiles();
|
connectAllProfiles();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void connectAndPreferAllProfiles() {
|
private void connectAllProfiles() {
|
||||||
if (!ensurePaired()) return;
|
if (!ensurePaired()) return;
|
||||||
|
|
||||||
// Reset the only-show-one-error-dialog tracking variable
|
// Reset the only-show-one-error-dialog tracking variable
|
||||||
@@ -412,12 +419,13 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
for (Profile profile : mProfiles) {
|
for (Profile profile : mProfiles) {
|
||||||
LocalBluetoothProfileManager profileManager =
|
LocalBluetoothProfileManager profileManager =
|
||||||
LocalBluetoothProfileManager.getProfileManager(mLocalManager, profile);
|
LocalBluetoothProfileManager.getProfileManager(mLocalManager, profile);
|
||||||
profileManager.setPreferred(mDevice, true);
|
profileManager.setPreferred(mDevice, false);
|
||||||
queueCommand(new BluetoothJob(BluetoothCommand.CONNECT, this, profile));
|
queueCommand(new BluetoothJob(BluetoothCommand.CONNECT, this, profile));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void connect(Profile profile) {
|
public void connect(Profile profile) {
|
||||||
|
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;
|
||||||
queueCommand(new BluetoothJob(BluetoothCommand.CONNECT, this, profile));
|
queueCommand(new BluetoothJob(BluetoothCommand.CONNECT, this, profile));
|
||||||
@@ -434,8 +442,9 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Log.i(TAG, "Failed to connect " + profile.toString() + " to " + cachedDevice.mName);
|
Log.i(TAG, "Failed to connect " + profile.toString() + " to " + cachedDevice.mName);
|
||||||
|
} else {
|
||||||
|
Log.i(TAG, "Already connected");
|
||||||
}
|
}
|
||||||
Log.i(TAG, "Not connected");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -539,6 +548,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
|
|
||||||
if (TextUtils.isEmpty(mName)) {
|
if (TextUtils.isEmpty(mName)) {
|
||||||
mName = mDevice.getAddress();
|
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() {
|
public void onUuidChanged() {
|
||||||
updateProfiles();
|
updateProfiles();
|
||||||
|
|
||||||
if (DEBUG) Log.e(TAG, "onUuidChanged: Time since last connect w/ no uuid "
|
if (DEBUG) {
|
||||||
+ (SystemClock.elapsedRealtime() - mConnectAttemptedWithoutUuid));
|
Log.e(TAG, "onUuidChanged: Time since last connect"
|
||||||
|
+ (SystemClock.elapsedRealtime() - mConnectAttempted));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If a connect was attempted earlier without any UUID, we will do the
|
* If a connect was attempted earlier without any UUID, we will do the
|
||||||
* connect now.
|
* connect now.
|
||||||
*/
|
*/
|
||||||
if (mProfiles.size() > 0
|
if (mProfiles.size() > 0
|
||||||
&& (mConnectAttemptedWithoutUuid + MAX_UUID_DELAY_FOR_AUTO_CONNECT) > SystemClock
|
&& (mConnectAttempted + MAX_UUID_DELAY_FOR_AUTO_CONNECT) > SystemClock
|
||||||
.elapsedRealtime()) {
|
.elapsedRealtime()) {
|
||||||
connect();
|
connectWithoutResettingTimer();
|
||||||
}
|
}
|
||||||
dispatchAttributesChanged();
|
dispatchAttributesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onBondingStateChanged(int bondState) {
|
||||||
|
if (bondState == BluetoothDevice.BOND_NONE) {
|
||||||
|
mProfiles.clear();
|
||||||
|
}
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
public void setBtClass(BluetoothClass btClass) {
|
public void setBtClass(BluetoothClass btClass) {
|
||||||
if (btClass != null && mBtClass != btClass) {
|
if (btClass != null && mBtClass != btClass) {
|
||||||
mBtClass = btClass;
|
mBtClass = btClass;
|
||||||
|
@@ -176,7 +176,7 @@ public class CachedBluetoothDeviceManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cachedDevice.refresh();
|
cachedDevice.onBondingStateChanged(bondState);
|
||||||
|
|
||||||
if (bondState == BluetoothDevice.BOND_BONDED) {
|
if (bondState == BluetoothDevice.BOND_BONDED) {
|
||||||
// Auto-connect after pairing
|
// 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 device The remote device.
|
||||||
* @param reason The reason, one of the error reasons from
|
* @param reason The reason, one of the error reasons from
|
||||||
* BluetoothDevice.UNBOND_REASON_*
|
* BluetoothDevice.UNBOND_REASON_*
|
||||||
*/
|
*/
|
||||||
public synchronized void onBondingError(BluetoothDevice device, int reason) {
|
public synchronized void showUnbondMessage(BluetoothDevice device, int reason) {
|
||||||
int errorMsg;
|
int errorMsg;
|
||||||
|
|
||||||
switch(reason) {
|
switch(reason) {
|
||||||
@@ -214,7 +214,7 @@ public class CachedBluetoothDeviceManager {
|
|||||||
mLocalManager.showError(device, R.string.bluetooth_error_title, errorMsg);
|
mLocalManager.showError(device, R.string.bluetooth_error_title, errorMsg);
|
||||||
break;
|
break;
|
||||||
default:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user