From cd45c2acfe7988cfae36d904126c598d6fc6559f Mon Sep 17 00:00:00 2001 From: Kuba Kleczkowski Date: Fri, 26 Mar 2021 12:54:40 +0100 Subject: [PATCH] [EGD-6322] Add rejecting incoming calls in dnd mode Adds rejecting incoming calls in Do not disturb mode. --- .../service-cellular/CellularUrcHandler.cpp | 4 +- .../service-cellular/ServiceCellular.cpp | 56 ++++++++++++++++++- .../service-cellular/CellularMessage.hpp | 46 +++++++++++++++ .../service-cellular/ServiceCellular.hpp | 5 ++ 4 files changed, 108 insertions(+), 3 deletions(-) diff --git a/module-services/service-cellular/CellularUrcHandler.cpp b/module-services/service-cellular/CellularUrcHandler.cpp index 60ea2d3e5664c921f90b867b9e61bf0be1ab8b75..34a8e05f2771003a818f1e4988ed894753cf8848 100644 --- a/module-services/service-cellular/CellularUrcHandler.cpp +++ b/module-services/service-cellular/CellularUrcHandler.cpp @@ -25,13 +25,13 @@ void CellularUrcHandler::Handle(Clip &urc) if (urc.isValid()) { phoneNumber = urc.getNumber(); } - response = std::make_unique(phoneNumber); + response = std::make_unique(phoneNumber); urc.setHandled(true); } void CellularUrcHandler::Handle(Ring &urc) { - response = std::make_unique(""); + response = std::make_unique(""); urc.setHandled(true); } diff --git a/module-services/service-cellular/ServiceCellular.cpp b/module-services/service-cellular/ServiceCellular.cpp index 575a5ba18b4c982333ee692997371d3b9d82cdbc..064390d47396322535e7c4e96e660409e3056302 100644 --- a/module-services/service-cellular/ServiceCellular.cpp +++ b/module-services/service-cellular/ServiceCellular.cpp @@ -517,11 +517,17 @@ void ServiceCellular::registerMessageHandlers() }); connect(typeid(CellularIncominCallMessage), [&](sys::Message *request) -> sys::MessagePointer { + if (doNotDisturbCondition()) { + return std::make_shared(hangUpCall()); + } auto msg = static_cast(request); return handleCellularIncominCallMessage(msg); }); connect(typeid(CellularCallerIdMessage), [&](sys::Message *request) -> sys::MessagePointer { + if (doNotDisturbCondition()) { + return std::make_shared(true); + } auto msg = static_cast(request); return handleCellularCallerIdMessage(msg); }); @@ -631,6 +637,12 @@ void ServiceCellular::registerMessageHandlers() connect(typeid(CellularSendSMSMessage), [&](sys::Message *request) -> sys::MessagePointer { return handleCellularSendSMSMessage(request); }); + connect(typeid(CellularRingNotification), + [&](sys::Message *request) -> sys::MessagePointer { return handleCellularRingNotification(request); }); + + connect(typeid(CellularCallerIdNotification), + [&](sys::Message *request) -> sys::MessagePointer { return handleCellularCallerIdNotification(request); }); + handle_CellularGetChannelMessage(); } @@ -1145,6 +1157,7 @@ bool ServiceCellular::unlockSimPuk(std::string puk, std::string pin) auto ServiceCellular::handleSimPinMessage(sys::Message *msgl) -> std::shared_ptr { + auto msgSimPin = dynamic_cast(msgl); if (msgSimPin != nullptr) { LOG_DEBUG("Unlocking sim"); @@ -2241,7 +2254,6 @@ auto ServiceCellular::handleCellularAnswerIncomingCallMessage(CellularMessage *m auto ServiceCellular::handleCellularCallRequestMessage(CellularCallRequestMessage *msg) -> std::shared_ptr { - auto channel = cmux->get(TS0710::Channel::Commands); if (channel == nullptr) { return std::make_shared(false); @@ -2639,6 +2651,31 @@ auto ServiceCellular::handleCellularSendSMSMessage(sys::Message *msg) -> std::sh return std::make_shared(true); } +auto ServiceCellular::handleCellularRingNotification(sys::Message *msg) -> std::shared_ptr +{ + auto message = static_cast(msg); + + if (doNotDisturbCondition()) { + return std::make_shared(this->hangUpCall()); + } + bus.sendMulticast(std::make_shared(message->getNubmer()), + sys::BusChannel::ServiceCellularNotifications); + return std::make_shared(true); +} + +auto ServiceCellular::handleCellularCallerIdNotification(sys::Message *msg) -> std::shared_ptr +{ + auto message = static_cast(msg); + + if (doNotDisturbCondition()) { + return std::make_shared(this->hangUpCall()); + } + + bus.sendMulticast(std::make_shared(message->getNubmer()), + sys::BusChannel::ServiceCellularNotifications); + return std::make_shared(true); +} + auto ServiceCellular::isModemRadioModuleOn() -> bool { using at::cfun::Functionality; @@ -2712,3 +2749,20 @@ auto ServiceCellular::switchToOffline() -> bool return true; } + +auto ServiceCellular::doNotDisturbCondition() -> bool +{ + return phoneModeObserver->isInMode(sys::phone_modes::PhoneMode::DoNotDisturb); +} + +auto ServiceCellular::hangUpCall() -> bool +{ + auto channel = cmux->get(TS0710::Channel::Commands); + if (channel) { + if (channel->cmd(at::factory(at::AT::ATH))) { + return true; + } + } + LOG_ERROR("Failed to hang up call"); + return false; +} diff --git a/module-services/service-cellular/service-cellular/CellularMessage.hpp b/module-services/service-cellular/service-cellular/CellularMessage.hpp index 78f2780fadbe23f123208d135fdb9a578ea539c8..808094fd113d9e9b3fdb6f6f5394238221e6bb98 100644 --- a/module-services/service-cellular/service-cellular/CellularMessage.hpp +++ b/module-services/service-cellular/service-cellular/CellularMessage.hpp @@ -96,6 +96,8 @@ class CellularNotificationMessage : public CellularMessage PowerDownDeregistered, // modem informed it has disconnected from network SMSDone, // SMS initialization finished NewIncomingUrc, // phone received new URC from network and we need to wake up modem and host + Ring, // phone received Ring notification + CallerID // phone received Caller Id notification }; // TODO check and fix all CellularNotificationMessage constructors @@ -1027,6 +1029,50 @@ class CellularSendSMSMessage : public CellularMessage SMSRecord record; }; +class CellularRingNotification : public CellularNotificationMessage +{ + public: + explicit CellularRingNotification(const utils::PhoneNumber::View &number) + : CellularNotificationMessage(CellularNotificationMessage::Type::Ring), number(number) + {} + explicit CellularRingNotification(const utils::PhoneNumber &number) + : CellularNotificationMessage(CellularNotificationMessage::Type::Ring), number(number.getView()) + {} + explicit CellularRingNotification(const std::string &e164number) + : CellularNotificationMessage(CellularNotificationMessage::Type::Ring), + number(utils::PhoneNumber::parse(e164number)) + {} + auto getNubmer() const -> utils::PhoneNumber::View + { + return number; + } + + private: + utils::PhoneNumber::View number; +}; + +class CellularCallerIdNotification : public CellularNotificationMessage +{ + public: + explicit CellularCallerIdNotification(const utils::PhoneNumber::View &number) + : CellularNotificationMessage(CellularNotificationMessage::Type::Ring), number(number) + {} + explicit CellularCallerIdNotification(const utils::PhoneNumber &number) + : CellularNotificationMessage(CellularNotificationMessage::Type::Ring), number(number.getView()) + {} + explicit CellularCallerIdNotification(const std::string &e164number) + : CellularNotificationMessage(CellularNotificationMessage::Type::Ring), + number(utils::PhoneNumber::parse(e164number)) + {} + auto getNubmer() const -> utils::PhoneNumber::View + { + return number; + } + + private: + utils::PhoneNumber::View number; +}; + namespace cellular { diff --git a/module-services/service-cellular/service-cellular/ServiceCellular.hpp b/module-services/service-cellular/service-cellular/ServiceCellular.hpp index 2e83a4c7207b65ec6bfac5e5a53158c952385c5e..005c61849bcbfcd695db44da353601bbec9076f8 100644 --- a/module-services/service-cellular/service-cellular/ServiceCellular.hpp +++ b/module-services/service-cellular/service-cellular/ServiceCellular.hpp @@ -377,12 +377,17 @@ class ServiceCellular : public sys::Service auto handleCellularSetFlightModeMessage(sys::Message *msg) -> std::shared_ptr; auto handleCellularSetRadioOnOffMessage(sys::Message *msg) -> std::shared_ptr; auto handleCellularSendSMSMessage(sys::Message *msg) -> std::shared_ptr; + auto handleCellularRingNotification(sys::Message *msg) -> std::shared_ptr; + auto handleCellularCallerIdNotification(sys::Message *msg) -> std::shared_ptr; auto isModemRadioModuleOn() -> bool; auto turnOnRadioModule() -> bool; auto turnOffRadioModule() -> bool; auto switchToOffline() -> bool; + auto doNotDisturbCondition() -> bool; + + auto hangUpCall() -> bool; }; namespace sys