static final int BT_UUID_SIZE = 16; // bytes
public static final int BT_STATUS_SUCCESS = 0;
+ public static final int BT_STATUS_FAIL = 1;
+ public static final int BT_STATUS_NOT_READY = 2;
+ public static final int BT_STATUS_NOMEM = 3;
+ public static final int BT_STATUS_BUSY = 4;
+ public static final int BT_STATUS_DONE = 5;
+ public static final int BT_STATUS_UNSUPPORTED = 6;
+ public static final int BT_STATUS_PARM_INVALID = 7;
+ public static final int BT_STATUS_UNHANDLED = 8;
+ public static final int BT_STATUS_AUTH_FAILURE = 9;
+ public static final int BT_STATUS_RMT_DEV_DOWN = 10;
}
/* if incoming pairing, transition to pending state */
if (newState == BluetoothDevice.BOND_BONDING)
{
- sendIntent(dev, newState);
+ sendIntent(dev, newState, 0);
transitionTo(mPendingCommandState);
}
else
break;
case BONDING_STATE_CHANGE:
int newState = msg.arg1;
- sendIntent(dev, newState);
+ int reason = getUnbondReasonFromHALCode(msg.arg2);
+ sendIntent(dev, newState, reason);
if(newState != BluetoothDevice.BOND_BONDING )
{
/* this is either none/bonded, remove and transition */
infoLog("Bond address is:" + dev);
byte[] addr = Utils.getBytesFromAddress(dev.getAddress());
if (!mAdapterService.createBondNative(addr)) {
- sendIntent(dev, BluetoothDevice.BOND_NONE);
+ sendIntent(dev, BluetoothDevice.BOND_NONE,
+ BluetoothDevice.UNBOND_REASON_REMOVED);
return false;
} else if (transition) {
transitionTo(mPendingCommandState);
return false;
}
- private void sendIntent(BluetoothDevice device, int newState) {
+ private void sendIntent(BluetoothDevice device, int newState, int reason) {
DeviceProperties devProp = mRemoteDevices.getDeviceProperties(device);
int oldState = BluetoothDevice.BOND_NONE;
if (devProp != null) {
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
intent.putExtra(BluetoothDevice.EXTRA_BOND_STATE, newState);
intent.putExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE, oldState);
+ if (newState == BluetoothDevice.BOND_NONE)
+ intent.putExtra(BluetoothDevice.EXTRA_REASON, reason);
mAdapterService.sendBroadcast(intent, AdapterService.BLUETOOTH_PERM);
infoLog("Bond State Change Intent:" + device + " OldState: " + oldState
+ " NewState: " + newState);
msg.arg1 = BluetoothDevice.BOND_BONDING;
else
msg.arg1 = BluetoothDevice.BOND_NONE;
+ msg.arg2 = status;
sendMessage(msg);
}
Log.e(TAG, msg);
}
+ private int getUnbondReasonFromHALCode (int reason) {
+ if (reason == AbstractionLayer.BT_STATUS_SUCCESS)
+ return BluetoothDevice.BOND_SUCCESS;
+ else if (reason == AbstractionLayer.BT_STATUS_RMT_DEV_DOWN)
+ return BluetoothDevice.UNBOND_REASON_REMOTE_DEVICE_DOWN;
+ else if (reason == AbstractionLayer.BT_STATUS_AUTH_FAILURE)
+ return BluetoothDevice.UNBOND_REASON_AUTH_FAILED;
+
+ /* default */
+ return BluetoothDevice.UNBOND_REASON_REMOVED;
+ }
}