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

Commit 338d2de7 authored by David Duarte's avatar David Duarte Committed by Automerger Merge Worker
Browse files

Merge "RootCanal: Handle args in DeviceBoutique instead of the Device" am: 2e417030

parents 8cd77043 2e417030
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ namespace V1_1 {
namespace sim {

using android::hardware::hidl_vec;
using ::bluetooth::hci::Address;
using rootcanal::AsyncTaskId;
using rootcanal::DualModeController;
using rootcanal::HciDevice;
@@ -109,7 +110,12 @@ Return<void> BluetoothHci::initialize_impl(
  char mac_property[PROPERTY_VALUE_MAX] = "";
  property_get("vendor.bt.rootcanal_mac_address", mac_property,
               "3C:5A:B4:01:02:03");
  controller_->Initialize({"dmc", std::string(mac_property)});
  auto addr = Address::FromString(std::string(mac_property));
  if (addr) {
    controller_->SetAddress(*addr);
  } else {
    LOG_ALWAYS_FATAL("Invalid address: %s", mac_property);
  }

  controller_->RegisterEventChannel(
      [this, cb](std::shared_ptr<std::vector<uint8_t>> packet) {
+0 −11
Original line number Diff line number Diff line
@@ -38,17 +38,6 @@ constexpr uint16_t kLeMaximumDataLength = 64;
constexpr uint16_t kLeMaximumDataTime = 0x148;

// Device methods.
void DualModeController::Initialize(const std::vector<std::string>& args) {
  if (args.size() < 2) return;

  Address addr{};
  if (Address::FromString(args[1], addr)) {
    properties_.SetAddress(addr);
  } else {
    LOG_ALWAYS_FATAL("Invalid address: %s", args[1].c_str());
  }
};

std::string DualModeController::GetTypeString() const {
  return "Simulated Bluetooth Controller";
}
+0 −2
Original line number Diff line number Diff line
@@ -62,8 +62,6 @@ class DualModeController : public Device {
  ~DualModeController() = default;

  // Device methods.
  virtual void Initialize(const std::vector<std::string>& args) override;

  virtual std::string GetTypeString() const override;

  virtual void IncomingPacket(
+11 −11
Original line number Diff line number Diff line
@@ -40,6 +40,17 @@ Beacon::Beacon() {
                                 'c'});
}

Beacon::Beacon(const vector<std::string>& args) : Beacon() {
  if (args.size() >= 2) {
    Address addr{};
    if (Address::FromString(args[1], addr)) properties_.SetLeAddress(addr);
  }

  if (args.size() >= 3) {
    SetAdvertisementInterval(std::chrono::milliseconds(std::stoi(args[2])));
  }
}

std::string Beacon::GetTypeString() const { return "beacon"; }

std::string Beacon::ToString() const {
@@ -49,17 +60,6 @@ std::string Beacon::ToString() const {
  return dev;
}

void Beacon::Initialize(const vector<std::string>& args) {
  if (args.size() < 2) return;

  Address addr{};
  if (Address::FromString(args[1], addr)) properties_.SetLeAddress(addr);

  if (args.size() < 3) return;

  SetAdvertisementInterval(std::chrono::milliseconds(std::stoi(args[2])));
}

void Beacon::TimerTick() {
  if (IsAdvertisementAvailable()) {
    last_advertisement_ = std::chrono::steady_clock::now();
+4 −4
Original line number Diff line number Diff line
@@ -27,9 +27,12 @@ namespace rootcanal {
class Beacon : public Device {
 public:
  Beacon();
  Beacon(const std::vector<std::string>& args);
  virtual ~Beacon() = default;

  static std::shared_ptr<Device> Create() { return std::make_shared<Beacon>(); }
  static std::shared_ptr<Device> Create(const std::vector<std::string>& args) {
    return std::make_shared<Beacon>(args);
  }

  // Return a string representation of the type of device.
  virtual std::string GetTypeString() const override;
@@ -37,9 +40,6 @@ class Beacon : public Device {
  // Return a string representation of the device.
  virtual std::string ToString() const override;

  // Set the address and advertising interval from string args.
  virtual void Initialize(const std::vector<std::string>& args) override;

  virtual void IncomingPacket(
      model::packets::LinkLayerPacketView packet) override;

Loading