~aleteoryx/muditaos

bc6eda40833b26140da2d2ec8234bdb73440061b — Maciej-Mudita 3 years ago 9c71684
[MOS-800] Add a popup for changing the SIM card

Sometimes the process of changing the SIM card
takes a few seconds and the user needs to be informed
that something is going on in the background.
M image/assets/lang/Deutsch.json => image/assets/lang/Deutsch.json +2 -0
@@ 265,6 265,8 @@
  "sim_setup_wrong_pin_last_attempt": "<text>Falscher PIN-Code. <br></br>1 Versuch übrig.</text>",
  "sim_wrong_pin_confirmation": "Falscher PIN-Code.",
  "sim_pin_changed_successfully": "PIN-Code erfolgreich geändert",
  "sim_card_changed_successfully": "SIM-Karte erfolgreich geändert.",
  "sim_card_change_in_progress": "<text>SIM-Wechselvorgang läuft.<br></br>Es dauert bis zu ein paar Sekunden.</text>",
  "sim_cme_error": "<text>SIM-Karte<br></br>CME-Fehler:<token>$CMECODE</token></text>",
  "sim_puk_blocked": "<text>Die SIM-Karte ist gesperrt.<br></br>Bitte kontaktieren Sie den Betreiber.</text>",
  "sim_setup_enter_puk": "<text>Die SIM-Karte ist gesperrt.<br></br>Zum Entsperren PUK-Code eingeben:</text>",

M image/assets/lang/English.json => image/assets/lang/English.json +2 -0
@@ 232,6 232,8 @@
  "sim_setup_wrong_pin_last_attempt": "<text>Wrong PIN code. You have<br></br>1 attempt left.</text>",
  "sim_wrong_pin_confirmation": "Wrong PIN code.",
  "sim_pin_changed_successfully": "PIN code changed successfully",
  "sim_card_changed_successfully": "SIM card changed successfully.",
  "sim_card_change_in_progress": "<text>SIM change process in progress.<br></br>It will take up to a few seconds.</text>",
  "sim_cme_error": "<text>SIM card<br></br>CME error:<token>$CMECODE</token></text>",
  "sim_puk_blocked": "<text>The SIM card is blocked.<br></br>Please, contact the operator.</text>",
  "sim_setup_enter_puk": "<text>The SIM card is blocked.<br></br>To unblock it, type the PUK code:</text>",

M image/assets/lang/Espanol.json => image/assets/lang/Espanol.json +2 -0
@@ 265,6 265,8 @@
  "sim_setup_wrong_pin_last_attempt": "<text>Código PIN incorrecto. Te queda<br></br>1 intento.</text>",
  "sim_wrong_pin_confirmation": "Código PIN incorrecto.",
  "sim_pin_changed_successfully": "El código PIN se ha cambiado con éxito.",
  "sim_card_changed_successfully": "La tarjeta SIM se ha cambiado con éxito.",
  "sim_card_change_in_progress": "<text>Proceso de cambio de SIM en curso.<br></br>Tarda unos segundos.</text>",
  "sim_cme_error": "<text>Tarjeta SIM<br></br>Error CME:<token>$CMECODE</token></text>",
  "sim_puk_blocked": "<text>La tarjeta SIM está bloqueada.<br></br>Ponte en contacto con tu operador.</text>",
  "sim_setup_enter_puk": "<text>La tarjeta SIM está bloqueada.<br></br>Para desbloquearla, introduce el código PUK:</text>",

M image/assets/lang/Francais.json => image/assets/lang/Francais.json +2 -0
@@ 234,6 234,8 @@
  "sim_setup_wrong_pin_last_attempt": "<text>Mauvais code. Il ne vous reste<br></br>qu'une seule tentative.</text>",
  "sim_wrong_pin_confirmation": "Mauvais code.",
  "sim_pin_changed_successfully": "Le code a bien été modifié.",
  "sim_card_changed_successfully": "La carte SIM a bien été modifié.",
  "sim_card_change_in_progress": "<text>Processus de changement de carte SIM en cours.<br></br>Cela prend quelques secondes.</text>",
  "sim_cme_error": "<text>SIM card<br></br>CME error:<token>$CMECODE</token></text>",
  "sim_puk_blocked": "<text>La carte SIM est bloquée.<br></br>Veuillez contacter l'opérateur.</text>",
  "sim_setup_enter_puk": "<text>La carte SIM est bloquée.<br></br>Pour la débloquer, saisissez le code PUK :</text>",

M image/assets/lang/Polski.json => image/assets/lang/Polski.json +2 -0
@@ 276,6 276,8 @@
  "sim_setup_wrong_pin_last_attempt": "<text>Błędny kod PIN. Pozostała ci<br></br>1 próba.</text>",
  "sim_wrong_pin_confirmation": "Błędny kod PIN.",
  "sim_pin_changed_successfully": "Pomyślnie zmieniono kod PIN",
  "sim_card_changed_successfully": "Pomyślnie zmieniono kartę SIM.",
  "sim_card_change_in_progress": "<text>Proces zmiany karty SIM w toku.<br></br>Może to potrwać kilka sekund.</text>",
  "sim_cme_error": "<text>Błąd CME<br></br>karty SIM:<token>$CMECODE</token></text>",
  "sim_puk_blocked": "<text>Karta SIM jest zablokowana.<br></br>Skontaktuj się z operatorem.</text>",
  "sim_setup_enter_puk": "<text>Karta SIM jest zablokowana.<br></br>Aby odblokować, wprowadź kod PUK:</text>",

M module-apps/application-onboarding/windows/OnBoardingSimSelectWindow.cpp => module-apps/application-onboarding/windows/OnBoardingSimSelectWindow.cpp +3 -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 "OnBoardingSimSelectWindow.hpp"


@@ 49,6 49,7 @@ namespace app::onBoarding
            "SIM1",
            [=](const gui::Item &item) {
                application->getSimLockSubject().setSim(cellular::api::SimSlot::SIM1);
                application->switchWindow(gui::popup::window::sim_switching_window);
                return true;
            },
            nullptr,


@@ 59,6 60,7 @@ namespace app::onBoarding
            "SIM2",
            [=](const gui::Item &item) {
                application->getSimLockSubject().setSim(cellular::api::SimSlot::SIM2);
                application->switchWindow(gui::popup::window::sim_switching_window);
                return true;
            },
            nullptr,

M module-apps/application-settings/windows/network/SimCardsWindow.cpp => module-apps/application-settings/windows/network/SimCardsWindow.cpp +1 -0
@@ 152,6 152,7 @@ namespace gui
    {
        selectedSim == Store::GSM::SelectedSIM::SIM1 ? simParams->setSelectedSim(Store::GSM::SelectedSIM::SIM2)
                                                     : simParams->setSelectedSim(Store::GSM::SelectedSIM::SIM1);
        this->application->switchWindow(gui::popup::window::sim_switching_window);
        return true;
    }


M module-apps/apps-common/locks/data/SimLockMessages.hpp => module-apps/apps-common/locks/data/SimLockMessages.hpp +2 -0
@@ 53,4 53,6 @@ namespace locks
    class UnblockSim : public sys::DataMessage
    {};

    class SimSwitched : public sys::DataMessage
    {};
} // namespace locks

M module-apps/apps-common/locks/handlers/SimLockHandler.cpp => module-apps/apps-common/locks/handlers/SimLockHandler.cpp +40 -2
@@ 49,6 49,9 @@ namespace locks
    void SimLockHandler::simErrorAction(unsigned int errorCode)
    {
        app::manager::Controller::sendAction(owner,
                                             app::manager::actions::AbortPopup,
                                             std::make_unique<gui::PopupRequestParams>(gui::popup::ID::SimSwitching));
        app::manager::Controller::sendAction(owner,
                                             app::manager::actions::ShowPopup,
                                             std::make_unique<gui::SimUnlockInputRequestParams>(
                                                 gui::popup::ID::SimLock, lock, simInputTypeAction, errorCode));


@@ 64,6 67,9 @@ namespace locks
    void SimLockHandler::simNotReadyAction()
    {
        app::manager::Controller::sendAction(owner,
                                             app::manager::actions::AbortPopup,
                                             std::make_unique<gui::PopupRequestParams>(gui::popup::ID::SimSwitching));
        app::manager::Controller::sendAction(owner,
                                             app::manager::actions::ShowPopup,
                                             std::make_unique<gui::PopupRequestParams>(gui::popup::ID::SimNotReady));
    }


@@ 77,6 83,9 @@ namespace locks

    void SimLockHandler::simInfoAction()
    {
        app::manager::Controller::sendAction(owner,
                                             app::manager::actions::AbortPopup,
                                             std::make_unique<gui::PopupRequestParams>(gui::popup::ID::SimSwitching));
        app::manager::Controller::sendAction(
            owner,
            app::manager::actions::ShowPopup,


@@ 113,7 122,7 @@ namespace locks
        lock.attemptsLeft = attempts;
        lock.lockName     = utils::enumToString(Store::GSM::get()->selected);

        if (simUnlockingNeeded_) {
        if (simUnlockingNeeded_ || simSwitching) {
            return sys::msgNotHandled();
        }



@@ 134,7 143,7 @@ namespace locks
        lock.attemptsLeft = attempts;
        lock.lockName     = utils::enumToString(Store::GSM::get()->selected);

        if (simUnlockingNeeded_) {
        if (simUnlockingNeeded_ || simSwitching) {
            return sys::msgNotHandled();
        }



@@ 412,4 421,33 @@ namespace locks
        return sys::msgHandled();
    }

    sys::MessagePointer SimLockHandler::handleSimSwitchingMessage(cellular::api::SimSlot simSlot)
    {
        simSwitching = true;
        setSim(simSlot);
        return sys::msgHandled();
    }

    sys::MessagePointer SimLockHandler::handleSimSwitchedMessage()
    {
        auto retValue = sys::msgHandled();
        simSwitching  = false;
        auto simState = Store::GSM::get()->sim;
        switch (simState) {
        case Store::GSM::SIM::SIM_LOCKED:
        case Store::GSM::SIM::SIM_NEED_PIN:
        case Store::GSM::SIM::SIM_NEED_PUK:
            retValue = handleSimUnlockRequest();
            break;
        case Store::GSM::SIM::NONE:
        case Store::GSM::SIM::SIM1:
        case Store::GSM::SIM::SIM2:
        case Store::GSM::SIM::SIM_FAIL:
        case Store::GSM::SIM::SIM_UNKNOWN:
            retValue = sys::msgHandled();
            break;
        }
        return retValue;
    }

} // namespace locks

M module-apps/apps-common/locks/handlers/SimLockHandler.hpp => module-apps/apps-common/locks/handlers/SimLockHandler.hpp +4 -1
@@ 24,11 24,13 @@ namespace locks
        unsigned int storedErrorCode          = 0;
        bool simUnlockingNeeded_              = false;
        bool simReady                         = false;
        bool simSwitching                     = false;
        StoredLockInput storedFirstInput;
        StoredLockInput storedSecondInput;

        void clearStoredInputs();
        void setSimInputTypeAction(SimInputTypeAction _simInputTypeAction);
        void setSim(cellular::api::SimSlot simSlot);

        void simInputRequiredAction();
        void simErrorAction(unsigned int errorCode);


@@ 71,9 73,10 @@ namespace locks
        sys::MessagePointer handleSimNotInsertedMessage();
        sys::MessagePointer handleSimNotRespondingMessage();
        sys::MessagePointer handleSimUnlockRequest();
        sys::MessagePointer handleSimSwitchingMessage(cellular::api::SimSlot simSlot);
        sys::MessagePointer handleSimSwitchedMessage();

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

} // namespace locks

M module-apps/apps-common/locks/handlers/SimLockSubject.cpp => module-apps/apps-common/locks/handlers/SimLockSubject.cpp +5 -0
@@ 50,4 50,9 @@ namespace locks
    {
        owner->bus.sendUnicast(std::make_shared<UnblockSim>(), service::name::appmgr);
    }

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

M module-apps/apps-common/locks/handlers/SimLockSubject.hpp => module-apps/apps-common/locks/handlers/SimLockSubject.hpp +1 -0
@@ 25,6 25,7 @@ namespace locks
        void disableSimPin();
        void verifyInput(LockInput inputData);
        void unblockSim();
        void simSwitched();
    };

} // namespace locks

M module-apps/apps-common/popups/CMakeLists.txt => module-apps/apps-common/popups/CMakeLists.txt +2 -0
@@ 26,6 26,7 @@ target_sources(apps-common
		lock-popups/SimLockInputWindow.cpp
		lock-popups/SimInfoWindow.cpp
		lock-popups/SimNotReadyWindow.cpp
		lock-popups/SimSwitchingWindow.cpp
		lock-popups/phone-lock-wallpapers/WallpaperBase.cpp
		lock-popups/phone-lock-wallpapers/WallpaperClock.cpp
		lock-popups/phone-lock-wallpapers/WallpaperQuote.cpp


@@ 56,6 57,7 @@ target_sources(apps-common
		lock-popups/SimLockInputWindow.hpp
		lock-popups/SimInfoWindow.hpp
		lock-popups/SimNotReadyWindow.hpp
		lock-popups/SimSwitchingWindow.hpp
		lock-popups/phone-lock-wallpapers/WallpaperBase.hpp
		lock-popups/phone-lock-wallpapers/WallpaperClock.hpp
		lock-popups/phone-lock-wallpapers/WallpaperQuote.hpp

M module-apps/apps-common/popups/Popups.cpp => module-apps/apps-common/popups/Popups.cpp +2 -0
@@ 38,6 38,8 @@ namespace gui::popup
            return gui::popup::window::sim_info_window;
        case ID::SimNotReady:
            return gui::popup::window::sim_not_ready_window;
        case ID::SimSwitching:
            return gui::popup::window::sim_switching_window;
        case ID::AlarmActivated:
            return gui::popup::window::alarm_activated_window;
        case ID::AlarmDeactivated:

M module-apps/apps-common/popups/Popups.hpp => module-apps/apps-common/popups/Popups.hpp +2 -0
@@ 25,6 25,7 @@ namespace gui
            SimLock,
            SimInfo,
            SimNotReady,
            SimSwitching,
            AlarmActivated,
            AlarmDeactivated,
            Alarm,


@@ 53,6 54,7 @@ namespace gui
            inline constexpr auto sim_unlock_window                 = "SimUnlockPopup";
            inline constexpr auto sim_info_window                   = "SimInfoPopup";
            inline constexpr auto sim_not_ready_window              = "SimNotReadyPopup";
            inline constexpr auto sim_switching_window              = "SimSwitchingPopup";
            inline constexpr auto alarm_activated_window            = "AlarmActivatedPopup";
            inline constexpr auto alarm_deactivated_window          = "AlarmDeactivatedPopup";
            inline constexpr auto alarm_window                      = "AlarmPopup";

A module-apps/apps-common/popups/lock-popups/SimSwitchingWindow.cpp => module-apps/apps-common/popups/lock-popups/SimSwitchingWindow.cpp +89 -0
@@ 0,0 1,89 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "SimSwitchingWindow.hpp"

#include <Application.hpp>
#include <EventStore.hpp>

namespace constants
{
    constexpr auto timerName = "SimSwitchingTimer";
    inline constexpr std::chrono::seconds timerStartInterval{3};
    inline constexpr std::chrono::seconds timerRepeatInterval{1};
    inline constexpr std::chrono::seconds maxDurationTime{10};
} // namespace constants

namespace gui
{
    SimSwitchingWindow::SimSwitchingWindow(app::ApplicationCommon *app, const std::string &name)
        : WindowWithTimer(app, name)
    {
        buildInterface();
        auto startTime = std::chrono::steady_clock::now();
        timerCallback  = [this, name, startTime](Item &, sys::Timer &timer) {
            if (application->getCurrentWindow()->getName() == name) {
                auto simState = Store::GSM::get()->sim;

                if (switchedSuccessful) {
                    application->getSimLockSubject().simSwitched();
                    application->returnToPreviousWindow();
                }
                else {
                    switch (simState) {
                    case Store::GSM::SIM::SIM1:
                    case Store::GSM::SIM::SIM2:
                    case Store::GSM::SIM::SIM_NEED_PIN:
                    case Store::GSM::SIM::SIM_NEED_PUK:
                    case Store::GSM::SIM::SIM_LOCKED:
                        switchedSuccessful = true;
                        resetTimer(constants::timerStartInterval);
                        updateInterface();
                        application->refreshWindow(RefreshModes::GUI_REFRESH_FAST);
                        break;
                    case Store::GSM::SIM::NONE:
                    case Store::GSM::SIM::SIM_FAIL:
                    case Store::GSM::SIM::SIM_UNKNOWN:
                        if (std::chrono::steady_clock::now() - startTime >= constants::maxDurationTime) {
                            LOG_INFO("The SIM switch operation failed. We return to the previous window.");
                            application->getSimLockSubject().simSwitched();
                            application->returnToPreviousWindow();
                        }
                        else {
                            resetTimer(constants::timerRepeatInterval);
                        }
                        break;
                    }
                }
                return true;
            }
            else {
                return false;
            }
        };
        resetTimer(constants::timerStartInterval);
    }

    void SimSwitchingWindow::buildInterface()
    {
        AppWindow::buildInterface();
        setTitle(utils::translate("app_settings_network_sim_cards"));
        infoIcon = new gui::Icon(this,
                                 style::window::default_left_margin,
                                 style::window::default_vertical_pos,
                                 style::window::default_body_width,
                                 style::window::default_body_height,
                                 "progress_128px_W_G",
                                 utils::translate("sim_card_change_in_progress"));
        infoIcon->setAlignment(Alignment::Horizontal::Center);
    }

    void SimSwitchingWindow::updateInterface()
    {
        setTitle(utils::translate(switchedSuccessful ? "app_settings_net" : "app_settings_network_sim_cards"));
        infoIcon->text->setRichText(
            utils::translate(switchedSuccessful ? "sim_card_changed_successfully" : "sim_card_change_in_progress"));
        infoIcon->image->set(switchedSuccessful ? "success_128px_W_G" : "progress_128px_W_G");
    }

} // namespace gui

A module-apps/apps-common/popups/lock-popups/SimSwitchingWindow.hpp => module-apps/apps-common/popups/lock-popups/SimSwitchingWindow.hpp +25 -0
@@ 0,0 1,25 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <popups/WindowWithTimer.hpp>
#include <Timers/TimerHandle.hpp>
#include <gui/widgets/Icon.hpp>

namespace gui
{
    class SimSwitchingWindow : public WindowWithTimer
    {
      private:
        Icon *infoIcon{nullptr};
        bool switchedSuccessful{false};

        void updateInterface();

      public:
        SimSwitchingWindow(app::ApplicationCommon *app, const std::string &name);

        void buildInterface() override;
    };
} // namespace gui

M products/PurePhone/apps/Application.cpp => products/PurePhone/apps/Application.cpp +6 -0
@@ 19,6 19,7 @@
#include <popups/lock-popups/SimLockInputWindow.hpp>
#include <popups/lock-popups/SimInfoWindow.hpp>
#include <popups/lock-popups/SimNotReadyWindow.hpp>
#include <popups/lock-popups/SimSwitchingWindow.hpp>
#include <service-db/agents/settings/SystemSettings.hpp>

namespace app


@@ 108,6 109,7 @@ namespace app
            case ID::SimLock:
            case ID::SimInfo:
            case ID::SimNotReady:
            case ID::SimSwitching:
                windowsFactory.attach(window::sim_unlock_window, [](ApplicationCommon *app, const std::string &name) {
                    return std::make_unique<gui::SimLockInputWindow>(app, window::sim_unlock_window);
                });


@@ 118,6 120,10 @@ namespace app
                    window::sim_not_ready_window, [](ApplicationCommon *app, const std::string &name) {
                        return std::make_unique<gui::SimNotReadyWindow>(app, window::sim_not_ready_window);
                    });
                windowsFactory.attach(
                    window::sim_switching_window, [](ApplicationCommon *app, const std::string &name) {
                        return std::make_unique<gui::SimSwitchingWindow>(app, window::sim_switching_window);
                    });
                break;
            case ID::Alarm:
                windowsFactory.attach(window::alarm_window, [](ApplicationCommon *app, const std::string &name) {

M products/PurePhone/services/appmgr/ApplicationManager.cpp => products/PurePhone/services/appmgr/ApplicationManager.cpp +4 -2
@@ 317,8 317,10 @@ namespace app::manager
        });
        connect(typeid(locks::SetSim), [&](sys::Message *request) -> sys::MessagePointer {
            auto data = static_cast<locks::SetSim *>(request);
            simLockHandler.setSim(data->getSimSlot());
            return sys::msgHandled();
            return simLockHandler.handleSimSwitchingMessage(data->getSimSlot());
        });
        connect(typeid(locks::SimSwitched), [&](sys::Message *request) -> sys::MessagePointer {
            return simLockHandler.handleSimSwitchedMessage();
        });
        connect(typeid(cellular::msg::request::sim::SetActiveSim::Response),
                [&](sys::Message *request) -> sys::MessagePointer {

M pure_changelog.md => pure_changelog.md +1 -0
@@ 41,6 41,7 @@
* Fixed disappearing "confirm" button in PIN entering screen

### Added
* Added a popup for changing the SIM card
* Added tethering information on the status bar
* Added basic MMS handling
* Added run-time statistics for tasks