Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 946c0035 authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

APM: Fix config de-serialization

Audio Policy Manager and EngineConfig now try to load only one
readable APM config file. Previously they could try several
until one of them parses successfully. This could result in
loading of different files by APM and EC due to use of different
parts of the config.

Centralize finding of APM config file in audio_config.h.
This allows using the same logic in AudioPolicyManager.cpp
and EngineConfig.cpp which previously got duplicated
and later diverged.

Ensure that failed attempts to de-serialize config do not leave
APM or EC in a "dirty" state.

Bug: 171339398
Test: check audio on the device
Test: atest audiopolicy_engineconfig_tests
Test: atest audiopolicy_tests
Change-Id: I98c21ab03d869eb5f4259ea12cd433632cf6da5d
parent d6fe406c
Loading
Loading
Loading
Loading
+25 −6
Original line number Diff line number Diff line
@@ -33,6 +33,15 @@

namespace android {

// This class gathers together various bits of AudioPolicyManager
// configuration, which are usually filled out as a result of parsing
// the audio_policy_configuration.xml file.
//
// Note that AudioPolicyConfig doesn't own some of the data,
// it simply proxies access to the fields of AudioPolicyManager
// class. Be careful about the fields that are references,
// e.g. 'mOutputDevices'. This also means that it's impossible
// to implement "deep copying" of this class without re-designing it.
class AudioPolicyConfig
{
public:
@@ -40,14 +49,24 @@ public:
                      DeviceVector &outputDevices,
                      DeviceVector &inputDevices,
                      sp<DeviceDescriptor> &defaultOutputDevice)
        : mEngineLibraryNameSuffix(kDefaultEngineLibraryNameSuffix),
          mHwModules(hwModules),
        : mHwModules(hwModules),
          mOutputDevices(outputDevices),
          mInputDevices(inputDevices),
          mDefaultOutputDevice(defaultOutputDevice),
          mIsSpeakerDrcEnabled(false),
          mIsCallScreenModeSupported(false)
    {}
          mDefaultOutputDevice(defaultOutputDevice) {
        clear();
    }

    void clear() {
        mSource = {};
        mEngineLibraryNameSuffix = kDefaultEngineLibraryNameSuffix;
        mHwModules.clear();
        mOutputDevices.clear();
        mInputDevices.clear();
        mDefaultOutputDevice.clear();
        mIsSpeakerDrcEnabled = false;
        mIsCallScreenModeSupported = false;
        mSurroundFormats.clear();
    }

    const std::string& getSource() const {
        return mSource;
+4 −3
Original line number Diff line number Diff line
@@ -254,9 +254,8 @@ template <class T>
constexpr void (*xmlDeleter)(T* t);
template <>
constexpr auto xmlDeleter<xmlDoc> = xmlFreeDoc;
// http://b/111067277 - Add back constexpr when we switch to C++17.
template <>
auto xmlDeleter<xmlChar> = [](xmlChar *s) { xmlFree(s); };
constexpr auto xmlDeleter<xmlChar> = [](xmlChar *s) { xmlFree(s); };

/** @return a unique_ptr with the correct deleter for the libxml2 object. */
template <class T>
@@ -804,7 +803,9 @@ status_t PolicySerializer::deserialize(const char *configFile, AudioPolicyConfig
status_t deserializeAudioPolicyFile(const char *fileName, AudioPolicyConfig *config)
{
    PolicySerializer serializer;
    return serializer.deserialize(fileName, config);
    status_t status = serializer.deserialize(fileName, config);
    if (status != OK) config->clear();
    return status;
}

} // namespace android
+0 −1
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@

#include "EngineBase.h"
#include "EngineDefaultConfig.h"
#include "../include/EngineBase.h"
#include <TypeConverter.h>

namespace android {
+7 −0
Original line number Diff line number Diff line
{
  "presubmit": [
    {
       "name": "audiopolicy_engineconfig_tests"
    }
  ]
}
+2 −0
Original line number Diff line number Diff line
@@ -111,6 +111,8 @@ struct ParsingResult {
 */
ParsingResult parse(const char* path = DEFAULT_PATH);
android::status_t parseLegacyVolumes(VolumeGroups &volumeGroups);
// Exposed for testing.
android::status_t parseLegacyVolumeFile(const char* path, VolumeGroups &volumeGroups);

} // namespace engineConfig
} // namespace android
Loading