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

Commit 3f44d654 authored by Arman Uguray's avatar Arman Uguray
Browse files

service: Implement IBluetooth.isMultiAdvertisementSupported()

Added the Binder bindings, bluetoothtbd implementation, and new
bluetooth-cli command for testing it.

Bug: 23227962
Change-Id: I2de62e49e5d8b0bcc118ccb654d72fdd9f11f748
parent 9dc532d7
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -27,6 +27,15 @@ const char Adapter::kDefaultAddress[] = "00:00:00:00:00:00";
// static
const char Adapter::kDefaultName[] = "not-initialized";

// The minimum number of advertising instances required for multi-advertisement
// support.
//
// TODO(armansito): This number comes straight from
// packages/apps/Bluetooth/src/c/a/b/btservice/AdapterService.java. It would be
// nice to know if there were a way to obtain this number from the stack instead
// of hardcoding it here.
const char kMinAdvInstancesForMultiAdv = 5;

void Adapter::Observer::OnAdapterStateChanged(Adapter* adapter,
                                              AdapterState prev_state,
                                              AdapterState new_state) {
@@ -37,6 +46,7 @@ Adapter::Adapter()
    : state_(ADAPTER_STATE_OFF),
      address_(kDefaultAddress),
      name_(kDefaultName) {
  memset(&local_le_features_, 0, sizeof(local_le_features_));
  hal::BluetoothInterface::Get()->AddObserver(this);
  hal::BluetoothInterface::Get()->GetHALInterface()->get_adapter_properties();
}
@@ -145,6 +155,10 @@ std::string Adapter::GetAddress() const {
  return address_.Get();
}

bool Adapter::IsMultiAdvertisementSupported() const {
  return local_le_features_.max_adv_instance >= kMinAdvInstancesForMultiAdv;
}

void Adapter::AdapterStateChangedCallback(bt_state_t state) {
  LOG(INFO) << "Adapter state changed: " << BtStateText(state);

@@ -193,6 +207,18 @@ void Adapter::AdapterPropertiesCallback(bt_status_t status,
        name_.Set(name);
        break;
      }
      case BT_PROPERTY_LOCAL_LE_FEATURES: {
        if (property->len != sizeof(bt_local_le_features_t)) {
          LOG(WARNING) << "Malformed value received for property: "
                       << "BT_PROPERTY_LOCAL_LE_FEATURES";
          break;
        }
        bt_local_le_features_t* features =
            reinterpret_cast<bt_local_le_features_t*>(property->val);
        memcpy(&local_le_features_, features, sizeof(*features));
        LOG(INFO) << "Supported LE features updated";
        break;
      }
      default:
        VLOG(1) << "Unhandled adapter property: "
                << BtPropertyText(property->type);
+9 −0
Original line number Diff line number Diff line
@@ -84,6 +84,10 @@ class Adapter : hal::BluetoothInterface::Observer {
  // Returns the local adapter addess in string form (XX:XX:XX:XX:XX:XX).
  std::string GetAddress() const;

  // Returns true if the local adapter supports the Low-Energy
  // multi-advertisement feature.
  bool IsMultiAdvertisementSupported() const;

 private:
  // hal::BluetoothInterface::Observer overrides.
  void AdapterStateChangedCallback(bt_state_t state) override;
@@ -108,6 +112,11 @@ class Adapter : hal::BluetoothInterface::Observer {
  // The current local adapter name.
  util::AtomicString name_;

  // The current set of supported LE features as obtained from the stack. The
  // values here are all initially set to 0 and updated when the corresponding
  // adapter property has been received from the stack.
  bt_local_le_features_t local_le_features_;

  // List of observers that are interested in notifications from us.
  std::mutex observers_lock_;
  base::ObserverList<Observer> observers_;
+11 −0
Original line number Diff line number Diff line
@@ -170,6 +170,15 @@ void HandleAdapterInfo(IBluetooth* bt_iface, const vector<string>& args) {
  PrintFieldAndValue("\tState", bluetooth::AdapterStateToString(
      static_cast<bluetooth::AdapterState>(bt_iface->GetState())));
  PrintFieldAndValue("\tName", bt_iface->GetName());
  PrintFieldAndBoolValue("\tMulti-Adv. supported",
                         bt_iface->IsMultiAdvertisementSupported());
}

void HandleSupportsMultiAdv(IBluetooth* bt_iface, const vector<string>& args) {
  CHECK_NO_ARGS(args);

  bool status = bt_iface->IsMultiAdvertisementSupported();
  PrintFieldAndBoolValue("Multi-advertisement support", status);
}

void HandleHelp(IBluetooth* bt_iface, const vector<string>& args);
@@ -189,6 +198,8 @@ struct {
  { "set-local-name", HandleSetLocalName, "\t\tSet the local adapter name" },
  { "get-local-name", HandleGetLocalName, "\t\tGet the local adapter name" },
  { "adapter-info", HandleAdapterInfo, "\t\tPrint adapter properties" },
  { "supports-multi-adv", HandleSupportsMultiAdv,
    "\tWhether multi-advertisement is currently supported" },
  {},
};

+10 −0
Original line number Diff line number Diff line
@@ -124,6 +124,16 @@ void FakeBluetoothInterface::NotifyAdapterAddressPropertyChanged(
  NotifyAdapterPropertiesChanged(1, &property);
}

void FakeBluetoothInterface::NotifyAdapterLocalLeFeaturesPropertyChanged(
      const bt_local_le_features_t* features) {
  bt_property_t property;
  property.len = sizeof(*features);
  property.val = (void*)features;
  property.type = BT_PROPERTY_LOCAL_LE_FEATURES;

  NotifyAdapterPropertiesChanged(1, &property);
}

void FakeBluetoothInterface::AddObserver(Observer* observer) {
  observers_.AddObserver(observer);
}
+2 −0
Original line number Diff line number Diff line
@@ -50,6 +50,8 @@ class FakeBluetoothInterface : public BluetoothInterface {
                                      bt_property_t* properties);
  void NotifyAdapterNamePropertyChanged(const std::string& name);
  void NotifyAdapterAddressPropertyChanged(const bt_bdaddr_t* address);
  void NotifyAdapterLocalLeFeaturesPropertyChanged(
      const bt_local_le_features_t* features);

  // hal::BluetoothInterface overrides:
  void AddObserver(Observer* observer) override;
Loading