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

Commit b9c4f48f authored by Zach Johnson's avatar Zach Johnson
Browse files

Simplify canceling the bond process

Bug: 145171640
Test: compile & try cancelling a bond
Change-Id: I0f35199104e203c2477c4091f2e46826b769ee31
parent 5ba9fd9d
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -71,6 +71,10 @@ public final class Utils {
        return getBytesFromAddress(device.getAddress());
    }

    public static byte[] addressToBytes(String address) {
        return getBytesFromAddress(address);
    }

    public static byte[] getBytesFromAddress(String address) {
        int i, j = 0;
        byte[] output = new byte[BD_ADDR_LEN];
+7 −12
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static com.android.bluetooth.Utils.enforceLocalMacAddressPermission;
import static com.android.bluetooth.Utils.enforceDumpPermission;
import static com.android.bluetooth.Utils.callerIsSystemOrActiveUser;
import static com.android.bluetooth.Utils.callerIsSystemOrActiveOrManagedUser;
import static com.android.bluetooth.Utils.addressToBytes;

import android.app.ActivityManager;
import android.app.AlarmManager;
@@ -1422,7 +1423,12 @@ public class AdapterService extends Service {

            enforceBluetoothAdminPermission(service);

            return service.cancelBondProcess(device);
            DeviceProperties deviceProp = service.mRemoteDevices.getDeviceProperties(device);
            if (deviceProp != null) {
                deviceProp.setBondingInitiatedLocally(false);
            }

            return service.cancelBondNative(addressToBytes(device.getAddress()));
        }

        @Override
@@ -2068,17 +2074,6 @@ public class AdapterService extends Service {
        mBondStateMachine.sendMessage(msg);
    }

    boolean cancelBondProcess(BluetoothDevice device) {
        byte[] addr = Utils.getBytesFromAddress(device.getAddress());

        DeviceProperties deviceProp = mRemoteDevices.getDeviceProperties(device);
        if (deviceProp != null) {
            deviceProp.setBondingInitiatedLocally(false);
        }

        return cancelBondNative(addr);
    }

    boolean removeBond(BluetoothDevice device) {
        DeviceProperties deviceProp = mRemoteDevices.getDeviceProperties(device);
        if (deviceProp == null || deviceProp.getBondState() != BluetoothDevice.BOND_BONDED) {