in amazonfreertossdk/src/main/java/software/amazon/freertos/amazonfreertossdk/AmazonFreeRTOSDevice.java [389:424]
private void registerBondStateCallback() {
mBondStateCallback = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
switch (action) {
case BluetoothDevice.ACTION_BOND_STATE_CHANGED: {
int prev = intent.getIntExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE, BluetoothDevice.ERROR);
int now = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.ERROR);
Log.d(TAG, "Bond state changed from " + prev + " to " + now);
/**
* If the state changed from bonding to bonded, then we have a valid bond created
* for the device.
* If discovery is not performed initiate discovery.
* If services are discovered start initialization by reading device version characteristic.
*/
if (prev == BluetoothDevice.BOND_BONDING && now == BluetoothDevice.BOND_BONDED) {
List<BluetoothGattService> services = mBluetoothGatt.getServices();
if (services == null || services.isEmpty()) {
discoverServices();
} else {
probe();
}
}
break;
}
default:
break;
}
}
};
final IntentFilter bondFilter = new IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
mContext.registerReceiver(mBondStateCallback, bondFilter);
}