summaryrefslogtreecommitdiffstats
path: root/binding-bluetooth/bluetooth-manager.c
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-08-04 15:30:56 -0700
commit232f305c3f845fcd75918447fc7262a19fdd0399 (patch)
tree86954a8ae918f7bd2eda570408a7042eefafb303 /binding-bluetooth/bluetooth-manager.c
parentae84f859b95b5b32524529e2e0a0f8c93a5ad3e0 (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. Change-Id: Iadc78ca809f0c492d65e0f1cc59837a0f5d2fe45 Bug-AGL: SPEC-722 Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
Diffstat (limited to 'binding-bluetooth/bluetooth-manager.c')
-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);