From daf6500977a5cd9858236ca7ecd213c315f413a4 Mon Sep 17 00:00:00 2001 From: marek303 <33912109+marek303@users.noreply.github.com> Date: Fri, 23 Oct 2020 13:52:28 +0200 Subject: [PATCH] [EGD-4123] SwitchToNotification added to ApplicationManager (#879) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [EGD-4123] Implemented notifications based on application manager actions. Co-authored-by: marek303 Co-authored-by: Piotr TaƄski --- changelog.md | 1 + .../service-appmgr/ApplicationManager.cpp | 32 +++ .../service-appmgr/ApplicationManager.hpp | 9 + .../service-appmgr/messages/APMMessage.hpp | 25 ++- source/MessageType.hpp | 190 +++++++++--------- 5 files changed, 162 insertions(+), 95 deletions(-) diff --git a/changelog.md b/changelog.md index 826755934a94cdb2e706b935049cda2d579b60c4..43388d95f699a277f4b3cb383a67fa3036bd0b7f 100644 --- a/changelog.md +++ b/changelog.md @@ -10,6 +10,7 @@ * `[audio][bluetooth]` Added Bluetooth A2DP playback * `[settings][bluetooth]` Create "Add device" windows. * `[hardware]` Slider driver (offline/online mode selection) +* `[appmgr]` Application manager actions introduced. ### Fixed diff --git a/module-services/service-appmgr/ApplicationManager.cpp b/module-services/service-appmgr/ApplicationManager.cpp index 96dd1a2129a8a903306214cced5d7fa5954ebd63..f86b6b5d197976aa6f62bca922a808a3db843b2e 100644 --- a/module-services/service-appmgr/ApplicationManager.cpp +++ b/module-services/service-appmgr/ApplicationManager.cpp @@ -7,6 +7,7 @@ #include "service-appmgr/ApplicationManager.hpp" #include "service-evtmgr/EventManager.hpp" #include "messages/APMMessage.hpp" +#include "AppMessage.hpp" #include "application-call/data/CallSwitchData.hpp" #include "service-db/api/DBServiceAPI.hpp" @@ -162,6 +163,12 @@ namespace sapm blockingTimer = std::make_unique( "BlockTimer", this, std::numeric_limits().max(), sys::Timer::Type::SingleShot); blockingTimer->connect([&](sys::Timer &) { phoneLockCB(); }); + + connect(typeid(APMAction), [this](sys::DataMessage *request, sys::ResponseMessage *) { + auto actionMsg = static_cast(request); + handleAction(actionMsg); + return std::make_shared(); + }); } ApplicationManager::~ApplicationManager() @@ -529,6 +536,26 @@ namespace sapm return true; } + auto ApplicationManager::handleAction(APMAction *actionMsg) -> bool + { + auto &action = actionMsg->getAction(); + const auto targetApp = appGet(action.targetApplication); + if (targetApp == nullptr) { + LOG_ERROR("Failed to switch to %s application: No such application.", action.targetApplication.c_str()); + return false; + } + + if (targetApp->getState() == app::Application::State::ACTIVE_FORGROUND) { + // If the app is already focused, then switch window. + auto msg = std::make_shared( + action.targetWindow, std::string{}, std::move(action.data), gui::ShowMode::GUI_SHOW_INIT); + return sys::Bus::SendUnicast(msg, targetApp->name(), this); + } + APMSwitch switchRequest( + actionMsg->getSenderName(), targetApp->name(), action.targetWindow, std::move(action.data)); + return handleSwitchApplication(&switchRequest); + } + // tries to switch the application bool ApplicationManager::handleSwitchPrevApplication(APMSwitchPrevApp *msg) { @@ -771,6 +798,11 @@ namespace sapm } // Static methods + auto ApplicationManager::sendAction(sys::Service *sender, Action &&action) -> bool + { + auto msg = std::make_shared(sender->GetName(), std::move(action)); + return sys::Bus::SendUnicast(msg, "ApplicationManager", sender); + } bool ApplicationManager::messageSwitchApplication(sys::Service *sender, const std::string &applicationName, diff --git a/module-services/service-appmgr/ApplicationManager.hpp b/module-services/service-appmgr/ApplicationManager.hpp index 09a49b3701459e209e2f5d0ab0d27965c54e2777..c9ddfdb4fc672ca5a72e2e4210052d7fc4645c55 100644 --- a/module-services/service-appmgr/ApplicationManager.hpp +++ b/module-services/service-appmgr/ApplicationManager.hpp @@ -156,6 +156,7 @@ namespace sapm // tries to switch the application bool handleSwitchApplication(APMSwitch *msg); + auto handleAction(APMAction *actionMsg) -> bool; // bool handleSwitchApplicationWithData( APMSwitchWithData* msg); bool handleCloseConfirmation(APMConfirmClose *msg); bool handleSwitchConfirmation(APMConfirmSwitch *msg); @@ -188,6 +189,14 @@ namespace sapm sys::ReturnCodes SwitchPowerModeHandler(const sys::ServicePowerMode mode) override final; + /** + * @brief Sends the action request to application manager. + * @param sender Sender service name. + * @param action Action request + * @return true on success, false otherwise. + */ + static auto sendAction(sys::Service *sender, Action &&action) -> bool; + /** * @brief Sends request to application manager to switch from current application to specific window in * application with specified name . diff --git a/module-services/service-appmgr/messages/APMMessage.hpp b/module-services/service-appmgr/messages/APMMessage.hpp index 97d8d8aef20819fa49d0bfd33cd4b91d5a665d4c..a4aa4505fbd32998e079c4b58fc8230a60afd2e0 100644 --- a/module-services/service-appmgr/messages/APMMessage.hpp +++ b/module-services/service-appmgr/messages/APMMessage.hpp @@ -35,10 +35,11 @@ namespace sapm }; // APMSwitch, //request to switch to given application, optionally also to specified window + // APMSwitchToNotification, //request to switch to given notification (application and specified window) // APMSwitchData, //request to switch to given application, optionally also to specified window with provided data. // APMSwitchPrevApp, //Request to switch to previous application. // APMConfirmSwitch, //Used when application confirms that it is loosing focus and also when application confirms - //that is has gained focus APMConfirmClose, //Sent by application to confirm completion of the close procedure + // that is has gained focus APMConfirmClose, //Sent by application to confirm completion of the close procedure class APMSwitch : public APMMessage { @@ -180,6 +181,28 @@ namespace sapm bool isRunning = false; }; + struct Action + { + std::string targetApplication; + std::string targetWindow; + std::unique_ptr data; + }; + + class APMAction : public APMMessage + { + public: + APMAction(const std::string &senderName, Action &&_action) + : APMMessage{MessageType::APMAction, senderName}, action{std::move(_action)} + {} + + auto getAction() noexcept -> Action & + { + return action; + } + + private: + Action action; + }; } /* namespace sapm */ #endif /* MODULE_SERVICES_SERVICE_APPMGR_MESSAGES_APMMESSAGE_HPP_ */ diff --git a/source/MessageType.hpp b/source/MessageType.hpp index 6a22a209ee85063ee62ea4d5a297166ea201666c..d422243143f2812dd3bb4761b803f9b4423ebbe6 100644 --- a/source/MessageType.hpp +++ b/source/MessageType.hpp @@ -9,81 +9,81 @@ enum class MessageType MessageTypeUninitialized = 0, // eink messages - EinkStateRequest, // message is used to pull status of the eink. If eink is ready to display image - EinkImageData, // message with pointer to the image data for displaying - EinkDMATransfer, // this message is internally sent from wink service to eink service. This will trigger DMA - // transfer to Eink's controller. After tranfer gui service wil lbewill be notified - EinkTemperatureUpdate, // message sent from timer handler. Message forces service to update temperature measured by - // the eink. + EinkStateRequest, ///< message is used to pull status of the eink. If eink is ready to display image + EinkImageData, ///< message with pointer to the image data for displaying + EinkDMATransfer, ///< this message is internally sent from wink service to eink service. This will trigger DMA + ///< transfer to Eink's controller. After tranfer gui service wil lbewill be notified + EinkTemperatureUpdate, ///< message sent from timer handler. Message forces service to update temperature measured + ///< by the eink. // gui messages - GUICommands, // list of rendering commands - GUIFocusInfo, // information about application that gained focus - GUIDisplayReady, // message that informs gui service that service controlling display device is ready for new buffer - // data. - GUIRenderingFinished, // Message is sent from the worker when all rendering is finished. + GUICommands, ///< list of rendering commands + GUIFocusInfo, ///< information about application that gained focus + GUIDisplayReady, ///< message that informs gui service that service controlling display device is ready for new + ///< buffer data. + GUIRenderingFinished, ///< Message is sent from the worker when all rendering is finished. // DB messages DBServiceEvents, - DBServiceNotification, // Common service-db notification message. + DBServiceNotification, ///< Common service-db notification message. DBServiceBackup, - DBSettingsGet, // get current settings from database - DBSettingsUpdate, // update settings - - DBSMSAdd, // Add new sms record - DBSMSRemove, // Remove specified SMS record - DBSMSUpdate, // Update specified SMS record - DBSMSGetSMSLimitOffset, // Get SMS records by limit,offset - DBSMSGetSMSLimitOffsetByThreadID, // Get SMS records by limit,offset with specified ThreadID field - DBSMSGetLastRecord, // Get last edited record - DBSMSGetCount, // Get all sms count - - DBThreadGet, // Get thread by ID - DBThreadGetForContact, // Get thread between 2 contacts - DBThreadRemove, // Remove thread by ID - DBThreadGetLimitOffset, // Get Thread record by limit,offset - DBThreadGetCount, // get Thread count - DBThreadUpdate, // Thread update - - DBSMSTemplateAdd, // Add new sms template record - DBSMSTemplateRemove, // Remove selected sms template record - DBSMSTemplateUpdate, // Update selected sms template record - DBSMSTemplateGetLimitOffset, // Get sms templates records by limit,offset - DBSMSTemplateGetCount, // Get sms templates reocrds count - - DBContactVerify, // checks database for a contact that has the same name (primary+" "+alternative) or phone number 1 - // or phone number 2 or speed dial key - DBContactGetByName, // used to ask for a contact with specified primary and alternative name. + DBSettingsGet, ///< get current settings from database + DBSettingsUpdate, ///< update settings + + DBSMSAdd, ///< Add new sms record + DBSMSRemove, ///< Remove specified SMS record + DBSMSUpdate, ///< Update specified SMS record + DBSMSGetSMSLimitOffset, ///< Get SMS records by limit,offset + DBSMSGetSMSLimitOffsetByThreadID, ///< Get SMS records by limit,offset with specified ThreadID field + DBSMSGetLastRecord, ///< Get last edited record + DBSMSGetCount, ///< Get all sms count + + DBThreadGet, ///< Get thread by ID + DBThreadGetForContact, ///< Get thread between 2 contacts + DBThreadRemove, ///< Remove thread by ID + DBThreadGetLimitOffset, ///< Get Thread record by limit,offset + DBThreadGetCount, ///< get Thread count + DBThreadUpdate, ///< Thread update + + DBSMSTemplateAdd, ///< Add new sms template record + DBSMSTemplateRemove, ///< Remove selected sms template record + DBSMSTemplateUpdate, ///< Update selected sms template record + DBSMSTemplateGetLimitOffset, ///< Get sms templates records by limit,offset + DBSMSTemplateGetCount, ///< Get sms templates reocrds count + + DBContactVerify, ///< checks database for a contact that has the same name (primary+" "+alternative) or phone number + ///< 1 or phone number 2 or speed dial key + DBContactGetByName, ///< used to ask for a contact with specified primary and alternative name. DBContactSearch, - DBContactGetByID, // used to ask for a contact with specified id - DBContactGetBySpeedDial, // used to ask for a contact with specified speed dial key assigned - DBContactGetByNumber, // used to ask for a contact with specified primary or secondary phone number - DBContactMatchByNumber, // used to best match with a single contact using a phone number (primary or secondary) - DBContactAdd, // Add contact record - DBContactRemove, // Remove contact remove - DBContactUpdate, // Update contact remove - DBContactGetLimitOffset, // Get contact records by limit,offset - DBContactGetCount, // Get contacts count + DBContactGetByID, ///< used to ask for a contact with specified id + DBContactGetBySpeedDial, ///< used to ask for a contact with specified speed dial key assigned + DBContactGetByNumber, ///< used to ask for a contact with specified primary or secondary phone number + DBContactMatchByNumber, ///< used to best match with a single contact using a phone number (primary or secondary) + DBContactAdd, ///< Add contact record + DBContactRemove, ///< Remove contact remove + DBContactUpdate, ///< Update contact remove + DBContactGetLimitOffset, ///< Get contact records by limit,offset + DBContactGetCount, ///< Get contacts count DBContactBlock, - DBAlarmAdd, // Add alarm record - DBAlarmRemove, // Remove alarm remove - DBAlarmUpdate, // Update alarm remove - DBAlarmGetLimitOffset, // Get alarm records by limit,offset - DBAlarmGetCount, // Get alarm count - DBAlarmGetNext, // Get alarm, closest or equal to current timestamp. + DBAlarmAdd, ///< Add alarm record + DBAlarmRemove, ///< Remove alarm remove + DBAlarmUpdate, ///< Update alarm remove + DBAlarmGetLimitOffset, ///< Get alarm records by limit,offset + DBAlarmGetCount, ///< Get alarm count + DBAlarmGetNext, ///< Get alarm, closest or equal to current timestamp. DBCountryCode, DBQuery, // Cellular messages - CellularStateRequest, /// cellular change state request, only for use by cellular - CellularNotification, // Async notification message - CellularAnswerIncomingCall, // Answer incoming call - CellularHangupCall, // Hang up call - CellularCall, // Call related events - CellularCallRequest, // Call request + CellularStateRequest, ///< cellular change state request, only for use by cellular + CellularNotification, ///< Async notification message + CellularAnswerIncomingCall, ///< Answer incoming call + CellularHangupCall, ///< Hang up call + CellularCall, ///< Call related events + CellularCallRequest, ///< Call request CellularListCurrentCalls, CellularSimProcedure, @@ -109,49 +109,51 @@ enum class MessageType CellularUSSDRequest, CellularTimeUpdated, - DBNotesAdd, // Add new note's record - DBNotesRemove, // Remove selected note's record - DBNotesUpdate, // Update selected note's record - DBNotesGetLimitOffset, // Get notes records by limit,offset - DBNotesGetCount, // Get notes reocrds count + DBNotesAdd, ///< Add new note's record + DBNotesRemove, ///< Remove selected note's record + DBNotesUpdate, ///< Update selected note's record + DBNotesGetLimitOffset, ///< Get notes records by limit,offset + DBNotesGetCount, ///< Get notes reocrds count - DBCalllogAdd, // Add new note's record - DBCalllogRemove, // Remove selected note's record - DBCalllogUpdate, // Update selected note's record - DBCalllogGetLimitOffset, // Get Calllog records by limit,offset - DBCalllogGetCount, // Get Calllog reocrds count + DBCalllogAdd, ///< Add new note's record + DBCalllogRemove, ///< Remove selected note's record + DBCalllogUpdate, ///< Update selected note's record + DBCalllogGetLimitOffset, ///< Get Calllog records by limit,offset + DBCalllogGetCount, ///< Get Calllog reocrds count // Audio service messages AudioMessage, // application manager - APMCheckAppRunning, // check if application is running in application manager - APMSwitch, // request to switch to given application, optionally also to specified window - APMSwitchPrevApp, // Request to switch to previous application. - APMConfirmSwitch, // Used when application confirms that it is loosing focus and also when application confirms that - // is has gained focus - APMConfirmClose, // Sent by application to confirm completion of the close procedure - APMRegister, // when application finishes initHandler it is sending this messag to inform whether init was - // successful or not. - APMDeleydClose, // this message is sent internally from and to application manager to close specified application. - APMChangeLanguage, // this message is sent from any application to inform application manager that it should send - // gui rebuild command to all applications in background and currently active application. - APMClose, // this message will trigger application manager to close itself, all running applications gui and eink - // services. - APMPreventBlocking, // Prevents application manager from initializing device blocking. - APMInitPowerSaveMode, // This message is sent to application manager from desktop when locking timeout has triggered - // or user explicitly locked the phone. + APMAction, ///< Used to send an action request to application manager. + APMCheckAppRunning, ///< check if application is running in application manager + APMSwitch, ///< request to switch to given application, optionally also to specified window + APMSwitchToNotification, ///< request to switch to given notification (application and specified window) + APMSwitchPrevApp, ///< Request to switch to previous application. + APMConfirmSwitch, ///< Used when application confirms that it is loosing focus and also when application confirms + ///< that is has gained focus + APMConfirmClose, ///< Sent by application to confirm completion of the close procedure + APMRegister, ///< when application finishes initHandler it is sending this messag to inform whether init was + ///< successful or not. + APMDeleydClose, ///< this message is sent internally from and to application manager to close specified application. + APMChangeLanguage, ///< this message is sent from any application to inform application manager that it should send + ///< gui rebuild command to all applications in background and currently active application. + APMClose, ///< this message will trigger application manager to close itself, all running applications gui and eink + ///< services. + APMPreventBlocking, ///< Prevents application manager from initializing device blocking. + APMInitPowerSaveMode, ///< This message is sent to application manager from desktop when locking timeout has + ///< triggered or user explicitly locked the phone. // keyboard messages KBDKeyEvent, - AppSwitch, // application receives this message from application manager. It a signal to gain or loose focus. - AppSwitchWindow, // This is internal message transmitted within application to change window. Additional command and - // data are transmitted with it. - AppInputEvent, // used after key event translation to send input event to application + AppSwitch, ///< application receives this message from application manager. It a signal to gain or loose focus. + AppSwitchWindow, ///< This is internal message transmitted within application to change window. Additional command + ///< and data are transmitted with it. + AppInputEvent, ///< used after key event translation to send input event to application AppRefresh, - AppRebuild, // message used to notify application that it should recreate it's GUI (i.e. language has beed changed - // by the user) + AppRebuild, ///< message used to notify application that it should recreate it's GUI (i.e. language has beed changed + ///< by the user) AppClose, AppFocus, @@ -165,8 +167,8 @@ enum class MessageType EVMBatteryLevel, EVMChargerPlugged, // rtc messages - EVMMinuteUpdated, // This message is send to current focused application on every minute time change. - EVMTimeUpdated, // This message is send on every time update. + EVMMinuteUpdated, ///< This message is send to current focused application on every minute time change. + EVMTimeUpdated, ///< This message is send on every time update. // Torch messages EVMTorchStateMessage,