Maintain pending outgoing bonding address.

This helps us to distinguish between incoming and outgoing Bonding requests.

Change-Id: I69e6a269b7dd6aad60e6f5711cad812291a7d313
This commit is contained in:
Jaikumar Ganesh
2009-09-20 12:56:21 -07:00
parent cc7f40a88d
commit 2092361d58
2 changed files with 27 additions and 4 deletions

View File

@@ -457,8 +457,9 @@ class BluetoothEventLoop {
String address = checkPairingRequestAndGetAddress(objectPath, nativeData);
if (address == null) return;
if (mBluetoothService.getBondState().getBondState(address) ==
BluetoothDevice.BOND_BONDING) {
String pendingOutgoingAddress =
mBluetoothService.getBondState().getPendingOutgoingBonding();
if (address.equals(pendingOutgoingAddress)) {
// we initiated the bonding
BluetoothClass btClass = new BluetoothClass(mBluetoothService.getRemoteClass(address));

View File

@@ -427,6 +427,18 @@ public class BluetoothService extends IBluetooth.Stub {
new ArrayList<String>(Arrays.asList(
"Motorola IHF1000", "i.TechBlueBAND", "X5 Stereo v1.3"));
// If this is an outgoing connection, store the address.
// There can be only 1 pending outgoing connection at a time,
private String mPendingOutgoingBonding;
private synchronized void setPendingOutgoingBonding(String address) {
mPendingOutgoingBonding = address;
}
public synchronized String getPendingOutgoingBonding() {
return mPendingOutgoingBonding;
}
public synchronized void loadBondState() {
if (mBluetoothState != BluetoothAdapter.STATE_TURNING_ON) {
return;
@@ -457,6 +469,15 @@ public class BluetoothService extends IBluetooth.Stub {
if (oldState == state) {
return;
}
// Check if this was an pending outgoing bonding.
// If yes, reset the state.
if (oldState == BluetoothDevice.BOND_BONDING) {
if (address.equals(mPendingOutgoingBonding)) {
mPendingOutgoingBonding = null;
}
}
if (DBG) log(address + " bond state " + oldState + " -> " + state + " (" +
reason + ")");
Intent intent = new Intent(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
@@ -779,8 +800,7 @@ public class BluetoothService extends IBluetooth.Stub {
}
address = address.toUpperCase();
String[] bonding = mBondState.listInState(BluetoothDevice.BOND_BONDING);
if (bonding.length > 0 && !bonding[0].equals(address)) {
if (mBondState.getPendingOutgoingBonding() != null) {
log("Ignoring createBond(): another device is bonding");
// a different device is currently bonding, fail
return false;
@@ -798,7 +818,9 @@ public class BluetoothService extends IBluetooth.Stub {
return false;
}
mBondState.setPendingOutgoingBonding(address);
mBondState.setBondState(address, BluetoothDevice.BOND_BONDING);
return true;
}