hal: Fix for no audio on BT headset till waiting call is ended.

-Issue: Voice call audio is not routing to BT headset
 though connected, till the waiting call is ended.
-Rootcause: During voice call, if another call is received, the
 audio mode is changed to MODE_RINGTONE. Due to this, the primary
 output on which the voice call is setup, is not able to find
 new device as BT in getNewdevice().
-Fix: Avoid mode change to MODE_RINGTONE when voice call is already
 active.

Change-Id: I38582e2500ff4c44eb5ac45dab3aab35606d1c7d
CRs-Fixed: 662883
diff --git a/policy_hal/AudioPolicyManager.cpp b/policy_hal/AudioPolicyManager.cpp
index b679fdb..a8cbcda 100644
--- a/policy_hal/AudioPolicyManager.cpp
+++ b/policy_hal/AudioPolicyManager.cpp
@@ -1558,8 +1558,8 @@
                                                   0 /* ignored */);
        }
     }
-    mPrevPhoneState = oldState;
 #endif
+    mPrevPhoneState = oldState;
 
     int delayMs = 0;
     if (isStateInCall(state)) {
@@ -1609,6 +1609,12 @@
     ALOGD(" End of setPhoneState ... mPhoneState: %d ",mPhoneState);
 }
 
+bool AudioPolicyManager::isStateInCall(int state)
+{
+    return ((state == AudioSystem::MODE_IN_CALL) || (state == AudioSystem::MODE_IN_COMMUNICATION) ||
+       ((state == AudioSystem::MODE_RINGTONE) && (mPrevPhoneState == AudioSystem::MODE_IN_CALL)));
+}
+
 extern "C" AudioPolicyInterface* createAudioPolicyManager(AudioPolicyClientInterface *clientInterface)
 {
     return new AudioPolicyManager(clientInterface);