~aleteoryx/muditaos

ref: 950cf78aa9fe3f30d25d5048f0ec46bf5fe2eac0 muditaos/module-services/service-desktop/USBSecurityModel.cpp -rw-r--r-- 2.2 KiB
950cf78a — Lukasz Mastalerz [CP-1825] Update while on onboarding screen 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "service-desktop/USBSecurityModel.hpp"

#include "Service/Service.hpp"
#include "service-desktop/DesktopMessages.hpp"
#include "service-desktop/WorkerDesktop.hpp"

#include <service-db/Settings.hpp>
#include <service-db/agents/settings/SystemSettings.hpp>

namespace sdesktop
{
    USBSecurityModel::USBSecurityModel(sys::Service *ownerSrv, settings::Settings *srvSettings)
    {
        settings    = srvSettings;
        phoneLocked = PhoneLockState::Locked;
    }

    auto USBSecurityModel::isPasscodeEnabled() const -> bool
    {
        return utils::getNumericValue<bool>(
            settings->getValue(settings::SystemProperties::lockScreenPasscodeIsOn, settings::SettingsScope::Global));
    }

    auto USBSecurityModel::setPhoneLocked() -> void
    {
        phoneLocked = PhoneLockState::Locked;
    }

    auto USBSecurityModel::setPhoneUnlocked() -> void
    {
        phoneLocked = PhoneLockState::Unlocked;
    }

    auto USBSecurityModel::isPhoneLocked() const -> bool
    {
        return phoneLocked == PhoneLockState::Locked;
    }

    auto USBSecurityModel::isSecurityEnabled() const -> bool
    {
        return isPasscodeEnabled() && isPhoneLocked();
    }

    auto USBSecurityModel::isEulaAccepted() const -> bool
    {
        return utils::getNumericValue<bool>(
            settings->getValue(settings::SystemProperties::eulaAccepted, settings::SettingsScope::Global));
    }

    auto USBSecurityModel::getEndpointSecurity() const -> endpointSecurity_t
    {
        if (!isEulaAccepted()) {
            return {EndpointSecurity::Block, BlockReason::EulaNotAccepted};
        }
        else if (isSecurityEnabled()) {
            return {EndpointSecurity::Block, BlockReason::DeviceLocked};
        }
        else {
            return {EndpointSecurity::Allow, BlockReason::NoReason};
        }
    }

    auto USBSecurityModel::updatePhoneLockTime(const time_t newPhoneLockTime) -> void
    {
        phoneLockTime = newPhoneLockTime;
    }

    auto USBSecurityModel::getPhoneLockTime() const -> time_t
    {
        return phoneLockTime;
    }
} // namespace sdesktop