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

Commit b47e50c2 authored by Vlad Popa's avatar Vlad Popa Committed by Android (Google) Code Review
Browse files

Merge "CSD: When testing use random port id" into main

parents 0014ba04 eb8036aa
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ namespace android {

bool MelReporter::activateHalSoundDoseComputation(const std::string& module,
        const sp<DeviceHalInterface>& device) {
    if (mSoundDoseManager->forceUseFrameworkMel()) {
    if (mSoundDoseManager->isFrameworkMelForced()) {
        ALOGD("%s: Forcing use of internal MEL computation.", __func__);
        activateInternalSoundDoseComputation();
        return false;
@@ -318,7 +318,7 @@ std::optional<audio_patch_handle_t> MelReporter::activePatchStreamHandle_l(
}

bool MelReporter::useHalSoundDoseInterface_l() {
    return !mSoundDoseManager->forceUseFrameworkMel() & mUseHalSoundDoseInterface;
    return !mSoundDoseManager->isFrameworkMelForced() & mUseHalSoundDoseInterface;
}

std::string MelReporter::dump() {
+15 −4
Original line number Diff line number Diff line
@@ -33,6 +33,10 @@ using aidl::android::media::audio::common::AudioDevice;

namespace {

// Port handle used when CSD is computed on all devices. Should be a different value than
// AUDIO_PORT_HANDLE_NONE which is associated with a sound dose callback failure
constexpr audio_port_handle_t CSD_ON_ALL_DEVICES_PORT_HANDLE = -1;

int64_t getMonotonicSecond() {
    struct timespec now_ts;
    if (clock_gettime(CLOCK_MONOTONIC, &now_ts) != 0) {
@@ -175,6 +179,13 @@ void SoundDoseManager::removeStreamProcessor(audio_io_handle_t streamHandle) {
}

audio_port_handle_t SoundDoseManager::getIdForAudioDevice(const AudioDevice& audioDevice) const {
    if (isComputeCsdForcedOnAllDevices()) {
        // If CSD is forced on all devices return random port id. Used only in testing.
        // This is necessary since the patches that are registered before
        // setComputeCsdOnAllDevices will not be contributing to mActiveDevices
        return CSD_ON_ALL_DEVICES_PORT_HANDLE;
    }

    const std::lock_guard _l(mLock);

    audio_devices_t type;
@@ -491,7 +502,7 @@ bool SoundDoseManager::shouldComputeCsdForDeviceType(audio_devices_t device) {
        ALOGV("%s csd is disabled", __func__);
        return false;
    }
    if (forceComputeCsdOnAllDevices()) {
    if (isComputeCsdForcedOnAllDevices()) {
        return true;
    }

@@ -515,7 +526,7 @@ bool SoundDoseManager::shouldComputeCsdForDeviceWithAddress(const audio_devices_
        ALOGV("%s csd is disabled", __func__);
        return false;
    }
    if (forceComputeCsdOnAllDevices()) {
    if (isComputeCsdForcedOnAllDevices()) {
        return true;
    }

@@ -536,7 +547,7 @@ void SoundDoseManager::setUseFrameworkMel(bool useFrameworkMel) {
    mUseFrameworkMel = useFrameworkMel;
}

bool SoundDoseManager::forceUseFrameworkMel() const {
bool SoundDoseManager::isFrameworkMelForced() const {
    const std::lock_guard _l(mLock);
    return mUseFrameworkMel;
}
@@ -546,7 +557,7 @@ void SoundDoseManager::setComputeCsdOnAllDevices(bool computeCsdOnAllDevices) {
    mComputeCsdOnAllDevices = computeCsdOnAllDevices;
}

bool SoundDoseManager::forceComputeCsdOnAllDevices() const {
bool SoundDoseManager::isComputeCsdForcedOnAllDevices() const {
    const std::lock_guard _l(mLock);
    return mComputeCsdOnAllDevices;
}
+2 −2
Original line number Diff line number Diff line
@@ -136,8 +136,8 @@ public:

    // used for testing only
    size_t getCachedMelRecordsSize() const;
    bool forceUseFrameworkMel() const;
    bool forceComputeCsdOnAllDevices() const;
    bool isFrameworkMelForced() const;
    bool isComputeCsdForcedOnAllDevices() const;

    /** Method for converting from audio_utils::CsdRecord to media::SoundDoseRecord. */
    static media::SoundDoseRecord csdRecordToSoundDoseRecord(const audio_utils::CsdRecord& legacy);
+2 −2
Original line number Diff line number Diff line
@@ -262,11 +262,11 @@ TEST_F(SoundDoseManagerTest, GetUnmappedIdReturnsHandleNone) {
}

TEST_F(SoundDoseManagerTest, GetDefaultForceComputeCsdOnAllDevices) {
    EXPECT_FALSE(mSoundDoseManager->forceComputeCsdOnAllDevices());
    EXPECT_FALSE(mSoundDoseManager->isComputeCsdForcedOnAllDevices());
}

TEST_F(SoundDoseManagerTest, GetDefaultForceUseFrameworkMel) {
    EXPECT_FALSE(mSoundDoseManager->forceUseFrameworkMel());
    EXPECT_FALSE(mSoundDoseManager->isFrameworkMelForced());
}

TEST_F(SoundDoseManagerTest, SetAudioDeviceCategoryStopsNonHeadphone) {