From 42426e3efedb46651a2df86affe743a0ab3e2a0c Mon Sep 17 00:00:00 2001 From: Mateusz Grzegorzek Date: Thu, 1 Apr 2021 09:30:40 +0200 Subject: [PATCH] [EGD-4736] Change PIN windows Implement changing SIM PIN code flow --- image/assets/lang/English.json | 2 + .../ApplicationDesktop.cpp | 40 +++++++++++++++++++ .../application-desktop/widgets/PinLock.cpp | 2 +- .../widgets/PinLockHandler.cpp | 27 ++++++++++++- .../widgets/PinLockHandler.hpp | 1 + .../windows/PinLockWindow.cpp | 11 +++-- .../windows/SimLockBox.cpp | 2 +- .../windows/PINSettingsWindow.cpp | 9 ++++- .../service-appmgr/data/SimActionsParams.hpp | 8 +++- .../service-cellular/ServiceCellular.cpp | 4 +- module-services/service-cellular/SimCard.cpp | 2 +- .../service-cellular/CellularMessage.hpp | 14 +++++++ 12 files changed, 110 insertions(+), 12 deletions(-) diff --git a/image/assets/lang/English.json b/image/assets/lang/English.json index 1b7bb494c93c7caef48f6f26bac22c6d54616f9e..0978b144510d2cf43c8f64672af4ea6bd361a013 100644 --- a/image/assets/lang/English.json +++ b/image/assets/lang/English.json @@ -236,11 +236,13 @@ "app_desktop_info_mmi_result_failed": "Failed", "app_desktop_header_sim_setup": "$SIM setup", "app_desktop_sim_enter_pin_unlock": "Type current $PINTYPE code:", + "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": "Wrong PIN code. You have

1 attempt left.
", "app_desktop_sim_setup_wrong_pin": "Wrong PIN code. You have

$ATTEMPTS attempts left.
", "app_desktop_sim_wrong_pin_confirmation": "Wrong PIN code.", + "app_desktop_sim_pin_changed_successfully": "PIN code changed successfully", "app_desktop_sim_cme_error": "SIM card

CME error:$CMECODE
", "app_desktop_sim_puk_blocked": "The SIM card is blocked.

Please, contact the operator.
", "app_desktop_sim_setup_enter_puk": "The SIM card is blocked.

To unblock it, type the PUK code:
", diff --git a/module-apps/application-desktop/ApplicationDesktop.cpp b/module-apps/application-desktop/ApplicationDesktop.cpp index be33f13054420c709abfce0ac2bf9679a8a1b0ae..232ea6ef1be4d8f369c69def8d4c177ebb6e1708 100644 --- a/module-apps/application-desktop/ApplicationDesktop.cpp +++ b/module-apps/application-desktop/ApplicationDesktop.cpp @@ -20,6 +20,9 @@ #include "windows/MmiPushWindow.hpp" #include "windows/MmiInternalMsgWindow.hpp" #include "presenter/PowerOffPresenter.hpp" +#include +#include +#include #include "AppWindow.hpp" #include "data/LockPhoneData.hpp" @@ -408,6 +411,40 @@ namespace app return sys::msgHandled(); }); + auto createPinChangedSuccessfullyDialog = + [](app::ApplicationDesktop *app) -> std::unique_ptr { + return std::make_unique( + 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(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(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(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(app, desktop_mmi_internal); }); + windowsFactory.attach(gui::window::name::dialog_confirm, [](Application *app, const std::string &name) { + return std::make_unique(app, name); + }); attachPopups({gui::popup::ID::Volume, gui::popup::ID::Tethering, gui::popup::ID::PhoneModes}); } diff --git a/module-apps/application-desktop/widgets/PinLock.cpp b/module-apps/application-desktop/widgets/PinLock.cpp index 993ceb0ab8bfb6fe6c4954270e3566a38183702e..af4032e4a274581bf110dbf4a43054e12ea2ea85 100644 --- a/module-apps/application-desktop/widgets/PinLock.cpp +++ b/module-apps/application-desktop/widgets/PinLock.cpp @@ -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" diff --git a/module-apps/application-desktop/widgets/PinLockHandler.cpp b/module-apps/application-desktop/widgets/PinLockHandler.cpp index bbf00f9dee725cff731538d73238eec133ce1e4b..0c9f8c72a64faf33e166c8aad8512dc5854bc982 100644 --- a/module-apps/application-desktop/widgets/PinLockHandler.cpp +++ b/module-apps/application-desktop/widgets/PinLockHandler.cpp @@ -6,7 +6,6 @@ #include "application-desktop/ApplicationDesktop.hpp" #include "application-desktop/data/LockPhoneData.hpp" #include "application-desktop/windows/Names.hpp" - #include #include #include @@ -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 &data) { + auto params = std::make_unique( + Store::GSM::get()->selected, simLock.value, PasscodeParams::pinName); + handlePinChangeRequest(std::move(params)); + }; + switchToPinLockWindow(PinLock::LockState::PasscodeInvalidRetryRequired, onActivatedCallback); + } + else { + auto params = std::make_unique( + 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 &passcode, const std::vector &pin) { - setSimLockHandled(); if (type == PinLock::LockType::SimPin) { app->bus.sendUnicast(std::make_shared(simLock.sim, passcode, pin), serviceCellular); diff --git a/module-apps/application-desktop/widgets/PinLockHandler.hpp b/module-apps/application-desktop/widgets/PinLockHandler.hpp index 98c27a66284fb032ed2d2aed6de291afb1b1cddd..df7d218dfab33e213b517a37f7fde87171a1b196 100644 --- a/module-apps/application-desktop/widgets/PinLockHandler.hpp +++ b/module-apps/application-desktop/widgets/PinLockHandler.hpp @@ -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 { diff --git a/module-apps/application-desktop/windows/PinLockWindow.cpp b/module-apps/application-desktop/windows/PinLockWindow.cpp index 39edea9b763e5c3ff91dd7ea82e771354ed2f725..ff0c9d56898e101a0769e40fa2bc749c1d41035a 100644 --- a/module-apps/application-desktop/windows/PinLockWindow.cpp +++ b/module-apps/application-desktop/windows/PinLockWindow.cpp @@ -154,14 +154,19 @@ namespace gui } else if (lockType == PinLock::LockType::SimPin) { LockBox = std::make_unique(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 */ diff --git a/module-apps/application-desktop/windows/SimLockBox.cpp b/module-apps/application-desktop/windows/SimLockBox.cpp index dbd6f0e9a4514eef9628b6a7366ea4a1229e41ce..07a4730a724b9d1f659b2db8d1a00a91e493d0b4 100644 --- a/module-apps/application-desktop/windows/SimLockBox.cpp +++ b/module-apps/application-desktop/windows/SimLockBox.cpp @@ -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" diff --git a/module-apps/application-settings-new/windows/PINSettingsWindow.cpp b/module-apps/application-settings-new/windows/PINSettingsWindow.cpp index 546f1869e6a27422e5aee365fe0b831be88030be..6bf59219cbc26e651b956b2c3d3e171e1b232e1a 100644 --- a/module-apps/application-settings-new/windows/PINSettingsWindow.cpp +++ b/module-apps/application-settings-new/windows/PINSettingsWindow.cpp @@ -57,7 +57,14 @@ namespace gui if (pinIsOn) { optionList.emplace_back(std::make_unique( utils::translateI18("app_settings_network_pin_change_code"), - [=](Item & /*item*/) { return true; }, + [=](Item & /*item*/) { + using namespace app::manager::actions; + auto params = std::make_unique(Store::GSM::get()->selected, + PasscodeParams::numOfAttemptsForEnteringPIN, + PasscodeParams::pinName); + app::manager::Controller::sendAction(application, RequestPinChange, std::move(params)); + return true; + }, nullptr, nullptr, option::SettingRightItem::ArrowWhite)); diff --git a/module-services/service-appmgr/service-appmgr/data/SimActionsParams.hpp b/module-services/service-appmgr/service-appmgr/data/SimActionsParams.hpp index 0c16744e3d8a822e6725f6336e6b091c1f0929b6..aab59902868550d83c06e8c68f5b374e6788ce57 100644 --- a/module-services/service-appmgr/service-appmgr/data/SimActionsParams.hpp +++ b/module-services/service-appmgr/service-appmgr/data/SimActionsParams.hpp @@ -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 diff --git a/module-services/service-cellular/ServiceCellular.cpp b/module-services/service-cellular/ServiceCellular.cpp index 6ee53b3881e35942c633aeb902039e2feabaa470..2a820da9bfa2bdb690c6db8f9c62d499b73963a1 100644 --- a/module-services/service-cellular/ServiceCellular.cpp +++ b/module-services/service-cellular/ServiceCellular.cpp @@ -349,7 +349,7 @@ void ServiceCellular::registerMessageHandlers() connect(typeid(CellularSimNewPinDataMessage), [&](sys::Message *request) -> sys::MessagePointer { auto msg = static_cast(request); - return std::make_shared( + return std::make_shared( 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(msgl); if (msgSimPuk != nullptr) { LOG_DEBUG("Unlocking puk"); - return std::make_shared( + return std::make_shared( unlockSimPuk(SimCard::pinToString(msgSimPuk->getPuk()), SimCard::pinToString(msgSimPuk->getNewPin()))); } LOG_ERROR("Request message is not CellularSimPukDataMessage!"); diff --git a/module-services/service-cellular/SimCard.cpp b/module-services/service-cellular/SimCard.cpp index 905e43816bc0700e7484ae540b5312a762d2fe5d..4b15f7e25b03bb780c67bd586cc3b3c9a7287e8d 100644 --- a/module-services/service-cellular/SimCard.cpp +++ b/module-services/service-cellular/SimCard.cpp @@ -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" diff --git a/module-services/service-cellular/service-cellular/CellularMessage.hpp b/module-services/service-cellular/service-cellular/CellularMessage.hpp index d9bc7e7bae319ef293e61e564124a2d2129311f1..786e8f72f0f6badca9479b9fbf474516bd1eb9f3 100644 --- a/module-services/service-cellular/service-cellular/CellularMessage.hpp +++ b/module-services/service-cellular/service-cellular/CellularMessage.hpp @@ -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: