diff options
author | Matt Ranostay <matt.ranostay@konsulko.com> | 2018-11-05 20:06:10 -0800 |
---|---|---|
committer | Matt Ranostay <matt.ranostay@konsulko.com> | 2018-11-12 03:58:47 -0800 |
commit | 50078d83552f02051a5706b3dfea0953eff3a02b (patch) | |
tree | aff9a4308adb7c1a86be933b2320d263ece89d80 /binding/bluetooth-bluez.c | |
parent | 672d403da4fec2455c583b541e7dc10093889b48 (diff) |
binding: bluetooth: add autoconnect feature
Attempt connection on each paired device till one is successful
on startup.
Bug-AGL: SPEC-1630
Change-Id: I213876f65528d0eaeaa5b55a745f541b286f26b5
Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
Diffstat (limited to 'binding/bluetooth-bluez.c')
-rw-r--r-- | binding/bluetooth-bluez.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/binding/bluetooth-bluez.c b/binding/bluetooth-bluez.c index 37c4469..052ea7b 100644 --- a/binding/bluetooth-bluez.c +++ b/binding/bluetooth-bluez.c @@ -518,3 +518,50 @@ gboolean bluez_set_property(struct bluetooth_state *ns, return TRUE; } + +gboolean bluetooth_autoconnect(gpointer data) +{ + struct bluetooth_state *ns = data; + GError *error = NULL; + json_object *jresp, *jobj = NULL; + int i; + + jresp = object_properties(ns, &error); + + json_object_object_get_ex(jresp, "devices", &jobj); + + for (i = 0; i < json_object_array_length(jobj); i++) { + json_object *idx = json_object_array_get_idx(jobj, i); + json_object *props = NULL; + json_object_object_get_ex(idx, "properties", &props); + + if (props) { + json_object *paired = NULL; + json_object_object_get_ex(props, "paired", &paired); + + if (paired && json_object_get_boolean(paired)) { + GVariant *reply; + json_object *tmp = NULL; + const char *adapter, *device; + gchar *path; + + json_object_object_get_ex(idx, "device", &tmp); + device = json_object_get_string(tmp); + + json_object_object_get_ex(idx, "adapter", &tmp); + adapter = json_object_get_string(tmp); + + path = g_strconcat("/org/bluez/", adapter, "/", device, NULL); + + reply = bluez_call(ns, "device", path, "Connect", NULL, NULL); + g_free(path); + + if (reply) + return FALSE; + g_variant_unref(reply); + } + } + } + + return FALSE; +} |