Loading system/service/adapter.cpp +26 −0 Original line number Diff line number Diff line Loading @@ -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) { Loading @@ -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(); } Loading Loading @@ -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); Loading Loading @@ -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); Loading system/service/adapter.h +9 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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_; Loading system/service/client/main.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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" }, {}, }; Loading system/service/hal/fake_bluetooth_interface.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -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); } Loading system/service/hal/fake_bluetooth_interface.h +2 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
system/service/adapter.cpp +26 −0 Original line number Diff line number Diff line Loading @@ -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) { Loading @@ -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(); } Loading Loading @@ -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); Loading Loading @@ -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); Loading
system/service/adapter.h +9 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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_; Loading
system/service/client/main.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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" }, {}, }; Loading
system/service/hal/fake_bluetooth_interface.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -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); } Loading
system/service/hal/fake_bluetooth_interface.h +2 −0 Original line number Diff line number Diff line Loading @@ -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