~aleteoryx/muditaos

c7513c2c65f87eb42176a70b9ecdaadd32279195 — Adam Dobrowolski 3 years ago f7f5bc3
[EGD-8208] Post rebase and review cleanup

Style fixed, moved files to catalog, renames
M module-apps/tests/test-PhoneModesPolicies.cpp => module-apps/tests/test-PhoneModesPolicies.cpp +0 -1
@@ 62,7 62,6 @@ TEST_CASE("DoNotDisturb Mode notifications  - calls policy test")
    callPolicy.updateCurrentCall(sys::phone_modes::PhoneMode::DoNotDisturb);
    REQUIRE(!callPolicy.isPopupAllowed());
    REQUIRE(!callPolicy.isRingtoneAllowed());
    REQUIRE(callPolicy.isDismissedCallNotificationAllowed());

    SECTION("Number in/not in Favourites")
    {

M module-cellular/at/cmd/src/CLCC.cpp => module-cellular/at/cmd/src/CLCC.cpp +2 -2
@@ 1,11 1,11 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <at/cmd/CLCC.hpp>
#include <memory>
#include <string>
#include <string_view>
#include <service-cellular/CellularCall.hpp>
#include <service-cellular/call/CellularCall.hpp>

namespace at
{

M module-services/service-cellular/CMakeLists.txt => module-services/service-cellular/CMakeLists.txt +4 -4
@@ 16,10 16,10 @@ set(SOURCES
    src/URCCounter.cpp
    src/CSQHandler.cpp

    CellularCall.cpp
    CallAudio.cpp
    CallGUI.cpp
    CallRingGuard.cpp
    call/CellularCall.cpp
    call/CallAudio.cpp
    call/CallGUI.cpp
    call/CallRingGuard.cpp
    CellularServiceAPI.cpp
    CellularUrcHandler.cpp
    checkSmsCenter.cpp

M module-services/service-cellular/ServiceCellular.cpp => module-services/service-cellular/ServiceCellular.cpp +7 -15
@@ 4,7 4,7 @@
#include "endpoints/developerMode/event/ATRequest.hpp"
#include "handler/RawATHandler.hpp"
#include "CellularUrcHandler.hpp"
#include "service-cellular/CellularCall.hpp"
#include "service-cellular/call/CellularCall.hpp"
#include "service-cellular/CellularMessage.hpp"
#include "service-cellular/CellularServiceAPI.hpp"
#include "service-cellular/ServiceCellular.hpp"


@@ 486,9 486,6 @@ void ServiceCellular::registerMessageHandlers()
        return handleCellularRingingMessage(msg);
    });

    connect(typeid(CellularIncominCallMessage),
            [&](sys::Message *request) -> sys::MessagePointer { return handleCellularIncomingCallMessage(request); });

    connect(typeid(CellularCallerIdMessage), [&](sys::Message *request) -> sys::MessagePointer {
        auto msg = static_cast<CellularCallerIdMessage *>(request);
        return handleCellularCallerIdMessage(msg);


@@ 1927,18 1924,12 @@ auto ServiceCellular::handleCellularRingingMessage(CellularRingingMessage *msg) 
    return std::make_shared<CellularResponseMessage>(ongoingCall.startOutgoing(msg->number));
}

auto ServiceCellular::handleCellularIncomingCallMessage(sys::Message *msg) -> std::shared_ptr<sys::ResponseMessage>
{
    LOG_INFO("%s", __PRETTY_FUNCTION__);
    auto ret     = true;
    return std::make_shared<CellularResponseMessage>(ret);
}

auto ServiceCellular::handleCellularCallerIdMessage(sys::Message *msg) -> std::shared_ptr<sys::ResponseMessage>
{
    auto message = static_cast<CellularCallerIdMessage *>(msg);
    if ( not ongoingCall.handleCLIP(message->number) ) {
        CellularServiceAPI::DismissCall(this, phoneModeObserver->getCurrentPhoneMode() == sys::phone_modes::PhoneMode::DoNotDisturb);
    if (not ongoingCall.handleCLIP(message->number)) {
        CellularServiceAPI::DismissCall(
            this, phoneModeObserver->getCurrentPhoneMode() == sys::phone_modes::PhoneMode::DoNotDisturb);
    }

    return sys::MessageNone{};


@@ 2207,8 2198,10 @@ auto ServiceCellular::handleCellularRingNotification(sys::Message *msg) -> std::
    ongoingCall.handleRING();

    /// NOTE: the code below should be investigated as there is something weird in this flow
    /// most probably should be done on not dropped clip/ring
    /// please see that in this case we lock antena, which makes sense when call is in progress
    if (!callManager.isIncomingCallPropagated()) {
        bus.sendMulticast(std::make_shared<CellularIncominCallMessage>(""),
        bus.sendMulticast(std::make_shared<CellularIncominCallMessage>(),
                          sys::BusChannel::ServiceCellularNotifications);
        callManager.ring();
    }


@@ 2221,7 2214,6 @@ auto ServiceCellular::handleCellularCallerIdNotification(sys::Message *msg) -> s
        return std::make_shared<CellularResponseMessage>(hangUpCall());
    }


    auto message = static_cast<CellularCallerIdNotification *>(msg);
    if (phoneModeObserver->isTetheringOn()) {
        tetheringCalllog.push_back(CalllogRecord{CallType::CT_MISSED, message->getNubmer()});

R module-services/service-cellular/CallAudio.cpp => module-services/service-cellular/call/CallAudio.cpp +6 -6
@@ 12,7 12,7 @@

struct CallRingAudio::CallMeta
{
    sys::Async<AudioStartPlaybackRequest, AudioStartPlaybackResponse> p;
    sys::Async<AudioStartPlaybackRequest, AudioStartPlaybackResponse> async;
};

CallRingAudio::CallRingAudio(sys::Service &s) : owner(s), meta(new CallRingAudio::CallMeta)


@@ 25,17 25,17 @@ CallRingAudio::~CallRingAudio()

void CallRingAudio::play()
{
    started = true;
    started         = true;
    const auto file = AudioServiceAPI::GetSound(&owner, audio::PlaybackType::CallRingtone);
    meta->p         = owner.async_call<AudioStartPlaybackRequest, AudioStartPlaybackResponse>(
    meta->async     = owner.async_call<AudioStartPlaybackRequest, AudioStartPlaybackResponse>(
        service::name::audio, file, audio::PlaybackType::CallRingtone);
}

void CallRingAudio::stop()
{
    if ( not started ) {
    if (not started) {
        return;
    }
    owner.sync(meta->p);
    AudioServiceAPI::Stop(&owner, meta->p.getResult().token);
    owner.sync(meta->async);
    AudioServiceAPI::Stop(&owner, meta->async.getResult().token);
}

R module-services/service-cellular/CallAudio.hpp => module-services/service-cellular/call/CallAudio.hpp +1 -1
@@ 13,7 13,7 @@ class CallRingAudio
    struct CallMeta;
    sys::Service &owner;
    CallMeta *meta = nullptr;
    bool started = false;
    bool started   = false;

  public:
    explicit CallRingAudio(sys::Service &);

R module-services/service-cellular/CallGUI.cpp => module-services/service-cellular/call/CallGUI.cpp +5 -8
@@ 8,17 8,14 @@
CallGUI::CallGUI(sys::Service &s) : owner(s)
{}


void CallGUI::notifyRING()
{
        app::manager::Controller::sendAction(&owner,
                                             app::manager::actions::HandleIncomingCall,
                                             std::make_unique<app::manager::actions::CallParams>());
    app::manager::Controller::sendAction(
        &owner, app::manager::actions::HandleIncomingCall, std::make_unique<app::manager::actions::CallParams>());
}

void CallGUI::notifyCLIP(const utils::PhoneNumber::View & number)
void CallGUI::notifyCLIP(const utils::PhoneNumber::View &number)
{
        app::manager::Controller::sendAction(&owner,
                                             app::manager::actions::HandleCallerId,
                                             std::make_unique<app::manager::actions::CallParams>(number));
    app::manager::Controller::sendAction(
        &owner, app::manager::actions::HandleCallerId, std::make_unique<app::manager::actions::CallParams>(number));
}

R module-services/service-cellular/CallGUI.hpp => module-services/service-cellular/call/CallGUI.hpp +1 -1
@@ 19,5 19,5 @@ class CallGUI
    explicit CallGUI(sys::Service &);

    void notifyRING();
    void notifyCLIP(const utils::PhoneNumber::View & number);
    void notifyCLIP(const utils::PhoneNumber::View &number);
};

R module-services/service-cellular/CallRingGuard.cpp => module-services/service-cellular/call/CallRingGuard.cpp +3 -2
@@ 2,7 2,7 @@
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "CallRingGuard.hpp"
#include "service-cellular/CellularCall.hpp"
#include "service-cellular/call/CellularCall.hpp"

bool callRingGuard(CellularCall::Call &call)
{


@@ 11,5 11,6 @@ bool callRingGuard(CellularCall::Call &call)

bool callClipGuard(CellularCall::Call &call)
{
    return call.mode == sys::phone_modes::PhoneMode::DoNotDisturb && call.operations.areCallsFromFavouritesEnabled() && call.operations.isNumberInFavourites();
    return call.mode == sys::phone_modes::PhoneMode::DoNotDisturb && call.operations.areCallsFromFavouritesEnabled() &&
           call.operations.isNumberInFavourites();
}

R module-services/service-cellular/CallRingGuard.hpp => module-services/service-cellular/call/CallRingGuard.hpp +0 -0
R module-services/service-cellular/CellularCall.cpp => module-services/service-cellular/call/CellularCall.cpp +5 -5
@@ 1,9 1,9 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "service-cellular/CellularCall.hpp"
#include "service-cellular/call/CellularCall.hpp"
#include "service-cellular/call/CallRingGuard.hpp"
#include "service-cellular/ServiceCellular.hpp"
#include "service-cellular/CallRingGuard.hpp"
#include "service-db/agents/settings/SystemSettings.hpp"

#include <CalllogRecord.hpp>


@@ 51,7 51,7 @@ namespace CellularCall
    bool Call::handleCLIP(const utils::PhoneNumber::View &number)
    {
        setNumber(number);
        if ( callClipGuard(*this)) {
        if (callClipGuard(*this)) {
            startCall(number, CallType::CT_INCOMING);
            audio.play();
        }


@@ 175,12 175,12 @@ namespace CellularCall

    bool Call::Operations::areCallsFromFavouritesEnabled()
    {
        return owner.owner.areCallsFromFavouritesEnabled();
        return call.owner.areCallsFromFavouritesEnabled();
    }

    bool Call::Operations::isNumberInFavourites()
    {
        return DBServiceAPI::IsContactInFavourites(&owner.owner, owner.call.phoneNumber);
        return DBServiceAPI::IsContactInFavourites(&call.owner, call.call.phoneNumber);
    }

} // namespace CellularCall

M module-services/service-cellular/service-cellular/CellularMessage.hpp => module-services/service-cellular/service-cellular/CellularMessage.hpp +1 -10
@@ 109,17 109,8 @@ class CellularRingingMessage : public CellularMessage, public app::manager::acti
class CellularIncominCallMessage : public CellularMessage
{
  public:
    CellularIncominCallMessage(const utils::PhoneNumber::View &number)
        : CellularMessage(Type::IncomingCall), number(number)
    CellularIncominCallMessage() : CellularMessage(Type::IncomingCall)
    {}
    CellularIncominCallMessage(const utils::PhoneNumber &number)
        : CellularMessage(Type::IncomingCall), number(number.getView())
    {}
    CellularIncominCallMessage(const std::string &e164number)
        : CellularMessage(Type::IncomingCall), number(utils::PhoneNumber::parse(e164number))
    {}

    utils::PhoneNumber::View number;
};

class CellularCallerIdMessage : public CellularMessage

M module-services/service-cellular/service-cellular/ServiceCellular.hpp => module-services/service-cellular/service-cellular/ServiceCellular.hpp +1 -2
@@ 3,7 3,7 @@

#pragma once

#include "CellularCall.hpp"
#include "call/CellularCall.hpp"
#include "CellularMessage.hpp"
#include "USSD.hpp"
#include "PacketData.hpp"


@@ 274,7 274,6 @@ class ServiceCellular : public sys::Service
    auto handleCellularListCallsMessage(CellularMessage *msg) -> std::shared_ptr<sys::ResponseMessage>;
    auto handleDBNotificationMessage(db::NotificationMessage *msg) -> std::shared_ptr<sys::ResponseMessage>;
    auto handleCellularRingingMessage(CellularRingingMessage *msg) -> std::shared_ptr<sys::ResponseMessage>;
    auto handleCellularIncomingCallMessage(sys::Message *msg) -> std::shared_ptr<sys::ResponseMessage>;
    auto handleCellularCallerIdMessage(sys::Message *msg) -> std::shared_ptr<sys::ResponseMessage>;
    auto handleCellularGetIMSIMessage(sys::Message *msg) -> std::shared_ptr<sys::ResponseMessage>;
    auto handleCellularGetOwnNumberMessage(sys::Message *msg) -> std::shared_ptr<sys::ResponseMessage>;

R module-services/service-cellular/service-cellular/CellularCall.hpp => module-services/service-cellular/service-cellular/call/CellularCall.hpp +6 -5
@@ 3,8 3,8 @@

#pragma once

#include "CallAudio.hpp"
#include "CallGUI.hpp"
#include "call/CallAudio.hpp"
#include "call/CallGUI.hpp"
#include "PhoneModes/PhoneMode.hpp"
#include <Interface/CalllogRecord.hpp>
#include <SystemManager/CpuSentinel.hpp>


@@ 58,6 58,8 @@ namespace CellularCall
            startActiveTime.set_time(0);
        }

        bool startCall(const utils::PhoneNumber::View &number, const CallType type);

        ServiceCellular &owner;
        CallRingAudio audio;
        CallGUI gui;


@@ 89,7 91,6 @@ namespace CellularCall
        bool startOutgoing(const utils::PhoneNumber::View &number);
        bool handleRING();
        bool handleCLIP(const utils::PhoneNumber::View &number);
        bool startCall(const utils::PhoneNumber::View &number, const CallType type);
        bool endCall(Forced forced = Forced::False);

        bool isValid() const


@@ 116,8 117,8 @@ namespace CellularCall

          private:
            friend Call;
            Call &owner;
            explicit Operations(Call &owner) : owner(owner)
            Call &call;
            explicit Operations(Call &owner) : call(owner)
            {}
        };
        Operations operations = Operations(*this);

M module-sys/Service/include/Service/Service.hpp => module-sys/Service/include/Service/Service.hpp +21 -22
@@ 34,7 34,7 @@ namespace sys
        {}
    };

    template <typename Request, typename Response> struct Async // : public with_timer
    template <typename Request, typename Response> struct Async
    {
        enum class State
        {


@@ 46,17 46,17 @@ namespace sys

        State getState()
        {
            return m->state;
            return metadata->state;
        }

        Response &getResult()
        {
            return *m->result;
            return *metadata->result;
        }

        Request &getRequest()
        {
            return *m->request;
            return *metadata->request;
        }

        static_assert(std::is_base_of<sys::Message, Request>::value, "Request has to be based on system message");


@@ 64,22 64,22 @@ namespace sys
                      "Response has to be based on system response message");
        explicit operator bool()
        {
            return m->state == State::Done;
            return metadata->state == State::Done;
        }

      private:
        friend sys::Service;
        void setState(State state)
        {
            this->m->state = state;
            this->metadata->state = state;
        }
        struct M
        struct Metadata
        {
            State state = State::Pending;
            std::shared_ptr<Request> request;
            std::shared_ptr<Response> result;
        };
        std::shared_ptr<M> m = std::make_shared<M>();
        std::shared_ptr<Metadata> metadata = std::make_shared<Metadata>();
    };

    class Service : public cpp_freertos::Thread, public std::enable_shared_from_this<Service>


@@ 157,19 157,18 @@ namespace sys
        {
            static_assert(std::is_base_of<sys::ResponseMessage, Response>::value,
                          "Response has to be based on system message");
            Async<Request, Response> p;
            Async<Request, Response> async;
            auto request = std::make_shared<Request>(arg...);
            if (isConnected(std::type_index(typeid(Response)))) {
                p.setState(Async<Request, Response>::State::Error);
                async.setState(Async<Request, Response>::State::Error);
                throw async_fail();
            }
            auto meta                                    = p.m;
            auto meta                                    = async.metadata;
            meta->request                                = request;
            std::function<MessagePointer(Message *)> foo = [this, meta](Message *m) {
                auto &response = dynamic_cast<Response &>(*m);
            std::function<MessagePointer(Message *)> foo = [this, meta](Message *message) {
                auto &response = dynamic_cast<Response &>(*message);
                meta->state    = Async<Request, Response>::State::Done;
                // this is counter productive - but this is what needs to be done here
                meta->result = std::make_shared<Response>(response);
                meta->result   = std::make_shared<Response>(response);
                disconnect(typeid(Response));
                return sys::msgHandled();
            };


@@ 180,24 179,24 @@ namespace sys
            if (!bus.sendUnicast(request, whom)) {
                throw async_fail();
            }
            return p;
            return async;
        }

        template <typename Request, typename Response>
        void sync(Async<Request, Response> &p, std::uint32_t timeout = std::numeric_limits<std::uint32_t>::max())
        void sync(Async<Request, Response> &async, std::uint32_t timeout = std::numeric_limits<std::uint32_t>::max())
        {
            static_assert(std::is_base_of<sys::ResponseMessage, Response>::value,
                          "Response has to be based on system message");
            if (p.m->request == nullptr) {
            if (async.metadata->request == nullptr) {
                throw async_fail();
            }
            if (p.getState() != Async<Request, Response>::State::Pending) {
            if (async.getState() != Async<Request, Response>::State::Pending) {
                return;
            }
            auto val = bus.unicastSync(p.m->request, this, timeout);
            auto val = bus.unicastSync(async.metadata->request, this, timeout);
            if (val.first != sys::ReturnCodes::Success) {
                val.first == sys::ReturnCodes::Timeout ? p.setState(Async<Request, Response>::State::TimedOut)
                                                       : p.setState(Async<Request, Response>::State::Error);
                val.first == sys::ReturnCodes::Timeout ? async.setState(Async<Request, Response>::State::TimedOut)
                                                       : async.setState(Async<Request, Response>::State::Error);
                return;
            }
            this->HandleResponse(dynamic_cast<sys::ResponseMessage *>(val.second.get()));