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.
This commit is contained in:
Devin Lin 2024-02-12 14:57:07 -05:00
parent 5363853f66
commit aea30553b1
3 changed files with 65 additions and 20 deletions

View file

@ -71,6 +71,11 @@ bool SignalIndicator::mobileDataSupported() const
bool SignalIndicator::mobileDataEnabled() const bool SignalIndicator::mobileDataEnabled() const
{ {
// if wwan is globally disabled
if (!NetworkManager::isWwanEnabled()) {
return false;
}
// no modem -> no mobile data -> report disabled // no modem -> no mobile data -> report disabled
if (!m_nmModem) { if (!m_nmModem) {
return false; return false;
@ -104,19 +109,20 @@ bool SignalIndicator::needsAPNAdded() const
void SignalIndicator::setMobileDataEnabled(bool enabled) void SignalIndicator::setMobileDataEnabled(bool enabled)
{ {
// ensure that wwan is on
if (enabled && !NetworkManager::isWwanEnabled()) {
NetworkManager::setWwanEnabled(true);
}
if (!m_nmModem) { if (!m_nmModem) {
return; return;
} }
if (!enabled) {
m_nmModem->setAutoconnect(false); if (enabled) {
// we need to also set all connections to not autoconnect (#182) // enable mobile data...
for (NetworkManager::Connection::Ptr con : m_nmModem->availableConnections()) {
con->settings()->setAutoconnect(false);
con->update(con->settings()->toMap());
}
m_nmModem->disconnectInterface();
} else {
m_nmModem->setAutoconnect(true); m_nmModem->setAutoconnect(true);
// activate the connection that was last used // activate the connection that was last used
QDateTime latestTimestamp; QDateTime latestTimestamp;
NetworkManager::Connection::Ptr latestCon; NetworkManager::Connection::Ptr latestCon;
@ -131,6 +137,7 @@ void SignalIndicator::setMobileDataEnabled(bool enabled)
latestCon = con; latestCon = con;
} }
} }
// if we found the last used connection // if we found the last used connection
if (!latestCon.isNull()) { if (!latestCon.isNull()) {
// set it to autoconnect and connect it immediately // set it to autoconnect and connect it immediately
@ -138,6 +145,22 @@ void SignalIndicator::setMobileDataEnabled(bool enabled)
latestCon->update(latestCon->settings()->toMap()); latestCon->update(latestCon->settings()->toMap());
NetworkManager::activateConnection(latestCon->path(), m_nmModem->uni(), ""); 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();
} }
} }

View file

@ -143,6 +143,11 @@ bool Modem::needsAPNAdded() const
bool Modem::mobileDataEnabled() const bool Modem::mobileDataEnabled() const
{ {
// if wwan is globally disabled
if (!NetworkManager::isWwanEnabled()) {
return false;
}
// no modem -> no mobile data -> report disabled // no modem -> no mobile data -> report disabled
if (!m_nmModem) { if (!m_nmModem) {
return false; return false;
@ -171,20 +176,20 @@ bool Modem::mobileDataEnabled() const
void Modem::setMobileDataEnabled(bool enabled) void Modem::setMobileDataEnabled(bool enabled)
{ {
// ensure that wwan is on
if (enabled && !NetworkManager::isWwanEnabled()) {
NetworkManager::setWwanEnabled(true);
}
if (!m_nmModem) { if (!m_nmModem) {
return; return;
} }
if (!enabled) { if (enabled) {
m_nmModem->setAutoconnect(false); // enable mobile data...
// 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 {
m_nmModem->setAutoconnect(true); m_nmModem->setAutoconnect(true);
// activate the connection that was last used // activate the connection that was last used
QDateTime latestTimestamp; QDateTime latestTimestamp;
NetworkManager::Connection::Ptr latestCon; NetworkManager::Connection::Ptr latestCon;
@ -199,6 +204,7 @@ void Modem::setMobileDataEnabled(bool enabled)
latestCon = con; latestCon = con;
} }
} }
// if we found the last used connection // if we found the last used connection
if (!latestCon.isNull()) { if (!latestCon.isNull()) {
// set it to autoconnect and connect it immediately // set it to autoconnect and connect it immediately
@ -206,6 +212,22 @@ void Modem::setMobileDataEnabled(bool enabled)
latestCon->update(latestCon->settings()->toMap()); latestCon->update(latestCon->settings()->toMap());
NetworkManager::activateConnection(latestCon->path(), m_nmModem->uni(), ""); 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();
} }
} }

View file

@ -71,7 +71,7 @@ FormCard.FormCardPage {
icon.name: "globe" icon.name: "globe"
text: i18n("Modify APNs") text: i18n("Modify APNs")
description: i18n("Configure access point names for your carrier.") description: i18n("Configure access point names for your carrier.")
enabled: simEnabled && enabledConnections.wwanEnabled enabled: simEnabled
onClicked: kcm.push("ProfileList.qml", { "modem": sim.modem }); onClicked: kcm.push("ProfileList.qml", { "modem": sim.modem });
} }
@ -93,7 +93,7 @@ FormCard.FormCardPage {
icon.name: "unlock" icon.name: "unlock"
text: i18n("SIM Lock") text: i18n("SIM Lock")
description: i18n("Modify SIM lock settings.") description: i18n("Modify SIM lock settings.")
// enabled: simEnabled enabled: simEnabled
onClicked: kcm.push("SimLockPage.qml", { "sim": sim }); onClicked: kcm.push("SimLockPage.qml", { "sim": sim });
} }