~aleteoryx/muditaos

4b35b13fe9951db347c214a3cc4503af0fe5f850 — Pawel Olejniczak 5 years ago 5499640
[EGD-4734] Add PIN settings window

This window displays switch button for
disabling/enabling pin code for sim card.
Its also starting point for changing pin code.
Added actions for enabling and disabling
pin code for sim card.
Added method for checking if pin code is
set for sim card.
M image/assets/lang/English.json => image/assets/lang/English.json +3 -0
@@ 425,6 425,9 @@
  "app_settings_network_active_card": "Active card",
  "app_settings_network_operator_auto_select": "Operator auto-select",
  "app_settings_network_all_operators": "All operators",
  "app_settings_network_pin_settings": "PIN settings",
  "app_settings_network_pin": "PIN",
  "app_settings_network_pin_change_code": "Change PIN code",
  "app_settings_network_import_contacts_from_sim_card": "Import contacts from SIM card",
  "app_settings_network_sim1": "SIM1",
  "app_settings_network_sim2": "SIM2",

M module-apps/application-desktop/ApplicationDesktop.cpp => module-apps/application-desktop/ApplicationDesktop.cpp +10 -0
@@ 100,6 100,16 @@ namespace app
            return actionHandled();
        });

        addActionReceiver(app::manager::actions::RequestPinDisable, [this](auto &&data) {
            lockHandler.handlePinDisableRequest(std::forward<decltype(data)>(data));
            return actionHandled();
        });

        addActionReceiver(app::manager::actions::RequestPinEnable, [this](auto &&data) {
            lockHandler.handlePinEnableRequest(std::forward<decltype(data)>(data));
            return actionHandled();
        });

        addActionReceiver(app::manager::actions::BlockSim, [this](auto &&data) {
            lockHandler.handleSimBlocked(std::move(data));
            return actionHandled();

M module-apps/application-desktop/ApplicationDesktop.hpp => module-apps/application-desktop/ApplicationDesktop.hpp +2 -0
@@ 120,6 120,8 @@ namespace app
                     manager::actions::RequestPin,
                     manager::actions::RequestPuk,
                     manager::actions::RequestPinChange,
                     manager::actions::RequestPinDisable,
                     manager::actions::RequestPinEnable,
                     manager::actions::RequestScreenPasscode,
                     manager::actions::UnlockSim,
                     manager::actions::BlockSim,

M module-apps/application-desktop/widgets/PinLock.hpp => module-apps/application-desktop/widgets/PinLock.hpp +3 -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


@@ 32,6 32,8 @@ namespace gui
            NewPasscodeInvalidRetryRequired,
            NewPasscodeConfirmRequired,
            NewPasscodeInvalid,
            PinLockDisableRequired,
            PinLockEnableRequired,
            ErrorOccurred
        };


M module-apps/application-desktop/widgets/PinLockHandler.cpp => module-apps/application-desktop/widgets/PinLockHandler.cpp +10 -0
@@ 116,6 116,16 @@ namespace gui
        switchToPinLockWindow(onActivatedCallback);
    }

    void PinLockHandler::handlePinDisableRequest(app::manager::actions::ActionParamsPtr &&data)
    {
        LOG_INFO("Handling RequestPinDisable action");
    }

    void PinLockHandler::handlePinEnableRequest(app::manager::actions::ActionParamsPtr &&data)
    {
        LOG_INFO("Handling RequestPinEnable action");
    }

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

M module-apps/application-desktop/widgets/PinLockHandler.hpp => module-apps/application-desktop/widgets/PinLockHandler.hpp +2 -0
@@ 49,6 49,8 @@ namespace gui

        void handlePasscodeRequest(PinLock::LockType type, app::manager::actions::ActionParamsPtr &&data);
        void handlePinChangeRequest(app::manager::actions::ActionParamsPtr &&data);
        void handlePinDisableRequest(app::manager::actions::ActionParamsPtr &&data);
        void handlePinEnableRequest(app::manager::actions::ActionParamsPtr &&data);
        void handleSimBlocked(app::manager::actions::ActionParamsPtr &&data);
        void handleUnlockSim(app::manager::actions::ActionParamsPtr &&data);
        void handleCMEError(app::manager::actions::ActionParamsPtr &&data) const;

M module-apps/application-settings-new/ApplicationSettings.cpp => module-apps/application-settings-new/ApplicationSettings.cpp +15 -0
@@ 38,6 38,7 @@
#include "windows/ChangeTimeZone.hpp"
#include "windows/ChangeDateAndTimeWindow.hpp"
#include "windows/PhoneModesWindow.hpp"
#include "windows/PINSettingsWindow.hpp"
#include "windows/DoNotDisturbWindow.hpp"
#include "windows/OfflineWindow.hpp"
#include "windows/ConnectionFrequencyWindow.hpp"


@@ 67,6 68,7 @@
#include <application-settings-new/data/DeviceData.hpp>
#include <application-settings-new/data/LanguagesData.hpp>
#include <application-settings-new/data/PhoneNameData.hpp>
#include <application-settings-new/data/PINSettingsLockStateData.hpp>
#include <module-services/service-db/agents/settings/SystemSettings.hpp>
#include <service-db/Settings.hpp>



@@ 297,6 299,16 @@ namespace app
            return sys::MessageNone{};
        });

        connect(typeid(CellularSimCardPinLockStateResponseDataMessage), [&](sys::Message *msg) {
            auto simCardPinLockState = dynamic_cast<CellularSimCardPinLockStateResponseDataMessage *>(msg);
            if (simCardPinLockState != nullptr) {
                auto pinSettingsLockStateData =
                    std::make_unique<gui::PINSettingsLockStateData>(simCardPinLockState->getSimCardPinLockState());
                updateWindow(gui::window::name::pin_settings, std::move(pinSettingsLockStateData));
            }
            return sys::MessageNone{};
        });

        connect(typeid(manager::GetCurrentDisplayLanguageResponse), [&](sys::Message *msg) {
            if (gui::window::name::languages == getCurrentWindow()->getName()) {
                auto response = dynamic_cast<manager::GetCurrentDisplayLanguageResponse *>(msg);


@@ 435,6 447,9 @@ namespace app
        windowsFactory.attach(gui::window::name::system, [](Application *app, const std::string &name) {
            return std::make_unique<gui::SystemMainWindow>(app);
        });
        windowsFactory.attach(gui::window::name::pin_settings, [](Application *app, const std::string &name) {
            return std::make_unique<gui::PINSettingsWindow>(app);
        });
        windowsFactory.attach(gui::window::name::new_apn, [](Application *app, const std::string &name) {
            return std::make_unique<gui::NewApnWindow>(app);
        });

M module-apps/application-settings-new/ApplicationSettings.hpp => module-apps/application-settings-new/ApplicationSettings.hpp +1 -0
@@ 49,6 49,7 @@ namespace gui::window::name
    inline constexpr auto display_and_keypad = "DisplayAndKeypad";
    inline constexpr auto change_settings    = "ChangeSettings";
    inline constexpr auto all_operators      = "AllOperators";
    inline constexpr auto pin_settings       = "PINSettings";
    inline constexpr auto import_contacts    = "ImportContacts";
    inline constexpr auto dialog_settings    = "DialogSettings";
    inline constexpr auto change_passcode    = "ChangePasscode";

M module-apps/application-settings-new/CMakeLists.txt => module-apps/application-settings-new/CMakeLists.txt +1 -0
@@ 72,6 72,7 @@ target_sources( ${PROJECT_NAME}
        windows/DoNotDisturbWindow.cpp
        windows/OfflineWindow.cpp
        windows/PhoneModesWindow.cpp
        windows/PINSettingsWindow.cpp
        windows/AboutYourPureWindow.cpp
        windows/CertificationWindow.cpp
        windows/TechnicalInformationWindow.cpp

A module-apps/application-settings-new/data/PINSettingsLockStateData.hpp => module-apps/application-settings-new/data/PINSettingsLockStateData.hpp +24 -0
@@ 0,0 1,24 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <string>
#include <SwitchData.hpp>

namespace gui
{
    class PINSettingsLockStateData : public SwitchData
    {
      public:
        explicit PINSettingsLockStateData(bool state) : state(state)
        {}
        [[nodiscard]] bool getSimCardPinLockState() const noexcept
        {
            return state;
        }

      private:
        const bool state;
    };
} // namespace gui

A module-apps/application-settings-new/data/PINSettingsSimData.hpp => module-apps/application-settings-new/data/PINSettingsSimData.hpp +24 -0
@@ 0,0 1,24 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <string>
#include <SwitchData.hpp>

namespace gui
{
    class PINSettingsSimData : public SwitchData
    {
      public:
        explicit PINSettingsSimData(std::string sim) : sim(std::move(sim))
        {}
        [[nodiscard]] auto getSim() const -> const std::string &
        {
            return sim;
        }

      private:
        const std::string sim;
    };
} // namespace gui

M module-apps/application-settings-new/windows/NetworkWindow.cpp => module-apps/application-settings-new/windows/NetworkWindow.cpp +16 -2
@@ 1,8 1,9 @@
// 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 "NetworkWindow.hpp"
#include "application-settings-new/ApplicationSettings.hpp"
#include "application-settings-new/data/PINSettingsSimData.hpp"

#include "OptionSetting.hpp"



@@ 87,8 88,21 @@ namespace gui
                nullptr,
                nullptr,
                gui::option::SettingRightItem::ArrowWhite,
                true));
                false));
        }

        optList.emplace_back(std::make_unique<gui::option::OptionSettings>(
            utils::translateI18("app_settings_network_pin_settings") + " (" + simStr + ")",
            [=](gui::Item &item) {
                auto pinSettingsData = std::make_unique<gui::PINSettingsSimData>(simStr);
                this->application->switchWindow(gui::window::name::pin_settings, std::move(pinSettingsData));
                return true;
            },
            nullptr,
            nullptr,
            gui::option::SettingRightItem::ArrowWhite,
            false));

        optList.emplace_back(std::make_unique<gui::option::OptionSettings>(
            utils::translateI18("app_settings_network_import_contacts_from_sim_card"),
            [=](gui::Item &item) {

A module-apps/application-settings-new/windows/PINSettingsWindow.cpp => module-apps/application-settings-new/windows/PINSettingsWindow.cpp +80 -0
@@ 0,0 1,80 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "PINSettingsWindow.hpp"
#include "application-settings-new/ApplicationSettings.hpp"
#include "application-settings-new/data/PINSettingsLockStateData.hpp"
#include "application-settings-new/data/PINSettingsSimData.hpp"
#include "OptionSetting.hpp"

#include <service-appmgr/Controller.hpp>
#include "service-cellular/CellularServiceAPI.hpp"

namespace gui
{
    PINSettingsWindow::PINSettingsWindow(app::Application *app) : BaseSettingsWindow(app, window::name::pin_settings)
    {
        CellularServiceAPI::RequestSimCardPinLockState(app);
    }

    void PINSettingsWindow::onBeforeShow(ShowMode /*mode*/, SwitchData *data)
    {
        if (const auto pinSettingsSimData = dynamic_cast<PINSettingsSimData *>(data); pinSettingsSimData != nullptr) {
            setTitle(utils::translateI18("app_settings_network_pin_settings") + " (" + pinSettingsSimData->getSim() +
                     ")");
        }
        if (const auto pinSettingsLockStateData = dynamic_cast<PINSettingsLockStateData *>(data);
            pinSettingsLockStateData != nullptr) {
            pinIsOn = pinSettingsLockStateData->getSimCardPinLockState();
        }
        refreshOptionsList();
    }

    auto PINSettingsWindow::buildOptionsList() -> std::list<Option>
    {
        std::list<Option> optionList;

        optionList.emplace_back(std::make_unique<option::OptionSettings>(
            utils::translateI18("app_settings_network_pin"),
            [=](Item & /*item*/) {
                changePinState(pinIsOn);
                return true;
            },
            [=](Item &item) {
                if (item.focus) {
                    this->setBottomBarText(utils::localize.get(style::strings::common::Switch),
                                           BottomBar::Side::CENTER);
                }
                else {
                    this->setBottomBarText(utils::localize.get(style::strings::common::select),
                                           BottomBar::Side::CENTER);
                }
                return true;
            },
            nullptr,
            pinIsOn ? option::SettingRightItem::On : option::SettingRightItem::Off));

        if (pinIsOn) {
            optionList.emplace_back(std::make_unique<option::OptionSettings>(
                utils::translateI18("app_settings_network_pin_change_code"),
                [=](Item & /*item*/) { return true; },
                nullptr,
                nullptr,
                option::SettingRightItem::ArrowWhite));
        }

        return optionList;
    }

    void PINSettingsWindow::changePinState(bool &currentState)
    {
        currentState = !currentState;
        refreshOptionsList();
        if (!currentState) {
            app::manager::Controller::sendAction(application, app::manager::actions::RequestPinDisable, nullptr);
        }
        else {
            app::manager::Controller::sendAction(application, app::manager::actions::RequestPinEnable, nullptr);
        }
    }
} // namespace gui

A module-apps/application-settings-new/windows/PINSettingsWindow.hpp => module-apps/application-settings-new/windows/PINSettingsWindow.hpp +22 -0
@@ 0,0 1,22 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "BaseSettingsWindow.hpp"

namespace gui
{
    class PINSettingsWindow : public BaseSettingsWindow
    {
      public:
        explicit PINSettingsWindow(app::Application *app);

      private:
        auto buildOptionsList() -> std::list<Option> override;
        void onBeforeShow(ShowMode mode, SwitchData *data) override;
        void changePinState(bool &currentState);

        bool pinIsOn = false;
    };
} // namespace gui

M module-services/service-appmgr/service-appmgr/Actions.hpp => module-services/service-appmgr/service-appmgr/Actions.hpp +2 -0
@@ 45,6 45,8 @@ namespace app::manager
            RequestPin,
            RequestPuk,
            RequestPinChange,
            RequestPinDisable,
            RequestPinEnable,
            UnlockSim,
            BlockSim,
            ShowMMIResult,

M module-services/service-cellular/CellularServiceAPI.cpp => module-services/service-cellular/CellularServiceAPI.cpp +8 -2
@@ 144,8 144,8 @@ bool CellularServiceAPI::SelectAntenna(sys::Service *serv, bsp::cellular::antenn

bool CellularServiceAPI::SetScanMode(sys::Service *serv, std::string mode)
{
    auto msg  = std::make_shared<CellularSetScanModeMessage>(mode);
    auto ret  = serv->bus.sendUnicast(msg, ServiceCellular::serviceName, 5000);
    auto msg = std::make_shared<CellularSetScanModeMessage>(mode);
    auto ret = serv->bus.sendUnicast(msg, ServiceCellular::serviceName, 5000);

    CellularResponseMessage *response = dynamic_cast<CellularResponseMessage *>(ret.second.get());



@@ 274,6 274,12 @@ bool CellularServiceAPI::ChangeSimPin(sys::Service *serv,
                                 ServiceCellular::serviceName);
}

bool CellularServiceAPI::RequestSimCardPinLockState(sys::Service *serv)
{
    return serv->bus.sendUnicast(std::make_shared<CellularSimCardPinLockStateRequestDataMessage>(),
                                 ServiceCellular::serviceName);
}

bool CellularServiceAPI::SetSimCardLock(sys::Service *serv,
                                        Store::GSM::SIM sim,
                                        CellularSimCardLockDataMessage::SimCardLock lock,

M module-services/service-cellular/ServiceCellular.cpp => module-services/service-cellular/ServiceCellular.cpp +11 -0
@@ 342,6 342,11 @@ void ServiceCellular::registerMessageHandlers()
            }
        });

    connect(typeid(CellularSimCardPinLockStateRequestDataMessage),
            [&](sys::Message * /*request*/) -> sys::MessagePointer {
                return std::make_shared<CellularSimCardPinLockStateResponseDataMessage>(isPinLocked());
            });

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


@@ 1100,6 1105,12 @@ bool ServiceCellular::sendChangePinResult(SimCardResult res)
    return true;
}

bool ServiceCellular::isPinLocked()
{
    SimCard simCard(*this);
    return simCard.isPinLocked();
}

bool ServiceCellular::changePin(const std::string oldPin, const std::string newPin)
{
    SimCard simCard(*this);

M module-services/service-cellular/service-cellular/CellularMessage.hpp => module-services/service-cellular/service-cellular/CellularMessage.hpp +18 -0
@@ 524,6 524,24 @@ class CellularSimNewPinDataMessage : public CellularSimDataMessage
    }
};

class CellularSimCardPinLockStateRequestDataMessage : public sys::DataMessage
{};

class CellularSimCardPinLockStateResponseDataMessage : public sys::DataMessage
{
  public:
    explicit CellularSimCardPinLockStateResponseDataMessage(bool state) : simCardPinLockState(state)
    {}

    [[nodiscard]] bool getSimCardPinLockState() const noexcept
    {
        return simCardPinLockState;
    }

  private:
    const bool simCardPinLockState;
};

class CellularSimCardLockDataMessage : public CellularSimDataMessage
{


M module-services/service-cellular/service-cellular/CellularServiceAPI.hpp => module-services/service-cellular/service-cellular/CellularServiceAPI.hpp +1 -0
@@ 91,6 91,7 @@ namespace CellularServiceAPI
                      Store::GSM::SIM sim,
                      const std::vector<unsigned int> &passcode,
                      const std::vector<unsigned int> &pin);
    bool RequestSimCardPinLockState(sys::Service *serv);
    bool SetSimCardLock(sys::Service *serv,
                        Store::GSM::SIM sim,
                        CellularSimCardLockDataMessage::SimCardLock lock,

M module-services/service-cellular/service-cellular/ServiceCellular.hpp => module-services/service-cellular/service-cellular/ServiceCellular.hpp +5 -0
@@ 160,6 160,11 @@ class ServiceCellular : public sys::Service

    /// sim functionality

    /** Function checks if sim pin is locked (enabled)
     * @return True if sim pin is locked, False if it's not
     */
    bool isPinLocked();

    /** Function ready for change pin action send to Service Cellular form eg. GUI
     * \param oldPin
     * \param newPin