Commit e37fcd1d authored by Bastien Nocera's avatar Bastien Nocera

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
parent 3bade56d
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment