~aleteoryx/muditaos

5cb4cfcea969cdcdbefa62ab278f0f9fa8968d6d — breichel 4 years ago 5c7b518
[EGD-5545] Add PIN2 handling

Possibility of handling PIN2 request from modem.
Description of the message in PinLock what type of
code is required
M image/assets/lang/English.json => image/assets/lang/English.json +1 -1
@@ 228,7 228,7 @@
  "app_desktop_info_mmi_result_success": "Success",
  "app_desktop_info_mmi_result_failed": "Failed",
  "app_desktop_header_sim_setup": "<text><token>$SIM</token> setup</text>",
  "app_desktop_sim_enter_pin_unlock": "Type current PIN code:",
  "app_desktop_sim_enter_pin_unlock": "<text>Type current <token>$PINTYPE</token> code:</text>",
  "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>",

M module-apps/application-desktop/widgets/PinLock.hpp => module-apps/application-desktop/widgets/PinLock.hpp +9 -0
@@ 80,6 80,14 @@ namespace gui
        {
            return lockType == type;
        }
        [[nodiscard]] const std::string &getPasscodeName() const noexcept
        {
            return passcodeName;
        }
        [[nodiscard]] Store::GSM::SIM getSim() const noexcept
        {
            return sim;
        }

        void putNextChar(unsigned int c);
        /// removes a last character passed to Lock via putNextChar. The last character can not be popped


@@ 100,6 108,7 @@ namespace gui
        std::function<void(LockType type, const std::vector<unsigned int> &)> onActivatedCallback = nullptr;

      private:
        std::string passcodeName;
        Store::GSM::SIM sim = Store::GSM::SIM::NONE;
        LockState lockState = LockState::Unlocked;
        LockType lockType   = LockType::Screen;

M module-apps/application-desktop/widgets/PinLockHandler.cpp => module-apps/application-desktop/widgets/PinLockHandler.cpp +1 -0
@@ 67,6 67,7 @@ namespace gui
            simLock.sim       = passcodeData->getSim();
            simLock.lockType  = type;
        }
        simLock.passcodeName = passcodeData->getPasscodeName();
        simLock.value = passcodeData->getAttempts();
    }


M module-apps/application-desktop/windows/LockWindow.hpp => module-apps/application-desktop/windows/LockWindow.hpp +2 -1
@@ 29,7 29,8 @@ namespace gui
            Sim,
            Attempts,
            Mins,
            CmeCode
            CmeCode,
            PinType
        };

        LockWindow(app::Application *app, std::string name) : AppWindow(app, std::move(name))

M module-apps/application-desktop/windows/PinLockBaseWindow.cpp => module-apps/application-desktop/windows/PinLockBaseWindow.cpp +4 -1
@@ 18,7 18,10 @@ namespace gui

    auto PinLockBaseWindow::getToken(Token token) const -> std::string
    {
        if (token == Token::Sim) {
        if (token == Token::PinType) {
            return "$PINTYPE";
        }
        else if (token == Token::Sim) {
            return "$SIM";
        }
        else if (token == Token::Attempts) {

M module-apps/application-desktop/windows/PinLockWindow.cpp => module-apps/application-desktop/windows/PinLockWindow.cpp +4 -1
@@ 147,7 147,10 @@ namespace gui
        else if (lockType == PinLock::LockType::SimPuk) {
            LockBox = std::make_unique<PukLockBox>(this);
            setTitleBar(true, true);
            setText("app_desktop_header_sim_setup", TextType::Title, true, {{getToken(Token::Sim), "SIM1"}});
            setText("app_desktop_header_sim_setup",
                    TextType::Title,
                    true,
                    {{getToken(Token::Sim), utils::enumToString(lock->getSim())}});
        }
        else if (lockType == PinLock::LockType::SimPin) {
            LockBox = std::make_unique<SimLockBox>(this);

M module-apps/application-desktop/windows/SimLockBox.cpp => module-apps/application-desktop/windows/SimLockBox.cpp +5 -1
@@ 49,7 49,11 @@ namespace gui
        LockWindow->pinLabelsBox->setVisible(true);
        switch (type) {
        case PinLockBox::EnterPasscodeType::ProvidePasscode: {
            LockWindow->setText("app_desktop_sim_enter_pin_unlock", PinLockBaseWindow::TextType::Primary, true);
            LockWindow->setText(
                "app_desktop_sim_enter_pin_unlock",
                PinLockBaseWindow::TextType::Primary,
                true,
                {{LockWindow->getToken(PinLockBaseWindow::Token::PinType), LockWindow->lock->getPasscodeName()}});
            break;
        }
        case PinLockBox::EnterPasscodeType::ProvideNewPasscode:

M module-services/service-cellular/ServiceCellular.cpp => module-services/service-cellular/ServiceCellular.cpp +22 -4
@@ 1396,10 1396,28 @@ bool ServiceCellular::handleSimState(at::SimState state, const std::string messa
        sendSimBlocked();
        break;
    }
    case at::SimState::SimPin2:
        [[fallthrough]];
    case at::SimState::SimPuk2:
        [[fallthrough]];
    case at::SimState::SimPin2: {
        SimCard simCard(*this);
        if (auto pc = simCard.getAttemptsCounters(SimPinType::SimPin2); pc) {
            if (pc.value().PukCounter != 0) {
                requestPin(pc.value().PinCounter, message);
                break;
            }
        }
        sendSimBlocked();
        break;
    }
    case at::SimState::SimPuk2: {
        SimCard simCard(*this);
        if (auto pc = simCard.getAttemptsCounters(SimPinType::SimPin2); pc) {
            if (pc.value().PukCounter != 0) {
                requestPuk(pc.value().PukCounter, message);
                break;
            }
        }
        sendSimBlocked();
        break;
    }
    case at::SimState::PhNetPin:
        [[fallthrough]];
    case at::SimState::PhNetPuk:

M module-services/service-cellular/SimCard.cpp => module-services/service-cellular/SimCard.cpp +2 -2
@@ 21,11 21,11 @@ SimCardResult SimCard::convertErrorFromATResult(const at::Result atres) const
    return SimCardResult::Unknown;
}

std::optional<at::response::qpinc::AttemptsCounters> SimCard::getAttemptsCounters() const
std::optional<at::response::qpinc::AttemptsCounters> SimCard::getAttemptsCounters(const std::string &type) const
{
    auto channel = cellularService.cmux->get(TS0710::Channel::Commands);
    if (channel) {
        auto resp = channel->cmd(at::factory(at::AT::QPINC) + "\"SC\"");
        auto resp = channel->cmd(at::factory(at::AT::QPINC) + "\"" + type + "\"");
        at::response::qpinc::AttemptsCounters ret;
        if (at::response::parseQPINC(resp, ret)) {
            return ret;

M module-services/service-cellular/SimCard.hpp => module-services/service-cellular/SimCard.hpp +2 -1
@@ 24,7 24,8 @@ class SimCard
     * return SIMFailure which could mean 0 attempts (happen if lock during session, on modem/sim reboot again return
     * 0,0);
     */
    std::optional<at::response::qpinc::AttemptsCounters> getAttemptsCounters() const;
    std::optional<at::response::qpinc::AttemptsCounters> getAttemptsCounters(
        const std::string &type = SimPinType::SimPin) const;

    /** Supply pin for modem
     * \param pin digits as a string from 4-8 digits

M module-services/service-cellular/service-cellular/SimCardResult.hpp => module-services/service-cellular/service-cellular/SimCardResult.hpp +6 -1
@@ 2,7 2,12 @@
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

class SimPinType
{
  public:
    static constexpr auto SimPin  = "SC";
    static constexpr auto SimPin2 = "P2";
};
enum class SimCardResult
{
    OK     = 0,