mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
ble: remove macAddress parameter from BondingUtil.companionDeviceManagerBond
Redundant source of truth. The information is already available via the device parameter. Leaving it in would complicate future improvements to the CompanionDevice handling.
This commit is contained in:
committed by
José Rebelo
parent
c244785523
commit
afdf6e6888
+1
-1
@@ -154,7 +154,7 @@ public class MiBandPairingActivity extends AbstractGBActivity implements Bonding
|
||||
BondingUtil.attemptToFirstConnect(getCurrentTarget().getDevice());
|
||||
})
|
||||
.setPositiveButton(getContext().getString(R.string.discovery_yes_pair), (dialog, which) -> {
|
||||
BondingUtil.tryBondThenComplete(thiz, deviceCandidate.getDevice(), deviceCandidate.getMacAddress());
|
||||
BondingUtil.tryBondThenComplete(thiz, deviceCandidate.getDevice());
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
+1
-1
@@ -126,7 +126,7 @@ public class PebblePairingActivity extends AbstractGBActivity implements Bonding
|
||||
btDevice.getBondState() == BluetoothDevice.BOND_BONDING) {
|
||||
BondingUtil.connectThenComplete(this, deviceCandidate);
|
||||
} else {
|
||||
BondingUtil.tryBondThenComplete(this, deviceCandidate.getDevice(), deviceCandidate.getDevice().getAddress());
|
||||
BondingUtil.tryBondThenComplete(this, deviceCandidate.getDevice());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -77,7 +77,7 @@ public class BondAction extends PlainAction implements BondingInterface {
|
||||
@Override
|
||||
public boolean run(BluetoothGatt gatt) {
|
||||
mMacAddress = gatt.getDevice().getAddress();
|
||||
BondingUtil.tryBondThenComplete(this, gatt.getDevice(), gatt.getDevice().getAddress());
|
||||
BondingUtil.tryBondThenComplete(this, gatt.getDevice());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ public class BondingUtil {
|
||||
.setPositiveButton(bondingInterface.getContext().getString(R.string.discovery_yes_pair), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
BondingUtil.tryBondThenComplete(bondingInterface, deviceCandidate.getDevice(), deviceCandidate.getMacAddress());
|
||||
BondingUtil.tryBondThenComplete(bondingInterface, deviceCandidate.getDevice());
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.discovery_dont_pair, new DialogInterface.OnClickListener() {
|
||||
@@ -227,7 +227,7 @@ public class BondingUtil {
|
||||
})
|
||||
.show();
|
||||
} else {
|
||||
BondingUtil.tryBondThenComplete(bondingInterface, deviceCandidate.getDevice(), deviceCandidate.getMacAddress());
|
||||
BondingUtil.tryBondThenComplete(bondingInterface, deviceCandidate.getDevice());
|
||||
}
|
||||
LOG.debug("Bonding initiated");
|
||||
}
|
||||
@@ -318,8 +318,8 @@ public class BondingUtil {
|
||||
*/
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
private static void companionDeviceManagerBond(BondingInterface bondingInterface,
|
||||
BluetoothDevice device,
|
||||
String macAddress) {
|
||||
BluetoothDevice device) {
|
||||
final String macAddress = device.getAddress();
|
||||
BluetoothDeviceFilter deviceFilter = new BluetoothDeviceFilter.Builder()
|
||||
.setAddress(macAddress)
|
||||
.build();
|
||||
@@ -376,7 +376,7 @@ public class BondingUtil {
|
||||
/**
|
||||
* Use this function to initiate bonding to a GBDeviceCandidate
|
||||
*/
|
||||
public static void tryBondThenComplete(final BondingInterface bondingInterface, final BluetoothDevice device, final String macAddress) {
|
||||
public static void tryBondThenComplete(final BondingInterface bondingInterface, final BluetoothDevice device) {
|
||||
bondingInterface.registerBroadcastReceivers();
|
||||
|
||||
final int bondState = device.getBondState();
|
||||
@@ -397,7 +397,7 @@ public class BondingUtil {
|
||||
// If CompanionDeviceManager is available, skip connection and go bond
|
||||
// TODO: It would theoretically be nice to check if it's already been granted,
|
||||
// but re-bond works
|
||||
askCompanionPairing(bondingInterface, device, macAddress);
|
||||
askCompanionPairing(bondingInterface, device);
|
||||
} else {
|
||||
attemptToFirstConnect(bondingInterface.getCurrentTarget().getDevice());
|
||||
}
|
||||
@@ -407,7 +407,7 @@ public class BondingUtil {
|
||||
GB.toast(bondingInterface.getContext(), bondingInterface.getContext().getString(R.string.pairing_creating_bond_with, device.getName(), device.getAddress()), Toast.LENGTH_LONG, GB.INFO);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !isPebble2(device) && contextIsActivity) {
|
||||
askCompanionPairing(bondingInterface, device, macAddress);
|
||||
askCompanionPairing(bondingInterface, device);
|
||||
} else if (isPebble2(device)) {
|
||||
// TODO: start companionDevicePairing after connecting to Pebble 2 but before writing to pairing trigger
|
||||
attemptToFirstConnect(device);
|
||||
@@ -419,12 +419,12 @@ public class BondingUtil {
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
private static void askCompanionPairing(BondingInterface bondingInterface, BluetoothDevice device, String macAddress) {
|
||||
private static void askCompanionPairing(BondingInterface bondingInterface, BluetoothDevice device) {
|
||||
new MaterialAlertDialogBuilder(bondingInterface.getContext())
|
||||
.setTitle(R.string.companion_pairing_request_title)
|
||||
.setMessage(R.string.companion_pairing_request_description)
|
||||
.setPositiveButton(R.string.yes, (dialog, whichButton) -> {
|
||||
companionDeviceManagerBond(bondingInterface, device, macAddress);
|
||||
companionDeviceManagerBond(bondingInterface, device);
|
||||
})
|
||||
.setNegativeButton(R.string.no, (dialog, whichButton) -> {
|
||||
bluetoothBond(bondingInterface, device);
|
||||
|
||||
Reference in New Issue
Block a user