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

Commit 974bb999 authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

Get rid of Advertising shim

Bug: 149757450
Change-Id: I1f27fffa5aca3bed420c9bfe4e1bb404460f3ffc
parent 2810e77e
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@
#include "hci/facade/le_acl_manager_facade.h"
#include "hci/facade/le_advertising_manager_facade.h"
#include "hci/facade/le_scanning_manager_facade.h"
#include "hci/le_advertising_manager.h"
#include "hci/le_scanning_manager.h"
#include "l2cap/classic/facade.h"
#include "neighbor/connectability.h"
@@ -40,7 +41,6 @@
#include "os/thread.h"
#include "security/facade.h"
#include "security/security_module.h"
#include "shim/advertising.h"
#include "shim/dumpsys.h"
#include "shim/hci_layer.h"
#include "shim/l2cap.h"
@@ -105,7 +105,6 @@ class RootFacadeService : public ::bluetooth::facade::RootFacade::Service {
        modules.add<::bluetooth::hci::facade::LeScanningManagerFacadeModule>();
        break;
      case BluetoothModule::SHIM:
        modules.add<::bluetooth::shim::Advertising>();
        modules.add<::bluetooth::neighbor::ConnectabilityModule>();
        modules.add<::bluetooth::neighbor::DiscoverabilityModule>();
        modules.add<::bluetooth::neighbor::InquiryModule>();
@@ -114,6 +113,7 @@ class RootFacadeService : public ::bluetooth::facade::RootFacade::Service {
        modules.add<::bluetooth::shim::HciLayer>();
        modules.add<::bluetooth::shim::L2cap>();
        modules.add<::bluetooth::neighbor::PageModule>();
        modules.add<::bluetooth::hci::LeAdvertisingManager>();
        modules.add<::bluetooth::hci::LeScanningManager>();
        modules.add<::bluetooth::security::SecurityModule>();
        modules.add<::bluetooth::storage::LegacyModule>();
+0 −1
Original line number Diff line number Diff line
filegroup {
    name: "BluetoothShimSources",
    srcs: [
            "advertising.cc",
            "dumpsys.cc",
            "hci_layer.cc",
            "l2cap.cc",

system/gd/shim/advertising.cc

deleted100644 → 0
+0 −134
Original line number Diff line number Diff line
/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#define LOG_TAG "bt_gd_shim"

#include <functional>
#include <memory>
#include <string>

#include "hci/address.h"
#include "hci/hci_packets.h"
#include "hci/le_advertising_manager.h"
#include "module.h"
#include "os/handler.h"
#include "os/log.h"
#include "shim/advertising.h"

namespace bluetooth {
namespace shim {

namespace {
constexpr char kModuleName[] = "shim::Advertising";
}  // namespace

struct Advertising::impl {
  impl(hci::LeAdvertisingManager* module, os::Handler* handler);
  ~impl();

  void StartAdvertising();
  void StopAdvertising();

  size_t GetNumberOfAdvertisingInstances() const;

 private:
  void OnScan(hci::Address address, hci::AddressType address_type);
  void OnTerminated(hci::ErrorCode code, uint8_t handle, uint8_t num_events);

  hci::AdvertiserId advertiser_id_{hci::LeAdvertisingManager::kInvalidId};

  hci::LeAdvertisingManager* advertising_manager_{nullptr};
  os::Handler* handler_;
};

const ModuleFactory Advertising::Factory = ModuleFactory([]() { return new Advertising(); });

Advertising::impl::impl(hci::LeAdvertisingManager* advertising_manager, os::Handler* handler)
    : advertising_manager_(advertising_manager), handler_(handler) {}

Advertising::impl::~impl() {}

void Advertising::impl::StartAdvertising() {
  if (advertiser_id_ == hci::LeAdvertisingManager::kInvalidId) {
    LOG_WARN("%s Already advertising; please stop prior to starting again", __func__);
    return;
  }

  hci::AdvertisingConfig config;
  advertiser_id_ =
      advertising_manager_->CreateAdvertiser(config, common::Bind(&impl::OnScan, common::Unretained(this)),
                                             common::Bind(&impl::OnTerminated, common::Unretained(this)), handler_);
  if (advertiser_id_ == hci::LeAdvertisingManager::kInvalidId) {
    LOG_WARN("%s Unable to start advertising", __func__);
    return;
  }
  LOG_DEBUG("%s Started advertising", __func__);
}

void Advertising::impl::StopAdvertising() {
  if (advertiser_id_ == hci::LeAdvertisingManager::kInvalidId) {
    LOG_WARN("%s No active advertising", __func__);
    return;
  }
  advertising_manager_->RemoveAdvertiser(advertiser_id_);
  advertiser_id_ = hci::LeAdvertisingManager::kInvalidId;
  LOG_DEBUG("%s Stopped advertising", __func__);
}

void Advertising::impl::OnScan(hci::Address address, hci::AddressType address_type) {
  LOG_INFO("%s UNIMPLEMENTED Received le advert from:%s", __func__, address.ToString().c_str());
}

void Advertising::impl::OnTerminated(hci::ErrorCode code, uint8_t handle, uint8_t num_events) {
  LOG_INFO("%s UNIMPLEMENTED", __func__);
}

size_t Advertising::impl::GetNumberOfAdvertisingInstances() const {
  return advertising_manager_->GetNumberOfAdvertisingInstances();
}

size_t Advertising::GetNumberOfAdvertisingInstances() const {
  return pimpl_->GetNumberOfAdvertisingInstances();
}

void Advertising::StartAdvertising() {
  pimpl_->StartAdvertising();
}

void Advertising::StopAdvertising() {
  pimpl_->StopAdvertising();
}

/**
 * Module methods
 */
void Advertising::ListDependencies(ModuleList* list) {
  list->add<hci::LeAdvertisingManager>();
}

void Advertising::Start() {
  pimpl_ = std::make_unique<impl>(GetDependency<hci::LeAdvertisingManager>(), GetHandler());
}

void Advertising::Stop() {
  pimpl_.reset();
}

std::string Advertising::ToString() const {
  return kModuleName;
}

}  // namespace shim
}  // namespace bluetooth

system/gd/shim/advertising.h

deleted100644 → 0
+0 −51
Original line number Diff line number Diff line
/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#pragma once

#include <memory>
#include <string>

#include "module.h"

namespace bluetooth {
namespace shim {

class Advertising : public bluetooth::Module {
 public:
  Advertising() = default;
  ~Advertising() = default;

  void StartAdvertising();
  void StopAdvertising();

  size_t GetNumberOfAdvertisingInstances() const;

  static const ModuleFactory Factory;

 protected:
  void ListDependencies(ModuleList* list) override;  // Module
  void Start() override;                             // Module
  void Stop() override;                              // Module
  std::string ToString() const override;             // Module

 private:
  struct impl;
  std::unique_ptr<impl> pimpl_;
  DISALLOW_COPY_AND_ASSIGN(Advertising);
};

}  // namespace shim
}  // namespace bluetooth
+0 −1
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@
 */
namespace bluetooth {
namespace shim {
class Advertising;
class Dumpsys;
class HciLayer;
class L2cap;
Loading