~aleteoryx/muditaos

1f9f429b0b4e5f6c04942a144f158a9795050793 — Mateusz Grzegorzek 4 years ago b419649
[EGD-5773] Device becomes not responsive when opening settings

Use asynchronous communication with service cellular
to obtain own number.
M module-apps/application-settings-new/ApplicationSettings.cpp => module-apps/application-settings-new/ApplicationSettings.cpp +6 -2
@@ 100,9 100,13 @@ namespace app
                                                   StartInBackground startInBackground)
        : Application(std::move(name), std::move(parent), mode, startInBackground), AsyncCallbackReceiver{this}
    {
        CellularServiceAPI::SubscribeForOwnNumber(this, [&](const std::string &number) {
            selectedSimNumber = number;
            LOG_DEBUG("Sim number changed: %s", selectedSimNumber.c_str());
        });
        if ((Store::GSM::SIM::SIM1 == selectedSim || Store::GSM::SIM::SIM2 == selectedSim) &&
            Store::GSM::get()->sim == selectedSim) {
            selectedSimNumber = CellularServiceAPI::GetOwnNumber(this);
            CellularServiceAPI::RequestForOwnNumber(this);
        }
    }



@@ 123,7 127,7 @@ namespace app
        if (auto phoneMsg = dynamic_cast<CellularNotificationMessage *>(msgl); nullptr != phoneMsg) {
            selectedSim = Store::GSM::get()->selected;
            if (CellularNotificationMessage::Content::SIM_READY == phoneMsg->content) {
                selectedSimNumber = CellularServiceAPI::GetOwnNumber(this);
                CellularServiceAPI::RequestForOwnNumber(this);
            }
            else if (CellularNotificationMessage::Content::SIM_NOT_READY == phoneMsg->content) {
                selectedSimNumber = {};

M module-services/service-cellular/CellularServiceAPI.cpp => module-services/service-cellular/CellularServiceAPI.cpp +16 -17
@@ 70,25 70,24 @@ std::string CellularServiceAPI::GetIMSI(sys::Service *serv, bool getFullIMSINumb
    }
}

std::string CellularServiceAPI::GetOwnNumber(sys::Service *serv)
void CellularServiceAPI::SubscribeForOwnNumber(sys::Service *serv, std::function<void(const std::string &)> callback)
{
    auto msg = std::make_shared<CellularGetOwnNumberMessage>();

    auto ret                          = serv->bus.sendUnicastSync(msg, ServiceCellular::serviceName, 5000);
    CellularResponseMessage *response = dynamic_cast<CellularResponseMessage *>(ret.second.get());

    if (response == nullptr) {
        LOG_ERROR("CellularServiceAPI::GetOwnNumber failed");
        return std::string();
    }
    serv->connect(typeid(CellularGetOwnNumberResponseMessage), [callback](sys::Message *msg) {
        auto response = dynamic_cast<CellularGetOwnNumberResponseMessage *>(msg);
        if (response != nullptr && response->retCode) {
            callback(response->data);
        }
        else {
            LOG_ERROR("Getting own number failed");
            callback(std::string());
        }
        return sys::MessageNone{};
    });
}

    if ((ret.first == sys::ReturnCodes::Success) && (response->retCode == true)) {
        return response->data;
    }
    else {
        LOG_ERROR("CellularServiceAPI::GetOwnNumber failed");
        return std::string();
    }
void CellularServiceAPI::RequestForOwnNumber(sys::Service *serv)
{
    serv->bus.sendUnicast(std::make_shared<CellularGetOwnNumberMessage>(), ServiceCellular::serviceName);
}

void CellularServiceAPI::GetNetworkInfo(sys::Service *serv)

M module-services/service-cellular/ServiceCellular.cpp => module-services/service-cellular/ServiceCellular.cpp +2 -2
@@ 2412,9 2412,9 @@ auto ServiceCellular::handleCellularGetOwnNumberMessage(sys::Message *msg) -> st
{
    std::string temp;
    if (getOwnNumber(temp)) {
        return std::make_shared<CellularResponseMessage>(true, temp);
        return std::make_shared<CellularGetOwnNumberResponseMessage>(true, temp);
    }
    return std::make_shared<CellularResponseMessage>(false);
    return std::make_shared<CellularGetOwnNumberResponseMessage>(false);
}

auto ServiceCellular::handleCellularGetNetworkInfoMessage(sys::Message *msg) -> std::shared_ptr<sys::ResponseMessage>

M module-services/service-cellular/service-cellular/CellularMessage.hpp => module-services/service-cellular/service-cellular/CellularMessage.hpp +8 -0
@@ 705,6 705,14 @@ class CellularSimCardLockResponseMessage : public CellularResponseMessage
    }
};

class CellularGetOwnNumberResponseMessage : public CellularResponseMessage
{
  public:
    CellularGetOwnNumberResponseMessage(bool retCode, std::string number = std::string())
        : CellularResponseMessage(retCode, std::move(number))
    {}
};

class CellularAntennaResponseMessage : public CellularResponseMessage
{
  public:

M module-services/service-cellular/service-cellular/CellularServiceAPI.hpp => module-services/service-cellular/service-cellular/CellularServiceAPI.hpp +8 -3
@@ 35,11 35,16 @@ namespace CellularServiceAPI
     */
    std::string GetIMSI(sys::Service *serv, bool getFullIMSINumber = false);
    /*
     * @brief Its calls sercive-cellular for selected SIM own phone number.
     * @brief Its subscribes service-cellular for selected SIM own phone number response messages.
     * @param serv pointer to caller service.
     * #return SIM own number when succeeds, empty string when fails
     * @param callback called on response message receive event.
     */
    std::string GetOwnNumber(sys::Service *serv);
    void SubscribeForOwnNumber(sys::Service *serv, std::function<void(const std::string &)> callback);
    /*
     * @brief Its calls service-cellular for selected SIM own phone number.
     * @param serv pointer to caller service.
     */
    void RequestForOwnNumber(sys::Service *serv);
    /*
     * @brief It calls service-cellulat fo newtwork info
     * @param serv pointer to caller service.