am 2092361d: Maintain pending outgoing bonding address.

Merge commit '2092361d586a20190c9137fb3cc9434cdc9ec99f' into eclair-plus-aosp

* commit '2092361d586a20190c9137fb3cc9434cdc9ec99f':
  Maintain pending outgoing bonding address.
This commit is contained in:
Jaikumar Ganesh
2009-09-20 16:30:39 -07:00
committed by Android Git Automerger
2 changed files with 27 additions and 4 deletions

View File

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

View File

@@ -427,6 +427,18 @@ public class BluetoothService extends IBluetooth.Stub {
new ArrayList<String>(Arrays.asList( new ArrayList<String>(Arrays.asList(
"Motorola IHF1000", "i.TechBlueBAND", "X5 Stereo v1.3")); "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() { public synchronized void loadBondState() {
if (mBluetoothState != BluetoothAdapter.STATE_TURNING_ON) { if (mBluetoothState != BluetoothAdapter.STATE_TURNING_ON) {
return; return;
@@ -457,6 +469,15 @@ public class BluetoothService extends IBluetooth.Stub {
if (oldState == state) { if (oldState == state) {
return; 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 + " (" + if (DBG) log(address + " bond state " + oldState + " -> " + state + " (" +
reason + ")"); reason + ")");
Intent intent = new Intent(BluetoothDevice.ACTION_BOND_STATE_CHANGED); Intent intent = new Intent(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
@@ -779,8 +800,7 @@ public class BluetoothService extends IBluetooth.Stub {
} }
address = address.toUpperCase(); address = address.toUpperCase();
String[] bonding = mBondState.listInState(BluetoothDevice.BOND_BONDING); if (mBondState.getPendingOutgoingBonding() != null) {
if (bonding.length > 0 && !bonding[0].equals(address)) {
log("Ignoring createBond(): another device is bonding"); log("Ignoring createBond(): another device is bonding");
// a different device is currently bonding, fail // a different device is currently bonding, fail
return false; return false;
@@ -798,7 +818,9 @@ public class BluetoothService extends IBluetooth.Stub {
return false; return false;
} }
mBondState.setPendingOutgoingBonding(address);
mBondState.setBondState(address, BluetoothDevice.BOND_BONDING); mBondState.setBondState(address, BluetoothDevice.BOND_BONDING);
return true; return true;
} }