Diff between 2d56d5e87b132b4f7ba33b87cebd1f0065e23325 and 54c07e307016863a6d9c7b5a330cda78d108b32c

Changed Files

File Additions Deletions Status
profiles/audio/manager.c +1 -0 modified
src/device.c +12 -2 modified
src/profile.c +21 -0 modified
src/profile.h +5 -0 modified

Full Patch

diff --git a/profiles/audio/manager.c b/profiles/audio/manager.c
index f59a2f3..19aeb24 100644
--- a/profiles/audio/manager.c
+++ b/profiles/audio/manager.c
@@ -327,6 +327,7 @@ static void media_server_remove(struct btd_adapter *adapter)
 
 static struct btd_profile a2dp_profile = {
 	.name		= "audio-a2dp",
+	.priority	= BTD_PROFILE_PRIORITY_MEDIUM,
 
 	.remote_uuids	= BTD_UUIDS(A2DP_SOURCE_UUID, A2DP_SINK_UUID,
 							ADVANCED_AUDIO_UUID),
diff --git a/src/device.c b/src/device.c
index 48970d2..3ca265e 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1313,6 +1313,13 @@ static struct btd_profile *find_connectable_profile(struct btd_device *dev,
 	return NULL;
 }
 
+static gint profile_prio_cmp(gconstpointer a, gconstpointer b)
+{
+	const struct btd_profile *p1 = a, *p2 = b;
+
+	return p1->priority - p2->priority;
+}
+
 static DBusMessage *connect_profiles(struct btd_device *dev, DBusMessage *msg,
 							const char *uuid)
 {
@@ -1351,8 +1358,11 @@ static DBusMessage *connect_profiles(struct btd_device *dev, DBusMessage *msg,
 	for (l = dev->profiles; l != NULL; l = g_slist_next(l)) {
 		p = l->data;
 
-		if (p->auto_connect)
-			dev->pending = g_slist_append(dev->pending, p);
+		if (!p->auto_connect)
+			continue;
+
+		dev->pending = g_slist_insert_sorted(dev->pending, p,
+							profile_prio_cmp);
 	}
 
 	if (!dev->pending)
diff --git a/src/profile.c b/src/profile.c
index aed36fc..abb5a53 100644
--- a/src/profile.c
+++ b/src/profile.c
@@ -1074,6 +1074,26 @@ static int parse_ext_opt(struct ext_profile *ext, const char *key,
 	return 0;
 }
 
+static gint get_priority(const struct btd_profile *p)
+{
+	if (strcasecmp(p->local_uuid, HFP_HS_UUID) == 0)
+		return BTD_PROFILE_PRIORITY_HIGH;
+
+	if (strcasecmp(p->local_uuid, HFP_AG_UUID) == 0)
+		return BTD_PROFILE_PRIORITY_HIGH;
+
+	if (strcasecmp(p->local_uuid, A2DP_SOURCE_UUID) == 0)
+		return BTD_PROFILE_PRIORITY_MEDIUM;
+
+	if (strcasecmp(p->local_uuid, A2DP_SINK_UUID) == 0)
+		return BTD_PROFILE_PRIORITY_MEDIUM;
+
+	if (strcasecmp(p->local_uuid, ADVANCED_AUDIO_UUID) == 0)
+		return BTD_PROFILE_PRIORITY_MEDIUM;
+
+	return BTD_PROFILE_PRIORITY_LOW;
+}
+
 static struct ext_profile *create_ext(const char *owner, const char *path,
 					const char *uuid,
 					DBusMessageIter *opts)
@@ -1118,6 +1138,7 @@ static struct ext_profile *create_ext(const char *owner, const char *path,
 	p = &ext->p;
 
 	p->name = ext->name;
+	p->priority = get_priority(p);
 	p->local_uuid = ext->uuid;
 
 	/* Typecast can't really be avoided here:
diff --git a/src/profile.h b/src/profile.h
index d7b1ba1..6991041 100644
--- a/src/profile.h
+++ b/src/profile.h
@@ -23,6 +23,10 @@
 
 #define BTD_UUIDS(args...) ((const char *[]) { args, NULL } )
 
+#define BTD_PROFILE_PRIORITY_LOW	0
+#define BTD_PROFILE_PRIORITY_MEDIUM	1
+#define BTD_PROFILE_PRIORITY_HIGH	2
+
 struct btd_profile;
 
 typedef void (*btd_profile_cb)(struct btd_profile *profile,
@@ -30,6 +34,7 @@ typedef void (*btd_profile_cb)(struct btd_profile *profile,
 
 struct btd_profile {
 	const char *name;
+	int priority;
 
 	const char *local_uuid;
 	const char **remote_uuids;