~aleteoryx/muditaos

c5fbf28208a708744b748f8545abce95a501c96d — Kuba Kleczkowski 2 years ago ff89d4d
[MOS-879] Fixed misleding SMS flow

Fixed misleading SMS flow after sending error.
When modem was rebooting attempt to send SMS was causing
Rejected by no sim popup, which was misleading for user.
M module-services/service-cellular/ServiceCellular.cpp => module-services/service-cellular/ServiceCellular.cpp +11 -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

#include "endpoints/developerMode/event/ATRequest.hpp"


@@ 632,7 632,13 @@ void ServiceCellular::registerMessageHandlers()
        if (priv->volteHandler->isFunctionalityResetNeeded()) {
            LOG_INFO("[VoLTE] first run after switching - functionality reset needed");
            priv->modemResetHandler->performFunctionalityReset();
            return sys::MessageNone{};
        }

        if (priv->state->get() == State::ST::Ready) {
            priv->outSMSHandler.requestNotSendMessage();
        }

        return sys::MessageNone{};
    });
}


@@ 941,6 947,10 @@ bool ServiceCellular::handle_cellular_priv_init()
}
auto ServiceCellular::handle(db::query::SMSSearchByTypeResult *response) -> bool
{
    if (priv->state->get() != State::ST::Ready) {
        LOG_ERROR("Cellular not ready, skip request");
        return false;
    }
    if (response->getResults().empty()) {
        priv->outSMSHandler.handleNoMoreDbRecords();
    }

M module-services/service-cellular/src/SMSSendHandler.cpp => module-services/service-cellular/src/SMSSendHandler.cpp +14 -5
@@ 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

#include "SMSSendHandler.hpp"


@@ 51,7 51,10 @@ namespace cellular::internal::sms
    {
        handleStateChange(currentState->handle(SMSRecord{}));
    }

    void SMSSendHandler::requestNotSendMessage()
    {
        onSendQuery(db::Interface::Name::SMS, std::make_unique<db::query::SMSSearchByType>(SMSType::QUEUED, 0, 1));
    }
    bool State::isNotification(const std::optional<const SMSRecord> record)
    {
        return !record;


@@ 83,13 86,19 @@ namespace cellular::internal::sms
            return std::make_unique<IdleState>(context);
        }

        if (context.onGetModemResetInProgress()) {
            LOG_ERROR("Modem is rebooting, skipping SMS sending attempt");
            return {};
        }

        if (context.onGetOfflineMode() || context.onSIMNotInitialized()) {
            LOG_ERROR("Failed to send SMS");
            record->type = SMSType::FAILED;
            context.onSendQuery(db::Interface::Name::SMS, std::make_unique<db::query::SMSUpdate>(std::move(*record)));
            return {};
        }
        else {
            context.onSend(*record);
        }

        context.onSend(*record);

        // Check if there are more queued records
        context.onSendQuery(db::Interface::Name::SMS,

M module-services/service-cellular/src/SMSSendHandler.hpp => module-services/service-cellular/src/SMSSendHandler.hpp +4 -2
@@ 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


@@ 58,7 58,6 @@ namespace cellular::internal::sms
    {
      public:
        SMSSendHandler();

        /**
         * External action events
         */


@@ 66,6 65,7 @@ namespace cellular::internal::sms
        void handleIncomingDbRecord(SMSRecord &record, bool onDelay);
        void handleNoMoreDbRecords();
        void sendMessageIfDelayed();
        void requestNotSendMessage();

        /**
         * User defined callbacks/events


@@ 79,6 79,8 @@ namespace cellular::internal::sms
        std::function<bool()> onGetOfflineMode;
        /// Called when SMSSendHandler wants to check SIM state
        std::function<bool()> onSIMNotInitialized;
        /// Called when SMSHandler wants to check if modem is rebooting
        std::function<bool()> onGetModemResetInProgress;

      private:
        void handleStateChange(OptionalState state);

M module-services/service-cellular/src/ServiceCellularPriv.cpp => module-services/service-cellular/src/ServiceCellularPriv.cpp +8 -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 "ServiceCellularPriv.hpp"


@@ 83,7 83,6 @@ namespace cellular::internal
                modemResetHandler->performHardReset();
                return;
            }

            owner->bus.sendMulticast<notification::SimReady>();
        };
        simCard->onNeedPin = [this](unsigned int attempts) {


@@ 241,6 240,8 @@ namespace cellular::internal
            }
            return ret;
        };

        outSMSHandler.onGetModemResetInProgress = [this]() -> bool { return modemResetHandler->isResetInProgress(); };
    }

    bool ServiceCellularPriv::onSendSMS(SMSRecord &record)


@@ 262,6 263,11 @@ namespace cellular::internal
                channelSetup = false;
            }
        }
        else {
            LOG_ERROR("No channel provided! SMS sending failed");
            record.type = SMSType::FAILED;
            return false;
        }

        if (channelSetup) {
            auto partHandler = sms::SMSPartsHandler(record.body);

M module-services/service-cellular/tests/unittest_smssendhandler.cpp => module-services/service-cellular/tests/unittest_smssendhandler.cpp +4 -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 <catch2/catch.hpp>


@@ 32,6 32,8 @@ TEST_CASE("SMSSendHandler functionality")

    outSMS.onSIMNotInitialized = []() -> bool { return false; };

    outSMS.onGetModemResetInProgress = []() -> bool { return false; };

    SECTION("Schedule standard send SMS procedure")
    {
        auto record                = buildValidSMSRecord();


@@ 87,7 89,7 @@ TEST_CASE("SMSSendHandler functionality")
        outSMS.handleIncomingDbRecord(record, sendOnDelay);

        CHECK(wasOnSendInvoked == 0);
        CHECK(wasOnSendQueryInvoked == 3);
        CHECK(wasOnSendQueryInvoked == 2);
    }

    SECTION("Delayed send - positive flow")

M pure_changelog.md => pure_changelog.md +1 -0
@@ 76,6 76,7 @@
* Fixed minor issues in the Calculator Application
* Fixed displaying usual SMS template call rejection window when no templates were defined
* Fixed going back to wrong window after confirming or cancelling creation of new contact from call log
* Fixed misleading popup on SMS send when modem is rebooting

## [1.5.0 2022-12-20]