~aleteoryx/muditaos

cd45c2acfe7988cfae36d904126c598d6fc6559f — Kuba Kleczkowski 5 years ago b88b8fc
[EGD-6322] Add rejecting incoming calls in dnd mode

Adds rejecting incoming calls in Do not disturb mode.
M module-services/service-cellular/CellularUrcHandler.cpp => module-services/service-cellular/CellularUrcHandler.cpp +2 -2
@@ 25,13 25,13 @@ void CellularUrcHandler::Handle(Clip &urc)
    if (urc.isValid()) {
        phoneNumber = urc.getNumber();
    }
    response = std::make_unique<CellularCallerIdMessage>(phoneNumber);
    response = std::make_unique<CellularCallerIdNotification>(phoneNumber);
    urc.setHandled(true);
}

void CellularUrcHandler::Handle(Ring &urc)
{
    response = std::make_unique<CellularIncominCallMessage>("");
    response = std::make_unique<CellularRingNotification>("");
    urc.setHandled(true);
}


M module-services/service-cellular/ServiceCellular.cpp => module-services/service-cellular/ServiceCellular.cpp +55 -1
@@ 517,11 517,17 @@ void ServiceCellular::registerMessageHandlers()
    });

    connect(typeid(CellularIncominCallMessage), [&](sys::Message *request) -> sys::MessagePointer {
        if (doNotDisturbCondition()) {
            return std::make_shared<CellularResponseMessage>(hangUpCall());
        }
        auto msg = static_cast<CellularIncominCallMessage *>(request);
        return handleCellularIncominCallMessage(msg);
    });

    connect(typeid(CellularCallerIdMessage), [&](sys::Message *request) -> sys::MessagePointer {
        if (doNotDisturbCondition()) {
            return std::make_shared<CellularResponseMessage>(true);
        }
        auto msg = static_cast<CellularCallerIdMessage *>(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<sys::ResponseMessage>
{

    auto msgSimPin = dynamic_cast<CellularSimPinDataMessage *>(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<CellularResponseMessage>
{

    auto channel = cmux->get(TS0710::Channel::Commands);
    if (channel == nullptr) {
        return std::make_shared<CellularResponseMessage>(false);


@@ 2639,6 2651,31 @@ auto ServiceCellular::handleCellularSendSMSMessage(sys::Message *msg) -> std::sh
    return std::make_shared<CellularResponseMessage>(true);
}

auto ServiceCellular::handleCellularRingNotification(sys::Message *msg) -> std::shared_ptr<sys::ResponseMessage>
{
    auto message = static_cast<CellularRingNotification *>(msg);

    if (doNotDisturbCondition()) {
        return std::make_shared<CellularResponseMessage>(this->hangUpCall());
    }
    bus.sendMulticast(std::make_shared<CellularIncominCallMessage>(message->getNubmer()),
                      sys::BusChannel::ServiceCellularNotifications);
    return std::make_shared<CellularResponseMessage>(true);
}

auto ServiceCellular::handleCellularCallerIdNotification(sys::Message *msg) -> std::shared_ptr<sys::ResponseMessage>
{
    auto message = static_cast<CellularCallerIdNotification *>(msg);

    if (doNotDisturbCondition()) {
        return std::make_shared<CellularResponseMessage>(this->hangUpCall());
    }

    bus.sendMulticast(std::make_shared<CellularCallerIdMessage>(message->getNubmer()),
                      sys::BusChannel::ServiceCellularNotifications);
    return std::make_shared<CellularResponseMessage>(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;
}

M module-services/service-cellular/service-cellular/CellularMessage.hpp => module-services/service-cellular/service-cellular/CellularMessage.hpp +46 -0
@@ 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
{


M module-services/service-cellular/service-cellular/ServiceCellular.hpp => module-services/service-cellular/service-cellular/ServiceCellular.hpp +5 -0
@@ 377,12 377,17 @@ class ServiceCellular : public sys::Service
    auto handleCellularSetFlightModeMessage(sys::Message *msg) -> std::shared_ptr<sys::ResponseMessage>;
    auto handleCellularSetRadioOnOffMessage(sys::Message *msg) -> std::shared_ptr<sys::ResponseMessage>;
    auto handleCellularSendSMSMessage(sys::Message *msg) -> std::shared_ptr<sys::ResponseMessage>;
    auto handleCellularRingNotification(sys::Message *msg) -> std::shared_ptr<sys::ResponseMessage>;
    auto handleCellularCallerIdNotification(sys::Message *msg) -> std::shared_ptr<sys::ResponseMessage>;

    auto isModemRadioModuleOn() -> bool;
    auto turnOnRadioModule() -> bool;
    auto turnOffRadioModule() -> bool;

    auto switchToOffline() -> bool;
    auto doNotDisturbCondition() -> bool;

    auto hangUpCall() -> bool;
};

namespace sys