~aleteoryx/muditaos

b0fae5c4b83fe1ef8fef1807a0cad9387aed72d5 — RobertPiet 5 years ago 0f36b07
[EGD-3995] setup sim window prepared basing on the old settings (#913)

[EGD-3995] updated to new settings
[EGD-3995] sim switch using CellularServiceApi
M image/assets/lang/English.json => image/assets/lang/English.json +1 -0
@@ 324,6 324,7 @@
  "app_settings_network_import_contacts_from_sim_card": "Import contacts from SIM card",
  "app_settings_network_sim1": "Sim1",
  "app_settings_network_sim2": "Sim2",
  "app_settings_network_sim_none": "No Sim",
  "app_settings_toggle_on": "ON",
  "app_settings_toggle_off": "OFF",
  "app_phonebook_title_main": "Contacts",

A image/user/db/settings_001.sql => image/user/db/settings_001.sql +8 -0
@@ 0,0 1,8 @@
INSERT OR REPLACE INTO settings_tab (path, value) VALUES
    ('timeFormat12', '0'),
    ('timeDateFormat', '1'),
    ('activeSim', '1'),
    ('lockPassHash', '0'),
    ('lockTime', '30000'),
    ('displayLanguage', 'En'),
    ('inputLanguag', 'En');

M module-apps/application-settings-new/ApplicationSettings.cpp => module-apps/application-settings-new/ApplicationSettings.cpp +39 -2
@@ 29,6 29,9 @@
#include <service-evtmgr/EventManagerServiceAPI.hpp>
#include <service-bluetooth/BluetoothMessage.hpp>
#include <module-utils/i18n/i18n.hpp>
#include <service-cellular/CellularServiceAPI.hpp>
#include <service-db/Settings.hpp>
#include <module-services/service-db/agents/settings/SystemSettings.hpp>

namespace app
{


@@ 36,7 39,12 @@ namespace app
                                                   std::string parent,
                                                   StartInBackground startInBackground)
        : Application(name, parent, startInBackground)
    {}
    {
        if ((Store::GSM::SIM::SIM1 == selectedSim || Store::GSM::SIM::SIM2 == selectedSim) &&
            Store::GSM::get()->sim == selectedSim) {
            selectedSimNumber = CellularServiceAPI::GetOwnNumber(this);
        }
    }

    // Invoked upon receiving data message
    auto ApplicationSettingsNew::DataReceivedHandler(sys::DataMessage *msgl,


@@ 58,6 66,19 @@ namespace app
            switchWindow(gui::window::name::add_device, gui::ShowMode::GUI_SHOW_INIT, std::move(data));
            render(gui::RefreshModes::GUI_REFRESH_FAST);
        }
        else if (auto phoneMsg = dynamic_cast<CellularNotificationMessage *>(msgl); nullptr != phoneMsg) {
            selectedSim = Store::GSM::get()->selected;
            if (CellularNotificationMessage::Type::SIM_READY == phoneMsg->type) {
                selectedSimNumber = CellularServiceAPI::GetOwnNumber(this);
            }
            else if (CellularNotificationMessage::Type::SIM_NOT_READY == phoneMsg->type) {
                selectedSimNumber = {};
            }
            auto currentWindow = getCurrentWindow();
            if (gui::window::name::network == currentWindow->getName()) {
                currentWindow->rebuild();
            }
        }

        return std::make_shared<sys::ResponseMessage>();
    }


@@ 122,7 143,7 @@ namespace app
            return std::make_unique<gui::NightshiftWindow>(app);
        });
        windowsFactory.attach(gui::window::name::network, [](Application *app, const std::string &name) {
            return std::make_unique<gui::NetworkWindow>(app);
            return std::make_unique<gui::NetworkWindow>(app, dynamic_cast<SimParams *>(app));
        });
        windowsFactory.attach(gui::window::name::messages, [](Application *app, const std::string &name) {
            return std::make_unique<gui::MessagesWindow>(app);


@@ 149,4 170,20 @@ namespace app

    void ApplicationSettingsNew::destroyUserInterface()
    {}

    std::string ApplicationSettingsNew::getNumber()
    {
        return selectedSimNumber;
    }

    void ApplicationSettingsNew::setSim(Store::GSM::SIM sim)
    {
        CellularServiceAPI::SetSimCard(this, sim);
    }

    Store::GSM::SIM ApplicationSettingsNew::getSim()
    {
        return selectedSim;
    }

} /* namespace app */

M module-apps/application-settings-new/ApplicationSettings.hpp => module-apps/application-settings-new/ApplicationSettings.hpp +20 -1
@@ 48,7 48,19 @@ namespace app
{
    inline constexpr auto name_settings_new = "ApplicationSettingsNew";

    class ApplicationSettingsNew : public app::Application
    namespace settingsInterface
    {
        class SimParams
        {
          public:
            virtual ~SimParams()                     = default;
            virtual void setSim(Store::GSM::SIM sim) = 0;
            virtual Store::GSM::SIM getSim()         = 0;
            virtual std::string getNumber()          = 0;
        };
    } // namespace settingsInterface

    class ApplicationSettingsNew : public app::Application, public settingsInterface::SimParams
    {
      public:
        ApplicationSettingsNew(std::string name                    = name_settings_new,


@@ 64,7 76,14 @@ namespace app

        void createUserInterface() override;
        void destroyUserInterface() override;
        void setSim(Store::GSM::SIM sim) override;
        Store::GSM::SIM getSim() override;
        std::string getNumber() override;
        bsp::Board board = bsp::Board::none;

      private:
        Store::GSM::SIM selectedSim   = Store::GSM::get()->selected;
        std::string selectedSimNumber = {};
    };

    template <> struct ManifestTraits<ApplicationSettingsNew>

M module-apps/application-settings-new/windows/NetworkWindow.cpp => module-apps/application-settings-new/windows/NetworkWindow.cpp +29 -9
@@ 10,26 10,45 @@

namespace gui
{
    NetworkWindow::NetworkWindow(app::Application *app) : OptionWindow(app, gui::window::name::network)
    NetworkWindow::NetworkWindow(app::Application *app, app::settingsInterface::SimParams *simParams)
        : OptionWindow(app, gui::window::name::network), simParams(simParams)
    {
        operatorsOn = false;
    }
    void NetworkWindow::onBeforeShow(ShowMode m, SwitchData *d)
    {
        rebuildOptList();
        rebuild();
    }
    auto NetworkWindow::netOptList() -> std::list<gui::Option>
    {
        std::list<gui::Option> optList;
        auto sim    = Store::GSM::get()->selected;
        auto simStr = utils::translateI18("app_settings_network_sim1");
        if (sim == Store::GSM::SIM::SIM2) {
        std::string simStr;
        auto phoneNumber = simParams->getNumber();
        auto sim         = simParams->getSim();
        switch (sim) {
        case Store::GSM::SIM::SIM1:
            simStr = utils::translateI18("app_settings_network_sim1");
            break;
        case Store::GSM::SIM::SIM2:
            simStr = utils::translateI18("app_settings_network_sim2");
            break;
        case Store::GSM::SIM::NONE:
        case Store::GSM::SIM::SIM_FAIL:
        case Store::GSM::SIM::SIM_UNKNOWN:
            simStr      = utils::translateI18("app_settings_network_sim_none");
            phoneNumber = {};
            break;
        }
        optList.emplace_back(std::make_unique<gui::OptionSettings>(
            utils::translateI18("app_settings_network_active_card") + ":" + simStr,
            utils::translateI18("app_settings_network_active_card") + ":" + simStr + " / " + phoneNumber,
            [=](gui::Item &item) {
                this->application->switchWindow(gui::window::name::change_settings, nullptr);
                if (Store::GSM::SIM::SIM1 == sim) {
                    simParams->setSim(Store::GSM::SIM::SIM2);
                }
                else {
                    simParams->setSim(Store::GSM::SIM::SIM1);
                }

                return true;
            },
            [=](gui::Item &item) {


@@ 48,7 67,7 @@ namespace gui
            utils::translateI18("app_settings_network_operator_auto_select"),
            [=](gui::Item &item) {
                operatorsOn = !operatorsOn;
                rebuildOptList();
                rebuild();
                return true;
            },
            nullptr,


@@ 78,9 97,10 @@ namespace gui
        topBar->setActive(TopBar::Elements::SIM, false);
        return optList;
    }
    void NetworkWindow::rebuildOptList()
    void NetworkWindow::rebuild()
    {
        clearOptions();
        addOptions(netOptList());
    }

} // namespace gui

M module-apps/application-settings-new/windows/NetworkWindow.hpp => module-apps/application-settings-new/windows/NetworkWindow.hpp +8 -2
@@ 6,6 6,11 @@
#include "OptionWindow.hpp"
#include "Application.hpp"

namespace app::settingsInterface
{
    class SimParams;
}

namespace gui
{



@@ 18,11 23,12 @@ namespace gui
    {
      private:
        bool operatorsOn;
        app::settingsInterface::SimParams *simParams;
        auto netOptList() -> std::list<gui::Option>;
        void rebuildOptList();
        void rebuild() override;

      public:
        NetworkWindow(app::Application *app);
        NetworkWindow(app::Application *app, app::settingsInterface::SimParams *simParams);
        void onBeforeShow(ShowMode m, SwitchData *d) override;
    };
} // namespace gui

M module-apps/application-settings/ApplicationSettings.cpp => module-apps/application-settings/ApplicationSettings.cpp +7 -2
@@ 56,7 56,11 @@ namespace app
    }

    ApplicationSettings::~ApplicationSettings()
    {}
    {
        settings->unregisterValueChange(settings::SystemProperties::lockPassHash);
        settings->unregisterValueChange(settings::SystemProperties::timeDateFormat);
        settings->unregisterValueChange(settings::SystemProperties::displayLanguage);
    }

    // Invoked upon receiving data message
    sys::MessagePointer ApplicationSettings::DataReceivedHandler(sys::DataMessage *msgl,


@@ 167,18 171,19 @@ namespace app

    void ApplicationSettings::setSim(Store::GSM::SIM sim)
    {
        settings->setValue(settings::SystemProperties::activeSim, utils::enumToString(sim));
        CellularServiceAPI::SetSimCard(this, sim);
    }

    void ApplicationSettings::setPin(unsigned int value)
    {
        settings->setValue(settings::SystemProperties::lockPassHash, std::to_string(value));
        lockPassHash = value;
    }

    void ApplicationSettings::clearPin()
    {
        settings->setValue(settings::SystemProperties::lockPassHash, "");
        lockPassHash = 0U;
    }

    void ApplicationSettings::lockPassChanged(std::string value)

M module-services/service-cellular/ServiceCellular.cpp => module-services/service-cellular/ServiceCellular.cpp +9 -4
@@ 648,7 648,7 @@ sys::MessagePointer ServiceCellular::DataReceivedHandler(sys::DataMessage *msgl,
            responseMsg = respMsg;
            break;
        } break;
        case CellularNotificationMessage::Type::SIM:
        case CellularNotificationMessage::Type::SIM_READY:
            if (Store::GSM::get()->tray == Store::GSM::Tray::IN) {
                state.set(this, cellular::State::ST::SimInit);
                responseMsg = std::make_shared<CellularResponseMessage>(true);


@@ 660,7 660,8 @@ sys::MessagePointer ServiceCellular::DataReceivedHandler(sys::DataMessage *msgl,
            responseMsg = std::make_shared<CellularResponseMessage>(resp);
        } break;
        case CellularNotificationMessage::Type::SignalStrengthUpdate:
        case CellularNotificationMessage::Type::NetworkStatusUpdate: {
        case CellularNotificationMessage::Type::NetworkStatusUpdate:
        case CellularNotificationMessage::Type::SIM_NOT_READY: {
            // skipped
            responseMsg = std::make_shared<CellularResponseMessage>(false);
        }


@@ 1168,14 1169,19 @@ bool ServiceCellular::handleSimState(at::SimState state, const std::string messa
    switch (state) {
    case at::SimState::Ready:
        Store::GSM::get()->sim = Store::GSM::get()->selected;
        settings->setValue(settings::SystemProperties::activeSim, utils::enumToString(Store::GSM::get()->selected));
        // SIM causes SIM INIT, only on ready
        response = std::move(std::make_unique<CellularNotificationMessage>(CellularNotificationMessage::Type::SIM));
        response =
            std::move(std::make_unique<CellularNotificationMessage>(CellularNotificationMessage::Type::SIM_READY));
        sys::Bus::SendMulticast(response, sys::BusChannels::ServiceCellularNotifications, this);
        sendSimUnlocked();
        break;
    case at::SimState::NotReady:
        LOG_DEBUG("Not ready");
        Store::GSM::get()->sim = Store::GSM::SIM::SIM_FAIL;
        response =
            std::move(std::make_unique<CellularNotificationMessage>(CellularNotificationMessage::Type::SIM_NOT_READY));
        sys::Bus::SendMulticast(response, sys::BusChannels::ServiceCellularNotifications, this);
        break;
    case at::SimState::SimPin: {
        SimCard simCard(*this);


@@ 1230,7 1236,6 @@ bool ServiceCellular::handleSimState(at::SimState state, const std::string messa
        Store::GSM::get()->sim = Store::GSM::SIM::SIM_UNKNOWN;
        break;
    }

    auto simMessage = std::make_shared<sevm::SIMMessage>();
    sys::Bus::SendUnicast(simMessage, service::name::evt_manager, this);


M module-services/service-cellular/service-cellular/CellularMessage.hpp => module-services/service-cellular/service-cellular/CellularMessage.hpp +2 -1
@@ 65,7 65,8 @@ class CellularNotificationMessage : public CellularMessage
        NetworkStatusUpdate,      // update of the status of the network
        PowerUpProcedureComplete, // modem without cmux on initialization complete (cold start || reset modem -> and
                                  // cold start)
        SIM,                      // change on SIM from URC
        SIM_READY,                // change on SIM from URC
        SIM_NOT_READY,            // change to not existing/not valid SIM
        RawCommand,               // send raw command to modem -> returns raw, tokenised result
        PowerDownDeregistering,   // modem informed it has started to disconnect from network
        PowerDownDeregistered,    // modem informed it has disconnected from network

M module-services/service-cellular/service-cellular/ServiceCellular.hpp => module-services/service-cellular/service-cellular/ServiceCellular.hpp +3 -0
@@ 23,6 23,8 @@
#include <memory>   // for unique_ptr, allocator, make_unique, shared_ptr
#include <string>   // for string
#include <vector>   // for vector
#include <service-db/Settings.hpp>
#include <module-services/service-db/agents/settings/SystemSettings.hpp>

#include <cstdint>
#include <memory>


@@ 219,6 221,7 @@ class ServiceCellular : public sys::Service
    /// \note some run state should be added to ignore non system messages now...
    bool handle_fatal_failure();
    bool handle_ready();
    std::unique_ptr<settings::Settings> settings = std::make_unique<settings::Settings>(this);

    bool handleAllMessagesFromMessageStorage();
    [[nodiscard]] SMSRecord createSMSRecord(const UTF8 &decodedMessage,