mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-06-29 18:42:07 +08:00
networking: network type function (#21732)
* debug known connections * print type * on mobile if no wifi and a sim card * clean up * debug primary connection * network type * not specifying current suggests you can pass it a path * debug debug Revert "debug" This reverts commit fe4748aa4df77449e1887685aa958ae2b89b88d0. hotspot check This reverts commit 5d2fc5f3bba45c87af8322766e426e8adee64ead. Revert "Revert "Revert "debug""" This reverts commit 6115204d5013ae5d613add92c1dded7a8f5cadbc. hotspot check * fixes old-commit-hash: 905138054b3e08103d8bd1ee9108697c0e281a0f
This commit is contained in:
@@ -117,8 +117,7 @@ QString WifiManager::get_ipv4_address() {
|
||||
}
|
||||
QVector<QDBusObjectPath> conns = get_active_connections();
|
||||
for (auto &p : conns) {
|
||||
QString active_connection = p.path();
|
||||
QDBusInterface nm(NM_DBUS_SERVICE, active_connection, NM_DBUS_INTERFACE_PROPERTIES, bus);
|
||||
QDBusInterface nm(NM_DBUS_SERVICE, p.path(), NM_DBUS_INTERFACE_PROPERTIES, bus);
|
||||
nm.setTimeout(DBUS_TIMEOUT);
|
||||
|
||||
QDBusObjectPath pth = get_response<QDBusObjectPath>(nm.call("Get", NM_DBUS_INTERFACE_ACTIVE_CONNECTION, "Ip4Config"));
|
||||
@@ -391,6 +390,33 @@ void WifiManager::activateWifiConnection(const QString &ssid) {
|
||||
}
|
||||
}
|
||||
|
||||
// function matches tici/hardware.py
|
||||
NetworkType WifiManager::currentNetworkType() {
|
||||
QDBusInterface nm(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE_PROPERTIES, bus);
|
||||
nm.setTimeout(DBUS_TIMEOUT);
|
||||
const QDBusObjectPath &path = get_response<QDBusObjectPath>(nm.call("Get", NM_DBUS_INTERFACE, "PrimaryConnection"));
|
||||
|
||||
QDBusInterface nm2(NM_DBUS_SERVICE, path.path(), NM_DBUS_INTERFACE_PROPERTIES, bus);
|
||||
nm.setTimeout(DBUS_TIMEOUT);
|
||||
const QString &type = get_response<QString>(nm2.call("Get", NM_DBUS_INTERFACE_ACTIVE_CONNECTION, "Type"));
|
||||
|
||||
if (type == "802-3-ethernet") {
|
||||
return NetworkType::ETHERNET;
|
||||
} else if (type == "802-11-wireless" && !isTetheringEnabled()) {
|
||||
return NetworkType::WIFI;
|
||||
} else {
|
||||
for (const QDBusObjectPath &path : get_active_connections()) {
|
||||
QDBusInterface nm3(NM_DBUS_SERVICE, path.path(), NM_DBUS_INTERFACE_PROPERTIES, bus);
|
||||
nm3.setTimeout(DBUS_TIMEOUT);
|
||||
const QString &type = get_response<QString>(nm3.call("Get", NM_DBUS_INTERFACE_ACTIVE_CONNECTION, "Type"));
|
||||
if (type == "gsm") {
|
||||
return NetworkType::CELL;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NetworkType::NONE;
|
||||
}
|
||||
|
||||
// Functions for tethering
|
||||
void WifiManager::addTetheringConnection() {
|
||||
Connection connection;
|
||||
|
||||
@@ -10,11 +10,17 @@ enum class SecurityType {
|
||||
WPA,
|
||||
UNSUPPORTED
|
||||
};
|
||||
enum class ConnectedType{
|
||||
enum class ConnectedType {
|
||||
DISCONNECTED,
|
||||
CONNECTING,
|
||||
CONNECTED
|
||||
};
|
||||
enum class NetworkType {
|
||||
NONE,
|
||||
WIFI,
|
||||
CELL,
|
||||
ETHERNET
|
||||
};
|
||||
|
||||
typedef QMap<QString, QMap<QString, QVariant>> Connection;
|
||||
typedef QVector<QMap<QString, QVariant>> IpConfig;
|
||||
@@ -42,6 +48,7 @@ public:
|
||||
void forgetConnection(const QString &ssid);
|
||||
bool isKnownConnection(const QString &ssid);
|
||||
void activateWifiConnection(const QString &ssid);
|
||||
NetworkType currentNetworkType();
|
||||
|
||||
void connect(const Network &ssid);
|
||||
void connect(const Network &ssid, const QString &password);
|
||||
|
||||
Reference in New Issue
Block a user