From 71a82520296605c6ce9be4473b38f58b9c6ed445 Mon Sep 17 00:00:00 2001 From: SP2FET Date: Tue, 22 Dec 2020 12:18:07 +0100 Subject: [PATCH] [EGD-4580] Add BT settings middleware Added bluetooth settings middleware to store BT status in settings. Added middleware layer to handle new settings queries. --- changelog.md | 1 + image/user/db/settings_v2_001.sql | 43 --------- module-apps/CMakeLists.txt | 2 +- .../ApplicationSettings.cpp | 25 ++++- .../data/BondedDevicesData.hpp | 24 +++++ .../data/PhoneNameData.hpp | 22 +++++ .../windows/AllDevicesWindow.cpp | 25 +++-- .../windows/AllDevicesWindow.hpp | 13 +-- .../windows/BluetoothWindow.cpp | 4 +- .../windows/BluetoothWindow.hpp | 2 +- .../windows/PhoneNameWindow.cpp | 31 ++++++- .../windows/PhoneNameWindow.hpp | 10 +- .../Bluetooth/BluetoothWorker.cpp | 92 ++++++++++++++++--- .../Bluetooth/BluetoothWorker.hpp | 26 +++++- module-bluetooth/Bluetooth/BtCommand.hpp | 1 + module-bluetooth/Bluetooth/BtKeysStorage.cpp | 89 +++++++----------- module-bluetooth/Bluetooth/BtKeysStorage.hpp | 9 +- module-bluetooth/Bluetooth/BtstackWorker.cpp | 1 - .../Bluetooth/interface/profiles/GAP.cpp | 43 +++++---- .../service-bluetooth/CMakeLists.txt | 1 + .../service-bluetooth/ServiceBluetooth.cpp | 83 ++++++++++++----- .../service-bluetooth/BluetoothMessage.hpp | 2 +- .../service-bluetooth/ServiceBluetooth.hpp | 5 +- .../service-bluetooth/SettingsHolder.cpp | 26 ++++-- .../service-bluetooth/SettingsHolder.hpp | 44 ++++++++- .../service-bluetooth/SettingsSerializer.cpp | 47 ++++++++++ .../service-bluetooth/SettingsSerializer.hpp | 14 +++ .../agents/settings/SystemSettings.hpp | 1 + .../endpoints/calllog/CalllogHelper.cpp | 1 - module-utils/log/Logger.hpp | 1 + 30 files changed, 481 insertions(+), 207 deletions(-) delete mode 100644 image/user/db/settings_v2_001.sql create mode 100644 module-apps/application-settings-new/data/BondedDevicesData.hpp create mode 100644 module-apps/application-settings-new/data/PhoneNameData.hpp create mode 100644 module-services/service-bluetooth/service-bluetooth/SettingsSerializer.cpp create mode 100644 module-services/service-bluetooth/service-bluetooth/SettingsSerializer.hpp diff --git a/changelog.md b/changelog.md index 424de6d62e4f3cbbd8f339e518387082843b1385..237755b47d5d89854cd74793a008b75fce552c76 100644 --- a/changelog.md +++ b/changelog.md @@ -8,6 +8,7 @@ * Add PLL2 clock switching * Support for asynchronous callbacks on application side. * APN settings window - empty. +* Bluetooth settings middleware layer ### Changed diff --git a/image/user/db/settings_v2_001.sql b/image/user/db/settings_v2_001.sql deleted file mode 100644 index 9761e5309349ef351588c891b3b0d68b5ecc6dd0..0000000000000000000000000000000000000000 --- a/image/user/db/settings_v2_001.sql +++ /dev/null @@ -1,43 +0,0 @@ --- --- Main settings table, for string application persistent data --- -CREATE TABLE IF NOT EXISTS settings_tab ( - path TEXT NOT NULL UNIQUE PRIMARY KEY, - value TEXT -); - --- --- Dictionary table, for variables with fixed set of values --- -CREATE TABLE IF NOT EXISTS dictionary_tab ( - id INTEGER PRIMARY KEY, - path TEXT NOT NULL, - value TEXT, - CONSTRAINT dictionary_unique - UNIQUE (path, value) ON CONFLICT REPLACE - ); - --- --- Table contains information who to inform --- about changes in values. --- -CREATE TABLE IF NOT EXISTS notifications_tab ( - id INTEGER PRIMARY KEY, - path TEXT NOT NULL, - service TEXT, - CONSTRAINT notification_unique - UNIQUE(path, service) - ); - -CREATE TABLE IF NOT EXISTS settings_changed_tab( - - id INTEGER PRIMARY KEY, - path TEXT NOT NULL, - value TEXT, - CONSTRAINT changed_unique - UNIQUE(path ) ON CONFLICT REPLACE -); - -CREATE TRIGGER IF NOT EXISTS on_update UPDATE OF value ON settings_tab -WHEN new.value <> old.value BEGIN INSERT OR REPLACE INTO settings_changed_tab (path, value) VALUES (new.path,new.value); END; - diff --git a/module-apps/CMakeLists.txt b/module-apps/CMakeLists.txt index 2c515d72ee7b6e69f99fac6ea7e1b39143c5c5e5..4659ab21f649cc708dbf23d3d6d3eab4d1ac27f0 100644 --- a/module-apps/CMakeLists.txt +++ b/module-apps/CMakeLists.txt @@ -32,7 +32,7 @@ set( SOURCES "widgets/BrightnessBox.cpp" "widgets/ModesBox.cpp" "widgets/BarGraph.cpp" - ) +) add_library(${PROJECT_NAME} STATIC ${SOURCES} ${BOARD_SOURCES}) diff --git a/module-apps/application-settings-new/ApplicationSettings.cpp b/module-apps/application-settings-new/ApplicationSettings.cpp index d8989f6557dddc3a26519a8fb010aca6aaf19ff4..cc2e7b1caa1c1d2c70e1727371db0e09a0cbe988 100644 --- a/module-apps/application-settings-new/ApplicationSettings.cpp +++ b/module-apps/application-settings-new/ApplicationSettings.cpp @@ -33,7 +33,11 @@ #include #include #include +#include +#include +#include #include +#include namespace app { @@ -105,7 +109,7 @@ namespace app } } - return std::make_shared(); + return sys::MessageNone{}; } // Invoked during initialization @@ -118,6 +122,25 @@ namespace app return ret; } + connect(typeid(::message::bluetooth::ResponseDeviceName), [&](sys::Message *msg) { + auto responseDeviceNameMsg = static_cast<::message::bluetooth::ResponseDeviceName *>(msg); + if (gui::window::name::phone_name == getCurrentWindow()->getName()) { + auto phoneNameData = std::make_unique(responseDeviceNameMsg->getName()); + switchWindow(gui::window::name::phone_name, std::move(phoneNameData)); + } + return sys::MessageNone{}; + }); + + connect(typeid(::message::bluetooth::ResponseBondedDevices), [&](sys::Message *msg) { + auto responseBondedDevicesMsg = static_cast<::message::bluetooth::ResponseBondedDevices *>(msg); + if (gui::window::name::all_devices == getCurrentWindow()->getName()) { + auto bondedDevicesData = + std::make_unique(responseBondedDevicesMsg->getDevices()); + switchWindow(gui::window::name::all_devices, std::move(bondedDevicesData)); + } + return sys::MessageNone{}; + }); + createUserInterface(); setActiveWindow(gui::name::window::main_window); diff --git a/module-apps/application-settings-new/data/BondedDevicesData.hpp b/module-apps/application-settings-new/data/BondedDevicesData.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2a5b2eebad87460f012e9c3fadd2db75229c137c --- /dev/null +++ b/module-apps/application-settings-new/data/BondedDevicesData.hpp @@ -0,0 +1,24 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include + +namespace gui +{ + + class BondedDevicesData : public SwitchData + { + public: + explicit BondedDevicesData(std::vector devices) : devices(std::move(devices)) + {} + [[nodiscard]] auto getDevices() const noexcept -> const std::vector & + { + return devices; + } + + private: + const std::vector devices; + }; +} // namespace gui diff --git a/module-apps/application-settings-new/data/PhoneNameData.hpp b/module-apps/application-settings-new/data/PhoneNameData.hpp new file mode 100644 index 0000000000000000000000000000000000000000..021155715da844fa13954e30b6e04c632a8fc36c --- /dev/null +++ b/module-apps/application-settings-new/data/PhoneNameData.hpp @@ -0,0 +1,22 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once +#include +#include +namespace gui +{ + class PhoneNameData : public SwitchData + { + public: + explicit PhoneNameData(std::string name) : name(std::move(name)) + {} + [[nodiscard]] auto getName() const -> const std::string & + { + return name; + } + + private: + const std::string name; + }; +} // namespace gui diff --git a/module-apps/application-settings-new/windows/AllDevicesWindow.cpp b/module-apps/application-settings-new/windows/AllDevicesWindow.cpp index 0e45bb6ff5f1f4f77b7f3ca0d0b9ee5af698aaef..695ad2e404891417e8463f76e0b2a4b1cec26b90 100644 --- a/module-apps/application-settings-new/windows/AllDevicesWindow.cpp +++ b/module-apps/application-settings-new/windows/AllDevicesWindow.cpp @@ -8,18 +8,29 @@ #include "OptionSetting.hpp" #include "DialogMetadata.hpp" #include "DialogMetadataMessage.hpp" +#include #include #include #include - +#include +#include "application-settings-new/data/BondedDevicesData.hpp" namespace gui { AllDevicesWindow::AllDevicesWindow(app::Application *app) : OptionWindow(app, gui::window::name::all_devices) { setTitle(utils::localize.get("app_settings_bluetooth_all_devices")); - addOptions(allDevicesOptionsList()); + sys::Bus::SendUnicast( + std::make_shared<::message::bluetooth::RequestBondedDevices>(), service::name::bluetooth, application); + } + + void AllDevicesWindow::onBeforeShow(ShowMode mode, SwitchData *data) + { + clearOptions(); + if (const auto newData = dynamic_cast(data); newData != nullptr) { + addOptions(allDevicesOptionsList(newData->getDevices())); + } } auto AllDevicesWindow::onInput(const InputEvent &inputEvent) -> bool @@ -44,17 +55,11 @@ namespace gui return AppWindow::onInput(inputEvent); } - auto AllDevicesWindow::allDevicesOptionsList() -> std::list