summaryrefslogtreecommitdiffstats
path: root/binding-bluetooth
diff options
context:
space:
mode:
authorMatt Ranostay <matt.ranostay@konsulko.com>2017-07-26 22:10:04 -0700
committerMatt Ranostay <matt.ranostay@konsulko.com>2017-07-27 13:14:08 -0700
commita260014337f3686a5735ffaba7a79b595839a3f8 (patch)
tree384e87b11cc7a820b1ca4206fbf65a9ea8593fb5 /binding-bluetooth
parentd704861baac62d4a387731b7ea88bfad695b0a60 (diff)
binding: bluetooth: autoconnect to first paired device
Attempt to connect to the first paired device, and poll every 5 seconds till it is successful or another device is connected. Bug-AGL: SPEC-722 Change-Id: Ic32fbcc6eeb2f0d789d17da1f8722d49b869bc24 Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
Diffstat (limited to 'binding-bluetooth')
-rw-r--r--binding-bluetooth/bluetooth-manager.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/binding-bluetooth/bluetooth-manager.c b/binding-bluetooth/bluetooth-manager.c
index 13210bb..3038a6e 100644
--- a/binding-bluetooth/bluetooth-manager.c
+++ b/binding-bluetooth/bluetooth-manager.c
@@ -1066,6 +1066,52 @@ int BluetoothMonitorInit()
return 0;
}
+gboolean bt_autoconnect(gpointer ptr)
+{
+ LOGD("\n");
+ gboolean ret = TRUE;
+ GSList *list, *tmp;
+ gchar *bdaddr = NULL;
+
+ devices_list_lock();
+
+ list = GetBluezDevicesList();
+ tmp = list;
+
+ while (tmp)
+ {
+ struct bt_device *BDdevice = tmp->data;
+ tmp = tmp->next;
+
+ if (BDdevice->paired && bdaddr == NULL)
+ {
+ bdaddr = g_strdup(BDdevice->bdaddr);
+ }
+
+ if (BDdevice->connected)
+ {
+ g_slist_free_full(list, g_free);
+ devices_list_unlock();
+ return FALSE;
+ }
+ }
+
+ g_slist_free_full(list, g_free);
+ devices_list_unlock();
+
+ /*
+ * NOTE: Attempt to connect to first paired device, and once connected don't
+ * poll anymore.
+ */
+ if (bdaddr != NULL)
+ {
+ ret = device_connect(bdaddr, NULL) ? TRUE : FALSE;
+ g_free(bdaddr);
+ }
+
+ return ret;
+}
+
/*
* Bluetooth Manager Thread
* register callback function and create a new GMainLoop structure
@@ -1084,6 +1130,9 @@ static void *bt_event_loop_thread()
BluetoothManage_InitFlag_Set(TRUE);
BluetoothMonitorInit();
+
+ g_timeout_add_seconds(5, bt_autoconnect, NULL);
+
LOGD("g_main_loop_run\n");
g_main_loop_run(cli.clientloop);