~aleteoryx/muditaos

81e49a91cef1b9407d6e77a63cca09aac9fba22b — Pawel Olejniczak 4 years ago 1e219f3
[EGD-2630] Add pairing passkey handling on bluetooth settings side

Connect prompt window and add missing messages.
M module-apps/application-settings-new/ApplicationSettings.cpp => module-apps/application-settings-new/ApplicationSettings.cpp +6 -0
@@ 45,6 45,7 @@
#include <service-bluetooth/messages/Status.hpp>
#include <service-bluetooth/messages/BondedDevices.hpp>
#include <service-bluetooth/messages/DeviceName.hpp>
#include <service-bluetooth/messages/Passkey.hpp>
#include <service-bluetooth/messages/ResponseVisibleDevices.hpp>
#include <service-db/agents/settings/SystemSettings.hpp>
#include <application-settings-new/data/ApnListData.hpp>


@@ 191,6 192,11 @@ namespace app
            return sys::MessageNone{};
        });

        connect(typeid(::message::bluetooth::RequestPasskey), [&](sys::Message *msg) {
            switchWindow(gui::window::name::bluetooth_check_passkey);
            return sys::MessageNone{};
        });

        connect(typeid(CellularGetAPNResponse), [&](sys::Message *msg) {
            if (gui::window::name::apn_settings == getCurrentWindow()->getName()) {
                auto apns = dynamic_cast<CellularGetAPNResponse *>(msg);

M module-apps/application-settings-new/models/BluetoothSettingsModel.cpp => module-apps/application-settings-new/models/BluetoothSettingsModel.cpp +7 -0
@@ 9,6 9,7 @@
#include <service-bluetooth/messages/Status.hpp>
#include <service-bluetooth/messages/SetStatus.hpp>
#include <service-bluetooth/messages/SetDeviceName.hpp>
#include <service-bluetooth/messages/Passkey.hpp>

BluetoothSettingsModel::BluetoothSettingsModel(app::Application *application) : application{application}
{}


@@ 65,3 66,9 @@ void BluetoothSettingsModel::requestDevicePairing(std::string addr)
{
    application->bus.sendUnicast(std::make_shared<BluetoothPairMessage>(std::move(addr)), service::name::bluetooth);
}

void BluetoothSettingsModel::responsePasskey(std::string passkey)
{
    application->bus.sendUnicast(std::make_shared<message::bluetooth::ResponsePasskey>(std::move(passkey)),
                                 service::name::bluetooth);
}

M module-apps/application-settings-new/models/BluetoothSettingsModel.hpp => module-apps/application-settings-new/models/BluetoothSettingsModel.hpp +1 -0
@@ 23,6 23,7 @@ class BluetoothSettingsModel
    void requestScan();
    void stopScan();
    void requestDevicePairing(std::string addr);
    void responsePasskey(std::string passkey);
    void setAddrForAudioProfiles(std::string addr);

  private:

M module-apps/application-settings-new/windows/BluetoothCheckPasskeyWindow.cpp => module-apps/application-settings-new/windows/BluetoothCheckPasskeyWindow.cpp +13 -1
@@ 11,7 11,8 @@ namespace gui
    namespace
    {
        constexpr auto maxPasskeyCharactersCount = 16U;
    }
        constexpr auto minPasskeyCharactersCount = 4U;
    } // namespace
    namespace passkey_style = style::settings::window::bluetooth::passkey;

    BluetoothCheckPasskeyWindow::BluetoothCheckPasskeyWindow(app::Application *app)


@@ 53,4 54,15 @@ namespace gui

        setFocusItem(text);
    }

    auto BluetoothCheckPasskeyWindow::onInput(const InputEvent &inputEvent) -> bool
    {
        auto passkey = text->getText();
        if (passkey.length() >= minPasskeyCharactersCount && inputEvent.isShortPress() &&
            inputEvent.is(KeyCode::KEY_ENTER)) {
            bluetoothSettingsModel->responsePasskey(passkey);
            return true;
        }
        return AppWindow::onInput(inputEvent);
    }
} // namespace gui

M module-apps/application-settings-new/windows/BluetoothCheckPasskeyWindow.hpp => module-apps/application-settings-new/windows/BluetoothCheckPasskeyWindow.hpp +4 -1
@@ 3,6 3,7 @@

#pragma once

#include "application-settings-new/models/BluetoothSettingsModel.hpp"
#include <AppWindow.hpp>

namespace gui


@@ 13,13 14,15 @@ namespace gui
    class BluetoothCheckPasskeyWindow : public AppWindow
    {
      public:
        BluetoothCheckPasskeyWindow(app::Application *app);
        explicit BluetoothCheckPasskeyWindow(app::Application *app);

      private:
        void buildInterface() override;
        auto onInput(const InputEvent &inputEvent) -> bool override;

        Image *image = nullptr;
        Label *label = nullptr;
        Text *text   = nullptr;
        std::unique_ptr<BluetoothSettingsModel> bluetoothSettingsModel;
    };
} // namespace gui

M module-services/service-bluetooth/service-bluetooth/BluetoothMessage.hpp => module-services/service-bluetooth/service-bluetooth/BluetoothMessage.hpp +2 -1
@@ 60,7 60,8 @@ class BluetoothPairResultMessage : public sys::DataMessage
    std::string name;
    bool status;
    explicit BluetoothPairResultMessage(std::string addr, std::string name, bool status)
        : sys::DataMessage(MessageType::BluetoothPairResult), addr(addr), name(name), status(status){};
        : sys::DataMessage(MessageType::BluetoothPairResult), addr(std::move(addr)), name(std::move(name)),
          status(status){};
};

class BluetoothScanMessage : public sys::DataMessage

A module-services/service-bluetooth/service-bluetooth/messages/Passkey.hpp => module-services/service-bluetooth/service-bluetooth/messages/Passkey.hpp +26 -0
@@ 0,0 1,26 @@
// 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 RequestPasskey : public BluetoothMessage
    {};

    class ResponsePasskey : public BluetoothMessage
    {
      public:
        explicit ResponsePasskey(std::string passkey) : passkey(std::move(passkey))
        {}
        [[nodiscard]] auto getName() const -> std::string
        {
            return passkey;
        }

      private:
        std::string passkey;
    };
} // namespace message::bluetooth