Temporary workaround for the Play / Pause problem.

In lots of cases as soon as the car kit connects, we start
playing music. This is a bad user experience. We need to separate
key codes for play and pause in the media land - there is an open
bug for this. This will solve the problem but some one button
headsets send pause key when the user wants to start the music
(Sony DRB50), some send play key (Motorola S9, S7, LG, Sony HBH-DS980)
In the former case the user will have to press the key twice, the
latter will work fine. We could always have this code to check for
the class of the device (car vs headset) but thats fragile and
nothing prevents a headset from sending a pause on connection.
   We would need to implement AVRCP 1.3 and the headset would
also have to support this to get it right.
   This, I believe is a much better user experience and then our
current scenario where the music starts playing on connection.

Change-Id: Ibf6d47e32c3d8fa6d23c8913f9558e2fbd8883e6
diff --git a/audio/control.c b/audio/control.c
index 1674b0d..617b7c7 100644
--- a/audio/control.c
+++ b/audio/control.c
@@ -373,6 +373,15 @@
 		pressed = 1;
+#ifdef ANDROID
+	if ((operands[0] & 0x7F) == PAUSE_OP) {
+		if (!sink_is_streaming(control->dev)) {
+			DBG("AVRCP: Ignoring Pause key");
+			return;
+		}
+	}
 	for (i = 0; key_map[i].name != NULL; i++) {
 		uint8_t key_quirks;
diff --git a/audio/sink.c b/audio/sink.c
index 94fe9f2..ba9f27e 100644
--- a/audio/sink.c
+++ b/audio/sink.c
@@ -877,6 +877,16 @@
 	return FALSE;
+gboolean sink_is_streaming(struct audio_device *dev)
+	struct sink *sink = dev->sink;
+	if (sink_get_state(dev) == AVDTP_STATE_STREAMING)
+		return TRUE;
+	return FALSE;
 avdtp_state_t sink_get_state(struct audio_device *dev)
 	struct sink *sink = dev->sink;
diff --git a/audio/sink.h b/audio/sink.h
index 7b1902b..2d7f9e5 100644
--- a/audio/sink.h
+++ b/audio/sink.h
@@ -42,6 +42,7 @@
 struct sink *sink_init(struct audio_device *dev);
 void sink_unregister(struct audio_device *dev);
 gboolean sink_is_active(struct audio_device *dev);
+gboolean sink_is_streaming(struct audio_device *dev);
 avdtp_state_t sink_get_state(struct audio_device *dev);
 gboolean sink_new_stream(struct audio_device *dev, struct avdtp *session,
 				struct avdtp_stream *stream);