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

Commit 49e69a1e authored by jiabin's avatar jiabin
Browse files

Add equals functions for classes in libaudiofoundation.

Add equals functions that can be used to check if current object is the
same as the given object by checking if all members are the same.

Bug: 135621476
Test: make
Change-Id: Idcf09587f629e6719e9dcf2f0fb7d68a01eafef9
parent 17058fa5
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@
#define ALOGVV(a...) do { } while(0)
#endif

#include <algorithm>

#include <android-base/stringprintf.h>
#include <media/AudioGain.h>
#include <utils/Log.h>
@@ -111,6 +113,22 @@ void AudioGain::dump(std::string *dst, int spaces, int index) const
    dst->append(base::StringPrintf("%*s- max_ramp_ms: %d ms\n", spaces, "", mGain.max_ramp_ms));
}

bool AudioGain::equals(const sp<AudioGain>& other) const
{
    return other != nullptr &&
           mUseInChannelMask == other->mUseInChannelMask &&
           mUseForVolume == other->mUseForVolume &&
           // Compare audio gain
           mGain.mode == other->mGain.mode &&
           mGain.channel_mask == other->mGain.channel_mask &&
           mGain.min_value == other->mGain.min_value &&
           mGain.max_value == other->mGain.max_value &&
           mGain.default_value == other->mGain.default_value &&
           mGain.step_value == other->mGain.step_value &&
           mGain.min_ramp_ms == other->mGain.min_ramp_ms &&
           mGain.max_ramp_ms == other->mGain.max_ramp_ms;
}

status_t AudioGain::writeToParcel(android::Parcel *parcel) const
{
    status_t status = NO_ERROR;
@@ -145,6 +163,14 @@ status_t AudioGain::readFromParcel(const android::Parcel *parcel)
    return status;
}

bool AudioGains::equals(const AudioGains &other) const
{
    return std::equal(begin(), end(), other.begin(), other.end(),
                      [](const sp<AudioGain>& left, const sp<AudioGain>& right) {
                          return left->equals(right);
                      });
}

status_t AudioGains::writeToParcel(android::Parcel *parcel) const {
    status_t status = NO_ERROR;
    if ((status = parcel->writeVectorSize(*this)) != NO_ERROR) return status;
+25 −0
Original line number Diff line number Diff line
@@ -105,6 +105,16 @@ void AudioPort::log(const char* indent) const
    ALOGI("%s Port[nm:%s, type:%d, role:%d]", indent, mName.c_str(), mType, mRole);
}

bool AudioPort::equals(const sp<AudioPort> &other) const
{
    return other != nullptr &&
           mGains.equals(other->getGains()) &&
           mName.compare(other->getName()) == 0 &&
           mType == other->getType() &&
           mRole == other->getRole() &&
           mProfiles.equals(other->getAudioProfiles());
}

status_t AudioPort::writeToParcel(Parcel *parcel) const
{
    status_t status = NO_ERROR;
@@ -218,6 +228,21 @@ bool AudioPortConfig::hasGainController(bool canUseForVolume) const
                           : audioport->getGains().size() > 0;
}

bool AudioPortConfig::equals(const sp<AudioPortConfig> &other) const
{
    return other != nullptr &&
           mSamplingRate == other->getSamplingRate() &&
           mFormat == other->getFormat() &&
           mChannelMask == other->getChannelMask() &&
           // Compare audio gain config
           mGain.index == other->mGain.index &&
           mGain.mode == other->mGain.mode &&
           mGain.channel_mask == other->mGain.channel_mask &&
           std::equal(std::begin(mGain.values), std::end(mGain.values),
                      std::begin(other->mGain.values)) &&
           mGain.ramp_duration_ms == other->mGain.ramp_duration_ms;
}

status_t AudioPortConfig::writeToParcel(Parcel *parcel) const
{
    status_t status = NO_ERROR;
+20 −0
Original line number Diff line number Diff line
@@ -118,6 +118,18 @@ void AudioProfile::dump(std::string *dst, int spaces) const
    }
}

bool AudioProfile::equals(const sp<AudioProfile>& other) const
{
    return other != nullptr &&
           mName.compare(other->mName) == 0 &&
           mFormat == other->getFormat() &&
           mChannelMasks == other->getChannels() &&
           mSamplingRates == other->getSampleRates() &&
           mIsDynamicFormat == other->isDynamicFormat() &&
           mIsDynamicChannels == other->isDynamicChannels() &&
           mIsDynamicRate == other->isDynamicRate();
}

status_t AudioProfile::writeToParcel(Parcel *parcel) const
{
    status_t status = NO_ERROR;
@@ -284,4 +296,12 @@ status_t AudioProfileVector::readFromParcel(const Parcel *parcel)
    return status;
}

bool AudioProfileVector::equals(const AudioProfileVector& other) const
{
    return std::equal(begin(), end(), other.begin(), other.end(),
                      [](const sp<AudioProfile>& left, const sp<AudioProfile>& right) {
                          return left->equals(right);
                      });
}

} // namespace android
+9 −0
Original line number Diff line number Diff line
@@ -110,6 +110,15 @@ void DeviceDescriptorBase::log() const
    AudioPort::log("  ");
}

bool DeviceDescriptorBase::equals(const sp<DeviceDescriptorBase> &other) const
{
    return other != nullptr &&
           static_cast<const AudioPort*>(this)->equals(other) &&
           static_cast<const AudioPortConfig*>(this)->equals(other) &&
           mAddress.compare(other->address()) == 0 &&
           mDeviceType == other->type();
}

status_t DeviceDescriptorBase::writeToParcel(Parcel *parcel) const
{
    status_t status = NO_ERROR;
+4 −0
Original line number Diff line number Diff line
@@ -67,6 +67,8 @@ public:

    const struct audio_gain &getGain() const { return mGain; }

    bool equals(const sp<AudioGain>& other) const;

    status_t writeToParcel(Parcel* parcel) const override;
    status_t readFromParcel(const Parcel* parcel) override;

@@ -96,6 +98,8 @@ public:
        return 0;
    }

    bool equals(const AudioGains& other) const;

    status_t writeToParcel(Parcel* parcel) const override;
    status_t readFromParcel(const Parcel* parcel) override;
};
Loading