From 59a5af9771b942ea6878e2f428635daae624f229 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Aug 2018 17:27:53 +0200 Subject: iface-modem: reload current bands after setting Setting bands is a very device-specific operation. Sometimes the device requires specific band combinations, or sometimes the 'any' specific logic doesn't apply to all supported bands (e.g. may apply only to the currently selected modes, as in XMM based devices). So, don't assume that if the set command succeeds we have set all expected bands. Instead, do an explicit loading of the current bands after the set operation, same thing as we do when setting modes. --- src/mm-iface-modem.c | 90 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 66 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index 11bdf1f6..03a680dd 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -2220,6 +2220,59 @@ mm_iface_modem_set_current_bands_finish (MMIfaceModem *self, return g_task_propagate_boolean (G_TASK (res), error); } +static void +set_current_bands_complete_with_defaults (GTask *task) +{ + SetCurrentBandsContext *ctx; + + ctx = g_task_get_task_data (task); + + /* Never show just 'any' in the interface */ + if (ctx->bands_array->len == 1 && g_array_index (ctx->bands_array, MMModemBand, 0) == MM_MODEM_BAND_ANY) { + GArray *supported_bands; + + supported_bands = (mm_common_bands_variant_to_garray (mm_gdbus_modem_get_supported_bands (ctx->skeleton))); + mm_common_bands_garray_sort (supported_bands); + mm_gdbus_modem_set_current_bands (ctx->skeleton, mm_common_bands_garray_to_variant (supported_bands)); + g_array_unref (supported_bands); + } else { + mm_common_bands_garray_sort (ctx->bands_array); + mm_gdbus_modem_set_current_bands (ctx->skeleton, mm_common_bands_garray_to_variant (ctx->bands_array)); + } + + g_task_return_boolean (task, TRUE); + g_object_unref (task); +} + +static void +after_set_load_current_bands_ready (MMIfaceModem *self, + GAsyncResult *res, + GTask *task) +{ + GError *error = NULL; + GArray *current_bands; + SetCurrentBandsContext *ctx; + + ctx = g_task_get_task_data (task); + + current_bands = MM_IFACE_MODEM_GET_INTERFACE (self)->load_current_bands_finish (self, res, &error); + if (!current_bands) { + /* Errors when getting bands won't be critical */ + mm_warn ("couldn't load current bands: '%s'", error->message); + g_error_free (error); + /* Default to the ones we requested */ + set_current_bands_complete_with_defaults (task); + return; + } + + mm_common_bands_garray_sort (current_bands); + mm_gdbus_modem_set_current_bands (ctx->skeleton, mm_common_bands_garray_to_variant (current_bands)); + g_array_unref (current_bands); + + g_task_return_boolean (task, TRUE); + g_object_unref (task); +} + static void set_current_bands_ready (MMIfaceModem *self, GAsyncResult *res, @@ -2227,34 +2280,23 @@ set_current_bands_ready (MMIfaceModem *self, { GError *error = NULL; - if (!MM_IFACE_MODEM_GET_INTERFACE (self)->set_current_bands_finish (self, res, &error)) + if (!MM_IFACE_MODEM_GET_INTERFACE (self)->set_current_bands_finish (self, res, &error)) { g_task_return_error (task, error); - else { - SetCurrentBandsContext *ctx; - - ctx = g_task_get_task_data (task); - - /* Never show just 'any' in the interface */ - if (ctx->bands_array->len == 1 && - g_array_index (ctx->bands_array, MMModemBand, 0) == MM_MODEM_BAND_ANY) { - GArray *supported_bands; - - supported_bands = (mm_common_bands_variant_to_garray ( - mm_gdbus_modem_get_supported_bands (ctx->skeleton))); - mm_common_bands_garray_sort (supported_bands); - mm_gdbus_modem_set_current_bands (ctx->skeleton, - mm_common_bands_garray_to_variant (supported_bands)); - g_array_unref (supported_bands); - } else { - mm_common_bands_garray_sort (ctx->bands_array); - mm_gdbus_modem_set_current_bands (ctx->skeleton, - mm_common_bands_garray_to_variant (ctx->bands_array)); - } + g_object_unref (task); + return; + } - g_task_return_boolean (task, TRUE); + if (MM_IFACE_MODEM_GET_INTERFACE (self)->load_current_bands && + MM_IFACE_MODEM_GET_INTERFACE (self)->load_current_bands_finish) { + MM_IFACE_MODEM_GET_INTERFACE (self)->load_current_bands ( + self, + (GAsyncReadyCallback)after_set_load_current_bands_ready, + task); + return; } - g_object_unref (task); + /* Default to the ones we requested */ + set_current_bands_complete_with_defaults (task); } static gboolean -- cgit v1.2.3-70-g09d2