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

Commit 6b1c4252 authored by Henri Chataing's avatar Henri Chataing
Browse files

system/gd/neighbor: Migrate to libbluetooth_log

Test: m com.android.btservices
Bug: 305066880
Flag: EXEMPT, mechanical refactor
Change-Id: I067483ae417e42c14c6d2f55973fed62398da9d5
parent 0780e65a
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@

#include "neighbor/discoverability.h"

#include <bluetooth/log.h>

#include <memory>

#include "common/bind.h"
@@ -85,7 +87,7 @@ void neighbor::DiscoverabilityModule::impl::OnCommandComplete(hci::CommandComple
      num_supported_iac_ = packet.GetNumSupportIac();
    } break;
    default:
      LOG_WARN("Unhandled command:%s", hci::OpCodeText(status.GetCommandOpCode()).c_str());
      log::warn("Unhandled command:{}", hci::OpCodeText(status.GetCommandOpCode()));
      break;
  }
}
@@ -121,14 +123,14 @@ void neighbor::DiscoverabilityModule::impl::Start() {

  hci_layer_->EnqueueCommand(
      hci::ReadNumberOfSupportedIacBuilder::Create(), handler_->BindOnceOn(this, &impl::OnCommandComplete));
  LOG_INFO("Started discoverability module");
  log::info("Started discoverability module");
}

void neighbor::DiscoverabilityModule::impl::Dump() const {
  LOG_INFO("Number of supported iacs:%hhd", num_supported_iac_);
  LOG_INFO("Number of current iacs:%zd", laps_.size());
  log::info("Number of supported iacs:{}", num_supported_iac_);
  log::info("Number of current iacs:{}", laps_.size());
  for (auto it : laps_) {
    LOG_INFO("  discoverability lap:%x", it.lap_);
    log::info("discoverability lap:{:x}", it.lap_);
  }
}

+9 −4
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

#include "neighbor/facade/facade.h"

#include <bluetooth/log.h>

#include <memory>

#include "blueberry/facade/neighbor/facade.grpc.pb.h"
@@ -78,7 +80,7 @@ class NeighborFacadeService : public NeighborFacade::Service {
        discoverability_module_->StartGeneralDiscoverability();
        break;
      default:
        LOG_ALWAYS_FATAL("Unknown discoverability mode %d", static_cast<int>(request->mode()));
        log::fatal("Unknown discoverability mode {}", static_cast<int>(request->mode()));
    }
    return ::grpc::Status::OK;
  }
@@ -99,7 +101,7 @@ class NeighborFacadeService : public NeighborFacade::Service {
        inquiry_module_->SetExtendedInquiryResultMode();
        break;
      default:
        LOG_ALWAYS_FATAL("Unknown result mode %d", static_cast<int>(request->result_mode()));
        log::fatal("Unknown result mode {}", static_cast<int>(request->result_mode()));
    }
    switch (request->inquiry_mode()) {
      case DiscoverabilityMode::OFF:
@@ -112,7 +114,7 @@ class NeighborFacadeService : public NeighborFacade::Service {
        inquiry_module_->StartGeneralInquiry(request->length_1_28s(), request->max_results());
        break;
      default:
        LOG_ALWAYS_FATAL("Unknown discoverability mode %d", static_cast<int>(request->inquiry_mode()));
        log::fatal("Unknown discoverability mode {}", static_cast<int>(request->inquiry_mode()));
    }
    return pending_events_.RunLoop(context, writer);
  }
@@ -135,7 +137,10 @@ class NeighborFacadeService : public NeighborFacade::Service {
        mode = hci::PageScanRepetitionMode::R2;
        break;
      default:
        LOG_ALWAYS_FATAL("Unknown PageScanRepetition mode %d", static_cast<int>(request->page_scan_repetition_mode()));
        log::fatal(
            "Unknown PageScanRepetition mode {}",
            static_cast<int>(request->page_scan_repetition_mode()));
        std::abort();
    }
    name_module_->StartRemoteNameRequest(
        remote,
+26 −23
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@

#include "neighbor/inquiry.h"

#include <bluetooth/log.h>

#include <memory>

#include "common/bind.h"
@@ -171,7 +173,7 @@ void neighbor::InquiryModule::impl::OnCommandComplete(hci::CommandCompleteView v
    } break;

    default:
      LOG_WARN("Unhandled command:%s", hci::OpCodeText(view.GetCommandOpCode()).c_str());
      log::warn("Unhandled command:{}", hci::OpCodeText(view.GetCommandOpCode()));
      break;
  }
}
@@ -184,12 +186,12 @@ void neighbor::InquiryModule::impl::OnCommandStatus(hci::CommandStatusView statu
      auto packet = hci::InquiryStatusView::Create(status);
      ASSERT(packet.IsValid());
      if (active_limited_one_shot_ || active_general_one_shot_) {
        LOG_INFO("Inquiry started lap: %s", active_limited_one_shot_ ? "Limited" : "General");
        log::info("Inquiry started lap: {}", active_limited_one_shot_ ? "Limited" : "General");
      }
    } break;

    default:
      LOG_WARN("Unhandled command:%s", hci::OpCodeText(status.GetCommandOpCode()).c_str());
      log::warn("Unhandled command:{}", hci::OpCodeText(status.GetCommandOpCode()));
      break;
  }
}
@@ -199,7 +201,7 @@ void neighbor::InquiryModule::impl::OnEvent(hci::EventView view) {
    case hci::EventCode::INQUIRY_COMPLETE: {
      auto packet = hci::InquiryCompleteView::Create(view);
      ASSERT(packet.IsValid());
      LOG_INFO("inquiry complete");
      log::info("inquiry complete");
      active_limited_one_shot_ = false;
      active_general_one_shot_ = false;
      inquiry_callbacks_.complete(packet.GetStatus());
@@ -208,32 +210,33 @@ void neighbor::InquiryModule::impl::OnEvent(hci::EventView view) {
    case hci::EventCode::INQUIRY_RESULT: {
      auto packet = hci::InquiryResultView::Create(view);
      ASSERT(packet.IsValid());
      LOG_INFO("Inquiry result size:%zd num_responses:%zu", packet.size(), packet.GetResponses().size());
      log::info(
          "Inquiry result size:{} num_responses:{}", packet.size(), packet.GetResponses().size());
      inquiry_callbacks_.result(packet);
    } break;

    case hci::EventCode::INQUIRY_RESULT_WITH_RSSI: {
      auto packet = hci::InquiryResultWithRssiView::Create(view);
      ASSERT(packet.IsValid());
      LOG_INFO("Inquiry result with rssi num_responses:%zu", packet.GetResponses().size());
      log::info("Inquiry result with rssi num_responses:{}", packet.GetResponses().size());
      inquiry_callbacks_.result_with_rssi(packet);
    } break;

    case hci::EventCode::EXTENDED_INQUIRY_RESULT: {
      auto packet = hci::ExtendedInquiryResultView::Create(view);
      ASSERT(packet.IsValid());
      LOG_INFO(
          "Extended inquiry result addr:%s repetition_mode:%s cod:%s clock_offset:%d rssi:%hhd",
      log::info(
          "Extended inquiry result addr:{} repetition_mode:{} cod:{} clock_offset:{} rssi:{}",
          ADDRESS_TO_LOGGABLE_CSTR(packet.GetAddress()),
          hci::PageScanRepetitionModeText(packet.GetPageScanRepetitionMode()).c_str(),
          packet.GetClassOfDevice().ToString().c_str(),
          hci::PageScanRepetitionModeText(packet.GetPageScanRepetitionMode()),
          packet.GetClassOfDevice().ToString(),
          packet.GetClockOffset(),
          packet.GetRssi());
      inquiry_callbacks_.extended_result(packet);
    } break;

    default:
      LOG_ERROR("Unhandled event:%s", hci::EventCodeText(view.GetEventCode()).c_str());
      log::error("Unhandled event:{}", hci::EventCodeText(view.GetEventCode()));
      break;
  }
}
@@ -343,30 +346,30 @@ void neighbor::InquiryModule::impl::Start() {
  EnqueueCommandComplete(hci::ReadInquiryScanTypeBuilder::Create());
  EnqueueCommandCompleteSync(hci::ReadInquiryModeBuilder::Create());

  LOG_INFO("Started inquiry module");
  log::info("Started inquiry module");
}

void neighbor::InquiryModule::impl::Stop() {
  LOG_INFO("Inquiry scan interval:%hu window:%hu", inquiry_scan_.interval, inquiry_scan_.window);
  LOG_INFO(
      "Inquiry mode:%s scan_type:%s",
      hci::InquiryModeText(inquiry_mode_).c_str(),
      hci::InquiryScanTypeText(inquiry_scan_type_).c_str());
  LOG_INFO("Inquiry response tx power:%hhd", inquiry_response_tx_power_);
  LOG_INFO("Stopped inquiry module");
  log::info("Inquiry scan interval:{} window:{}", inquiry_scan_.interval, inquiry_scan_.window);
  log::info(
      "Inquiry mode:{} scan_type:{}",
      hci::InquiryModeText(inquiry_mode_),
      hci::InquiryScanTypeText(inquiry_scan_type_));
  log::info("Inquiry response tx power:{}", inquiry_response_tx_power_);
  log::info("Stopped inquiry module");
}

void neighbor::InquiryModule::impl::SetInquiryMode(hci::InquiryMode mode) {
  EnqueueCommandComplete(hci::WriteInquiryModeBuilder::Create(mode));
  inquiry_mode_ = mode;
  LOG_INFO("Set inquiry mode:%s", hci::InquiryModeText(mode).c_str());
  log::info("Set inquiry mode:{}", hci::InquiryModeText(mode));
}

void neighbor::InquiryModule::impl::SetScanActivity(ScanParameters params) {
  EnqueueCommandComplete(hci::WriteInquiryScanActivityBuilder::Create(params.interval, params.window));
  inquiry_scan_ = params;
  LOG_INFO(
      "Set scan activity interval:0x%x/%.02fms window:0x%x/%.02fms",
  log::info(
      "Set scan activity interval:0x{:x}/{:.02f}ms window:0x{:x}/{:.02f}ms",
      params.interval,
      ScanIntervalTimeMs(params.interval),
      params.window,
@@ -375,7 +378,7 @@ void neighbor::InquiryModule::impl::SetScanActivity(ScanParameters params) {

void neighbor::InquiryModule::impl::SetScanType(hci::InquiryScanType scan_type) {
  EnqueueCommandComplete(hci::WriteInquiryScanTypeBuilder::Create(scan_type));
  LOG_INFO("Set scan type:%s", hci::InquiryScanTypeText(scan_type).c_str());
  log::info("Set scan type:{}", hci::InquiryScanTypeText(scan_type));
}

bool neighbor::InquiryModule::impl::HasCallbacks() const {
+4 −2
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@

#include "neighbor/name_db.h"

#include <bluetooth/log.h>

#include <memory>
#include <unordered_map>
#include <utility>
@@ -70,7 +72,7 @@ neighbor::NameDbModule::impl::impl(const neighbor::NameDbModule& module) : modul
void neighbor::NameDbModule::impl::ReadRemoteNameRequest(
    hci::Address address, ReadRemoteNameDbCallback callback, os::Handler* handler) {
  if (address_to_pending_read_map_.find(address) != address_to_pending_read_map_.end()) {
    LOG_WARN("Already have remote read db in progress; adding callback to callback list");
    log::warn("Already have remote read db in progress; adding callback to callback list");
    address_to_pending_read_map_[address].push_back({std::move(callback), handler});
    return;
  }
@@ -89,7 +91,7 @@ void neighbor::NameDbModule::impl::ReadRemoteNameRequest(
          address, page_scan_repetition_mode, clock_offset, clock_offset_valid),
      handler_->BindOnce([](hci::ErrorCode /* status */) {}),
      handler_->BindOnce([&](uint64_t /* features */) {
        LOG_WARN("UNIMPLEMENTED: ignoring host supported features");
        log::warn("UNIMPLEMENTED: ignoring host supported features");
      }),
      handler_->BindOnceOn(this, &NameDbModule::impl::OnRemoteNameResponse, address));
}
+9 −7
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@

#include "neighbor/page.h"

#include <bluetooth/log.h>

#include <memory>

#include "common/bind.h"
@@ -103,7 +105,7 @@ void neighbor::PageModule::impl::OnCommandComplete(hci::CommandCompleteView view
    } break;

    default:
      LOG_ERROR("Unhandled command %s", hci::OpCodeText(view.GetCommandOpCode()).c_str());
      log::error("Unhandled command {}", hci::OpCodeText(view.GetCommandOpCode()));
      break;
  }
}
@@ -123,8 +125,8 @@ void neighbor::PageModule::impl::Start() {
}

void neighbor::PageModule::impl::Stop() {
  LOG_INFO("Page scan interval:%hd window:%hd", scan_parameters_.interval, scan_parameters_.window);
  LOG_INFO("Page scan_type:%s", hci::PageScanTypeText(scan_type_).c_str());
  log::info("Page scan interval:{} window:{}", scan_parameters_.interval, scan_parameters_.window);
  log::info("Page scan_type:{}", hci::PageScanTypeText(scan_type_));
}

void neighbor::PageModule::impl::SetScanActivity(ScanParameters params) {
@@ -134,8 +136,8 @@ void neighbor::PageModule::impl::SetScanActivity(ScanParameters params) {

  hci_layer_->EnqueueCommand(
      hci::ReadPageScanActivityBuilder::Create(), handler_->BindOnceOn(this, &impl::OnCommandComplete));
  LOG_INFO(
      "Set page scan activity interval:0x%x/%.02fms window:0x%x/%.02fms",
  log::info(
      "Set page scan activity interval:0x{:x}/{:.02f}ms window:0x{:x}/{:.02f}ms",
      params.interval,
      ScanIntervalTimeMs(params.interval),
      params.window,
@@ -152,7 +154,7 @@ void neighbor::PageModule::impl::SetScanType(hci::PageScanType scan_type) {

  hci_layer_->EnqueueCommand(
      hci::ReadPageScanTypeBuilder::Create(), handler_->BindOnceOn(this, &impl::OnCommandComplete));
  LOG_INFO("Set page scan type:%s", hci::PageScanTypeText(scan_type).c_str());
  log::info("Set page scan type:{}", hci::PageScanTypeText(scan_type));
}

void neighbor::PageModule::impl::SetTimeout(PageTimeout timeout) {
@@ -161,7 +163,7 @@ void neighbor::PageModule::impl::SetTimeout(PageTimeout timeout) {

  hci_layer_->EnqueueCommand(
      hci::ReadPageTimeoutBuilder::Create(), handler_->BindOnceOn(this, &impl::OnCommandComplete));
  LOG_INFO("Set page scan timeout:0x%x/%.02fms", timeout, PageTimeoutMs(timeout));
  log::info("Set page scan timeout:0x{:x}/{:.02f}ms", timeout, PageTimeoutMs(timeout));
}

/**
Loading