From 4b8543912a8c17f0563d7bd6fbe21bb9c143a153 Mon Sep 17 00:00:00 2001 From: rrandomsky Date: Tue, 13 Jun 2023 15:00:09 +0200 Subject: [PATCH] [MOS-30] Fix for Alarm not being handled properly during a phone call During the phone call, the alarm was not displayed and subsequent alarms after this scenario did not work. This has now been fixed and the alarm during a phone call will be automatically snooze. --- .../ApplicationAlarmClock.cpp | 2 +- .../models/AlarmsRepository.cpp | 2 +- .../application-call/ApplicationCall.cpp | 7 ++- .../popups/presenter/AlarmPresenter.cpp | 2 +- module-audio/Audio/AudioCommon.hpp | 3 +- module-db/Interface/AlarmEventRecord.cpp | 2 +- module-db/Interface/EventRecord.hpp | 11 +++-- module-db/Tables/AlarmEventsTable.cpp | 2 +- .../service-audio/ServiceAudio.cpp | 8 ++++ .../include/service-audio/AudioMessage.hpp | 7 +++ .../include/service-audio/ServiceAudio.hpp | 6 ++- .../service-cellular/CellularServiceAPI.cpp | 17 ++++++- .../service-cellular/CellularServiceAPI.hpp | 3 +- .../api/EventManagerServiceAPI.cpp | 2 +- .../service-time/AlarmOperations.cpp | 45 ++++++++++++++++--- .../service-time/AlarmOperations.hpp | 8 ++++ module-services/service-time/ServiceTime.cpp | 13 ++++++ module-services/service-time/ServiceTime.hpp | 3 +- .../service-time/SnoozedAlarmEventRecord.hpp | 9 ++-- module-sys/Service/Service.cpp | 2 +- pure_changelog.md | 1 + 21 files changed, 129 insertions(+), 26 deletions(-) diff --git a/module-apps/application-alarm-clock/ApplicationAlarmClock.cpp b/module-apps/application-alarm-clock/ApplicationAlarmClock.cpp index 3f554df065675b8225f7dabd2804881121744fa1..9d3443461caf37dff8f35b5b7d7b847817d535ec 100644 --- a/module-apps/application-alarm-clock/ApplicationAlarmClock.cpp +++ b/module-apps/application-alarm-clock/ApplicationAlarmClock.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "ApplicationAlarmClock.hpp" diff --git a/module-apps/application-alarm-clock/models/AlarmsRepository.cpp b/module-apps/application-alarm-clock/models/AlarmsRepository.cpp index 8ef7511b27e81e98f903153e200ce196c9331210..701e0d223e7628d48351ac7514674375ef077e19 100644 --- a/module-apps/application-alarm-clock/models/AlarmsRepository.cpp +++ b/module-apps/application-alarm-clock/models/AlarmsRepository.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "AlarmsRepository.hpp" diff --git a/module-apps/application-call/ApplicationCall.cpp b/module-apps/application-call/ApplicationCall.cpp index 2679d9a8dc1138508046c212793b069569c41226..4e412917e99813dcc97c9223c5df9287122daed2 100644 --- a/module-apps/application-call/ApplicationCall.cpp +++ b/module-apps/application-call/ApplicationCall.cpp @@ -225,8 +225,11 @@ namespace app windowsFactory.attach(app::window::name_dialogConfirm, [](ApplicationCommon *app, const std::string &name) { return std::make_unique(app, name); }); - attachPopups( - {gui::popup::ID::Volume, gui::popup::ID::Tethering, gui::popup::ID::PhoneModes, gui::popup::ID::SimLock}); + attachPopups({gui::popup::ID::Volume, + gui::popup::ID::Tethering, + gui::popup::ID::PhoneModes, + gui::popup::ID::SimLock, + gui::popup::ID::Alarm}); // Alarm pop-up is blocked during phone call - logic is on Alarm side } bool ApplicationCall::showNotification(std::function action, diff --git a/module-apps/apps-common/popups/presenter/AlarmPresenter.cpp b/module-apps/apps-common/popups/presenter/AlarmPresenter.cpp index f9203941c1d258114406796d80263a7a77ba4cbe..21273fc9c8f5e0ceedeb1087288e18135a914b09 100644 --- a/module-apps/apps-common/popups/presenter/AlarmPresenter.cpp +++ b/module-apps/apps-common/popups/presenter/AlarmPresenter.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "AlarmPresenter.hpp" diff --git a/module-audio/Audio/AudioCommon.hpp b/module-audio/Audio/AudioCommon.hpp index bc743db78a27fc267240527825dae87319ecb5de..3e5c57884dc5f61903a1375cea6227a574eb692b 100644 --- a/module-audio/Audio/AudioCommon.hpp +++ b/module-audio/Audio/AudioCommon.hpp @@ -60,7 +60,8 @@ namespace audio None, Multimedia, Notifications, - System = Notifications, + System = Notifications, + SingleVibration = Notifications, KeypadSound, CallRingtone, TextMessageRingtone, diff --git a/module-db/Interface/AlarmEventRecord.cpp b/module-db/Interface/AlarmEventRecord.cpp index d44ea4b98704eda52913e9ee388a590915a45079..c0adc696fe480a11eed35fbc0cdb5582b8f275f8 100644 --- a/module-db/Interface/AlarmEventRecord.cpp +++ b/module-db/Interface/AlarmEventRecord.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "AlarmEventRecord.hpp" diff --git a/module-db/Interface/EventRecord.hpp b/module-db/Interface/EventRecord.hpp index e2ac9998ddb276cd85c78e16db2194d50e154e2e..123179787c67c3b4097a801272eed2e858cc6cbb 100644 --- a/module-db/Interface/EventRecord.hpp +++ b/module-db/Interface/EventRecord.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -56,8 +56,13 @@ struct SingleEventRecord : public Record, public EventInfo virtual ~SingleEventRecord() = default; SingleEventRecord() = default; - SingleEventRecord(std::shared_ptr parent, TimePoint startDate, TimePoint endDate) - : EventInfo{startDate, endDate}, parent{parent} {}; + SingleEventRecord(std::shared_ptr parent, + TimePoint startDate, + TimePoint endDate, + bool wasHandledDuringCall = false) + : EventInfo{startDate, endDate}, parent{parent}, wasHandledDuringPhoneCall(wasHandledDuringCall){}; auto isValid() const -> bool; + + bool wasHandledDuringPhoneCall; }; diff --git a/module-db/Tables/AlarmEventsTable.cpp b/module-db/Tables/AlarmEventsTable.cpp index 8f46102593ad39c360a90a5e1ad4d1f043d4ffe9..2658e202b0bc62bb3857ffe87beccbd144f2af77 100644 --- a/module-db/Tables/AlarmEventsTable.cpp +++ b/module-db/Tables/AlarmEventsTable.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "AlarmEventsTable.hpp" diff --git a/module-services/service-audio/ServiceAudio.cpp b/module-services/service-audio/ServiceAudio.cpp index bf24aef535bf7aeffb786c7dffa1043e82ba1d54..2cee406865baf716704f2dca3a01cf21c0094478 100644 --- a/module-services/service-audio/ServiceAudio.cpp +++ b/module-services/service-audio/ServiceAudio.cpp @@ -126,6 +126,8 @@ ServiceAudio::ServiceAudio() [this](sys::Message *msg) -> sys::MessagePointer { return handleMultimediaAudioPause(); }); connect(typeid(message::bluetooth::AudioStart), [this](sys::Message *msg) -> sys::MessagePointer { return handleMultimediaAudioStart(); }); + connect(typeid(SingleVibrationStart), + [this](sys::Message *msg) -> sys::MessagePointer { return handleSingleVibrationStart(); }); } ServiceAudio::~ServiceAudio() @@ -898,6 +900,12 @@ auto ServiceAudio::handleMultimediaAudioStart() -> sys::MessagePointer return sys::msgHandled(); } +auto ServiceAudio::handleSingleVibrationStart() -> sys::MessagePointer +{ + VibrationUpdate(audio::PlaybackType::SingleVibration); + return sys::msgHandled(); +} + void ServiceAudio::notifyAboutNewRoutingIfRouterAvailable() { for (auto &input : audioMux.GetAllInputs()) { diff --git a/module-services/service-audio/include/service-audio/AudioMessage.hpp b/module-services/service-audio/include/service-audio/AudioMessage.hpp index 6fb8d4984598184d51c3e46ee23eae9fcbb1cb0e..0a3a090a0d0a806e844c4159bf6e4c688a388312 100644 --- a/module-services/service-audio/include/service-audio/AudioMessage.hpp +++ b/module-services/service-audio/include/service-audio/AudioMessage.hpp @@ -321,3 +321,10 @@ class HFPDeviceVolumeChanged : public BluetoothDeviceVolumeChanged HFPDeviceVolumeChanged(std::uint8_t volume) : BluetoothDeviceVolumeChanged{volume} {} }; + +class SingleVibrationStart : public AudioMessage +{ + public: + SingleVibrationStart() + {} +}; diff --git a/module-services/service-audio/include/service-audio/ServiceAudio.hpp b/module-services/service-audio/include/service-audio/ServiceAudio.hpp index 65dd80d0d28d83dae9a317a3aa5263d572dafc82..9207efe28a1b2d8ef181bdaae9537e1219dcd13c 100644 --- a/module-services/service-audio/include/service-audio/ServiceAudio.hpp +++ b/module-services/service-audio/include/service-audio/ServiceAudio.hpp @@ -55,7 +55,10 @@ class ServiceAudio : public sys::Service std::map> vibrationMap = { {VibrationType::None, {}}, {VibrationType::Continuous, {audio::PlaybackType::CallRingtone, audio::PlaybackType::Alarm}}, - {VibrationType::OneShot, {audio::PlaybackType::Notifications, audio::PlaybackType::TextMessageRingtone}}}; + {VibrationType::OneShot, + {audio::PlaybackType::Notifications, + audio::PlaybackType::TextMessageRingtone, + audio::PlaybackType::SingleVibration}}}; auto IsVibrationMotorOn() { @@ -127,6 +130,7 @@ class ServiceAudio : public sys::Service auto handleHFPVolumeChangedOnBluetoothDevice(sys::Message *msgl) -> sys::MessagePointer; auto handleMultimediaAudioPause() -> sys::MessagePointer; auto handleMultimediaAudioStart() -> sys::MessagePointer; + auto handleSingleVibrationStart() -> sys::MessagePointer; void notifyAboutNewRoutingIfRouterAvailable(); }; diff --git a/module-services/service-cellular/CellularServiceAPI.cpp b/module-services/service-cellular/CellularServiceAPI.cpp index 2e3397d95592317fa789911b4cb1ffccd4e8b21f..b45af420d19f3038e886bfab22827cbb9010d58c 100644 --- a/module-services/service-cellular/CellularServiceAPI.cpp +++ b/module-services/service-cellular/CellularServiceAPI.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "service-cellular/CellularMessage.hpp" @@ -238,6 +238,21 @@ bool CellularServiceAPI::GetAntenna(sys::Service *serv, bsp::cellular::antenna & return false; } +bool CellularServiceAPI::IsCallInProgress(sys::Service *serv, bool &response) +{ + auto msg = std::make_shared(); + auto ret = serv->bus.sendUnicastSync(msg, ServiceCellular::serviceName, 1000); + if (ret.first == sys::ReturnCodes::Success) { + auto celResponse = std::dynamic_pointer_cast(ret.second); + if ((celResponse != nullptr) && (celResponse->retCode == sys::ReturnCodes::Success)) { + LOG_DEBUG("Is Call in progress: %d", celResponse->active); + response = celResponse->active; + return true; + } + } + return false; +} + bool CellularServiceAPI::TransmitDtmfTones(sys::Service *serv, DTMFCode code) { auto msg = std::make_shared(code); diff --git a/module-services/service-cellular/service-cellular/CellularServiceAPI.hpp b/module-services/service-cellular/service-cellular/CellularServiceAPI.hpp index afa815bc81152da656585321563183f68534375e..9fab5b148068812e96b3ca3ea6233b4270ccc313 100644 --- a/module-services/service-cellular/service-cellular/CellularServiceAPI.hpp +++ b/module-services/service-cellular/service-cellular/CellularServiceAPI.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -85,6 +85,7 @@ namespace CellularServiceAPI bool GetCREG(sys::Service *serv, std::string &response); bool GetQNWINFO(sys::Service *serv, std::string &response); bool GetAntenna(sys::Service *serv, bsp::cellular::antenna &response); + bool IsCallInProgress(sys::Service *serv, bool &response); /** * @brief Transmits DTMF tone * @param serv diff --git a/module-services/service-evtmgr/api/EventManagerServiceAPI.cpp b/module-services/service-evtmgr/api/EventManagerServiceAPI.cpp index 73a889674e898110bf838784fca86f80a89b3f12..895c5b35cfa4e79f300e75442dc7933b4670ffc0 100644 --- a/module-services/service-evtmgr/api/EventManagerServiceAPI.cpp +++ b/module-services/service-evtmgr/api/EventManagerServiceAPI.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include diff --git a/module-services/service-time/AlarmOperations.cpp b/module-services/service-time/AlarmOperations.cpp index 838a3ef92afbeb38d87439c274c8ba1c557f59c6..832fb4e8c8f64d000730743e5625598d9a7a7abe 100644 --- a/module-services/service-time/AlarmOperations.cpp +++ b/module-services/service-time/AlarmOperations.cpp @@ -2,6 +2,7 @@ // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "AlarmOperations.hpp" +#include "service-evtmgr/EVMessages.hpp" #include #include @@ -167,7 +168,6 @@ namespace alarms callback(false); return; } - auto newSnoozed = std::make_unique((*found).get()); if (typeid(*(*found)) == typeid(SnoozedAlarmEventRecord)) { @@ -193,7 +193,9 @@ namespace alarms newSnoozed->startDate = nextAlarmTime; snoozedSingleEvents.push_back(std::move(newSnoozed)); - switchAlarmExecution(*(*found), false); + if ((*found)->wasHandledDuringPhoneCall == false) { + switchAlarmExecution(*(*found), false); + } ongoingSingleEvents.erase(found); processOngoingEvents(); @@ -292,11 +294,32 @@ namespace alarms void AlarmOperationsCommon::processOngoingEvents() { - if (!ongoingSingleEvents.empty()) { - switchAlarmExecution(*(ongoingSingleEvents.front()), true); - handleActiveAlarmsCountChange(); - handleSnoozedAlarmsCountChange(); + if (ongoingSingleEvents.empty()) { + return; + } + + if (onCheckIfPhoneCallIsOngoingCallback && onCheckIfPhoneCallIsOngoingCallback()) { + + // Handle once during a phone call + if (!ongoingSingleEvents.front()->wasHandledDuringPhoneCall && onAlarmDuringPhoneCallCallback) { + onAlarmDuringPhoneCallCallback(); + ongoingSingleEvents.front()->wasHandledDuringPhoneCall = true; + } + + // Snooze Alarm during a phone call + OnSnoozeRingingAlarm onSnoozeRingingAlarmCallback = [](bool success) { + success ? LOG_DEBUG("Alarm snoozed during a phone call ") : LOG_ERROR("Unable to snooze alarm!"); + }; + snoozeRingingAlarm(ongoingSingleEvents.front()->parent->ID, + std::chrono::floor(TimePointNow()) + std::chrono::minutes(1), + onSnoozeRingingAlarmCallback); + return; } + + ongoingSingleEvents.front()->wasHandledDuringPhoneCall = false; + switchAlarmExecution(*(ongoingSingleEvents.front()), true); + handleActiveAlarmsCountChange(); + handleSnoozedAlarmsCountChange(); } void AlarmOperationsCommon::addAlarmExecutionHandler(const alarms::AlarmType type, @@ -477,4 +500,14 @@ namespace alarms return id == event->parent->ID; }); } + + auto AlarmOperationsCommon::addCheckIfPhoneCallIsOngoingCallback(CheckIfPhoneCallIsOngoing callback) -> void + { + onCheckIfPhoneCallIsOngoingCallback = callback; + } + + auto AlarmOperationsCommon::addAlarmDuringPhoneCallCallback(OnAlarmDuringPhoneCall callback) -> void + { + onAlarmDuringPhoneCallCallback = callback; + } } // namespace alarms diff --git a/module-services/service-time/AlarmOperations.hpp b/module-services/service-time/AlarmOperations.hpp index 3f9ab4b1c2a1be7ede2c297f3bfcb23c457eb93b..bc0a406a8d7a150c11e62b91f9ca29b7db688b32 100644 --- a/module-services/service-time/AlarmOperations.hpp +++ b/module-services/service-time/AlarmOperations.hpp @@ -32,6 +32,8 @@ namespace alarms using OnSnoozedAlarmsCountChange = std::function; using OnActiveAlarmCountChange = std::function; using OnToggleAllProcessed = std::function; + using CheckIfPhoneCallIsOngoing = std::function; + using OnAlarmDuringPhoneCall = std::function; virtual ~IAlarmOperations() noexcept = default; @@ -66,6 +68,8 @@ namespace alarms virtual void getSnoozedAlarms(OnGetSnoozedAlarms callback) = 0; virtual void handleCriticalBatteryLevel() = 0; virtual void handleNormalBatteryLevel() = 0; + virtual void addCheckIfPhoneCallIsOngoingCallback(CheckIfPhoneCallIsOngoing) = 0; + virtual void addAlarmDuringPhoneCallCallback(OnAlarmDuringPhoneCall) = 0; }; class IAlarmOperationsFactory @@ -112,6 +116,8 @@ namespace alarms void getSnoozedAlarms(OnGetSnoozedAlarms callback) override; void handleCriticalBatteryLevel() override; void handleNormalBatteryLevel() override; + void addCheckIfPhoneCallIsOngoingCallback(CheckIfPhoneCallIsOngoing callback) override; + void addAlarmDuringPhoneCallCallback(OnAlarmDuringPhoneCall callback) override; protected: std::unique_ptr alarmEventsRepo; @@ -132,6 +138,8 @@ namespace alarms GetCurrentTime getCurrentTimeCallback; OnSnoozedAlarmsCountChange onSnoozedAlarmsCountChangeCallback = nullptr; OnActiveAlarmCountChange onActiveAlarmCountChangeCallback = nullptr; + CheckIfPhoneCallIsOngoing onCheckIfPhoneCallIsOngoingCallback = nullptr; + OnAlarmDuringPhoneCall onAlarmDuringPhoneCallCallback = nullptr; // Max 100 alarms for one minute seems reasonable, next events will be dropped constexpr static auto getNextSingleEventsOffset = 0; diff --git a/module-services/service-time/ServiceTime.cpp b/module-services/service-time/ServiceTime.cpp index 574799839c59c2c59758e180c332cd72892dc4d6..35211e0d7b706dac8c9be3c802a3730e6b0b8cd5 100644 --- a/module-services/service-time/ServiceTime.cpp +++ b/module-services/service-time/ServiceTime.cpp @@ -2,11 +2,15 @@ // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "ServiceTime.hpp" +#include "service-evtmgr/Constants.hpp" +#include "service-evtmgr/EVMessages.hpp" #include #include #include #include #include +#include +#include #include #include