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

Commit c549bf9f authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Shim: Add GD advertising init flags" am: 01d4917f am: 33a84878

Original change: https://android-review.googlesource.com/c/platform/system/bt/+/1420888

Change-Id: I81b850b218afa41715c80bc560b4b0e95811f1d1
parents 8a72320c 33a84878
Loading
Loading
Loading
Loading
+9 −1
Original line number Original line Diff line number Diff line
@@ -25,6 +25,9 @@
namespace bluetooth {
namespace bluetooth {
namespace common {
namespace common {


const std::string kGdAdvertisingFlag = "INIT_gd_advertising";
bool InitFlags::gd_advertising_enabled = false;

const std::string kGdSecurityFlag = "INIT_gd_security";
const std::string kGdSecurityFlag = "INIT_gd_security";
bool InitFlags::gd_security_enabled = false;
bool InitFlags::gd_security_enabled = false;


@@ -48,6 +51,8 @@ void InitFlags::Load(const char** flags) {
  while (flags != nullptr && *flags != nullptr) {
  while (flags != nullptr && *flags != nullptr) {
    if (kGdCoreFlag == *flags) {
    if (kGdCoreFlag == *flags) {
      gd_core_enabled = true;
      gd_core_enabled = true;
    } else if (kGdAdvertisingFlag == *flags) {
      gd_advertising_enabled = true;
    } else if (kGdSecurityFlag == *flags) {
    } else if (kGdSecurityFlag == *flags) {
      gd_security_enabled = true;
      gd_security_enabled = true;
    } else if (kGdAclFlag == *flags) {
    } else if (kGdAclFlag == *flags) {
@@ -76,8 +81,10 @@ void InitFlags::Load(const char** flags) {
  }
  }


  LOG_INFO(
  LOG_INFO(
      "Flags loaded: gd_security_enabled: %s, gd_acl_enabled: %s, gd_hci_enabled: %s, gd_controller_enabled: %s, "
      "Flags loaded: gd_advertising_enabled %s, gd_security_enabled: %s, gd_acl_enabled: %s, gd_hci_enabled: %s, "
      "gd_controller_enabled: %s, "
      "gd_core_enabled: %s",
      "gd_core_enabled: %s",
      gd_advertising_enabled ? "true" : "false",
      gd_security_enabled ? "true" : "false",
      gd_security_enabled ? "true" : "false",
      gd_acl_enabled ? "true" : "false",
      gd_acl_enabled ? "true" : "false",
      gd_hci_enabled ? "true" : "false",
      gd_hci_enabled ? "true" : "false",
@@ -87,6 +94,7 @@ void InitFlags::Load(const char** flags) {


void InitFlags::SetAll(bool value) {
void InitFlags::SetAll(bool value) {
  gd_core_enabled = value;
  gd_core_enabled = value;
  gd_advertising_enabled = value;
  gd_acl_enabled = value;
  gd_acl_enabled = value;
  gd_security_enabled = value;
  gd_security_enabled = value;
  gd_controller_enabled = value;
  gd_controller_enabled = value;
+1 −0
Original line number Original line Diff line number Diff line
@@ -4,6 +4,7 @@ attribute "privacy";


table InitFlagsData {
table InitFlagsData {
    title:string;
    title:string;
    gd_advertising_enabled:bool;
    gd_security_enabled:bool;
    gd_security_enabled:bool;
    gd_acl_enabled:bool;
    gd_acl_enabled:bool;
    gd_hci_enabled:bool;
    gd_hci_enabled:bool;
+5 −0
Original line number Original line Diff line number Diff line
@@ -23,6 +23,10 @@ class InitFlags final {
 public:
 public:
  static void Load(const char** flags);
  static void Load(const char** flags);


  static bool GdAdvertisingEnabled() {
    return gd_advertising_enabled;
  }

  static bool GdSecurityEnabled() {
  static bool GdSecurityEnabled() {
    return gd_security_enabled;
    return gd_security_enabled;
  }
  }
@@ -51,6 +55,7 @@ class InitFlags final {


 private:
 private:
  static void SetAll(bool value);
  static void SetAll(bool value);
  static bool gd_advertising_enabled;
  static bool gd_security_enabled;
  static bool gd_security_enabled;
  static bool gd_acl_enabled;
  static bool gd_acl_enabled;
  static bool gd_hci_enabled;
  static bool gd_hci_enabled;
+1 −0
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ flatbuffers::Offset<bluetooth::common::InitFlagsData> bluetooth::dumpsys::InitFl
  auto title = fb_builder->CreateString("----- Init Flags -----");
  auto title = fb_builder->CreateString("----- Init Flags -----");
  common::InitFlagsDataBuilder builder(*fb_builder);
  common::InitFlagsDataBuilder builder(*fb_builder);
  builder.add_title(title);
  builder.add_title(title);
  builder.add_gd_advertising_enabled(bluetooth::common::InitFlags::GdAdvertisingEnabled());
  builder.add_gd_security_enabled(bluetooth::common::InitFlags::GdSecurityEnabled());
  builder.add_gd_security_enabled(bluetooth::common::InitFlags::GdSecurityEnabled());
  builder.add_gd_acl_enabled(bluetooth::common::InitFlags::GdAclEnabled());
  builder.add_gd_acl_enabled(bluetooth::common::InitFlags::GdAclEnabled());
  builder.add_gd_hci_enabled(bluetooth::common::InitFlags::GdHciEnabled());
  builder.add_gd_hci_enabled(bluetooth::common::InitFlags::GdHciEnabled());
+40 −3
Original line number Original line Diff line number Diff line
@@ -185,6 +185,29 @@ static bool event_already_registered_in_hci_layer(
  }
  }
}
}


static bool event_already_registered_in_le_advertising_manager(
    bluetooth::hci::EventCode event_code) {
  switch (event_code) {
    case bluetooth::hci::EventCode::CONNECTION_PACKET_TYPE_CHANGED:
    case bluetooth::hci::EventCode::ROLE_CHANGE:
    case bluetooth::hci::EventCode::CONNECTION_COMPLETE:
    case bluetooth::hci::EventCode::CONNECTION_REQUEST:
    case bluetooth::hci::EventCode::AUTHENTICATION_COMPLETE:
    case bluetooth::hci::EventCode::READ_CLOCK_OFFSET_COMPLETE:
    case bluetooth::hci::EventCode::MODE_CHANGE:
    case bluetooth::hci::EventCode::QOS_SETUP_COMPLETE:
    case bluetooth::hci::EventCode::FLOW_SPECIFICATION_COMPLETE:
    case bluetooth::hci::EventCode::FLUSH_OCCURRED:
    case bluetooth::hci::EventCode::READ_REMOTE_SUPPORTED_FEATURES_COMPLETE:
    case bluetooth::hci::EventCode::READ_REMOTE_EXTENDED_FEATURES_COMPLETE:
    case bluetooth::hci::EventCode::READ_REMOTE_VERSION_INFORMATION_COMPLETE:
    case bluetooth::hci::EventCode::LINK_SUPERVISION_TIMEOUT_CHANGED:
      return bluetooth::shim::is_gd_advertising_enabled();
    default:
      return false;
  }
}

std::unique_ptr<bluetooth::packet::RawBuilder> MakeUniquePacket(
std::unique_ptr<bluetooth::packet::RawBuilder> MakeUniquePacket(
    const uint8_t* data, size_t len) {
    const uint8_t* data, size_t len) {
  bluetooth::packet::RawBuilder builder;
  bluetooth::packet::RawBuilder builder;
@@ -412,14 +435,23 @@ void bluetooth::shim::hci_on_reset_complete() {
    auto event_code = static_cast<bluetooth::hci::EventCode>(event_code_raw);
    auto event_code = static_cast<bluetooth::hci::EventCode>(event_code_raw);
    if (event_already_registered_in_hci_layer(event_code)) {
    if (event_already_registered_in_hci_layer(event_code)) {
      continue;
      continue;
    } else if (event_already_registered_in_le_advertising_manager(event_code)) {
      continue;
    }
    }
    auto handler = bluetooth::shim::GetGdShimHandler();
    auto handler = bluetooth::shim::GetGdShimHandler();
    bluetooth::shim::GetHciLayer()->RegisterEventHandler(
    bluetooth::shim::GetHciLayer()->RegisterEventHandler(
        event_code, handler->Bind(event_callback));
        event_code, handler->Bind(event_callback));
  }
  }

  hci_queue_end = bluetooth::shim::GetHciLayer()->GetAclQueueEnd();
  hci_queue_end = bluetooth::shim::GetHciLayer()->GetAclQueueEnd();

  // if gd advertising enabled, hci_queue_end will be register in
  // AclManager::impl::Start
  if (!bluetooth::shim::is_gd_advertising_enabled()) {
    hci_queue_end->RegisterDequeue(bluetooth::shim::GetGdShimHandler(),
    hci_queue_end->RegisterDequeue(bluetooth::shim::GetGdShimHandler(),
                                   bluetooth::common::Bind(acl_data_callback));
                                   bluetooth::common::Bind(acl_data_callback));
  }

  pending_data =
  pending_data =
      new bluetooth::os::EnqueueBuffer<bluetooth::hci::AclPacketBuilder>(
      new bluetooth::os::EnqueueBuffer<bluetooth::hci::AclPacketBuilder>(
          hci_queue_end);
          hci_queue_end);
@@ -432,7 +464,9 @@ void bluetooth::shim::hci_on_shutting_down() {
    pending_data = nullptr;
    pending_data = nullptr;
  }
  }
  if (hci_queue_end != nullptr) {
  if (hci_queue_end != nullptr) {
    if (!bluetooth::shim::is_gd_advertising_enabled()) {
      hci_queue_end->UnregisterDequeue();
      hci_queue_end->UnregisterDequeue();
    }
    for (uint8_t event_code_raw = 0; event_code_raw < 0xFF; event_code_raw++) {
    for (uint8_t event_code_raw = 0; event_code_raw < 0xFF; event_code_raw++) {
      if (!is_valid_event_code(event_code_raw)) {
      if (!is_valid_event_code(event_code_raw)) {
        continue;
        continue;
@@ -440,6 +474,9 @@ void bluetooth::shim::hci_on_shutting_down() {
      auto event_code = static_cast<bluetooth::hci::EventCode>(event_code_raw);
      auto event_code = static_cast<bluetooth::hci::EventCode>(event_code_raw);
      if (event_already_registered_in_hci_layer(event_code)) {
      if (event_already_registered_in_hci_layer(event_code)) {
        continue;
        continue;
      } else if (event_already_registered_in_le_advertising_manager(
                     event_code)) {
        continue;
      }
      }
      bluetooth::shim::GetHciLayer()->UnregisterEventHandler(event_code);
      bluetooth::shim::GetHciLayer()->UnregisterEventHandler(event_code);
    }
    }
Loading