Skip to content

Commit 94378c7

Browse files
authored
Revert "[EGD-4168] passcodes for sim change to variable length (#924)" (#934)
This reverts commit 0bdc633.
1 parent 9ac95dc commit 94378c7

File tree

17 files changed

+168
-236
lines changed

17 files changed

+168
-236
lines changed

changelog.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
### Fixed
1717

18-
* `[desktop][gui]` Fixed SIM passcodes to accepts variable length
1918
* `[desktop][messages]` Fixed notifications display and navigation
2019
* `[cellular]` Fixed 32 bit UCS2 codes handling.
2120
* `[call]` Fixed incorrect start of call duration timer

module-apps/application-desktop/ApplicationDesktop.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ namespace app
4141
// Invoked upon receiving data message
4242
sys::Message_t ApplicationDesktop::DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp)
4343
{
44+
4445
auto retMsg = Application::DataReceivedHandler(msgl);
4546
// if message was handled by application's template there is no need to process further.
4647
if (dynamic_cast<sys::ResponseMessage *>(retMsg.get())->retCode == sys::ReturnCodes::Success) {

module-apps/application-desktop/data/AppDesktopStyle.hpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77

88
namespace style::window::pin_lock
99
{
10-
constexpr auto image_x = 177;
11-
constexpr auto image_y = 132;
12-
constexpr auto title_label_y = 60;
13-
constexpr auto title_label_h = 40;
14-
constexpr auto label_size = 60;
15-
constexpr auto label_margins = 10;
16-
constexpr auto pin_label_x = 85;
17-
constexpr auto pin_label_y = 450;
18-
constexpr auto pin_label_y_screen = 400;
19-
constexpr auto info_text_y = 294;
20-
constexpr auto info_text_h_screen = 60;
21-
constexpr auto info_text_h_sim = 150;
22-
constexpr auto info_text_h_puk = 180;
10+
const inline uint32_t image_x = 177;
11+
const inline uint32_t image_y = 132;
12+
const inline uint32_t title_label_y = 60;
13+
const inline uint32_t title_label_h = 40;
14+
const inline uint32_t label_size = 30;
15+
const inline uint32_t label_size_screen = 60;
16+
const inline uint32_t pin_label_x = 85;
17+
const inline uint32_t pin_label_x_screen = 100;
18+
const inline uint32_t pin_label_y = 450;
19+
const inline uint32_t info_text_y = 294;
20+
const inline uint32_t info_text_h_screen = 60;
21+
const inline uint32_t info_text_h_sim = 150;
22+
const inline uint32_t info_text_h_puk = 180;
2323
} // namespace style::window::pin_lock

module-apps/application-desktop/widgets/PinLock.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,40 @@ namespace gui
1616
}
1717
}
1818

19-
void PinLock::putNextChar(unsigned int c)
19+
void PinLock::putNextChar(unsigned int c) noexcept
2020
{
21-
if (state == State::EnterPin && maxPinSize > pinValue.size()) {
22-
pinValue.push_back(c);
21+
if (state == State::EnterPin && charCount < pinValue.size()) {
22+
pinValue[charCount++] = c;
2323
}
2424
}
2525

26-
void PinLock::verifyPin()
26+
void PinLock::verifyPin() noexcept
2727
{
28-
handler->handle(pinValue);
29-
clearAttempt();
28+
if (charCount == pinValue.size()) {
29+
handler->handle(pinValue);
30+
clearAttempt();
31+
}
3032
}
3133

32-
void PinLock::popChar()
34+
void PinLock::popChar() noexcept
3335
{
34-
if (state == State::EnterPin && pinValue.size() > 0) {
35-
pinValue.pop_back();
36+
if (state == State::EnterPin && charCount > 0) {
37+
charCount--;
38+
pinValue[charCount] = 0;
3639
}
3740
}
3841

3942
void PinLock::clearAttempt() noexcept
4043
{
41-
pinValue.clear();
44+
for (auto &c : pinValue) {
45+
c = 0;
46+
}
47+
charCount = 0;
4248
}
4349

4450
bool PinLock::unlock() noexcept
4551
{
46-
if (state == State::VerifiedPin || maxPinSize == 0) {
52+
if (state == State::VerifiedPin || pinValue.size() == 0) {
4753
state = State::Unlocked;
4854
return true;
4955
}
@@ -72,17 +78,11 @@ namespace gui
7278
}
7379
}
7480

75-
void PinLock::reset(LockType _type,
76-
State _state,
77-
unsigned int _remainingAttempts,
78-
unsigned int _maxPinSize,
79-
unsigned int _minPinSize) noexcept
81+
void PinLock::reset(LockType newType, State newState, unsigned int attempts, unsigned int size) noexcept
8082
{
81-
type = _type;
82-
state = _state;
83-
remainingAttempts = _remainingAttempts;
84-
pinValue = std::vector<unsigned int>();
85-
maxPinSize = _maxPinSize;
86-
minPinSize = _minPinSize;
83+
type = newType;
84+
state = newState;
85+
remainingAttempts = attempts;
86+
pinValue = std::vector<unsigned int>(size, 0);
8787
}
8888
} // namespace gui

module-apps/application-desktop/widgets/PinLock.hpp

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,27 @@ namespace gui
3737
{
3838
return state;
3939
}
40-
[[nodiscard]] unsigned int getMaxPinSize() const noexcept
40+
[[nodiscard]] unsigned int getPinSize() const noexcept
4141
{
42-
return maxPinSize;
42+
return pinValue.size();
4343
}
4444
/// returns current position of a PIN character to be inserted
4545
[[nodiscard]] unsigned int getCharCount() const noexcept
4646
{
47-
return pinValue.size();
47+
return charCount;
4848
}
4949
[[nodiscard]] unsigned int getRemainingAttempts() const noexcept
5050
{
5151
return remainingAttempts;
5252
}
5353
[[nodiscard]] bool canPut() const noexcept
5454
{
55-
return getCharCount() != getMaxPinSize();
56-
}
57-
[[nodiscard]] bool canVerify() const noexcept
58-
{
59-
return getCharCount() >= minPinSize;
55+
return getCharCount() != getPinSize();
6056
}
61-
void putNextChar(unsigned int c);
62-
void verifyPin();
57+
void putNextChar(unsigned int c) noexcept;
58+
void verifyPin() noexcept;
6359
/// removes a last character passed to Lock via putNextChar. The last character can not be popped
64-
void popChar();
60+
void popChar() noexcept;
6561
/// clear all characters passed to the Lock
6662
void clearAttempt() noexcept;
6763
/// if Lock is in the State::InvalidPin state, changes it's state to the State::EnterPin
@@ -87,15 +83,11 @@ namespace gui
8783
unsigned int remainingAttempts = 0;
8884
/// code of the entered character on specified position
8985
std::vector<unsigned int> pinValue;
90-
unsigned int maxPinSize = 0;
91-
unsigned int minPinSize = 0;
86+
/// flag defines number of entered pin characters
87+
unsigned int charCount = 0;
9288
std::map<InfoName, std::string> additionalLockInfo;
9389

94-
void reset(LockType _type,
95-
State _state,
96-
unsigned int _remainingAttempts,
97-
unsigned int _maxPinSize,
98-
unsigned int _minPinSize) noexcept;
90+
void reset(LockType, State, unsigned int remainingAttempts, unsigned int pinSize) noexcept;
9991

10092
friend class gui::PinLockHandler;
10193
};

module-apps/application-desktop/widgets/PinLockHandler.cpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88

99
namespace gui
1010
{
11-
constexpr unsigned int defaultScreenPinSize = 4;
12-
constexpr unsigned int defaultScreenAttempts = 4;
13-
constexpr unsigned int maxSimPasscodesSize = 10;
14-
constexpr unsigned int minSimPasscodesSize = 4;
11+
constexpr unsigned int default_screen_pin_size = 4;
12+
constexpr unsigned int default_screen_attempts = 4;
1513

1614
PinLockHandler::PinLockHandler(app::ApplicationDesktop *app, SettingsRecord &settings)
1715
: app(app), appSettings(settings), lock(this)
@@ -22,15 +20,13 @@ namespace gui
2220
auto PinLockHandler::handle(CellularSimResponseMessage *msg) -> bool
2321
{
2422
assert(msg);
23+
2524
parseSimCard(msg);
2625
parseSimState(msg);
2726
parseAttemptsAndPinSize(msg);
2827
lock.additionalLockInfo[gui::PinLock::InfoName::PhoneNum] = msg->getPhoneNumber().getFormatted();
2928

30-
auto currentWindow = app->getWindow(app::window::name::desktop_pin_lock);
31-
if (currentWindow != nullptr && currentWindow->getName() == gui::name::window::main_window) {
32-
currentWindow->rebuild();
33-
}
29+
app->getWindow(app::window::name::desktop_pin_lock)->rebuild();
3430
app->switchWindow(gui::name::window::main_window);
3531
return true;
3632
}
@@ -95,9 +91,7 @@ namespace gui
9591
reloadScreenLock();
9692
}
9793
else {
98-
lock.pinValue = std::vector<unsigned int>();
99-
lock.maxPinSize = maxSimPasscodesSize;
100-
lock.minPinSize = minSimPasscodesSize;
94+
lock.pinValue = std::vector<unsigned int>(msg->getPinSize(), 0);
10195
lock.remainingAttempts = msg->getAttemptsLeft();
10296
}
10397
}
@@ -109,7 +103,7 @@ namespace gui
109103
uint32_t hash = hashEngine(pin);
110104
lock.remainingAttempts--;
111105
if (hash == appSettings.lockPassHash) {
112-
lock.remainingAttempts = defaultScreenAttempts;
106+
lock.remainingAttempts = default_screen_attempts;
113107
lock.state = gui::PinLock::State::VerifiedPin;
114108
}
115109
else if (lock.remainingAttempts > 0) {
@@ -132,10 +126,12 @@ namespace gui
132126

133127
void PinLockHandler::reloadScreenLock()
134128
{
135-
auto type = gui::PinLock::LockType::Screen;
136-
auto state = gui::PinLock::State::EnterPin;
137-
unsigned int pinSize = appSettings.lockPassHash == 0 ? 0 : defaultScreenPinSize;
138-
lock.reset(type, state, defaultScreenAttempts, pinSize, pinSize);
129+
lock.type = gui::PinLock::LockType::Screen;
130+
lock.state = gui::PinLock::State::EnterPin;
131+
132+
unsigned int pinSize = appSettings.lockPassHash == 0 ? 0 : default_screen_pin_size;
133+
lock.pinValue = std::vector<unsigned int>(pinSize, 0);
134+
lock.remainingAttempts = default_screen_attempts;
139135
}
140136

141137
} // namespace gui

module-apps/application-desktop/windows/PinLockBaseWindow.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,26 @@ namespace gui
4747
infoText->setVisible(true);
4848
infoText->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Top));
4949
}
50-
void PinLockBaseWindow::buildPinLabels(std::function<Rect *()> itemBuilder,
51-
unsigned int pinSize,
52-
unsigned int offsetX,
53-
unsigned int offsetY,
54-
unsigned int boxWidth)
50+
void PinLockBaseWindow::buildPinLabels(gui::Label *labelsBox, unsigned int pinSize, unsigned int singleLabelWidth)
5551
{
56-
pinLabelsBox = new gui::HBox(this, offsetX, offsetY, boxWidth, lock_style::label_size);
57-
pinLabelsBox->setAlignment(Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));
58-
59-
if (pinSize == 0) {
60-
return;
52+
if (pinSize * singleLabelWidth > labelsBox->getWidth()) {
53+
singleLabelWidth = labelsBox->getWidth() / pinSize;
6154
}
55+
const uint32_t pinLabelSpacing = (labelsBox->getWidth() - pinSize * singleLabelWidth) / (pinSize - 1);
6256

57+
uint32_t pinLabelX = 0;
6358
for (uint32_t i = 0; i < pinSize; i++) {
64-
auto label = itemBuilder();
59+
gui::Label *label = new gui::Label(labelsBox, pinLabelX, 0, singleLabelWidth, lock_style::label_size);
6560
label->setFilled(false);
6661
label->setBorderColor(gui::ColorFullBlack);
6762
label->setPenWidth(2);
68-
label->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));
63+
label->setFont(style::window::font::largelight);
64+
label->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Bottom));
6965
label->setVisible(true);
70-
label->activeItem = false;
71-
pinLabelsBox->addWidget(label);
66+
this->pinLabels.push_back(label);
67+
pinLabelX += singleLabelWidth + pinLabelSpacing;
7268
}
7369
}
74-
7570
void PinLockBaseWindow::buildImages(const std::string &lockImg, const std::string &infoImg)
7671
{
7772
lockImage = new gui::Image(this, lock_style::image_x, lock_style::image_y, 0, 0, lockImg);
@@ -93,5 +88,10 @@ namespace gui
9388
{
9489
bottomBar->setText(side, txt, false);
9590
}
96-
91+
void PinLockBaseWindow::clearPinLabels()
92+
{
93+
for (auto label : pinLabels) {
94+
label->clear();
95+
}
96+
}
9797
} // namespace gui

module-apps/application-desktop/windows/PinLockBaseWindow.hpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include "AppWindow.hpp"
77
#include "Text.hpp"
8-
#include "BoxLayout.hpp"
98

109
namespace gui
1110
{
@@ -21,21 +20,19 @@ namespace gui
2120
{}
2221
void build();
2322
void buildInfoText(unsigned int textHight);
24-
void buildPinLabels(std::function<Rect *()> itemBuilder,
25-
unsigned int pinSize,
26-
unsigned int offsetX,
27-
unsigned int offsetY,
28-
unsigned int boxWidth);
23+
void buildPinLabels(gui::Label *labelBox, unsigned int pinSize, unsigned int singleLabelWidth);
2924
void buildImages(const std::string &lockImg, const std::string &infoImg);
3025
void setBottomBarWidgetsActive(bool left, bool center, bool right);
3126
void setImagesVisible(bool lockImg, bool infoImg);
3227
void setBottomBarWidgetText(BottomBar::Side side, const UTF8 &txt);
28+
void clearPinLabels();
3329

3430
gui::Label *titleLabel = nullptr;
3531
gui::Text *infoText = nullptr;
32+
gui::Label *pinLabel = nullptr;
33+
std::vector<gui::Label *> pinLabels;
3634
gui::Image *lockImage = nullptr;
3735
gui::Image *infoImage = nullptr;
38-
gui::HBox *pinLabelsBox = nullptr;
3936

4037
PinLock &lock;
4138

module-apps/application-desktop/windows/PinLockBox.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ namespace gui
1010
class PinLockBox
1111
{
1212
public:
13-
virtual void popChar(unsigned int charNum) = 0;
14-
virtual void putChar(unsigned int charNum) = 0;
13+
virtual void popChar(uint32_t charNum) = 0;
14+
virtual void putChar(uint32_t charNum) = 0;
1515

1616
virtual void setVisibleStateEnterPin() = 0;
1717
virtual void setVisibleStateVerifiedPin() = 0;

0 commit comments

Comments
 (0)