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

Commit 954683bd authored by Rongxuan Liu's avatar Rongxuan Liu Committed by Gerrit Code Review
Browse files

Merge changes I84dd1ea8,I22000ea0

* changes:
  Add support to create le bond with address type (2/2)
  Add support to create le bond with address type (1/2)
parents 4fef6cef 2d9e1d50
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -58,6 +58,9 @@ namespace android {
#define TRANSPORT_BREDR 1
#define TRANSPORT_LE 2

#define BLE_ADDR_PUBLIC 0x00
#define BLE_ADDR_RANDOM 0x01

const jint INVALID_FD = -1;

static jmethodID method_oobDataReceivedCallback;
@@ -1120,7 +1123,7 @@ static jboolean cancelDiscoveryNative(JNIEnv* env, jobject obj) {
}

static jboolean createBondNative(JNIEnv* env, jobject obj, jbyteArray address,
                                 jint transport) {
                                 jint addrType, jint transport) {
  ALOGV("%s", __func__);

  if (!sBluetoothInterface) return JNI_FALSE;
@@ -1131,7 +1134,13 @@ static jboolean createBondNative(JNIEnv* env, jobject obj, jbyteArray address,
    return JNI_FALSE;
  }

  int ret = sBluetoothInterface->create_bond((RawAddress*)addr, transport);
  uint8_t addr_type = (uint8_t)addrType;
  int ret = BT_STATUS_SUCCESS;
  if (addr_type == BLE_ADDR_RANDOM) {
    ret = sBluetoothInterface->create_bond_le((RawAddress*)addr, addr_type);
  } else {
    ret = sBluetoothInterface->create_bond((RawAddress*)addr, transport);
  }
  env->ReleaseByteArrayElements(address, addr, 0);
  return (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
@@ -1860,7 +1869,7 @@ static JNINativeMethod sMethods[] = {
    {"setDevicePropertyNative", "([BI[B)Z", (void*)setDevicePropertyNative},
    {"startDiscoveryNative", "()Z", (void*)startDiscoveryNative},
    {"cancelDiscoveryNative", "()Z", (void*)cancelDiscoveryNative},
    {"createBondNative", "([BI)Z", (void*)createBondNative},
    {"createBondNative", "([BII)Z", (void*)createBondNative},
    {"createBondOutOfBandNative",
     "([BILandroid/bluetooth/OobData;Landroid/bluetooth/OobData;)Z",
     (void*)createBondOutOfBandNative},
+2 −2
Original line number Diff line number Diff line
@@ -6278,8 +6278,8 @@ public class AdapterService extends Service {
    /*package*/
    native boolean getDevicePropertyNative(byte[] address, int type);

    /*package*/
    public native boolean createBondNative(byte[] address, int transport);
    /** package */
    public native boolean createBondNative(byte[] address, int addressType, int transport);

    /*package*/
    native boolean createBondOutOfBandNative(byte[] address, int transport,
+2 −1
Original line number Diff line number Diff line
@@ -344,6 +344,7 @@ final class BondStateMachine extends StateMachine {
        if (dev.getBondState() == BluetoothDevice.BOND_NONE) {
            infoLog("Bond address is:" + dev);
            byte[] addr = Utils.getBytesFromAddress(dev.getAddress());
            int addrType = dev.getAddressType();
            boolean result;
            // If we have some data
            if (remoteP192Data != null || remoteP256Data != null) {
@@ -360,7 +361,7 @@ final class BondStateMachine extends StateMachine {
                      BluetoothDevice.BOND_BONDING,
                      BluetoothProtoEnums.BOND_SUB_STATE_LOCAL_START_PAIRING,
                      BluetoothProtoEnums.UNBOND_REASON_UNKNOWN, mAdapterService.getMetricId(dev));
                result = mAdapterService.createBondNative(addr, transport);
                result = mAdapterService.createBondNative(addr, addrType, transport);
            }
            BluetoothStatsLog.write(BluetoothStatsLog.BLUETOOTH_DEVICE_NAME_REPORTED,
                    mAdapterService.getMetricId(dev), dev.getName());
+35 −3
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import static android.Manifest.permission.BLUETOOTH_CONNECT;

import static org.mockito.Mockito.*;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothManager;
import android.content.Context;
@@ -34,6 +35,7 @@ import androidx.test.filters.MediumTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.bluetooth.TestUtils;
import com.android.bluetooth.Utils;

import org.junit.After;
import org.junit.Assert;
@@ -113,7 +115,8 @@ public class BondStateMachineTest {
        deviceProperties2.mBondState = BOND_BONDED;

        doReturn(true).when(mAdapterService).removeBondNative(any(byte[].class));
        doReturn(true).when(mAdapterService).createBondNative(any(byte[].class), anyInt());
        doReturn(true).when(mAdapterService).createBondNative(any(byte[].class),
                eq(BluetoothDevice.ADDRESS_TYPE_PUBLIC), anyInt());

        // The removeBond() request for a bonded device should invoke the removeBondNative() call.
        Message removeBondMsg1 = mBondStateMachine.obtainMessage(BondStateMachine.REMOVE_BOND);
@@ -144,8 +147,37 @@ public class BondStateMachineTest {
        mBondStateMachine.sendMessage(createBondMsg2);
        TestUtils.waitForLooperToFinishScheduledTask(mBondStateMachine.getHandler().getLooper());

        verify(mAdapterService, times(1)).createBondNative(eq(TEST_BT_ADDR_BYTES), anyInt());
        verify(mAdapterService, times(1)).createBondNative(eq(TEST_BT_ADDR_BYTES_2), anyInt());
        verify(mAdapterService, times(1)).createBondNative(eq(TEST_BT_ADDR_BYTES),
                eq(BluetoothDevice.ADDRESS_TYPE_PUBLIC), anyInt());
        verify(mAdapterService, times(1)).createBondNative(eq(TEST_BT_ADDR_BYTES_2),
                eq(BluetoothDevice.ADDRESS_TYPE_PUBLIC), anyInt());
    }

    @Test
    public void testCreateBondWithLeDevice() {
        mRemoteDevices.reset();
        mBondStateMachine.mPendingBondedDevices.clear();

        BluetoothDevice device1 = BluetoothAdapter.getDefaultAdapter().getRemoteLeDevice(
                        Utils.getAddressStringFromByte(TEST_BT_ADDR_BYTES),
                        BluetoothDevice.ADDRESS_TYPE_PUBLIC);
        BluetoothDevice device2 = BluetoothAdapter.getDefaultAdapter().getRemoteLeDevice(
                        Utils.getAddressStringFromByte(TEST_BT_ADDR_BYTES_2),
                        BluetoothDevice.ADDRESS_TYPE_RANDOM);

        // The createBond() request for two devices with different address types.
        Message createBondMsg1 = mBondStateMachine.obtainMessage(BondStateMachine.CREATE_BOND);
        createBondMsg1.obj = device1;
        mBondStateMachine.sendMessage(createBondMsg1);
        Message createBondMsg2 = mBondStateMachine.obtainMessage(BondStateMachine.CREATE_BOND);
        createBondMsg2.obj = device2;
        mBondStateMachine.sendMessage(createBondMsg2);
        TestUtils.waitForLooperToFinishScheduledTask(mBondStateMachine.getHandler().getLooper());

        verify(mAdapterService, times(1)).createBondNative(eq(TEST_BT_ADDR_BYTES),
                eq(BluetoothDevice.ADDRESS_TYPE_PUBLIC), anyInt());
        verify(mAdapterService, times(1)).createBondNative(eq(TEST_BT_ADDR_BYTES_2),
                eq(BluetoothDevice.ADDRESS_TYPE_RANDOM), anyInt());
    }

    @Test
+9 −0
Original line number Diff line number Diff line
@@ -224,6 +224,15 @@ bool btif_dm_pairing_is_busy();
 ******************************************************************************/
void btif_dm_create_bond(const RawAddress bd_addr, int transport);

/*******************************************************************************
 *
 * Function         btif_dm_create_bond_le
 *
 * Description      Initiate bonding with the specified device over le transport
 *
 ******************************************************************************/
void btif_dm_create_bond_le(const RawAddress bd_addr, uint8_t addr_type);

/*******************************************************************************
 *
 * Function         btif_dm_create_bond_out_of_band
Loading