From d8786f39c6d2f3752c676efeb2f6e027ec326a0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Zieli=C5=84ski?= Date: Wed, 30 Nov 2022 14:26:51 +0100 Subject: [PATCH] [MOS-839] Fix crashes after a few VoLTE toggles Those were occuring after calls which were preceded by a few VoLTE on/off toggles. --- .../service-cellular/call/CellularCall.cpp | 2 +- .../call/api/ModemCallApi.cpp | 58 ++++++++----------- .../call/api/ModemCallApi.hpp | 10 +++- 3 files changed, 34 insertions(+), 36 deletions(-) diff --git a/module-services/service-cellular/call/CellularCall.cpp b/module-services/service-cellular/call/CellularCall.cpp index b827ba99b1b35519078a5722571243cd422d3b86..758c056cb354af776377b5f28ed4e61578ffee01 100644 --- a/module-services/service-cellular/call/CellularCall.cpp +++ b/module-services/service-cellular/call/CellularCall.cpp @@ -28,7 +28,7 @@ namespace call std::make_unique(owner), std::make_unique(std::move(timer)), std::make_unique(std::move(timerRing)), - std::make_unique(owner, cmux), + std::make_unique(owner), std::move(sentinel)}); } diff --git a/module-services/service-cellular/call/api/ModemCallApi.cpp b/module-services/service-cellular/call/api/ModemCallApi.cpp index bfc02bf3cc9d7afa2c497dc6b671e623fe614723..eba48934ff4304a8d4f79e0911ef82dcc996a698 100644 --- a/module-services/service-cellular/call/api/ModemCallApi.cpp +++ b/module-services/service-cellular/call/api/ModemCallApi.cpp @@ -3,58 +3,50 @@ #include "ModemCallApi.hpp" #include +#include #include #include #include namespace cellular { - Api::Api(ServiceCellular *cellular, CellularMux *cmux) : cellular(cellular), cmux(cmux) + Api::Api(ServiceCellular *cellular) : cellular{cellular} {} - bool Api::answerIncomingCall() + bool Api::handleEvent(at::AT modemCommand) { - if (cmux == nullptr) { - throw std::runtime_error("call api not initialized"); + if (!cellular->cmux) { + LOG_INFO("no cmux at this time - ignoring request"); + return false; + } + + auto channel = cellular->cmux->get(CellularMux::Channel::Commands); + if (!channel) { + LOG_INFO("no cmux command channel at this time - ignoring request"); + return false; } - auto channel = cmux->get(CellularMux::Channel::Commands); - if (channel != nullptr) { - auto response = channel->cmd(at::AT::ATA); - if (response) { - return true; - } + + if (!channel->cmd(modemCommand)) { + LOG_WARN("AT+%s command failed - ignoring request", magic_enum::enum_name(modemCommand).data()); + return false; } - return false; + + return true; + } + + bool Api::answerIncomingCall() + { + return handleEvent(at::AT::ATA); } bool Api::hangupCall() { - if (cmux == nullptr) { - return false; - } - auto channel = cmux->get(CellularMux::Channel::Commands); - if (channel != nullptr) { - auto response = channel->cmd(at::AT::ATH); - if (response) { - return true; - } - } - return false; + return handleEvent(at::AT::ATH); } bool Api::rejectCall() { - if (cmux == nullptr) { - return false; - } - auto channel = cmux->get(CellularMux::Channel::Commands); - if (channel != nullptr) { - auto response = channel->cmd(at::AT::CHUP); - if (response) { - return true; - } - } - return false; + return handleEvent(at::AT::CHUP); } bool Api::areCallsFromFavouritesEnabled() diff --git a/module-services/service-cellular/call/api/ModemCallApi.hpp b/module-services/service-cellular/call/api/ModemCallApi.hpp index 185dc5ed768dcf5886ffadc6624e8bee395c4954..79d1de0627e9e92a6f1d07038ffa2ab227e831e5 100644 --- a/module-services/service-cellular/call/api/ModemCallApi.hpp +++ b/module-services/service-cellular/call/api/ModemCallApi.hpp @@ -6,6 +6,11 @@ #include "PhoneModes/PhoneMode.hpp" #include "PhoneModes/Tethering.hpp" +namespace at +{ + enum class AT; +} + class CellularMux; class ServiceCellular; @@ -30,11 +35,12 @@ namespace cellular { private: ServiceCellular *cellular = nullptr; - CellularMux *cmux = nullptr; + + bool handleEvent(at::AT modemCommand); public: Api() = default; - Api(ServiceCellular *cellular, CellularMux *); + Api(ServiceCellular *cellular); bool answerIncomingCall() override; bool hangupCall() override;