From aea30553b1546ee46c6c5e8b52639365643e3f2c Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Mon, 12 Feb 2024 14:57:07 -0500 Subject: [PATCH] kcms/mobiledata: Clarify behavior when networkmanager wwanEnabled is off In NetworkManager, there is a global "wwanEnabled" setting. We do not typically deal with this because toggling it off shuts off cellular in ModemManager (the mobile data toggle just disconnects the connection instead). Here we ensure that we address the case when "wwanEnabled" is off, and ensure that it's on when mobile data is toggled on. Also remove a check in the SIM page that seemed to depend on it. --- components/mmplugin/signalindicator.cpp | 41 +++++++++++++++++++------ kcms/cellularnetwork/modem.cpp | 40 ++++++++++++++++++------ kcms/cellularnetwork/ui/SimPage.qml | 4 +-- 3 files changed, 65 insertions(+), 20 deletions(-) diff --git a/components/mmplugin/signalindicator.cpp b/components/mmplugin/signalindicator.cpp index cff4dba3..226d733b 100644 --- a/components/mmplugin/signalindicator.cpp +++ b/components/mmplugin/signalindicator.cpp @@ -71,6 +71,11 @@ bool SignalIndicator::mobileDataSupported() const bool SignalIndicator::mobileDataEnabled() const { + // if wwan is globally disabled + if (!NetworkManager::isWwanEnabled()) { + return false; + } + // no modem -> no mobile data -> report disabled if (!m_nmModem) { return false; @@ -104,19 +109,20 @@ bool SignalIndicator::needsAPNAdded() const void SignalIndicator::setMobileDataEnabled(bool enabled) { + // ensure that wwan is on + if (enabled && !NetworkManager::isWwanEnabled()) { + NetworkManager::setWwanEnabled(true); + } + if (!m_nmModem) { return; } - if (!enabled) { - m_nmModem->setAutoconnect(false); - // we need to also set all connections to not autoconnect (#182) - for (NetworkManager::Connection::Ptr con : m_nmModem->availableConnections()) { - con->settings()->setAutoconnect(false); - con->update(con->settings()->toMap()); - } - m_nmModem->disconnectInterface(); - } else { + + if (enabled) { + // enable mobile data... + m_nmModem->setAutoconnect(true); + // activate the connection that was last used QDateTime latestTimestamp; NetworkManager::Connection::Ptr latestCon; @@ -131,6 +137,7 @@ void SignalIndicator::setMobileDataEnabled(bool enabled) latestCon = con; } } + // if we found the last used connection if (!latestCon.isNull()) { // set it to autoconnect and connect it immediately @@ -138,6 +145,22 @@ void SignalIndicator::setMobileDataEnabled(bool enabled) latestCon->update(latestCon->settings()->toMap()); NetworkManager::activateConnection(latestCon->path(), m_nmModem->uni(), ""); } + + } else { + // disable mobile data... + + // we do not call NetworkManager::setWwanEnabled(false), because it turns off cellular + + // turn off autoconnect + m_nmModem->setAutoconnect(false); + // we need to also set all connections to not autoconnect (#182) + for (NetworkManager::Connection::Ptr con : m_nmModem->availableConnections()) { + con->settings()->setAutoconnect(false); + con->update(con->settings()->toMap()); + } + + // disconnect network + m_nmModem->disconnectInterface(); } } diff --git a/kcms/cellularnetwork/modem.cpp b/kcms/cellularnetwork/modem.cpp index a0a90833..2de0c591 100644 --- a/kcms/cellularnetwork/modem.cpp +++ b/kcms/cellularnetwork/modem.cpp @@ -143,6 +143,11 @@ bool Modem::needsAPNAdded() const bool Modem::mobileDataEnabled() const { + // if wwan is globally disabled + if (!NetworkManager::isWwanEnabled()) { + return false; + } + // no modem -> no mobile data -> report disabled if (!m_nmModem) { return false; @@ -171,20 +176,20 @@ bool Modem::mobileDataEnabled() const void Modem::setMobileDataEnabled(bool enabled) { + // ensure that wwan is on + if (enabled && !NetworkManager::isWwanEnabled()) { + NetworkManager::setWwanEnabled(true); + } + if (!m_nmModem) { return; } - if (!enabled) { - m_nmModem->setAutoconnect(false); - // we need to also set all connections to not autoconnect (#182) - for (NetworkManager::Connection::Ptr con : m_nmModem->availableConnections()) { - con->settings()->setAutoconnect(false); - con->update(con->settings()->toMap()); - } - m_nmModem->disconnectInterface(); - } else { + if (enabled) { + // enable mobile data... + m_nmModem->setAutoconnect(true); + // activate the connection that was last used QDateTime latestTimestamp; NetworkManager::Connection::Ptr latestCon; @@ -199,6 +204,7 @@ void Modem::setMobileDataEnabled(bool enabled) latestCon = con; } } + // if we found the last used connection if (!latestCon.isNull()) { // set it to autoconnect and connect it immediately @@ -206,6 +212,22 @@ void Modem::setMobileDataEnabled(bool enabled) latestCon->update(latestCon->settings()->toMap()); NetworkManager::activateConnection(latestCon->path(), m_nmModem->uni(), ""); } + + } else { + // disable mobile data... + + // we do not call NetworkManager::setWwanEnabled(false), because it turns off cellular + + // turn off autoconnect + m_nmModem->setAutoconnect(false); + // we need to also set all connections to not autoconnect (#182) + for (NetworkManager::Connection::Ptr con : m_nmModem->availableConnections()) { + con->settings()->setAutoconnect(false); + con->update(con->settings()->toMap()); + } + + // disconnect network + m_nmModem->disconnectInterface(); } } diff --git a/kcms/cellularnetwork/ui/SimPage.qml b/kcms/cellularnetwork/ui/SimPage.qml index 30be0663..2e71f0d5 100644 --- a/kcms/cellularnetwork/ui/SimPage.qml +++ b/kcms/cellularnetwork/ui/SimPage.qml @@ -71,7 +71,7 @@ FormCard.FormCardPage { icon.name: "globe" text: i18n("Modify APNs") description: i18n("Configure access point names for your carrier.") - enabled: simEnabled && enabledConnections.wwanEnabled + enabled: simEnabled onClicked: kcm.push("ProfileList.qml", { "modem": sim.modem }); } @@ -93,7 +93,7 @@ FormCard.FormCardPage { icon.name: "unlock" text: i18n("SIM Lock") description: i18n("Modify SIM lock settings.") - // enabled: simEnabled + enabled: simEnabled onClicked: kcm.push("SimLockPage.qml", { "sim": sim }); }