~aleteoryx/muditaos

ref: 427c4f2d62d7a936b5dfbe12290a024d142aec2f muditaos/module-apps/application-desktop/widgets/PinLockHandler.hpp -rw-r--r-- 2.7 KiB
427c4f2d — Szymon Mroczek EGD-4546 builtin mic not working (#1102) 5 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// 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 "PinLock.hpp"

#include "Interface/SettingsRecord.hpp"

#include <module-services/service-appmgr/service-appmgr/messages/ActionRequest.hpp>
#include <module-services/service-appmgr/service-appmgr/Actions.hpp>

namespace app
{
    class ApplicationDesktop;
}

namespace gui
{
    class PinLockHandler
    {
        app::ApplicationDesktop *app = nullptr;
        const SettingsRecord &appSettings;
        gui::PinLock screenLock;
        gui::PinLock simLock;
        bool promptSimLockWindow = true;

        void handleScreenPin(const std::vector<unsigned int> &pin);
        void handlePasscode(PinLock::LockType type, const std::vector<unsigned int> passcode);
        void handlePasscodeChange(const std::vector<unsigned int> passcode);
        void handleNewPasscodeUnconfirmed(const std::vector<unsigned int> &passcode,
                                          const std::vector<unsigned int> &pin);
        void handleNewPasscodeConfirmed(PinLock::LockType type,
                                        const std::vector<unsigned int> &passcode,
                                        const std::vector<unsigned int> &pin);
        void handleNewPasscodeInvalid(const std::vector<unsigned int> &passcode);
        void handlePasscodeParams(PinLock::LockType type,
                                  PinLock::LockState state,
                                  app::manager::actions::ActionParamsPtr &&data);
        void switchToPinLockWindow(
            std::function<void(PinLock::LockType, const std::vector<unsigned int> &)> onLockActivatedCallback);
        void switchToPinLockWindow(
            PinLock::LockState type,
            std::function<void(PinLock::LockType, const std::vector<unsigned int> &)> onLockActivatedCallback);

        auto getStrongestLock() noexcept -> gui::PinLock &;
        void unlock();
        void setSimLockHandled() noexcept;

      public:
        PinLockHandler(app::ApplicationDesktop *app, SettingsRecord &settings);

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

        [[nodiscard]] auto isScreenLocked() const noexcept -> bool
        {
            return !screenLock.isState(PinLock::LockState::Unlocked);
        }
        void lockScreen();
        void unlockScreen();
    };
} // namespace gui