1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 04:46:51 +01:00

More logging for pairing, destroy pairing activity when bonding failed #349

This commit is contained in:
cpfeiffer 2016-07-10 00:10:50 +02:00
parent eb7b4be986
commit 80930ce42a

View File

@ -56,6 +56,7 @@ public class MiBandPairingActivity extends GBActivity {
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(intent.getAction())) { if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(intent.getAction())) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
LOG.info("Bond state changed: " + device + ", state: " + device.getBondState() + ", expected address: " + bondingMacAddress);
if (bondingMacAddress != null && bondingMacAddress.equals(device.getAddress())) { if (bondingMacAddress != null && bondingMacAddress.equals(device.getAddress())) {
int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.BOND_NONE); int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.BOND_NONE);
if (bondState == BluetoothDevice.BOND_BONDED) { if (bondState == BluetoothDevice.BOND_BONDED) {
@ -68,6 +69,13 @@ public class MiBandPairingActivity extends GBActivity {
performPair(); performPair();
} }
}, DELAY_AFTER_BONDING); }, DELAY_AFTER_BONDING);
} else if (bondState == BluetoothDevice.BOND_BONDING) {
LOG.info("Bonding in progress with " + device.getAddress());
} else if (bondState == BluetoothDevice.BOND_NONE) {
LOG.info("Not bonded with " + device.getAddress() + ", aborting bonding.");
pairingFinished(false);
} else {
LOG.warn("Unknown bond state for device " + device.getAddress() + ": " + bondState);
} }
} }
} }
@ -169,8 +177,10 @@ public class MiBandPairingActivity extends GBActivity {
LocalBroadcastManager.getInstance(this).unregisterReceiver(mPairingReceiver); LocalBroadcastManager.getInstance(this).unregisterReceiver(mPairingReceiver);
unregisterReceiver(mBondingReceiver); unregisterReceiver(mBondingReceiver);
Intent intent = new Intent(this, ControlCenter.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); if (pairedSuccessfully) {
startActivity(intent); Intent intent = new Intent(this, ControlCenter.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
finish(); finish();
} }
@ -182,7 +192,7 @@ public class MiBandPairingActivity extends GBActivity {
protected void performBluetoothPair(BluetoothDevice device) { protected void performBluetoothPair(BluetoothDevice device) {
int bondState = device.getBondState(); int bondState = device.getBondState();
if (bondState == BluetoothDevice.BOND_BONDED) { if (bondState == BluetoothDevice.BOND_BONDED) {
LOG.info("Already bonded: " + device.getAddress()); GB.toast("Already bonded with " + device.getName() + " (" + device.getAddress() + "), connecting...", Toast.LENGTH_SHORT, GB.INFO);
performPair(); performPair();
return; return;
} }