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

Commit f9003628 authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

audiopolicy: Remove global static initializers

Replace global static instances of non-primitive
types with function static instances. The latter
get initialized on the first call to the function
instead of module load time.

This also gets rid of ASAN UAF errors reported
during unit test execution.

Bug: 150649241
Test: atest audiopolicy_tests
Test: atest audio_health_tests
  (for ASAN-instrumented libraries and test)
Change-Id: I514c9205b9d3e7a3f0a1d8aa71d71fcc792e7a7b
parent c62ad13a
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -33,7 +33,10 @@

namespace android {

DeviceTypeSet APM_AUDIO_OUT_DEVICE_REMOTE_ALL = {AUDIO_DEVICE_OUT_REMOTE_SUBMIX};
static const DeviceTypeSet& getAllOutRemoteDevices() {
    static const DeviceTypeSet allOutRemoteDevices = {AUDIO_DEVICE_OUT_REMOTE_SUBMIX};
    return allOutRemoteDevices;
}

AudioOutputDescriptor::AudioOutputDescriptor(const sp<PolicyAudioPort>& policyAudioPort,
                                             AudioPolicyClientInterface *clientInterface)
@@ -681,7 +684,7 @@ bool SwAudioOutputCollection::isActiveLocally(VolumeSource volumeSource, uint32_
        const sp<SwAudioOutputDescriptor> outputDesc = this->valueAt(i);
        if (outputDesc->isActive(volumeSource, inPastMs, sysTime)
                && (!(outputDesc->devices()
                        .containsDeviceAmongTypes(APM_AUDIO_OUT_DEVICE_REMOTE_ALL)))) {
                        .containsDeviceAmongTypes(getAllOutRemoteDevices())))) {
            return true;
        }
    }
@@ -693,7 +696,7 @@ bool SwAudioOutputCollection::isActiveRemotely(VolumeSource volumeSource, uint32
    nsecs_t sysTime = systemTime();
    for (size_t i = 0; i < size(); i++) {
        const sp<SwAudioOutputDescriptor> outputDesc = valueAt(i);
        if (outputDesc->devices().containsDeviceAmongTypes(APM_AUDIO_OUT_DEVICE_REMOTE_ALL) &&
        if (outputDesc->devices().containsDeviceAmongTypes(getAllOutRemoteDevices()) &&
                outputDesc->isActive(volumeSource, inPastMs, sysTime)) {
            // do not consider re routing (when the output is going to a dynamic policy)
            // as "remote playback"
+19 −15
Original line number Diff line number Diff line
@@ -41,7 +41,8 @@ namespace audio_policy
{

struct legacy_strategy_map { const char *name; legacy_strategy id; };
static const std::vector<legacy_strategy_map> gLegacyStrategy = {
static const std::vector<legacy_strategy_map>& getLegacyStrategy() {
    static const std::vector<legacy_strategy_map> legacyStrategy = {
        { "STRATEGY_NONE", STRATEGY_NONE },
        { "STRATEGY_MEDIA", STRATEGY_MEDIA },
        { "STRATEGY_PHONE", STRATEGY_PHONE },
@@ -55,6 +56,8 @@ static const std::vector<legacy_strategy_map> gLegacyStrategy = {
        { "STRATEGY_PATCH", STRATEGY_REROUTING }, // boiler to manage stream patch volume
        { "STRATEGY_CALL_ASSISTANT", STRATEGY_CALL_ASSISTANT },
    };
    return legacyStrategy;
}

Engine::Engine()
{
@@ -63,7 +66,8 @@ Engine::Engine()
             "Policy Engine configuration is partially invalid, skipped %zu elements",
             result.nbSkippedElement);

    for (const auto &strategy : gLegacyStrategy) {
    auto legacyStrategy = getLegacyStrategy();
    for (const auto &strategy : legacyStrategy) {
        mLegacyStrategyMap[getProductStrategyByName(strategy.name)] = strategy.id;
    }
}