From d76cfa3814915cc12c7af9e7bdc4d7ac3dc71e49 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 8 Mar 2018 13:37:39 +0100 Subject: [PATCH] device: rework checking for bluetooth NAP connection in nm_device_update_metered() NAP connections are a bit special, in that they also have a [bridge] setting, but their connection.type is "bluetooth". The canonical way to check whether a bluetooth connection is of NAP type is by calling _nm_connection_get_setting_bluetooth_for_nap(). So, instead of checking for bluetooth.type "pan" or "dun", check the opposite and whether the connection is of NAP type. In practice it's the same, but let'check for NAP consistently via get_setting_bluetooth_for_nap(). --- src/devices/nm-device.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index ce02292079..23c8c9b500 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -12368,22 +12368,19 @@ nm_device_update_metered (NMDevice *self) * another device) we set GUESS_YES; for NAP (where we are sharing internet * to another device) we set GUESS_NO. We ignore WiMAX here as it’s no * longer supported by NetworkManager. */ - if (value == NM_METERED_INVALID && - nm_connection_is_type (connection, NM_SETTING_BLUETOOTH_SETTING_NAME)) { - NMSettingBluetooth *bt = nm_connection_get_setting_bluetooth (connection); - const gchar *bt_type = (bt != NULL) ? nm_setting_bluetooth_get_connection_type (bt) : NULL; + if ( value == NM_METERED_INVALID + && nm_connection_is_type (connection, NM_SETTING_BLUETOOTH_SETTING_NAME)) { - if ( nm_streq0 (bt_type, NM_SETTING_BLUETOOTH_TYPE_PANU) - || nm_streq0 (bt_type, NM_SETTING_BLUETOOTH_TYPE_DUN)) - value = NM_METERED_GUESS_YES; - else + if (_nm_connection_get_setting_bluetooth_for_nap (connection)) { + /* NAP types are not metered, but other types are. */ value = NM_METERED_GUESS_NO; + } else + value = NM_METERED_GUESS_YES; } if (value == NM_METERED_INVALID) { if ( nm_connection_is_type (connection, NM_SETTING_GSM_SETTING_NAME) - || nm_connection_is_type (connection, NM_SETTING_CDMA_SETTING_NAME) - || nm_connection_is_type (connection, NM_SETTING_BLUETOOTH_SETTING_NAME)) + || nm_connection_is_type (connection, NM_SETTING_CDMA_SETTING_NAME)) value = NM_METERED_GUESS_YES; else value = NM_METERED_GUESS_NO;