~aleteoryx/muditaos

ref: ccce9bb19f4725b03d8b713ed04df6421f2d223e muditaos/module-apps/apps-common/popups/lock-popups/SimLockInputWindow.cpp -rw-r--r-- 5.1 KiB
ccce9bb1 — Bartosz [MOS-724] CodeQL setup 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "SimLockInputWindow.hpp"

#include <locks/data/LockData.hpp>
#include <locks/widgets/SimLockBox.hpp>
#include <locks/widgets/LockHash.hpp>

#include <application-settings/ApplicationSettings.hpp>

#include <service-appmgr/Controller.hpp>
#include <popups/data/PopupRequestParams.hpp>

namespace gui
{
    SimLockInputWindow::SimLockInputWindow(app::ApplicationCommon *app, const std::string &window_name)
        : LockInputWindow(app, window_name)
    {
        buildInterface();
    }

    void SimLockInputWindow::rebuild()
    {
        destroyInterface();
        buildInterface();
    }
    void SimLockInputWindow::buildInterface()
    {
        AppWindow::buildInterface();
        LockInputWindow::build();
    }

    void SimLockInputWindow::destroyInterface()
    {
        erase();
    }

    void SimLockInputWindow::setVisibleState()
    {
        LockInputWindow::setVisibleState();

        if (lock->isState(locks::Lock::LockState::ErrorOccurred)) {
            lockBox->setVisibleStateError(errorCode);
        }
    }

    status_bar::Configuration SimLockInputWindow::configureStatusBar(status_bar::Configuration appConfiguration)
    {
        appConfiguration.disable(status_bar::Indicator::NetworkAccessTechnology);
        appConfiguration.enable(status_bar::Indicator::Time);
        appConfiguration.enable(status_bar::Indicator::PhoneMode);
        appConfiguration.enable(status_bar::Indicator::Battery);
        appConfiguration.enable(status_bar::Indicator::Signal);
        appConfiguration.enable(status_bar::Indicator::SimCard);
        appConfiguration.enable(status_bar::Indicator::Bluetooth);
        appConfiguration.enable(status_bar::Indicator::AlarmClock);
        return appConfiguration;
    }

    void SimLockInputWindow::onBeforeShow(ShowMode mode, SwitchData *data)
    {
        if (auto SimLockData = dynamic_cast<locks::SimLockData *>(data)) {
            lock                   = std::make_unique<locks::Lock>(SimLockData->getLock());
            simLockInputTypeAction = SimLockData->getSimInputTypeAction();
            errorCode              = SimLockData->getErrorCode();
        }

        // Lock need to exist in that window flow
        assert(lock);

        rebuild();
        lockBox = std::make_unique<SimLockBox>(this, simLockInputTypeAction);
        lockBox->buildLockBox(lock->getMaxInputSize());
        lockBox->update(lock->getCharCount());

        setVisibleState();
    }

    bool SimLockInputWindow::onInput(const InputEvent &inputEvent)
    {
        if (!inputEvent.isShortRelease()) {
            return AppWindow::onInput(inputEvent);
        }
        else if (inputEvent.is(KeyCode::KEY_RF) && navBar->isActive(nav_bar::Side::Right)) {
            if (isInInputState()) {
                lock->clearAttempt();
            }
            else if (lock->isState(locks::Lock::LockState::InputInvalid)) {
                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();
            }
            return true;
        }
        else if (inputEvent.is(KeyCode::KEY_PND)) {
            if (isInInputState()) {
                lock->popChar();
                lockBox->popChar(lock->getCharCount());
                navBar->setActive(nav_bar::Side::Center, lock->canVerify());
                return true;
            }
        }
        else if (inputEvent.isDigit()) {
            if (isInInputState() && lock->canPut()) {
                lockBox->putChar(lock->getCharCount());
                lock->putNextChar(inputEvent.numericValue());

                navBar->setActive(nav_bar::Side::Center, lock->canVerify());
                return true;
            }
        }
        else if (inputEvent.is(KeyCode::KEY_ENTER) && navBar->isActive(nav_bar::Side::Center)) {
            if (isInInputState()) {
                application->getSimLockSubject().verifyInput(lock->getInput());
            }
            else if (isInInvalidInputState()) {
                lock->consumeState();
                lock->clearAttempt();
                setVisibleState();
            }
            return true;
        }
        else if (inputEvent.is(KeyCode::KEY_LEFT) && isIceVisible()) {
            app::manager::Controller::sendAction(application,
                                                 app::manager::actions::EmergencyDial,
                                                 std::make_unique<gui::SwitchData>(),
                                                 app::manager::OnSwitchBehaviour::RunInBackground);
            return true;
        }

        // check if any of the lower inheritance onInput methods catch the event
        return AppWindow::onInput(inputEvent);
    }

} /* namespace gui */