policy_hal: fix for FM playback without active music stream
- Increase primary output ref count before getting new device
- This prevents to use NULL device for FM playback.
Change-Id: Idd2b36dab1990cdc1c1f603c5bdfd53b53c5c311
CRs-Fixed: 957807
diff --git a/policy_hal/AudioPolicyManager.cpp b/policy_hal/AudioPolicyManager.cpp
index 1b1578e..37cceab 100644
--- a/policy_hal/AudioPolicyManager.cpp
+++ b/policy_hal/AudioPolicyManager.cpp
@@ -280,12 +280,13 @@
#ifdef FM_POWER_OPT
// handle FM device connection state to trigger FM AFE loopback
if (device == AUDIO_DEVICE_OUT_FM && hasPrimaryOutput()) {
- audio_devices_t newDevice = getNewOutputDevice(mPrimaryOutput, false /*fromCache*/);
+ audio_devices_t newDevice = AUDIO_DEVICE_NONE;
if (state == AUDIO_POLICY_DEVICE_STATE_AVAILABLE) {
mPrimaryOutput->changeRefCount(AUDIO_STREAM_MUSIC, 1);
- newDevice = newDevice | AUDIO_DEVICE_OUT_FM;
+ newDevice = (audio_devices_t)(getNewOutputDevice(mPrimaryOutput, false)|AUDIO_DEVICE_OUT_FM);
mFMIsActive = true;
} else {
+ newDevice = (audio_devices_t)(getNewOutputDevice(mPrimaryOutput, false));
mFMIsActive = false;
mPrimaryOutput->changeRefCount(AUDIO_STREAM_MUSIC, -1);
}