From 81adfe41ab8f915e6cfcee02d9acf35442a93d7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ta=C5=84ski?= Date: Thu, 8 Apr 2021 18:27:08 +0200 Subject: [PATCH] [EGD-6347] Refactored phone modes handling in applications PhoneModeObserver doesn't work properly in applications. Applications have to handle the phone mode changes via AppMgr. Phone mode and tethering handlers separated. --- module-apps/Application.cpp | 55 +++++++++------ module-apps/Application.hpp | 23 ++---- module-apps/ApplicationLauncher.hpp | 12 ++-- .../ApplicationAlarmClock.cpp | 3 +- .../ApplicationAlarmClock.hpp | 9 +-- .../ApplicationAntenna.cpp | 7 +- .../ApplicationAntenna.hpp | 3 +- .../ApplicationCalculator.cpp | 3 +- .../ApplicationCalculator.hpp | 3 +- .../ApplicationCalendar.cpp | 3 +- .../ApplicationCalendar.hpp | 5 +- .../application-call/ApplicationCall.cpp | 7 +- .../application-call/ApplicationCall.hpp | 4 +- .../ApplicationCallLog.cpp | 7 +- .../ApplicationCallLog.hpp | 5 +- .../application-clock/ApplicationClock.cpp | 3 +- .../application-clock/ApplicationClock.hpp | 3 +- .../ApplicationDesktop.cpp | 7 +- .../ApplicationDesktop.hpp | 4 +- .../ApplicationMeditation.cpp | 3 +- .../ApplicationMeditation.hpp | 5 +- .../ApplicationMessages.cpp | 7 +- .../ApplicationMessages.hpp | 4 +- .../ApplicationMusicPlayer.cpp | 3 +- .../ApplicationMusicPlayer.hpp | 5 +- .../application-notes/ApplicationNotes.cpp | 7 +- .../application-notes/ApplicationNotes.hpp | 5 +- .../ApplicationOnBoarding.cpp | 3 +- .../ApplicationOnBoarding.hpp | 3 +- .../ApplicationPhonebook.cpp | 3 +- .../ApplicationPhonebook.hpp | 4 +- .../ApplicationSettings.cpp | 9 ++- .../ApplicationSettings.hpp | 3 +- .../ApplicationSettings.cpp | 7 +- .../ApplicationSettings.hpp | 5 +- .../ApplicationSpecialInput.cpp | 5 +- .../ApplicationSpecialInput.hpp | 5 +- .../popups/TetheringPhoneModePopup.cpp | 4 +- module-apps/popups/data/PhoneModeParams.hpp | 27 +++++++ .../popups/data/PopupRequestParams.hpp | 44 ++++++++++++ .../service-antenna/ServiceAntenna.cpp | 17 +++-- .../model/ApplicationHandle.cpp | 10 +-- .../model/ApplicationManager.cpp | 67 ++++++++++++++++-- .../service-appmgr/service-appmgr/Actions.hpp | 1 + .../model/ApplicationHandle.hpp | 6 +- .../model/ApplicationManager.hpp | 6 ++ .../service-audio/ServiceAudio.cpp | 7 +- .../service-audio/ServiceAudio.hpp | 2 +- .../service-cellular/ServiceCellular.cpp | 30 ++++---- module-sys/PhoneModes/Common.hpp | 21 ++++-- module-sys/PhoneModes/Observer.cpp | 70 +++++++++++++------ module-sys/PhoneModes/Observer.hpp | 22 ++++-- module-sys/PhoneModes/Subject.cpp | 31 +++++--- module-sys/PhoneModes/Subject.hpp | 3 +- ...heringPhoneModeChangeProhibitedMessage.hpp | 2 +- .../messages/TetheringQuestionRequest.hpp | 6 +- 56 files changed, 435 insertions(+), 193 deletions(-) create mode 100644 module-apps/popups/data/PhoneModeParams.hpp create mode 100644 module-apps/popups/data/PopupRequestParams.hpp diff --git a/module-apps/Application.cpp b/module-apps/Application.cpp index 3df2a04995b393939b754e1fbbc9dc9a76f6f8cf..5b31a01b4145983116b376f01d54ac23ad9b9139 100644 --- a/module-apps/Application.cpp +++ b/module-apps/Application.cpp @@ -6,6 +6,8 @@ #include "GuiTimer.hpp" // for GuiTimer #include "Item.hpp" // for Item #include "MessageType.hpp" // for MessageType +#include "module-apps/popups/data/PopupRequestParams.hpp" +#include "module-apps/popups/data/PhoneModeParams.hpp" #include "module-sys/Timers/TimerFactory.hpp" // for Timer #include "TopBar.hpp" #include "popups/TetheringConfirmationPopup.hpp" @@ -82,6 +84,7 @@ namespace app Application::Application(std::string name, std::string parent, + sys::phone_modes::PhoneMode mode, StartInBackground startInBackground, uint32_t stackDepth, sys::ServicePriority priority) @@ -89,14 +92,12 @@ namespace app default_window(gui::name::window::main_window), windowsStack(this), keyTranslator{std::make_unique()}, startInBackground{startInBackground}, callbackStorage{std::make_unique()}, topBarManager{std::make_unique()}, - settings(std::make_unique(this)), - phoneModeObserver(std::make_unique()) + settings(std::make_unique(this)), phoneMode{mode} { topBarManager->enableIndicators({gui::top_bar::Indicator::Time}); topBarManager->set(utils::dateAndTimeSettings.isTimeFormat12() ? gui::top_bar::TimeMode::Time12h : gui::top_bar::TimeMode::Time24h); bus.channels.push_back(sys::BusChannel::ServiceCellularNotifications); - bus.channels.push_back(sys::BusChannel::PhoneModeChanges); longPressTimer = sys::TimerFactory::createPeriodicTimer(this, "LongPress", @@ -111,22 +112,22 @@ namespace app connect(typeid(AppUpdateWindowMessage), [&](sys::Message *msg) -> sys::MessagePointer { return handleUpdateWindow(msg); }); - // handle phone mode changes - phoneModeObserver->connect(this); - phoneModeObserver->subscribe( - [&](sys::phone_modes::PhoneMode phoneMode, sys::phone_modes::Tethering tetheringMode) { - handlePhoneModeChanged(phoneMode, tetheringMode); - }); - + addActionReceiver(app::manager::actions::PhoneModeChanged, [this](auto &¶ms) { + if (params != nullptr) { + auto modeParams = static_cast(params.get()); + phoneMode = modeParams->getPhoneMode(); + } + return actionHandled(); + }); addActionReceiver(app::manager::actions::ShowPopup, [this](auto &¶ms) { - auto popupParams = static_cast(params.get()); + auto popupParams = static_cast(params.get()); if (const auto popupId = popupParams->getPopupId(); isPopupPermitted(popupId)) { - switchWindow(gui::popup::resolveWindowName(popupId)); + showPopup(popupId, popupParams); } return actionHandled(); }); addActionReceiver(app::manager::actions::AbortPopup, [this](auto &¶ms) { - auto popupParams = static_cast(params.get()); + auto popupParams = static_cast(params.get()); const auto popupId = popupParams->getPopupId(); abortPopup(popupId); return actionHandled(); @@ -186,7 +187,7 @@ namespace app window->updateSignalStrength(); window->updateNetworkAccessTechnology(); window->updateTime(); - window->updatePhoneMode(phoneModeObserver->getCurrentPhoneMode()); + window->updatePhoneMode(phoneMode); auto message = std::make_shared(window->buildDrawList(), mode); @@ -687,19 +688,15 @@ namespace app sender->bus.sendUnicast(msg, application); } - void Application::handlePhoneModeChanged(sys::phone_modes::PhoneMode mode, sys::phone_modes::Tethering tethering) + void Application::handlePhoneModeChanged(sys::phone_modes::PhoneMode mode) { - // only foreground rendering application will react to mode changes - if (state != State::ACTIVE_FORGROUND) { - return; - } - using namespace gui::popup; - if (getCurrentWindow()->getName() == window::phone_modes_window) { - updateWindow(window::phone_modes_window, std::make_unique(mode)); + const auto &popupName = resolveWindowName(gui::popup::ID::PhoneModes); + if (const auto currentWindowName = getCurrentWindow()->getName(); currentWindowName == popupName) { + updateWindow(popupName, std::make_unique(mode)); } else { - switchWindow(window::phone_modes_window, std::make_unique(mode)); + switchWindow(popupName, std::make_unique(mode)); } } @@ -738,6 +735,18 @@ namespace app } } + void Application::showPopup(gui::popup::ID id, const gui::PopupRequestParams *params) + { + using namespace gui::popup; + if (id == ID::PhoneModes) { + auto popupParams = static_cast(params); + handlePhoneModeChanged(popupParams->getPhoneMode()); + } + else { + switchWindow(gui::popup::resolveWindowName(id)); + } + } + void Application::abortPopup(gui::popup::ID id) { const auto popupName = gui::popup::resolveWindowName(id); diff --git a/module-apps/Application.hpp b/module-apps/Application.hpp index 4da881541c454cc026a300166f08600d56bce99c..5b2217d285cc0429c571ec63063ac95a2df497ec 100644 --- a/module-apps/Application.hpp +++ b/module-apps/Application.hpp @@ -48,6 +48,7 @@ namespace gui namespace gui { class Item; + class PopupRequestParams; } namespace gui { @@ -188,6 +189,7 @@ namespace app Application(std::string name, std::string parent = "", + sys::phone_modes::PhoneMode mode = sys::phone_modes::PhoneMode::Connected, StartInBackground startInBackground = {false}, uint32_t stackDepth = 4096, sys::ServicePriority priority = sys::ServicePriority::Idle); @@ -326,7 +328,7 @@ namespace app /// Handle the change of phone mode and tethering mode /// @param mode new phone mode /// @param tethering new tethering mode - void handlePhoneModeChanged(sys::phone_modes::PhoneMode mode, sys::phone_modes::Tethering tethering); + void handlePhoneModeChanged(sys::phone_modes::PhoneMode mode); /// @ingrup AppWindowStack WindowsStack windowsStack; @@ -334,6 +336,7 @@ namespace app /// Method used to attach popups windows to application void attachPopups(const std::vector &popupsList); + void showPopup(gui::popup::ID id, const gui::PopupRequestParams *params); void abortPopup(gui::popup::ID id); public: @@ -391,7 +394,7 @@ namespace app /// application's settings std::unique_ptr settings; - std::unique_ptr phoneModeObserver; + sys::phone_modes::PhoneMode phoneMode; public: void setLockScreenPasscodeOn(bool screenPasscodeOn) noexcept; @@ -415,20 +418,4 @@ namespace app private: ApplicationName targetAppName; }; - - class PopupRequestParams : public manager::actions::ActionParams - { - public: - explicit PopupRequestParams(gui::popup::ID popupId) - : manager::actions::ActionParams{"Popup request parameters"}, popupId{popupId} - {} - - [[nodiscard]] auto getPopupId() const noexcept - { - return popupId; - } - - private: - gui::popup::ID popupId; - }; } /* namespace app */ diff --git a/module-apps/ApplicationLauncher.hpp b/module-apps/ApplicationLauncher.hpp index 9726675b1e26ef9cf97759e7e66e64c51973a4e7..27c524184fa241bbbf0ebd67a392d9f2f44d10a8 100644 --- a/module-apps/ApplicationLauncher.hpp +++ b/module-apps/ApplicationLauncher.hpp @@ -65,12 +65,12 @@ namespace app return (preventAutoLocking == PreventAutoLocking::True); } - virtual bool run(sys::Service *caller = nullptr) + virtual bool run(sys::phone_modes::PhoneMode mode, sys::Service *caller = nullptr) { return false; } - virtual bool runBackground(sys::Service *caller = nullptr) + virtual bool runBackground(sys::phone_modes::PhoneMode mode, sys::Service *caller = nullptr) { return false; } @@ -89,17 +89,17 @@ namespace app : ApplicationLauncher(name, std::move(manifest), isCloseable, preventBlocking) {} - bool run(sys::Service *caller) override + bool run(sys::phone_modes::PhoneMode mode, sys::Service *caller) override { parent = (caller == nullptr ? "" : caller->GetName()); - handle = std::make_shared(name, parent); + handle = std::make_shared(name, parent, mode); return sys::SystemManager::RunApplication(handle, caller); } - bool runBackground(sys::Service *caller) override + bool runBackground(sys::phone_modes::PhoneMode mode, sys::Service *caller) override { parent = (caller == nullptr ? "" : caller->GetName()); - handle = std::make_shared(name, parent, true); + handle = std::make_shared(name, parent, mode, true); return sys::SystemManager::RunApplication(handle, caller); } }; diff --git a/module-apps/application-alarm-clock/ApplicationAlarmClock.cpp b/module-apps/application-alarm-clock/ApplicationAlarmClock.cpp index d92e7989d559b7a0d8b3b0cbabf6ff194fcb5f4f..85fbf8dc12e971fc522fc32aaf7736be9cf17375 100644 --- a/module-apps/application-alarm-clock/ApplicationAlarmClock.cpp +++ b/module-apps/application-alarm-clock/ApplicationAlarmClock.cpp @@ -19,9 +19,10 @@ namespace app ApplicationAlarmClock::ApplicationAlarmClock(std::string name, std::string parent, + sys::phone_modes::PhoneMode mode, uint32_t stackDepth, sys::ServicePriority priority) - : Application(name, parent, false, stackDepth, priority) + : Application(name, parent, mode, false, stackDepth, priority) { bus.channels.push_back(sys::BusChannel::ServiceDBNotifications); } diff --git a/module-apps/application-alarm-clock/ApplicationAlarmClock.hpp b/module-apps/application-alarm-clock/ApplicationAlarmClock.hpp index 1aada81386abfc05fdc52be4c3653cdc5a33145e..3412521b1f83eaab4338c90e6444269c7c6792fb 100644 --- a/module-apps/application-alarm-clock/ApplicationAlarmClock.hpp +++ b/module-apps/application-alarm-clock/ApplicationAlarmClock.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 @@ -14,8 +14,9 @@ namespace app public: ApplicationAlarmClock(std::string name, std::string parent, - uint32_t stackDepth = 4096, - sys::ServicePriority priority = sys::ServicePriority::Idle); + sys::phone_modes::PhoneMode mode = sys::phone_modes::PhoneMode::Connected, + uint32_t stackDepth = 4096, + sys::ServicePriority priority = sys::ServicePriority::Idle); sys::MessagePointer DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp) override; @@ -36,7 +37,7 @@ namespace app { static auto GetManifest() -> manager::ApplicationManifest { - return {{manager::actions::Launch}}; + return {{manager::actions::Launch, manager::actions::PhoneModeChanged}}; } }; } // namespace app diff --git a/module-apps/application-antenna/ApplicationAntenna.cpp b/module-apps/application-antenna/ApplicationAntenna.cpp index e52258b2f1926b05a078f8c01f982c146f55716e..b186946f40fda3abf7d897cfe39bdc068f2301a8 100644 --- a/module-apps/application-antenna/ApplicationAntenna.cpp +++ b/module-apps/application-antenna/ApplicationAntenna.cpp @@ -36,8 +36,11 @@ namespace app inline constexpr auto antennaApplicationStackSize = 1024 * 3; - ApplicationAntenna::ApplicationAntenna(std::string name, std::string parent, StartInBackground startInBackground) - : Application(name, parent, startInBackground, antennaApplicationStackSize) + ApplicationAntenna::ApplicationAntenna(std::string name, + std::string parent, + sys::phone_modes::PhoneMode mode, + StartInBackground startInBackground) + : Application(name, parent, mode, startInBackground, antennaApplicationStackSize) { bus.channels.push_back(sys::BusChannel::AntennaNotifications); appTimer = sys::TimerFactory::createPeriodicTimer( diff --git a/module-apps/application-antenna/ApplicationAntenna.hpp b/module-apps/application-antenna/ApplicationAntenna.hpp index 38ed035934fb20b96360b8ef6bcf68966b9b6be3..58a740aef4f41d2a312c649c5c8bfd19ae3f3ea5 100644 --- a/module-apps/application-antenna/ApplicationAntenna.hpp +++ b/module-apps/application-antenna/ApplicationAntenna.hpp @@ -40,6 +40,7 @@ namespace app public: ApplicationAntenna(std::string name = name_antenna, std::string parent = {}, + sys::phone_modes::PhoneMode mode = sys::phone_modes::PhoneMode::Connected, StartInBackground startInBackground = {false}); virtual ~ApplicationAntenna(); @@ -73,7 +74,7 @@ namespace app { static auto GetManifest() -> manager::ApplicationManifest { - return {{manager::actions::Launch}}; + return {{manager::actions::Launch, manager::actions::PhoneModeChanged}}; } }; } /* namespace app */ diff --git a/module-apps/application-calculator/ApplicationCalculator.cpp b/module-apps/application-calculator/ApplicationCalculator.cpp index 9625dd4c2d47104e2f9fded684340d9c028601a6..227b50cf36dfa82812b43c50efa08ddacda87182 100644 --- a/module-apps/application-calculator/ApplicationCalculator.cpp +++ b/module-apps/application-calculator/ApplicationCalculator.cpp @@ -9,8 +9,9 @@ namespace app { ApplicationCalculator::ApplicationCalculator(std::string name, std::string parent, + sys::phone_modes::PhoneMode mode, StartInBackground startInBackground) - : Application(name, parent, startInBackground, stack_size) + : Application(name, parent, mode, startInBackground, stack_size) {} sys::MessagePointer ApplicationCalculator::DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp) diff --git a/module-apps/application-calculator/ApplicationCalculator.hpp b/module-apps/application-calculator/ApplicationCalculator.hpp index 2bfad34b5488bcd9907b56dd044b237c15d0ac80..81a0a2feeba3af2a9d2074671af6a8a532b5edf5 100644 --- a/module-apps/application-calculator/ApplicationCalculator.hpp +++ b/module-apps/application-calculator/ApplicationCalculator.hpp @@ -15,6 +15,7 @@ namespace app public: ApplicationCalculator(std::string name = name_calculator, std::string parent = {}, + sys::phone_modes::PhoneMode mode = sys::phone_modes::PhoneMode::Connected, StartInBackground startInBackground = {false}); ~ApplicationCalculator() override = default; @@ -35,7 +36,7 @@ namespace app { static auto GetManifest() -> manager::ApplicationManifest { - return {{manager::actions::Launch}}; + return {{manager::actions::Launch, manager::actions::PhoneModeChanged}}; } }; } /* namespace app */ diff --git a/module-apps/application-calendar/ApplicationCalendar.cpp b/module-apps/application-calendar/ApplicationCalendar.cpp index b235ae32756b8096ddb39eadff0ed31c9a450483..4f6fb12fa5bf763679fc6a53d1b15810449bbf1c 100644 --- a/module-apps/application-calendar/ApplicationCalendar.cpp +++ b/module-apps/application-calendar/ApplicationCalendar.cpp @@ -44,10 +44,11 @@ namespace app ApplicationCalendar::ApplicationCalendar(std::string name, std::string parent, + sys::phone_modes::PhoneMode mode, StartInBackground startInBackground, uint32_t stackDepth, sys::ServicePriority priority) - : Application(name, parent, startInBackground, stackDepth, priority) + : Application(name, parent, mode, startInBackground, stackDepth, priority) { bus.channels.push_back(sys::BusChannel::ServiceDBNotifications); addActionReceiver(manager::actions::ShowReminder, [this](auto &&data) { diff --git a/module-apps/application-calendar/ApplicationCalendar.hpp b/module-apps/application-calendar/ApplicationCalendar.hpp index e30f4556897064fb234a008ca35dacd0e9dd5655..10e5cf07a2762ec112d5f3eba077d68e780d41eb 100644 --- a/module-apps/application-calendar/ApplicationCalendar.hpp +++ b/module-apps/application-calendar/ApplicationCalendar.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 @@ -25,6 +25,7 @@ namespace app public: ApplicationCalendar(std::string name, std::string parent, + sys::phone_modes::PhoneMode mode = sys::phone_modes::PhoneMode::Connected, StartInBackground startInBackground = {false}, uint32_t stackDepth = 8192, sys::ServicePriority priority = sys::ServicePriority::Idle); @@ -65,7 +66,7 @@ namespace app { static auto GetManifest() -> manager::ApplicationManifest { - return {{manager::actions::Launch, manager::actions::ShowReminder}}; + return {{manager::actions::Launch, manager::actions::ShowReminder, manager::actions::PhoneModeChanged}}; } }; } /* namespace app */ diff --git a/module-apps/application-call/ApplicationCall.cpp b/module-apps/application-call/ApplicationCall.cpp index bdd3298ecfc42c6a80c648ed052a48232e7d1e69..a363b80619a9a36c3d384e8d014df9625dc03632 100644 --- a/module-apps/application-call/ApplicationCall.cpp +++ b/module-apps/application-call/ApplicationCall.cpp @@ -30,8 +30,11 @@ namespace app { - ApplicationCall::ApplicationCall(std::string name, std::string parent, StartInBackground startInBackground) - : Application(name, parent, startInBackground, app::call_stack_size) + ApplicationCall::ApplicationCall(std::string name, + std::string parent, + sys::phone_modes::PhoneMode mode, + StartInBackground startInBackground) + : Application(name, parent, mode, startInBackground, app::call_stack_size) { using namespace gui::top_bar; topBarManager->enableIndicators({Indicator::Signal, diff --git a/module-apps/application-call/ApplicationCall.hpp b/module-apps/application-call/ApplicationCall.hpp index 1026b30b8dd42aff6bdd00a8fad13442d55af0f2..0a081bff3f4a868b3fb6f0dfe8d37662c2e9200c 100644 --- a/module-apps/application-call/ApplicationCall.hpp +++ b/module-apps/application-call/ApplicationCall.hpp @@ -82,6 +82,7 @@ namespace app public: ApplicationCall(std::string name = name_call, std::string parent = {}, + sys::phone_modes::PhoneMode mode = sys::phone_modes::PhoneMode::Connected, StartInBackground startInBackground = {false}); sys::MessagePointer DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp) override; sys::ReturnCodes InitHandler() override; @@ -131,7 +132,8 @@ namespace app manager::actions::EmergencyDial, manager::actions::NotAnEmergencyNotification, manager::actions::NoSimNotification, - manager::actions::CallRejectedByOfflineNotification}}; + manager::actions::CallRejectedByOfflineNotification, + manager::actions::PhoneModeChanged}}; } }; } /* namespace app */ diff --git a/module-apps/application-calllog/ApplicationCallLog.cpp b/module-apps/application-calllog/ApplicationCallLog.cpp index 47566e62740ed99c43714c5d4a6d772fd9a316ac..7c9e76db0be2d41bbd9d95f71877994d3010831e 100644 --- a/module-apps/application-calllog/ApplicationCallLog.cpp +++ b/module-apps/application-calllog/ApplicationCallLog.cpp @@ -22,8 +22,11 @@ using namespace calllog; namespace app { - ApplicationCallLog::ApplicationCallLog(std::string name, std::string parent, StartInBackground startInBackground) - : Application(name, parent, startInBackground, 4096) + ApplicationCallLog::ApplicationCallLog(std::string name, + std::string parent, + sys::phone_modes::PhoneMode mode, + StartInBackground startInBackground) + : Application(name, parent, mode, startInBackground, 4096) { addActionReceiver(manager::actions::ShowCallLog, [this](auto &&data) { switchWindow(gui::name::window::main_window, std::move(data)); diff --git a/module-apps/application-calllog/ApplicationCallLog.hpp b/module-apps/application-calllog/ApplicationCallLog.hpp index 12871a4a3f7cd2aa01b5208f38e7bd606440a70d..d3f7930eb3be4c23eaa03f7d1ec8e9fcb58fa0f2 100644 --- a/module-apps/application-calllog/ApplicationCallLog.hpp +++ b/module-apps/application-calllog/ApplicationCallLog.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 @@ -17,6 +17,7 @@ namespace app public: ApplicationCallLog(std::string name = CallLogAppStr, std::string parent = {}, + sys::phone_modes::PhoneMode mode = sys::phone_modes::PhoneMode::Connected, StartInBackground startInBackground = {false}); ~ApplicationCallLog() override; @@ -41,7 +42,7 @@ namespace app { static auto GetManifest() -> manager::ApplicationManifest { - return {{manager::actions::Launch, manager::actions::ShowCallLog}}; + return {{manager::actions::Launch, manager::actions::ShowCallLog, manager::actions::PhoneModeChanged}}; } }; } /* namespace app */ diff --git a/module-apps/application-clock/ApplicationClock.cpp b/module-apps/application-clock/ApplicationClock.cpp index 8715ee33f9998cf723cf842749ab96ccfba5a2c0..474166acbc5c1ea410422cfd88c94c561a6d6257 100644 --- a/module-apps/application-clock/ApplicationClock.cpp +++ b/module-apps/application-clock/ApplicationClock.cpp @@ -21,10 +21,11 @@ namespace app { ApplicationClock::ApplicationClock(std::string name, std::string parent, + sys::phone_modes::PhoneMode mode, StartInBackground startInBackground, uint32_t stackDepth, sys::ServicePriority priority) - : Application(name, parent, startInBackground, stackDepth, priority) + : Application(name, parent, mode, startInBackground, stackDepth, priority) { timerClock = sys::TimerFactory::createPeriodicTimer( this, "Clock", std::chrono::milliseconds{1000}, [&](sys::Timer &) { timerClockCallback(); }); diff --git a/module-apps/application-clock/ApplicationClock.hpp b/module-apps/application-clock/ApplicationClock.hpp index 4cd18040ca18b6cb2b65db3b337a996648721c44..5d8da1a1c495370936a4635d82a543dff70d7e34 100644 --- a/module-apps/application-clock/ApplicationClock.hpp +++ b/module-apps/application-clock/ApplicationClock.hpp @@ -21,6 +21,7 @@ namespace app public: ApplicationClock(std::string name = name_clock, std::string parent = {}, + sys::phone_modes::PhoneMode mode = sys::phone_modes::PhoneMode::Connected, StartInBackground startInBackground = {false}, uint32_t stackDepth = 4096, sys::ServicePriority priority = sys::ServicePriority::Idle); @@ -42,7 +43,7 @@ namespace app { static auto GetManifest() -> manager::ApplicationManifest { - return {{manager::actions::Launch}}; + return {{manager::actions::Launch, manager::actions::PhoneModeChanged}}; } }; } /* namespace app */ diff --git a/module-apps/application-desktop/ApplicationDesktop.cpp b/module-apps/application-desktop/ApplicationDesktop.cpp index 9d47876313f2794ba4a755db2cd5970cf898f44e..4e82015de603cd39b4f2dfc24f3de30d024fae13 100644 --- a/module-apps/application-desktop/ApplicationDesktop.cpp +++ b/module-apps/application-desktop/ApplicationDesktop.cpp @@ -72,8 +72,11 @@ namespace app } } // namespace - ApplicationDesktop::ApplicationDesktop(std::string name, std::string parent, StartInBackground startInBackground) - : Application(name, parent, startInBackground), lockHandler(this) + ApplicationDesktop::ApplicationDesktop(std::string name, + std::string parent, + sys::phone_modes::PhoneMode mode, + StartInBackground startInBackground) + : Application(name, parent, mode, startInBackground), lockHandler(this) { using namespace gui::top_bar; topBarManager->enableIndicators({Indicator::Signal, diff --git a/module-apps/application-desktop/ApplicationDesktop.hpp b/module-apps/application-desktop/ApplicationDesktop.hpp index 3b0892cc9d73d1597af36a1e53d3eed2d9d8ebc9..ecb4c8d76d7ffe8cab67bf299b550d25a52ce895 100644 --- a/module-apps/application-desktop/ApplicationDesktop.hpp +++ b/module-apps/application-desktop/ApplicationDesktop.hpp @@ -56,6 +56,7 @@ namespace app ApplicationDesktop(std::string name = name_desktop, std::string parent = {}, + sys::phone_modes::PhoneMode mode = sys::phone_modes::PhoneMode::Connected, StartInBackground startInBackground = {false}); virtual ~ApplicationDesktop(); sys::MessagePointer DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp) override; @@ -131,7 +132,8 @@ namespace app manager::actions::DisplayCMEError, manager::actions::DisplayLowBatteryScreen, manager::actions::SystemBrownout, - manager::actions::DisplayLogoAtExit}}; + manager::actions::DisplayLogoAtExit, + manager::actions::PhoneModeChanged}}; } }; diff --git a/module-apps/application-meditation/ApplicationMeditation.cpp b/module-apps/application-meditation/ApplicationMeditation.cpp index c0db25b65c84271357c8ae9467e67b177f2bf72c..b053bbdb17d55764aaa16d112cc8766c9342058d 100644 --- a/module-apps/application-meditation/ApplicationMeditation.cpp +++ b/module-apps/application-meditation/ApplicationMeditation.cpp @@ -12,8 +12,9 @@ namespace app { ApplicationMeditation::ApplicationMeditation(std::string name, std::string parent, + sys::phone_modes::PhoneMode mode, StartInBackground startInBackground) - : Application{name, parent, startInBackground}, state{std::make_unique()} + : Application{name, parent, mode, startInBackground}, state{std::make_unique()} {} auto ApplicationMeditation::InitHandler() -> sys::ReturnCodes diff --git a/module-apps/application-meditation/ApplicationMeditation.hpp b/module-apps/application-meditation/ApplicationMeditation.hpp index 76f73a99164edd0539272c2736e9e2ae10f5b004..70a7de421c1849f507ccb1403e101f01d00c953c 100644 --- a/module-apps/application-meditation/ApplicationMeditation.hpp +++ b/module-apps/application-meditation/ApplicationMeditation.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 @@ -17,6 +17,7 @@ namespace app public: explicit ApplicationMeditation(std::string name = name_meditation, std::string parent = {}, + sys::phone_modes::PhoneMode mode = sys::phone_modes::PhoneMode::Connected, StartInBackground startInBackground = {false}); auto InitHandler() -> sys::ReturnCodes override; @@ -32,7 +33,7 @@ namespace app { static auto GetManifest() -> manager::ApplicationManifest { - return {{manager::actions::Launch}}; + return {{manager::actions::Launch, manager::actions::PhoneModeChanged}}; } }; } // namespace app diff --git a/module-apps/application-messages/ApplicationMessages.cpp b/module-apps/application-messages/ApplicationMessages.cpp index a64bd1f779cbc5049e8a7baf83e99392dec17801..5e7ae13a5c2d6eee2364660fe548800d2a404539 100644 --- a/module-apps/application-messages/ApplicationMessages.cpp +++ b/module-apps/application-messages/ApplicationMessages.cpp @@ -41,8 +41,11 @@ namespace app { static constexpr auto messagesStackDepth = 1024 * 6; // 6Kb stack size - ApplicationMessages::ApplicationMessages(std::string name, std::string parent, StartInBackground startInBackground) - : Application(name, parent, startInBackground, messagesStackDepth), AsyncCallbackReceiver{this} + ApplicationMessages::ApplicationMessages(std::string name, + std::string parent, + sys::phone_modes::PhoneMode mode, + StartInBackground startInBackground) + : Application(name, parent, mode, startInBackground, messagesStackDepth), AsyncCallbackReceiver{this} { bus.channels.push_back(sys::BusChannel::ServiceDBNotifications); addActionReceiver(manager::actions::CreateSms, [this](auto &&data) { diff --git a/module-apps/application-messages/ApplicationMessages.hpp b/module-apps/application-messages/ApplicationMessages.hpp index 8e64c3eb28a28d0c6eadd2319e9d54a0674261ab..b8db49eed315f049d8bde44afa7903593b4fb153 100644 --- a/module-apps/application-messages/ApplicationMessages.hpp +++ b/module-apps/application-messages/ApplicationMessages.hpp @@ -40,6 +40,7 @@ namespace app public: ApplicationMessages(std::string name = name_messages, std::string parent = {}, + sys::phone_modes::PhoneMode mode = sys::phone_modes::PhoneMode::Connected, StartInBackground startInBackground = {false}); sys::MessagePointer DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp) override; @@ -87,7 +88,8 @@ namespace app manager::actions::CreateSms, manager::actions::ShowSmsTemplates, manager::actions::SmsRejectNoSim, - manager::actions::SMSRejectedByOfflineNotification}}; + manager::actions::SMSRejectedByOfflineNotification, + manager::actions::PhoneModeChanged}}; } }; } /* namespace app */ diff --git a/module-apps/application-music-player/ApplicationMusicPlayer.cpp b/module-apps/application-music-player/ApplicationMusicPlayer.cpp index b292ede5f9e8e90a187457a81104d95941aeb7d6..4597dab9c5e82b1781017d455a7afa0f34aa387c 100644 --- a/module-apps/application-music-player/ApplicationMusicPlayer.cpp +++ b/module-apps/application-music-player/ApplicationMusicPlayer.cpp @@ -18,8 +18,9 @@ namespace app ApplicationMusicPlayer::ApplicationMusicPlayer(std::string name, std::string parent, + sys::phone_modes::PhoneMode mode, StartInBackground startInBackground) - : Application(std::move(name), std::move(parent), startInBackground, applicationMusicPlayerStackSize) + : Application(std::move(name), std::move(parent), mode, startInBackground, applicationMusicPlayerStackSize) { LOG_INFO("ApplicationMusicPlayer::create"); connect(typeid(AudioStartPlaybackResponse), [&](sys::Message *msg) { diff --git a/module-apps/application-music-player/ApplicationMusicPlayer.hpp b/module-apps/application-music-player/ApplicationMusicPlayer.hpp index f59a4d31ae363e145f9c85ed3640e73a9dceaab0..ae52a818fa205dc0da1688631b9e099bd65291d4 100644 --- a/module-apps/application-music-player/ApplicationMusicPlayer.hpp +++ b/module-apps/application-music-player/ApplicationMusicPlayer.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 @@ -31,6 +31,7 @@ namespace app public: explicit ApplicationMusicPlayer(std::string name = name_music_player, std::string parent = {}, + sys::phone_modes::PhoneMode mode = sys::phone_modes::PhoneMode::Connected, StartInBackground startInBackground = {false}); sys::MessagePointer DataReceivedHandler(sys::DataMessage *msgl, @@ -60,7 +61,7 @@ namespace app { static auto GetManifest() -> manager::ApplicationManifest { - return {{manager::actions::Launch}}; + return {{manager::actions::Launch, manager::actions::PhoneModeChanged}}; } }; } /* namespace app */ diff --git a/module-apps/application-notes/ApplicationNotes.cpp b/module-apps/application-notes/ApplicationNotes.cpp index 6d455718d846d3807d076881b56616d0bc67fb18..c17a701941ded4c20b3471c9714b60f1432a4f93 100644 --- a/module-apps/application-notes/ApplicationNotes.cpp +++ b/module-apps/application-notes/ApplicationNotes.cpp @@ -27,8 +27,11 @@ namespace app constexpr auto NotesStackSize = 4096U; } // namespace - ApplicationNotes::ApplicationNotes(std::string name, std::string parent, StartInBackground startInBackground) - : Application(std::move(name), std::move(parent), startInBackground, NotesStackSize) + ApplicationNotes::ApplicationNotes(std::string name, + std::string parent, + sys::phone_modes::PhoneMode mode, + StartInBackground startInBackground) + : Application(std::move(name), std::move(parent), mode, startInBackground, NotesStackSize) { bus.channels.push_back(sys::BusChannel::ServiceDBNotifications); } diff --git a/module-apps/application-notes/ApplicationNotes.hpp b/module-apps/application-notes/ApplicationNotes.hpp index 25dc2440bed9cba860644e856ebaadd565bf2484..d7b31f60f978b3f121fac27c710775829ee98611 100644 --- a/module-apps/application-notes/ApplicationNotes.hpp +++ b/module-apps/application-notes/ApplicationNotes.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 @@ -25,6 +25,7 @@ namespace app public: explicit ApplicationNotes(std::string name = name_notes, std::string parent = {}, + sys::phone_modes::PhoneMode mode = sys::phone_modes::PhoneMode::Connected, StartInBackground startInBackground = {false}); sys::MessagePointer DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp) override; @@ -40,7 +41,7 @@ namespace app { static auto GetManifest() -> manager::ApplicationManifest { - return {{manager::actions::Launch}}; + return {{manager::actions::Launch, manager::actions::PhoneModeChanged}}; } }; } // namespace app diff --git a/module-apps/application-onboarding/ApplicationOnBoarding.cpp b/module-apps/application-onboarding/ApplicationOnBoarding.cpp index 643969e30c50f9daa1bea49cfecff07f911376f8..f2fe1dee23463f7b72d5e620aa70ed0c603976f9 100644 --- a/module-apps/application-onboarding/ApplicationOnBoarding.cpp +++ b/module-apps/application-onboarding/ApplicationOnBoarding.cpp @@ -30,8 +30,9 @@ namespace app ApplicationOnBoarding::ApplicationOnBoarding(std::string name, std::string parent, + sys::phone_modes::PhoneMode mode, StartInBackground startInBackground) - : Application(std::move(name), std::move(parent), startInBackground, OnBoardingStackSize) + : Application(std::move(name), std::move(parent), mode, startInBackground, OnBoardingStackSize) { using namespace gui::top_bar; topBarManager->enableIndicators({Indicator::Signal, diff --git a/module-apps/application-onboarding/ApplicationOnBoarding.hpp b/module-apps/application-onboarding/ApplicationOnBoarding.hpp index 79538511a888c5199ab4818294e530f7be1a3552..dbe234248a9488e81a66cc9c9b40a33d367f388a 100644 --- a/module-apps/application-onboarding/ApplicationOnBoarding.hpp +++ b/module-apps/application-onboarding/ApplicationOnBoarding.hpp @@ -27,6 +27,7 @@ namespace app public: explicit ApplicationOnBoarding(std::string name = name_onboarding, std::string parent = {}, + sys::phone_modes::PhoneMode mode = sys::phone_modes::PhoneMode::Connected, StartInBackground startInBackground = {false}); sys::MessagePointer DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp) override; @@ -44,7 +45,7 @@ namespace app { static auto GetManifest() -> manager::ApplicationManifest { - return {{manager::actions::Launch}}; + return {{manager::actions::Launch, manager::actions::PhoneModeChanged}}; } }; } // namespace app diff --git a/module-apps/application-phonebook/ApplicationPhonebook.cpp b/module-apps/application-phonebook/ApplicationPhonebook.cpp index 24da8cbfa702ae510b1387544a8ec5663750f229..1f425e137ec7680f380418ef4e68bdd16f203176 100644 --- a/module-apps/application-phonebook/ApplicationPhonebook.cpp +++ b/module-apps/application-phonebook/ApplicationPhonebook.cpp @@ -21,8 +21,9 @@ namespace app { ApplicationPhonebook::ApplicationPhonebook(std::string name, std::string parent, + sys::phone_modes::PhoneMode mode, StartInBackground startInBackground) - : Application(name, parent, startInBackground, phonebook_stack_size) + : Application(name, parent, mode, startInBackground, phonebook_stack_size) { bus.channels.push_back(sys::BusChannel::ServiceDBNotifications); addActionReceiver(manager::actions::ShowContacts, [this](auto &&data) { diff --git a/module-apps/application-phonebook/ApplicationPhonebook.hpp b/module-apps/application-phonebook/ApplicationPhonebook.hpp index 05f91f0b4d88b8c22fbd0099293d0b8d4a45a5fd..eda817ecfb8bcda1531f5092d99c199a008f81c1 100644 --- a/module-apps/application-phonebook/ApplicationPhonebook.hpp +++ b/module-apps/application-phonebook/ApplicationPhonebook.hpp @@ -32,6 +32,7 @@ namespace app public: ApplicationPhonebook(std::string name = name_phonebook, std::string parent = {}, + sys::phone_modes::PhoneMode mode = sys::phone_modes::PhoneMode::Connected, StartInBackground startInBackground = {false}); ~ApplicationPhonebook() override = default; @@ -59,7 +60,8 @@ namespace app manager::actions::AddContact, manager::actions::EditContact, manager::actions::ShowContactDetails, - manager::actions::ShowEmergencyContacts}}; + manager::actions::ShowEmergencyContacts, + manager::actions::PhoneModeChanged}}; } }; } // namespace app diff --git a/module-apps/application-settings-new/ApplicationSettings.cpp b/module-apps/application-settings-new/ApplicationSettings.cpp index b0689d08ce4826c3179063a13a53a2661f5a4e88..10008dd8afacb7c7deeae9f7348002c604552690 100644 --- a/module-apps/application-settings-new/ApplicationSettings.cpp +++ b/module-apps/application-settings-new/ApplicationSettings.cpp @@ -96,8 +96,9 @@ namespace app ApplicationSettingsNew::ApplicationSettingsNew(std::string name, std::string parent, + sys::phone_modes::PhoneMode mode, StartInBackground startInBackground) - : Application(std::move(name), std::move(parent), startInBackground), AsyncCallbackReceiver{this} + : Application(std::move(name), std::move(parent), mode, startInBackground), AsyncCallbackReceiver{this} { if ((Store::GSM::SIM::SIM1 == selectedSim || Store::GSM::SIM::SIM2 == selectedSim) && Store::GSM::get()->sim == selectedSim) { @@ -537,8 +538,10 @@ namespace app windowsFactory.attach(gui::window::name::connection_frequency, [](Application *app, const std::string &name) { return std::make_unique(app, static_cast(app)); }); - attachPopups( - {gui::popup::ID::Volume, gui::popup::ID::TetheringPhoneModeChangeProhibited, gui::popup::ID::Tethering}); + attachPopups({gui::popup::ID::Volume, + gui::popup::ID::TetheringPhoneModeChangeProhibited, + gui::popup::ID::Tethering, + gui::popup::ID::PhoneModes}); } void ApplicationSettingsNew::destroyUserInterface() diff --git a/module-apps/application-settings-new/ApplicationSettings.hpp b/module-apps/application-settings-new/ApplicationSettings.hpp index 11e41f3674431e9d60bdd249e1f80c825d4eb7eb..4fa67acd65a0ddf14de08dddc32d63c472e6713d 100644 --- a/module-apps/application-settings-new/ApplicationSettings.hpp +++ b/module-apps/application-settings-new/ApplicationSettings.hpp @@ -180,6 +180,7 @@ namespace app public: explicit ApplicationSettingsNew(std::string name = name_settings_new, std::string parent = {}, + sys::phone_modes::PhoneMode mode = sys::phone_modes::PhoneMode::Connected, StartInBackground startInBackground = {false}); ~ApplicationSettingsNew() override; auto DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp) -> sys::MessagePointer override; @@ -256,7 +257,7 @@ namespace app { static auto GetManifest() -> manager::ApplicationManifest { - return {{manager::actions::Launch}}; + return {{manager::actions::Launch, manager::actions::PhoneModeChanged}}; } }; } /* namespace app */ diff --git a/module-apps/application-settings/ApplicationSettings.cpp b/module-apps/application-settings/ApplicationSettings.cpp index 5a51892cf410e53e79aa464c7d8ed5d27cf7ba12..604027ed0a5522a7ae4093aec80874f74e1c3832 100644 --- a/module-apps/application-settings/ApplicationSettings.cpp +++ b/module-apps/application-settings/ApplicationSettings.cpp @@ -41,8 +41,11 @@ namespace gui::window::name namespace app { - ApplicationSettings::ApplicationSettings(std::string name, std::string parent, StartInBackground startInBackground) - : Application(name, parent, startInBackground) + ApplicationSettings::ApplicationSettings(std::string name, + std::string parent, + sys::phone_modes::PhoneMode mode, + StartInBackground startInBackground) + : Application(name, parent, mode, startInBackground) { bus.channels.push_back(sys::BusChannel::AntennaNotifications); addActionReceiver(manager::actions::SelectSimCard, [this](auto &&data) { diff --git a/module-apps/application-settings/ApplicationSettings.hpp b/module-apps/application-settings/ApplicationSettings.hpp index 089af884173445e2ef1c51607f7c12d86aa9ba61..2b714cb7b5ce15a3628498fcbf09c26280e379dc 100644 --- a/module-apps/application-settings/ApplicationSettings.hpp +++ b/module-apps/application-settings/ApplicationSettings.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 #ifndef MODULE_APPS_APPLICATION_SETTINGS_APPLICATIONSETTINGS_HPP_ @@ -35,6 +35,7 @@ namespace app public: ApplicationSettings(std::string name = name_settings, std::string parent = {}, + sys::phone_modes::PhoneMode mode = sys::phone_modes::PhoneMode::Connected, StartInBackground startInBackground = {false}); virtual ~ApplicationSettings(); sys::MessagePointer DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp) override; @@ -64,7 +65,7 @@ namespace app { static auto GetManifest() -> manager::ApplicationManifest { - return {{manager::actions::Launch, manager::actions::SelectSimCard}}; + return {{manager::actions::Launch, manager::actions::SelectSimCard, manager::actions::PhoneModeChanged}}; } }; } /* namespace app */ diff --git a/module-apps/application-special-input/ApplicationSpecialInput.cpp b/module-apps/application-special-input/ApplicationSpecialInput.cpp index 4690e4c5041e61b5fe240d66bafce4a4ab76b3f8..0dbddacb71908286f8a4981b753d8583aa5fb150 100644 --- a/module-apps/application-special-input/ApplicationSpecialInput.cpp +++ b/module-apps/application-special-input/ApplicationSpecialInput.cpp @@ -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 #include "ApplicationSpecialInput.hpp" @@ -14,8 +14,9 @@ namespace ApplicationSpecialInput::ApplicationSpecialInput(std::string name, std::string parent, + sys::phone_modes::PhoneMode mode, StartInBackground startInBackground) - : Application(name, parent, startInBackground, SpecialInputAppStackDepth) + : Application(name, parent, mode, startInBackground, SpecialInputAppStackDepth) { addActionReceiver(manager::actions::ShowSpecialInput, [this](auto &&data) { switchWindow(app::char_select, std::move(data)); diff --git a/module-apps/application-special-input/ApplicationSpecialInput.hpp b/module-apps/application-special-input/ApplicationSpecialInput.hpp index f76256b92ed90a9f1ef8861bd543edc6303c4a26..d20eb3ce51df0e7633989f5e5b32e9b62a9df8c4 100644 --- a/module-apps/application-special-input/ApplicationSpecialInput.hpp +++ b/module-apps/application-special-input/ApplicationSpecialInput.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 @@ -21,6 +21,7 @@ namespace app ApplicationSpecialInput(std::string name = special_input, std::string parent = {}, + sys::phone_modes::PhoneMode mode = sys::phone_modes::PhoneMode::Connected, StartInBackground startInBackground = {true}); virtual ~ApplicationSpecialInput() = default; @@ -39,7 +40,7 @@ namespace app { static auto GetManifest() -> manager::ApplicationManifest { - return {{manager::actions::ShowSpecialInput}}; + return {{manager::actions::ShowSpecialInput, manager::actions::PhoneModeChanged}}; } }; }; // namespace app diff --git a/module-apps/popups/TetheringPhoneModePopup.cpp b/module-apps/popups/TetheringPhoneModePopup.cpp index 2e44d0d791216d8055fcefbf6c5f132743758071..af8341b51a6613e1e2775dfa2f0f033d3c976fbb 100644 --- a/module-apps/popups/TetheringPhoneModePopup.cpp +++ b/module-apps/popups/TetheringPhoneModePopup.cpp @@ -4,7 +4,7 @@ #include "TetheringPhoneModePopup.hpp" #include "DialogMetadataMessage.hpp" #include "Application.hpp" -#include "SystemManager/messages/TetheringPhoneModeChangeProhibitedMessage.hpp" +#include "data/PopupRequestParams.hpp" #include namespace gui @@ -20,7 +20,7 @@ namespace gui metadata.text = utils::translateI18("tethering_phone_mode_change_prohibited"); metadata.icon = "info_big_circle_W_G"; metadata.action = [this]() { - auto params = std::make_unique(gui::popup::ID::TetheringPhoneModeChangeProhibited); + auto params = std::make_unique(gui::popup::ID::TetheringPhoneModeChangeProhibited); app::manager::Controller::sendAction(application, app::manager::actions::AbortPopup, std::move(params)); return true; }; diff --git a/module-apps/popups/data/PhoneModeParams.hpp b/module-apps/popups/data/PhoneModeParams.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5814311b57c7753c33000a5cbf0b0403f8171526 --- /dev/null +++ b/module-apps/popups/data/PhoneModeParams.hpp @@ -0,0 +1,27 @@ +// 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 "popups/Popups.hpp" + +#include +#include + +namespace gui +{ + class PhoneModeParams : public app::manager::actions::ActionParams + { + public: + explicit PhoneModeParams(sys::phone_modes::PhoneMode mode) : phoneMode{mode} + {} + + [[nodiscard]] auto getPhoneMode() const noexcept + { + return phoneMode; + } + + private: + sys::phone_modes::PhoneMode phoneMode; + }; +} // namespace gui diff --git a/module-apps/popups/data/PopupRequestParams.hpp b/module-apps/popups/data/PopupRequestParams.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f7542e703f2385dc9dbabe69c788e7c1462bcede --- /dev/null +++ b/module-apps/popups/data/PopupRequestParams.hpp @@ -0,0 +1,44 @@ +// 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 "popups/Popups.hpp" + +#include +#include + +namespace gui +{ + class PopupRequestParams : public app::manager::actions::ActionParams + { + public: + explicit PopupRequestParams(gui::popup::ID popupId) + : app::manager::actions::ActionParams{"Popup request parameters"}, popupId{popupId} + {} + + [[nodiscard]] auto getPopupId() const noexcept + { + return popupId; + } + + private: + gui::popup::ID popupId; + }; + + class PhoneModePopupRequestParams : public PopupRequestParams + { + public: + explicit PhoneModePopupRequestParams(sys::phone_modes::PhoneMode mode) + : PopupRequestParams{gui::popup::ID::PhoneModes}, phoneMode{mode} + {} + + [[nodiscard]] auto getPhoneMode() const noexcept + { + return phoneMode; + } + + private: + sys::phone_modes::PhoneMode phoneMode; + }; +} // namespace gui diff --git a/module-services/service-antenna/ServiceAntenna.cpp b/module-services/service-antenna/ServiceAntenna.cpp index 1241ee04d49215ba51220293540bfbffa398b157..dc0e589eee564e12541fdfc4e6bcfe2a6d424036 100644 --- a/module-services/service-antenna/ServiceAntenna.cpp +++ b/module-services/service-antenna/ServiceAntenna.cpp @@ -78,15 +78,14 @@ ServiceAntenna::ServiceAntenna() bus.channels.push_back(sys::BusChannel::PhoneModeChanges); phoneModeObserver->connect(this); - phoneModeObserver->subscribe( - [=]([[maybe_unused]] sys::phone_modes::PhoneMode mode, sys::phone_modes::Tethering tethering) { - if (mode == sys::phone_modes::PhoneMode::Offline) { - this->handleLockRequest(antenna::lockState::locked); - } - else { - this->handleLockRequest(antenna::lockState::unlocked); - } - }); + phoneModeObserver->subscribe([this](sys::phone_modes::PhoneMode mode) { + if (mode == sys::phone_modes::PhoneMode::Offline) { + handleLockRequest(antenna::lockState::locked); + } + else { + handleLockRequest(antenna::lockState::unlocked); + } + }); } ServiceAntenna::~ServiceAntenna() diff --git a/module-services/service-appmgr/model/ApplicationHandle.cpp b/module-services/service-appmgr/model/ApplicationHandle.cpp index 8479a06b42c06f3d2035722be2fb33ccaf8b73d8..973ae37804cef04bcaca6414e5dada52b2399366 100644 --- a/module-services/service-appmgr/model/ApplicationHandle.cpp +++ b/module-services/service-appmgr/model/ApplicationHandle.cpp @@ -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 #include @@ -58,14 +58,14 @@ namespace app::manager return manifest.contains(action); } - void ApplicationHandle::run(sys::Service *caller) + void ApplicationHandle::run(sys::phone_modes::PhoneMode mode, sys::Service *caller) { - launcher->run(caller); + launcher->run(mode, caller); } - void ApplicationHandle::runInBackground(sys::Service *caller) + void ApplicationHandle::runInBackground(sys::phone_modes::PhoneMode mode, sys::Service *caller) { - launcher->runBackground(caller); + launcher->runBackground(mode, caller); } void ApplicationHandle::close() noexcept diff --git a/module-services/service-appmgr/model/ApplicationManager.cpp b/module-services/service-appmgr/model/ApplicationManager.cpp index cba4dfaef2faf03a65f00883fb522a6255fad72a..9bf3a3dbbf69afa86d3dedd50279c59ed894faeb 100644 --- a/module-services/service-appmgr/model/ApplicationManager.cpp +++ b/module-services/service-appmgr/model/ApplicationManager.cpp @@ -5,6 +5,8 @@ #include #include +#include +#include #include #include #include @@ -103,6 +105,26 @@ namespace app::manager return applications.findByName(name); } + auto ApplicationManagerBase::getRunningApplications() noexcept -> std::vector + { + const auto &stackOfUniqueApps = getStackOfUniqueApplications(); + std::vector runningApps; + std::transform(stackOfUniqueApps.begin(), + stackOfUniqueApps.end(), + std::back_inserter(runningApps), + [this](const auto &appName) { return getApplication(appName); }); + return runningApps; + } + + auto ApplicationManagerBase::getStackOfUniqueApplications() const -> ApplicationsStack + { + auto stackOfUniqueApps = stack; + std::sort(stackOfUniqueApps.begin(), stackOfUniqueApps.end()); + const auto last = std::unique(stackOfUniqueApps.begin(), stackOfUniqueApps.end()); + stackOfUniqueApps.erase(last, stackOfUniqueApps.end()); + return stackOfUniqueApps; + } + ApplicationManager::ApplicationManager(const ApplicationName &serviceName, std::vector> &&launchers, const ApplicationName &_rootApplicationName) @@ -198,7 +220,7 @@ namespace app::manager { for (const auto &name : std::vector{app::name_call, app::special_input}) { if (auto app = getApplication(name); app != nullptr) { - app->runInBackground(this); + app->runInBackground(phoneModeObserver->getCurrentPhoneMode(), this); } } } @@ -237,10 +259,11 @@ namespace app::manager void ApplicationManager::registerMessageHandlers() { phoneModeObserver->connect(this); - phoneModeObserver->subscribe( - [](sys::phone_modes::PhoneMode phoneMode, sys::phone_modes::Tethering tetheringMode) { - LOG_INFO("Phone mode changed."); - }); + phoneModeObserver->subscribe([this](sys::phone_modes::PhoneMode phoneMode) { + handlePhoneModeChanged(phoneMode); + actionsRegistry.enqueue( + ActionEntry{actions::ShowPopup, std::make_unique(phoneMode)}); + }); connect(typeid(StartAllowedMessage), [this](sys::Message *request) { auto msg = static_cast(request); @@ -398,7 +421,7 @@ namespace app::manager } else { LOG_INFO("Starting application %s", app.name().c_str()); - app.run(this); + app.run(phoneModeObserver->getCurrentPhoneMode(), this); } return true; } @@ -515,6 +538,20 @@ namespace app::manager actionsRegistry.enqueue(std::move(entry)); } + void ApplicationManager::handlePhoneModeChanged(sys::phone_modes::PhoneMode phoneMode) + { + for (const auto app : getRunningApplications()) { + changePhoneMode(phoneMode, app); + } + } + + void ApplicationManager::changePhoneMode(sys::phone_modes::PhoneMode phoneMode, const ApplicationHandle *app) + { + ActionEntry action{actions::PhoneModeChanged, std::make_unique(phoneMode)}; + action.setTargetApplication(app->name()); + actionsRegistry.enqueue(std::move(action)); + } + ActionProcessStatus ApplicationManager::handleAction(ActionEntry &action) { switch (action.actionId) { @@ -522,6 +559,8 @@ namespace app::manager return handleHomeAction(action); case actions::Launch: return handleLaunchAction(action); + case actions::PhoneModeChanged: + return handlePhoneModeChangedAction(action); case actions::ShowPopup: [[fallthrough]]; case actions::AbortPopup: @@ -551,6 +590,22 @@ namespace app::manager return handleSwitchApplication(&switchRequest) ? ActionProcessStatus::Accepted : ActionProcessStatus::Dropped; } + auto ApplicationManager::handlePhoneModeChangedAction(ActionEntry &action) -> ActionProcessStatus + { + const auto &targetName = action.target; + auto targetApp = getApplication(targetName); + if (targetApp == nullptr || !targetApp->handles(action.actionId)) { + return ActionProcessStatus::Dropped; + } + + if (targetApp->state() == ApplicationHandle::State::ACTIVE_FORGROUND || + targetApp->state() == ApplicationHandle::State::ACTIVE_BACKGROUND) { + app::Application::requestAction(this, targetName, action.actionId, std::move(action.params)); + return ActionProcessStatus::Accepted; + } + return ActionProcessStatus::Skipped; + } + auto ApplicationManager::handlePopupAction(ActionEntry &action) -> ActionProcessStatus { auto targetApp = getFocusedApplication(); diff --git a/module-services/service-appmgr/service-appmgr/Actions.hpp b/module-services/service-appmgr/service-appmgr/Actions.hpp index 82cb68e0eec4738a082d602a64faff6222b8ed34..f9c817fb002e713e4b13ad16f9c9d62bafa75c45 100644 --- a/module-services/service-appmgr/service-appmgr/Actions.hpp +++ b/module-services/service-appmgr/service-appmgr/Actions.hpp @@ -60,6 +60,7 @@ namespace app::manager DisplayLogoAtExit, SMSRejectedByOfflineNotification, CallRejectedByOfflineNotification, + PhoneModeChanged, ShowPopup, AbortPopup, UserAction // The last enumerator in the Action enum. diff --git a/module-services/service-appmgr/service-appmgr/model/ApplicationHandle.hpp b/module-services/service-appmgr/service-appmgr/model/ApplicationHandle.hpp index 4d5bdeb75bf21dac663c17dcd11c07bdfe3a5b2c..4a30aa5eb41054ffd780d35da18b16b9ddece038 100644 --- a/module-services/service-appmgr/service-appmgr/model/ApplicationHandle.hpp +++ b/module-services/service-appmgr/service-appmgr/model/ApplicationHandle.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 @@ -24,8 +24,8 @@ namespace app::manager explicit ApplicationHandle(std::unique_ptr &&_launcher); void setState(State state) noexcept; - void run(sys::Service *caller); - void runInBackground(sys::Service *caller); + void run(sys::phone_modes::PhoneMode mode, sys::Service *caller); + void runInBackground(sys::phone_modes::PhoneMode mode, sys::Service *caller); void close() noexcept; auto valid() const noexcept -> bool; diff --git a/module-services/service-appmgr/service-appmgr/model/ApplicationManager.hpp b/module-services/service-appmgr/service-appmgr/model/ApplicationManager.hpp index 96ff1369da1262c81a5d8848d55e79288e6d6cd4..4f0819171b60753532f0b935a01533f1cd90a899 100644 --- a/module-services/service-appmgr/service-appmgr/model/ApplicationManager.hpp +++ b/module-services/service-appmgr/service-appmgr/model/ApplicationManager.hpp @@ -68,6 +68,7 @@ namespace app::manager auto getLaunchingApplication() const noexcept -> ApplicationHandle *; auto getPreviousApplication() const noexcept -> ApplicationHandle *; auto getApplication(const ApplicationName &name) const noexcept -> ApplicationHandle *; + auto getRunningApplications() noexcept -> std::vector; auto getApplications() const noexcept -> const ApplicationsContainer & { return applications.getAll(); @@ -85,6 +86,8 @@ namespace app::manager private: using ApplicationsStack = std::deque; + auto getStackOfUniqueApplications() const -> ApplicationsStack; + State state = State::Running; ApplicationsStack stack; }; @@ -120,6 +123,9 @@ namespace app::manager auto handleHomeAction(ActionEntry &action) -> ActionProcessStatus; auto handleLaunchAction(ActionEntry &action) -> ActionProcessStatus; auto handlePopupAction(ActionEntry &action) -> ActionProcessStatus; + auto handlePhoneModeChangedAction(ActionEntry &action) -> ActionProcessStatus; + void handlePhoneModeChanged(sys::phone_modes::PhoneMode phoneMode); + void changePhoneMode(sys::phone_modes::PhoneMode phoneMode, const ApplicationHandle *app); auto handleCustomAction(ActionEntry &action) -> ActionProcessStatus; auto handleSwitchApplication(SwitchRequest *msg, bool closeCurrentlyFocusedApp = true) -> bool; auto handleCloseConfirmation(CloseConfirmation *msg) -> bool; diff --git a/module-services/service-audio/ServiceAudio.cpp b/module-services/service-audio/ServiceAudio.cpp index ee67fe6f55bfc029b67cb7aebfbcdc548843d8ad..28fa04ef8bcc0329f0e28f1f4d1d46ab6495ef1f 100644 --- a/module-services/service-audio/ServiceAudio.cpp +++ b/module-services/service-audio/ServiceAudio.cpp @@ -165,9 +165,7 @@ ServiceAudio::ServiceAudio() bus.channels.push_back(sys::BusChannel::PhoneModeChanges); phoneModeObserver->connect(this); - phoneModeObserver->subscribe([&](sys::phone_modes::PhoneMode phoneMode, sys::phone_modes::Tethering tetheringMode) { - HandlePhoneModeChange(phoneMode, tetheringMode); - }); + phoneModeObserver->subscribe([&](sys::phone_modes::PhoneMode phoneMode) { HandlePhoneModeChange(phoneMode); }); connect(typeid(BluetoothDeviceVolumeChanged), [this](sys::Message *msg) -> sys::MessagePointer { return handleVolumeChangedOnBluetoothDevice(msg); }); @@ -546,8 +544,7 @@ auto ServiceAudio::HandleKeyPressed(const int step) -> std::unique_ptr std::unique_ptr; void HandleNotification(const AudioNotificationMessage::Type &type, const audio::Token &token); auto HandleKeyPressed(const int step) -> std::unique_ptr; - void HandlePhoneModeChange(sys::phone_modes::PhoneMode phoneMode, sys::phone_modes::Tethering tetheringMode); + void HandlePhoneModeChange(sys::phone_modes::PhoneMode phoneMode); void MuteCurrentOperation(); void VibrationUpdate(const audio::PlaybackType &type = audio::PlaybackType::None, std::optional input = std::nullopt); diff --git a/module-services/service-cellular/ServiceCellular.cpp b/module-services/service-cellular/ServiceCellular.cpp index 5f57846f8f45a52a2dedea19ec38a3936f310d3a..4ccc9d8442c4d30e9b2e36bd128839762c5deb20 100644 --- a/module-services/service-cellular/ServiceCellular.cpp +++ b/module-services/service-cellular/ServiceCellular.cpp @@ -326,22 +326,22 @@ void handleCellularSimNewPinDataMessage(CellularSimNewPinDataMessage *msg) void ServiceCellular::registerMessageHandlers() { phoneModeObserver->connect(this); - phoneModeObserver->subscribe( - [=]([[maybe_unused]] sys::phone_modes::PhoneMode mode, sys::phone_modes::Tethering tethering) { - using bsp::cellular::USB::setPassthrough; - using bsp::cellular::USB::PassthroughState; - setPassthrough(tethering == sys::phone_modes::Tethering::On ? PassthroughState::ENABLED - : PassthroughState::DISABLED); - - if (mode == sys::phone_modes::PhoneMode::Offline) { - this->switchToOffline(); - } - else { - if (!this->isModemRadioModuleOn()) { - this->turnOnRadioModule(); - } + phoneModeObserver->subscribe([this](sys::phone_modes::PhoneMode mode) { + if (mode == sys::phone_modes::PhoneMode::Offline) { + this->switchToOffline(); + } + else { + if (!this->isModemRadioModuleOn()) { + this->turnOnRadioModule(); } - }); + } + }); + phoneModeObserver->subscribe([](sys::phone_modes::Tethering tethering) { + using bsp::cellular::USB::setPassthrough; + using bsp::cellular::USB::PassthroughState; + setPassthrough(tethering == sys::phone_modes::Tethering::On ? PassthroughState::ENABLED + : PassthroughState::DISABLED); + }); connect(typeid(CellularSimCardPinLockStateRequestDataMessage), [&](sys::Message * /*request*/) -> sys::MessagePointer { diff --git a/module-sys/PhoneModes/Common.hpp b/module-sys/PhoneModes/Common.hpp index e6ce860930945f48700dc8db31a14762fd912357..a43e5f22e3a3c778f93ae89a2726c5ed2211e6a9 100644 --- a/module-sys/PhoneModes/Common.hpp +++ b/module-sys/PhoneModes/Common.hpp @@ -23,27 +23,38 @@ namespace sys::phone_modes class PhoneModeChanged : public DataMessage { public: - PhoneModeChanged(PhoneMode phoneMode, Tethering tetheringMode) - : DataMessage{MessageType::MessageTypeUninitialized}, phoneMode{phoneMode}, tethering{tetheringMode} + explicit PhoneModeChanged(PhoneMode phoneMode) + : DataMessage{MessageType::MessageTypeUninitialized}, phoneMode{phoneMode} {} [[nodiscard]] auto getPhoneMode() const noexcept { return phoneMode; } + + private: + PhoneMode phoneMode; + }; + + class TetheringChanged : public DataMessage + { + public: + explicit TetheringChanged(Tethering tetheringMode) + : DataMessage{MessageType::MessageTypeUninitialized}, tethering{tetheringMode} + {} + [[nodiscard]] auto getTetheringMode() const noexcept { return tethering; } private: - PhoneMode phoneMode; Tethering tethering; }; - class PhoneModeChangedSuccessfully : public ResponseMessage + class ChangedSuccessfully : public ResponseMessage {}; - class PhoneModeChangeFailed : public ResponseMessage + class ChangeFailed : public ResponseMessage {}; } // namespace sys::phone_modes diff --git a/module-sys/PhoneModes/Observer.cpp b/module-sys/PhoneModes/Observer.cpp index 8f6006cd2c9f6008b26f4427a9f18eaa648bd0d7..6a3d5d7d50f5ee3eed62362f37ae0f37a553f04d 100644 --- a/module-sys/PhoneModes/Observer.cpp +++ b/module-sys/PhoneModes/Observer.cpp @@ -7,20 +7,51 @@ namespace sys::phone_modes { + namespace + { + template void onChanged(const F &onChanged, const Observer::OnFinishedCallbacks &onFinished) + { + try { + onChanged(); + if (onFinished.onComplete) { + onFinished.onComplete(); + } + } + catch (const std::exception &error) { + if (onFinished.onError) { + onFinished.onError(error); + } + throw; + } + } + } // namespace + void Observer::connect(Service *owner) { owner->connect(typeid(PhoneModeChanged), [this](sys::Message *request) -> sys::MessagePointer { return handlePhoneModeChange(static_cast(request)); }); + owner->connect(typeid(TetheringChanged), [this](sys::Message *request) -> sys::MessagePointer { + return handleTetheringChange(static_cast(request)); + }); + } + + void Observer::subscribe(OnPhoneModeChangedCallback &&onChange, + OnCompleteCallback &&onComplete, + OnErrorCallback &&onError) noexcept + { + onPhoneModeChangedCallback = std::move(onChange); + onPhoneModeChangeFinished.onComplete = std::move(onComplete); + onPhoneModeChangeFinished.onError = std::move(onError); } - void Observer::subscribe(OnChangeCallback &&onChange, + void Observer::subscribe(OnTetheringChangedCallback &&onChange, OnCompleteCallback &&onComplete, OnErrorCallback &&onError) noexcept { - onChangeCallback = std::move(onChange); - onCompleteCallback = std::move(onComplete); - onErrorCallback = std::move(onError); + onTetheringChangedCallback = std::move(onChange); + onTetheringChangeFinished.onComplete = std::move(onComplete); + onTetheringChangeFinished.onError = std::move(onError); } bool Observer::isInMode(PhoneMode mode) const noexcept @@ -41,35 +72,34 @@ namespace sys::phone_modes sys::MessagePointer Observer::handlePhoneModeChange(PhoneModeChanged *message) { phoneMode = message->getPhoneMode(); - tetheringMode = message->getTetheringMode(); + if (!onPhoneModeChangedCallback) { + LOG_WARN("No subscriber on phone mode change."); + return MessageNone{}; + } try { - onPhoneModeChanged(); + onChanged([this]() { onPhoneModeChangedCallback(phoneMode); }, onPhoneModeChangeFinished); } catch (const std::exception &) { - return std::make_shared(); + return std::make_shared(); } - return std::make_shared(); + return std::make_shared(); } - void Observer::onPhoneModeChanged() + sys::MessagePointer Observer::handleTetheringChange(TetheringChanged *message) { - if (!onChangeCallback) { + tetheringMode = message->getTetheringMode(); + if (!onTetheringChangedCallback) { LOG_WARN("No subscriber on phone mode change."); - return; + return MessageNone{}; } try { - onChangeCallback(phoneMode, tetheringMode); - if (onCompleteCallback) { - onCompleteCallback(); - } + onChanged([this]() { onTetheringChangedCallback(tetheringMode); }, onTetheringChangeFinished); } - catch (const std::exception &error) { - if (onErrorCallback) { - onErrorCallback(error); - } - throw; + catch (const std::exception &) { + return std::make_shared(); } + return std::make_shared(); } } // namespace sys::phone_modes diff --git a/module-sys/PhoneModes/Observer.hpp b/module-sys/PhoneModes/Observer.hpp index 9af6b9ec62d33dd4743f95eb604d703cbe707a99..d6c022df6aeefc76d3a0e133bf05f409c65e1956 100644 --- a/module-sys/PhoneModes/Observer.hpp +++ b/module-sys/PhoneModes/Observer.hpp @@ -18,12 +18,21 @@ namespace sys::phone_modes class Observer { public: - using OnChangeCallback = std::function; + using OnPhoneModeChangedCallback = std::function; + using OnTetheringChangedCallback = std::function; using OnCompleteCallback = std::function; using OnErrorCallback = std::function; + struct OnFinishedCallbacks + { + OnCompleteCallback onComplete; + OnErrorCallback onError; + }; void connect(Service *owner); - void subscribe(OnChangeCallback &&onChange, + void subscribe(OnPhoneModeChangedCallback &&onChange, + OnCompleteCallback &&onComplete = {}, + OnErrorCallback &&onError = {}) noexcept; + void subscribe(OnTetheringChangedCallback &&onChange, OnCompleteCallback &&onComplete = {}, OnErrorCallback &&onError = {}) noexcept; @@ -33,11 +42,12 @@ namespace sys::phone_modes private: sys::MessagePointer handlePhoneModeChange(PhoneModeChanged *message); - void onPhoneModeChanged(); + sys::MessagePointer handleTetheringChange(TetheringChanged *message); - OnChangeCallback onChangeCallback; - OnCompleteCallback onCompleteCallback; - OnErrorCallback onErrorCallback; + OnPhoneModeChangedCallback onPhoneModeChangedCallback; + OnTetheringChangedCallback onTetheringChangedCallback; + OnFinishedCallbacks onPhoneModeChangeFinished; + OnFinishedCallbacks onTetheringChangeFinished; PhoneMode phoneMode = PhoneMode::Connected; Tethering tetheringMode = Tethering::Off; }; diff --git a/module-sys/PhoneModes/Subject.cpp b/module-sys/PhoneModes/Subject.cpp index 931719aada60e26301aa2442541caa6bda986f56..9ff5410511d7e3fe0f0bb302494c9861b5d05dae 100644 --- a/module-sys/PhoneModes/Subject.cpp +++ b/module-sys/PhoneModes/Subject.cpp @@ -21,18 +21,22 @@ namespace sys::phone_modes bool Subject::setMode(PhoneMode _phoneMode, Tethering _tetheringMode) { - const bool changed = changePhoneMode(_phoneMode) || changeTetheringMode(_tetheringMode); - if (changed) { - notifyChange(); + const bool phoneModeChanged = changePhoneMode(_phoneMode); + if (phoneModeChanged) { + notifyPhoneModeChange(); } - return changed; + const bool tetheringChanged = changeTetheringMode(_tetheringMode); + if (tetheringChanged) { + notifyTetheringChange(); + } + return phoneModeChanged || tetheringChanged; } bool Subject::setPhoneMode(PhoneMode mode) { const auto changed = changePhoneMode(mode); if (changed) { - notifyChange(); + notifyPhoneModeChange(); } return changed; } @@ -46,7 +50,7 @@ namespace sys::phone_modes { const auto changed = changeTetheringMode(mode); if (changed) { - notifyChange(); + notifyTetheringChange(); } return changed; } @@ -56,13 +60,18 @@ namespace sys::phone_modes return std::exchange(tetheringMode, mode) != mode; } - void Subject::notifyChange() + void Subject::notifyPhoneModeChange() + { + LOG_INFO("Phone mode changed to: [%s]. Notifying phone modes observers.", + magic_enum::enum_name(phoneMode).data()); + owner->bus.sendMulticast(std::make_shared(phoneMode), BusChannel::PhoneModeChanges); + } + + void Subject::notifyTetheringChange() { - LOG_INFO("Phone modes changed: Phone mode: [%s]; Tethering: [%s]. Notifying phone modes observers.", - magic_enum::enum_name(phoneMode).data(), + LOG_INFO("Tethering mode changed to: [%s]. Notifying phone modes observers.", magic_enum::enum_name(tetheringMode).data()); - auto message = std::make_shared(phoneMode, tetheringMode); - owner->bus.sendMulticast(std::move(message), BusChannel::PhoneModeChanges); + owner->bus.sendMulticast(std::make_shared(tetheringMode), BusChannel::PhoneModeChanges); } bool Subject::isTetheringEnabled() const noexcept { diff --git a/module-sys/PhoneModes/Subject.hpp b/module-sys/PhoneModes/Subject.hpp index 9e65a3751d1000d0e2430d38efb5ddd855872523..d7236bc82517cf90604102110af4300be3c500f2 100644 --- a/module-sys/PhoneModes/Subject.hpp +++ b/module-sys/PhoneModes/Subject.hpp @@ -42,9 +42,10 @@ namespace sys::phone_modes bool isTetheringEnabled() const noexcept; private: - void notifyChange(); bool changePhoneMode(PhoneMode mode) noexcept; + void notifyPhoneModeChange(); bool changeTetheringMode(Tethering mode) noexcept; + void notifyTetheringChange(); Service *owner; PhoneMode phoneMode = PhoneMode::Connected; diff --git a/module-sys/SystemManager/messages/TetheringPhoneModeChangeProhibitedMessage.hpp b/module-sys/SystemManager/messages/TetheringPhoneModeChangeProhibitedMessage.hpp index 249e6d159889a814beb79e6bbfc358f12ac9406c..6e62004809ab0810bc9ec452999ff82f7afba80a 100644 --- a/module-sys/SystemManager/messages/TetheringPhoneModeChangeProhibitedMessage.hpp +++ b/module-sys/SystemManager/messages/TetheringPhoneModeChangeProhibitedMessage.hpp @@ -19,7 +19,7 @@ namespace sys std::unique_ptr toAction() const override { - auto params = std::make_unique(gui::popup::ID::TetheringPhoneModeChangeProhibited); + auto params = std::make_unique(gui::popup::ID::TetheringPhoneModeChangeProhibited); return std::make_unique( sender, app::manager::actions::ShowPopup, std::move(params)); } diff --git a/module-sys/SystemManager/messages/TetheringQuestionRequest.hpp b/module-sys/SystemManager/messages/TetheringQuestionRequest.hpp index 87afa944097bdd2fb8214b96b72430f0b9c1885a..872b137e22bc011330d88947cac44150270d4407 100644 --- a/module-sys/SystemManager/messages/TetheringQuestionRequest.hpp +++ b/module-sys/SystemManager/messages/TetheringQuestionRequest.hpp @@ -5,6 +5,8 @@ #include +#include + #include #include @@ -18,7 +20,7 @@ namespace sys std::unique_ptr toAction() const override { - auto params = std::make_unique(gui::popup::ID::Tethering); + auto params = std::make_unique(gui::popup::ID::Tethering); return std::make_unique( sender, app::manager::actions::ShowPopup, std::move(params)); } @@ -32,7 +34,7 @@ namespace sys std::unique_ptr toAction() const override { - auto params = std::make_unique(gui::popup::ID::Tethering); + auto params = std::make_unique(gui::popup::ID::Tethering); return std::make_unique( sender, app::manager::actions::AbortPopup, std::move(params)); }