~aleteoryx/muditaos

a0b79647edff9336d89e0f9f7be8bb3ce2927fd4 — lblach 5 years ago a30887b
[EGD-4068] Add Update Package Installation Mode

It is necessary that the PureOS update mechanism enters Update Package
Installation Mode (where most of the services are stopped)
when the PureOS update package gets downloaded into the phone.
D .idea/runConfigurations/PurePhone.xml => .idea/runConfigurations/PurePhone.xml +0 -7
@@ 1,7 0,0 @@
<component name="ProjectRunConfigurationManager">
  <configuration default="false" name="PurePhone" type="CMakeRunConfiguration" factoryName="Application" activateToolWindowBeforeRun="false" REDIRECT_INPUT="false" WORKING_DIR="file://$CMakeCurrentBuildDir$" PASS_PARENT_ENVS_2="true" PROJECT_NAME="PurePhone" TARGET_NAME="PurePhone" CONFIG_NAME="Linux" RUN_TARGET_PROJECT_NAME="PurePhone" RUN_TARGET_NAME="PurePhone">
    <method v="2">
      <option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
    </method>
  </configuration>
</component>
\ No newline at end of file

M module-bsp/board/rt1051/common/startup_mimxrt1052.cpp => module-bsp/board/rt1051/common/startup_mimxrt1052.cpp +1 -1
@@ 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

//*****************************************************************************

M module-services/service-appmgr/CMakeLists.txt => module-services/service-appmgr/CMakeLists.txt +1 -1
@@ 22,7 22,7 @@ set(SOURCES
    messages/SwitchBackRequest.cpp
    messages/SwitchConfirmation.cpp
    messages/SwitchRequest.cpp
)
    messages/UpdateInProgress.cpp)

add_library(${PROJECT_NAME} STATIC ${SOURCES})


A module-services/service-appmgr/messages/UpdateInProgress.cpp => module-services/service-appmgr/messages/UpdateInProgress.cpp +12 -0
@@ 0,0 1,12 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <service-appmgr/messages/UpdateInProgress.hpp>

namespace app::manager
{
    UpdateInProgress::UpdateInProgress(const ApplicationName &sender)
        : BaseMessage(MessageType::APMDelayedClose, sender)
    {}

} // namespace app::manager

M module-services/service-appmgr/model/ApplicationManager.cpp => module-services/service-appmgr/model/ApplicationManager.cpp +22 -0
@@ 12,6 12,7 @@
#include <SystemManager/messages/SystemManagerMessage.hpp>
#include <application-call/ApplicationCall.hpp>
#include <application-special-input/ApplicationSpecialInput.hpp>
#include <application-desktop/ApplicationDesktop.hpp>
#include <i18n/i18n.hpp>
#include <log/log.hpp>
#include <service-appmgr/messages/Message.hpp>


@@ 282,6 283,10 @@ namespace app::manager
        connect(typeid(GetCurrentDisplayLanguageRequest), [&](sys::Message *request) {
            return std::make_shared<GetCurrentDisplayLanguageResponse>(displayLanguage);
        });
        connect(typeid(UpdateInProgress), [this](sys::Message *) {
            closeApplicationsOnUpdate();
            return msgHandled();
        });

        auto convertibleToActionHandler = [this](sys::Message *request) { return handleMessageAsAction(request); };
        connect(typeid(CellularSimRequestPinMessage), convertibleToActionHandler);


@@ 347,6 352,23 @@ namespace app::manager
        return true;
    }

    auto ApplicationManager::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 ApplicationManager::closeService(const std::string &name)
    {
        bool ret = sys::SystemManager::DestroyService(name, this);

M module-services/service-appmgr/service-appmgr/messages/Message.hpp => module-services/service-appmgr/service-appmgr/messages/Message.hpp +1 -0
@@ 19,3 19,4 @@
#include "GetCurrentDisplayLanguageRequest.hpp"
#include "GetCurrentDisplayLanguageResponse.hpp"
#include "DateAndTimeChangeRequest.hpp"
#include "UpdateInProgress.hpp"

A module-services/service-appmgr/service-appmgr/messages/UpdateInProgress.hpp => module-services/service-appmgr/service-appmgr/messages/UpdateInProgress.hpp +15 -0
@@ 0,0 1,15 @@
// 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 "BaseMessage.hpp"

namespace app::manager
{
    class UpdateInProgress : public BaseMessage
    {
      public:
        explicit UpdateInProgress(const ApplicationName &sender);
    };
} // namespace app::manager

M module-services/service-appmgr/service-appmgr/model/ApplicationManager.hpp => module-services/service-appmgr/service-appmgr/model/ApplicationManager.hpp +1 -0
@@ 108,6 108,7 @@ namespace app::manager
        void suspendSystemServices();
        auto closeServices() -> bool;
        auto closeApplications() -> bool;
        auto closeApplicationsOnUpdate() -> bool;
        void closeService(const std::string &name);
        void closeApplication(ApplicationHandle *application);


M module-services/service-desktop/ServiceDesktop.cpp => module-services/service-desktop/ServiceDesktop.cpp +3 -1
@@ 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 "service-desktop/DesktopMessages.hpp"


@@ 18,6 18,8 @@
#include <service-db/service-db/Settings.hpp>
#include <service-db/QueryMessage.hpp>

#include <module-sys/SystemManager/SystemManager.hpp>

#include <cinttypes>
#include <filesystem>


M module-services/service-desktop/endpoints/update/UpdateMuditaOS.cpp => module-services/service-desktop/endpoints/update/UpdateMuditaOS.cpp +2 -1
@@ 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 "UpdateMuditaOS.hpp"


@@ 131,6 131,7 @@ updateos::UpdateError UpdateMuditaOS::runUpdate()
    // at this point we should set the system to update mode we are
    // writing directly to eMMC when updating the bootloader
    // then placing the new files in destination folders/files
    sys::SystemManager::Update(owner);

    if ((err = updateBootloader()) == updateos::UpdateError::NoError) {
        informUpdate(status, "Update bootloader");

M module-sys/SystemManager/SystemManager.cpp => module-sys/SystemManager/SystemManager.cpp +60 -0
@@ 16,9 16,11 @@
#include <service-evtmgr/Constants.hpp>
#include <service-evtmgr/EventManagerServiceAPI.hpp>
#include <Service/Timer.hpp>
#include <service-desktop/service-desktop/Constants.hpp>
#include <service-cellular/CellularServiceAPI.hpp>
#include <service-cellular/CellularMessage.hpp>
#include <service-appmgr/model/ApplicationManager.hpp>
#include <service-appmgr/service-appmgr/Controller.hpp>
#include "messages/CpuFrequencyMessage.hpp"
#include "messages/DeviceRegistrationMessage.hpp"
#include <time/ScopedTime.hpp>


@@ 159,6 161,15 @@ namespace sys
        s->bus.sendUnicast(std::make_shared<SystemManagerCmd>(Code::CloseSystem), service::name::system_manager);
        return true;
    }
    bool SystemManager::Update(Service *s)
    {
        s->bus.sendUnicast(std::make_shared<SystemManagerCmd>(Code::Update), service::name::system_manager);

        auto msg = std::make_shared<app::manager::UpdateInProgress>(service::name::system_manager);
        s->bus.sendUnicast(msg, app::manager::ApplicationManager::ServiceName);

        return true;
    }

    bool SystemManager::Reboot(Service *s)
    {


@@ 260,6 271,9 @@ namespace sys
                case Code::CloseSystem:
                    CloseSystemHandler();
                    break;
                case Code::Update:
                    UpdateSystemHandler();
                    break;
                case Code::Reboot:
                    RebootHandler();
                    break;


@@ 383,6 397,52 @@ namespace sys
        set(State::Shutdown);
    }

    void SystemManager::UpdateSystemHandler()
    {
        LOG_DEBUG("Starting system update procedure...");

        // We are going to remove services in reversed order of creation
        CriticalSection::Enter();
        std::reverse(servicesList.begin(), servicesList.end());
        CriticalSection::Exit();

        for (bool retry{};; retry = false) {
            for (auto &service : servicesList) {
                if (service->GetName() == service::name::evt_manager) {
                    LOG_DEBUG("Delay closing %s", service::name::evt_manager);
                    continue;
                }
                if (service->GetName() == service::name::service_desktop) {
                    LOG_DEBUG("Delay closing %s", service::name::service_desktop);
                    continue;
                }

                if (service->GetName() == service::name::db) {
                    LOG_DEBUG("Delay closing %s", service::name::db);
                    continue;
                }

                if (service->GetName() == app::manager::ApplicationManager::ServiceName) {
                    LOG_DEBUG("Delay closing %s", app::manager::ApplicationManager::ServiceName);
                    continue;
                }
                if (service->parent.empty()) {
                    const auto ret = DestroyService(service->GetName(), this);
                    if (!ret) {
                        // no response to exit message,
                        LOG_FATAL("%s failed to response to exit message", service->GetName().c_str());
                        kill(service);
                    }
                    retry = true;
                    break;
                }
            }
            if (!retry) {
                break;
            }
        }
    }

    void SystemManager::RebootHandler()
    {
        CloseSystemHandler();

M module-sys/SystemManager/SystemManager.hpp => module-sys/SystemManager/SystemManager.hpp +5 -0
@@ 37,6 37,7 @@ namespace sys
    enum class Code
    {
        CloseSystem,
        Update,
        Reboot,
        None,
    };


@@ 76,6 77,8 @@ namespace sys
        // Invoke system close procedure
        static bool CloseSystem(Service *s);

        static bool Update(Service *s);

        static bool Reboot(Service *s);

        static bool SuspendService(const std::string &name, Service *caller);


@@ 125,6 128,8 @@ namespace sys
        /// shutdown
        void CloseSystemHandler();

        void UpdateSystemHandler();

        void RebootHandler();

        /// loop to handle prior to full system close