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

Commit c60c3691 authored by François Gaffie's avatar François Gaffie Committed by Eric Laurent
Browse files

audiopolicy: engineconfigurable: fix potential segfault if no default device



If no default device is available from configuration.xml, and if
the engine fallbacks on it anyway, it tries to get its type without checking
the pointer validity.

This CL fix the potential segfault and assert with explicit error message.

Test: build

Change-Id: Icf8d7f5ef998dad6f4033d934b48d408030c7e17
Signed-off-by: default avatarFrançois Gaffie <francois.gaffie@renault.com>
parent bc5c7de7
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));