M module-apps/application-settings-new/models/BluetoothSettingsModel.cpp => module-apps/application-settings-new/models/BluetoothSettingsModel.cpp +2 -0
@@ 86,4 86,6 @@ void BluetoothSettingsModel::requestConnection(std::string addr)
void BluetoothSettingsModel::requestDisconnection()
{
application->bus.sendUnicast(std::make_shared<message::bluetooth::Disconnect>(), service::name::bluetooth);
+ application->bus.sendUnicast(std::make_shared<::message::bluetooth::RequestBondedDevices>(),
+ service::name::bluetooth);
}
M module-apps/application-settings-new/windows/AllDevicesWindow.cpp => module-apps/application-settings-new/windows/AllDevicesWindow.cpp +8 -1
@@ 87,7 87,14 @@ namespace gui
device.name,
[=](gui::Item & /*item*/) {
LOG_DEBUG("Device: %s", device.name.c_str());
- bluetoothSettingsModel->requestConnection(addr);
+ if (isConnected) {
+ bluetoothSettingsModel->requestDisconnection();
+ refreshOptionsList();
+ }
+ else {
+ bluetoothSettingsModel->requestConnection(addr);
+ }
+
return true;
},
[=](gui::Item &item) {
M module-bluetooth/Bluetooth/CommandHandler.cpp => module-bluetooth/Bluetooth/CommandHandler.cpp +3 -0
@@ 116,6 116,8 @@ namespace bluetooth
{
profileManager->init();
LOG_INFO("Connecting audio with %s", bd_addr_to_str(addr));
+ std::string devAddr{bd_addr_to_str(addr)};
+ settings->setValue(bluetooth::Settings::ConnectedDevice, std::move(devAddr));
profileManager->connect(addr);
return Error::Success;
@@ 123,6 125,7 @@ namespace bluetooth
Error::Code CommandHandler::disconnectAudioConnection()
{
+ settings->setValue(bluetooth::Settings::ConnectedDevice, std::string());
profileManager->disconnect();
return Error::Success;
}
M module-bluetooth/Bluetooth/interface/profiles/A2DP/A2DP.cpp => module-bluetooth/Bluetooth/interface/profiles/A2DP/A2DP.cpp +12 -3
@@ 17,6 17,7 @@
#include <service-audio/AudioMessage.hpp>
#include <service-evtmgr/Constants.hpp>
#include <log/log.hpp>
+#include "service-bluetooth/messages/Connect.hpp"
extern "C"
{
#include "module-bluetooth/lib/btstack/src/btstack.h"
@@ 319,17 320,22 @@ namespace bluetooth
}
switch (hci_event_a2dp_meta_get_subevent_code(packet)) {
- case A2DP_SUBEVENT_SIGNALING_CONNECTION_ESTABLISHED:
+ case A2DP_SUBEVENT_SIGNALING_CONNECTION_ESTABLISHED: {
a2dp_subevent_signaling_connection_established_get_bd_addr(packet, address);
cid = a2dp_subevent_signaling_connection_established_get_a2dp_cid(packet);
status = a2dp_subevent_signaling_connection_established_get_status(packet);
-
+ std::string deviceAddress{bd_addr_to_str(address)};
if (status != ERROR_CODE_SUCCESS) {
LOG_INFO("A2DP Source: Connection failed, status 0x%02x, cid 0x%02x, a2dp_cid 0x%02x \n",
status,
cid,
AVRCP::mediaTracker.a2dp_cid);
AVRCP::mediaTracker.a2dp_cid = 0;
+
+ auto &busProxy = const_cast<sys::Service *>(ownerService)->bus;
+ busProxy.sendUnicast(
+ std::make_shared<message::bluetooth::ConnectResult>(std::move(deviceAddress), false),
+ "ApplicationSettingsNew");
break;
}
AVRCP::mediaTracker.a2dp_cid = cid;
@@ 340,8 346,11 @@ namespace bluetooth
AVRCP::mediaTracker.a2dp_cid,
AVRCP::mediaTracker.local_seid);
isConnected = true;
+ auto &busProxy = const_cast<sys::Service *>(ownerService)->bus;
+ busProxy.sendUnicast(std::make_shared<message::bluetooth::ConnectResult>(std::move(deviceAddress), true),
+ "ApplicationSettingsNew");
break;
-
+ }
case A2DP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CONFIGURATION: {
cid = avdtp_subevent_signaling_media_codec_sbc_configuration_get_avdtp_cid(packet);
if (cid != AVRCP::mediaTracker.a2dp_cid) {
M module-bluetooth/Bluetooth/interface/profiles/GAP/GAP.cpp => module-bluetooth/Bluetooth/interface/profiles/GAP/GAP.cpp +5 -2
@@ 15,6 15,7 @@ extern "C"
};
namespace bluetooth
{
+ std::string GAP::currentlyProcessedDeviceAddr;
sys::Service *GAP::ownerService = nullptr;
std::vector<Devicei> GAP::devices;
btstack_packet_callback_registration_t GAP::cb_handler;
@@ 60,6 61,7 @@ namespace bluetooth
auto GAP::pair(std::uint8_t *addr, std::uint8_t protectionLevel) -> bool
{
if (hci_get_state() == HCI_STATE_WORKING) {
+ currentlyProcessedDeviceAddr = bd_addr_to_str(addr);
return gap_dedicated_bonding(addr, protectionLevel) == 0;
}
return false;
@@ 196,10 198,11 @@ namespace bluetooth
}
void GAP::processDedicatedBondingCompleted(std::uint8_t *packet, bd_addr_t &addr)
{
- LOG_INFO("Pairing completed!");
auto result = packet[2];
auto name = std::string{reinterpret_cast<const char *>(&packet[9])};
- auto msg = std::make_shared<BluetoothPairResultMessage>(bd_addr_to_str(addr), name, result == 0u);
+ auto msg =
+ std::make_shared<BluetoothPairResultMessage>(currentlyProcessedDeviceAddr, std::move(name), result == 0u);
+ currentlyProcessedDeviceAddr.clear();
ownerService->bus.sendUnicast(std::move(msg), "ApplicationSettingsNew");
}
/* @text In ACTIVE, the following events are processed:
M module-bluetooth/Bluetooth/interface/profiles/GAP/GAP.hpp => module-bluetooth/Bluetooth/interface/profiles/GAP/GAP.hpp +1 -0
@@ 52,6 52,7 @@ namespace bluetooth
auto pair(uint8_t *addr, std::uint8_t protectionLevel = 0) -> bool;
auto unpair(uint8_t *addr) -> bool;
static auto getDevicesList() -> const std::vector<Devicei> &;
+ static std::string currentlyProcessedDeviceAddr;
explicit GAP(sys::Service *owner);
};
} // namespace bluetooth
M module-services/service-bluetooth/ServiceBluetooth.cpp => module-services/service-bluetooth/ServiceBluetooth.cpp +3 -1
@@ 61,9 61,11 @@ sys::ReturnCodes ServiceBluetooth::InitHandler()
LOG_INFO("Requested bonded devices!");
auto bondedDevicesStr =
std::visit(bluetooth::StringVisitor(), this->settingsHolder->getValue(bluetooth::Settings::BondedDevices));
+ auto connectedAddress = std::visit(bluetooth::StringVisitor(),
+ this->settingsHolder->getValue(bluetooth::Settings::ConnectedDevice));
return std::make_shared<message::bluetooth::ResponseBondedDevices>(
- SettingsSerializer::fromString(bondedDevicesStr), std::string());
+ SettingsSerializer::fromString(bondedDevicesStr), std::move(connectedAddress));
});
connect(message::bluetooth::RequestStatus(), [&](sys::Message *msg) {
M module-services/service-bluetooth/service-bluetooth/SettingsHolder.cpp => module-services/service-bluetooth/service-bluetooth/SettingsHolder.cpp +2 -0
@@ 10,6 10,8 @@ namespace bluetooth
{Settings::State, settings::Bluetooth::state},
{Settings::BondedDevices, settings::Bluetooth::bondedDevices},
{Settings::BtKeys, settings::Bluetooth::btKeys},
+ {Settings::ConnectedDevice, settings::Bluetooth::connectedDevice},
+
};
auto SettingsHolder::getValue(const Settings setting) -> SettingEntry
M module-services/service-bluetooth/service-bluetooth/SettingsHolder.hpp => module-services/service-bluetooth/service-bluetooth/SettingsHolder.hpp +2 -1
@@ 18,7 18,8 @@ namespace bluetooth
Visibility,
State,
BondedDevices,
- BtKeys
+ BtKeys,
+ ConnectedDevice
};
constexpr inline auto trueStr = "true";
M module-services/service-db/agents/settings/SystemSettings.hpp => module-services/service-db/agents/settings/SystemSettings.hpp +1 -0
@@ 29,6 29,7 @@ namespace settings
constexpr inline auto deviceName = "bt_device_name";
constexpr inline auto bondedDevices = "bt_bonded_devices";
constexpr inline auto btKeys = "bt_keys";
+ constexpr inline auto connectedDevice = "connected_device";
} // namespace Bluetooth
namespace Brightness
{