From 182f694ac2a1c3da23df72e0494588fc579e7616 Mon Sep 17 00:00:00 2001 From: Przemyslaw Brudny Date: Tue, 27 Apr 2021 11:41:02 +0200 Subject: [PATCH] [EGD-6637] Cleanup locks structure Renaming existing locks namespace and created proper directory structure. --- image/assets/lang/English.json | 2 +- image/assets/lang/Svenska.json | 2 +- module-apps/Application.cpp | 2 +- module-apps/Application.hpp | 3 +- module-apps/CMakeLists.txt | 11 +- .../ApplicationDesktop.cpp | 9 +- .../ApplicationDesktop.hpp | 2 +- .../application-desktop/CMakeLists.txt | 24 +-- .../application-desktop/data/DesktopData.hpp | 46 ++++ .../data/{Style.hpp => DesktopStyle.hpp} | 2 + .../data/LockPhoneData.hpp | 79 ------- .../application-desktop/widgets/PinLock.cpp | 58 ----- .../windows/DesktopMainWindow.cpp | 5 +- .../windows/LockedInfoWindow.cpp | 3 +- .../windows/PinLockBox.hpp | 38 ---- .../windows/PostUpdateWindow.cpp | 5 +- .../windows/ScreenLockBox.hpp | 25 --- .../application-desktop/windows/Update.cpp | 2 +- .../windows/UpdateProgress.cpp | 4 +- .../windows/ConfigurePasscodeWindow.cpp | 14 +- .../windows/ConfigurePasscodeWindow.hpp | 4 +- .../ApplicationSettings.cpp | 2 +- .../widgets/ChangePasscodeLockHandler.cpp | 38 ++-- .../widgets/ChangePasscodeLockHandler.hpp | 18 +- .../windows/ChangePasscodeWindow.cpp | 40 ++-- .../windows/ChangePasscodeWindow.hpp | 8 +- .../windows/SecurityMainWindow.cpp | 11 +- module-apps/locks/CMakeLists.txt | 41 ++++ module-apps/locks/data/LockData.hpp | 30 +++ .../data/LockStyle.hpp} | 0 .../handlers}/PinLockHandler.cpp | 200 +++++++++--------- .../handlers}/PinLockHandler.hpp | 30 +-- module-apps/locks/widgets/Lock.cpp | 50 +++++ .../PinLock.hpp => locks/widgets/Lock.hpp} | 91 ++++---- module-apps/locks/widgets/LockBox.hpp | 38 ++++ .../widgets/LockHash.hpp} | 10 +- .../widgets/PhoneLockBaseBox.cpp} | 38 ++-- .../widgets/PhoneLockBaseBox.hpp} | 20 +- .../widgets/PhoneLockBox.cpp} | 20 +- module-apps/locks/widgets/PhoneLockBox.hpp | 26 +++ .../windows => locks/widgets}/PukLockBox.cpp | 42 ++-- .../windows => locks/widgets}/PukLockBox.hpp | 14 +- .../windows => locks/widgets}/SimLockBox.cpp | 42 ++-- .../windows => locks/widgets}/SimLockBox.hpp | 16 +- .../windows/LockWindow.cpp | 4 +- .../windows/LockWindow.hpp | 14 +- .../windows/PinLockBaseWindow.cpp | 4 +- .../windows/PinLockBaseWindow.hpp | 0 .../windows/PinLockWindow.cpp | 80 ++++--- .../windows/PinLockWindow.hpp | 11 +- module-apps/popups/CMakeLists.txt | 34 +++ module-gui/gui/SwitchData.hpp | 7 +- 52 files changed, 684 insertions(+), 635 deletions(-) create mode 100644 module-apps/application-desktop/data/DesktopData.hpp rename module-apps/application-desktop/data/{Style.hpp => DesktopStyle.hpp} (98%) delete mode 100644 module-apps/application-desktop/data/LockPhoneData.hpp delete mode 100644 module-apps/application-desktop/widgets/PinLock.cpp delete mode 100644 module-apps/application-desktop/windows/PinLockBox.hpp delete mode 100644 module-apps/application-desktop/windows/ScreenLockBox.hpp create mode 100644 module-apps/locks/CMakeLists.txt create mode 100644 module-apps/locks/data/LockData.hpp rename module-apps/{application-desktop/data/AppDesktopStyle.hpp => locks/data/LockStyle.hpp} (100%) rename module-apps/{application-desktop/widgets => locks/handlers}/PinLockHandler.cpp (53%) rename module-apps/{application-desktop/widgets => locks/handlers}/PinLockHandler.hpp (71%) create mode 100644 module-apps/locks/widgets/Lock.cpp rename module-apps/{application-desktop/widgets/PinLock.hpp => locks/widgets/Lock.hpp} (54%) create mode 100644 module-apps/locks/widgets/LockBox.hpp rename module-apps/{application-desktop/widgets/PinHash.hpp => locks/widgets/LockHash.hpp} (61%) rename module-apps/{application-desktop/windows/ScreenLockBaseBox.cpp => locks/widgets/PhoneLockBaseBox.cpp} (61%) rename module-apps/{application-desktop/windows/ScreenLockBaseBox.hpp => locks/widgets/PhoneLockBaseBox.hpp} (55%) rename module-apps/{application-desktop/windows/ScreenLockBox.cpp => locks/widgets/PhoneLockBox.cpp} (77%) create mode 100644 module-apps/locks/widgets/PhoneLockBox.hpp rename module-apps/{application-desktop/windows => locks/widgets}/PukLockBox.cpp (70%) rename module-apps/{application-desktop/windows => locks/widgets}/PukLockBox.hpp (60%) rename module-apps/{application-desktop/windows => locks/widgets}/SimLockBox.cpp (71%) rename module-apps/{application-desktop/windows => locks/widgets}/SimLockBox.hpp (53%) rename module-apps/{application-desktop => locks}/windows/LockWindow.cpp (97%) rename module-apps/{application-desktop => locks}/windows/LockWindow.hpp (84%) rename module-apps/{application-desktop => locks}/windows/PinLockBaseWindow.cpp (97%) rename module-apps/{application-desktop => locks}/windows/PinLockBaseWindow.hpp (100%) rename module-apps/{application-desktop => locks}/windows/PinLockWindow.cpp (58%) rename module-apps/{application-desktop => locks}/windows/PinLockWindow.hpp (77%) create mode 100644 module-apps/popups/CMakeLists.txt diff --git a/image/assets/lang/English.json b/image/assets/lang/English.json index ad1bbcd6610095ce94e7a4b43add37ba66e3048b..f41f4cd5842cf9faf851243e5dcc17f37b842d95 100644 --- a/image/assets/lang/English.json +++ b/image/assets/lang/English.json @@ -248,7 +248,7 @@ "app_desktop_screen_wrong_passcode_last_attempt_warning": "If the passcode is wrong this time,

you'll have to wait $MINUTES minutes

before trying again.
", "app_desktop_screen_wrong_passcode": "Wrong passcode.

You have $ATTEMPTS attempts left.
", "app_desktop_screen_blocked_info": "Sorry, phone blocked", - "app_desktop_press_to_unlock": "Press Unlock and then #", + "app_desktop_press_to_unlock": "Press Unlock and then #", "app_desktop_unread_messages": "Unread messages", "app_desktop_missed_calls": "Missed calls", "app_desktop_menu_phone": "CALLS", diff --git a/image/assets/lang/Svenska.json b/image/assets/lang/Svenska.json index e295a1abd2a18a99fa2f769edfee7d70ffb43d36..11b39b1000c2c63d4aea14de400464c3183f10af 100644 --- a/image/assets/lang/Svenska.json +++ b/image/assets/lang/Svenska.json @@ -234,7 +234,7 @@ "app_desktop_screen_wrong_passcode_last_attempt_warning": "Om lösenordet är fel den här gången,

måste du vänta $MINUTES minuter

innan nästa försök.
", "app_desktop_screen_wrong_passcode": "Fel lösenord.

Du har $ATTEMPTS försök kvar.
", "app_desktop_screen_blocked_info": "Tyvärr, telefonen blockerad.", - "app_desktop_press_to_unlock": "Tryck Lås upp följt av #", + "app_desktop_press_to_unlock": "Tryck Lås upp följt av #", "app_desktop_unread_messages": "Olästa meddelanden", "app_desktop_missed_calls": "Missade samtal", "app_desktop_menu_phone": "SAMTAL", diff --git a/module-apps/Application.cpp b/module-apps/Application.cpp index 2e0c891b5c3fc91c6cc09541c29ca005e51cd6de..c4d9939f5c5e77355fd1081ccc9ec4138a76f6e7 100644 --- a/module-apps/Application.cpp +++ b/module-apps/Application.cpp @@ -42,7 +42,7 @@ #include #include // for GetOutputVolume -#include +#include #include "popups/data/PopupData.hpp" namespace gui diff --git a/module-apps/Application.hpp b/module-apps/Application.hpp index 4b17ffe3de6a72710072f302e5dd447deadc4bb1..d27e9c0c452c574524c081f9ef7971dc0898849d 100644 --- a/module-apps/Application.hpp +++ b/module-apps/Application.hpp @@ -28,10 +28,9 @@ #include // for move, pair #include // for vector #include "TopBarManager.hpp" -#include "popups/Popups.hpp" #include "WindowsFactory.hpp" #include "WindowsStack.hpp" -#include "Popups.hpp" +#include "popups/Popups.hpp" namespace app { diff --git a/module-apps/CMakeLists.txt b/module-apps/CMakeLists.txt index d484a0c729ed731db05bccfe2f3d54f5a7fb8a53..6804af901302bc5e5056c4f6a2f06b1dff4c8fce 100644 --- a/module-apps/CMakeLists.txt +++ b/module-apps/CMakeLists.txt @@ -30,13 +30,6 @@ set( SOURCES "windows/NoEvents.cpp" "widgets/ButtonOnOff.cpp" "widgets/InputBox.cpp" - "popups/Popups.cpp" - "popups/VolumeWindow.cpp" - "popups/WindowWithTimer.cpp" - "popups/HomeModesWindow.cpp" - "popups/TetheringNotificationPopup.cpp" - "popups/TetheringConfirmationPopup.cpp" - "popups/TetheringPhoneModePopup.cpp" "windows/BrightnessWindow.cpp" "widgets/BrightnessBox.cpp" "widgets/ModesBox.cpp" @@ -120,6 +113,9 @@ include_directories( ../module-os ) include_directories( ../module-bsp ) include_directories( ../module-db ) +add_subdirectory(popups) +add_subdirectory(locks) + target_link_libraries(${PROJECT_NAME} PRIVATE service-appmgr @@ -156,7 +152,6 @@ target_include_directories(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/messages ${CMAKE_CURRENT_SOURCE_DIR}/windows - ${CMAKE_CURRENT_SOURCE_DIR}/popups ${CMAKE_CURRENT_SOURCE_DIR}/options ${CMAKE_CURRENT_SOURCE_DIR}/options/type ${CMAKE_BINARY_DIR} diff --git a/module-apps/application-desktop/ApplicationDesktop.cpp b/module-apps/application-desktop/ApplicationDesktop.cpp index 11e50ef05bbcb25f093b531cf58b7ba87c2997bd..d82c91d5f7b9f5e305a3eb6dd93bf4c6c0822958 100644 --- a/module-apps/application-desktop/ApplicationDesktop.cpp +++ b/module-apps/application-desktop/ApplicationDesktop.cpp @@ -6,7 +6,7 @@ #include "MessageType.hpp" #include "windows/DesktopMainWindow.hpp" #include "windows/MenuWindow.hpp" -#include "windows/PinLockWindow.hpp" +#include "locks/windows/PinLockWindow.hpp" #include "windows/PowerOffWindow.hpp" #include "windows/DeadBatteryWindow.hpp" #include "windows/LogoWindow.hpp" @@ -25,7 +25,8 @@ #include #include "AppWindow.hpp" -#include "data/LockPhoneData.hpp" +#include "locks/data/LockData.hpp" +#include "data/DesktopData.hpp" #include "models/ActiveNotificationsModel.hpp" #include @@ -86,7 +87,7 @@ namespace app bus.channels.push_back(sys::BusChannel::ServiceDBNotifications); addActionReceiver(app::manager::actions::RequestPin, [this](auto &&data) { - lockHandler.handlePasscodeRequest(gui::PinLock::LockType::SimPin, std::move(data)); + lockHandler.handlePasscodeRequest(locks::Lock::LockType::SimPin, std::move(data)); return actionHandled(); }); @@ -96,7 +97,7 @@ namespace app }); addActionReceiver(app::manager::actions::RequestPuk, [this](auto &&data) { - lockHandler.handlePasscodeRequest(gui::PinLock::LockType::SimPuk, std::move(data)); + lockHandler.handlePasscodeRequest(locks::Lock::LockType::SimPuk, std::move(data)); return actionHandled(); }); diff --git a/module-apps/application-desktop/ApplicationDesktop.hpp b/module-apps/application-desktop/ApplicationDesktop.hpp index 6e53cf83f3531280b4fc52527070af0d4a3a8e75..75110a14a5c4444aaad590061ee77815e752bd1c 100644 --- a/module-apps/application-desktop/ApplicationDesktop.hpp +++ b/module-apps/application-desktop/ApplicationDesktop.hpp @@ -4,7 +4,7 @@ #pragma once #include "windows/Names.hpp" -#include "widgets/PinLockHandler.hpp" +#include "locks/handlers/PinLockHandler.hpp" #include #include diff --git a/module-apps/application-desktop/CMakeLists.txt b/module-apps/application-desktop/CMakeLists.txt index e48ecfe0cefa4a75dc20d02879526cc5d9dd8e5e..6d23ddf4c30ff71bbd11f87a544468c62a4aa82b 100644 --- a/module-apps/application-desktop/CMakeLists.txt +++ b/module-apps/application-desktop/CMakeLists.txt @@ -15,15 +15,8 @@ target_sources( ${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_LIST_DIR}/ApplicationDesktop.cpp" - "${CMAKE_CURRENT_LIST_DIR}/widgets/PinLock.cpp" - "${CMAKE_CURRENT_LIST_DIR}/widgets/PinLockHandler.cpp" "${CMAKE_CURRENT_LIST_DIR}/widgets/DesktopInputWidget.cpp" "${CMAKE_CURRENT_LIST_DIR}/windows/DesktopMainWindow.cpp" - "${CMAKE_CURRENT_LIST_DIR}/windows/PinLockBaseWindow.cpp" - "${CMAKE_CURRENT_LIST_DIR}/windows/ScreenLockBox.cpp" - "${CMAKE_CURRENT_LIST_DIR}/windows/SimLockBox.cpp" - "${CMAKE_CURRENT_LIST_DIR}/windows/PukLockBox.cpp" - "${CMAKE_CURRENT_LIST_DIR}/windows/PinLockWindow.cpp" "${CMAKE_CURRENT_LIST_DIR}/windows/MenuWindow.cpp" "${CMAKE_CURRENT_LIST_DIR}/windows/PowerOffWindow.cpp" "${CMAKE_CURRENT_LIST_DIR}/windows/DeadBatteryWindow.cpp" @@ -37,27 +30,16 @@ target_sources( ${PROJECT_NAME} "${CMAKE_CURRENT_LIST_DIR}/windows/MmiPullWindow.cpp" "${CMAKE_CURRENT_LIST_DIR}/windows/MmiPushWindow.cpp" "${CMAKE_CURRENT_LIST_DIR}/windows/MmiInternalMsgWindow.cpp" - "${CMAKE_CURRENT_LIST_DIR}/windows/ScreenLockBaseBox.cpp" - "${CMAKE_CURRENT_LIST_DIR}/windows/LockWindow.cpp" "${CMAKE_CURRENT_LIST_DIR}/windows/UpdateProgress.cpp" "${CMAKE_CURRENT_LIST_DIR}/presenter/PowerOffPresenter.cpp" "${CMAKE_CURRENT_LIST_DIR}/models/ActiveNotificationsModel.cpp" PUBLIC "${CMAKE_CURRENT_LIST_DIR}/ApplicationDesktop.hpp" - "${CMAKE_CURRENT_LIST_DIR}/data/LockPhoneData.hpp" - "${CMAKE_CURRENT_LIST_DIR}/data/Style.hpp" + "${CMAKE_CURRENT_LIST_DIR}/data/DesktopData.hpp" + "${CMAKE_CURRENT_LIST_DIR}/data/DesktopStyle.hpp" "${CMAKE_CURRENT_LIST_DIR}/data/Mmi.hpp" - "${CMAKE_CURRENT_LIST_DIR}/widgets/PinHash.hpp" - "${CMAKE_CURRENT_LIST_DIR}/widgets/PinLock.hpp" "${CMAKE_CURRENT_LIST_DIR}/widgets/DesktopInputWidget.hpp" - "${CMAKE_CURRENT_LIST_DIR}/widgets/PinLockHandler.hpp" "${CMAKE_CURRENT_LIST_DIR}/windows/DesktopMainWindow.hpp" - "${CMAKE_CURRENT_LIST_DIR}/windows/PinLockBaseWindow.hpp" - "${CMAKE_CURRENT_LIST_DIR}/windows/PinLockBox.hpp" - "${CMAKE_CURRENT_LIST_DIR}/windows/ScreenLockBox.hpp" - "${CMAKE_CURRENT_LIST_DIR}/windows/SimLockBox.hpp" - "${CMAKE_CURRENT_LIST_DIR}/windows/PukLockBox.hpp" - "${CMAKE_CURRENT_LIST_DIR}/windows/PinLockWindow.hpp" "${CMAKE_CURRENT_LIST_DIR}/windows/MenuWindow.hpp" "${CMAKE_CURRENT_LIST_DIR}/windows/PowerOffWindow.hpp" "${CMAKE_CURRENT_LIST_DIR}/windows/LockedInfoWindow.hpp" @@ -69,8 +51,6 @@ target_sources( ${PROJECT_NAME} "${CMAKE_CURRENT_LIST_DIR}/windows/MmiPullWindow.hpp" "${CMAKE_CURRENT_LIST_DIR}/windows/MmiPushWindow.hpp" "${CMAKE_CURRENT_LIST_DIR}/windows/MmiInternalMsgWindow.hpp" - "${CMAKE_CURRENT_LIST_DIR}/windows/ScreenLockBaseBox.hpp" - "${CMAKE_CURRENT_LIST_DIR}/windows/LockWindow.hpp" "${CMAKE_CURRENT_LIST_DIR}/models/ActiveNotificationsModel.hpp" ) diff --git a/module-apps/application-desktop/data/DesktopData.hpp b/module-apps/application-desktop/data/DesktopData.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7c78c9115014514dc740c67590119dba058bc2dd --- /dev/null +++ b/module-apps/application-desktop/data/DesktopData.hpp @@ -0,0 +1,46 @@ +// 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 "gui/SwitchData.hpp" +#include +#include +#include +#include + +namespace gui +{ + + class UpdateSwitchData : public gui::SwitchData + { + public: + explicit UpdateSwitchData(sdesktop::UpdateOsMessage *messageToCopyFrom) : updateOsMessage(*messageToCopyFrom) + {} + + [[nodiscard]] const sdesktop::UpdateOsMessage &getUpdateOsMessage() const noexcept + { + return updateOsMessage; + } + + private: + sdesktop::UpdateOsMessage updateOsMessage; + }; + + class CurrentOsVersion : public gui::SwitchData + { + std::string osVersion; + + public: + [[nodiscard]] std::string getCurrentOsVersion() const + { + return osVersion; + } + + void setData(std::string version) + { + osVersion = std::move(version); + } + }; + +} // namespace gui diff --git a/module-apps/application-desktop/data/Style.hpp b/module-apps/application-desktop/data/DesktopStyle.hpp similarity index 98% rename from module-apps/application-desktop/data/Style.hpp rename to module-apps/application-desktop/data/DesktopStyle.hpp index ecfa21d81c0ac807a160cfdaf2252ffe114aa7b2..2bba94a4673224d9eb05b0d5e6efa3d744e0f1d5 100644 --- a/module-apps/application-desktop/data/Style.hpp +++ b/module-apps/application-desktop/data/DesktopStyle.hpp @@ -3,6 +3,8 @@ #pragma once +#include "Style.hpp" + namespace style::desktop { namespace timeLabel diff --git a/module-apps/application-desktop/data/LockPhoneData.hpp b/module-apps/application-desktop/data/LockPhoneData.hpp deleted file mode 100644 index 575edc36cbe7965b8a706f80983d6a093aeb0d13..0000000000000000000000000000000000000000 --- a/module-apps/application-desktop/data/LockPhoneData.hpp +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#ifndef MODULE_APPS_APPLICATION_DESKTOP_DATA_LOCKPHONEDATA_HPP_ -#define MODULE_APPS_APPLICATION_DESKTOP_DATA_LOCKPHONEDATA_HPP_ - -#include "gui/SwitchData.hpp" -#include -#include -#include - -#include "application-desktop/widgets/PinLock.hpp" - -namespace gui -{ - - // class template that stores information that was sent along with switch message - class LockPhoneData : public gui::SwitchData - { - std::string previousApplication; - std::unique_ptr lock; - - public: - LockPhoneData(std::unique_ptr &&lock) : SwitchData(), lock(std::move(lock)) - { - description = "LockPhoneData"; - } - - virtual ~LockPhoneData(){}; - - void setPrevApplication(const std::string &prevApp) - { - previousApplication = prevApp; - }; - [[nodiscard]] const std::string &getPreviousApplication() - { - return previousApplication; - }; - - [[nodiscard]] std::unique_ptr getLock() - { - return std::make_unique(*lock.get()); - } - }; - - class UpdateSwitchData : public gui::SwitchData - { - public: - UpdateSwitchData(sdesktop::UpdateOsMessage *messageToCopyFrom) : updateOsMessage(*messageToCopyFrom) - {} - - const sdesktop::UpdateOsMessage &getUpdateOsMessage() - { - return updateOsMessage; - } - - private: - sdesktop::UpdateOsMessage updateOsMessage; - }; - - class CurrentOsVersion : public gui::SwitchData - { - std::string osVersion; - - public: - [[nodiscard]] std::string getCurrentOsVersion() const - { - return osVersion; - } - - void setData(std::string version) - { - osVersion = version; - } - }; - -} // namespace gui - -#endif /* MODULE_APPS_APPLICATION_DESKTOP_DATA_LOCKPHONEDATA_HPP_ */ diff --git a/module-apps/application-desktop/widgets/PinLock.cpp b/module-apps/application-desktop/widgets/PinLock.cpp deleted file mode 100644 index af4032e4a274581bf110dbf4a43054e12ea2ea85..0000000000000000000000000000000000000000 --- a/module-apps/application-desktop/widgets/PinLock.cpp +++ /dev/null @@ -1,58 +0,0 @@ -// 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" -#include - -namespace gui -{ - void PinLock::consumeState() noexcept - { - if (lockState == LockState::PasscodeInvalidRetryRequired) { - lockState = LockState::PasscodeRequired; - } - else if (lockState == LockState::NewPasscodeInvalid) { - lockState = LockState::NewPasscodeRequired; - } - } - - void PinLock::setNewPasscodeInvalidState() noexcept - { - if (lockState == LockState::NewPasscodeRequired) { - lockState = LockState::NewPasscodeInvalid; - } - } - - void PinLock::putNextChar(unsigned int c) - { - if (maxPinSize > pinValue.size()) { - pinValue.push_back(c); - } - if (canVerify() && autoActivate && onActivatedCallback != nullptr) { - onActivatedCallback(lockType, pinValue); - } - } - - void PinLock::popChar() - { - if (pinValue.size() > 0) { - pinValue.pop_back(); - } - } - - void PinLock::clearAttempt() noexcept - { - pinValue.clear(); - } - - void PinLock::activate() - { - auto pinCopy = std::move(pinValue); - clearAttempt(); - if (!onActivatedCallback) { - LOG_ERROR("Passcode verification callback null"); - return; - } - onActivatedCallback(lockType, pinCopy); - } -} // namespace gui diff --git a/module-apps/application-desktop/windows/DesktopMainWindow.cpp b/module-apps/application-desktop/windows/DesktopMainWindow.cpp index d56d0b2454b4ef3d91fb6a27d051f70ce4a5ac12..8128866916070aa313d572c5d642654524e31299 100644 --- a/module-apps/application-desktop/windows/DesktopMainWindow.cpp +++ b/module-apps/application-desktop/windows/DesktopMainWindow.cpp @@ -8,8 +8,9 @@ #include "DesktopMainWindow.hpp" #include "GuiTimer.hpp" #include "application-desktop/ApplicationDesktop.hpp" -#include "application-desktop/data/LockPhoneData.hpp" -#include "application-desktop/data/Style.hpp" +#include "locks/data/LockData.hpp" +#include "application-desktop/data/DesktopStyle.hpp" +#include "application-desktop/data/DesktopData.hpp" #include "application-messages/ApplicationMessages.hpp" #include "gui/widgets/Image.hpp" #include diff --git a/module-apps/application-desktop/windows/LockedInfoWindow.cpp b/module-apps/application-desktop/windows/LockedInfoWindow.cpp index 9bdc3a0999216eb47315ce02228ad37e25abc887..bb70d5cfff919178517c23770a021d8ee0f4c627 100644 --- a/module-apps/application-desktop/windows/LockedInfoWindow.cpp +++ b/module-apps/application-desktop/windows/LockedInfoWindow.cpp @@ -9,7 +9,8 @@ #include "RichTextParser.hpp" #include "FontManager.hpp" -#include "application-desktop/data/AppDesktopStyle.hpp" +#include "application-desktop/data/DesktopStyle.hpp" +#include "locks/data/LockStyle.hpp" #include "Names.hpp" #include diff --git a/module-apps/application-desktop/windows/PinLockBox.hpp b/module-apps/application-desktop/windows/PinLockBox.hpp deleted file mode 100644 index 58882f6ab6d23507a00ff8869ef1edd340cea31a..0000000000000000000000000000000000000000 --- a/module-apps/application-desktop/windows/PinLockBox.hpp +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#pragma once - -#include - -namespace gui -{ - class PinLockBox - { - public: - enum class EnterPasscodeType - { - ProvidePasscode, - ProvideNewPasscode, - ConfirmNewPasscode - }; - - enum class PasscodeErrorType - { - InvalidPasscode, - NewPasscodeConfirmFailed, - UnhandledError - }; - - virtual void popChar(unsigned int charNum) = 0; - virtual void putChar(unsigned int charNum) = 0; - virtual void clear() = 0; - - virtual void setVisibleStateEnterPin(EnterPasscodeType type) = 0; - virtual void setVisibleStateInvalidPin(PasscodeErrorType type, unsigned int value) = 0; - virtual void setVisibleStateBlocked() = 0; - - virtual void buildLockBox(unsigned int pinSize) = 0; - virtual ~PinLockBox() = default; - }; -} // namespace gui diff --git a/module-apps/application-desktop/windows/PostUpdateWindow.cpp b/module-apps/application-desktop/windows/PostUpdateWindow.cpp index 5c4c10025a75bc679374b8cf947fb613b474e293..4060bf8cfa34d4439c199f3fa5111ceaa3f9307d 100644 --- a/module-apps/application-desktop/windows/PostUpdateWindow.cpp +++ b/module-apps/application-desktop/windows/PostUpdateWindow.cpp @@ -12,8 +12,9 @@ #include #include -#include -#include +#include +#include +#include #include #include diff --git a/module-apps/application-desktop/windows/ScreenLockBox.hpp b/module-apps/application-desktop/windows/ScreenLockBox.hpp deleted file mode 100644 index 184cca71138886e48565d65bcd096b5dc3e215f5..0000000000000000000000000000000000000000 --- a/module-apps/application-desktop/windows/ScreenLockBox.hpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#pragma once - -#include "PinLockBaseWindow.hpp" -#include "ScreenLockBaseBox.hpp" - -namespace gui -{ - class ScreenLockBox : public ScreenLockBaseBox - { - public: - ScreenLockBox(PinLockBaseWindow *LockBaseWindow) : ScreenLockBaseBox(LockBaseWindow), LockWindow(LockBaseWindow) - {} - - private: - void buildLockBox(unsigned int pinSize) final; - void setVisibleStateBlocked() final; - void setVisibleStateEnterPin(EnterPasscodeType type) final; - void setVisibleStateInvalidPin(PasscodeErrorType type, unsigned int value) final; - - PinLockBaseWindow *LockWindow; - }; -} // namespace gui diff --git a/module-apps/application-desktop/windows/Update.cpp b/module-apps/application-desktop/windows/Update.cpp index cdb35cd19af72c0bdc74c352742aedf1c184e9b6..fe077ad189af5885a4f4836f42c40622c73677bb 100644 --- a/module-apps/application-desktop/windows/Update.cpp +++ b/module-apps/application-desktop/windows/Update.cpp @@ -4,7 +4,7 @@ #include "log/log.hpp" #include "gui/widgets/BottomBar.hpp" #include "gui/widgets/TopBar.hpp" -#include "../data/LockPhoneData.hpp" +#include "application-desktop/data/DesktopData.hpp" #include // module-utils diff --git a/module-apps/application-desktop/windows/UpdateProgress.cpp b/module-apps/application-desktop/windows/UpdateProgress.cpp index 8a86c59bf0adc4e289d8a7d8efa4f8162b7afb8a..64459385f186da9150e527001d65f1f0d3156728 100644 --- a/module-apps/application-desktop/windows/UpdateProgress.cpp +++ b/module-apps/application-desktop/windows/UpdateProgress.cpp @@ -4,14 +4,14 @@ #include #include #include -#include #include // module-utils #include #include -#include +#include +#include // services #include diff --git a/module-apps/application-onboarding/windows/ConfigurePasscodeWindow.cpp b/module-apps/application-onboarding/windows/ConfigurePasscodeWindow.cpp index cd9e5a4ad0133a35a82c678db0206eb3220500a6..754891091aa11eaf9f56f5be0a467387173d840d 100644 --- a/module-apps/application-onboarding/windows/ConfigurePasscodeWindow.cpp +++ b/module-apps/application-onboarding/windows/ConfigurePasscodeWindow.cpp @@ -2,10 +2,10 @@ // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "ConfigurePasscodeWindow.hpp" +#include "locks/data/LockStyle.hpp" #include #include -#include #include #include @@ -20,7 +20,7 @@ namespace gui { ConfigurePasscodeWindow::ConfigurePasscodeWindow(app::Application *app) : ChangePasscodeWindow(app) { - lockState = PinLock::LockState::NewPasscodeRequired; + lockState = Lock::LockState::NewInputRequired; textForEnterNewPassword = "app_onboarding_set_password"; testForConfirmPassword = "app_onboarding_confirm_password"; @@ -54,10 +54,10 @@ namespace gui void ConfigurePasscodeWindow::processPasscode() { switch (lockState) { - case PinLock::LockState::NewPasscodeConfirmRequired: - case PinLock::LockState::NewPasscodeInvalid: { + case Lock::LockState::NewInputConfirmRequired: + case Lock::LockState::NewInputInvalid: { lockState = lockHandler.newPasscodeConfirmed(); - if (lockState == PinLock::LockState::Unlocked) { + if (lockState == Lock::LockState::Unlocked) { auto app = static_cast(application); app->setLockPassHash(lockHandler.getNewPasscodeHash()); } @@ -71,7 +71,7 @@ namespace gui void ConfigurePasscodeWindow::setVisibleState() { switch (lockState) { - case PinLock::LockState::NewPasscodeInvalid: { + case Lock::LockState::NewInputInvalid: { auto metaData = std::make_unique( gui::DialogMetadata{utils::translate("app_onboarding_passcode_configuration"), @@ -91,7 +91,7 @@ namespace gui break; } - case PinLock::LockState::Unlocked: { + case Lock::LockState::Unlocked: { application->setLockScreenPasscodeOn(true); application->switchWindow(gui::window::name::onBoarding_date_and_time, gui::ShowMode::GUI_SHOW_INIT, diff --git a/module-apps/application-onboarding/windows/ConfigurePasscodeWindow.hpp b/module-apps/application-onboarding/windows/ConfigurePasscodeWindow.hpp index 1740a5b7dbb55c0767740bcee33e202cdf82121a..8a5508bcfa1de660f8083a3317a236040d3e08ac 100644 --- a/module-apps/application-onboarding/windows/ConfigurePasscodeWindow.hpp +++ b/module-apps/application-onboarding/windows/ConfigurePasscodeWindow.hpp @@ -3,8 +3,8 @@ #pragma once -#include -#include +#include +#include #include #include #include diff --git a/module-apps/application-settings-new/ApplicationSettings.cpp b/module-apps/application-settings-new/ApplicationSettings.cpp index 7b688c3621106e877a0e804a113d633f4de10eca..41e16eeed9c34f1f923631106d72bf6d4e094045 100644 --- a/module-apps/application-settings-new/ApplicationSettings.cpp +++ b/module-apps/application-settings-new/ApplicationSettings.cpp @@ -77,7 +77,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/module-apps/application-settings-new/widgets/ChangePasscodeLockHandler.cpp b/module-apps/application-settings-new/widgets/ChangePasscodeLockHandler.cpp index b7f721ee556639252ae5249ab79ea5e13c337ae2..eeb78ad9be6717869865a8165fb9bb71fc2c3af3 100644 --- a/module-apps/application-settings-new/widgets/ChangePasscodeLockHandler.cpp +++ b/module-apps/application-settings-new/widgets/ChangePasscodeLockHandler.cpp @@ -2,53 +2,53 @@ // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "ChangePasscodeLockHandler.hpp" -#include "application-desktop/widgets/PinHash.hpp" +#include "locks/widgets/LockHash.hpp" namespace gui { ChangePasscodeLockHandler::ChangePasscodeLockHandler() - : lock(Store::GSM::SIM::NONE, PinLock::LockState::PasscodeRequired, PinLock::LockType::Screen) + : lock(Store::GSM::SIM::NONE, Lock::LockState::InputRequired, Lock::LockType::Screen) {} - PinLock::LockState ChangePasscodeLockHandler::checkPasscode(unsigned int currentLockPassHash) + Lock::LockState ChangePasscodeLockHandler::checkPasscode(unsigned int currentLockPassHash) { - return activateLock([this, currentLockPassHash](PinLock::LockType, const std::vector &pin) { - const auto hash = GetPinHash(pin); + return activateLock([this, currentLockPassHash](Lock::LockType, const std::vector &pin) { + const auto hash = getHash(pin); if (hash == currentLockPassHash) { - lock.lockState = PinLock::LockState::NewPasscodeRequired; + lock.lockState = Lock::LockState::NewInputRequired; } else { - lock.lockState = PinLock::LockState::PasscodeInvalidRetryRequired; + lock.lockState = Lock::LockState::InputInvalidRetryRequired; } }); } - PinLock::LockState ChangePasscodeLockHandler::newPasscodeConfirmed() + Lock::LockState ChangePasscodeLockHandler::newPasscodeConfirmed() { - return activateLock([this](PinLock::LockType, const std::vector &pin) { - const auto newPasscodeConfirmedHash = GetPinHash(pin); + return activateLock([this](Lock::LockType, const std::vector &pin) { + const auto newPasscodeConfirmedHash = getHash(pin); if (newPasscodeHash == newPasscodeConfirmedHash) { - lock.lockState = PinLock::LockState::Unlocked; + lock.lockState = Lock::LockState::Unlocked; } else { - lock.lockState = PinLock::LockState::NewPasscodeInvalid; + lock.lockState = Lock::LockState::NewInputInvalid; } }); } - PinLock::LockState ChangePasscodeLockHandler::newPasscodeProvided() + Lock::LockState ChangePasscodeLockHandler::newPasscodeProvided() { - return activateLock([this](PinLock::LockType, const std::vector &pin) { - if (pin.size() < lock.getMaxPinSize()) { - lock.lockState = PinLock::LockState::NewPasscodeInvalidRetryRequired; + return activateLock([this](Lock::LockType, const std::vector &pin) { + if (pin.size() < lock.getMaxInputSize()) { + lock.lockState = Lock::LockState::NewInputInvalidRetryRequired; return; } - newPasscodeHash = GetPinHash(pin); - lock.lockState = PinLock::LockState::NewPasscodeConfirmRequired; + newPasscodeHash = getHash(pin); + lock.lockState = Lock::LockState::NewInputConfirmRequired; }); } - PinLock::LockState ChangePasscodeLockHandler::activateLock(OnActivatedCallback onActivatedCallback) + Lock::LockState ChangePasscodeLockHandler::activateLock(OnActivatedCallback onActivatedCallback) { lock.onActivatedCallback = onActivatedCallback; lock.activate(); diff --git a/module-apps/application-settings-new/widgets/ChangePasscodeLockHandler.hpp b/module-apps/application-settings-new/widgets/ChangePasscodeLockHandler.hpp index 95588d0c92540ef2cf65e190660f1ade2aab2e08..64dacb2f7e69838db8afaac98b633f657da4f6a1 100644 --- a/module-apps/application-settings-new/widgets/ChangePasscodeLockHandler.hpp +++ b/module-apps/application-settings-new/widgets/ChangePasscodeLockHandler.hpp @@ -3,17 +3,19 @@ #pragma once -#include "application-desktop/widgets/PinLock.hpp" +#include "locks/widgets/Lock.hpp" namespace gui { + using namespace locks; + class ChangePasscodeLockHandler { public: ChangePasscodeLockHandler(); - auto checkPasscode(unsigned int currentLockPassHash) -> PinLock::LockState; - [[nodiscard]] auto getLock() -> PinLock & + auto checkPasscode(unsigned int currentLockPassHash) -> Lock::LockState; + [[nodiscard]] auto getLock() -> Lock & { return lock; } @@ -21,14 +23,14 @@ namespace gui { return newPasscodeHash; } - auto newPasscodeConfirmed() -> PinLock::LockState; - auto newPasscodeProvided() -> PinLock::LockState; + auto newPasscodeConfirmed() -> Lock::LockState; + auto newPasscodeProvided() -> Lock::LockState; private: - using OnActivatedCallback = std::function &)>; - auto activateLock(OnActivatedCallback onActivatedCallback) -> PinLock::LockState; + using OnActivatedCallback = std::function &)>; + auto activateLock(OnActivatedCallback onActivatedCallback) -> Lock::LockState; - PinLock lock; + Lock lock; unsigned int newPasscodeHash; }; } // namespace gui diff --git a/module-apps/application-settings-new/windows/ChangePasscodeWindow.cpp b/module-apps/application-settings-new/windows/ChangePasscodeWindow.cpp index db9996602279d2c7cb0bc57f0309244d197d015a..77a7d2018f1a64d480ecdd95922d99ae9ad0cc45 100644 --- a/module-apps/application-settings-new/windows/ChangePasscodeWindow.cpp +++ b/module-apps/application-settings-new/windows/ChangePasscodeWindow.cpp @@ -1,8 +1,8 @@ // Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md -#include "application-desktop/data/AppDesktopStyle.hpp" #include "application-settings-new/ApplicationSettings.hpp" +#include "locks/data/LockStyle.hpp" #include "ChangePasscodeWindow.hpp" #include "DialogMetadata.hpp" #include "DialogMetadataMessage.hpp" @@ -22,7 +22,7 @@ namespace gui auto ChangePasscodeWindow::onInput(const InputEvent &inputEvent) -> bool { auto &lock = lockHandler.getLock(); - if (lock.isState(PinLock::LockState::Unlocked) && inputEvent.isShortPress()) { + if (lock.isState(Lock::LockState::Unlocked) && inputEvent.isShortPress()) { application->returnToPreviousWindow(); } if (!inputEvent.isShortPress()) { @@ -65,8 +65,8 @@ namespace gui AppWindow::buildInterface(); LockWindow::build(); - lockBox = std::make_unique(this); - lockBox->buildLockBox(lockHandler.getLock().getMaxPinSize()); + lockBox = std::make_unique(this); + lockBox->buildLockBox(lockHandler.getLock().getMaxInputSize()); lockImage = new gui::Image(this, lock_style::image::x, lock_style::image::y, 0, 0, "pin_lock"); @@ -90,7 +90,7 @@ namespace gui auto changePasscodeData = static_cast(data); changePasscodeAction = changePasscodeData->changePasscodeAction; if (ChangePasscodeAction::OnlyProvideNewPasscode == changePasscodeAction) { - lockState = PinLock::LockState::NewPasscodeRequired; + lockState = Lock::LockState::NewInputRequired; } } setVisibleState(); @@ -99,12 +99,12 @@ namespace gui void ChangePasscodeWindow::processPasscode() { switch (lockState) { - case PinLock::LockState::PasscodeRequired: - case PinLock::LockState::PasscodeInvalidRetryRequired: { + case Lock::LockState::InputRequired: + case Lock::LockState::InputInvalidRetryRequired: { auto app = static_cast(application); lockState = lockHandler.checkPasscode(app->getLockPassHash()); if (ChangePasscodeAction::OnlyCheckCurrentPasscode == changePasscodeAction && - lockState == PinLock::LockState::NewPasscodeRequired) { + lockState == Lock::LockState::NewInputRequired) { application->setLockScreenPasscodeOn(false); auto metaData = std::make_unique( @@ -122,15 +122,15 @@ namespace gui } break; } - case PinLock::LockState::NewPasscodeRequired: - case PinLock::LockState::NewPasscodeInvalidRetryRequired: { + case Lock::LockState::NewInputRequired: + case Lock::LockState::NewInputInvalidRetryRequired: { lockState = lockHandler.newPasscodeProvided(); break; } - case PinLock::LockState::NewPasscodeConfirmRequired: - case PinLock::LockState::NewPasscodeInvalid: { + case Lock::LockState::NewInputConfirmRequired: + case Lock::LockState::NewInputInvalid: { lockState = lockHandler.newPasscodeConfirmed(); - if (lockState == PinLock::LockState::Unlocked) { + if (lockState == Lock::LockState::Unlocked) { auto app = static_cast(application); app->setLockPassHash(lockHandler.getNewPasscodeHash()); } @@ -145,28 +145,28 @@ namespace gui { lockBox->clear(); switch (lockState) { - case PinLock::LockState::PasscodeRequired: { + case Lock::LockState::InputRequired: { setText("app_settings_security_type_current_passcode", LockWindow::TextType::Primary); secondaryText->setVisible(false); break; } - case PinLock::LockState::NewPasscodeRequired: { + case Lock::LockState::NewInputRequired: { setText("app_settings_security_enter_new_passcode", LockWindow::TextType::Primary); secondaryText->setVisible(false); break; } - case PinLock::LockState::NewPasscodeConfirmRequired: { + case Lock::LockState::NewInputConfirmRequired: { setText("app_settings_security_confirm_new_passcode", LockWindow::TextType::Primary); secondaryText->setVisible(false); break; } - case PinLock::LockState::PasscodeInvalidRetryRequired: - case PinLock::LockState::NewPasscodeInvalidRetryRequired: - case PinLock::LockState::NewPasscodeInvalid: { + case Lock::LockState::InputInvalidRetryRequired: + case Lock::LockState::NewInputInvalidRetryRequired: + case Lock::LockState::NewInputInvalid: { setText("app_settings_security_wrong_passcode", LockWindow::TextType::Secondary); break; } - case PinLock::LockState::Unlocked: { + case Lock::LockState::Unlocked: { application->setLockScreenPasscodeOn(true); auto metaData = std::make_unique( diff --git a/module-apps/application-settings-new/windows/ChangePasscodeWindow.hpp b/module-apps/application-settings-new/windows/ChangePasscodeWindow.hpp index d89a6f1cba36c1cb695c969cd570af71437e3dbb..291858b1fb4374daf0a2d2fd3ec6f18a1c25747a 100644 --- a/module-apps/application-settings-new/windows/ChangePasscodeWindow.hpp +++ b/module-apps/application-settings-new/windows/ChangePasscodeWindow.hpp @@ -3,8 +3,8 @@ #pragma once -#include "application-desktop/windows/LockWindow.hpp" -#include "application-desktop/windows/ScreenLockBaseBox.hpp" +#include "locks/windows/LockWindow.hpp" +#include "locks/widgets/PhoneLockBaseBox.hpp" #include "application-settings-new/data/ChangePasscodeData.hpp" #include "application-settings-new/widgets/ChangePasscodeLockHandler.hpp" @@ -28,9 +28,9 @@ namespace gui virtual void setVisibleState(); ChangePasscodeAction changePasscodeAction; - std::unique_ptr lockBox = nullptr; + std::unique_ptr lockBox = nullptr; gui::Image *lockImage = nullptr; - PinLock::LockState lockState{PinLock::LockState::PasscodeRequired}; + Lock::LockState lockState{Lock::LockState::InputRequired}; ChangePasscodeLockHandler lockHandler; std::string textForEnterCurrentPassword = "app_settings_security_type_current_passcode"; diff --git a/module-apps/application-settings-new/windows/SecurityMainWindow.cpp b/module-apps/application-settings-new/windows/SecurityMainWindow.cpp index bd443443da58a83ffae02f2e41e435919cebdf1a..a955da5bc2da542a16577be0e49762859c497762 100644 --- a/module-apps/application-settings-new/windows/SecurityMainWindow.cpp +++ b/module-apps/application-settings-new/windows/SecurityMainWindow.cpp @@ -1,10 +1,11 @@ // Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md +#include +#include #include "application-settings-new/ApplicationSettings.hpp" #include "application-settings-new/data/ChangePasscodeData.hpp" #include "module-apps/application-desktop/windows/Names.hpp" -#include "module-apps/application-desktop/data/LockPhoneData.hpp" #include "OptionSetting.hpp" #include "SecurityMainWindow.hpp" @@ -45,15 +46,15 @@ namespace gui optionList.emplace_back(std::make_unique( utils::translate("app_settings_security_usb_passcode"), [=](Item &item) { - auto lock = std::make_unique( - Store::GSM::SIM::NONE, PinLock::LockState::PasscodeRequired, PinLock::LockType::Screen); - lock->onActivatedCallback = [this](PinLock::LockType type, const std::vector &data) { + auto lock = std::make_unique( + Store::GSM::SIM::NONE, locks::Lock::LockState::InputRequired, locks::Lock::LockType::Screen); + lock->onActivatedCallback = [this](locks::Lock::LockType type, const std::vector &data) { securitySettings->setUSBSecurity(!securitySettings->isUSBSecured()); application->returnToPreviousWindow(); }; application->switchWindow(app::window::name::desktop_pin_lock, gui::ShowMode::GUI_SHOW_INIT, - std::make_unique(std::move(lock))); + std::make_unique(*lock)); return true; }, [=](Item &item) { diff --git a/module-apps/locks/CMakeLists.txt b/module-apps/locks/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..a809df328225c65e3174266429dbded3293eb7d7 --- /dev/null +++ b/module-apps/locks/CMakeLists.txt @@ -0,0 +1,41 @@ + +include_directories( ${CMAKE_PROJECT_NAME} + + PRIVATE + "${CMAKE_CURRENT_LIST_DIR}" +) + +include_directories( ${PROJECT_NAME} + + PRIVATE + "${CMAKE_CURRENT_LIST_DIR}" +) + +target_sources( ${PROJECT_NAME} + + PRIVATE + "${CMAKE_CURRENT_LIST_DIR}/handlers/PinLockHandler.cpp" + "${CMAKE_CURRENT_LIST_DIR}/windows/LockWindow.cpp" + "${CMAKE_CURRENT_LIST_DIR}/windows/PinLockBaseWindow.cpp" + "${CMAKE_CURRENT_LIST_DIR}/windows/PinLockWindow.cpp" + "${CMAKE_CURRENT_LIST_DIR}/widgets/Lock.cpp" + "${CMAKE_CURRENT_LIST_DIR}/widgets/PukLockBox.cpp" + "${CMAKE_CURRENT_LIST_DIR}/widgets/PhoneLockBaseBox.cpp" + "${CMAKE_CURRENT_LIST_DIR}/widgets/PhoneLockBox.cpp" + "${CMAKE_CURRENT_LIST_DIR}/widgets/SimLockBox.cpp" + + PRIVATE + "${CMAKE_CURRENT_LIST_DIR}/data/LockData.hpp" + "${CMAKE_CURRENT_LIST_DIR}/data/LockStyle.hpp" + "${CMAKE_CURRENT_LIST_DIR}/handlers/PinLockHandler.hpp" + "${CMAKE_CURRENT_LIST_DIR}/windows/LockWindow.hpp" + "${CMAKE_CURRENT_LIST_DIR}/windows/PinLockBaseWindow.hpp" + "${CMAKE_CURRENT_LIST_DIR}/windows/PinLockWindow.hpp" + "${CMAKE_CURRENT_LIST_DIR}/widgets/LockHash.hpp" + "${CMAKE_CURRENT_LIST_DIR}/widgets/Lock.hpp" + "${CMAKE_CURRENT_LIST_DIR}/widgets/LockBox.hpp" + "${CMAKE_CURRENT_LIST_DIR}/widgets/PukLockBox.hpp" + "${CMAKE_CURRENT_LIST_DIR}/widgets/PhoneLockBaseBox.hpp" + "${CMAKE_CURRENT_LIST_DIR}/widgets/PhoneLockBox.hpp" + "${CMAKE_CURRENT_LIST_DIR}/widgets/SimLockBox.hpp" +) diff --git a/module-apps/locks/data/LockData.hpp b/module-apps/locks/data/LockData.hpp new file mode 100644 index 0000000000000000000000000000000000000000..221fc1afbcdb6f3e00ebaa68e3fbbf4a38cc879e --- /dev/null +++ b/module-apps/locks/data/LockData.hpp @@ -0,0 +1,30 @@ +// 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 +#include "gui/SwitchData.hpp" +#include "locks/widgets/Lock.hpp" + +namespace locks +{ + + // class template that stores information that was sent along with switch message + class LockData : public gui::SwitchData + { + Lock lock; + + public: + explicit LockData(Lock lock) : SwitchData(), lock(std::move(lock)) + { + description = "LockPhoneData"; + } + + [[nodiscard]] const Lock &getLock() const noexcept + { + return lock; + } + }; + +} // namespace lock diff --git a/module-apps/application-desktop/data/AppDesktopStyle.hpp b/module-apps/locks/data/LockStyle.hpp similarity index 100% rename from module-apps/application-desktop/data/AppDesktopStyle.hpp rename to module-apps/locks/data/LockStyle.hpp diff --git a/module-apps/application-desktop/widgets/PinLockHandler.cpp b/module-apps/locks/handlers/PinLockHandler.cpp similarity index 53% rename from module-apps/application-desktop/widgets/PinLockHandler.cpp rename to module-apps/locks/handlers/PinLockHandler.cpp index 984ab30c3a30c1a3082c7723dadf907ba0c29ae2..75f91c454be64eafb9dca4bcba364800be921298 100644 --- a/module-apps/application-desktop/widgets/PinLockHandler.cpp +++ b/module-apps/locks/handlers/PinLockHandler.cpp @@ -1,10 +1,10 @@ //// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. //// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md +#include "locks/data/LockData.hpp" #include "PinLockHandler.hpp" -#include "PinHash.hpp" +#include "locks/widgets/LockHash.hpp" #include "application-desktop/ApplicationDesktop.hpp" -#include "application-desktop/data/LockPhoneData.hpp" #include "application-desktop/windows/Names.hpp" #include #include @@ -25,56 +25,55 @@ namespace gui PinLockHandler::PinLockHandler(app::ApplicationDesktop *app) : app(app), - screenLock( - Store::GSM::SIM::NONE, PinLock::LockState::PasscodeRequired, PinLock::LockType::Screen, default_attempts), - simLock(Store::GSM::SIM::NONE, PinLock::LockState::Unlocked, PinLock::LockType::SimPin, default_attempts) + screenLock(Store::GSM::SIM::NONE, Lock::LockState::InputRequired, Lock::LockType::Screen, default_attempts), + simLock(Store::GSM::SIM::NONE, Lock::LockState::Unlocked, Lock::LockType::SimPin, default_attempts) { - simLock.setPinSizeBounds(sim_min_passcode_size, sim_max_passcode_size); - screenLock.setPinSizeBounds(default_screen_pin_size, default_screen_pin_size); + simLock.setInputSizeBounds(sim_min_passcode_size, sim_max_passcode_size); + screenLock.setInputSizeBounds(default_screen_pin_size, default_screen_pin_size); screenLock.setAutoActivate(true); } void PinLockHandler::handleScreenPin(const std::vector &pin) { - const uint32_t hash = GetPinHash(pin); - screenLock.value--; + const uint32_t hash = getHash(pin); + screenLock.attemptsLeft--; if (hash == app->getLockPassHash()) { - screenLock.lockState = gui::PinLock::LockState::Unlocked; - screenLock.value = default_attempts; + screenLock.lockState = gui::Lock::LockState::Unlocked; + screenLock.attemptsLeft = default_attempts; } - else if (screenLock.value > 0) { - screenLock.lockState = gui::PinLock::LockState::PasscodeInvalidRetryRequired; + else if (screenLock.attemptsLeft > 0) { + screenLock.lockState = gui::Lock::LockState::InputInvalidRetryRequired; } else { - screenLock.lockState = gui::PinLock::LockState::Blocked; + screenLock.lockState = gui::Lock::LockState::Blocked; } unlock(); } - void PinLockHandler::handlePasscodeParams(PinLock::LockType type, - PinLock::LockState state, + void PinLockHandler::handlePasscodeParams(Lock::LockType type, + Lock::LockState state, app::manager::actions::ActionParamsPtr &&data) { auto passcodeData = static_cast(data.get()); if (simLock.isSim(passcodeData->getSim()) && simLock.isType(type) && simLock.isState(state) && - simLock.getValue() > passcodeData->getAttempts()) { - simLock.lockState = PinLock::LockState::PasscodeInvalidRetryRequired; + simLock.getAttemptsLeft() > passcodeData->getAttempts()) { + simLock.lockState = Lock::LockState::InputInvalidRetryRequired; } else { simLock.lockState = state; simLock.sim = passcodeData->getSim(); simLock.lockType = type; } - simLock.passcodeName = passcodeData->getPasscodeName(); - simLock.value = passcodeData->getAttempts(); + simLock.lockName = passcodeData->getPasscodeName(); + simLock.attemptsLeft = passcodeData->getAttempts(); } - void PinLockHandler::handlePasscodeRequest(PinLock::LockType type, app::manager::actions::ActionParamsPtr &&data) + void PinLockHandler::handlePasscodeRequest(Lock::LockType type, app::manager::actions::ActionParamsPtr &&data) { LOG_DEBUG("Handling on of PasscodeRequest actions"); promptSimLockWindow = true; - handlePasscodeParams(type, PinLock::LockState::PasscodeRequired, std::move(data)); - if (!getStrongestLock().isType(PinLock::LockType::Screen)) { + handlePasscodeParams(type, Lock::LockState::InputRequired, std::move(data)); + if (!getStrongestLock().isType(Lock::LockType::Screen)) { unlock(); } } @@ -82,8 +81,8 @@ namespace gui void PinLockHandler::handleScreenPasscodeRequest(app::manager::actions::ActionParamsPtr &&data) const { auto params = static_cast(data.get()); - auto lock = std::make_unique( - Store::GSM::SIM::NONE, PinLock::LockState::PasscodeRequired, PinLock::LockType::Screen); + auto lock = + std::make_unique(Store::GSM::SIM::NONE, Lock::LockState::InputRequired, Lock::LockType::Screen); if (params->isCancel()) { if (app->getCurrentWindow()->getName() == app::window::name::desktop_pin_lock) { @@ -92,23 +91,22 @@ namespace gui return; } - lock->onActivatedCallback = [this](PinLock::LockType type, const std::vector &data) { + lock->onActivatedCallback = [this](Lock::LockType type, const std::vector &data) { app->bus.sendUnicast(std::make_shared(), service::name::service_desktop); app->switchWindow(app::window::name::desktop_main_window); }; - app->switchWindow(app::window::name::desktop_pin_lock, - gui::ShowMode::GUI_SHOW_INIT, - std::make_unique(std::move(lock))); + app->switchWindow( + app::window::name::desktop_pin_lock, gui::ShowMode::GUI_SHOW_INIT, std::make_unique(*lock)); } void PinLockHandler::handlePinChangeRequest(app::manager::actions::ActionParamsPtr &&data) { LOG_DEBUG("Handling RequestPinChange action"); - handlePasscodeParams(PinLock::LockType::SimPin, PinLock::LockState::PasscodeRequired, std::move(data)); + handlePasscodeParams(Lock::LockType::SimPin, Lock::LockState::InputRequired, std::move(data)); promptSimLockWindow = true; - auto onActivatedCallback = [this](PinLock::LockType type, const std::vector &data) { + auto onActivatedCallback = [this](Lock::LockType type, const std::vector &data) { handlePasscodeChange(data); }; switchToPinLockWindow(onActivatedCallback); @@ -118,9 +116,9 @@ namespace gui CellularSimCardLockDataMessage::SimCardLock simCardLock) { LOG_DEBUG("Handling PinEnableRequest action, simCardLock = %d", static_cast(simCardLock)); - handlePasscodeParams(PinLock::LockType::SimPin, PinLock::LockState::PasscodeRequired, std::move(data)); + handlePasscodeParams(Lock::LockType::SimPin, Lock::LockState::InputRequired, std::move(data)); promptSimLockWindow = true; - auto onActivatedCallback = [this, simCardLock](PinLock::LockType type, const std::vector &data) { + auto onActivatedCallback = [this, simCardLock](Lock::LockType type, const std::vector &data) { app->bus.sendUnicast( std::make_shared(Store::GSM::get()->selected, simCardLock, data), serviceCellular); @@ -132,66 +130,65 @@ namespace gui { LOG_DEBUG("Handling PinEnableRequestFailed action, simCardLock = %d, simLock.value = %u", static_cast(simCardLock), - simLock.value); + simLock.attemptsLeft); using namespace app::manager::actions; - if (simLock.value > 0) { - --simLock.value; + if (simLock.attemptsLeft > 0) { + --simLock.attemptsLeft; } 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, simCardLock](PinLock::LockType type, - const std::vector &data) { + if (simLock.attemptsLeft > 0) { + simLock.lockState = Lock::LockState::InputInvalidRetryRequired; + auto onActivatedCallback = [this, simCardLock](Lock::LockType type, const std::vector &data) { auto params = std::make_unique( - Store::GSM::get()->selected, simLock.value, PasscodeParams::pinName); + Store::GSM::get()->selected, simLock.attemptsLeft, PasscodeParams::pinName); handlePinEnableRequest(std::move(params), simCardLock); }; - switchToPinLockWindow(PinLock::LockState::PasscodeInvalidRetryRequired, onActivatedCallback); + switchToPinLockWindow(Lock::LockState::InputInvalidRetryRequired, onActivatedCallback); } else { auto params = std::make_unique( Store::GSM::get()->selected, PasscodeParams::numOfAttemptsForEnteringPUK, PasscodeParams::pukName); - handlePasscodeRequest(gui::PinLock::LockType::SimPuk, std::move(params)); + handlePasscodeRequest(gui::Lock::LockType::SimPuk, std::move(params)); } } void PinLockHandler::handlePinChangeRequestFailed() { - LOG_DEBUG("Handling PinChangeRequestFailed action, simLock.value = %u", simLock.value); + LOG_DEBUG("Handling PinChangeRequestFailed action, simLock.value = %u", simLock.attemptsLeft); using namespace app::manager::actions; - if (simLock.value > 0) { - --simLock.value; + if (simLock.attemptsLeft > 0) { + --simLock.attemptsLeft; } 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) { + if (simLock.attemptsLeft > 0) { + simLock.lockState = Lock::LockState::InputInvalidRetryRequired; + auto onActivatedCallback = [this](Lock::LockType type, const std::vector &data) { auto params = std::make_unique( - Store::GSM::get()->selected, simLock.value, PasscodeParams::pinName); + Store::GSM::get()->selected, simLock.attemptsLeft, PasscodeParams::pinName); handlePinChangeRequest(std::move(params)); }; - switchToPinLockWindow(PinLock::LockState::PasscodeInvalidRetryRequired, onActivatedCallback); + switchToPinLockWindow(Lock::LockState::InputInvalidRetryRequired, onActivatedCallback); } else { auto params = std::make_unique( Store::GSM::get()->selected, PasscodeParams::numOfAttemptsForEnteringPUK, PasscodeParams::pukName); - handlePasscodeRequest(gui::PinLock::LockType::SimPuk, std::move(params)); + handlePasscodeRequest(gui::Lock::LockType::SimPuk, std::move(params)); } } void PinLockHandler::handleSimBlocked(app::manager::actions::ActionParamsPtr &&data) { LOG_DEBUG("Handling BlockSim action"); - auto params = static_cast(data.get()); - promptSimLockWindow = true; - simLock.sim = params->getSim(); - simLock.lockState = gui::PinLock::LockState::Blocked; - simLock.lockType = gui::PinLock::LockType::SimPin; - simLock.value = blocked_sim_attempts; + auto params = static_cast(data.get()); + promptSimLockWindow = true; + simLock.sim = params->getSim(); + simLock.lockState = gui::Lock::LockState::Blocked; + simLock.lockType = gui::Lock::LockType::SimPin; + simLock.attemptsLeft = blocked_sim_attempts; unlock(); } @@ -199,8 +196,8 @@ namespace gui { LOG_DEBUG("Handling UnlockSim action"); promptSimLockWindow = false; - if (!simLock.isState(PinLock::LockState::Unlocked)) { - simLock.lockState = PinLock::LockState::Unlocked; + if (!simLock.isState(Lock::LockState::Unlocked)) { + simLock.lockState = Lock::LockState::Unlocked; unlock(); } } @@ -209,34 +206,33 @@ namespace gui { LOG_DEBUG("Handling DisplayCMEError action"); auto params = static_cast(data.get()); - auto lock = std::make_unique( - params->getSim(), PinLock::LockState::ErrorOccurred, PinLock::LockType::SimPin, params->getCMECode()); - lock->onActivatedCallback = [this](PinLock::LockType type, const std::vector &data) { + auto lock = std::make_unique( + params->getSim(), Lock::LockState::ErrorOccurred, Lock::LockType::SimPin, params->getCMECode()); + lock->onActivatedCallback = [this](Lock::LockType type, const std::vector &data) { app->switchWindow(app::window::name::desktop_main_window); }; - app->switchWindow(app::window::name::desktop_pin_lock, - gui::ShowMode::GUI_SHOW_INIT, - std::make_unique(std::move(lock))); + app->switchWindow( + app::window::name::desktop_pin_lock, gui::ShowMode::GUI_SHOW_INIT, std::make_unique(*lock)); } void PinLockHandler::switchToPinLockWindow( - std::function &)> onLockActivatedCallback) + std::function &)> onLockActivatedCallback) { - auto lock = std::make_unique(getStrongestLock()); - if (lock->isState(PinLock::LockState::PasscodeInvalidRetryRequired)) { + auto lock = std::make_unique(getStrongestLock()); + if (lock->isState(Lock::LockState::InputInvalidRetryRequired)) { getStrongestLock().consumeState(); - lock->onActivatedCallback = [this, onLockActivatedCallback](PinLock::LockType, + lock->onActivatedCallback = [this, onLockActivatedCallback](Lock::LockType, const std::vector &) { switchToPinLockWindow(onLockActivatedCallback); }; } - else if (lock->isState(gui::PinLock::LockState::Blocked)) { - lock->onActivatedCallback = [this](PinLock::LockType type, const std::vector &data) { + else if (lock->isState(gui::Lock::LockState::Blocked)) { + lock->onActivatedCallback = [this](Lock::LockType type, const std::vector &data) { setSimLockHandled(); app->switchWindow(app::window::name::desktop_main_window); }; } - else if (lock->isState(gui::PinLock::LockState::Unlocked)) { + else if (lock->isState(gui::Lock::LockState::Unlocked)) { setSimLockHandled(); app->switchWindow(app::window::name::desktop_main_window); return; @@ -244,49 +240,47 @@ namespace gui else { lock->onActivatedCallback = onLockActivatedCallback; } - app->switchWindow(app::window::name::desktop_pin_lock, - gui::ShowMode::GUI_SHOW_INIT, - std::make_unique(std::move(lock))); + app->switchWindow( + app::window::name::desktop_pin_lock, gui::ShowMode::GUI_SHOW_INIT, std::make_unique(*lock)); } void PinLockHandler::switchToPinLockWindow( - PinLock::LockState state, - std::function &)> onLockActivatedCallback) + Lock::LockState state, + std::function &)> onLockActivatedCallback) { - auto lock = std::make_unique(getStrongestLock()); + auto lock = std::make_unique(getStrongestLock()); lock->lockState = state; lock->onActivatedCallback = onLockActivatedCallback; - app->switchWindow(app::window::name::desktop_pin_lock, - gui::ShowMode::GUI_SHOW_INIT, - std::make_unique(std::move(lock))); + app->switchWindow( + app::window::name::desktop_pin_lock, gui::ShowMode::GUI_SHOW_INIT, std::make_unique(*lock)); } - void PinLockHandler::handlePasscode(PinLock::LockType type, const std::vector passcode) + void PinLockHandler::handlePasscode(Lock::LockType type, const std::vector passcode) { - if (type == PinLock::LockType::SimPin) { + if (type == Lock::LockType::SimPin) { setSimLockHandled(); app->bus.sendUnicast(std::make_shared(simLock.sim, passcode), serviceCellular); } - else if (type == PinLock::LockType::SimPuk) { + else if (type == Lock::LockType::SimPuk) { handlePasscodeChange(passcode); } - else if (type == PinLock::LockType::Screen) { + else if (type == Lock::LockType::Screen) { handleScreenPin(passcode); } } void PinLockHandler::handlePasscodeChange(const std::vector passcode) { - auto onActivatedCallback = [this, passcode](PinLock::LockType, const std::vector &pin) { + auto onActivatedCallback = [this, passcode](Lock::LockType, const std::vector &pin) { handleNewPasscodeUnconfirmed(passcode, pin); }; - switchToPinLockWindow(PinLock::LockState::NewPasscodeRequired, onActivatedCallback); + switchToPinLockWindow(Lock::LockState::NewInputRequired, onActivatedCallback); } void PinLockHandler::handleNewPasscodeUnconfirmed(const std::vector &passcode, const std::vector &pin) { - auto onActivatedCallback = [this, passcode, pin](PinLock::LockType type, + auto onActivatedCallback = [this, passcode, pin](Lock::LockType type, const std::vector &pinConfirmed) { if (pin == pinConfirmed) { handleNewPasscodeConfirmed(type, passcode, pin); @@ -295,18 +289,18 @@ namespace gui handleNewPasscodeInvalid(passcode); } }; - switchToPinLockWindow(PinLock::LockState::NewPasscodeConfirmRequired, onActivatedCallback); + switchToPinLockWindow(Lock::LockState::NewInputConfirmRequired, onActivatedCallback); } - void PinLockHandler::handleNewPasscodeConfirmed(PinLock::LockType type, + void PinLockHandler::handleNewPasscodeConfirmed(Lock::LockType type, const std::vector &passcode, const std::vector &pin) { - if (type == PinLock::LockType::SimPin) { + if (type == Lock::LockType::SimPin) { app->bus.sendUnicast(std::make_shared(simLock.sim, passcode, pin), serviceCellular); } - else if (type == PinLock::LockType::SimPuk) { + else if (type == Lock::LockType::SimPuk) { app->bus.sendUnicast(std::make_shared(simLock.sim, passcode, pin), serviceCellular); } @@ -314,25 +308,25 @@ namespace gui void PinLockHandler::handleNewPasscodeInvalid(const std::vector &passcode) { - auto onActivatedCallback = [this, passcode](PinLock::LockType type, const std::vector &pin) { + auto onActivatedCallback = [this, passcode](Lock::LockType type, const std::vector &pin) { handlePasscodeChange(passcode); }; - switchToPinLockWindow(PinLock::LockState::NewPasscodeInvalid, onActivatedCallback); + switchToPinLockWindow(Lock::LockState::NewInputInvalid, onActivatedCallback); } void PinLockHandler::unlock() { - auto onActivatedCallback = [this](PinLock::LockType type, const std::vector &data) { + auto onActivatedCallback = [this](Lock::LockType type, const std::vector &data) { handlePasscode(type, data); }; switchToPinLockWindow(onActivatedCallback); } - auto PinLockHandler::getStrongestLock() noexcept -> gui::PinLock & + auto PinLockHandler::getStrongestLock() noexcept -> gui::Lock & { - if (!screenLock.isState(PinLock::LockState::Unlocked)) { + if (!screenLock.isState(Lock::LockState::Unlocked)) { return screenLock; } - else if (promptSimLockWindow && !simLock.isState(PinLock::LockState::Unlocked)) { + else if (promptSimLockWindow && !simLock.isState(Lock::LockState::Unlocked)) { return simLock; } return screenLock; @@ -340,20 +334,20 @@ namespace gui void PinLockHandler::lockScreen() { - screenLock.lockState = PinLock::LockState::PasscodeRequired; + screenLock.lockState = Lock::LockState::InputRequired; } void PinLockHandler::unlockScreen() { - if (getStrongestLock().isType(PinLock::LockType::Screen) && !app->isLockScreenPasscodeOn()) { - screenLock.lockState = gui::PinLock::LockState::Unlocked; + if (getStrongestLock().isType(Lock::LockType::Screen) && !app->isLockScreenPasscodeOn()) { + screenLock.lockState = gui::Lock::LockState::Unlocked; } unlock(); } void PinLockHandler::setSimLockHandled() noexcept { - if (!getStrongestLock().isType(PinLock::LockType::Screen)) { + if (!getStrongestLock().isType(Lock::LockType::Screen)) { promptSimLockWindow = false; } } diff --git a/module-apps/application-desktop/widgets/PinLockHandler.hpp b/module-apps/locks/handlers/PinLockHandler.hpp similarity index 71% rename from module-apps/application-desktop/widgets/PinLockHandler.hpp rename to module-apps/locks/handlers/PinLockHandler.hpp index e0c0c1c1c26f56a9cf298b8a1d7629a5d4de8999..d25f34d2e40043b20b305211ae139f31d5a448e1 100644 --- a/module-apps/application-desktop/widgets/PinLockHandler.hpp +++ b/module-apps/locks/handlers/PinLockHandler.hpp @@ -3,7 +3,7 @@ #pragma once -#include "PinLock.hpp" +#include "locks/widgets/Lock.hpp" #include #include @@ -16,39 +16,41 @@ namespace app namespace gui { + using namespace locks; + class PinLockHandler { app::ApplicationDesktop *app = nullptr; - gui::PinLock screenLock; - gui::PinLock simLock; + Lock screenLock; + Lock simLock; bool promptSimLockWindow = true; void handleScreenPin(const std::vector &pin); - void handlePasscode(PinLock::LockType type, const std::vector passcode); + void handlePasscode(Lock::LockType type, const std::vector passcode); void handlePasscodeChange(const std::vector passcode); void handleNewPasscodeUnconfirmed(const std::vector &passcode, const std::vector &pin); - void handleNewPasscodeConfirmed(PinLock::LockType type, + void handleNewPasscodeConfirmed(Lock::LockType type, const std::vector &passcode, const std::vector &pin); void handleNewPasscodeInvalid(const std::vector &passcode); - void handlePasscodeParams(PinLock::LockType type, - PinLock::LockState state, + void handlePasscodeParams(Lock::LockType type, + Lock::LockState state, app::manager::actions::ActionParamsPtr &&data); void switchToPinLockWindow( - std::function &)> onLockActivatedCallback); + std::function &)> onLockActivatedCallback); void switchToPinLockWindow( - PinLock::LockState type, - std::function &)> onLockActivatedCallback); + Lock::LockState type, + std::function &)> onLockActivatedCallback); - auto getStrongestLock() noexcept -> gui::PinLock &; + auto getStrongestLock() noexcept -> gui::Lock &; void unlock(); void setSimLockHandled() noexcept; public: PinLockHandler(app::ApplicationDesktop *app); - void handlePasscodeRequest(PinLock::LockType type, app::manager::actions::ActionParamsPtr &&data); + void handlePasscodeRequest(Lock::LockType type, app::manager::actions::ActionParamsPtr &&data); void handlePinChangeRequest(app::manager::actions::ActionParamsPtr &&data); void handlePinEnableRequest(app::manager::actions::ActionParamsPtr &&data, CellularSimCardLockDataMessage::SimCardLock simCardLock); @@ -61,11 +63,11 @@ namespace gui [[nodiscard]] auto isScreenLocked() const noexcept -> bool { - return !screenLock.isState(PinLock::LockState::Unlocked); + return !screenLock.isState(Lock::LockState::Unlocked); } [[nodiscard]] auto isScreenBlocked() const noexcept -> bool { - return screenLock.isState(PinLock::LockState::Blocked); + return screenLock.isState(Lock::LockState::Blocked); } void lockScreen(); void unlockScreen(); diff --git a/module-apps/locks/widgets/Lock.cpp b/module-apps/locks/widgets/Lock.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6ac5ead5cd93e4d7cc91c0a2237b4f9924db4e4f --- /dev/null +++ b/module-apps/locks/widgets/Lock.cpp @@ -0,0 +1,50 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "Lock.hpp" +#include + +namespace locks +{ + void Lock::consumeState() noexcept + { + if (lockState == LockState::InputInvalidRetryRequired) { + lockState = LockState::InputRequired; + } + else if (lockState == LockState::NewInputInvalid) { + lockState = LockState::NewInputRequired; + } + } + + void Lock::putNextChar(unsigned int c) + { + if (maxInputSize > inputValue.size()) { + inputValue.push_back(c); + } + if (canVerify() && autoActivate && onActivatedCallback != nullptr) { + onActivatedCallback(lockType, inputValue); + } + } + + void Lock::popChar() + { + if (inputValue.size() > 0) { + inputValue.pop_back(); + } + } + + void Lock::clearAttempt() noexcept + { + inputValue.clear(); + } + + void Lock::activate() + { + if (!onActivatedCallback) { + LOG_ERROR("Passcode verification callback null"); + return; + } + onActivatedCallback(lockType, inputValue); + clearAttempt(); + } +} // namespace lock diff --git a/module-apps/application-desktop/widgets/PinLock.hpp b/module-apps/locks/widgets/Lock.hpp similarity index 54% rename from module-apps/application-desktop/widgets/PinLock.hpp rename to module-apps/locks/widgets/Lock.hpp index 3c4986898f320a21be512452f76f0399afef0c20..cb8cd8dd40483735a6204476521cd6623162065c 100644 --- a/module-apps/application-desktop/widgets/PinLock.hpp +++ b/module-apps/locks/widgets/Lock.hpp @@ -12,8 +12,12 @@ namespace gui { class PinLockHandler; + class ChangePasscodeLockHandler; +} // namespace gui - class PinLock +namespace locks +{ + class Lock { public: enum class LockType @@ -22,18 +26,17 @@ namespace gui SimPuk, Screen }; + enum class LockState { Unlocked, - PasscodeRequired, - PasscodeInvalidRetryRequired, + InputRequired, + InputInvalidRetryRequired, Blocked, - NewPasscodeRequired, - NewPasscodeInvalidRetryRequired, - NewPasscodeConfirmRequired, - NewPasscodeInvalid, - PinLockDisableRequired, - PinLockEnableRequired, + NewInputRequired, + NewInputInvalidRetryRequired, + NewInputConfirmRequired, + NewInputInvalid, ErrorOccurred }; @@ -45,30 +48,30 @@ namespace gui { return lockType; } - [[nodiscard]] unsigned int getMaxPinSize() const noexcept + [[nodiscard]] unsigned int getMaxInputSize() const noexcept { - return maxPinSize; + return maxInputSize; } - /// returns current position of a PIN character to be inserted + /// returns current position of a Input character to be inserted [[nodiscard]] unsigned int getCharCount() const noexcept { - return pinValue.size(); + return inputValue.size(); } [[nodiscard]] bool canPut() const noexcept { - return getCharCount() < getMaxPinSize(); + return getCharCount() < getMaxInputSize(); } [[nodiscard]] bool canVerify() const noexcept { - return getCharCount() >= minPinSize; + return getCharCount() >= minInputSize; } - [[nodiscard]] std::vector getPin() const + [[nodiscard]] std::vector getInput() const { - return pinValue; + return inputValue; } - [[nodiscard]] unsigned int getValue() const noexcept + [[nodiscard]] unsigned int getAttemptsLeft() const noexcept { - return value; + return attemptsLeft; } [[nodiscard]] bool isSim(Store::GSM::SIM _sim) const noexcept { @@ -82,9 +85,9 @@ namespace gui { return lockType == type; } - [[nodiscard]] const std::string &getPasscodeName() const noexcept + [[nodiscard]] const std::string &getLockName() const noexcept { - return passcodeName; + return lockName; } [[nodiscard]] Store::GSM::SIM getSim() const noexcept { @@ -98,44 +101,46 @@ namespace gui void clearAttempt() noexcept; /// consumes LockState::PasscodeInvalidRetryRequired state and LockState::NewPasscodeInvalid) void consumeState() noexcept; - void setNewPasscodeInvalidState() noexcept; /// calls void activate(); - PinLock(Store::GSM::SIM sim, LockState state, LockType type, unsigned int value = unlimitedNumOfAttempts) - : sim{sim}, lockState{state}, lockType{type}, value{value} + Lock(Store::GSM::SIM sim, LockState state, LockType type, unsigned int attemptsLeft = unlimitedNumOfAttempts) + : sim{sim}, lockState{state}, lockType{type}, attemptsLeft{attemptsLeft} + {} + + Lock(LockState state, unsigned int attemptsLeft = unlimitedNumOfAttempts) + : lockState{state}, attemptsLeft{attemptsLeft} {} - PinLock(const PinLock &other) = default; std::function &)> onActivatedCallback = nullptr; private: - std::string passcodeName; - Store::GSM::SIM sim = Store::GSM::SIM::NONE; - LockState lockState = LockState::Unlocked; - LockType lockType = LockType::Screen; - unsigned int value = 0; - - std::vector pinValue; - unsigned int maxPinSize = defaultPasscodeSize; - unsigned int minPinSize = defaultPasscodeSize; - bool autoActivate = false; - - static constexpr unsigned int defaultPasscodeSize = 4; + std::string lockName; + Store::GSM::SIM sim = Store::GSM::SIM::NONE; + LockState lockState = LockState::Unlocked; + LockType lockType = LockType::Screen; + unsigned int attemptsLeft = 0; + + std::vector inputValue; + unsigned int maxInputSize = defaultInputSize; + unsigned int minInputSize = defaultInputSize; + bool autoActivate = false; + + static constexpr unsigned int defaultInputSize = 4; static constexpr unsigned int unlimitedNumOfAttempts = std::numeric_limits::max(); void setAutoActivate(bool _autoActivate) { autoActivate = _autoActivate; } - void setPinSizeBounds(unsigned int _minPinSize, unsigned int _maxPinSize) + void setInputSizeBounds(unsigned int _minInputSize, unsigned int _maxInputSize) { - minPinSize = _minPinSize; - maxPinSize = _maxPinSize; + minInputSize = _minInputSize; + maxInputSize = _maxInputSize; } - friend class PinLockHandler; - friend class ChangePasscodeLockHandler; + friend class gui::PinLockHandler; + friend class gui::ChangePasscodeLockHandler; }; -} // namespace gui +} // namespace lock diff --git a/module-apps/locks/widgets/LockBox.hpp b/module-apps/locks/widgets/LockBox.hpp new file mode 100644 index 0000000000000000000000000000000000000000..44cb620e64b0a1bb9d03ac71a5e1471f95bc4ff0 --- /dev/null +++ b/module-apps/locks/widgets/LockBox.hpp @@ -0,0 +1,38 @@ +// 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 + +namespace gui +{ + class LockBox + { + public: + enum class InputActionType + { + ProvideInput, + ProvideNewInput, + ConfirmNewInput + }; + + enum class InputErrorType + { + InvalidInput, + NewInputConfirmFailed, + UnhandledError + }; + + virtual void popChar(unsigned int charNum) = 0; + virtual void putChar(unsigned int charNum) = 0; + virtual void clear() = 0; + + virtual void setVisibleStateInputRequired(InputActionType type) = 0; + virtual void setVisibleStateInputInvalid(InputErrorType type, unsigned int value) = 0; + virtual void setVisibleStateBlocked() = 0; + + virtual void buildLockBox(unsigned int inputSize) = 0; + virtual ~LockBox() = default; + }; +} // namespace gui diff --git a/module-apps/application-desktop/widgets/PinHash.hpp b/module-apps/locks/widgets/LockHash.hpp similarity index 61% rename from module-apps/application-desktop/widgets/PinHash.hpp rename to module-apps/locks/widgets/LockHash.hpp index 01df9a15c5dad766363d2e09dd1497261ff9a78a..44c5789bbdb7fa43f0dc93cf6762d9c404607c75 100644 --- a/module-apps/application-desktop/widgets/PinHash.hpp +++ b/module-apps/locks/widgets/LockHash.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 @@ -10,18 +10,18 @@ template <> struct std::hash> { const static unsigned int digit_multiplier = 10; - uint32_t operator()(std::vector const &pin) const noexcept + uint32_t operator()(std::vector const &input) const noexcept { uint32_t value = 0; - for (auto i : pin) { + for (auto i : input) { value = digit_multiplier * value + i; } return value; } }; -static inline uint32_t GetPinHash(const std::vector &pin) +static inline uint32_t getHash(const std::vector &input) { static std::hash> hashEngine; - return hashEngine(pin); + return hashEngine(input); } diff --git a/module-apps/application-desktop/windows/ScreenLockBaseBox.cpp b/module-apps/locks/widgets/PhoneLockBaseBox.cpp similarity index 61% rename from module-apps/application-desktop/windows/ScreenLockBaseBox.cpp rename to module-apps/locks/widgets/PhoneLockBaseBox.cpp index 326bb5032b6594c304493e81636c33e2052a4ae9..b55c2f29169d93d5ec3748c4cee840d519e9033c 100644 --- a/module-apps/application-desktop/windows/ScreenLockBaseBox.cpp +++ b/module-apps/locks/widgets/PhoneLockBaseBox.cpp @@ -1,45 +1,45 @@ // Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md -#include "application-desktop/data/AppDesktopStyle.hpp" -#include "application-desktop/widgets/PinLock.hpp" -#include "PinLockBaseWindow.hpp" -#include "ScreenLockBaseBox.hpp" +#include "locks/data/LockStyle.hpp" +#include "locks/windows/PinLockBaseWindow.hpp" +#include "Lock.hpp" +#include "PhoneLockBaseBox.hpp" namespace label_style = style::window::pin_lock::pin_label; namespace gui { - void ScreenLockBaseBox::buildLockBox(unsigned int pinSize) + void PhoneLockBaseBox::buildLockBox(unsigned int pinSize) { buildPinLabels(pinSize); } - void ScreenLockBaseBox::clear() + void PhoneLockBaseBox::clear() { - for (unsigned i = 0; i < pinLabels.size(); i++) { + for (unsigned i = 0; i < inputLabels.size(); i++) { popChar(i); } } - void ScreenLockBaseBox::popChar(unsigned int charNum) + void PhoneLockBaseBox::popChar(unsigned int charNum) { - if (charNum < pinLabels.size()) { - pinLabels[charNum]->setVisibleState(false); + if (charNum < inputLabels.size()) { + inputLabels[charNum]->setVisibleState(false); } } - void ScreenLockBaseBox::putChar(unsigned int charNum) + void PhoneLockBaseBox::putChar(unsigned int charNum) { - if (charNum < pinLabels.size()) { - pinLabels[charNum]->setVisibleState(true); + if (charNum < inputLabels.size()) { + inputLabels[charNum]->setVisibleState(true); } } - void ScreenLockBaseBox::buildPinLabels(unsigned int pinSize) + void PhoneLockBaseBox::buildPinLabels(unsigned int pinSize) { constexpr auto pinLabelWidth = style::window::default_body_width; - pinLabels.clear(); + inputLabels.clear(); if (pinSize == 0) { return; @@ -53,10 +53,10 @@ namespace gui } auto itemBuilder = [this, singleLabelWidth]() { - auto label = new PinLabel(nullptr, singleLabelWidth, label_style::size); + auto label = new InputLabel(nullptr, singleLabelWidth, label_style::size); label->setEdges(RectangleEdge::Bottom); label->setMargins(Margins(label_style::margin, 0, label_style::margin, 0)); - pinLabels.push_back(label); + inputLabels.push_back(label); return label; }; @@ -65,10 +65,10 @@ namespace gui lockWindow->pinLabelsBox->setEdges(RectangleEdge::None); } - ScreenLockBaseBox::PinLabel::PinLabel(Item *parent, uint32_t w, uint32_t h) : HBox(parent, 0, 0, w, h) + PhoneLockBaseBox::InputLabel::InputLabel(Item *parent, uint32_t w, uint32_t h) : HBox(parent, 0, 0, w, h) {} - void ScreenLockBaseBox::PinLabel::setVisibleState(bool isImageVisible) + void PhoneLockBaseBox::InputLabel::setVisibleState(bool isImageVisible) { if (isImageVisible && image == nullptr) { image = new gui::Image("dot_12px_hard_alpha_W_G"); diff --git a/module-apps/application-desktop/windows/ScreenLockBaseBox.hpp b/module-apps/locks/widgets/PhoneLockBaseBox.hpp similarity index 55% rename from module-apps/application-desktop/windows/ScreenLockBaseBox.hpp rename to module-apps/locks/widgets/PhoneLockBaseBox.hpp index 6dc49f51db9c1d74dd91e072c06d47492dece27f..a888080422e00fae01b7ca42a41e5bd9228eb90c 100644 --- a/module-apps/application-desktop/windows/ScreenLockBaseBox.hpp +++ b/module-apps/locks/widgets/PhoneLockBaseBox.hpp @@ -4,15 +4,15 @@ #pragma once #include "Image.hpp" -#include "PinLockBox.hpp" -#include "LockWindow.hpp" +#include "LockBox.hpp" +#include "locks/windows/LockWindow.hpp" namespace gui { - class ScreenLockBaseBox : public PinLockBox + class PhoneLockBaseBox : public LockBox { public: - ScreenLockBaseBox(LockWindow *lockBaseWindow) : lockWindow(lockBaseWindow) + explicit PhoneLockBaseBox(LockWindow *lockBaseWindow) : lockWindow(lockBaseWindow) {} void buildLockBox(unsigned int pinSize) override; @@ -22,22 +22,22 @@ namespace gui private: void buildPinLabels(unsigned int pinSize); - void setVisibleStateBlocked() + void setVisibleStateBlocked() override {} - void setVisibleStateEnterPin(EnterPasscodeType type) + void setVisibleStateInputRequired(InputActionType type) override {} - void setVisibleStateInvalidPin(PasscodeErrorType type, unsigned int value) + void setVisibleStateInputInvalid(InputErrorType type, unsigned int value) override {} - struct PinLabel : public HBox + struct InputLabel : public HBox { - PinLabel(Item *parent, uint32_t w, uint32_t h); + InputLabel(Item *parent, uint32_t w, uint32_t h); void setVisibleState(bool isImageVisible); gui::Image *image = nullptr; }; LockWindow *lockWindow; - std::vector pinLabels; + std::vector inputLabels; }; } // namespace gui diff --git a/module-apps/application-desktop/windows/ScreenLockBox.cpp b/module-apps/locks/widgets/PhoneLockBox.cpp similarity index 77% rename from module-apps/application-desktop/windows/ScreenLockBox.cpp rename to module-apps/locks/widgets/PhoneLockBox.cpp index 42d74babab006e9edb502f6ac5789d2ec4228169..aa25d895d6024a6f4a66dfd7590627e9634941ac 100644 --- a/module-apps/application-desktop/windows/ScreenLockBox.cpp +++ b/module-apps/locks/widgets/PhoneLockBox.cpp @@ -1,27 +1,27 @@ // Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md -#include "application-desktop/widgets/PinLock.hpp" -#include "ScreenLockBox.hpp" +#include "Lock.hpp" +#include "PhoneLockBox.hpp" namespace gui { constexpr auto timeToUnlock = 10; - void ScreenLockBox::buildLockBox(unsigned int pinSize) + void PhoneLockBox::buildLockBox(unsigned int pinSize) { LockWindow->buildImages("pin_lock", "pin_lock_info"); - ScreenLockBaseBox::buildLockBox(pinSize); + PhoneLockBaseBox::buildLockBox(pinSize); } - void ScreenLockBox::setVisibleStateBlocked() + void PhoneLockBox::setVisibleStateBlocked() { LockWindow->setText("app_desktop_screen_blocked_info", LockWindow::TextType::Primary); LockWindow->setImagesVisible(false, true); LockWindow->setBottomBarWidgetsActive(false, true, false); } - void ScreenLockBox::setVisibleStateEnterPin(EnterPasscodeType type) + void PhoneLockBox::setVisibleStateInputRequired(InputActionType type) { LockWindow->pinLabelsBox->setVisible(true); LockWindow->setText("app_desktop_screen_enter_passcode_to_unlock", LockWindow::TextType::Primary, true); @@ -29,10 +29,10 @@ namespace gui LockWindow->setBottomBarWidgetsActive(false, false, true); } - void ScreenLockBox::setVisibleStateInvalidPin(PasscodeErrorType type, unsigned int value) + void PhoneLockBox::setVisibleStateInputInvalid(InputErrorType type, unsigned int value) { switch (type) { - case PinLockBox::PasscodeErrorType::InvalidPasscode: + case LockBox::InputErrorType::InvalidInput: LockWindow->setTitleBar(false, false); if (value == 1) { LockWindow->setText( @@ -50,10 +50,10 @@ namespace gui } break; - case PinLockBox::PasscodeErrorType::NewPasscodeConfirmFailed: + case LockBox::InputErrorType::NewInputConfirmFailed: LOG_ERROR("No use case for NewPasscodeConfirmFailed"); break; - case PinLockBox::PasscodeErrorType::UnhandledError: + case LockBox::InputErrorType::UnhandledError: LOG_ERROR("No use case for UnhandledError"); break; } diff --git a/module-apps/locks/widgets/PhoneLockBox.hpp b/module-apps/locks/widgets/PhoneLockBox.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0a577e0a1136668327b4265c56c2d9f929fc2860 --- /dev/null +++ b/module-apps/locks/widgets/PhoneLockBox.hpp @@ -0,0 +1,26 @@ +// 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 "locks/windows/PinLockBaseWindow.hpp" +#include "PhoneLockBaseBox.hpp" + +namespace gui +{ + class PhoneLockBox : public PhoneLockBaseBox + { + public: + explicit PhoneLockBox(PinLockBaseWindow *LockBaseWindow) + : PhoneLockBaseBox(LockBaseWindow), LockWindow(LockBaseWindow) + {} + + private: + void buildLockBox(unsigned int pinSize) final; + void setVisibleStateBlocked() final; + void setVisibleStateInputRequired(InputActionType type) final; + void setVisibleStateInputInvalid(InputErrorType type, unsigned int value) final; + + PinLockBaseWindow *LockWindow; + }; +} // namespace gui diff --git a/module-apps/application-desktop/windows/PukLockBox.cpp b/module-apps/locks/widgets/PukLockBox.cpp similarity index 70% rename from module-apps/application-desktop/windows/PukLockBox.cpp rename to module-apps/locks/widgets/PukLockBox.cpp index 9a5cef1255508056118c439f88a1b8083a3d400b..8aacdd95eda62d27841ef901e2490bdd42144fcd 100644 --- a/module-apps/application-desktop/windows/PukLockBox.cpp +++ b/module-apps/locks/widgets/PukLockBox.cpp @@ -1,11 +1,11 @@ -// 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 "PukLockBox.hpp" -#include "PinLockBaseWindow.hpp" -#include "application-desktop/widgets/PinLock.hpp" -#include "application-desktop/data/AppDesktopStyle.hpp" +#include "locks/data/LockStyle.hpp" +#include "locks/windows/PinLockBaseWindow.hpp" +#include "Lock.hpp" #include "gui/widgets/Image.hpp" #include #include @@ -15,47 +15,47 @@ namespace gui { void PukLockBox::popChar(unsigned int charNum) { - rebuildPinLabels(charNum); + rebuildInputLabels(charNum); } void PukLockBox::putChar(unsigned int charNum) { - rebuildPinLabels(++charNum); + rebuildInputLabels(++charNum); } - void PukLockBox::buildLockBox(unsigned int pinSize) + void PukLockBox::buildLockBox(unsigned int inputSize) { LockWindow->buildImages("pin_lock", "pin_lock_info"); - buildPinLabels(0); + buildInputLabels(0); } - void PukLockBox::buildPinLabels(unsigned int pinSize) + void PukLockBox::buildInputLabels(unsigned int inputSize) { auto itemBuilder = []() { auto label = new gui::Image("dot_12px_hard_alpha_W_G"); return label; }; - LockWindow->buildPinLabels(itemBuilder, pinSize, label_style::x, label_style::y, label_style::w); + LockWindow->buildPinLabels(itemBuilder, inputSize, label_style::x, label_style::y, label_style::w); LockWindow->pinLabelsBox->setEdges(RectangleEdge::Bottom); } - void PukLockBox::rebuildPinLabels(unsigned int pinSize) + void PukLockBox::rebuildInputLabels(unsigned int inputSize) { LockWindow->pinLabelsBox->erase(); - buildPinLabels(pinSize); + buildInputLabels(inputSize); } - void PukLockBox::setVisibleStateEnterPin(EnterPasscodeType type) + void PukLockBox::setVisibleStateInputRequired(InputActionType type) { LockWindow->pinLabelsBox->setVisible(true); switch (type) { - case PinLockBox::EnterPasscodeType::ProvidePasscode: { + case LockBox::InputActionType::ProvideInput: { LockWindow->setText("app_desktop_sim_setup_enter_puk", PinLockBaseWindow::TextType::Primary, true); break; } - case PinLockBox::EnterPasscodeType::ProvideNewPasscode: { + case LockBox::InputActionType::ProvideNewInput: { LockWindow->setText("app_desktop_sim_enter_new_pin", PinLockBaseWindow::TextType::Primary); break; } - case PinLockBox::EnterPasscodeType::ConfirmNewPasscode: + case LockBox::InputActionType::ConfirmNewInput: LockWindow->setText("app_desktop_sim_confirm_new_pin", PinLockBaseWindow::TextType::Primary); break; } @@ -63,10 +63,10 @@ namespace gui LockWindow->setImagesVisible(true, false); LockWindow->setBottomBarWidgetsActive(false, false, true); } - void PukLockBox::setVisibleStateInvalidPin(PasscodeErrorType type, unsigned int value) + void PukLockBox::setVisibleStateInputInvalid(InputErrorType type, unsigned int value) { switch (type) { - case PinLockBox::PasscodeErrorType::InvalidPasscode: + case LockBox::InputErrorType::InvalidInput: if (value > 1) { LockWindow->setText( "app_desktop_sim_setup_wrong_puk", @@ -82,11 +82,11 @@ namespace gui true); } break; - case PinLockBox::PasscodeErrorType::NewPasscodeConfirmFailed: { + case LockBox::InputErrorType::NewInputConfirmFailed: { LockWindow->setText("app_desktop_sim_wrong_pin_confirmation", PinLockBaseWindow::TextType::Primary); break; } - case PinLockBox::PasscodeErrorType::UnhandledError: + case LockBox::InputErrorType::UnhandledError: LOG_ERROR("No use case for UnhandledError in PukLockBox"); break; } @@ -102,6 +102,6 @@ namespace gui void PukLockBox::clear() { - rebuildPinLabels(0); + rebuildInputLabels(0); } } // namespace gui diff --git a/module-apps/application-desktop/windows/PukLockBox.hpp b/module-apps/locks/widgets/PukLockBox.hpp similarity index 60% rename from module-apps/application-desktop/windows/PukLockBox.hpp rename to module-apps/locks/widgets/PukLockBox.hpp index 490111167f4e80ec7dcef5b974474cb5e2b0aecc..f71c346c8f142b3a98dbbbd282fded8999775e87 100644 --- a/module-apps/application-desktop/windows/PukLockBox.hpp +++ b/module-apps/locks/widgets/PukLockBox.hpp @@ -3,7 +3,7 @@ #pragma once -#include "PinLockBox.hpp" +#include "LockBox.hpp" namespace gui { @@ -12,7 +12,7 @@ namespace gui namespace gui { - class PukLockBox : public PinLockBox + class PukLockBox : public LockBox { public: explicit PukLockBox(PinLockBaseWindow *LockBaseWindow) : LockWindow(LockBaseWindow) @@ -24,12 +24,12 @@ namespace gui void putChar(unsigned int charNum) final; void clear() final; - void setVisibleStateEnterPin(EnterPasscodeType type) final; - void setVisibleStateInvalidPin(PasscodeErrorType type, unsigned int value) final; + void setVisibleStateInputRequired(InputActionType type) final; + void setVisibleStateInputInvalid(InputErrorType type, unsigned int value) final; void setVisibleStateBlocked() final; - void buildLockBox(unsigned int pinSize) final; - void buildPinLabels(unsigned int pinSize); - void rebuildPinLabels(unsigned int pinSize); + void buildLockBox(unsigned int inputSize) final; + void buildInputLabels(unsigned int inputSize); + void rebuildInputLabels(unsigned int inputSize); }; } // namespace gui diff --git a/module-apps/application-desktop/windows/SimLockBox.cpp b/module-apps/locks/widgets/SimLockBox.cpp similarity index 71% rename from module-apps/application-desktop/windows/SimLockBox.cpp rename to module-apps/locks/widgets/SimLockBox.cpp index 07a4730a724b9d1f659b2db8d1a00a91e493d0b4..996cc5f5416f07969c7c35e5a81892b0144406b1 100644 --- a/module-apps/application-desktop/windows/SimLockBox.cpp +++ b/module-apps/locks/widgets/SimLockBox.cpp @@ -3,9 +3,9 @@ #include "SimLockBox.hpp" -#include "PinLockBaseWindow.hpp" -#include "application-desktop/widgets/PinLock.hpp" -#include "application-desktop/data/AppDesktopStyle.hpp" +#include "locks/data/LockStyle.hpp" +#include "locks/windows/PinLockBaseWindow.hpp" +#include "Lock.hpp" #include #include @@ -16,51 +16,51 @@ namespace gui void SimLockBox::popChar(unsigned int charNum) { - rebuildPinLabels(charNum); + rebuildInputLabels(charNum); } void SimLockBox::putChar(unsigned int charNum) { - rebuildPinLabels(++charNum); + rebuildInputLabels(++charNum); } - void SimLockBox::buildLockBox(unsigned int pinSize) + void SimLockBox::buildLockBox(unsigned int inputSize) { LockWindow->buildImages("pin_lock", "pin_lock_info"); - buildPinLabels(0); + buildInputLabels(0); } - void SimLockBox::buildPinLabels(unsigned int pinSize) + void SimLockBox::buildInputLabels(unsigned int inputSize) { auto itemBuilder = []() { auto label = new gui::Image("dot_12px_hard_alpha_W_G"); return label; }; - LockWindow->buildPinLabels(itemBuilder, pinSize, label_style::x, label_style::y, label_style::w); + LockWindow->buildPinLabels(itemBuilder, inputSize, label_style::x, label_style::y, label_style::w); LockWindow->pinLabelsBox->setEdges(RectangleEdge::Bottom); } - void SimLockBox::rebuildPinLabels(unsigned int pinSize) + void SimLockBox::rebuildInputLabels(unsigned int inputSize) { LockWindow->pinLabelsBox->erase(); - buildPinLabels(pinSize); + buildInputLabels(inputSize); } - void SimLockBox::setVisibleStateEnterPin(EnterPasscodeType type) + void SimLockBox::setVisibleStateInputRequired(InputActionType type) { LockWindow->pinLabelsBox->setVisible(true); switch (type) { - case PinLockBox::EnterPasscodeType::ProvidePasscode: { + case LockBox::InputActionType::ProvideInput: { LockWindow->setText( "app_desktop_sim_enter_pin_unlock", PinLockBaseWindow::TextType::Primary, true, - {{LockWindow->getToken(PinLockBaseWindow::Token::PinType), LockWindow->lock->getPasscodeName()}}); + {{LockWindow->getToken(PinLockBaseWindow::Token::PinType), LockWindow->lock->getLockName()}}); break; } - case PinLockBox::EnterPasscodeType::ProvideNewPasscode: + case LockBox::InputActionType::ProvideNewInput: LockWindow->setText("app_desktop_sim_enter_new_pin", PinLockBaseWindow::TextType::Primary); break; - case PinLockBox::EnterPasscodeType::ConfirmNewPasscode: + case LockBox::InputActionType::ConfirmNewInput: LockWindow->setText("app_desktop_sim_confirm_new_pin", PinLockBaseWindow::TextType::Primary); break; } @@ -68,10 +68,10 @@ namespace gui LockWindow->setImagesVisible(true, false); LockWindow->setBottomBarWidgetsActive(false, false, true); } - void SimLockBox::setVisibleStateInvalidPin(PasscodeErrorType type, unsigned int value) + void SimLockBox::setVisibleStateInputInvalid(InputErrorType type, unsigned int value) { switch (type) { - case PinLockBox::PasscodeErrorType::InvalidPasscode: + case LockBox::InputErrorType::InvalidInput: if (value == 1) { LockWindow->setText( "app_desktop_sim_setup_wrong_pin_last_attempt", PinLockBaseWindow::TextType::Primary, true); @@ -84,10 +84,10 @@ namespace gui {{LockWindow->getToken(PinLockBaseWindow::Token::Attempts), static_cast(value)}}); } break; - case PinLockBox::PasscodeErrorType::NewPasscodeConfirmFailed: + case LockBox::InputErrorType::NewInputConfirmFailed: LockWindow->setText("app_desktop_sim_wrong_pin_confirmation", PinLockBaseWindow::TextType::Primary); break; - case PinLockBox::PasscodeErrorType::UnhandledError: { + case LockBox::InputErrorType::UnhandledError: { LockWindow->setText("app_desktop_sim_cme_error", PinLockBaseWindow::TextType::Primary, true, @@ -107,6 +107,6 @@ namespace gui void SimLockBox::clear() { - rebuildPinLabels(0); + rebuildInputLabels(0); } } // namespace gui diff --git a/module-apps/application-desktop/windows/SimLockBox.hpp b/module-apps/locks/widgets/SimLockBox.hpp similarity index 53% rename from module-apps/application-desktop/windows/SimLockBox.hpp rename to module-apps/locks/widgets/SimLockBox.hpp index 32084178fbea92da6c60d8c829218e2680b4d950..bf6bd19c2c1d19d155c79e11d434c239b2610d20 100644 --- a/module-apps/application-desktop/windows/SimLockBox.hpp +++ b/module-apps/locks/widgets/SimLockBox.hpp @@ -1,9 +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 #pragma once -#include "PinLockBox.hpp" +#include "LockBox.hpp" namespace gui { @@ -12,7 +12,7 @@ namespace gui namespace gui { - class SimLockBox : public PinLockBox + class SimLockBox : public LockBox { public: SimLockBox(PinLockBaseWindow *LockBaseWindow) : LockWindow(LockBaseWindow) @@ -24,12 +24,12 @@ namespace gui void putChar(unsigned int charNum) final; void clear() final; - void setVisibleStateEnterPin(EnterPasscodeType type) final; - void setVisibleStateInvalidPin(PasscodeErrorType type, unsigned int value) final; + void setVisibleStateInputRequired(InputActionType type) final; + void setVisibleStateInputInvalid(InputErrorType type, unsigned int value) final; void setVisibleStateBlocked() final; - void buildLockBox(unsigned int pinSize) final; - void buildPinLabels(unsigned int pinSize); - void rebuildPinLabels(unsigned int pinSize); + void buildLockBox(unsigned int inputSize) final; + void buildInputLabels(unsigned int inputSize); + void rebuildInputLabels(unsigned int inputSize); }; } // namespace gui diff --git a/module-apps/application-desktop/windows/LockWindow.cpp b/module-apps/locks/windows/LockWindow.cpp similarity index 97% rename from module-apps/application-desktop/windows/LockWindow.cpp rename to module-apps/locks/windows/LockWindow.cpp index 4a3dc0e27d19405967ebd58dce9d79cfdada605f..2abd37c6b7e9f8b3fe4ce6beccc47d2852f22361 100644 --- a/module-apps/application-desktop/windows/LockWindow.cpp +++ b/module-apps/locks/windows/LockWindow.cpp @@ -1,8 +1,8 @@ // Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md -#include "application-desktop/data/AppDesktopStyle.hpp" -#include "application-desktop/widgets/PinLock.hpp" +#include "locks/data/LockStyle.hpp" +#include "locks/widgets/Lock.hpp" #include "FontManager.hpp" #include #include "LockWindow.hpp" diff --git a/module-apps/application-desktop/windows/LockWindow.hpp b/module-apps/locks/windows/LockWindow.hpp similarity index 84% rename from module-apps/application-desktop/windows/LockWindow.hpp rename to module-apps/locks/windows/LockWindow.hpp index 6e05658afb98c4c43c818d2a4f6aaceb7da423cb..d62cfd0b67a74ae4c6748dff37ac89b43b6c86d0 100644 --- a/module-apps/application-desktop/windows/LockWindow.hpp +++ b/module-apps/locks/windows/LockWindow.hpp @@ -7,9 +7,9 @@ #include "RichTextParser.hpp" #include "Text.hpp" -namespace gui +namespace locks { - class PinLock; + class Lock; } namespace gui @@ -50,11 +50,11 @@ namespace gui text::RichTextParser::TokenMap tokens = text::RichTextParser::TokenMap{}); void setTitleBar(bool isVisible); - std::unique_ptr lock = nullptr; - gui::HBox *pinLabelsBox = nullptr; - gui::Text *primaryText = nullptr; - gui::Text *secondaryText = nullptr; - gui::Text *title = nullptr; + std::unique_ptr lock = nullptr; + gui::HBox *pinLabelsBox = nullptr; + gui::Text *primaryText = nullptr; + gui::Text *secondaryText = nullptr; + gui::Text *title = nullptr; protected: virtual void buildBottomBar(); diff --git a/module-apps/application-desktop/windows/PinLockBaseWindow.cpp b/module-apps/locks/windows/PinLockBaseWindow.cpp similarity index 97% rename from module-apps/application-desktop/windows/PinLockBaseWindow.cpp rename to module-apps/locks/windows/PinLockBaseWindow.cpp index 5e51ccfa75b11063163ce4d10b6f04d6dbfd2f3d..c2f9ea12f136cc68cf0fb944f8a79efddc4639be 100644 --- a/module-apps/application-desktop/windows/PinLockBaseWindow.cpp +++ b/module-apps/locks/windows/PinLockBaseWindow.cpp @@ -1,8 +1,8 @@ // Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md -#include "application-desktop/data/AppDesktopStyle.hpp" -#include "application-desktop/widgets/PinLock.hpp" +#include "locks/data/LockStyle.hpp" +#include "locks/widgets/Lock.hpp" #include #include "PinLockBaseWindow.hpp" #include diff --git a/module-apps/application-desktop/windows/PinLockBaseWindow.hpp b/module-apps/locks/windows/PinLockBaseWindow.hpp similarity index 100% rename from module-apps/application-desktop/windows/PinLockBaseWindow.hpp rename to module-apps/locks/windows/PinLockBaseWindow.hpp diff --git a/module-apps/application-desktop/windows/PinLockWindow.cpp b/module-apps/locks/windows/PinLockWindow.cpp similarity index 58% rename from module-apps/application-desktop/windows/PinLockWindow.cpp rename to module-apps/locks/windows/PinLockWindow.cpp index ff0c9d56898e101a0769e40fa2bc749c1d41035a..03020ba01cbd60f6c43b3128ab29d362c52b161b 100644 --- a/module-apps/application-desktop/windows/PinLockWindow.cpp +++ b/module-apps/locks/windows/PinLockWindow.cpp @@ -10,10 +10,10 @@ #include "PinLockWindow.hpp" #include "application-desktop/ApplicationDesktop.hpp" -#include "application-desktop/data/LockPhoneData.hpp" -#include "ScreenLockBox.hpp" -#include "SimLockBox.hpp" -#include "PukLockBox.hpp" +#include "locks/data/LockData.hpp" +#include "locks/widgets/PhoneLockBox.hpp" +#include "locks/widgets/SimLockBox.hpp" +#include "locks/widgets/PukLockBox.hpp" #include namespace gui @@ -47,47 +47,45 @@ namespace gui void PinLockWindow::setVisibleState() { restore(); - if (lock->isState(PinLock::LockState::PasscodeRequired)) { - LockBox->setVisibleStateEnterPin(PinLockBox::EnterPasscodeType::ProvidePasscode); + if (lock->isState(Lock::LockState::InputRequired)) { + lockBox->setVisibleStateInputRequired(LockBox::InputActionType::ProvideInput); } - else if (lock->isState(PinLock::LockState::PasscodeInvalidRetryRequired)) { - LockBox->setVisibleStateInvalidPin(PinLockBox::PasscodeErrorType::InvalidPasscode, lock->getValue()); + else if (lock->isState(Lock::LockState::InputInvalidRetryRequired)) { + lockBox->setVisibleStateInputInvalid(LockBox::InputErrorType::InvalidInput, lock->getAttemptsLeft()); } - else if (lock->isState(PinLock::LockState::Blocked)) { - LockBox->setVisibleStateBlocked(); + else if (lock->isState(Lock::LockState::Blocked)) { + lockBox->setVisibleStateBlocked(); } - else if (lock->isState(PinLock::LockState::NewPasscodeRequired)) { - LockBox->setVisibleStateEnterPin(PinLockBox::EnterPasscodeType::ProvideNewPasscode); + else if (lock->isState(Lock::LockState::NewInputRequired)) { + lockBox->setVisibleStateInputRequired(LockBox::InputActionType::ProvideNewInput); } - else if (lock->isState(PinLock::LockState::NewPasscodeConfirmRequired)) { - LockBox->setVisibleStateEnterPin(PinLockBox::EnterPasscodeType::ConfirmNewPasscode); + else if (lock->isState(Lock::LockState::NewInputConfirmRequired)) { + lockBox->setVisibleStateInputRequired(LockBox::InputActionType::ConfirmNewInput); } - else if (lock->isState(PinLock::LockState::NewPasscodeInvalid)) { - LockBox->setVisibleStateInvalidPin(PinLockBox::PasscodeErrorType::NewPasscodeConfirmFailed, - lock->getValue()); + else if (lock->isState(Lock::LockState::NewInputInvalid)) { + lockBox->setVisibleStateInputInvalid(LockBox::InputErrorType::NewInputConfirmFailed, + lock->getAttemptsLeft()); } - else if (lock->isState(PinLock::LockState::ErrorOccurred)) { - LockBox->setVisibleStateInvalidPin(PinLockBox::PasscodeErrorType::UnhandledError, lock->getValue()); + else if (lock->isState(Lock::LockState::ErrorOccurred)) { + lockBox->setVisibleStateInputInvalid(LockBox::InputErrorType::UnhandledError, lock->getAttemptsLeft()); } application->refreshWindow(RefreshModes::GUI_REFRESH_FAST); } void PinLockWindow::onBeforeShow(ShowMode mode, SwitchData *data) { - if (auto lockData = dynamic_cast(data)) { + if (auto lockData = dynamic_cast(data)) { rebuild(); - lockTimeoutApplication = lockData->getPreviousApplication(); - lock = lockData->getLock(); - assert(lock); + lock = std::make_unique(lockData->getLock()); buildPinLockBox(); - LockBox->buildLockBox(lock->getMaxPinSize()); + lockBox->buildLockBox(lock->getMaxInputSize()); - if (lock->isState(PinLock::LockState::PasscodeRequired)) { - currentPasscodeType = PinLockBox::EnterPasscodeType::ProvidePasscode; + if (lock->isState(Lock::LockState::InputRequired)) { + currentPasscodeType = LockBox::InputActionType::ProvideInput; } - else if (lock->isState(PinLock::LockState::NewPasscodeRequired)) { - currentPasscodeType = PinLockBox::EnterPasscodeType::ProvideNewPasscode; + else if (lock->isState(Lock::LockState::NewInputRequired)) { + currentPasscodeType = LockBox::InputActionType::ProvideNewInput; } setVisibleState(); } @@ -107,7 +105,7 @@ namespace gui if (usesNumericKeys()) { lock->clearAttempt(); } - else if (lock->isState(PinLock::LockState::PasscodeInvalidRetryRequired)) { + else if (lock->isState(Lock::LockState::InputInvalidRetryRequired)) { lock->consumeState(); } application->switchWindow(gui::name::window::main_window); @@ -116,14 +114,14 @@ namespace gui else if (inputEvent.is(KeyCode::KEY_PND)) { if (usesNumericKeys()) { lock->popChar(); - LockBox->popChar(lock->getCharCount()); + lockBox->popChar(lock->getCharCount()); bottomBar->setActive(BottomBar::Side::CENTER, lock->canVerify()); return true; } } else if (0 <= gui::toNumeric(inputEvent.keyCode) && gui::toNumeric(inputEvent.keyCode) <= 9) { if (usesNumericKeys() && lock->canPut()) { - LockBox->putChar(lock->getCharCount()); + lockBox->putChar(lock->getCharCount()); lock->putNextChar(gui::toNumeric(inputEvent.keyCode)); bottomBar->setActive(BottomBar::Side::CENTER, lock->canVerify()); return true; @@ -141,32 +139,32 @@ namespace gui void PinLockWindow::buildPinLockBox() { auto lockType = lock->getLockType(); - if (lockType == PinLock::LockType::Screen) { - LockBox = std::make_unique(this); + if (lockType == Lock::LockType::Screen) { + lockBox = std::make_unique(this); } - else if (lockType == PinLock::LockType::SimPuk) { - LockBox = std::make_unique(this); + else if (lockType == Lock::LockType::SimPuk) { + lockBox = std::make_unique(this); setTitleBar(true, true); 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(this); + else if (lockType == Lock::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); + assert(lockBox != nullptr); } auto PinLockWindow::usesNumericKeys() const noexcept -> bool { - return lock && (lock->isState(PinLock::LockState::PasscodeRequired) || - lock->isState(PinLock::LockState::NewPasscodeRequired) || - lock->isState(PinLock::LockState::NewPasscodeConfirmRequired)); + return lock && + (lock->isState(Lock::LockState::InputRequired) || lock->isState(Lock::LockState::NewInputRequired) || + lock->isState(Lock::LockState::NewInputConfirmRequired)); } } /* namespace gui */ diff --git a/module-apps/application-desktop/windows/PinLockWindow.hpp b/module-apps/locks/windows/PinLockWindow.hpp similarity index 77% rename from module-apps/application-desktop/windows/PinLockWindow.hpp rename to module-apps/locks/windows/PinLockWindow.hpp index 12ce3be0fb506936c9323c983e9a58c1cdda3d95..4e164da3cf014166cd2b670860f8a4869254e02d 100644 --- a/module-apps/application-desktop/windows/PinLockWindow.hpp +++ b/module-apps/locks/windows/PinLockWindow.hpp @@ -7,17 +7,18 @@ #include "gui/widgets/Label.hpp" #include "gui/widgets/Image.hpp" #include "gui/widgets/BottomBar.hpp" -#include "application-desktop/widgets/PinLock.hpp" -#include "PinLockBox.hpp" +#include "locks/widgets/Lock.hpp" +#include "locks/widgets/LockBox.hpp" #include "PinLockBaseWindow.hpp" + namespace gui { class PinLockWindow : public PinLockBaseWindow { const std::string this_window_name; - std::string lockTimeoutApplication = ""; - std::unique_ptr LockBox = nullptr; - PinLockBox::EnterPasscodeType currentPasscodeType = PinLockBox::EnterPasscodeType::ProvidePasscode; + std::string lockTimeoutApplication = ""; + std::unique_ptr lockBox = nullptr; + LockBox::InputActionType currentPasscodeType = LockBox::InputActionType::ProvideInput; // method hides or show widgets and sets bars according to provided state void setVisibleState(); diff --git a/module-apps/popups/CMakeLists.txt b/module-apps/popups/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..8fb47d3c725fc5fe83a35b77bfacc3f8effe3842 --- /dev/null +++ b/module-apps/popups/CMakeLists.txt @@ -0,0 +1,34 @@ + +include_directories( ${CMAKE_PROJECT_NAME} + + PRIVATE + "${CMAKE_CURRENT_LIST_DIR}" +) + +include_directories( ${PROJECT_NAME} + + PRIVATE + "${CMAKE_CURRENT_LIST_DIR}" +) + +target_sources( ${PROJECT_NAME} + + PRIVATE + "${CMAKE_CURRENT_LIST_DIR}/Popups.cpp" + "${CMAKE_CURRENT_LIST_DIR}/VolumeWindow.cpp" + "${CMAKE_CURRENT_LIST_DIR}/WindowWithTimer.cpp" + "${CMAKE_CURRENT_LIST_DIR}/HomeModesWindow.cpp" + "${CMAKE_CURRENT_LIST_DIR}/TetheringConfirmationPopup.cpp" + "${CMAKE_CURRENT_LIST_DIR}/TetheringNotificationPopup.cpp" + "${CMAKE_CURRENT_LIST_DIR}/TetheringPhoneModePopup.cpp" + + PRIVATE + "${CMAKE_CURRENT_LIST_DIR}/Popups.hpp" + "${CMAKE_CURRENT_LIST_DIR}/VolumeWindow.hpp" + "${CMAKE_CURRENT_LIST_DIR}/WindowWithTimer.hpp" + "${CMAKE_CURRENT_LIST_DIR}/HomeModesWindow.hpp" + "${CMAKE_CURRENT_LIST_DIR}/TetheringConfirmationPopup.hpp" + "${CMAKE_CURRENT_LIST_DIR}/TetheringNotificationPopup.hpp" + "${CMAKE_CURRENT_LIST_DIR}/TetheringPhoneModePopup.hpp" + "${CMAKE_CURRENT_LIST_DIR}/data/PopupData.hpp" +) diff --git a/module-gui/gui/SwitchData.hpp b/module-gui/gui/SwitchData.hpp index 48f12e1ffd6b34532f2d8d9f67db79027bcf404c..deeefabec9526f3a1c0352e44a35634eecafa852 100644 --- a/module-gui/gui/SwitchData.hpp +++ b/module-gui/gui/SwitchData.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 @@ -22,9 +22,10 @@ namespace gui public: SwitchData() = default; - SwitchData(const std::string &description) : description{description} {}; + explicit SwitchData(std::string description) : description{std::move(description)} {}; + virtual ~SwitchData() = default; - virtual const std::string &getDescription() const + [[nodiscard]] virtual const std::string &getDescription() const { return description; };