From 2f87c99b28f7b9d6a5dbb232e4468d5ebcda0571 Mon Sep 17 00:00:00 2001
From: Ajay Panicker <apanicke@google.com>
Date: Thu, 5 Apr 2018 09:14:51 -0700
Subject: [PATCH] Check if socket is closed before getting presentation
 position

Bug: 76456293
Test: Listen to music on a device that supports delay reporting
Change-Id: I4ca1c31819594750a7beb1d11ca5b8d64a7f836c
---
 system/audio_a2dp_hw/src/audio_a2dp_hw.cc | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/system/audio_a2dp_hw/src/audio_a2dp_hw.cc b/system/audio_a2dp_hw/src/audio_a2dp_hw.cc
index d8c39b87c8b..a43a4fbaa21 100644
--- a/system/audio_a2dp_hw/src/audio_a2dp_hw.cc
+++ b/system/audio_a2dp_hw/src/audio_a2dp_hw.cc
@@ -742,6 +742,10 @@ static int a2dp_write_output_audio_config(struct a2dp_stream_common* common) {
 static int a2dp_get_presentation_position_cmd(struct a2dp_stream_common* common,
                                               uint64_t* bytes, uint16_t* delay,
                                               struct timespec* timestamp) {
+  if (common->ctrl_fd == AUDIO_SKT_DISCONNECTED) {  // Already disconnected
+    return -1;
+  }
+
   if (a2dp_command(common, A2DP_CTRL_GET_PRESENTATION_POSITION) < 0) {
     return -1;
   }
-- 
GitLab