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

Commit 5b27eb66 authored by Franois Gaffie's avatar Franois Gaffie Committed by android-build-merger
Browse files

audiopolicy: engineconfigurable: fix potential segfault if no default device am: c60c3691

am: 8bae8ca1

Change-Id: I83420b56e66adec630d348e5096e9aba973ff50e
parents f05f6c33 8bae8ca1
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@
#include <AudioIODescriptorInterface.h>
#include <ParameterManagerWrapper.h>

#include <media/TypeConverter.h>

using std::string;
using std::map;

@@ -244,9 +246,9 @@ DeviceVector Engine::getDevicesForProductStrategy(product_strategy_t ps) const
    }
    if (devices == AUDIO_DEVICE_NONE ||
            (devices & availableOutputDevicesType) == AUDIO_DEVICE_NONE) {
        devices = getApmObserver()->getDefaultOutputDevice()->type();
        ALOGE_IF(devices == AUDIO_DEVICE_NONE, "%s: no valid default device defined", __FUNCTION__);
        return DeviceVector(getApmObserver()->getDefaultOutputDevice());
        auto defaultDevice = getApmObserver()->getDefaultOutputDevice();
        ALOG_ASSERT(defaultDevice != nullptr, "no valid default device defined");
        return DeviceVector(defaultDevice);
    }
    if (/*device_distinguishes_on_address(devices)*/ devices == AUDIO_DEVICE_OUT_BUS) {
        // We do expect only one device for these types of devices
@@ -254,6 +256,14 @@ DeviceVector Engine::getDevicesForProductStrategy(product_strategy_t ps) const
        // If this criterion is not wished, need to ensure this device is available
        const String8 address(productStrategies.getDeviceAddressForProductStrategy(ps).c_str());
        ALOGV("%s:device 0x%x %s %d", __FUNCTION__, devices, address.c_str(), ps);
        auto busDevice = availableOutputDevices.getDevice(devices, address, AUDIO_FORMAT_DEFAULT);
        if (busDevice == nullptr) {
            ALOGE("%s:unavailable device 0x%x %s, fallback on default", __func__, devices,
                  address.c_str());
            auto defaultDevice = getApmObserver()->getDefaultOutputDevice();
            ALOG_ASSERT(defaultDevice != nullptr, "Default Output Device NOT available");
            return DeviceVector(defaultDevice);
        }
        return DeviceVector(availableOutputDevices.getDevice(devices,
                                                             address,
                                                             AUDIO_FORMAT_DEFAULT));