Files
MuditaOS/module-apps/apps-common/notifications/NotificationsHandler.cpp
tomaszkrosnowski 9c0dde9a03 [EGD-7485] Fix cellular behaviour in offline mode
When in offline/message only, while Pure is in message poll mode and
incoming call will happen CellularService will start answering call thus
resulting to show the incorrect info in call log and not showing the
first call after Online mode is switched back.
This commit is cherry-picked from EGD-7332.
2021-09-03 14:41:06 +02:00

95 lines
3.6 KiB
C++

// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "NotificationsHandler.hpp"
#include <service-db/DBServiceAPI.hpp>
#include <log.hpp>
#include <service-cellular/service-cellular/CellularMessage.hpp>
#include <service-appmgr/Controller.hpp>
#include <service-audio/AudioServiceAPI.hpp>
#include <service-cellular/CellularServiceAPI.hpp>
using namespace notifications;
NotificationsHandler::NotificationsHandler(sys::Service *parentService, NotificationsConfiguration &notifcationConfig)
: parentService{parentService}, notifcationConfig{notifcationConfig}
{}
void NotificationsHandler::registerMessageHandlers()
{
parentService->connect(typeid(CellularIncominCallMessage), [&](sys::Message *request) -> sys::MessagePointer {
incomingCallHandler(request);
return sys::msgHandled();
});
parentService->connect(typeid(CellularCallerIdMessage), [&](sys::Message *request) -> sys::MessagePointer {
callerIdHandler(request);
return sys::msgHandled();
});
parentService->connect(typeid(CellularIncomingSMSNotificationMessage),
[&](sys::Message *request) -> sys::MessagePointer {
incomingSMSHandler();
return sys::msgHandled();
});
}
void NotificationsHandler::incomingCallHandler(sys::Message *request)
{
notifcationConfig.updateCurrentCall(currentCallPolicy);
if (currentCallPolicy.isPopupAllowed()) {
auto msg = static_cast<CellularIncominCallMessage *>(request);
app::manager::Controller::sendAction(parentService,
app::manager::actions::HandleIncomingCall,
std::make_unique<app::manager::actions::CallParams>(msg->number));
playbackCallRingtone();
}
}
void NotificationsHandler::callerIdHandler(sys::Message *request)
{
auto msg = static_cast<CellularCallerIdMessage *>(request);
if (currentCallPolicy.isNumberCheckRequired()) {
policyNumberCheck(msg->number);
}
if (currentCallPolicy.isPopupAllowed()) {
app::manager::Controller::sendAction(parentService,
app::manager::actions::HandleCallerId,
std::make_unique<app::manager::actions::CallParams>(msg->number));
playbackCallRingtone();
}
else {
CellularServiceAPI::DismissCall(parentService, currentCallPolicy.isDismissedCallNotificationAllowed());
}
}
void NotificationsHandler::policyNumberCheck(const utils::PhoneNumber::View &number)
{
auto isContactInFavourites = DBServiceAPI::IsContactInFavourites(parentService, number);
notifcationConfig.callNumberCheck(currentCallPolicy, isContactInFavourites);
}
void NotificationsHandler::incomingSMSHandler()
{
notifcationConfig.updateCurrentSMS(currentSMSPolicy);
playbackSMSRingtone();
}
void NotificationsHandler::playbackCallRingtone()
{
if (currentCallPolicy.isRingtoneAllowed()) {
const auto filePath = AudioServiceAPI::GetSound(parentService, audio::PlaybackType::CallRingtone);
AudioServiceAPI::PlaybackStart(parentService, audio::PlaybackType::CallRingtone, filePath);
}
}
void NotificationsHandler::playbackSMSRingtone()
{
if (currentSMSPolicy.isRingtoneAllowed()) {
const auto filePath = AudioServiceAPI::GetSound(parentService, audio::PlaybackType::TextMessageRingtone);
AudioServiceAPI::PlaybackStart(parentService, audio::PlaybackType::TextMessageRingtone, filePath);
}
}