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

Commit ac7e63ce authored by Rongxuan Liu's avatar Rongxuan Liu
Browse files

[le audio] Add allow list check when le audio device connected

When le audio device connected, check stored remote model name and compare with
allowlist, then update the flag.

Bug: 301448525
Test: atest bluetooth_le_audio_client_test bluetooth_le_audio_test
Test: manual test with allow list
Change-Id: Ib14b1086446f81f74834ad3557b1056384058be9
parent 787dc24b
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -863,6 +863,7 @@ cc_test {
    srcs: [
        ":TestCommonMockFunctions",
        ":TestMockBtaLeAudioHalVerifier",
        ":TestMockMainShim",
        ":TestStubOsi",
        "le_audio/audio_hal_client/audio_hal_client_test.cc",
        "le_audio/audio_hal_client/audio_sink_hal_client.cc",
@@ -901,6 +902,7 @@ cc_test {
        ":audio_set_scenarios_json",
    ],
    generated_headers: [
        "BluetoothGeneratedDumpsysDataSchema_h",
        "LeAudioSetConfigSchemas_h",
    ],
    shared_libs: [
@@ -914,6 +916,7 @@ cc_test {
        "libbluetooth-types",
        "libbluetooth_gd",
        "libbt-common",
        "libbt-platform-protos-lite",
        "libbt_shim_bridge",
        "libbt_shim_ffi",
        "libchrome",
@@ -949,6 +952,7 @@ cc_test {
    srcs: [
        ":TestCommonMockFunctions",
        ":TestMockBtaLeAudioHalVerifier",
        ":TestMockMainShim",
        ":TestStubOsi",
        "gatt/database.cc",
        "gatt/database_builder.cc",
+2 −1
Original line number Diff line number Diff line
@@ -1918,7 +1918,8 @@ class LeAudioClientImpl : public LeAudioClient {

    leAudioDevice->conn_id_ = conn_id;
    leAudioDevice->mtu_ = mtu;

    /* Check if the device is in allow list and update the flag */
    leAudioDevice->UpdateDeviceAllowlistFlag();
    if (BTM_SecIsSecurityPending(address)) {
      /* if security collision happened, wait for encryption done
       * (BTA_GATTC_ENC_CMPL_CB_EVT) */
+32 −0
Original line number Diff line number Diff line
@@ -986,6 +986,38 @@ bool LeAudioDevice::IsMetadataChanged(
  return false;
}

void LeAudioDevice::GetDeviceModelName(void) {
  bt_property_t prop_name;
  bt_bdname_t prop_value = {0};
  // Retrieve model name from storage
  BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_REMOTE_MODEL_NUM,
                             sizeof(bt_bdname_t), &prop_value);
  if (btif_storage_get_remote_device_property(&address_, &prop_name) ==
      BT_STATUS_SUCCESS) {
    model_name_.assign((char*)prop_value.name);
  }
}

void LeAudioDevice::UpdateDeviceAllowlistFlag(void) {
  char allow_list[PROPERTY_VALUE_MAX] = {0};
  GetDeviceModelName();
  osi_property_get(kLeAudioDeviceAllowListProp, allow_list, "");
  if (allow_list[0] == '\0' || model_name_ == "") {
    // if device allow list is empty or no remote model name available
    // return allowlist_flag_ as default false
    return;
  }

  std::istringstream stream(allow_list);
  std::string token;
  while (std::getline(stream, token, ',')) {
    if (token.compare(model_name_) == 0) {
      allowlist_flag_ = true;
      return;
    }
  }
}

/* LeAudioDevices Class methods implementation */
void LeAudioDevices::Add(const RawAddress& address, DeviceConnectState state,
                         int group_id) {
+9 −0
Original line number Diff line number Diff line
@@ -117,6 +117,8 @@ class LeAudioDevice {
  std::vector<struct types::ase> ases_;
  struct types::hdl_pair ctp_hdls_;
  uint16_t tmap_role_hdl_;
  std::string model_name_;
  bool allowlist_flag_;

  alarm_t* link_quality_timer;
  uint16_t link_quality_timer_data;
@@ -135,6 +137,8 @@ class LeAudioDevice {
        group_id_(group_id),
        csis_member_(false),
        audio_directions_(0),
        model_name_(""),
        allowlist_flag_(false),
        link_quality_timer(nullptr) {}
  ~LeAudioDevice(void);

@@ -238,9 +242,14 @@ class LeAudioDevice {
      const types::BidirectionalPair<types::AudioContexts>& context_types,
      const types::BidirectionalPair<std::vector<uint8_t>>& ccid_lists);

  void GetDeviceModelName(void);
  void UpdateDeviceAllowlistFlag(void);

 private:
  types::BidirectionalPair<types::AudioContexts> avail_contexts_;
  types::BidirectionalPair<types::AudioContexts> supp_contexts_;
  static constexpr char kLeAudioDeviceAllowListProp[] =
      "persist.bluetooth.leaudio.allow_list";

  void DumpPacsDebugState(std::stringstream& stream,
                          types::PublishedAudioCapabilities pacs);
+30 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include "btif_storage_mock.h"
#include "btm_api_mock.h"
#include "device_groups.h"
#include "le_audio_set_configuration_provider.h"
@@ -66,17 +67,20 @@ class LeAudioDevicesTest : public Test {
    devices_ = new LeAudioDevices();
    bluetooth::manager::SetMockBtmInterface(&btm_interface);
    controller::SetMockControllerInterface(&controller_interface_);
    bluetooth::storage::SetMockBtifStorageInterface(&mock_btif_storage_);
  }

  void TearDown() override {
    controller::SetMockControllerInterface(nullptr);
    bluetooth::manager::SetMockBtmInterface(nullptr);
    bluetooth::storage::SetMockBtifStorageInterface(nullptr);
    delete devices_;
  }

  LeAudioDevices* devices_ = nullptr;
  bluetooth::manager::MockBtmInterface btm_interface;
  controller::MockControllerInterface controller_interface_;
  bluetooth::storage::MockBtifStorageInterface mock_btif_storage_;
};

TEST_F(LeAudioDevicesTest, test_add) {
@@ -169,6 +173,32 @@ TEST_F(LeAudioDevicesTest, test_find_by_conn_id_failed) {
  ASSERT_EQ(nullptr, devices_->FindByConnId(0x0006));
}

TEST_F(LeAudioDevicesTest, test_get_device_model_name_success) {
  RawAddress test_address_0 = GetTestAddress(0);
  devices_->Add(test_address_0, DeviceConnectState::CONNECTING_BY_USER);
  std::shared_ptr<LeAudioDevice> device =
      devices_->GetByAddress(test_address_0);
  ASSERT_NE(nullptr, device);
  device->model_name_ = "Test";
  ON_CALL(mock_btif_storage_, GetRemoteDeviceProperty(_, _))
      .WillByDefault(Return(BT_STATUS_SUCCESS));
  device->GetDeviceModelName();
  ASSERT_EQ("", device->model_name_);
}

TEST_F(LeAudioDevicesTest, test_get_device_model_name_failed) {
  RawAddress test_address_0 = GetTestAddress(0);
  devices_->Add(test_address_0, DeviceConnectState::CONNECTING_BY_USER);
  std::shared_ptr<LeAudioDevice> device =
      devices_->GetByAddress(test_address_0);
  ASSERT_NE(nullptr, device);
  device->model_name_ = "Test";
  ON_CALL(mock_btif_storage_, GetRemoteDeviceProperty(_, _))
      .WillByDefault(Return(BT_STATUS_FAIL));
  device->GetDeviceModelName();
  ASSERT_EQ("Test", device->model_name_);
}

/* TODO: Add FindByCisConnHdl test cases (ASE) */

}  // namespace
Loading