~aleteoryx/muditaos

muditaos/module-apps/application-onboarding/ApplicationOnBoarding.cpp -rw-r--r-- 10.0 KiB
a405cad6Aleteoryx trim readme 6 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#include "ApplicationOnBoarding.hpp"

#include "apps-common/messages/OnBoardingMessages.hpp"
#include "windows/StartConfigurationWindow.hpp"
#include "windows/OnBoardingLanguagesWindow.hpp"
#include "windows/EULALicenseWindow.hpp"
#include "windows/OnBoardingSimSelectWindow.hpp"
#include "windows/NoSimSelectedDialogWindow.hpp"
#include "windows/ConfigurationSuccessfulDialogWindow.hpp"
#include "windows/NoConfigurationDialogWindow.hpp"
#include "windows/UpdateDialogWindow.hpp"
#include "windows/SkipDialogWindow.hpp"
#include "windows/OnBoardingDateAndTimeWindow.hpp"
#include "windows/OnBoardingChangeDateAndTimeWindow.hpp"
#include "WindowsPopupFilter.hpp"

#include <application-settings/windows/system/ChangeTimeZone.hpp>
#include <apps-common/locks/data/PhoneLockMessages.hpp>
#include <apps-common/locks/data/SimLockMessages.hpp>
#include <service-appmgr/ServiceApplicationManagerName.hpp>
#include <service-appmgr/messages/GetCurrentDisplayLanguageResponse.hpp>
#include <service-db/agents/settings/SystemSettings.hpp>
#include <EventStore.hpp>

namespace app
{
    namespace
    {
        constexpr auto OnBoardingStackSize = 4096U;
    } // namespace

    ApplicationOnBoarding::ApplicationOnBoarding(std::string name,
                                                 std::string parent,
                                                 StatusIndicators statusIndicators,
                                                 StartInBackground startInBackground)
        : Application(std::move(name), std::move(parent), statusIndicators, startInBackground, OnBoardingStackSize)
    {
        using namespace gui::status_bar;
        statusBarManager->enableIndicators(
            {Indicator::Signal, Indicator::Time, Indicator::Battery, Indicator::SimCard});

        bus.channels.push_back(sys::BusChannel::ServiceDBNotifications);
        bus.channels.push_back(sys::BusChannel::PhoneLockChanges);
        bus.channels.push_back(sys::BusChannel::ServiceCellularNotifications);

        getPopupFilter().addAppDependentFilter([&](const gui::PopupRequestParams & /*popupParams*/) {
            return gui::name::window::main_window != getCurrentWindow()->getName() ? gui::popup::FilterType::Show
                                                                                   : gui::popup::FilterType::Ignore;
        });
    }

    // Invoked upon receiving data message
    sys::MessagePointer ApplicationOnBoarding::DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp)
    {
        auto retMsg = Application::DataReceivedHandler(msgl);
        // if message was handled by application's template there is no need to process further.
        if (reinterpret_cast<sys::ResponseMessage *>(retMsg.get())->retCode == sys::ReturnCodes::Success) {
            return retMsg;
        }

        return handleAsyncResponse(resp);
    }

    sys::ReturnCodes ApplicationOnBoarding::InitHandler()
    {
        const auto ret = Application::InitHandler();
        if (ret != sys::ReturnCodes::Success) {
            return ret;
        }

        createUserInterface();

        settings->setValue(
            settings::SystemProperties::eulaAccepted, utils::to_string(false), settings::SettingsScope::Global);

        connect(typeid(manager::GetCurrentDisplayLanguageResponse), [&](sys::Message *msg) {
            if (gui::name::window::main_window == getCurrentWindow()->getName()) {
                switchWindow(gui::window::name::onBoarding_eula, nullptr);
                return sys::msgHandled();
            }
            else {
                return sys::msgNotHandled();
            }
        });

        connect(typeid(locks::SetConfirmedPhoneLock), [&](sys::Message *msg) {
            switchWindow(gui::window::name::onBoarding_date_and_time);
            return sys::msgHandled();
        });

        connect(typeid(locks::SkippedSetPhoneLock), [&](sys::Message *msg) {
            switchWindow(gui::window::name::onBoarding_date_and_time);
            return sys::msgHandled();
        });

        connect(typeid(locks::SimSwitched), [&](sys::Message *msg) {
            auto simState = Store::GSM::get()->sim;
            if (simState == Store::GSM::SIM::SIM1 || simState == Store::GSM::SIM::SIM2) {
                phoneLockSubject.setPhoneLock();
                return sys::msgHandled();
            }
            return sys::msgNotHandled();
        });

        connect(typeid(cellular::msg::notification::SimReady), [&](sys::Message *msg) {
            auto selectedSIM = Store::GSM::get()->selected;
            if (getCurrentWindow()->getName() != gui::popup::window::sim_switching_window &&
                selectedSIM != Store::GSM::SelectedSIM::NONE) {
                phoneLockSubject.setPhoneLock();
                return sys::msgHandled();
            }
            return sys::msgNotHandled();
        });

        return ret;
    }

    void ApplicationOnBoarding::acceptEULA()
    {
        settings->setValue(
            settings::SystemProperties::eulaAccepted, utils::to_string(true), settings::SettingsScope::Global);
    }

    void ApplicationOnBoarding::finalizeOnBoarding()
    {
        bus.sendUnicast(std::make_shared<onBoarding::FinalizeOnBoarding>(), service::name::appmgr);
    }

    sys::ReturnCodes ApplicationOnBoarding::SwitchPowerModeHandler(const sys::ServicePowerMode mode)
    {
        return sys::ReturnCodes::Success;
    }

    void ApplicationOnBoarding::createUserInterface()
    {
        windowsFactory.attach(gui::name::window::main_window, [](ApplicationCommon *app, const std::string &name) {
            return std::make_unique<app::onBoarding::OnBoardingLanguagesWindow>(app, gui::name::window::main_window);
        });
        windowsFactory.attach(gui::window::name::onBoarding_start_configuration,
                              [](ApplicationCommon *app, const std::string &name) {
                                  return std::make_unique<app::onBoarding::StartConfigurationWindow>(app);
                              });
        windowsFactory.attach(gui::window::name::onBoarding_eula, [&](ApplicationCommon *app, const std::string &name) {
            const auto eulaDirPath  = purefs::dir::getSystemDataDirPath() / "licenses";
            const auto eulaFilename = "eula.txt";
            auto eulaRepository     = std::make_unique<app::onBoarding::EULARepository>(eulaDirPath, eulaFilename);
            auto presenter = std::make_unique<app::onBoarding::EULALicenseWindowPresenter>([&]() { acceptEULA(); },
                                                                                           std::move(eulaRepository));
            return std::make_unique<app::onBoarding::EULALicenseWindow>(app, std::move(presenter));
        });
        windowsFactory.attach(gui::window::name::onBoarding_sim_select,
                              [](ApplicationCommon *app, const std::string &name) {
                                  return std::make_unique<app::onBoarding::OnBoardingSimSelectWindow>(
                                      app, gui::window::name::onBoarding_sim_select);
                              });
        windowsFactory.attach(gui::window::name::onBoarding_no_sim_selected,
                              [](ApplicationCommon *app, const std::string &name) {
                                  return std::make_unique<app::onBoarding::NoSimSelectedDialogWindow>(app);
                              });
        windowsFactory.attach(gui::window::name::onBoarding_configuration_successful,
                              [](ApplicationCommon *app, const std::string &name) {
                                  return std::make_unique<app::onBoarding::ConfigurationSuccessfulDialogWindow>(app);
                              });
        windowsFactory.attach(gui::window::name::onBoarding_no_configuration,
                              [](ApplicationCommon *app, const std::string &name) {
                                  return std::make_unique<app::onBoarding::NoConfigurationDialogWindow>(app);
                              });
        windowsFactory.attach(
            gui::window::name::onBoarding_update, [&](ApplicationCommon *app, const std::string &name) {
                auto presenter = std::make_unique<app::onBoarding::OnBoardingFinalizeWindowPresenter>(
                    [&]() { finalizeOnBoarding(); });
                return std::make_unique<app::onBoarding::UpdateDialogWindow>(app, std::move(presenter));
            });
        windowsFactory.attach(gui::window::name::onBoarding_skip, [](ApplicationCommon *app, const std::string &name) {
            return std::make_unique<app::onBoarding::SkipDialogWindow>(app);
        });
        windowsFactory.attach(gui::window::name::onBoarding_date_and_time,
                              [](ApplicationCommon *app, const std::string &name) {
                                  return std::make_unique<app::onBoarding::OnBoardingDateAndTimeWindow>(app);
                              });
        windowsFactory.attach(gui::window::name::onBoarding_change_date_and_time,
                              [](ApplicationCommon *app, const std::string &name) {
                                  return std::make_unique<app::onBoarding::OnBoardingChangeDateAndTimeWindow>(app);
                              });
        windowsFactory.attach(gui::window::name::change_time_zone, [](ApplicationCommon *app, const std::string &name) {
            return std::make_unique<gui::ChangeTimeZone>(app);
        });
        windowsFactory.attach(gui::window::name::dialog_confirm, [](ApplicationCommon *app, const std::string &name) {
            return std::make_unique<gui::DialogConfirm>(app, gui::window::name::dialog_confirm);
        });

        attachPopups({gui::popup::ID::Volume,
                      gui::popup::ID::PhoneModes,
                      gui::popup::ID::PhoneLock,
                      gui::popup::ID::SimLock,
                      gui::popup::ID::Alarm});
    }

    void ApplicationOnBoarding::destroyUserInterface()
    {}

} // namespace app