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.
This commit is contained in:
Aleksander Morgado
2018-08-04 17:27:53 +02:00
committed by Dan Williams
parent 518d62e731
commit 59a5af9771

View File

@@ -2220,6 +2220,59 @@ mm_iface_modem_set_current_bands_finish (MMIfaceModem *self,
return g_task_propagate_boolean (G_TASK (res), error); 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 static void
set_current_bands_ready (MMIfaceModem *self, set_current_bands_ready (MMIfaceModem *self,
GAsyncResult *res, GAsyncResult *res,
@@ -2227,34 +2280,23 @@ set_current_bands_ready (MMIfaceModem *self,
{ {
GError *error = NULL; 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); 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_task_return_boolean (task, TRUE);
}
g_object_unref (task); g_object_unref (task);
return;
}
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;
}
/* Default to the ones we requested */
set_current_bands_complete_with_defaults (task);
} }
static gboolean static gboolean