From e676068f626c410147be9be2e44c41e3fd0dc318 Mon Sep 17 00:00:00 2001 From: Pawel Olejniczak Date: Fri, 26 Feb 2021 18:29:52 +0100 Subject: [PATCH] [EGD-5912] Add forget bluetooth device feature Added button on AllDevices window, and handling for it. Added needed messages for communication with service bluetooth. Feature is now complete on application settings side. Further integration in service bluetooth is needed. --- image/assets/lang/English.json | 2 + .../ApplicationSettings.cpp | 23 ++++++++++ .../models/BluetoothSettingsModel.cpp | 9 +++- .../models/BluetoothSettingsModel.hpp | 3 +- .../windows/AddDeviceWindow.cpp | 2 +- .../windows/AllDevicesWindow.cpp | 19 ++++++++- .../windows/AllDevicesWindow.hpp | 1 + .../messages/BondedDevices.hpp | 2 +- .../service-bluetooth/messages/Connect.hpp | 6 +-- .../service-bluetooth/messages/DeviceName.hpp | 2 +- .../service-bluetooth/messages/Passkey.hpp | 2 +- .../messages/ResponseVisibleDevices.hpp | 2 +- .../messages/SetBondedDevices.hpp | 2 +- .../messages/SetDeviceName.hpp | 2 +- .../service-bluetooth/messages/Unpair.hpp | 42 +++++++++++++++++++ 15 files changed, 106 insertions(+), 13 deletions(-) create mode 100644 module-services/service-bluetooth/service-bluetooth/messages/Unpair.hpp diff --git a/image/assets/lang/English.json b/image/assets/lang/English.json index c6217eed6b35f7f2f5accbafcb18b269c91c9301..50f9e2035af7585fed91be215b845b1ed6b2c957 100644 --- a/image/assets/lang/English.json +++ b/image/assets/lang/English.json @@ -27,6 +27,7 @@ "common_abort": "ABORT", "common_connect": "CONNECT", "common_disconnect": "DISCONNECT", + "common_forget": "FORGET", "common_mo": "MO", "common_tu": "TU", "common_we": "WE", @@ -325,6 +326,7 @@ "app_settings_bluetooth_enter_passkey": "Enter passkey:", "app_settings_bluetooth_init_error_message": "Bluetooth initialization process \nhas failed. TRY AGAIN.", "app_settings_bluetooth_pairing_error_message": "Pairing process with %NAME\nhas failed. Check the device\nand TRY AGAIN.", + "app_settings_bluetooth_unpairing_error_message": "Unpairing process has failed.\nCheck the device and TRY AGAIN.", "app_settings_bluetooth_connecting_error_message": "Connection process has failed.\nCheck the device and TRY AGAIN.", "app_settings_net": "Network", "app_settings_disp_key": "Display and keypad", diff --git a/module-apps/application-settings-new/ApplicationSettings.cpp b/module-apps/application-settings-new/ApplicationSettings.cpp index 6c2fb806f12151c69830cf728286a56ac85037b6..816ed7460b1dbb211ba76e04ead5b522160a1aa0 100644 --- a/module-apps/application-settings-new/ApplicationSettings.cpp +++ b/module-apps/application-settings-new/ApplicationSettings.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -205,6 +206,28 @@ namespace app return sys::MessageNone{}; }); + connect(typeid(::message::bluetooth::UnpairResult), [&](sys::Message *msg) { + auto unpairResultMsg = static_cast<::message::bluetooth::UnpairResult *>(msg); + if (unpairResultMsg->isSucceed()) { + return sys::MessageNone{}; + } + bus.sendUnicast(std::make_shared<::message::bluetooth::RequestBondedDevices>(), service::name::bluetooth); + switchWindow(gui::window::name::dialog_retry, + gui::ShowMode::GUI_SHOW_INIT, + std::make_unique( + gui::DialogMetadata{utils::localize.get("app_settings_bt"), + "search_big", + utils::localize.get("app_settings_bluetooth_unpairing_error_message"), + "", + [=]() -> bool { + bus.sendUnicast(std::make_shared( + unpairResultMsg->getAddr()), + service::name::bluetooth); + return true; + }})); + return sys::MessageNone{}; + }); + connect(typeid(::message::bluetooth::ConnectResult), [&](sys::Message *msg) { auto connectResultMsg = static_cast<::message::bluetooth::ConnectResult *>(msg); if (connectResultMsg->isSucceed()) { diff --git a/module-apps/application-settings-new/models/BluetoothSettingsModel.cpp b/module-apps/application-settings-new/models/BluetoothSettingsModel.cpp index 8f56b1f98ba6f35919fa2520ba7a0d52a1b73d84..44b7ef765fd264379d642da87f97a9dd081d3e53 100644 --- a/module-apps/application-settings-new/models/BluetoothSettingsModel.cpp +++ b/module-apps/application-settings-new/models/BluetoothSettingsModel.cpp @@ -12,6 +12,7 @@ #include #include #include +#include BluetoothSettingsModel::BluetoothSettingsModel(app::Application *application) : application{application} {} @@ -59,11 +60,17 @@ void BluetoothSettingsModel::stopScan() service::name::bluetooth); } -void BluetoothSettingsModel::requestDevicePairing(std::string addr) +void BluetoothSettingsModel::requestDevicePair(std::string addr) { application->bus.sendUnicast(std::make_shared(std::move(addr)), service::name::bluetooth); } +void BluetoothSettingsModel::requestDeviceUnpair(std::string addr) +{ + application->bus.sendUnicast(std::make_shared(std::move(addr)), + service::name::bluetooth); +} + void BluetoothSettingsModel::responsePasskey(std::string passkey) { application->bus.sendUnicast(std::make_shared(std::move(passkey)), diff --git a/module-apps/application-settings-new/models/BluetoothSettingsModel.hpp b/module-apps/application-settings-new/models/BluetoothSettingsModel.hpp index dedcdc55b96486dd7e0cfe0d2145f917c774378e..bb6148175bde68e8e5e4c5c0997cbd78bf738d76 100644 --- a/module-apps/application-settings-new/models/BluetoothSettingsModel.hpp +++ b/module-apps/application-settings-new/models/BluetoothSettingsModel.hpp @@ -22,7 +22,8 @@ class BluetoothSettingsModel void requestBondedDevices(); void requestScan(); void stopScan(); - void requestDevicePairing(std::string addr); + void requestDevicePair(std::string addr); + void requestDeviceUnpair(std::string addr); void responsePasskey(std::string passkey); void requestConnection(std::string addr); void requestDisconnection(); diff --git a/module-apps/application-settings-new/windows/AddDeviceWindow.cpp b/module-apps/application-settings-new/windows/AddDeviceWindow.cpp index 81fce1482c0eea98b4579b7c7765b7b5a6c47cc0..097a0ccb6ec4da505a4c893037af7c6bbf186149 100644 --- a/module-apps/application-settings-new/windows/AddDeviceWindow.cpp +++ b/module-apps/application-settings-new/windows/AddDeviceWindow.cpp @@ -43,7 +43,7 @@ namespace gui device.name, [=](gui::Item & /*unused*/) { LOG_DEBUG("Device: %s", device.name.c_str()); - bluetoothSettingsModel->requestDevicePairing(bd_addr_to_str(device.address)); + bluetoothSettingsModel->requestDevicePair(bd_addr_to_str(device.address)); application->switchWindow(gui::window::name::all_devices); return true; }, diff --git a/module-apps/application-settings-new/windows/AllDevicesWindow.cpp b/module-apps/application-settings-new/windows/AllDevicesWindow.cpp index 12b4aaab922e73d523fb4c880f701d4fee283623..00b7f632ac4b6dd4357fd9c84cbb5300c6e27f7c 100644 --- a/module-apps/application-settings-new/windows/AllDevicesWindow.cpp +++ b/module-apps/application-settings-new/windows/AllDevicesWindow.cpp @@ -50,7 +50,10 @@ namespace gui auto AllDevicesWindow::onInput(const InputEvent &inputEvent) -> bool { - if (inputEvent.isShortPress() && inputEvent.is(KeyCode::KEY_LEFT)) { + if (!inputEvent.isShortPress()) { + return AppWindow::onInput(inputEvent); + } + if (inputEvent.is(KeyCode::KEY_LEFT)) { bluetoothSettingsModel->requestScan(); application->switchWindow(gui::window::name::dialog_settings, gui::ShowMode::GUI_SHOW_INIT, @@ -60,6 +63,17 @@ namespace gui utils::localize.get("app_settings_bluetooth_searching_devices")})); return true; } + if (inputEvent.is(KeyCode::KEY_LF)) { + devices.erase(std::remove_if(devices.begin(), + devices.end(), + [&](const auto &device) { + return (bd_addr_to_str(device.address) == addressOfSelectedDevice); + }), + devices.end()); + refreshOptionsList(); + bluetoothSettingsModel->requestDeviceUnpair(addressOfSelectedDevice); + return true; + } return AppWindow::onInput(inputEvent); } @@ -81,6 +95,9 @@ namespace gui this->setBottomBarText(isConnected ? utils::translateI18("common_disconnect") : utils::translateI18("common_connect"), BottomBar::Side::CENTER); + this->setBottomBarText(utils::translateI18("common_forget"), BottomBar::Side::LEFT); + this->bottomBar->setActive(BottomBar::Side::LEFT, true); + addressOfSelectedDevice = addr; } return true; }, diff --git a/module-apps/application-settings-new/windows/AllDevicesWindow.hpp b/module-apps/application-settings-new/windows/AllDevicesWindow.hpp index 7ee5196fb4733f6f9e2d9b33bc0d5893125f5a63..9196c0be8e89c437df8e5d21a32ecf082a2034c6 100644 --- a/module-apps/application-settings-new/windows/AllDevicesWindow.hpp +++ b/module-apps/application-settings-new/windows/AllDevicesWindow.hpp @@ -24,6 +24,7 @@ namespace gui Image *crossImage = nullptr; std::vector devices; std::string addressOfConnectedDevice; + std::string addressOfSelectedDevice; std::unique_ptr bluetoothSettingsModel; }; diff --git a/module-services/service-bluetooth/service-bluetooth/messages/BondedDevices.hpp b/module-services/service-bluetooth/service-bluetooth/messages/BondedDevices.hpp index e138c93005c575ec9dd52569c5cd72edc08d5960..c1436f231effcc1b3bf995b3a22b8e41313a4b93 100644 --- a/module-services/service-bluetooth/service-bluetooth/messages/BondedDevices.hpp +++ b/module-services/service-bluetooth/service-bluetooth/messages/BondedDevices.hpp @@ -16,7 +16,7 @@ namespace message::bluetooth explicit ResponseBondedDevices(std::vector devices, std::string addressOfConnectedDevice) : devices(std::move(devices)), addressOfConnectedDevice(std::move(addressOfConnectedDevice)) {} - [[nodiscard]] auto getDevices() const -> std::vector + [[nodiscard]] auto getDevices() const noexcept -> std::vector { return devices; } diff --git a/module-services/service-bluetooth/service-bluetooth/messages/Connect.hpp b/module-services/service-bluetooth/service-bluetooth/messages/Connect.hpp index 46fdeaceaa8fa94f5eab124396602ca78cdaf8e7..3c65a34d9ce64d8125dda27db35b0d4275d67ddf 100644 --- a/module-services/service-bluetooth/service-bluetooth/messages/Connect.hpp +++ b/module-services/service-bluetooth/service-bluetooth/messages/Connect.hpp @@ -12,7 +12,7 @@ namespace message::bluetooth public: explicit Connect(std::string addr) : addr(std::move(addr)) {} - [[nodiscard]] auto getAddr() const -> std::string + [[nodiscard]] auto getAddr() const noexcept -> std::string { return addr; } @@ -26,11 +26,11 @@ namespace message::bluetooth public: explicit ConnectResult(std::string addr, bool succeed) : addr(std::move(addr)), succeed(succeed) {} - [[nodiscard]] auto getAddr() const -> std::string + [[nodiscard]] auto getAddr() const noexcept -> std::string { return addr; } - [[nodiscard]] auto isSucceed() const -> bool + [[nodiscard]] auto isSucceed() const noexcept -> bool { return succeed; } diff --git a/module-services/service-bluetooth/service-bluetooth/messages/DeviceName.hpp b/module-services/service-bluetooth/service-bluetooth/messages/DeviceName.hpp index 8ad03e778423cccef2e35e1647da94372eb607c9..6632af7c1894047f1aedce9c02bfcbcc077cb9c9 100644 --- a/module-services/service-bluetooth/service-bluetooth/messages/DeviceName.hpp +++ b/module-services/service-bluetooth/service-bluetooth/messages/DeviceName.hpp @@ -15,7 +15,7 @@ namespace message::bluetooth public: explicit ResponseDeviceName(std::string name) : name(std::move(name)) {} - [[nodiscard]] auto getName() const -> std::string + [[nodiscard]] auto getName() const noexcept -> std::string { return name; } diff --git a/module-services/service-bluetooth/service-bluetooth/messages/Passkey.hpp b/module-services/service-bluetooth/service-bluetooth/messages/Passkey.hpp index 0e59569a2795e1d9ac2bd9ff1e54d9f55b4967a1..1b8691e5d83965374cfe053ecde2885274fd2ac6 100644 --- a/module-services/service-bluetooth/service-bluetooth/messages/Passkey.hpp +++ b/module-services/service-bluetooth/service-bluetooth/messages/Passkey.hpp @@ -15,7 +15,7 @@ namespace message::bluetooth public: explicit ResponsePasskey(std::string passkey) : passkey(std::move(passkey)) {} - [[nodiscard]] auto getPasskey() const -> std::string + [[nodiscard]] auto getPasskey() const noexcept -> std::string { return passkey; } diff --git a/module-services/service-bluetooth/service-bluetooth/messages/ResponseVisibleDevices.hpp b/module-services/service-bluetooth/service-bluetooth/messages/ResponseVisibleDevices.hpp index e4e40fd76aef502a48c3cf4fd85b54c752003ea8..bc9304f697acfb31e3cd396610817ab89edd39f5 100644 --- a/module-services/service-bluetooth/service-bluetooth/messages/ResponseVisibleDevices.hpp +++ b/module-services/service-bluetooth/service-bluetooth/messages/ResponseVisibleDevices.hpp @@ -12,7 +12,7 @@ namespace message::bluetooth public: explicit ResponseVisibleDevices(std::vector devices) : devices(std::move(devices)) {} - [[nodiscard]] auto getDevices() const -> std::vector + [[nodiscard]] auto getDevices() const noexcept -> std::vector { return devices; } diff --git a/module-services/service-bluetooth/service-bluetooth/messages/SetBondedDevices.hpp b/module-services/service-bluetooth/service-bluetooth/messages/SetBondedDevices.hpp index 41fec0544983fa84541415ed2978eecb5022b7fc..4278a795d701aaa3d9d73a4b7d4d9e66b941408d 100644 --- a/module-services/service-bluetooth/service-bluetooth/messages/SetBondedDevices.hpp +++ b/module-services/service-bluetooth/service-bluetooth/messages/SetBondedDevices.hpp @@ -12,7 +12,7 @@ namespace message::bluetooth public: explicit SetBondedDevices(std::vector devices) : devices(std::move(devices)) {} - [[nodiscard]] auto getDevices() const -> std::vector + [[nodiscard]] auto getDevices() const noexcept -> std::vector { return devices; } diff --git a/module-services/service-bluetooth/service-bluetooth/messages/SetDeviceName.hpp b/module-services/service-bluetooth/service-bluetooth/messages/SetDeviceName.hpp index 441c1d91b136269641aeca1084279009c1829b77..b511e0e4bdc7d7cc438fedc4a75c66d66681b81c 100644 --- a/module-services/service-bluetooth/service-bluetooth/messages/SetDeviceName.hpp +++ b/module-services/service-bluetooth/service-bluetooth/messages/SetDeviceName.hpp @@ -13,7 +13,7 @@ namespace message::bluetooth public: explicit SetDeviceName(std::string name) : name(std::move(name)) {} - [[nodiscard]] auto getName() const -> std::string + [[nodiscard]] auto getName() const noexcept -> std::string { return name; } diff --git a/module-services/service-bluetooth/service-bluetooth/messages/Unpair.hpp b/module-services/service-bluetooth/service-bluetooth/messages/Unpair.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9cc7fd704bcef1fc84b9ea553fddef40b1e03078 --- /dev/null +++ b/module-services/service-bluetooth/service-bluetooth/messages/Unpair.hpp @@ -0,0 +1,42 @@ +// 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 "service-bluetooth/BluetoothMessage.hpp" + +namespace message::bluetooth +{ + class Unpair : public BluetoothMessage + { + public: + explicit Unpair(std::string addr) : addr(std::move(addr)) + {} + [[nodiscard]] auto getAddr() const -> std::string + { + return addr; + } + + private: + std::string addr; + }; + + class UnpairResult : public BluetoothMessage + { + public: + explicit UnpairResult(std::string addr, bool succeed) : addr(std::move(addr)), succeed(succeed) + {} + [[nodiscard]] auto getAddr() const noexcept -> std::string + { + return addr; + } + [[nodiscard]] auto isSucceed() const noexcept -> bool + { + return succeed; + } + + private: + std::string addr; + bool succeed; + }; +} // namespace message::bluetooth