binding: bluetooth-pbap: cache contacts list on connection 11/19811/1
authorMatt Ranostay <matt.ranostay@konsulko.com>
Wed, 30 Jan 2019 02:20:52 +0000 (18:20 -0800)
committerMatt Ranostay <matt.ranostay@konsulko.com>
Wed, 30 Jan 2019 07:46:55 +0000 (23:46 -0800)
Populating the contacts list can take several seconds for the OBEX
transfer to complete. So to avoid phone UI delays service is started
at startup, and populates a cached version of contacts for clients.

Change-Id: I1687fc6bc075964b71be4515c5048bff1861b4ec
Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
binding/bluetooth-pbap-binding.c
conf.d/wgt/config.xml.in

index 5a7c140..2765f61 100644 (file)
@@ -39,6 +39,7 @@ static OrgBluezObexClient1 *client;
 static OrgBluezObexSession1 *session;
 static OrgBluezObexPhonebookAccess1 *phonebook;
 static GHashTable *xfer_queue;
+static GMutex cached_mutex;
 static GMutex xfer_queue_mutex;
 static GHashTable *xfer_complete;
 static GMutex xfer_complete_mutex;
@@ -47,6 +48,8 @@ static GMutex connected_mutex;
 static gboolean connected = FALSE;
 static afb_event_t status_event;
 
+json_object *cached_results = NULL;
+
 #define PBAP_UUID      "0000112f-0000-1000-8000-00805f9b34fb"
 
 #define INTERNAL       "int"
@@ -314,11 +317,20 @@ void contacts(afb_req_t request)
        if (!parse_max_entries_parameter(request, &max_entries))
                return;
 
-       org_bluez_obex_phonebook_access1_call_select_sync(
+       g_mutex_lock(&cached_mutex);
+
+       if (max_entries == -1 && cached_results) {
+               jresp = cached_results;
+               json_object_get(jresp);
+       } else {
+               org_bluez_obex_phonebook_access1_call_select_sync(
                        phonebook, INTERNAL, CONTACTS, NULL, NULL);
-       jresp = get_vcards(max_entries);
+               jresp = get_vcards(max_entries);
+       }
 
        afb_req_success(request, jresp, "contacts");
+
+       g_mutex_unlock(&cached_mutex);
 }
 
 void entry(afb_req_t request)
@@ -602,6 +614,17 @@ static gboolean is_pbap_dev_and_init(struct json_object *dev)
 
                        AFB_NOTICE("PBAP device connected: %s", address);
 
+                       g_mutex_lock(&cached_mutex);
+
+                       if (cached_results)
+                               json_object_put(cached_results);
+
+                       /* probably should be made async */
+                       org_bluez_obex_phonebook_access1_call_select_sync(
+                               phonebook, INTERNAL, CONTACTS, NULL, NULL);
+                       cached_results = get_vcards(-1);
+                       g_mutex_unlock(&cached_mutex);
+
                        return TRUE;
                }
                break;
@@ -728,6 +751,12 @@ static void process_connection_event(afb_api_t api, struct json_object *object)
 
        afb_event_push(status_event, jresp);
 
+       g_mutex_lock(&cached_mutex);
+       if (cached_results)
+               json_object_put(cached_results);
+       cached_results = NULL;
+       g_mutex_unlock(&cached_mutex);
+
        AFB_NOTICE("PBAP device disconnected: %s", address);
 }
 
index 161a39f..21040c8 100644 (file)
@@ -9,7 +9,7 @@
 
        <feature name="urn:AGL:widget:required-permission">
                <param name="urn:AGL:permission::public:hidden" value="required" />
-               <param name="urn:AGL:permission::public:no-htdocs" value="required" />
+               <param name="urn:AGL:permission::system:run-by-default" value="required" />
                <param name="http://tizen.org/privilege/internal/dbus" value="required" />
        </feature>