bluetooth: don't connect on unconnected profile
authorMarc-André Lureau <marcandre.lureau@gmail.com>
Mon, 29 Jun 2009 14:46:30 +0000 (17:46 +0300)
committerLennart Poettering <lennart@poettering.net>
Wed, 1 Jul 2009 19:00:42 +0000 (21:00 +0200)
src/modules/bluetooth/module-bluetooth-device.c

index f7dbfd9..0560ef3 100644 (file)
@@ -2086,6 +2086,15 @@ static int add_card(struct userdata *u, const pa_bluetooth_device *device) {
     u->card->set_profile = card_set_profile;
 
     d = PA_CARD_PROFILE_DATA(u->card->active_profile);
+
+    if ((device->headset_state < PA_BT_AUDIO_STATE_CONNECTED && *d == PROFILE_HSP) ||
+        (device->audio_sink_state < PA_BT_AUDIO_STATE_CONNECTED && *d == PROFILE_A2DP)) {
+        pa_log_warn("Default profile not connected, selecting off profile");
+        u->card->active_profile = pa_hashmap_get(u->card->profiles, "off");
+        u->card->save_profile = FALSE;
+    }
+
+    d = PA_CARD_PROFILE_DATA(u->card->active_profile);
     u->profile = *d;
 
     return 0;