~aleteoryx/muditaos

d68458f1b25c0607a90ee2b8faa9f700ee29640a — Mateusz Grzegorzek 4 years ago aaa41bf
[BH-740] Split ApplicationManager

- move `LowBattery` handling to Pure `ApplicationManager`,
- cleanup `ApplicationManagerCommon`
M module-services/service-appmgr/CMakeLists.txt => module-services/service-appmgr/CMakeLists.txt +0 -1
@@ 70,7 70,6 @@ target_sources(service-appmgr

target_link_libraries(service-appmgr
    PRIVATE
        application-desktop
        application-special-input
        json::json
        module-audio

M module-services/service-appmgr/include/service-appmgr/model/ActionsRegistry.hpp => module-services/service-appmgr/include/service-appmgr/model/ActionsRegistry.hpp +1 -2
@@ 42,8 42,7 @@ namespace app::manager
    {
        Accepted,
        Skipped,
        Dropped,
        NotHandled
        Dropped
    };

    class ActionsRegistry

M module-services/service-appmgr/include/service-appmgr/model/ApplicationManagerCommon.hpp => module-services/service-appmgr/include/service-appmgr/model/ApplicationManagerCommon.hpp +2 -15
@@ 13,13 13,10 @@
#include <apps-common/Application.hpp>
#include <apps-common/ApplicationLauncher.hpp>

#include <bsp/keypad_backlight/keypad_backlight.hpp>
#include <Service/Common.hpp>
#include <Service/Message.hpp>
#include <Service/Service.hpp>
#include <Timers/TimerHandle.hpp>
#include <PhoneModes/Observer.hpp>
#include <SwitchData.hpp>

#include <deque>
#include <memory>


@@ 33,8 30,6 @@
#include <service-eink/Common.hpp>

#include <notifications/NotificationProvider.hpp>
#include <apps-common/locks/handlers/PhoneLockHandler.hpp>
#include <apps-common/locks/handlers/SimLockHandler.hpp>
#include <apps-common/notifications/NotificationsHandler.hpp>
#include <apps-common/notifications/NotificationsConfiguration.hpp>



@@ 43,13 38,6 @@ namespace app
    class ApplicationLauncher;
    namespace manager
    {
        class APMAction;
        class APMChangeLanguage;
        class APMConfirmClose;
        class APMConfirmSwitch;
        class APMRegister;
        class APMSwitch;
        class APMSwitchPrevApp;
        class GetAutoLockTimeoutRequest;
        class SetAutoLockTimeoutRequest;
    } // namespace manager


@@ 120,6 108,8 @@ namespace app::manager
        }
        auto checkOnBoarding() -> bool;
        virtual void registerMessageHandlers();
        auto handleSwitchApplication(SwitchRequest *msg, bool closeCurrentlyFocusedApp = true) -> bool;
        virtual void handleStart(StartAllowedMessage *msg);

        ApplicationName rootApplicationName;
        ActionsRegistry actionsRegistry;


@@ 130,7 120,6 @@ namespace app::manager
        void suspendSystemServices();
        void closeNoLongerNeededApplications();
        auto closeApplications() -> bool;
        auto closeApplicationsOnUpdate() -> bool;
        void closeApplication(ApplicationHandle *application);

        // Message handlers


@@ 141,7 130,6 @@ namespace app::manager
        auto handleActionOnFocusedApp(ActionEntry &action) -> ActionProcessStatus;
        auto handleCustomAction(ActionEntry &action) -> ActionProcessStatus;
        auto handleCustomActionOnBackgroundApp(ApplicationHandle *app, ActionEntry &action) -> ActionProcessStatus;
        auto handleSwitchApplication(SwitchRequest *msg, bool closeCurrentlyFocusedApp = true) -> bool;
        auto handleCloseConfirmation(CloseConfirmation *msg) -> bool;
        auto handleSwitchConfirmation(SwitchConfirmation *msg) -> bool;
        auto handleSwitchBack(SwitchBackRequest *msg) -> bool;


@@ 152,7 140,6 @@ namespace app::manager
        virtual auto handleDeveloperModeRequest(sys::Message *request) -> sys::MessagePointer;
        /// handles dom request by passing this request to application which should provide the dom
        auto handleDOMRequest(sys::Message *request) -> std::shared_ptr<sys::ResponseMessage>;
        void handleStart(StartAllowedMessage *msg);

        void requestApplicationClose(ApplicationHandle &app, bool isCloseable);
        void onApplicationSwitch(ApplicationHandle &nextApp,

M module-services/service-appmgr/model/ActionsRegistry.cpp => module-services/service-appmgr/model/ActionsRegistry.cpp +0 -2
@@ 84,8 84,6 @@ namespace app::manager
                it = actions.erase(it);
                break;
            }
            case ActionProcessStatus::NotHandled:
                [[fallthrough]];
            case ActionProcessStatus::Skipped:
                // Skip the action and check the next one.
                ++it;

M module-services/service-appmgr/model/ApplicationManagerCommon.cpp => module-services/service-appmgr/model/ApplicationManagerCommon.cpp +2 -54
@@ 3,43 3,25 @@

#include "ApplicationManagerCommon.hpp"
#include "ApplicationStatus.hpp"
#include "AutoLockRequests.hpp"
#include "Controller.hpp"
#include "DOMRequest.hpp"
#include "FinishRequest.hpp"
#include "GetAllNotificationsRequest.hpp"
#include "Message.hpp"

#include <Common.hpp>
#include <Service/Message.hpp>
#include <SystemManager/SystemManagerCommon.hpp>
#include <SystemManager/messages/SystemManagerMessage.hpp>
#include <SystemManager/messages/TetheringPhoneModeChangeProhibitedMessage.hpp>
#include <SystemManager/messages/TetheringQuestionRequest.hpp>
#include <application-desktop/ApplicationDesktop.hpp>
#include <application-onboarding/ApplicationOnBoarding.hpp>
#include <application-onboarding/data/OnBoardingMessages.hpp>
#include <application-special-input/ApplicationSpecialInput.hpp>
#include <apps-common/messages/AppMessage.hpp>
#include <apps-common/popups/data/PhoneModeParams.hpp>
#include <apps-common/popups/data/PopupRequestParams.hpp>
#include <event-manager-api>
#include <i18n/i18n.hpp>
#include <log/log.hpp>
#include <module-db/queries/notifications/QueryNotificationsGetAll.hpp>
#include <service-audio/AudioMessage.hpp>
#include <service-db/agents/settings/SystemSettings.hpp>
#include <module-sys/Timers/TimerFactory.hpp>
#include <module-utils/Utils.hpp>
#include <service-appmgr/Constants.hpp>
#include <service-appmgr/StartupType.hpp>
#include <service-cellular-api>
#include <service-cellular/CellularMessage.hpp>
#include <service-db/DBNotificationMessage.hpp>
#include <service-desktop/Constants.hpp>
#include <service-desktop/DesktopMessages.hpp>
#include <service-eink/ServiceEink.hpp>
#include <service-evtmgr/EVMessages.hpp>
#include <service-evtmgr/EventManagerCommon.hpp>

#include <algorithm>


@@ 151,23 133,8 @@ namespace app::manager

    void ApplicationManagerCommon::handleStart(StartAllowedMessage *msg)
    {
        switch (msg->getStartupType()) {
        case StartupType::Regular:
            if (auto app = getApplication(rootApplicationName); app != nullptr) {
                Controller::sendAction(this, actions::Home);
            }
            break;
        case StartupType::LowBattery:
            handleSwitchApplication(std::make_unique<SwitchRequest>(
                                        service::name::appmgr, app::name_desktop, window::name::dead_battery, nullptr)
                                        .get());
            break;
        case StartupType::LowBatteryCharging:
            handleSwitchApplication(
                std::make_unique<SwitchRequest>(
                    service::name::appmgr, app::name_desktop, window::name::charging_battery, nullptr)
                    .get());
            break;
        if (auto app = getApplication(rootApplicationName); app != nullptr) {
            Controller::sendAction(this, actions::Home);
        }
    }



@@ 353,23 320,6 @@ namespace app::manager
        }
    }

    auto ApplicationManagerCommon::closeApplicationsOnUpdate() -> bool
    {
        for (const auto &app : getApplications()) {
            if (app->started()) {
                auto appName = app->name();
                if (appName == app::name_desktop) {
                    LOG_DEBUG("Delay closing %s", app::name_desktop);
                    continue;
                }
                LOG_INFO("Closing application on Update %s", appName.c_str());
                closeApplication(app.get());
                app->setState(ApplicationHandle::State::DEACTIVATED);
            }
        }
        return true;
    }

    void ApplicationManagerCommon::closeApplication(ApplicationHandle *application)
    {
        if (application == nullptr) {


@@ 468,8 418,6 @@ namespace app::manager
            return handleHomeAction(action);
        case actions::Launch:
            return handleLaunchAction(action);
        case actions::PhoneModeChanged:
            return ActionProcessStatus::NotHandled;
        case actions::ShowPopup:
            [[fallthrough]];
        case actions::AbortPopup:

M products/PurePhone/services/appmgr/ApplicationManager.cpp => products/PurePhone/services/appmgr/ApplicationManager.cpp +28 -10
@@ 3,6 3,7 @@

#include <appmgr/ApplicationManager.hpp>

#include <application-desktop/ApplicationDesktop.hpp>
#include <application-onboarding/ApplicationOnBoarding.hpp>
#include <application-onboarding/data/OnBoardingMessages.hpp>
#include <application-special-input/ApplicationSpecialInput.hpp>


@@ 12,17 13,18 @@
#include <module-sys/SystemManager/messages/TetheringPhoneModeChangeProhibitedMessage.hpp>
#include <module-sys/SystemManager/messages/TetheringQuestionRequest.hpp>
#include <module-sys/Timers/TimerFactory.hpp>
#include <service-appmgr/include/service-appmgr/messages/AutoLockRequests.hpp>
#include <service-appmgr/Constants.hpp>
#include <service-appmgr/messages/AutoLockRequests.hpp>
#include <service-appmgr/messages/GetAllNotificationsRequest.hpp>
#include <service-cellular/service-cellular/CellularMessage.hpp>
#include <service-db/agents/settings/SystemSettings.hpp>
#include <service-cellular/CellularMessage.hpp>
#include <service-db/DBNotificationMessage.hpp>
#include <service-db/agents/settings/SystemSettings.hpp>
#include <service-desktop/Constants.hpp>
#include <service-desktop/DesktopMessages.hpp>
#include <service-desktop/DeveloperModeMessage.hpp>
#include <service-evtmgr/EVMessages.hpp>
#include <service-evtmgr/service-evtmgr/Constants.hpp>
#include <service-evtmgr/service-evtmgr/torch.hpp>
#include <service-evtmgr/Constants.hpp>
#include <service-evtmgr/torch.hpp>

namespace app::manager
{


@@ 464,15 466,31 @@ namespace app::manager

    auto ApplicationManager::handleAction(ActionEntry &action) -> ActionProcessStatus
    {
        const auto status = ApplicationManagerCommon::handleAction(action);
        if (status != ActionProcessStatus::NotHandled) {
            return status;
        }
        switch (action.actionId) {
        case actions::PhoneModeChanged:
            return handlePhoneModeChangedAction(action);
        default:
            return ActionProcessStatus::NotHandled;
            return ApplicationManagerCommon::handleAction(action);
        }
    }

    void ApplicationManager::handleStart(StartAllowedMessage *msg)
    {
        switch (msg->getStartupType()) {
        case StartupType::Regular:
            ApplicationManagerCommon::handleStart(msg);
            break;
        case StartupType::LowBattery:
            handleSwitchApplication(std::make_unique<SwitchRequest>(
                                        service::name::appmgr, app::name_desktop, window::name::dead_battery, nullptr)
                                        .get());
            break;
        case StartupType::LowBatteryCharging:
            handleSwitchApplication(
                std::make_unique<SwitchRequest>(
                    service::name::appmgr, app::name_desktop, window::name::charging_battery, nullptr)
                    .get());
            break;
        }
    }
} // namespace app::manager

M products/PurePhone/services/appmgr/CMakeLists.txt => products/PurePhone/services/appmgr/CMakeLists.txt +1 -0
@@ 14,6 14,7 @@ target_include_directories(appmgr

target_link_libraries(appmgr
    PRIVATE
        application-desktop
        application-special-input
        apps-common
        module-apps

M products/PurePhone/services/appmgr/include/appmgr/ApplicationManager.hpp => products/PurePhone/services/appmgr/include/appmgr/ApplicationManager.hpp +5 -0
@@ 5,6 5,10 @@

#include <service-appmgr/model/ApplicationManagerCommon.hpp>

#include <apps-common/locks/handlers/PhoneLockHandler.hpp>
#include <apps-common/locks/handlers/SimLockHandler.hpp>
#include <bsp/keypad_backlight/keypad_backlight.hpp>

namespace app::manager
{
    class ApplicationManager : public ApplicationManagerCommon


@@ 38,6 42,7 @@ namespace app::manager
        auto handleDBResponse(db::QueryResponse *msg) -> bool;
        auto handlePhoneModeChangedAction(ActionEntry &action) -> ActionProcessStatus;
        auto handleAction(ActionEntry &action) -> ActionProcessStatus override;
        void handleStart(StartAllowedMessage *msg) override;

        std::shared_ptr<sys::phone_modes::Observer> phoneModeObserver;
        locks::PhoneLockHandler phoneLockHandler;