Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 25dac82f authored by Zach Johnson's avatar Zach Johnson
Browse files

Simplify remote device bonding or bonded checks

Bug: 145171640
Test: compile & run
Change-Id: I3fadbe9309c9e741ab96b8306df3fb7402adda11
parent 31c7e9c9
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -2550,8 +2550,7 @@ public class AdapterService extends Service {
    boolean setPin(BluetoothDevice device, boolean accept, int len, byte[] pinCode) {
        DeviceProperties deviceProp = mRemoteDevices.getDeviceProperties(device);
        // Only allow setting a pin in bonding state, or bonded state in case of security upgrade.
        if (deviceProp == null || (deviceProp.getBondState() != BluetoothDevice.BOND_BONDING
                && deviceProp.getBondState() != BluetoothDevice.BOND_BONDED)) {
        if (deviceProp == null || !deviceProp.isBondingOrBonded()) {
            return false;
        }

@@ -2569,7 +2568,7 @@ public class AdapterService extends Service {

    boolean setPasskey(BluetoothDevice device, boolean accept, int len, byte[] passkey) {
        DeviceProperties deviceProp = mRemoteDevices.getDeviceProperties(device);
        if (deviceProp == null || deviceProp.getBondState() != BluetoothDevice.BOND_BONDING) {
        if (deviceProp == null || !deviceProp.isBonding()) {
            return false;
        }

@@ -2588,7 +2587,7 @@ public class AdapterService extends Service {

    boolean setPairingConfirmation(BluetoothDevice device, boolean accept) {
        DeviceProperties deviceProp = mRemoteDevices.getDeviceProperties(device);
        if (deviceProp == null || deviceProp.getBondState() != BluetoothDevice.BOND_BONDING) {
        if (deviceProp == null || !deviceProp.isBonding()) {
            return false;
        }

+8 −0
Original line number Diff line number Diff line
@@ -336,6 +336,14 @@ final class RemoteDevices {
            }
        }

        boolean isBonding() {
            return getBondState() == BluetoothDevice.BOND_BONDING;
        }

        boolean isBondingOrBonded() {
            return isBonding() || getBondState() == BluetoothDevice.BOND_BONDED;
        }

        /**
         * @param isBondingInitiatedLocally wether bonding is initiated locally
         */