~aleteoryx/muditaos

24f63baf4875443d5070bb75b93eec116bcbdf90 — Lukasz Mastalerz 3 years ago 63f09cb
[MOS-871] Loudspeaker icon not updated when audio routing has changed

Fix for the loudspeaker icon has not changed while calling with
loudspeaker on and connecting headset to the phone.
M module-apps/application-call/ApplicationCall.cpp => module-apps/application-call/ApplicationCall.cpp +19 -2
@@ 1,4 1,4 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "ApplicationCall.hpp"


@@ 33,6 33,9 @@ namespace app
        : Application(name, parent, statusIndicators, startInBackground, app::call_stack_size)
    {
        using namespace gui::status_bar;

        bus.channels.push_back(sys::BusChannel::ServiceAudioNotifications);

        getPopupFilter().addAppDependentFilter([&](const gui::PopupRequestParams &popupParams) {
            if (popupParams.getPopupId() == gui::popup::ID::Volume) {
                return true;


@@ 136,7 139,7 @@ namespace app
            return retMsg;
        }
        return handleAsyncResponse(resp);
    } // namespace app
    }

    // Invoked during initialization
    sys::ReturnCodes ApplicationCall::InitHandler()


@@ 172,6 175,11 @@ namespace app
            return sys::MessageNone{};
        });

        connect(typeid(AudioEventRequest), [&](sys::Message *request) {
            auto message = static_cast<AudioEventRequest *>(request);
            return handleAudioMessageEvent(message);
        });

        createUserInterface();

        return ret;


@@ 266,4 274,13 @@ namespace app
                this, manager::actions::AddContact, std::move(data), manager::OnSwitchBehaviour::RunInBackground);
        }
    }

    sys::MessagePointer ApplicationCall::handleAudioMessageEvent(AudioEventRequest *message)
    {
        if (auto window = getCurrentWindow(); window->getName() == app::window::name_call) {
            static_cast<gui::CallWindow *>(window)->handleAudioEvent(*message->getEvent().get());
        }
        return sys::MessageNone{};
    }

} // namespace app

M module-apps/application-call/include/application-call/ApplicationCall.hpp => module-apps/application-call/include/application-call/ApplicationCall.hpp +4 -1
@@ 1,4 1,4 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


@@ 10,6 10,7 @@
#include <service-evtmgr/Constants.hpp>
#include <service-evtmgr/EVMessages.hpp>
#include <Service/Message.hpp>
#include <service-audio/AudioMessage.hpp>
#include <SystemManager/SystemManagerCommon.hpp>
#include <AppWindowConstants.hpp>
#include <products/PurePhone/apps/include/Application.hpp>


@@ 66,6 67,8 @@ namespace app
        void handleCallEvent(const std::string &number, ExternalRequest isExternalRequest) override;
        void handleAddContactEvent(const std::string &number) override;

        sys::MessagePointer handleAudioMessageEvent(AudioEventRequest *message);

        auto showNotification(std::function<bool()> action, const std::string &icon, const std::string &text) -> bool;
        enum class NotificationType
        {

M module-apps/application-call/windows/CallWindow.cpp => module-apps/application-call/windows/CallWindow.cpp +33 -1
@@ 161,7 161,7 @@ namespace gui

    bool CallWindow::onInput(const InputEvent &inputEvent)
    {
        bool handled = false;
        bool handled       = false;
        const auto keyCode = inputEvent.getKeyCode();

        // process only if key is released


@@ 297,4 297,36 @@ namespace gui
        numberLabel->setText(text);
    }

    void CallWindow::handleAudioEvent(const audio::Event &event)
    {

        switch (event.getType()) {
        case audio::EventType::BlutoothHFPDeviceState:
        case audio::EventType::BlutoothHSPDeviceState:
        case audio::EventType::JackState: {
            if (event.getDeviceState() == audio::Event::DeviceState::Connected) {
                devices_connected.insert(event.getType());
                changeSpeakerIconIfNeeded();
            }
            else {
                devices_connected.erase(event.getType());
                if (not devices_connected.empty()) {
                    changeSpeakerIconIfNeeded();
                }
            }
            break;
        }
        default: {
            break;
        }
        }
    }

    void CallWindow::changeSpeakerIconIfNeeded()
    {
        if (speakerIcon->get() == SpeakerIconState::SPEAKERON) {
            speakerIcon->setNext();
        }
    }

} /* namespace gui */

M module-apps/application-call/windows/CallWindow.hpp => module-apps/application-call/windows/CallWindow.hpp +5 -1
@@ 1,4 1,4 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


@@ 44,6 44,8 @@ namespace gui

        utils::PhoneNumber::View phoneNumber;

        std::set<audio::EventType> devices_connected{};

      public:
        CallWindow(app::ApplicationCommon *app,
                   std::unique_ptr<app::call::CallWindowContract::Presenter> &&windowPresenter);


@@ 67,6 69,8 @@ namespace gui
        void setActiveCallLayout() override;
        void setCallEndedLayout(bool delayedClose = true) override;
        void updateNumber(const UTF8 &text) override;
        void handleAudioEvent(const audio::Event &event);
        void changeSpeakerIconIfNeeded();
    };

} /* namespace gui */

M module-services/service-audio/AudioServiceAPI.cpp => module-services/service-audio/AudioServiceAPI.cpp +7 -5
@@ 1,4 1,4 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <AudioMessage.hpp>


@@ 90,16 90,18 @@ namespace AudioServiceAPI
        return serv->bus.sendUnicast(msg, service::name::audio);
    }

    bool SendEvent(sys::Service *serv, std::shared_ptr<audio::Event> evt)
    void SendEvent(sys::Service *serv, std::shared_ptr<audio::Event> evt)
    {
        auto msg = std::make_shared<AudioEventRequest>(std::move(evt));
        return serv->bus.sendUnicast(msg, service::name::audio);
        serv->bus.sendMulticast(msg, sys::BusChannel::ServiceAudioNotifications);
        // return true;
    }

    bool SendEvent(sys::Service *serv, audio::EventType eType, audio::Event::DeviceState state)
    void SendEvent(sys::Service *serv, audio::EventType eType, audio::Event::DeviceState state)
    {
        auto msg = std::make_shared<AudioEventRequest>(eType, state);
        return serv->bus.sendUnicast(msg, service::name::audio);
        serv->bus.sendMulticast(msg, sys::BusChannel::ServiceAudioNotifications);
        // return true;
    }

    std::string GetSetting(sys::Service *serv, audio::Setting setting, audio::PlaybackType playbackType)

M module-services/service-audio/ServiceAudio.cpp => module-services/service-audio/ServiceAudio.cpp +7 -6
@@ 126,6 126,11 @@ ServiceAudio::ServiceAudio()
            [this](sys::Message *msg) -> sys::MessagePointer { return handleMultimediaAudioPause(); });
    connect(typeid(message::bluetooth::AudioStart),
            [this](sys::Message *msg) -> sys::MessagePointer { return handleMultimediaAudioStart(); });
    connect(typeid(AudioEventRequest), [this](sys::Message *msg) -> sys::MessagePointer {
        auto message = static_cast<AudioEventRequest *>(msg);
        HandleSendEvent(message->getEvent());
        return sys::msgHandled();
    });
}

ServiceAudio::~ServiceAudio()


@@ 449,7 454,7 @@ std::unique_ptr<AudioResponseMessage> ServiceAudio::HandleStart(const Operation:
    return std::make_unique<AudioStartRoutingResponse>(RetCode::OperationNotSet, Token::MakeBadToken());
}

std::unique_ptr<AudioResponseMessage> ServiceAudio::HandleSendEvent(std::shared_ptr<Event> evt)
sys::MessagePointer ServiceAudio::HandleSendEvent(std::shared_ptr<Event> evt)
{
    const auto eventType       = evt->getType();
    const auto deviceConnected = evt->getDeviceState() == audio::Event::DeviceState::Connected;


@@ 492,7 497,7 @@ std::unique_ptr<AudioResponseMessage> ServiceAudio::HandleSendEvent(std::shared_
        input.audio->SendEvent(evt);
    }

    return std::make_unique<AudioEventResponse>(RetCode::Success);
    return sys::msgHandled();
}

std::unique_ptr<AudioResponseMessage> ServiceAudio::HandleStop(const std::vector<audio::PlaybackType> &stopTypes,


@@ 670,10 675,6 @@ sys::MessagePointer ServiceAudio::DataReceivedHandler(sys::DataMessage *msgl, sy
        auto *msg   = static_cast<AudioResumeRequest *>(msgl);
        responseMsg = HandleResume(msg->token);
    }
    else if (msgType == typeid(AudioEventRequest)) {
        auto *msg   = static_cast<AudioEventRequest *>(msgl);
        responseMsg = HandleSendEvent(msg->getEvent());
    }
    else if (msgType == typeid(AudioKeyPressedRequest)) {
        auto *msg   = static_cast<AudioKeyPressedRequest *>(msgl);
        responseMsg = HandleKeyPressed(msg->step);

M module-services/service-audio/include/service-audio/AudioServiceAPI.hpp => module-services/service-audio/include/service-audio/AudioServiceAPI.hpp +5 -9
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


@@ 104,22 104,18 @@ namespace AudioServiceAPI
     */
    bool Resume(sys::Service *serv, const audio::Token &token);
    /**
     * @brief Sends audio event
     * @brief Sends audio event as multicast
     * @param serv Requesting service.
     * @param evt Event to be sent.
     * @return True is request has been sent successfully, false otherwise
     *   Response will come as message AudioSendEventResponse
     */
    bool SendEvent(sys::Service *serv, std::shared_ptr<audio::Event> evt);
    void SendEvent(sys::Service *serv, std::shared_ptr<audio::Event> evt);
    /**
     * @brief Sends audio event
     * @brief Sends audio event as multicast
     * @param serv Requesting service.
     * @param evt Event to be sent.
     * @param state Optional parameter to request.
     * @return True is request has been sent successfully, false otherwise
     *   Response will come as message AudioSendEventResponse
     */
    bool SendEvent(sys::Service *serv,
    void SendEvent(sys::Service *serv,
                   audio::EventType evt,
                   audio::Event::DeviceState state = audio::Event::DeviceState::Connected);


M module-services/service-audio/include/service-audio/ServiceAudio.hpp => module-services/service-audio/include/service-audio/ServiceAudio.hpp +2 -2
@@ 1,4 1,4 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


@@ 78,7 78,7 @@ class ServiceAudio : public sys::Service
    };

    auto StopInput(audio::AudioMux::Input *input, StopReason stopReason = StopReason::Other) -> audio::RetCode;
    auto HandleSendEvent(std::shared_ptr<audio::Event> evt) -> std::unique_ptr<AudioResponseMessage>;
    auto HandleSendEvent(std::shared_ptr<audio::Event> evt) -> sys::MessagePointer;
    auto HandlePause(const audio::Token &token) -> std::unique_ptr<AudioResponseMessage>;
    auto HandlePause(std::optional<audio::AudioMux::Input *> input) -> std::unique_ptr<AudioResponseMessage>;
    auto HandleResume(const audio::Token &token) -> std::unique_ptr<AudioResponseMessage>;

M pure_changelog.md => pure_changelog.md +1 -0
@@ 63,6 63,7 @@
* Fixed (removed) redundant leading zero from time representation unless exactly midnight
* Fixed inability to type characters other than digits in USSD replies
* Fixed screen ghosting after emoji selection
* Fixed incorrect loudspeaker icon in call window when headset was connected during a call

## [1.5.0 2022-12-20]