audiopolicy: Add more tests, fix issues found
Added tests that ensure correct initialization of APM.
Fixed issues:
-- UB in VolumeCurvesForStream::volIndexToDb due to not
checking that the pointer is non-null;
-- AudioInputDescriptor::open and SwAudioOutputDescriptor::open
were not checking that the returned IO handle is valid,
this was causing an infinite loop in
AudioPolicyManager::selectOutputForMusicEffects, added an
assertion.
-- Memory leak of VolumeCurves collection in APM.
Test: audiopolicy_tests
Change-Id: Ia4ecca1dd03b74d7f93720f042da05d5a0c74a6b
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.h b/services/audiopolicy/managerdefault/AudioPolicyManager.h
index 3659e34..611edec 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.h
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.h
@@ -17,6 +17,7 @@
#pragma once
#include <atomic>
+#include <memory>
#include <stdint.h>
#include <sys/types.h>
@@ -547,7 +548,7 @@
float mLastVoiceVolume; // last voice volume value sent to audio HAL
bool mA2dpSuspended; // true if A2DP output is suspended
- IVolumeCurvesCollection *mVolumeCurves; // Volume Curves per use case and device category
+ std::unique_ptr<IVolumeCurvesCollection> mVolumeCurves; // Volume Curves per use case and device category
EffectDescriptorCollection mEffects; // list of registered audio effects
sp<DeviceDescriptor> mDefaultOutputDevice; // output device selected by default at boot time
HwModuleCollection mHwModules; // contains only modules that have been loaded successfully