base-bearer: report connection error on failed connection attempts

When a user-requested connection attempt fails, we not only return the
connection error to the user that requested it, we also publish the
specific connection error in DBus for others to check why the failure
happened.
This commit is contained in:
Aleksander Morgado
2021-05-18 16:00:35 +02:00
parent de6b1324cb
commit 7e8885d569

View File

@@ -242,6 +242,19 @@ connection_monitor_start (MMBaseBearer *self)
/*****************************************************************************/ /*****************************************************************************/
static void
bearer_update_connection_error (MMBaseBearer *self,
const GError *connection_error)
{
g_autoptr(GVariant) tuple = NULL;
if (connection_error)
tuple = mm_common_error_to_tuple (connection_error);
mm_gdbus_bearer_set_connection_error (MM_GDBUS_BEARER (self), tuple);
}
/*****************************************************************************/
static void static void
bearer_update_interface_stats (MMBaseBearer *self) bearer_update_interface_stats (MMBaseBearer *self)
{ {
@@ -815,9 +828,12 @@ connect_ready (MMBaseBearer *self,
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
/* Will launch disconnection */ /* Will launch disconnection */
launch_disconnect = TRUE; launch_disconnect = TRUE;
} else } else {
/* Update reported connection error before the status update */
bearer_update_connection_error (self, error);
bearer_update_status (self, MM_BEARER_STATUS_DISCONNECTED); bearer_update_status (self, MM_BEARER_STATUS_DISCONNECTED);
} }
}
/* Handle cancellations detected after successful connection */ /* Handle cancellations detected after successful connection */
else if (g_cancellable_is_cancelled (self->priv->connect_cancellable)) { else if (g_cancellable_is_cancelled (self->priv->connect_cancellable)) {
mm_obj_dbg (self, "connected, but need to disconnect"); mm_obj_dbg (self, "connected, but need to disconnect");
@@ -841,6 +857,8 @@ connect_ready (MMBaseBearer *self,
} }
if (launch_disconnect) { if (launch_disconnect) {
/* Update reported connection error before the status update */
bearer_update_connection_error (self, error);
bearer_update_status (self, MM_BEARER_STATUS_DISCONNECTING); bearer_update_status (self, MM_BEARER_STATUS_DISCONNECTING);
MM_BASE_BEARER_GET_CLASS (self)->disconnect ( MM_BASE_BEARER_GET_CLASS (self)->disconnect (
self, self,