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

Commit ed119267 authored by Chris Manton's avatar Chris Manton Committed by Gerrit Code Review
Browse files

Merge "Use direct API VolumeControlDevice::IsEncryptionEnabled"

parents c515f1fd e61a6e25
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -24,11 +24,8 @@ void bluetooth::manager::SetMockBtmInterface(
  btm_interface = mock_btm_interface;
}

bool BTM_GetSecurityFlagsByTransport(const RawAddress& bd_addr,
                                     uint8_t* p_sec_flags,
                                     tBT_TRANSPORT transport) {
  return btm_interface->GetSecurityFlagsByTransport(bd_addr, p_sec_flags,
                                                    transport);
bool BTM_IsEncrypted(const RawAddress& bd_addr, tBT_TRANSPORT transport) {
  return btm_interface->BTM_IsEncrypted(bd_addr, transport);
}

tBTM_STATUS BTM_SetEncryption(const RawAddress& bd_addr,
+4 −7
Original line number Diff line number Diff line
@@ -25,8 +25,7 @@ namespace manager {

class BtmInterface {
 public:
  virtual bool GetSecurityFlagsByTransport(const RawAddress& bd_addr,
                                           uint8_t* p_sec_flags,
  virtual bool BTM_IsEncrypted(const RawAddress& bd_addr,
                               tBT_TRANSPORT transport) = 0;
  virtual tBTM_STATUS SetEncryption(const RawAddress& bd_addr,
                                    tBT_TRANSPORT transport,
@@ -38,10 +37,8 @@ class BtmInterface {

class MockBtmInterface : public BtmInterface {
 public:
  MOCK_METHOD((bool), GetSecurityFlagsByTransport,
              (const RawAddress& bd_addr, uint8_t* p_sec_flags,
               tBT_TRANSPORT transport),
              (override));
  MOCK_METHOD((bool), BTM_IsEncrypted,
              (const RawAddress& bd_addr, tBT_TRANSPORT transport), (override));
  MOCK_METHOD((tBTM_STATUS), SetEncryption,
              (const RawAddress& bd_addr, tBT_TRANSPORT transport,
               tBTM_SEC_CALLBACK* p_callback, void* p_ref_data,
+1 −6
Original line number Diff line number Diff line
@@ -228,12 +228,7 @@ bool VolumeControlDevice::VerifyReady(uint16_t handle) {
}

bool VolumeControlDevice::IsEncryptionEnabled() {
  uint8_t sec_flag = 0;
  bool device_found =
      BTM_GetSecurityFlagsByTransport(address, &sec_flag, BT_TRANSPORT_LE);
  LOG(INFO) << __func__ << ": found=" << static_cast<int>(device_found)
            << " sec_flag=" << loghex(sec_flag);
  return device_found && (sec_flag & BTM_SEC_FLAG_ENCRYPTED);
  return BTM_IsEncrypted(address, BT_TRANSPORT_LE);
}

bool VolumeControlDevice::EnableEncryption(tBTM_SEC_CALLBACK* callback) {
+4 −9
Original line number Diff line number Diff line
@@ -428,17 +428,12 @@ TEST_F(VolumeControlDeviceTest, test_enqueue_remaining_requests) {
}

TEST_F(VolumeControlDeviceTest, test_check_link_encrypted) {
  ON_CALL(btm_interface, GetSecurityFlagsByTransport(_, _, _))
      .WillByDefault(
          DoAll(SetArgPointee<1>(BTM_SEC_FLAG_ENCRYPTED), Return(true)));
  ON_CALL(btm_interface, BTM_IsEncrypted(_, _))
      .WillByDefault(DoAll(Return(true)));
  ASSERT_EQ(true, device->IsEncryptionEnabled());

  ON_CALL(btm_interface, GetSecurityFlagsByTransport(_, _, _))
      .WillByDefault(DoAll(SetArgPointee<1>(0), Return(false)));
  ASSERT_NE(true, device->IsEncryptionEnabled());

  ON_CALL(btm_interface, GetSecurityFlagsByTransport(_, _, _))
      .WillByDefault(DoAll(SetArgPointee<1>(0), Return(true)));
  ON_CALL(btm_interface, BTM_IsEncrypted(_, _))
      .WillByDefault(DoAll(Return(false)));
  ASSERT_NE(true, device->IsEncryptionEnabled());
}

+6 −8
Original line number Diff line number Diff line
@@ -250,9 +250,8 @@ class VolumeControlTest : public ::testing::Test {

  void TestConnect(const RawAddress& address) {
    // by default indicate link as encrypted
    ON_CALL(btm_interface, GetSecurityFlagsByTransport(address, NotNull(), _))
        .WillByDefault(
            DoAll(SetArgPointee<1>(BTM_SEC_FLAG_ENCRYPTED), Return(true)));
    ON_CALL(btm_interface, BTM_IsEncrypted(address, _))
        .WillByDefault(DoAll(Return(true)));

    EXPECT_CALL(gatt_interface, Open(gatt_if, address, true, _));
    VolumeControl::Get()->Connect(address);
@@ -269,9 +268,8 @@ class VolumeControlTest : public ::testing::Test {

  void TestAddFromStorage(const RawAddress& address, bool auto_connect) {
    // by default indicate link as encrypted
    ON_CALL(btm_interface, GetSecurityFlagsByTransport(address, NotNull(), _))
        .WillByDefault(
            DoAll(SetArgPointee<1>(BTM_SEC_FLAG_ENCRYPTED), Return(true)));
    ON_CALL(btm_interface, BTM_IsEncrypted(address, _))
        .WillByDefault(DoAll(Return(true)));

    if (auto_connect) {
      EXPECT_CALL(gatt_interface, Open(gatt_if, address, false, _));
@@ -360,8 +358,8 @@ class VolumeControlTest : public ::testing::Test {
  }

  void SetEncryptionResult(const RawAddress& address, bool success) {
    ON_CALL(btm_interface, GetSecurityFlagsByTransport(address, NotNull(), _))
        .WillByDefault(DoAll(SetArgPointee<1>(0), Return(true)));
    ON_CALL(btm_interface, BTM_IsEncrypted(address, _))
        .WillByDefault(DoAll(Return(false)));
    EXPECT_CALL(btm_interface,
                SetEncryption(address, _, NotNull(), _, BTM_BLE_SEC_ENCRYPT))
        .WillOnce(Invoke(