Commit 314b775a authored by Chao Hu's avatar Chao Hu Committed by Chao Hu
Browse files

Fixed: #277 #467 #1242 #1301 #1319

parent 920bcbdc
Pipeline #290718 passed with stages
in 3 minutes and 31 seconds
......@@ -320,7 +320,7 @@ wifi_device_get_hotspot (CcWifiPanel *self,
if (nm_device_get_active_connection (device) == NULL)
return NULL;
c = net_device_get_find_connection (self->client, device);
c = net_device_get_find_connection (self->client, device, NULL);
if (c == NULL)
return NULL;
......
......@@ -106,7 +106,7 @@ device_off_switch_changed_cb (NetDeviceBluetooth *self)
if (self->updating_device)
return;
connection = net_device_get_find_connection (self->client, self->device);
connection = net_device_get_find_connection (self->client, self->device, NULL);
if (connection == NULL)
return;
......@@ -139,7 +139,7 @@ options_button_clicked_cb (NetDeviceBluetooth *self)
g_autoptr(GError) error = NULL;
NMConnection *connection;
connection = net_device_get_find_connection (self->client, self->device);
connection = net_device_get_find_connection (self->client, self->device, NULL);
uuid = nm_connection_get_uuid (connection);
cmdline = g_strdup_printf ("nm-connection-editor --edit %s", uuid);
g_debug ("Launching '%s'\n", cmdline);
......
......@@ -444,7 +444,7 @@ device_off_switch_changed_cb (NetDeviceEthernet *self)
return;
if (gtk_switch_get_active (self->device_off_switch)) {
connection = net_device_get_find_connection (self->client, self->device);
connection = net_device_get_find_connection (self->client, self->device, NULL);
if (connection != NULL) {
nm_client_activate_connection_async (self->client,
connection,
......
......@@ -363,7 +363,7 @@ nm_device_mobile_refresh_ui (NetDeviceMobile *self)
gtk_label_set_label (self->status_label, status);
/* sensitive for other connection types if the device is currently connected */
is_connected = net_device_get_find_connection (self->client, self->device) != NULL;
is_connected = net_device_get_find_connection (self->client, self->device, NULL) != NULL;
gtk_widget_set_sensitive (GTK_WIDGET (self->options_button), is_connected);
caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (self->device));
......@@ -483,11 +483,26 @@ device_off_switch_changed_cb (NetDeviceMobile *self)
gint i;
NMActiveConnection *a;
NMConnection *connection;
g_autofree gchar *object_path = NULL;
gboolean ret;
GtkTreeIter iter;
GtkTreeModel *model;
if (self->updating_device)
return;
connection = net_device_get_find_connection (self->client, self->device);
ret = gtk_combo_box_get_active_iter (self->network_combo, &iter);
if (!ret)
return;
/* get entry */
model = gtk_combo_box_get_model (self->network_combo);
/*Get the APN profile's uuid when we selected in combo, it must be matched while connetion*/
gtk_tree_model_get (model, &iter,
COLUMN_ID, &object_path,
-1);
connection = net_device_get_find_connection (self->client, self->device, object_path);
if (connection == NULL)
return;
......@@ -520,7 +535,7 @@ options_button_clicked_cb (NetDeviceMobile *self)
g_autoptr(GError) error = NULL;
NMConnection *connection;
connection = net_device_get_find_connection (self->client, self->device);
connection = net_device_get_find_connection (self->client, self->device, NULL);
uuid = nm_connection_get_uuid (connection);
cmdline = g_strdup_printf ("nm-connection-editor --edit %s", uuid);
g_debug ("Launching '%s'\n", cmdline);
......
......@@ -124,7 +124,7 @@ static NMConnection *
find_connection_for_device (NetDeviceWifi *self,
NMDevice *device)
{
return net_device_get_find_connection (self->client, device);
return net_device_get_find_connection (self->client, device, NULL);
}
static gboolean
......
......@@ -265,7 +265,7 @@ device_state_reason_to_localized_string (NMDevice *device)
}
static gchar *
get_mac_address_of_connection (NMConnection *connection)
get_mac_or_id_of_connection (NMConnection *connection, const gchar *setting_uuid)
{
if (!connection)
return NULL;
......@@ -285,31 +285,57 @@ get_mac_address_of_connection (NMConnection *connection)
if (!s_wired)
return NULL;
return g_strdup (nm_setting_wired_get_mac_address (s_wired));
} else if (nm_connection_is_type (connection,
NM_SETTING_GSM_SETTING_NAME)) {
/* check gsm settings */
/* setting seleted APN profile's uuid must be matched with connection*/
/* many APN profiles could have the same device id, but each APN profile has a unique uuid*/
if (g_strcmp0 (nm_connection_get_uuid (connection), setting_uuid) != 0)
return NULL;
NMSettingGsm *s_gsm = nm_connection_get_setting_gsm (connection);
if (!s_gsm)
return NULL;
return g_strdup (nm_setting_gsm_get_device_id (s_gsm));
}
/* no MAC address found */
return NULL;
}
static const gchar *
get_mac_or_id_of_device (NMDevice *device)
{
const gchar *mac_or_id = NULL;
if (nm_device_get_device_type (device) == NM_DEVICE_TYPE_MODEM) {
NMDeviceModem *device_modem = NM_DEVICE_MODEM (device);
mac_or_id = nm_device_modem_get_device_id (device_modem);
} else {
mac_or_id = nm_device_get_hw_address (device);
}
/* no MAC address or id found */
return mac_or_id;
}
/* returns TRUE if both MACs are equal */
static gboolean
compare_mac_device_with_mac_connection (NMDevice *device,
NMConnection *connection)
compare_device_with_connection (NMDevice *device,
NMConnection *connection,
const gchar *setting_uuid)
{
const gchar *mac_dev = NULL;
g_autofree gchar *mac_conn = NULL;
mac_dev = nm_device_get_hw_address (device);
if (mac_dev == NULL)
const gchar *mac_or_id_dev = NULL;
g_autofree gchar *mac_or_id_conn = NULL;
mac_or_id_dev = get_mac_or_id_of_device (device);
if (mac_or_id_dev == NULL)
return FALSE;
mac_conn = get_mac_address_of_connection (connection);
if (mac_conn == NULL)
/*setting_uuid just for modem connection*/
mac_or_id_conn = get_mac_or_id_of_connection (connection, setting_uuid);
if (mac_or_id_conn == NULL)
return FALSE;
/* compare both MACs */
return g_strcmp0 (mac_dev, mac_conn) == 0;
return g_strcmp0 (mac_or_id_dev, mac_or_id_conn) == 0;
}
gchar *
panel_device_status_to_localized_string (NMDevice *nm_device,
const gchar *speed)
......@@ -356,7 +382,7 @@ panel_device_status_to_localized_string (NMDevice *nm_device,
}
NMConnection *
net_device_get_find_connection (NMClient *client, NMDevice *device)
net_device_get_find_connection (NMClient *client, NMDevice *device, const gchar *setting_uuid)
{
GSList *list, *iterator;
NMConnection *connection = NULL;
......@@ -379,8 +405,9 @@ net_device_get_find_connection (NMClient *client, NMDevice *device)
/* is there connection with the MAC address of the device? */
for (iterator = list; iterator; iterator = iterator->next) {
connection = iterator->data;
if (compare_mac_device_with_mac_connection (device,
connection)) {
if (compare_device_with_connection(device,
connection,
setting_uuid)) {
goto out;
}
}
......
......@@ -29,7 +29,8 @@ gchar *panel_device_status_to_localized_string (NMDevice *nm_dev
const gchar *speed);
NMConnection *net_device_get_find_connection (NMClient *client,
NMDevice *device);
NMDevice *device,
const gchar *setting_uuid);
GSList *net_device_get_valid_connections (NMClient *client,
NMDevice *device);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment