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

Commit 325a8eb3 authored by Carter Hsu's avatar Carter Hsu
Browse files

audio: add API for querying the Ultrasound support



Bug: 200256985
Test: Check the return value with/without the Ultrasound
Output/Input in audio_policy_configuration.xml
Signed-off-by: default avatarCarter Hsu <carterhsu@google.com>
Change-Id: I681491bc21788e7eb75a052025a3feed89033524
parent e3009b64
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -1972,6 +1972,19 @@ bool AudioSystem::isHapticPlaybackSupported() {
    return result.value_or(false);
}

bool AudioSystem::isUltrasoundSupported() {
    const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
    if (aps == 0) return false;

    auto result = [&]() -> ConversionResult<bool> {
        bool retVal;
        RETURN_IF_ERROR(
                statusTFromBinderStatus(aps->isUltrasoundSupported(&retVal)));
        return retVal;
    }();
    return result.value_or(false);
}

status_t AudioSystem::getHwOffloadFormatsSupportedForBluetoothMedia(
        audio_devices_t device, std::vector<audio_format_t>* formats) {
    if (formats == nullptr) {
+2 −0
Original line number Diff line number Diff line
@@ -311,6 +311,8 @@ interface IAudioPolicyService {

    boolean isHapticPlaybackSupported();

    boolean isUltrasoundSupported();

    AudioProductStrategy[] listAudioProductStrategies();
    int /* product_strategy_t */ getProductStrategyFromAudioAttributes(in AudioAttributesEx aa,
                                                                       boolean fallbackOnDefault);
+2 −0
Original line number Diff line number Diff line
@@ -444,6 +444,8 @@ public:

    static bool     isHapticPlaybackSupported();

    static bool     isUltrasoundSupported();

    static status_t listAudioProductStrategies(AudioProductStrategyVector &strategies);
    static status_t getProductStrategyFromAudioAttributes(
            const AudioAttributes &aa, product_strategy_t &productStrategy,
+2 −0
Original line number Diff line number Diff line
@@ -300,6 +300,8 @@ public:

    virtual bool     isHapticPlaybackSupported() = 0;

    virtual bool     isUltrasoundSupported() = 0;

    virtual status_t getHwOffloadFormatsSupportedForBluetoothMedia(
                audio_devices_t device, std::vector<audio_format_t> *formats) = 0;

+31 −0
Original line number Diff line number Diff line
@@ -4890,6 +4890,37 @@ bool AudioPolicyManager::isHapticPlaybackSupported()
    return false;
}

bool AudioPolicyManager::isUltrasoundSupported()
{
    bool hasUltrasoundOutput = false;
    bool hasUltrasoundInput = false;
    for (const auto& hwModule : mHwModules) {
        const OutputProfileCollection &outputProfiles = hwModule->getOutputProfiles();
        if (!hasUltrasoundOutput) {
            for (const auto &outProfile : outputProfiles) {
                if (outProfile->getFlags() & AUDIO_OUTPUT_FLAG_ULTRASOUND) {
                    hasUltrasoundOutput = true;
                    break;
                }
            }
        }

        const InputProfileCollection &inputProfiles = hwModule->getInputProfiles();
        if (!hasUltrasoundInput) {
            for (const auto &inputProfile : inputProfiles) {
                if (inputProfile->getFlags() & AUDIO_INPUT_FLAG_ULTRASOUND) {
                    hasUltrasoundInput = true;
                    break;
                }
            }
        }

        if (hasUltrasoundOutput && hasUltrasoundInput)
            return true;
    }
    return false;
}

bool AudioPolicyManager::isCallScreenModeSupported()
{
    return getConfig().isCallScreenModeSupported();
Loading