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

Commit 022829e3 authored by Jakub Tyszkowski's avatar Jakub Tyszkowski Committed by Automerger Merge Worker
Browse files

Merge "vc: Fix doing initial reads and writes twice" am: 2bae2831

parents 21ef4c28 2bae2831
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -415,10 +415,8 @@ bool VolumeControlDevice::IsEncryptionEnabled() {
  return BTM_IsEncrypted(address, BT_TRANSPORT_LE);
}

bool VolumeControlDevice::EnableEncryption(tBTM_SEC_CALLBACK* callback) {
  int result = BTM_SetEncryption(address, BT_TRANSPORT_LE, callback, nullptr,
void VolumeControlDevice::EnableEncryption() {
  int result = BTM_SetEncryption(address, BT_TRANSPORT_LE, nullptr, nullptr,
                                 BTM_BLE_SEC_ENCRYPT);
  LOG(INFO) << __func__ << ": result=" << +result;
  // TODO: should we care about the result??
  return true;
}
+1 −1
Original line number Diff line number Diff line
@@ -130,7 +130,7 @@ class VolumeControlDevice {
                                        GATT_WRITE_OP_CB cb, void* cb_data);
  bool IsEncryptionEnabled();

  bool EnableEncryption(tBTM_SEC_CALLBACK* callback);
  void EnableEncryption();

  bool EnqueueInitialRequests(tGATT_IF gatt_if, GATT_READ_OP_CB chrc_read_cb,
                              GATT_WRITE_OP_CB cccd_write_cb);
+1 −8
Original line number Diff line number Diff line
@@ -145,9 +145,7 @@ class VolumeControlImpl : public VolumeControl {
      return;
    }

    if (!device->EnableEncryption(enc_callback_static)) {
      device_cleanup_helper(device, device->connecting_actively);
    }
    device->EnableEncryption();
  }

  void OnEncryptionComplete(const RawAddress& address, uint8_t success) {
@@ -1120,11 +1118,6 @@ class VolumeControlImpl : public VolumeControl {
    if (instance) instance->gattc_callback(event, p_data);
  }

  static void enc_callback_static(const RawAddress* address, tBT_TRANSPORT,
                                  void*, tBTM_STATUS status) {
    if (instance) instance->OnEncryptionComplete(*address, status);
  }

  static void chrc_read_callback_static(uint16_t conn_id, tGATT_STATUS status,
                                        uint16_t handle, uint16_t len,
                                        uint8_t* value, void* data) {
+21 −8
Original line number Diff line number Diff line
@@ -441,19 +441,32 @@ class VolumeControlTest : public ::testing::Test {
    gatt_callback(BTA_GATTC_SEARCH_CMPL_EVT, (tBTA_GATTC*)&event_data);
  }

  void GetEncryptionCompleteEvt(const RawAddress& bda) {
    tBTA_GATTC cb_data{};

    cb_data.enc_cmpl.client_if = gatt_if;
    cb_data.enc_cmpl.remote_bda = bda;
    gatt_callback(BTA_GATTC_ENC_CMPL_CB_EVT, &cb_data);
  }

  void SetEncryptionResult(const RawAddress& address, bool success) {
    ON_CALL(btm_interface, BTM_IsEncrypted(address, _))
        .WillByDefault(DoAll(Return(false)));
    EXPECT_CALL(btm_interface,
                SetEncryption(address, _, NotNull(), _, BTM_BLE_SEC_ENCRYPT))
        .WillOnce(Invoke(
            [&success](const RawAddress& bd_addr, tBT_TRANSPORT transport,
    ON_CALL(btm_interface, SetEncryption(address, _, _, _, BTM_BLE_SEC_ENCRYPT))
        .WillByDefault(Invoke(
            [&success, this](const RawAddress& bd_addr, tBT_TRANSPORT transport,
                             tBTM_SEC_CALLBACK* p_callback, void* p_ref_data,
                             tBTM_BLE_SEC_ACT sec_act) -> tBTM_STATUS {
              if (p_callback) {
                p_callback(&bd_addr, transport, p_ref_data,
                           success ? BTM_SUCCESS : BTM_FAILED_ON_SECURITY);
              }
              GetEncryptionCompleteEvt(bd_addr);
              return BTM_SUCCESS;
            }));
    EXPECT_CALL(btm_interface,
                SetEncryption(address, _, _, _, BTM_BLE_SEC_ENCRYPT))
        .Times(1);
  }

  void SetSampleDatabaseVCS(uint16_t conn_id) {
+1 −3
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ extern std::map<std::string, int> mock_function_count_map;
#include <vector>

#include "bta/vc/devices.h"
#include "stack/btm/btm_sec.h"

using namespace bluetooth::vc::internal;

@@ -36,9 +35,8 @@ using namespace bluetooth::vc::internal;
#define UNUSED_ATTR
#endif

bool VolumeControlDevice::EnableEncryption(tBTM_SEC_CALLBACK* callback) {
void VolumeControlDevice::EnableEncryption() {
  mock_function_count_map[__func__]++;
  return false;
}
bool VolumeControlDevice::EnqueueInitialRequests(
    tGATT_IF gatt_if, GATT_READ_OP_CB chrc_read_cb,