Fix race condition in authorizing audio connections

The current check for implicit authorization is if any other audio profile
is already connected. However, a the second profile might try to connect
right after we've gotten a positive authorization reply for the first one
but before the first profile has reached "connected" state. So just by
checking the connected state of other profiles we might get a false
negative for the decision of doing implicit authorization.

This patch adds a variable to the audio_device struct for keeping track of
if we've gotten a positive authorization reply that can be used in
addition to the "any other profiles" connected check. This variable gets
cleared when the (global audio) device state goes back to disconnected.
diff --git a/audio/device.c b/audio/device.c
index 3535257..f2ddd24 100644
--- a/audio/device.c
+++ b/audio/device.c
@@ -150,6 +150,9 @@
 	if (!state_str)
 		return;
 
+	if (new_state == AUDIO_STATE_DISCONNECTED)
+		dev->authorized = FALSE;
+
 	if (dev->priv->state == new_state) {
 		debug("state change attempted from %s to %s",
 							state_str, state_str);
@@ -679,6 +682,9 @@
 	struct audio_device *dev = user_data;
 	struct dev_priv *priv = dev->priv;
 
+	if (derr == NULL)
+		dev->authorized = TRUE;
+
 	while (priv->auths) {
 		struct service_auth *auth = priv->auths->data;
 
@@ -743,7 +749,7 @@
 	if (g_slist_length(priv->auths) > 1)
 		return 0;
 
-	if (audio_device_is_connected(dev)) {
+	if (dev->authorized || audio_device_is_connected(dev)) {
 		g_idle_add(auth_idle_cb, dev);
 		return 0;
 	}
diff --git a/audio/device.h b/audio/device.h
index 45c54e8..f4d8390 100644
--- a/audio/device.h
+++ b/audio/device.h
@@ -59,6 +59,7 @@
 	bdaddr_t dst;
 
 	gboolean auto_connect;
+	gboolean authorized;
 
 	struct headset *headset;
 	struct gateway *gateway;