~aleteoryx/muditaos

42426e3efedb46651a2df86affe743a0ab3e2a0c — Mateusz Grzegorzek 5 years ago b66d70e
[EGD-4736] Change PIN windows

Implement changing SIM PIN code flow
M image/assets/lang/English.json => image/assets/lang/English.json +2 -0
@@ 236,11 236,13 @@
  "app_desktop_info_mmi_result_failed": "Failed",
  "app_desktop_header_sim_setup": "<text><token>$SIM</token> setup</text>",
  "app_desktop_sim_enter_pin_unlock": "<text>Type current <token>$PINTYPE</token> code:</text>",
  "app_desktop_sim_change_pin": "Change PIN code",
  "app_desktop_sim_enter_new_pin": "Enter new PIN code:",
  "app_desktop_sim_confirm_new_pin": "Confirm new PIN code:",
  "app_desktop_sim_setup_wrong_pin_last_attempt": "<text>Wrong PIN code. You have<br></br>1 attempt left.</text>",
  "app_desktop_sim_setup_wrong_pin": "<text>Wrong PIN code. You have<br></br><token>$ATTEMPTS</token> attempts left.</text>",
  "app_desktop_sim_wrong_pin_confirmation": "Wrong PIN code.",
  "app_desktop_sim_pin_changed_successfully": "PIN code changed successfully",
  "app_desktop_sim_cme_error": "<text>SIM card<br></br>CME error:<token>$CMECODE</token></text>",
  "app_desktop_sim_puk_blocked": "<text>The SIM card is blocked.<br></br>Please, contact the operator.</text>",
  "app_desktop_sim_setup_enter_puk": "<text>The SIM card is blocked.<br></br>To unblock it, type the PUK code:</text>",

M module-apps/application-desktop/ApplicationDesktop.cpp => module-apps/application-desktop/ApplicationDesktop.cpp +40 -0
@@ 20,6 20,9 @@
#include "windows/MmiPushWindow.hpp"
#include "windows/MmiInternalMsgWindow.hpp"
#include "presenter/PowerOffPresenter.hpp"
#include <windows/Dialog.hpp>
#include <windows/DialogMetadata.hpp>
#include <messages/DialogMetadataMessage.hpp>

#include "AppWindow.hpp"
#include "data/LockPhoneData.hpp"


@@ 408,6 411,40 @@ namespace app
            return sys::msgHandled();
        });

        auto createPinChangedSuccessfullyDialog =
            [](app::ApplicationDesktop *app) -> std::unique_ptr<gui::DialogMetadataMessage> {
            return std::make_unique<gui::DialogMetadataMessage>(
                gui::DialogMetadata{utils::localize.get("app_desktop_sim_change_pin"),
                                    "big_circle_placeholder",
                                    utils::localize.get("app_desktop_sim_pin_changed_successfully"),
                                    "",
                                    [app]() {
                                        app->switchWindow(app::window::name::desktop_main_window);
                                        return true;
                                    }});
        };

        connect(typeid(CellularSimNewPinResponseMessage), [&](sys::Message *request) -> sys::MessagePointer {
            auto response = dynamic_cast<CellularSimNewPinResponseMessage *>(request);
            if (response->retCode) {
                auto metaData = createPinChangedSuccessfullyDialog(this);
                switchWindow(gui::window::name::dialog_confirm, gui::ShowMode::GUI_SHOW_INIT, std::move(metaData));
            }
            else {
                lockHandler.handlePinChangeRequestFailed();
            }
            return sys::MessageNone{};
        });

        connect(typeid(CellularSimPukResponseMessage), [&](sys::Message *request) -> sys::MessagePointer {
            auto response = dynamic_cast<CellularSimPukResponseMessage *>(request);
            if (response->retCode) {
                auto metaData = createPinChangedSuccessfullyDialog(this);
                switchWindow(gui::window::name::dialog_confirm, gui::ShowMode::GUI_SHOW_INIT, std::move(metaData));
            }
            return sys::MessageNone{};
        });

        auto msgToSend =
            std::make_shared<sdesktop::UpdateOsMessage>(updateos::UpdateMessageType::UpdateCheckForUpdateOnce);
        bus.sendUnicast(msgToSend, service::name::service_desktop);


@@ 492,6 529,9 @@ namespace app
        windowsFactory.attach(desktop_mmi_internal, [](Application *app, const std::string newname) {
            return std::make_unique<gui::MmiInternalMsgWindow>(app, desktop_mmi_internal);
        });
        windowsFactory.attach(gui::window::name::dialog_confirm, [](Application *app, const std::string &name) {
            return std::make_unique<gui::DialogConfirm>(app, name);
        });

        attachPopups({gui::popup::ID::Volume, gui::popup::ID::Tethering, gui::popup::ID::PhoneModes});
    }

M module-apps/application-desktop/widgets/PinLock.cpp => module-apps/application-desktop/widgets/PinLock.cpp +1 -1
@@ 1,4 1,4 @@
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "PinLock.hpp"

M module-apps/application-desktop/widgets/PinLockHandler.cpp => module-apps/application-desktop/widgets/PinLockHandler.cpp +25 -2
@@ 6,7 6,6 @@
#include "application-desktop/ApplicationDesktop.hpp"
#include "application-desktop/data/LockPhoneData.hpp"
#include "application-desktop/windows/Names.hpp"

#include <module-utils/common_data/EventStore.hpp>
#include <service-appmgr/service-appmgr/data/SimActionsParams.hpp>
#include <service-cellular/CellularMessage.hpp>


@@ 126,6 125,31 @@ namespace gui
        LOG_INFO("Handling RequestPinEnable action");
    }

    void PinLockHandler::handlePinChangeRequestFailed()
    {
        using namespace app::manager::actions;
        if (simLock.value > 0) {
            --simLock.value;
        }
        else {
            LOG_ERROR("Number of attempts left is equal to zero before decrementation!");
        }
        if (simLock.value > 0) {
            simLock.lockState        = PinLock::LockState::PasscodeInvalidRetryRequired;
            auto onActivatedCallback = [this](PinLock::LockType type, const std::vector<unsigned int> &data) {
                auto params = std::make_unique<PasscodeParams>(
                    Store::GSM::get()->selected, simLock.value, PasscodeParams::pinName);
                handlePinChangeRequest(std::move(params));
            };
            switchToPinLockWindow(PinLock::LockState::PasscodeInvalidRetryRequired, onActivatedCallback);
        }
        else {
            auto params = std::make_unique<PasscodeParams>(
                Store::GSM::get()->selected, PasscodeParams::numOfAttemptsForEnteringPUK, PasscodeParams::pukName);
            handlePasscodeRequest(gui::PinLock::LockType::SimPuk, std::move(params));
        }
    }

    void PinLockHandler::handleSimBlocked(app::manager::actions::ActionParamsPtr &&data)
    {
        LOG_DEBUG("Handling BlockSim action");


@@ 245,7 269,6 @@ namespace gui
                                                    const std::vector<unsigned int> &passcode,
                                                    const std::vector<unsigned int> &pin)
    {
        setSimLockHandled();
        if (type == PinLock::LockType::SimPin) {
            app->bus.sendUnicast(std::make_shared<CellularSimNewPinDataMessage>(simLock.sim, passcode, pin),
                                 serviceCellular);

M module-apps/application-desktop/widgets/PinLockHandler.hpp => module-apps/application-desktop/widgets/PinLockHandler.hpp +1 -0
@@ 55,6 55,7 @@ namespace gui
        void handleUnlockSim(app::manager::actions::ActionParamsPtr &&data);
        void handleCMEError(app::manager::actions::ActionParamsPtr &&data) const;
        void handleScreenPasscodeRequest(app::manager::actions::ActionParamsPtr &&data) const;
        void handlePinChangeRequestFailed();

        [[nodiscard]] auto isScreenLocked() const noexcept -> bool
        {

M module-apps/application-desktop/windows/PinLockWindow.cpp => module-apps/application-desktop/windows/PinLockWindow.cpp +8 -3
@@ 154,14 154,19 @@ namespace gui
        }
        else if (lockType == PinLock::LockType::SimPin) {
            LockBox = std::make_unique<SimLockBox>(this);
            setTitleBar(true, false);
            setText("app_desktop_header_sim_setup",
                    TextType::Title,
                    true,
                    {{getToken(Token::Sim), utils::enumToString(lock->getSim())}});
        }
        assert(LockBox != nullptr);
    }

    auto PinLockWindow::usesNumericKeys() const noexcept -> bool
    {
        return lock->isState(PinLock::LockState::PasscodeRequired) ||
               lock->isState(PinLock::LockState::NewPasscodeRequired) ||
               lock->isState(PinLock::LockState::NewPasscodeConfirmRequired);
        return lock && (lock->isState(PinLock::LockState::PasscodeRequired) ||
                        lock->isState(PinLock::LockState::NewPasscodeRequired) ||
                        lock->isState(PinLock::LockState::NewPasscodeConfirmRequired));
    }
} /* namespace gui */

M module-apps/application-desktop/windows/SimLockBox.cpp => module-apps/application-desktop/windows/SimLockBox.cpp +1 -1
@@ 1,4 1,4 @@
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "SimLockBox.hpp"

M module-apps/application-settings-new/windows/PINSettingsWindow.cpp => module-apps/application-settings-new/windows/PINSettingsWindow.cpp +8 -1
@@ 57,7 57,14 @@ namespace gui
        if (pinIsOn) {
            optionList.emplace_back(std::make_unique<option::OptionSettings>(
                utils::translateI18("app_settings_network_pin_change_code"),
                [=](Item & /*item*/) { return true; },
                [=](Item & /*item*/) {
                    using namespace app::manager::actions;
                    auto params = std::make_unique<PasscodeParams>(Store::GSM::get()->selected,
                                                                   PasscodeParams::numOfAttemptsForEnteringPIN,
                                                                   PasscodeParams::pinName);
                    app::manager::Controller::sendAction(application, RequestPinChange, std::move(params));
                    return true;
                },
                nullptr,
                nullptr,
                option::SettingRightItem::ArrowWhite));

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

#pragma once


@@ 26,6 26,12 @@ namespace app::manager::actions
        [[nodiscard]] Store::GSM::SIM getSim() const noexcept;
        [[nodiscard]] unsigned int getAttempts() const noexcept;
        [[nodiscard]] const std::string &getPasscodeName() const noexcept;

        static constexpr auto numOfAttemptsForEnteringPIN = 3u;
        static constexpr auto numOfAttemptsForEnteringPUK = 10u;

        static constexpr auto pinName = "PIN";
        static constexpr auto pukName = "PUK";
    };

    /** Action parameters for

M module-services/service-cellular/ServiceCellular.cpp => module-services/service-cellular/ServiceCellular.cpp +2 -2
@@ 349,7 349,7 @@ void ServiceCellular::registerMessageHandlers()

    connect(typeid(CellularSimNewPinDataMessage), [&](sys::Message *request) -> sys::MessagePointer {
        auto msg = static_cast<CellularSimNewPinDataMessage *>(request);
        return std::make_shared<CellularResponseMessage>(
        return std::make_shared<CellularSimNewPinResponseMessage>(
            changePin(SimCard::pinToString(msg->getOldPin()), SimCard::pinToString(msg->getNewPin())));
    });



@@ 1183,7 1183,7 @@ auto ServiceCellular::handleSimPukMessage(sys::Message *msgl) -> std::shared_ptr
    auto msgSimPuk = dynamic_cast<CellularSimPukDataMessage *>(msgl);
    if (msgSimPuk != nullptr) {
        LOG_DEBUG("Unlocking puk");
        return std::make_shared<CellularResponseMessage>(
        return std::make_shared<CellularSimPukResponseMessage>(
            unlockSimPuk(SimCard::pinToString(msgSimPuk->getPuk()), SimCard::pinToString(msgSimPuk->getNewPin())));
    }
    LOG_ERROR("Request message is not CellularSimPukDataMessage!");

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

#include "SimCard.hpp"

M module-services/service-cellular/service-cellular/CellularMessage.hpp => module-services/service-cellular/service-cellular/CellularMessage.hpp +14 -0
@@ 631,6 631,20 @@ class CellularResponseMessage : public sys::ResponseMessage
    std::string data;
};

class CellularSimNewPinResponseMessage : public CellularResponseMessage
{
  public:
    explicit CellularSimNewPinResponseMessage(bool retCode) : CellularResponseMessage(retCode)
    {}
};

class CellularSimPukResponseMessage : public CellularResponseMessage
{
  public:
    explicit CellularSimPukResponseMessage(bool retCode) : CellularResponseMessage(retCode)
    {}
};

class CellularAntennaResponseMessage : public sys::ResponseMessage
{
  public: