~aleteoryx/muditaos

b6a46e879d1bcd382916c6cb66dcb95e1bb33a2a — RobertPiet 5 years ago fb36efb
[EGD-4960] registerVariableChange moved to Init section of apps
M module-apps/application-settings-new/ApplicationSettings.cpp => module-apps/application-settings-new/ApplicationSettings.cpp +13 -11
@@ 68,17 68,10 @@ namespace app
            Store::GSM::get()->sim == selectedSim) {
            selectedSimNumber = CellularServiceAPI::GetOwnNumber(this);
        }
        settings->registerValueChange(settings::operators_on,
                                      [this](const std::string &value) { operatorOnChanged(value); });

        settings->registerValueChange(::settings::Cellular::volte_on,
                                      [this](const std::string &value) { volteChanged(value); });
    }

    ApplicationSettingsNew::~ApplicationSettingsNew()
    {
        settings->unregisterValueChange(settings::operators_on);
        settings->unregisterValueChange(::settings::Cellular::volte_on);
    }

    // Invoked upon receiving data message


@@ 158,9 151,14 @@ namespace app

        setActiveWindow(gui::name::window::main_window);

        settings->registerValueChange(::settings::SystemProperties::lockPassHash, [this](std::string value) {
            lockPassHash = utils::getNumericValue<unsigned int>(value);
        });
        settings->registerValueChange(settings::operators_on,
                                      [this](const std::string &value) { operatorOnChanged(value); });
        settings->registerValueChange(::settings::Cellular::volte_on,
                                      [this](const std::string &value) { volteChanged(value); });
        settings->registerValueChange(
            ::settings::SystemProperties::lockPassHash,
            [this](std::string value) { lockPassHash = utils::getNumericValue<unsigned int>(value); },
            ::settings::SettingsScope::Global);

        return ret;
    }


@@ 272,17 270,20 @@ namespace app

    void ApplicationSettingsNew::operatorOnChanged(const std::string &value)
    {
        LOG_DEBUG("[ApplicationSettingsNew::operatorOnChanged] value=%s", value.c_str());
        if (!value.empty()) {
            operatorsOn = utils::getNumericValue<bool>(value);
        }
    }
    bool ApplicationSettingsNew::getOperatorsOn() const noexcept
    {
        LOG_DEBUG("[ApplicationSettingsNew::getOperatorsOn] %d", operatorsOn);
        return operatorsOn;
    }
    void ApplicationSettingsNew::setOperatorsOn(bool value)
    {
        operatorsOn = value;
        LOG_DEBUG("[ApplicationSettingsNew::setOperatorsOn] to %d", operatorsOn);
        settings->setValue(settings::operators_on, std::to_string(value));
    }



@@ 307,7 308,8 @@ namespace app
    void ApplicationSettingsNew::setLockPassHash(unsigned int value)
    {
        lockPassHash = value;
        settings->setValue(::settings::SystemProperties::lockPassHash, std::to_string(value));
        settings->setValue(
            ::settings::SystemProperties::lockPassHash, std::to_string(value), ::settings::SettingsScope::Global);
    }

    auto ApplicationSettingsNew::getCurrentValues() -> settingsInterface::ScreenLightSettings::Values

M module-apps/application-settings/ApplicationSettings.cpp => module-apps/application-settings/ApplicationSettings.cpp +9 -8
@@ 47,14 47,6 @@ namespace app
            switchWindow(app::sim_select);
            return msgHandled();
        });
        settings->registerValueChange(
            settings::SystemProperties::lockPassHash,
            [this](std::string value) { lockPassChanged(value); },
            settings::SettingsScope::Global);
        settings->registerValueChange(
            settings::SystemProperties::timeDateFormat,
            [this](std::string value) { timeDateChanged(value); },
            settings::SettingsScope::Global);
    }

    ApplicationSettings::~ApplicationSettings()


@@ 106,6 98,15 @@ namespace app
        if (ret != sys::ReturnCodes::Success)
            return ret;

        settings->registerValueChange(
            settings::SystemProperties::lockPassHash,
            [this](std::string value) { lockPassChanged(value); },
            settings::SettingsScope::Global);
        settings->registerValueChange(
            settings::SystemProperties::timeDateFormat,
            [this](std::string value) { timeDateChanged(value); },
            settings::SettingsScope::Global);

        createUserInterface();

        setActiveWindow(gui::name::window::main_window);

M module-services/service-appmgr/model/ApplicationManager.cpp => module-services/service-appmgr/model/ApplicationManager.cpp +8 -8
@@ 106,6 106,14 @@ namespace app::manager
    {
        registerMessageHandlers();
        blockingTimer->connect([this](sys::Timer &) { onPhoneLocked(); });
    }

    sys::ReturnCodes ApplicationManager::InitHandler()
    {
        blockingTimer->setInterval(default_application_locktime_ms);
        utils::localize.setFallbackLanguage(utils::localize.DefaultLanguage);
        utils::localize.setDisplayLanguage(displayLanguage);
        utils::localize.setInputLanguage(inputLanguage);
        settings->registerValueChange(
            settings::SystemProperties::displayLanguage,
            [this](std::string value) { displayLanguageChanged(value); },


@@ 118,14 126,6 @@ namespace app::manager
            settings::SystemProperties::lockTime,
            [this](std::string value) { lockTimeChanged(value); },
            settings::SettingsScope::Global);
    }

    sys::ReturnCodes ApplicationManager::InitHandler()
    {
        blockingTimer->setInterval(default_application_locktime_ms);
        utils::localize.setFallbackLanguage(utils::localize.DefaultLanguage);
        utils::localize.setDisplayLanguage(displayLanguage);
        utils::localize.setInputLanguage(inputLanguage);

        startSystemServices();
        startBackgroundApplications();

M module-services/service-cellular/ServiceCellular.cpp => module-services/service-cellular/ServiceCellular.cpp +2 -2
@@ 204,8 204,6 @@ ServiceCellular::ServiceCellular() : sys::Service(serviceName, "", cellularStack
        sys::Bus::SendMulticast(msg.value(), sys::BusChannels::ServiceCellularNotifications, this);
    };
    registerMessageHandlers();
    settings->registerValueChange(settings::Cellular::volte_on,
                                  [this](const std::string &value) { volteChanged(value); });
    packetData = std::make_unique<packet_data::PacketData>(*this);
    packetData->loadAPNSettings();
}


@@ 235,6 233,8 @@ sys::ReturnCodes ServiceCellular::InitHandler()
    board = EventManagerServiceAPI::GetBoard(this);

    state.set(this, State::ST::WaitForStartPermission);
    settings->registerValueChange(settings::Cellular::volte_on,
                                  [this](const std::string &value) { volteChanged(value); });
    return sys::ReturnCodes::Success;
}


M module-services/service-db/agents/settings/Settings.cpp => module-services/service-db/agents/settings/Settings.cpp +2 -0
@@ 163,6 163,7 @@ namespace settings
            LOG_INFO("Callback function on value change (%s) does not exist", path.to_string().c_str());
        }
        else {
            LOG_DEBUG("[Settings::unregisterValueChange] %s", path.to_string().c_str());
            cbValues.erase(it_cb);
        }



@@ 173,6 174,7 @@ namespace settings
    void Settings::unregisterValueChange()
    {
        for (auto it_cb : cbValues) {
            LOG_DEBUG("[Settings::unregisterValueChange] %s", it_cb.first.to_string().c_str());
            auto msg = std::make_shared<settings::Messages::UnregisterOnVariableChange>(it_cb.first);
            sendMsg(std::move(msg));
        }

M module-services/service-db/agents/settings/SettingsAgent.cpp => module-services/service-db/agents/settings/SettingsAgent.cpp +7 -0
@@ 211,11 211,13 @@ auto SettingsAgent::handleSetVariable(sys::Message *req) -> sys::MessagePointer
        auto oldValue = dbGetValue(path);
        if (oldValue.has_value() && oldValue.value() != value) {
            dbSetValue(path, value);
            LOG_DEBUG("[SettingsAgent::handleSetVariable] %s=%s", path.to_string().c_str(), value.c_str());
            for (auto regPath : variableChangeRecipents[path.to_string()]) {
                if (regPath.service != path.service) {
                    auto updateMsg =
                        std::make_shared<settings::Messages::VariableChanged>(regPath, value, oldValue.value_or(""));
                    sys::Bus::SendUnicast(std::move(updateMsg), regPath.service, parentService);
                    LOG_DEBUG("[SettingsAgent::handleSetVariable] notified service: %s", regPath.service.c_str());
                }
            }
        }


@@ 234,6 236,10 @@ auto SettingsAgent::handleRegisterOnVariableChange(sys::Message *req) -> sys::Me
                auto currentValue                         = dbGetValue(path).value_or("");
                auto msgValue = std::make_shared<::settings::Messages::VariableChanged>(path, currentValue, "");
                sys::Bus::SendUnicast(std::move(msgValue), msg->sender, parentService);
                LOG_DEBUG("[SettingsAgent::handleRegisterOnVariableChange] %s=%s to %s",
                          path.to_string().c_str(),
                          currentValue.c_str(),
                          msg->sender.c_str());
            }
            else {
                it->second.insert(path);


@@ 251,6 257,7 @@ auto SettingsAgent::handleUnregisterOnVariableChange(sys::Message *req) -> sys::
            auto it = variableChangeRecipents.find(path.to_string());
            if (variableChangeRecipents.end() != it) {
                it->second.erase(path);
                LOG_DEBUG("[SettingsAgent::handleUnregisterOnVariableChange] %s", path.to_string().c_str());
            }
        }
    }

M module-services/service-desktop/ServiceDesktop.cpp => module-services/service-desktop/ServiceDesktop.cpp +3 -2
@@ 29,8 29,6 @@ ServiceDesktop::ServiceDesktop() : sys::Service(service::name::service_desktop, 
    updateOS = std::make_unique<UpdateMuditaOS>(this);
    settings = std::make_unique<settings::Settings>(this);

    settings->registerValueChange(updateos::settings::history,
                                  [this](const std::string &value) { updateOS->setInitialHistory(value); });
}

ServiceDesktop::~ServiceDesktop()


@@ 115,6 113,9 @@ sys::ReturnCodes ServiceDesktop::InitHandler()
        return std::make_shared<sys::ResponseMessage>();
    });

    settings->registerValueChange(updateos::settings::history,
                                  [this](const std::string &value) { updateOS->setInitialHistory(value); });

    return (sys::ReturnCodes::Success);
}