diff options
author | Bastien Nocera <hadess@hadess.net> | 2015-02-03 21:27:32 +0100 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2015-02-03 23:07:31 +0100 |
commit | e37fcd1db10c1c1df619a5cb290678687481347e (patch) | |
tree | a837d5aa321225511fcc6262baa035b85bbaaba4 | |
parent | 3bade56d1fc1e75a6e8fda70330b4f4f9d7b3d2d (diff) | |
download | upower-e37fcd1db10c1c1df619a5cb290678687481347e.tar.gz |
linux: Defer getting iDevice info until ready
We're a bit too fast for usbmuxd to have noticed the USB device getting
plugged in, so defer until either the device is 1) noticed by usbmuxd
and 2) paired.
https://bugs.freedesktop.org/show_bug.cgi?id=88950
-rw-r--r-- | src/linux/up-device-idevice.c | 92 |
1 files changed, 56 insertions, 36 deletions
diff --git a/src/linux/up-device-idevice.c b/src/linux/up-device-idevice.c index b88fb1f..e6de0ea 100644 --- a/src/linux/up-device-idevice.c +++ b/src/linux/up-device-idevice.c @@ -43,6 +43,7 @@ struct UpDeviceIdevicePrivate { + guint start_id; idevice_t dev; lockdownd_client_t client; }; @@ -67,6 +68,52 @@ up_device_idevice_poll_cb (UpDeviceIdevice *idevice) return TRUE; } +static gboolean +start_poll_cb (UpDeviceIdevice *idevice) +{ + UpDevice *device = UP_DEVICE (idevice); + idevice_t dev = NULL; + lockdownd_client_t client = NULL; + char *uuid; + + g_object_get (G_OBJECT (idevice), "serial", &uuid, NULL); + g_assert (uuid); + + /* Connect to the device */ + if (idevice_new (&dev, uuid) != IDEVICE_E_SUCCESS) + goto out; + + g_free (uuid); + + if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake (dev, &client, "upower")) + goto out; + + /* Set up struct */ + idevice->priv->dev = dev; + idevice->priv->client = client; + + /* coldplug */ + if (up_device_idevice_refresh (device) == FALSE) + goto out; + + /* disconnect */ + g_clear_pointer (&idevice->priv->client, lockdownd_client_free); + + g_object_set (G_OBJECT (idevice), "is-present", TRUE, NULL); + + /* set up a poll */ + up_daemon_start_poll (G_OBJECT (idevice), (GSourceFunc) up_device_idevice_poll_cb); + + idevice->priv->start_id = 0; + return G_SOURCE_REMOVE; + +out: + g_clear_pointer (&client, lockdownd_client_free); + g_clear_pointer (&dev, idevice_free); + g_free (uuid); + return G_SOURCE_CONTINUE; +} + /** * up_device_idevice_coldplug: * @@ -79,30 +126,17 @@ up_device_idevice_coldplug (UpDevice *device) GUdevDevice *native; const gchar *uuid; const gchar *model; - idevice_t dev = NULL; - lockdownd_client_t client = NULL; UpDeviceKind kind; /* Is it an iDevice? */ native = G_UDEV_DEVICE (up_device_get_native (device)); if (g_udev_device_get_property_as_boolean (native, "USBMUX_SUPPORTED") == FALSE) - goto out; + return FALSE; /* Get the UUID */ uuid = g_udev_device_get_property (native, "ID_SERIAL_SHORT"); if (uuid == NULL) - goto out; - - /* Connect to the device */ - if (idevice_new (&dev, uuid) != IDEVICE_E_SUCCESS) - goto out; - - if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake (dev, &client, "upower")) - goto out; - - /* Set up struct */ - idevice->priv->dev = dev; - idevice->priv->client = client; + return FALSE; /* find the kind of device */ model = g_udev_device_get_property (native, "ID_MODEL"); @@ -120,33 +154,14 @@ up_device_idevice_coldplug (UpDevice *device) "vendor", g_udev_device_get_property (native, "ID_VENDOR"), "model", g_udev_device_get_property (native, "ID_MODEL"), "power-supply", FALSE, - "is-present", TRUE, + "is-present", FALSE, "is-rechargeable", TRUE, "has-history", TRUE, NULL); - /* coldplug */ - if (up_device_idevice_refresh (device) == FALSE) - goto out; - - /* disconnect */ - lockdownd_client_free (idevice->priv->client); - idevice->priv->client = NULL; + idevice->priv->start_id = g_timeout_add_seconds (1, (GSourceFunc) start_poll_cb, idevice); - /* set up a poll */ - up_daemon_start_poll (G_OBJECT (idevice), (GSourceFunc) up_device_idevice_poll_cb); return TRUE; - -out: - if (client != NULL) { - lockdownd_client_free (client); - idevice->priv->client = NULL; - } - if (dev != NULL) { - idevice_free (dev); - idevice->priv->dev = NULL; - } - return FALSE; } /** @@ -239,6 +254,11 @@ up_device_idevice_finalize (GObject *object) idevice = UP_DEVICE_IDEVICE (object); g_return_if_fail (idevice->priv != NULL); + if (idevice->priv->start_id > 0) { + g_source_remove (idevice->priv->start_id); + idevice->priv->start_id = 0; + } + up_daemon_stop_poll (object); if (idevice->priv->client != NULL) lockdownd_client_free (idevice->priv->client); |