~aleteoryx/muditaos

d528cac7df03906e67d64987e7c0b2ca5cfe6361 — Maciej-Mudita 3 years ago 9b79f9f
[MOS-641] Fix SIM cards window

Creating menus and actions depending on the SIM card
lock status.
M image/assets/lang/Deutsch.json => image/assets/lang/Deutsch.json +3 -2
@@ 467,7 467,9 @@
  "app_settings_about": "Über Mudita Pure",
  "app_settings_title_languages": "Sprachauswahl",
  "app_settings_network_sim_cards": "SIM-Karten",
  "app_settings_network_active_card": "Aktive Karte",
  "app_settings_network_active_card": "Aktiver Slot",
  "app_settings_network_unblock_card": "Entsperren Karte",
  "app_settings_network_not_connected": "keine Karte",
  "app_settings_network_operator_auto_select": "Automatische Auswahl",
  "app_settings_network_all_operators": "Alle Bediener",
  "app_settings_network_pin_settings": "PIN-Einstellungen",


@@ 475,7 477,6 @@
  "app_settings_network_pin_change_code": "PIN-Code ändern",
  "app_settings_network_import_contacts_from_sim_card": "Kontakte von SIM import.",
  "app_settings_network_import_contacts_duplicates": "Duplikate von SIM",
  "app_settings_network_import_contacts_from_sim_card": "Kontakte von SIM-Karte importieren",
  "app_settings_network_import_contacts_from_sim_card_reading": "<text>Import läuft...<br></br>Bitte warte einen Moment.</text>",
  "app_settings_network_import_contacts_from_sim_card_no_contacts": "<text>Auf dieser SIM-Karte befinden <br></br> sich keine Kontakte.</text>",
  "app_settings_network_import_contacts_from_sim_card_duplicates": "<text>Wir haben <token>$DUPLICATES</token> Duplikate gefunden. Möchten Sie<br></br>doppelte Kontakte importieren <br></br>und vorhandene ersetzen?</text>",

M image/assets/lang/English.json => image/assets/lang/English.json +3 -1
@@ 424,7 424,9 @@
  "app_settings_about": "About Mudita Pure",
  "app_settings_title_languages": "Language selection",
  "app_settings_network_sim_cards": "SIM cards",
  "app_settings_network_active_card": "Active card",
  "app_settings_network_active_card": "Active slot",
  "app_settings_network_unblock_card": "Unblock card",
  "app_settings_network_not_connected": "no card",
  "app_settings_network_operator_auto_select": "Operator auto-select",
  "app_settings_network_all_operators": "All operators",
  "app_settings_network_pin_settings": "PIN settings",

M image/assets/lang/Espanol.json => image/assets/lang/Espanol.json +3 -2
@@ 467,7 467,9 @@
  "app_settings_about": "Sobre Mudita Pure",
  "app_settings_title_languages": "Selección de idioma",
  "app_settings_network_sim_cards": "Tarjetas SIM",
  "app_settings_network_active_card": "Tarjeta activa",
  "app_settings_network_active_card": "Toma activa",
  "app_settings_network_unblock_card": "Desbloquear la tarjeta",
  "app_settings_network_not_connected": "sin tarjeta",
  "app_settings_network_operator_auto_select": "Selección automática de operador",
  "app_settings_network_all_operators": "Todos los operadores",
  "app_settings_network_pin_settings": "Configuración de PIN",


@@ 476,7 478,6 @@
  "app_settings_network_import_contacts_from_sim_card": "Importar contactos de la SIM",
  "app_settings_network_import_contacts": "Importar contactos",
  "app_settings_network_import_contacts_duplicates": "Duplicados de SIM",
  "app_settings_network_import_contacts_from_sim_card": "Importar contactos de la tarjeta SIM",
  "app_settings_network_import_contacts_from_sim_card_reading": "<text>Importación en curso ...<br></br>Espere un momento.</text>",
  "app_settings_network_import_contacts_from_sim_card_no_contacts": "<text>No hay contactos <br></br>en esta tarjeta SIM.</text>",
  "app_settings_network_import_contacts_from_sim_card_duplicates": "<text>Encontramos <token>$DUPLICATES</token> duplicados. ¿Quieres importar <br></br>contactos duplicados y reemplazar los existentes?</text>",

M image/assets/lang/Francais.json => image/assets/lang/Francais.json +3 -1
@@ 435,7 435,9 @@
  "app_settings_about": "À propos de Mudita Pure",
  "app_settings_title_languages": "Sélection de langue",
  "app_settings_network_sim_cards": "Cartes SIM",
  "app_settings_network_active_card": "Activer la carte",
  "app_settings_network_active_card": "Fente active",
  "app_settings_network_unblock_card": "Débloquer la carte",
  "app_settings_network_not_connected": "pas de carte",
  "app_settings_network_operator_auto_select": "Operator auto-select",
  "app_settings_network_all_operators": "All operators",
  "app_settings_network_pin_settings": "PIN settings",

M image/assets/lang/Polski.json => image/assets/lang/Polski.json +3 -1
@@ 478,7 478,9 @@
  "app_settings_about": "O Mudita Pure",
  "app_settings_title_languages": "Wybór języka",
  "app_settings_network_sim_cards": "Karty SIM",
  "app_settings_network_active_card": "Aktywna karta",
  "app_settings_network_active_card": "Aktywny slot",
  "app_settings_network_unblock_card": "Odblokuj kartę",
  "app_settings_network_not_connected": "brak karty",
  "app_settings_network_operator_auto_select": "Automatyczny wybór operatora",
  "app_settings_network_all_operators": "Wszyscy operatorzy",
  "app_settings_network_pin_settings": "Ustawienia PIN",

M image/assets/lang/Svenska.json => image/assets/lang/Svenska.json +3 -1
@@ 377,7 377,9 @@
  "app_settings_about": "Om Mudita Pure",
  "app_settings_title_languages": "Språkval",
  "app_settings_network_sim_cards": "SIM-kort",
  "app_settings_network_active_card": "Aktivt kort",
  "app_settings_network_active_card": "Aktivt slot",
  "app_settings_network_unblock_card": "Avblockera kort",
  "app_settings_network_not_connected": "inget kort",
  "app_settings_network_operator_auto_select": "Välj operatör automatiskt",
  "app_settings_network_all_operators": "Alla operatörer",
  "app_settings_network_import_contacts_from_sim_card": "Importera kontakter från SIM",

M module-apps/application-settings/ApplicationSettings.cpp => module-apps/application-settings/ApplicationSettings.cpp +36 -17
@@ 109,13 109,14 @@ namespace app
        bus.channels.push_back(sys::BusChannel::ServiceAudioNotifications);
        bus.channels.push_back(sys::BusChannel::BluetoothNotifications);
        bus.channels.push_back(sys::BusChannel::BluetoothModeChanges);
        bus.channels.push_back(sys::BusChannel::ServiceCellularNotifications);

        CellularServiceAPI::SubscribeForOwnNumber(this, [&](const std::string &number) {
            selectedSimNumber = number;
            LOG_DEBUG("Sim number changed");
        });
        if ((Store::GSM::SIM::SIM1 == selectedSim || Store::GSM::SIM::SIM2 == selectedSim) &&
            Store::GSM::get()->sim == selectedSim) {
        if ((Store::GSM::SIM::SIM1 == simState || Store::GSM::SIM::SIM2 == simState) &&
            Store::GSM::get()->sim == simState) {
            CellularServiceAPI::RequestForOwnNumber(this);
        }
        bluetoothSettingsModel = std::make_shared<BluetoothSettingsModel>(this);


@@ 153,15 154,19 @@ namespace app
            return ret;
        }
        connect(typeid(cellular::msg::notification::SimReady), [&](sys::Message *) {
            selectedSim = Store::GSM::get()->selected;
            CellularServiceAPI::RequestForOwnNumber(this);
            auto currentWindow = getCurrentWindow();
            if (gui::window::name::sim_cards == currentWindow->getName()) {
                updateCurrentWindow();
            }
            return sys::MessageNone{};
            return handleSimNotification();
        });

        connect(typeid(cellular::msg::notification::SimBlocked),
                [&](sys::Message *) { return handleSimNotification(); });

        connect(typeid(cellular::msg::notification::SimNeedPin),
                [&](sys::Message *) { return handleSimNotification(); });

        connect(typeid(cellular::msg::notification::SimNeedPuk),
                [&](sys::Message *) { return handleSimNotification(); });

        connect(typeid(::sys::bluetooth::BluetoothModeChanged), [&](sys::Message *msg) {
            const auto message   = static_cast<::sys::bluetooth::BluetoothModeChanged *>(msg);
            const auto newState  = message->getBluetoothMode();


@@ 288,11 293,10 @@ namespace app
            return sys::MessageNone{};
        });

        connect(typeid(cellular::msg::request::sim::GetLockState::Response), [&](sys::Message *msg) {
            auto simCardPinLockState = static_cast<cellular::msg::request::sim::GetLockState::Response *>(msg);
            auto pinSettingsLockStateData =
                std::make_unique<gui::PINSettingsLockStateData>(simCardPinLockState->locked);
            updateCurrentWindow(std::move(pinSettingsLockStateData));
        connect(typeid(cellular::msg::request::sim::GetPinSettings::Response), [&](sys::Message *msg) {
            auto simCardPinSettings     = static_cast<cellular::msg::request::sim::GetPinSettings::Response *>(msg);
            auto simCardPinSettingsData = std::make_unique<gui::PINSettingsLockStateData>(simCardPinSettings->locked);
            updateCurrentWindow(std::move(simCardPinSettingsData));
            return sys::MessageNone{};
        });



@@ 596,22 600,28 @@ namespace app
        ApplicationCommon::returnToPreviousWindow();
    }

    void ApplicationSettings::setSim(Store::GSM::SIM sim)
    void ApplicationSettings::setSelectedSim(Store::GSM::SelectedSIM sim)
    {
        auto arg = (sim == Store::GSM::SIM::SIM2) ? cellular::api::SimSlot::SIM2 : cellular::api::SimSlot::SIM1;
        auto arg = (sim == Store::GSM::SelectedSIM::SIM2) ? cellular::api::SimSlot::SIM2 : cellular::api::SimSlot::SIM1;
        getSimLockSubject().setSim(arg);
    }

    void ApplicationSettings::updateSim()
    void ApplicationSettings::updateSimParam()
    {
        selectedSim = Store::GSM::get()->selected;
        simState    = Store::GSM::get()->sim;
    }

    Store::GSM::SIM ApplicationSettings::getSim()
    Store::GSM::SelectedSIM ApplicationSettings::getSelectedSim()
    {
        return selectedSim;
    }

    Store::GSM::SIM ApplicationSettings::getSimState()
    {
        return simState;
    }

    void ApplicationSettings::operatorOnChanged(const std::string &value)
    {
        LOG_DEBUG("[ApplicationSettings::operatorOnChanged] value=%s", value.c_str());


@@ 786,4 796,13 @@ namespace app
        soundsPlayer->stop(notification->token);
        return sys::MessageNone{};
    }

    auto ApplicationSettings::handleSimNotification() -> sys::MessagePointer
    {
        auto currentWindow = getCurrentWindow();
        if (gui::window::name::sim_cards == currentWindow->getName()) {
            updateCurrentWindow();
        }
        return sys::MessageNone{};
    }
} /* namespace app */

M module-apps/application-settings/include/application-settings/ApplicationSettings.hpp => module-apps/application-settings/include/application-settings/ApplicationSettings.hpp +14 -10
@@ 25,11 25,12 @@ namespace app
        class SimParams
        {
          public:
            virtual ~SimParams()                     = default;
            virtual void setSim(Store::GSM::SIM sim) = 0;
            virtual void updateSim()                 = 0;
            virtual Store::GSM::SIM getSim()         = 0;
            virtual std::string getNumber()          = 0;
            virtual ~SimParams()                                     = default;
            virtual void updateSimParam()                            = 0;
            virtual void setSelectedSim(Store::GSM::SelectedSIM sim) = 0;
            virtual Store::GSM::SelectedSIM getSelectedSim()         = 0;
            virtual Store::GSM::SIM getSimState()                    = 0;
            virtual std::string getNumber()                          = 0;
        };
        class OperatorsSettings
        {


@@ 144,9 145,10 @@ namespace app
        void destroyUserInterface() override;
        void returnToPreviousWindow() override;

        void setSim(Store::GSM::SIM sim) override;
        void updateSim() override;
        Store::GSM::SIM getSim() override;
        void updateSimParam() override;
        void setSelectedSim(Store::GSM::SelectedSIM sim) override;
        Store::GSM::SelectedSIM getSelectedSim() override;
        Store::GSM::SIM getSimState() override;
        std::string getNumber() override;

        void operatorOnChanged(const std::string &value);


@@ 185,11 187,13 @@ namespace app
        void attachQuotesWindows();
        void switchToAllDevicesViaBtErrorPrompt(std::shared_ptr<sys::DataMessage> msg, const std::string &errorMsg);

        auto handleSimNotification() -> sys::MessagePointer;
        auto handleAudioStop(AudioStopNotification *notification) -> sys::MessagePointer;

        std::shared_ptr<SoundsPlayer> soundsPlayer;
        Store::GSM::SIM selectedSim   = Store::GSM::get()->selected;
        std::string selectedSimNumber = {};
        Store::GSM::SelectedSIM selectedSim = Store::GSM::get()->selected;
        Store::GSM::SIM simState            = Store::GSM::get()->sim;
        std::string selectedSimNumber       = {};

        bool operatorsOn                                               = false;
        bool notificationsWhenLocked                                   = true;

M module-apps/application-settings/presenter/network/SimPINSettingsPresenter.cpp => module-apps/application-settings/presenter/network/SimPINSettingsPresenter.cpp +1 -1
@@ 33,7 33,7 @@ bool SimPINSettingsPresenter::isPinEnabled() const noexcept

void SimPINSettingsPresenter::requestLockState() const
{
    application->bus.sendUnicast<cellular::msg::request::sim::GetLockState>();
    application->bus.sendUnicast<cellular::msg::request::sim::GetPinSettings>();
}

void SimPINSettingsPresenter::onBeforeShow(gui::ShowMode mode, gui::SwitchData *data)

M module-apps/application-settings/windows/network/SimCardsWindow.cpp => module-apps/application-settings/windows/network/SimCardsWindow.cpp +91 -26
@@ 3,10 3,8 @@

#include "SimCardsWindow.hpp"

#include <application-settings/ApplicationSettings.hpp>
#include <application-settings/data/PINSettingsSimData.hpp>
#include <application-settings/windows/WindowNames.hpp>

#include <OptionSetting.hpp>

namespace gui


@@ 18,7 16,7 @@ namespace gui
    void SimCardsWindow::onBeforeShow(ShowMode mode, SwitchData *data)
    {
        setTitle(utils::translate("app_settings_network_sim_cards"));
        simParams->updateSim();
        simParams->updateSimParam();
        BaseSettingsWindow::onBeforeShow(mode, data);
    }



@@ 27,43 25,98 @@ namespace gui
        std::list<gui::Option> optList;
        std::string simStr;
        auto phoneNumber = simParams->getNumber();
        auto sim         = simParams->getSim();
        switch (sim) {
        case Store::GSM::SIM::SIM1:
        auto selectedSim = simParams->getSelectedSim();
        auto simState    = simParams->getSimState();

        switch (selectedSim) {
        case Store::GSM::SelectedSIM::SIM1:
            simStr = utils::translate("app_settings_network_sim1");
            break;
        case Store::GSM::SIM::SIM2:
        case Store::GSM::SelectedSIM::SIM2:
            simStr = utils::translate("app_settings_network_sim2");
            break;
        case Store::GSM::SelectedSIM::NONE:
            simStr      = utils::translate("app_settings_network_sim_none");
            phoneNumber = {};
            break;
        }

        switch (simState) {
        case Store::GSM::SIM::SIM1:
        case Store::GSM::SIM::SIM2:
            optList = createListWithActiveSim(selectedSim, simStr, phoneNumber);
            break;
        case Store::GSM::SIM::SIM_NEED_PIN:
        case Store::GSM::SIM::SIM_NEED_PUK:
        case Store::GSM::SIM::SIM_LOCKED:
            optList = createListWithBlockedSim(selectedSim, simStr);
            break;
        case Store::GSM::SIM::NONE:
        case Store::GSM::SIM::SIM_FAIL:
        case Store::GSM::SIM::SIM_UNKNOWN:
            simStr      = utils::translate("app_settings_network_sim_none");
            phoneNumber = {};
            optList = createListWithNoConnectedSim(selectedSim, simStr);
            break;
        }

        navBar->setText(nav_bar::Side::Center, utils::translate(style::strings::common::select));

        return optList;
    }

    std::list<gui::Option> SimCardsWindow::createListWithNoConnectedSim(const Store::GSM::SelectedSIM sim,
                                                                        const std::string &simStr)
    {
        std::list<gui::Option> optList;
        optList.emplace_back(std::make_unique<gui::option::OptionSettings>(
            utils::translate("app_settings_network_active_card") + " (" +
                utils::translate("app_settings_network_not_connected") + ")",
            [=](gui::Item &item) { return createSwitchSimAction(sim); },
            [=](gui::Item &item) { return createNavBarText(item); },
            this,
            gui::option::SettingRightItem::Text,
            false,
            simStr,
            true));

        return optList;
    }

    std::list<gui::Option> SimCardsWindow::createListWithBlockedSim(const Store::GSM::SelectedSIM sim,
                                                                    const std::string &simStr)
    {
        std::list<gui::Option> optList;
        optList.emplace_back(std::make_unique<gui::option::OptionSettings>(
            utils::translate("app_settings_network_active_card"),
            [=](gui::Item &item) {
                if (Store::GSM::SIM::SIM1 == sim) {
                    simParams->setSim(Store::GSM::SIM::SIM2);
                }
                else {
                    simParams->setSim(Store::GSM::SIM::SIM1);
                }
            [=](gui::Item &item) { return createSwitchSimAction(sim); },
            [=](gui::Item &item) { return createNavBarText(item); },
            this,
            gui::option::SettingRightItem::Text,
            false,
            simStr,
            true));

                return true;
            },
        optList.emplace_back(std::make_unique<gui::option::OptionSettings>(
            utils::translate("app_settings_network_unblock_card"),
            [=](gui::Item &item) {
                if (item.focus) {
                    this->setNavBarText(utils::translate(style::strings::common::Switch), nav_bar::Side::Center);
                }
                else {
                    this->setNavBarText(utils::translate(style::strings::common::select), nav_bar::Side::Center);
                }
                application->getSimLockSubject().unblockSim();
                return true;
            },
            nullptr,
            nullptr,
            gui::option::SettingRightItem::ArrowWhite));

        return optList;
    }

    std::list<gui::Option> SimCardsWindow::createListWithActiveSim(const Store::GSM::SelectedSIM sim,
                                                                   const std::string &simStr,
                                                                   const std::string &phoneNumber)
    {
        std::list<gui::Option> optList;
        optList.emplace_back(std::make_unique<gui::option::OptionSettings>(
            utils::translate("app_settings_network_active_card"),
            [=](gui::Item &item) { return createSwitchSimAction(sim); },
            [=](gui::Item &item) { return createNavBarText(item); },
            this,
            gui::option::SettingRightItem::Text,
            false,


@@ 92,8 145,20 @@ namespace gui
            nullptr,
            gui::option::SettingRightItem::ArrowWhite));

        navBar->setText(nav_bar::Side::Center, utils::translate(style::strings::common::select));

        return optList;
    }

    bool SimCardsWindow::createSwitchSimAction(const Store::GSM::SelectedSIM selectedSim) const
    {
        selectedSim == Store::GSM::SelectedSIM::SIM1 ? simParams->setSelectedSim(Store::GSM::SelectedSIM::SIM2)
                                                     : simParams->setSelectedSim(Store::GSM::SelectedSIM::SIM1);
        return true;
    }

    bool SimCardsWindow::createNavBarText(const gui::Item &item)
    {
        item.focus ? this->setNavBarText(utils::translate(style::strings::common::Switch), nav_bar::Side::Center)
                   : this->setNavBarText(utils::translate(style::strings::common::select), nav_bar::Side::Center);
        return true;
    }
} // namespace gui

M module-apps/application-settings/windows/network/SimCardsWindow.hpp => module-apps/application-settings/windows/network/SimCardsWindow.hpp +10 -0
@@ 4,6 4,7 @@
#pragma once

#include <application-settings/windows/BaseSettingsWindow.hpp>
#include <application-settings/ApplicationSettings.hpp>

namespace app::settingsInterface
{


@@ 18,6 19,15 @@ namespace gui
        auto buildOptionsList() -> std::list<Option> override;
        app::settingsInterface::SimParams *simParams;

        std::list<gui::Option> createListWithNoConnectedSim(const Store::GSM::SelectedSIM sim,
                                                            const std::string &simStr);
        std::list<gui::Option> createListWithBlockedSim(const Store::GSM::SelectedSIM sim, const std::string &simStr);
        std::list<gui::Option> createListWithActiveSim(const Store::GSM::SelectedSIM sim,
                                                       const std::string &simStr,
                                                       const std::string &phoneNumber);
        bool createSwitchSimAction(const Store::GSM::SelectedSIM selectedSim) const;
        bool createNavBarText(const gui::Item &item);

      public:
        SimCardsWindow(app::ApplicationCommon *app, app::settingsInterface::SimParams *simParams);


M module-apps/apps-common/locks/data/SimLockMessages.hpp => module-apps/apps-common/locks/data/SimLockMessages.hpp +4 -1
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


@@ 50,4 50,7 @@ namespace locks
    class ResetSimLockState : public sys::DataMessage
    {};

    class UnblockSim : public sys::DataMessage
    {};

} // namespace locks

M module-apps/apps-common/locks/handlers/SimLockHandler.cpp => module-apps/apps-common/locks/handlers/SimLockHandler.cpp +13 -9
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "SimLockHandler.hpp"


@@ 85,21 85,21 @@ namespace locks

    void SimLockHandler::getSettingsSimSelect(const std::string &settingsSim)
    {
        auto selectedSim = magic_enum::enum_cast<Store::GSM::SIM>(settingsSim);
        auto selectedSim = magic_enum::enum_cast<Store::GSM::SelectedSIM>(settingsSim);

        if (selectedSim.has_value() &&
            (selectedSim.value() == Store::GSM::SIM::SIM1 || selectedSim.value() == Store::GSM::SIM::SIM2)) {
        if (selectedSim.has_value() && (selectedSim.value() == Store::GSM::SelectedSIM::SIM1 ||
                                        selectedSim.value() == Store::GSM::SelectedSIM::SIM2)) {
            setSim(static_cast<cellular::api::SimSlot>(selectedSim.value()));
        }
        else {
            Store::GSM::get()->selected = Store::GSM::SIM::NONE;
            Store::GSM::get()->selected = Store::GSM::SelectedSIM::NONE;
        }
    }

    void SimLockHandler::setSim(cellular::api::SimSlot simSlot)
    {
        if (simReady) {
            Store::GSM::get()->selected = static_cast<Store::GSM::SIM>(simSlot);
            Store::GSM::get()->selected = static_cast<Store::GSM::SelectedSIM>(simSlot);
            owner->bus.sendUnicast<cellular::msg::request::sim::SetActiveSim>(simSlot);
        }
        else {


@@ 348,8 348,12 @@ namespace locks
        if (!simUnlockingNeeded_) {
            return sys::msgNotHandled();
        }

        simUnlockingNeeded_ = false;
        return handleSimUnlockRequest();
    }

    sys::MessagePointer SimLockHandler::handleSimUnlockRequest()
    {
        switch (simInputTypeAction) {
        case SimInputTypeAction::UnlockWithPin:
            return handleSimPinRequest(lock.getAttemptsLeft());


@@ 396,14 400,14 @@ namespace locks

    sys::MessagePointer SimLockHandler::enableSimPin(LockInput pinInputData)
    {
        owner->bus.sendUnicast<cellular::msg::request::sim::SetPinLock>(cellular::api::SimLockState::Enabled,
        owner->bus.sendUnicast<cellular::msg::request::sim::SetPinLock>(cellular::api::SimPinState::Enabled,
                                                                        pinInputData);
        return sys::msgHandled();
    }

    sys::MessagePointer SimLockHandler::disableSimPin(LockInput pinInputData)
    {
        owner->bus.sendUnicast<cellular::msg::request::sim::SetPinLock>(cellular::api::SimLockState::Disabled,
        owner->bus.sendUnicast<cellular::msg::request::sim::SetPinLock>(cellular::api::SimPinState::Disabled,
                                                                        pinInputData);
        return sys::msgHandled();
    }

M module-apps/apps-common/locks/handlers/SimLockHandler.hpp => module-apps/apps-common/locks/handlers/SimLockHandler.hpp +2 -1
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


@@ 70,6 70,7 @@ namespace locks
        sys::MessagePointer handleSimReadyMessage();
        sys::MessagePointer handleSimNotInsertedMessage();
        sys::MessagePointer handleSimNotRespondingMessage();
        sys::MessagePointer handleSimUnlockRequest();

        void getSettingsSimSelect(const std::string &settingsSim);
        void setSim(cellular::api::SimSlot simSlot);

M module-apps/apps-common/locks/handlers/SimLockSubject.cpp => module-apps/apps-common/locks/handlers/SimLockSubject.cpp +6 -1
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "SimLockSubject.hpp"


@@ 45,4 45,9 @@ namespace locks
    {
        owner->bus.sendUnicast(std::make_shared<UnLockSimInput>(inputData), service::name::appmgr);
    }

    void SimLockSubject::unblockSim()
    {
        owner->bus.sendUnicast(std::make_shared<UnblockSim>(), service::name::appmgr);
    }
} // namespace locks

M module-apps/apps-common/locks/handlers/SimLockSubject.hpp => module-apps/apps-common/locks/handlers/SimLockSubject.hpp +2 -1
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


@@ 24,6 24,7 @@ namespace locks
        void enableSimPin();
        void disableSimPin();
        void verifyInput(LockInput inputData);
        void unblockSim();
    };

} // namespace locks

M module-gui/gui/widgets/status-bar/SIM.cpp => module-gui/gui/widgets/status-bar/SIM.cpp +7 -1
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "SIM.hpp"


@@ 31,6 31,12 @@ namespace gui::status_bar
            [[fallthrough]];
        case GSM::SIM::NONE:
            [[fallthrough]];
        case GSM::SIM::SIM_NEED_PIN:
            [[fallthrough]];
        case GSM::SIM::SIM_NEED_PUK:
            [[fallthrough]];
        case GSM::SIM::SIM_LOCKED:
            [[fallthrough]];
        case GSM::SIM::SIM_UNKNOWN:
            set(no_sim, style::status_bar::imageTypeSpecifier);
            break;

M module-services/service-cellular/include/service-cellular/api/common.hpp => module-services/service-cellular/include/service-cellular/api/common.hpp +2 -2
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


@@ 22,7 22,7 @@ namespace cellular
            Emergency
        };

        enum class SimLockState
        enum class SimPinState
        {
            Enabled,
            Disabled

M module-services/service-cellular/include/service-cellular/api/request/sim.hpp => module-services/service-cellular/include/service-cellular/api/request/sim.hpp +7 -7
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


@@ 23,9 23,9 @@ namespace cellular::msg::request::sim
        };
    };

    /** Get current state of PIN lock
    /** Get current state of settings PIN lock
     */
    struct GetLockState : public msg::Request
    struct GetPinSettings : public msg::Request
    {
        struct Response : public msg::Response
        {


@@ 86,16 86,16 @@ namespace cellular::msg::request::sim
     */
    struct SetPinLock : msg::Request
    {
        explicit SetPinLock(api::SimLockState lock, const api::SimCode &pin) : lock(lock), pin(pin)
        explicit SetPinLock(api::SimPinState pinLock, const api::SimCode &pin) : pinLock(pinLock), pin(pin)
        {}
        const api::SimLockState lock;
        const api::SimPinState pinLock;
        const api::SimCode pin;

        struct Response : msg::Response
        {
            explicit Response(bool retCode, api::SimLockState lock) : msg::Response(retCode), lock(lock)
            explicit Response(bool retCode, api::SimPinState pinLock) : msg::Response(retCode), pinLock(pinLock)
            {}
            const api::SimLockState lock;
            const api::SimPinState pinLock;
        };
    };
} // namespace cellular::msg::request::sim

M module-services/service-cellular/src/ServiceCellularPriv.cpp => module-services/service-cellular/src/ServiceCellularPriv.cpp +4 -4
@@ 86,12 86,12 @@ namespace cellular::internal
            simCard->handleSimCardSelected();
            return std::make_shared<request::sim::SetActiveSim::Response>(result);
        });
        owner->connect(typeid(request::sim::GetLockState), [&](sys::Message *) -> sys::MessagePointer {
        owner->connect(typeid(request::sim::GetPinSettings), [&](sys::Message *) -> sys::MessagePointer {
            if (!simCard->isSimCardInserted()) {
                owner->bus.sendMulticast<notification::SimNotInserted>();
                return sys::MessageNone{};
            }
            return std::make_shared<request::sim::GetLockState::Response>(simCard->handleIsPinLocked());
            return std::make_shared<request::sim::GetPinSettings::Response>(simCard->handleIsPinNeeded());
        });
        owner->connect(typeid(request::sim::ChangePin), [&](sys::Message *request) -> sys::MessagePointer {
            auto msg = static_cast<request::sim::ChangePin *>(request);


@@ 116,8 116,8 @@ namespace cellular::internal
                owner->bus.sendMulticast<notification::SimNotInserted>();
                return sys::MessageNone{};
            }
            return std::make_shared<request::sim::SetPinLock::Response>(simCard->handleSetPinLock(msg->pin, msg->lock),
                                                                        msg->lock);
            return std::make_shared<request::sim::SetPinLock::Response>(
                simCard->handleSetPinLock(msg->pin, msg->pinLock), msg->pinLock);
        });
        owner->connect(typeid(request::sim::PinUnlock), [&](sys::Message *request) -> sys::MessagePointer {
            auto msg = static_cast<request::sim::PinUnlock *>(request);

M module-services/service-cellular/src/SimCard.cpp => module-services/service-cellular/src/SimCard.cpp +24 -10
@@ 49,9 49,9 @@ namespace cellular
        bool SimCard::initialized() const
        {
            return (Store::GSM::get()->sim == Store::GSM::SIM::SIM1 &&
                    Store::GSM::get()->selected == Store::GSM::SIM::SIM1) ||
                    Store::GSM::get()->selected == Store::GSM::SelectedSIM::SIM1) ||
                   (Store::GSM::get()->sim == Store::GSM::SIM::SIM2 &&
                    Store::GSM::get()->selected == Store::GSM::SIM::SIM2);
                    Store::GSM::get()->selected == Store::GSM::SelectedSIM::SIM2);
        }

        void SimCard::setChannel(at::BaseChannel *channel)


@@ 61,7 61,8 @@ namespace cellular

        bool SimCard::handleSetActiveSim(api::SimSlot sim)
        {
            Store::GSM::get()->selected = static_cast<Store::GSM::SIM>(sim);
            Store::GSM::get()->selected =
                sim == api::SimSlot::SIM1 ? Store::GSM::SelectedSIM::SIM1 : Store::GSM::SelectedSIM::SIM2;
            bsp::cellular::sim::simSelect();
            bsp::cellular::sim::hotSwapTrigger();
            clearSimInsertedStatus();


@@ 69,9 70,9 @@ namespace cellular
            return true;
        }

        bool SimCard::handleIsPinLocked() const
        bool SimCard::handleIsPinNeeded() const
        {
            return isPinLocked();
            return isPinNeeded();
        }

        bool SimCard::handleChangePin(const api::SimCode &oldPin, const api::SimCode &pin)


@@ 88,10 89,10 @@ namespace cellular
            return processPinResult(supplyPuk(_puk, _pin));
        }

        bool SimCard::handleSetPinLock(const api::SimCode &pin, api::SimLockState lock)
        bool SimCard::handleSetPinLock(const api::SimCode &pin, api::SimPinState pinLock)
        {
            const auto _pin = internal::simCodeToString(pin);
            return processPinResult(setPinLock(_pin, lock == cellular::api::SimLockState::Enabled));
            return processPinResult(setPinLock(_pin, pinLock == cellular::api::SimPinState::Enabled));
        }

        bool SimCard::handlePinUnlock(const api::SimCode &pin)


@@ 131,7 132,18 @@ namespace cellular
            switch (state) {
            case at::SimState::Ready:
                if (initSimCard()) {
                    Store::GSM::get()->sim = Store::GSM::get()->selected;
                    switch (Store::GSM::get()->selected) {
                    case Store::GSM::SelectedSIM::SIM1:
                        Store::GSM::get()->sim = Store::GSM::SIM::SIM1;
                        break;
                    case Store::GSM::SelectedSIM::SIM2:
                        Store::GSM::get()->sim = Store::GSM::SIM::SIM2;
                        break;
                    case Store::GSM::SelectedSIM::NONE:
                        Store::GSM::get()->sim = Store::GSM::SIM::NONE;
                        break;
                    }

                    if (onSimReady)
                        onSimReady();
                }


@@ 146,6 158,7 @@ namespace cellular
            case at::SimState::SimPin:
                [[fallthrough]];
            case at::SimState::SimPin2: {
                Store::GSM::get()->sim = Store::GSM::SIM::SIM_NEED_PIN;
                if (auto pc = getAttemptsCounters(state == at::SimState::SimPin ? sim::Pin::PIN1 : sim::Pin::PIN2);
                    pc) {
                    if (pc.value().PukCounter != 0) {


@@ 161,6 174,7 @@ namespace cellular
            case at::SimState::SimPuk:
                [[fallthrough]];
            case at::SimState::SimPuk2: {
                Store::GSM::get()->sim = Store::GSM::SIM::SIM_NEED_PUK;
                if (auto pc = getAttemptsCounters(state == at::SimState::SimPuk ? sim::Pin::PIN1 : sim::Pin::PIN2);
                    pc) {
                    if (pc.value().PukCounter != 0) {


@@ 174,7 188,7 @@ namespace cellular
                break;
            }
            case at::SimState::Locked:
                Store::GSM::get()->sim = Store::GSM::SIM::SIM_FAIL;
                Store::GSM::get()->sim = Store::GSM::SIM::SIM_LOCKED;
                if (onSimBlocked)
                    onSimBlocked();
                break;


@@ 262,7 276,7 @@ namespace cellular
                               at::factory(at::AT::CLCK) + "\"SC\"," + (lock ? "1" : "0") + ",\"" + pin + "\"");
        }

        bool SimCard::isPinLocked() const
        bool SimCard::isPinNeeded() const
        {
            auto resp = channel->cmd(at::factory(at::AT::CLCK) + "\"SC\",2\r");
            int val   = 0;

M module-services/service-cellular/src/SimCard.hpp => module-services/service-cellular/src/SimCard.hpp +8 -7
@@ 84,10 84,10 @@ namespace cellular::service
         * Request message handlers
         */
        bool handleSetActiveSim(api::SimSlot sim);
        bool handleIsPinLocked() const;
        bool handleIsPinNeeded() const;
        bool handleChangePin(const api::SimCode &old_pin, const api::SimCode &pin);
        bool handleUnblockWithPuk(const api::SimCode &puk, const api::SimCode &pin);
        bool handleSetPinLock(const api::SimCode &pin, api::SimLockState lock);
        bool handleSetPinLock(const api::SimCode &pin, api::SimPinState pinLock);
        bool handlePinUnlock(const api::SimCode &pin);

        /**


@@ 173,6 173,11 @@ namespace cellular::service
        {
            return isSimSelected;
        }

        /** Read internal SIM state using CPIN AT commands
         */
        std::optional<at::SimState> simState() const;

        /**
         * Notification events
         */


@@ 229,11 234,7 @@ namespace cellular::service
        /** Check whether the pin needs to be provided, only for standard pin.
         * \return true if need pin to unlock SIM card functionality
         */
        bool isPinLocked() const;

        /** Read internal SIM state using CPIN AT commands
         */
        std::optional<at::SimState> simState() const;
        bool isPinNeeded() const;

        /** Process sim::Result from PIN lock/unlock operations
         * \param result result from operation (`sendCommand()`)

M module-utils/EventStore/EventStore.hpp => module-utils/EventStore/EventStore.hpp +11 -2
@@ 141,11 141,20 @@ namespace Store
        {
            SIM1 = static_cast<int>(hal::cellular::SimSlot::SIM1),
            SIM2 = static_cast<int>(hal::cellular::SimSlot::SIM2),
            SIM_NEED_PIN,
            SIM_NEED_PUK,
            SIM_LOCKED,
            SIM_FAIL,
            SIM_UNKNOWN,
            NONE,
        } sim      = SIM::SIM_UNKNOWN,
          selected = SIM::SIM1;
        } sim = SIM::SIM_UNKNOWN;

        enum class SelectedSIM
        {
            SIM1 = static_cast<int>(SIM::SIM1),
            SIM2 = static_cast<int>(SIM::SIM2),
            NONE,
        } selected = SelectedSIM::SIM1;

        bool simCardInserted();


M products/PurePhone/services/appmgr/ApplicationManager.cpp => products/PurePhone/services/appmgr/ApplicationManager.cpp +3 -1
@@ 248,6 248,8 @@ namespace app::manager
        connect(typeid(locks::ResetSimLockState), [&](sys::Message *request) -> sys::MessagePointer {
            return simLockHandler.handleResetSimLockStateRequest();
        });
        connect(typeid(locks::UnblockSim),
                [&](sys::Message *request) -> sys::MessagePointer { return simLockHandler.handleSimUnlockRequest(); });
        connect(typeid(cellular::msg::notification::SimNeedPuk), [&](sys::Message *request) -> sys::MessagePointer {
            auto data = static_cast<cellular::msg::notification::SimNeedPuk *>(request);
            if (phoneLockHandler.isPhoneLocked()) {


@@ 289,7 291,7 @@ namespace app::manager
                        return simLockHandler.handleSimPinLockStateMessage();
                    }
                    else {
                        if (data->lock == cellular::api::SimLockState::Enabled) {
                        if (data->pinLock == cellular::api::SimPinState::Enabled) {
                            return simLockHandler.handleSimPinLockEnableRequest();
                        }
                        else {

M products/PurePhone/sys/SystemManager.cpp => products/PurePhone/sys/SystemManager.cpp +2 -1
@@ 32,7 32,8 @@ namespace sys
    {
        auto activeSimSelected = []() {
            const auto storeGsm = Store::GSM::get();
            return ((storeGsm->selected == Store::GSM::SIM::SIM1 || storeGsm->selected == Store::GSM::SIM::SIM2) &&
            return ((storeGsm->selected == Store::GSM::SelectedSIM::SIM1 ||
                     storeGsm->selected == Store::GSM::SelectedSIM::SIM2) &&
                    storeGsm->simCardInserted());
        };
        auto isCallOngoing = [this]() {

M pure_changelog.md => pure_changelog.md +1 -0
@@ 10,6 10,7 @@
* Improve refreshing of the display.
* Fixed music files extension case sensitivity
* Fixed MTP issues
* Rebuilt SIM cards window

### Fixed
* Fixed incorrect total CPU usage in logs