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

Commit 7358daa4 authored by wescande's avatar wescande Committed by William Escande
Browse files

Add more information for bond and acl state change

Report hci error to java. Report transport type to java.
Add both information to log

Test: Manual
Bug: 193685554
Fix: 193685554
Tag: #feature
Merged-In: If2bc8bc903c68b966ab49ccdeba80b55683e663d
Change-Id: If2bc8bc903c68b966ab49ccdeba80b55683e663d
parent 0aea4189
Loading
Loading
Loading
Loading
+11 −6
Original line number Diff line number Diff line
@@ -278,7 +278,8 @@ static void device_found_callback(int num_properties,
}

static void bond_state_changed_callback(bt_status_t status, RawAddress* bd_addr,
                                        bt_bond_state_t state) {
                                        bt_bond_state_t state,
                                        int fail_reason) {
  CallbackEnv sCallbackEnv(__func__);
  if (!sCallbackEnv.valid()) return;

@@ -297,11 +298,14 @@ static void bond_state_changed_callback(bt_status_t status, RawAddress* bd_addr,
                                   (jbyte*)bd_addr);

  sCallbackEnv->CallVoidMethod(sJniCallbacksObj, method_bondStateChangeCallback,
                               (jint)status, addr.get(), (jint)state);
                               (jint)status, addr.get(), (jint)state,
                               (jint)fail_reason);
}

static void acl_state_changed_callback(bt_status_t status, RawAddress* bd_addr,
                                       bt_acl_state_t state, bt_hci_error_code_t hci_reason) {
                                       bt_acl_state_t state,
                                       int transport_link_type,
                                       bt_hci_error_code_t hci_reason) {
  if (!bd_addr) {
    ALOGE("Address is null in %s", __func__);
    return;
@@ -320,7 +324,8 @@ static void acl_state_changed_callback(bt_status_t status, RawAddress* bd_addr,
                                   (jbyte*)bd_addr);

  sCallbackEnv->CallVoidMethod(sJniCallbacksObj, method_aclStateChangeCallback,
                               (jint)status, addr.get(), (jint)state, (jint)hci_reason);
                               (jint)status, addr.get(), (jint)state,
                               (jint)transport_link_type, (jint)hci_reason);
}

static void discovery_state_changed_callback(bt_discovery_state_t state) {
@@ -840,10 +845,10 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
      env->GetMethodID(jniCallbackClass, "sspRequestCallback", "([B[BIII)V");

  method_bondStateChangeCallback =
      env->GetMethodID(jniCallbackClass, "bondStateChangeCallback", "(I[BI)V");
      env->GetMethodID(jniCallbackClass, "bondStateChangeCallback", "(I[BII)V");

  method_aclStateChangeCallback =
      env->GetMethodID(jniCallbackClass, "aclStateChangeCallback", "(I[BII)V");
      env->GetMethodID(jniCallbackClass, "aclStateChangeCallback", "(I[BIII)V");

  method_linkQualityReportCallback = env->GetMethodID(
      jniCallbackClass, "linkQualityReportCallback", "(JIIIIII)V");
+2 −2
Original line number Diff line number Diff line
@@ -426,7 +426,7 @@ final class BondStateMachine extends StateMachine {
                + state2str(newState));
    }

    void bondStateChangeCallback(int status, byte[] address, int newState) {
    void bondStateChangeCallback(int status, byte[] address, int newState, int hciReason) {
        BluetoothDevice device = mRemoteDevices.getDevice(address);

        if (device == null) {
@@ -437,7 +437,7 @@ final class BondStateMachine extends StateMachine {
        }

        infoLog("bondStateChangeCallback: Status: " + status + " Address: " + device + " newState: "
                + newState);
                + newState + " hciReason: " + hciReason);

        Message msg = obtainMessage(BONDING_STATE_CHANGE);
        msg.obj = device;
+6 −4
Original line number Diff line number Diff line
@@ -63,12 +63,14 @@ final class JniCallbacks {
        mBondStateMachine.pinRequestCallback(address, name, cod, min16Digits);
    }

    void bondStateChangeCallback(int status, byte[] address, int newState) {
        mBondStateMachine.bondStateChangeCallback(status, address, newState);
    void bondStateChangeCallback(int status, byte[] address, int newState, int hciReason) {
        mBondStateMachine.bondStateChangeCallback(status, address, newState, hciReason);
    }

    void aclStateChangeCallback(int status, byte[] address, int newState, int hciReason) {
        mRemoteDevices.aclStateChangeCallback(status, address, newState, hciReason);
    void aclStateChangeCallback(int status, byte[] address, int newState,
            int transportLinkType, int hciReason) {
        mRemoteDevices.aclStateChangeCallback(status, address, newState,
                transportLinkType, hciReason);
    }

    void stateChangeCallback(int status) {
+8 −6
Original line number Diff line number Diff line
@@ -608,7 +608,8 @@ final class RemoteDevices {
        }
    }

    void aclStateChangeCallback(int status, byte[] address, int newState, int hciReason) {
    void aclStateChangeCallback(int status, byte[] address, int newState,
                                int transportLinkType, int hciReason) {
        BluetoothDevice device = getDevice(address);

        if (device == null) {
@@ -649,7 +650,9 @@ final class RemoteDevices {
            }
            debugLog(
                    "aclStateChangeCallback: Adapter State: " + BluetoothAdapter.nameForState(state)
                            + " Disconnected: " + device);
                            + " Disconnected: " + device
                            + " transportLinkType: " + transportLinkType
                            + " hciReason: " + hciReason);
        }

        int connectionState = newState == AbstractionLayer.BT_ACL_STATE_CONNECTED
@@ -663,10 +666,9 @@ final class RemoteDevices {
                sAdapterService.obfuscateAddress(device), classOfDevice, metricId);

        if (intent != null) {
            intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
            intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
                    | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
            intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
            intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device)
                .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT)
                .addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
            sAdapterService.sendBroadcast(intent, sAdapterService.BLUETOOTH_PERM);

            synchronized (sAdapterService.getBluetoothConnectionCallbacks()) {
+2 −2
Original line number Diff line number Diff line
@@ -118,10 +118,10 @@ public class BondStateMachineTest {
        verify(mAdapterService, times(1)).removeBondNative(eq(TEST_BT_ADDR_BYTES_2));

        mBondStateMachine.bondStateChangeCallback(AbstractionLayer.BT_STATUS_SUCCESS,
                TEST_BT_ADDR_BYTES, BOND_NONE);
                TEST_BT_ADDR_BYTES, BOND_NONE, 0);
        TestUtils.waitForLooperToFinishScheduledTask(mBondStateMachine.getHandler().getLooper());
        mBondStateMachine.bondStateChangeCallback(AbstractionLayer.BT_STATUS_SUCCESS,
                TEST_BT_ADDR_BYTES_2, BOND_NONE);
                TEST_BT_ADDR_BYTES_2, BOND_NONE, 0);
        TestUtils.waitForLooperToFinishScheduledTask(mBondStateMachine.getHandler().getLooper());

        // Try to pair these two devices again, createBondNative() should be invoked.
Loading