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

Commit 53b810ea authored by Eric Laurent's avatar Eric Laurent
Browse files

audio policy: fix device address passed when opening HAL streams

Commit fe231127 caused a regression where the device address is
not passed properly to audio HAL by openInputStream() or
openOutputStream(). The address must be read from available
device descriptors, not supported devices in profiles which do not
have the current device address for removable devices.

Bug: 70321528
Test: audio smoke tests,CTS  AudioRecordTest
Change-Id: I83211a31f86391b80c3c244b436a2e36923ccea0
parent 5fb93fa2
Loading
Loading
Loading
Loading
+2 −10
Original line number Diff line number Diff line
@@ -206,24 +206,16 @@ status_t AudioInputDescriptor::open(const audio_config_t *config,
        lConfig = *config;
    }

    String8 lAddress = address;
    if (lAddress == "") {
        const DeviceVector& supportedDevices = mProfile->getSupportedDevices();
        const DeviceVector& devicesForType = supportedDevices.getDevicesFromType(device);
        lAddress = devicesForType.size() > 0 ? devicesForType.itemAt(0)->mAddress
                  : String8("");
    }

    mDevice = device;

    ALOGV("opening input for device %08x address %s profile %p name %s",
          mDevice, lAddress.string(), mProfile.get(), mProfile->getName().string());
          mDevice, address.string(), mProfile.get(), mProfile->getName().string());

    status_t status = mClientInterface->openInput(mProfile->getModuleHandle(),
                                                  input,
                                                  &lConfig,
                                                  &mDevice,
                                                  lAddress,
                                                  address,
                                                  source,
                                                  flags);
    LOG_ALWAYS_FATAL_IF(mDevice != device,
+2 −10
Original line number Diff line number Diff line
@@ -398,14 +398,6 @@ status_t SwAudioOutputDescriptor::open(const audio_config_t *config,
        lConfig = *config;
    }

    String8 lAddress = address;
    if (lAddress == "") {
        const DeviceVector& supportedDevices = mProfile->getSupportedDevices();
        const DeviceVector& devicesForType = supportedDevices.getDevicesFromType(device);
        lAddress = devicesForType.size() > 0 ? devicesForType.itemAt(0)->mAddress
                  : String8("");
    }

    mDevice = device;
    // if the selected profile is offloaded and no offload info was specified,
    // create a default one
@@ -425,13 +417,13 @@ status_t SwAudioOutputDescriptor::open(const audio_config_t *config,
    mFlags = (audio_output_flags_t)(mFlags | flags);

    ALOGV("opening output for device %08x address %s profile %p name %s",
          mDevice, lAddress.string(), mProfile.get(), mProfile->getName().string());
          mDevice, address.string(), mProfile.get(), mProfile->getName().string());

    status_t status = mClientInterface->openOutput(mProfile->getModuleHandle(),
                                                   output,
                                                   &lConfig,
                                                   &mDevice,
                                                   lAddress,
                                                   address,
                                                   &mLatency,
                                                   mFlags);
    LOG_ALWAYS_FATAL_IF(mDevice != device,
+20 −2
Original line number Diff line number Diff line
@@ -918,7 +918,12 @@ audio_io_handle_t AudioPolicyManager::getOutputForDevice(
        }

        outputDesc = new SwAudioOutputDescriptor(profile, mpClientInterface);
        status = outputDesc->open(config, device, String8(""), stream, flags, &output);

        DeviceVector outputDevices = mAvailableOutputDevices.getDevicesFromType(device);
        String8 address = outputDevices.size() > 0 ? outputDevices.itemAt(0)->mAddress
                : String8("");

        status = outputDesc->open(config, device, address, stream, flags, &output);

        // only accept an output with the requested parameters
        if (status != NO_ERROR ||
@@ -1678,6 +1683,12 @@ audio_io_handle_t AudioPolicyManager::getInputForDevice(audio_devices_t device,
    lConfig.channel_mask = profileChannelMask;
    lConfig.format = profileFormat;

    if (address == "") {
        DeviceVector inputDevices = mAvailableInputDevices.getDevicesFromType(device);
        // the inputs vector must be of size >= 1, but we don't want to crash here
        address = inputDevices.size() > 0 ? inputDevices.itemAt(0)->mAddress : String8("");
    }

    status_t status = inputDesc->open(&lConfig, device, address,
            halInputSource, profileFlags, &input);

@@ -3588,10 +3599,17 @@ AudioPolicyManager::AudioPolicyManager(AudioPolicyClientInterface *clientInterfa
            sp<AudioInputDescriptor> inputDesc =
                    new AudioInputDescriptor(inProfile, mpClientInterface);

            DeviceVector inputDevices = mAvailableInputDevices.getDevicesFromType(profileType);
            //   the inputs vector must be of size >= 1, but we don't want to crash here
            String8 address = inputDevices.size() > 0 ? inputDevices.itemAt(0)->mAddress
                    : String8("");
            ALOGV("  for input device 0x%x using address %s", profileType, address.string());
            ALOGE_IF(inputDevices.size() == 0, "Input device list is empty!");

            audio_io_handle_t input = AUDIO_IO_HANDLE_NONE;
            status_t status = inputDesc->open(nullptr,
                                              profileType,
                                              String8(""),
                                              address,
                                              AUDIO_SOURCE_MIC,
                                              AUDIO_INPUT_FLAG_NONE,
                                              &input);