~aleteoryx/muditaos

bd1222fcc8dfe81ef24111bd1b85f914144113a9 — Marcin Zieliński 3 years ago ccce9bb
[MOS-350] Restored notifications about PIN changes

Made SimInfo pop-ups completely omitted when
going back to windows.

Fixed the SimUnlockInputRequestParams's
constructor.

Done a bit of refactor in the places of
interest, e.g. naming clarification.
M module-apps/ModuleApps.md => module-apps/ModuleApps.md +1 -0
@@ 120,6 120,7 @@ With this, we can:

**WARNING** In the MuditaOS a popup is a Window that can be shown any time on an action request.
**NOTE** `attachPopups` should be most probably moved to `manifest` and popup enum just removed
**NOTE** Pop-ups regarding SIM cards' presence/availability currently have some special logic regarding windows stack around them.

Popups weren't designed as a part of the system, but rather step by step integrated into it. While there should be no issue with partially overflowing popups in the applications and UI, it would mean major source code refactoring and planning.


M module-apps/application-settings/ApplicationSettings.cpp => module-apps/application-settings/ApplicationSettings.cpp +13 -19
@@ 82,6 82,7 @@
#include <module-services/service-evtmgr/service-evtmgr/EVMessages.hpp>
#include <service-appmgr/messages/Message.hpp>
#include <service-appmgr/model/ApplicationManagerCommon.hpp>
#include <apps-common/WindowsStack.hpp>
#include <apps-common/messages/DialogMetadataMessage.hpp>
#include <apps-common/windows/Dialog.hpp>
#include <apps-common/popups/lock-popups/SimInfoWindow.hpp>


@@ 576,31 577,24 @@ namespace app
        using namespace gui::popup::window;
        using namespace gui::window::name;

        if (!windowsStack().isWindowOnStack(sim_cards)) {
            return ApplicationCommon::returnToPreviousWindow();
        }

        auto previousWindowName = getPreviousWindow();
        if (!previousWindowName.has_value()) {
            ApplicationCommon::returnToPreviousWindow();
            return;
            return ApplicationCommon::returnToPreviousWindow();
        }

        bool previousWindowBackingToSimCards =
            (previousWindowName == sim_pin_settings || previousWindowName == import_contacts ||
             previousWindowName == sim_unlock_window);
        auto currentWindowName = getCurrentWindow()->getName();

        // despite "import_contacts" has auto-lock prevented, it's included here in previousWindowBackingToSimCards for
        // simplicity
        if ((currentWindowName == phone_lock_window || currentWindowName == sim_unlock_window) &&
            previousWindowBackingToSimCards) {
            switchWindow(sim_cards);
            return;
        auto backToSimCards = [this]() { switchWindow(sim_cards); };

        if (previousWindowName == sim_pin_settings || previousWindowName == import_contacts ||
            previousWindowName == sim_unlock_window || previousWindowName == sim_info_window) {
            return backToSimCards();
        }

        if (currentWindowName == sim_info_window) {
            auto simInfoWindowAction = static_cast<gui::SimInfoWindow *>(getCurrentWindow())->getAction();
            if (simInfoWindowAction == locks::SimInputTypeAction::Error && previousWindowBackingToSimCards) {
                switchWindow(sim_cards);
                return;
            }
        if (getCurrentWindow()->getName() == sim_info_window) {
            return backToSimCards();
        }

        ApplicationCommon::returnToPreviousWindow();

M module-apps/apps-common/ApplicationCommon.cpp => module-apps/apps-common/ApplicationCommon.cpp +30 -10
@@ 288,6 288,15 @@ namespace app
        }
        LOG_INFO("Back to previous window: %s", window->c_str());
        windowsStack().pop(*window);

        // MOS-350: SimInfo pop-us should be ignored in windows history - pop one window deeper
        auto const simInfoName = gui::popup::resolveWindowName(gui::popup::ID::SimInfo);
        if (window == simInfoName) {
            window = windowsStack().get(previousWindow);
            // SimInfo won't arrive with no preceding window, so no need to check the optional
            LOG_INFO("Previous window is %s - omit it and go one more back: %s", simInfoName.c_str(), window->c_str());
        }

        switchWindow(*window, gui::ShowMode::GUI_SHOW_RETURN);
    }



@@ 846,18 855,29 @@ namespace app

    bool ApplicationCommon::tryShowPopup()
    {
        using namespace gui::popup;

        auto request = windowsPopupQueue->popRequest(getPopupFilter());
        if (request) {
            const auto popup = magic_enum::enum_name(request->getPopupParams().getPopupId()).data();
            LOG_DEBUG("handling popup: %s", popup);
            /// request handle actually switches window to popup window
            auto retval = request->handle();
            if (not retval) {
                LOG_ERROR("Popup %s handling failure, please check registered blueprint!", popup);
            }
            return retval;
        if (!request) {
            return false;
        }
        return false;

        auto const id = request->getPopupParams().getPopupId();

        if (id == ID::SimInfo) {
            // MOS-350: silently get rid of the first occurence of SimLock pop-up and all subsequent windows
            windowsStack().drop(resolveWindowName(ID::SimLock));
        }

        auto const popup = magic_enum::enum_name(id).data();
        LOG_DEBUG("handling popup: %s", popup);
        /// request handle actually switches window to popup window
        auto retval = request->handle();
        if (not retval) {
            LOG_ERROR("Popup %s handling failure, please check registered blueprint!", popup);
        }

        return retval;
    }

    void ApplicationCommon::abortPopup(gui::popup::ID id)

M module-apps/apps-common/locks/handlers/SimLockHandler.cpp => module-apps/apps-common/locks/handlers/SimLockHandler.cpp +3 -3
@@ 176,7 176,7 @@ namespace locks
        return sys::msgHandled();
    }

    sys::MessagePointer SimLockHandler::handleSimAvailabilityMessage()
    sys::MessagePointer SimLockHandler::handleSimPinLockStateMessage()
    {
        lock.lockState = Lock::LockState::Unlocked;
        simInfoAction();


@@ 207,7 207,7 @@ namespace locks
        return sys::MessagePointer();
    }

    sys::MessagePointer SimLockHandler::handleSimEnableRequest()
    sys::MessagePointer SimLockHandler::handleSimPinLockEnableRequest()
    {
        setSimInputTypeAction(SimInputTypeAction::EnablePin);



@@ 218,7 218,7 @@ namespace locks
        return sys::msgHandled();
    }

    sys::MessagePointer SimLockHandler::handleSimDisableRequest()
    sys::MessagePointer SimLockHandler::handleSimPinLockDisableRequest()
    {
        setSimInputTypeAction(SimInputTypeAction::DisablePin);


M module-apps/apps-common/locks/handlers/SimLockHandler.hpp => module-apps/apps-common/locks/handlers/SimLockHandler.hpp +3 -3
@@ 59,14 59,14 @@ namespace locks
        sys::MessagePointer handleSimPukRequest(unsigned int attempts);
        sys::MessagePointer handleSimPinChangeRequest();
        sys::MessagePointer handleSimPinChangeFailedRequest();
        sys::MessagePointer handleSimEnableRequest();
        sys::MessagePointer handleSimDisableRequest();
        sys::MessagePointer handleSimPinLockEnableRequest();
        sys::MessagePointer handleSimPinLockDisableRequest();
        sys::MessagePointer handleResetSimLockStateRequest();
        sys::MessagePointer handleSimBlockedRequest();
        sys::MessagePointer handleCMEErrorRequest(unsigned int errorCode);
        sys::MessagePointer handleSimUnlockedMessage();
        sys::MessagePointer handleSimPinChangedMessage();
        sys::MessagePointer handleSimAvailabilityMessage();
        sys::MessagePointer handleSimPinLockStateMessage();
        sys::MessagePointer handleSimReadyMessage();
        sys::MessagePointer handleSimNotInsertedMessage();
        sys::MessagePointer handleSimNotRespondingMessage();

M module-apps/apps-common/popups/data/PopupRequestParams.hpp => module-apps/apps-common/popups/data/PopupRequestParams.hpp +3 -2
@@ 45,8 45,9 @@ namespace gui
                                    locks::Lock lock,
                                    locks::SimInputTypeAction simInputTypeAction,
                                    unsigned int errorCode = 0)
            : PopupRequestParams{popupId}, lock{std::move(lock)}, simInputTypeAction(simInputTypeAction),
              errorCode(errorCode)
            : PopupRequestParams(
                  popupId, {popup::Disposition::Priority::Normal, popup::Disposition::WindowType::Popup, popupId}),
              lock{std::move(lock)}, simInputTypeAction(simInputTypeAction), errorCode(errorCode)
        {}

        [[nodiscard]] auto getLock() const noexcept

M module-apps/apps-common/popups/lock-popups/SimInfoWindow.cpp => module-apps/apps-common/popups/lock-popups/SimInfoWindow.cpp +1 -2
@@ 33,8 33,7 @@ void SimInfoWindow::onBeforeShow(ShowMode mode, SwitchData *data)
    WindowWithTimer::onBeforeShow(mode, data);

    if (auto infoData = dynamic_cast<locks::SimLockData *>(data)) {
        action_ = infoData->getSimInputTypeAction();
        switch (action_.value()) {
        switch (infoData->getSimInputTypeAction()) {
        case locks::SimInputTypeAction::UnlockWithPuk:
        case locks::SimInputTypeAction::ChangePin:
            setTitle(utils::translate("sim_change_pin"));

M module-apps/apps-common/popups/lock-popups/SimInfoWindow.hpp => module-apps/apps-common/popups/lock-popups/SimInfoWindow.hpp +0 -9
@@ 6,7 6,6 @@
#include <popups/WindowWithTimer.hpp>
#include <Text.hpp>
#include <gui/widgets/Icon.hpp>
#include <locks/data/LockData.hpp>

namespace gui
{


@@ 20,13 19,5 @@ namespace gui
        void buildInterface() override;
        void onBeforeShow(ShowMode mode, SwitchData *data) override;
        status_bar::Configuration configureStatusBar(status_bar::Configuration appConfiguration) override;

        locks::SimInputTypeAction getAction() const
        {
            return action_.value();
        }

      private:
        std::optional<locks::SimInputTypeAction> action_;
    };
} /* namespace gui */

M module-apps/apps-common/popups/lock-popups/SimLockInputWindow.cpp => module-apps/apps-common/popups/lock-popups/SimLockInputWindow.cpp +1 -7
@@ 90,13 90,7 @@ namespace gui
                lock->consumeState();
            }
            application->getSimLockSubject().resetSimLockState();
            if (auto *settingsApp = dynamic_cast<app::ApplicationSettings *>(application);
                settingsApp && settingsApp->isPreviousWindow(gui::window::name::sim_pin_settings)) {
                settingsApp->switchWindow(gui::window::name::sim_cards);
            }
            else {
                application->returnToPreviousWindow();
            }
            application->returnToPreviousWindow();
            return true;
        }
        else if (inputEvent.is(KeyCode::KEY_PND)) {

M products/PurePhone/services/appmgr/ApplicationManager.cpp => products/PurePhone/services/appmgr/ApplicationManager.cpp +9 -7
@@ 275,22 275,24 @@ namespace app::manager
                        return simLockHandler.handleSimPinChangeFailedRequest();
                    }
                });
        connect(typeid(locks::EnableSimPin),
                [&](sys::Message *request) -> sys::MessagePointer { return simLockHandler.handleSimEnableRequest(); });
        connect(typeid(locks::DisableSimPin),
                [&](sys::Message *request) -> sys::MessagePointer { return simLockHandler.handleSimDisableRequest(); });
        connect(typeid(locks::EnableSimPin), [&](sys::Message *request) -> sys::MessagePointer {
            return simLockHandler.handleSimPinLockEnableRequest();
        });
        connect(typeid(locks::DisableSimPin), [&](sys::Message *request) -> sys::MessagePointer {
            return simLockHandler.handleSimPinLockDisableRequest();
        });
        connect(typeid(cellular::msg::request::sim::SetPinLock::Response),
                [&](sys::Message *request) -> sys::MessagePointer {
                    auto data = static_cast<cellular::msg::request::sim::SetPinLock::Response *>(request);
                    if (data->retCode) {
                        return simLockHandler.handleSimAvailabilityMessage();
                        return simLockHandler.handleSimPinLockStateMessage();
                    }
                    else {
                        if (data->lock == cellular::api::SimLockState::Enabled) {
                            return simLockHandler.handleSimEnableRequest();
                            return simLockHandler.handleSimPinLockEnableRequest();
                        }
                        else {
                            return simLockHandler.handleSimDisableRequest();
                            return simLockHandler.handleSimPinLockDisableRequest();
                        }
                    }
                });