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

Commit 2478d528 authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

audiopolicy: Use range for loops in managerdefinitions classes

Use "range for" loops where it improves readability.

Change-Id: I4fc0360956b7aa70b9e282b83f6bb371c05a8522
Test: compiles
parent cf84e596
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -27,14 +27,12 @@ namespace android {

sp<AudioPort> AudioPortVector::findByTagName(const String8 &tagName) const
{
    sp<AudioPort> port = 0;
    for (size_t i = 0; i < size(); i++) {
        if (itemAt(i)->getTagName() == tagName) {
            port = itemAt(i);
            break;
    for (const auto& port : *this) {
        if (port->getTagName() == tagName) {
            return port;
        }
    }
    return port;
    return nullptr;
}

status_t AudioRouteVector::dump(int fd, int spaces) const
+8 −10
Original line number Diff line number Diff line
@@ -74,11 +74,11 @@ void AudioPort::toAudioPort(struct audio_port *port) const
    SortedVector<audio_format_t> flatenedFormats;
    SampleRateVector flatenedRates;
    ChannelsVector flatenedChannels;
    for (size_t profileIndex = 0; profileIndex < mProfiles.size(); profileIndex++) {
        if (mProfiles[profileIndex]->isValid()) {
            audio_format_t formatToExport = mProfiles[profileIndex]->getFormat();
            const SampleRateVector &ratesToExport = mProfiles[profileIndex]->getSampleRates();
            const ChannelsVector &channelsToExport = mProfiles[profileIndex]->getChannels();
    for (const auto& profile : mProfiles) {
        if (profile->isValid()) {
            audio_format_t formatToExport = profile->getFormat();
            const SampleRateVector &ratesToExport = profile->getSampleRates();
            const ChannelsVector &channelsToExport = profile->getChannels();

            if (flatenedFormats.indexOf(formatToExport) < 0) {
                flatenedFormats.add(formatToExport);
@@ -130,14 +130,12 @@ void AudioPort::toAudioPort(struct audio_port *port) const

void AudioPort::importAudioPort(const sp<AudioPort>& port, bool force __unused)
{
    size_t indexToImport;
    for (indexToImport = 0; indexToImport < port->mProfiles.size(); indexToImport++) {
        const sp<AudioProfile> &profileToImport = port->mProfiles[indexToImport];
    for (const auto& profileToImport : port->mProfiles) {
        if (profileToImport->isValid()) {
            // Import only valid port, i.e. valid format, non empty rates and channels masks
            bool hasSameProfile = false;
            for (size_t profileIndex = 0; profileIndex < mProfiles.size(); profileIndex++) {
                if (*mProfiles[profileIndex] == *profileToImport) {
            for (const auto& profile : mProfiles) {
                if (*profile == *profileToImport) {
                    // never import a profile twice
                    hasSameProfile = true;
                    break;
+1 −2
Original line number Diff line number Diff line
@@ -233,8 +233,7 @@ status_t AudioProfileVector::checkExactProfile(uint32_t samplingRate,
        return NO_ERROR;
    }

    for (size_t i = 0; i < size(); i++) {
        const sp<AudioProfile> profile = itemAt(i);
    for (const auto& profile : *this) {
        if (profile->checkExact(samplingRate, channelMask, format) == NO_ERROR) {
            return NO_ERROR;
        }
+19 −22
Original line number Diff line number Diff line
@@ -78,11 +78,14 @@ ssize_t DeviceVector::indexOf(const sp<DeviceDescriptor>& item) const

void DeviceVector::add(const DeviceVector &devices)
{
    for (size_t i = 0; i < devices.size(); i++) {
        sp<DeviceDescriptor> device = devices.itemAt(i);
    bool added = false;
    for (const auto& device : devices) {
        if (indexOf(device) < 0 && SortedVector::add(device) >= 0) {
            refreshTypes();
            added = true;
        }
    }
    if (added) {
        refreshTypes();
    }
}

@@ -148,14 +151,12 @@ sp<DeviceDescriptor> DeviceVector::getDevice(audio_devices_t type, const String8

sp<DeviceDescriptor> DeviceVector::getDeviceFromId(audio_port_handle_t id) const
{
    sp<DeviceDescriptor> device;
    for (size_t i = 0; i < size(); i++) {
        if (itemAt(i)->getId() == id) {
            device = itemAt(i);
            break;
    for (const auto& device : *this) {
        if (device->getId() == id) {
            return device;
        }
    }
    return device;
    return nullptr;
}

DeviceVector DeviceVector::getDevicesFromType(audio_devices_t type) const
@@ -180,11 +181,9 @@ DeviceVector DeviceVector::getDevicesFromTypeAddr(
        audio_devices_t type, const String8& address) const
{
    DeviceVector devices;
    for (size_t i = 0; i < size(); i++) {
        if (itemAt(i)->type() == type) {
            if (itemAt(i)->mAddress == address) {
                devices.add(itemAt(i));
            }
    for (const auto& device : *this) {
        if (device->type() == type && device->mAddress == address) {
            devices.add(device);
        }
    }
    return devices;
@@ -192,14 +191,12 @@ DeviceVector DeviceVector::getDevicesFromTypeAddr(

sp<DeviceDescriptor> DeviceVector::getDeviceFromTagName(const String8 &tagName) const
{
    sp<DeviceDescriptor> device;
    for (size_t i = 0; i < size(); i++) {
        if (itemAt(i)->getTagName() == tagName) {
            device = itemAt(i);
            break;
    for (const auto& device : *this) {
        if (device->getTagName() == tagName) {
            return device;
        }
    }
    return device;
    return nullptr;
}

status_t DeviceVector::dump(int fd, const String8 &tag, int spaces, bool verbose) const
+11 −16
Original line number Diff line number Diff line
@@ -154,10 +154,9 @@ sp<DeviceDescriptor> HwModule::getRouteSinkDevice(const sp<AudioRoute> &route) c
DeviceVector HwModule::getRouteSourceDevices(const sp<AudioRoute> &route) const
{
    DeviceVector sourceDevices;
    Vector <sp<AudioPort> > sources = route->getSources();
    for (size_t i = 0; i < sources.size(); i++) {
        if (sources[i]->getType() == AUDIO_PORT_TYPE_DEVICE) {
            sourceDevices.add(mDeclaredDevices.getDeviceFromTagName(sources[i]->getTagName()));
    for (const auto& source : route->getSources()) {
        if (source->getType() == AUDIO_PORT_TYPE_DEVICE) {
            sourceDevices.add(mDeclaredDevices.getDeviceFromTagName(source->getTagName()));
        }
    }
    return sourceDevices;
@@ -173,17 +172,15 @@ void HwModule::setRoutes(const AudioRouteVector &routes)
void HwModule::refreshSupportedDevices()
{
    // Now updating the streams (aka IOProfile until now) supported devices
    for (size_t i = 0; i < mInputProfiles.size(); i++) {
        sp<IOProfile> stream = mInputProfiles[i];
    for (const auto& stream : mInputProfiles) {
        DeviceVector sourceDevices;
        const AudioRouteVector &routes = stream->getRoutes();
        for (size_t j = 0; j < routes.size(); j++) {
            sp<AudioPort> sink = routes[j]->getSink();
        for (const auto& route : stream->getRoutes()) {
            sp<AudioPort> sink = route->getSink();
            if (sink == 0 || stream != sink) {
                ALOGE("%s: Invalid route attached to input stream", __FUNCTION__);
                continue;
            }
            DeviceVector sourceDevicesForRoute = getRouteSourceDevices(routes[j]);
            DeviceVector sourceDevicesForRoute = getRouteSourceDevices(route);
            if (sourceDevicesForRoute.isEmpty()) {
                ALOGE("%s: invalid source devices for %s", __FUNCTION__, stream->getName().string());
                continue;
@@ -196,17 +193,15 @@ void HwModule::refreshSupportedDevices()
        }
        stream->setSupportedDevices(sourceDevices);
    }
    for (size_t i = 0; i < mOutputProfiles.size(); i++) {
        sp<IOProfile> stream = mOutputProfiles[i];
    for (const auto& stream : mOutputProfiles) {
        DeviceVector sinkDevices;
        const AudioRouteVector &routes = stream->getRoutes();
        for (size_t j = 0; j < routes.size(); j++) {
            sp<AudioPort> source = routes[j]->getSources().findByTagName(stream->getTagName());
        for (const auto& route : stream->getRoutes()) {
            sp<AudioPort> source = route->getSources().findByTagName(stream->getTagName());
            if (source == 0 || stream != source) {
                ALOGE("%s: Invalid route attached to output stream", __FUNCTION__);
                continue;
            }
            sp<DeviceDescriptor> sinkDevice = getRouteSinkDevice(routes[j]);
            sp<DeviceDescriptor> sinkDevice = getRouteSinkDevice(route);
            if (sinkDevice == 0) {
                ALOGE("%s: invalid sink device for %s", __FUNCTION__, stream->getName().string());
                continue;