We can take care of it in Audio HAL but logically speaking since audio flinger calls add_audio_effect, it should also call remove_audio_effect. Tried below change to call setPreProcessorEnabled before release_input and seems to work but don't know if it is right thing to do. Now I see remove_audio_effect being called twice.
void AudioPolicyService::releaseInput(audio_io_handle_t input)
{
if (mpAudioPolicy == NULL) {
return;
}
Mutex::Autolock _l(mLock);
ssize_t index = mInputs.indexOfKey(input);
if (index >= 0) {
InputDesc *inputDesc = mInputs.valueAt(index);
setPreProcessorEnabled(inputDesc, false);
delete inputDesc;
}
mpAudioPolicy->release_input(mpAudioPolicy, input);
mInputs.removeItemsAt(index);