From 2214111f2ec88e38aa16341732785992682cb579 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 21 Dec 2015 18:06:10 +0100 Subject: [PATCH] broadband-mode: reload operator info if explicit operator selected When the user selects a specific operator to register to, try to refresh the registratoin information in the DBus interface before returning the successful reply to the user, so that the new operator info is available right away. https://bugs.freedesktop.org/show_bug.cgi?id=93398 --- src/mm-broadband-modem.c | 90 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 80 insertions(+), 10 deletions(-) diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 32a5eea..89d3cef 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -3707,12 +3707,69 @@ modem_3gpp_scan_networks (MMIfaceModem3gpp *self, /*****************************************************************************/ /* Register in network (3GPP interface) */ +typedef struct { + MMBroadbandModem *self; + GSimpleAsyncResult *result; + gboolean reload_registration_info; +} RegisterInNetworkContext; + +static void +register_in_network_context_complete_and_free (RegisterInNetworkContext *ctx) +{ + g_simple_async_result_complete (ctx->result); + g_object_unref (ctx->result); + g_object_unref (ctx->self); + g_slice_free (RegisterInNetworkContext, ctx); +} + static gboolean modem_3gpp_register_in_network_finish (MMIfaceModem3gpp *self, GAsyncResult *res, GError **error) { - return !!mm_base_modem_at_command_full_finish (MM_BASE_MODEM (self), res, error); + return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error); +} + +static void +after_cops_reload_current_registration_info (MMIfaceModem3gpp *self, + GAsyncResult *res, + RegisterInNetworkContext *ctx) +{ + GError *error = NULL; + + if (!mm_iface_modem_3gpp_reload_current_registration_info_finish (self, res, &error)) { + /* The main operator selection action succeed, we won't propagate this error */ + g_warning ("Couldn't reload registration info after operator selection: %s", error->message); + g_error_free (error); + } + + g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE); + register_in_network_context_complete_and_free (ctx); +} + +static void +cops_set_ready (MMBaseModem *self, + GAsyncResult *res, + RegisterInNetworkContext *ctx) +{ + GError *error = NULL; + + if (!mm_base_modem_at_command_full_finish (MM_BASE_MODEM (self), res, &error)) { + g_simple_async_result_take_error (ctx->result, error); + register_in_network_context_complete_and_free (ctx); + return; + } + + if (ctx->reload_registration_info) { + mm_iface_modem_3gpp_reload_current_registration_info ( + MM_IFACE_MODEM_3GPP (self), + (GAsyncReadyCallback)after_cops_reload_current_registration_info, + ctx); + return; + } + + g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE); + register_in_network_context_complete_and_free (ctx); } static void @@ -3722,19 +3779,32 @@ modem_3gpp_register_in_network (MMIfaceModem3gpp *self, GAsyncReadyCallback callback, gpointer user_data) { + RegisterInNetworkContext *ctx; gchar *command; + ctx = g_slice_new0 (RegisterInNetworkContext); + ctx->self = g_object_ref (self); + ctx->result = g_simple_async_result_new (G_OBJECT (self), + callback, + user_data, + modem_3gpp_register_in_network); + /* If the user sent a specific network to use, lock it in. */ - if (operator_id) + if (operator_id) { + /* We'll request to reload the info before returning, so that + * the new info is made available in the interface as soon as + * possible */ + ctx->reload_registration_info = TRUE; command = g_strdup_printf ("+COPS=1,2,\"%s\"", operator_id); - /* If no specific network was given, and the modem is not registered and not - * searching, kick it to search for a network. Also do auto registration if - * the modem had been set to manual registration last time but now is not. - */ - else - /* Note that '+COPS=0,,' (same but with commas) won't work in some Nokia + } else { + /* If no specific network was given, and the modem is not registered and not + * searching, kick it to search for a network. Also do auto registration if + * the modem had been set to manual registration last time but now is not. + * + * Note that '+COPS=0,,' (same but with commas) won't work in some Nokia * phones */ command = g_strdup ("+COPS=0"); + } mm_base_modem_at_command_full (MM_BASE_MODEM (self), mm_base_modem_peek_best_at_port (MM_BASE_MODEM (self), NULL), @@ -3743,8 +3813,8 @@ modem_3gpp_register_in_network (MMIfaceModem3gpp *self, FALSE, FALSE, /* raw */ cancellable, - callback, - user_data); + (GAsyncReadyCallback) cops_set_ready, + ctx); g_free (command); } -- 2.6.2