Merge "policy: close voip output when new output is opened by same voip client"
diff --git a/policy_hal/AudioPolicyManager.cpp b/policy_hal/AudioPolicyManager.cpp
index 7a323c9..ab933a0 100644
--- a/policy_hal/AudioPolicyManager.cpp
+++ b/policy_hal/AudioPolicyManager.cpp
@@ -1537,8 +1537,14 @@
         for (size_t i = 0; i < mOutputs.size(); i++) {
              sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
              if (desc->mFlags == (AUDIO_OUTPUT_FLAG_VOIP_RX | AUDIO_OUTPUT_FLAG_DIRECT)) {
-                 voip_pcm_already_in_use = true;
-                 ALOGD("VoIP PCM already in use");
+                 //close voip output if currently open by the same client with different device
+                 if (desc->mDirectClientSession == session &&
+                     desc->device() != device) {
+                     closeOutput(desc->mIoHandle);
+                 } else {
+                     voip_pcm_already_in_use = true;
+                     ALOGD("VoIP PCM already in use");
+                 }
                  break;
              }
         }