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

Commit 2834b95b authored by Tomasz Wasilczyk's avatar Tomasz Wasilczyk
Browse files

Move utils lib out from implementation namespace.

RadioService may benefit from it too.

Also, fix subchannel base, as I found a tiny comment about it in the 1.0 HAL.

Bug: b/32621193
Test: instrumentalization
Change-Id: I11939025b72bdeab4cc6393e25159f53164e22ed
parent e4a6cd4c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -98,7 +98,7 @@ static ProgramInfo makeDummyProgramInfo(const ProgramSelector& selector) {
    ProgramInfo info11 = {};
    auto& info10 = info11.base;

    utils::getLegacyChannel(selector, info10.channel, info10.subChannel);
    utils::getLegacyChannel(selector, &info10.channel, &info10.subChannel);
    info11.selector = selector;
    info11.flags |= ProgramInfoFlags::MUTED;

+1 −1
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ VirtualProgram::operator ProgramInfo() const {
    ProgramInfo info11 = {};
    auto& info10 = info11.base;

    utils::getLegacyChannel(selector, info10.channel, info10.subChannel);
    utils::getLegacyChannel(selector, &info10.channel, &info10.subChannel);
    info11.selector = selector;
    info10.tuned = true;
    info10.stereo = true;
+9 −1
Original line number Diff line number Diff line
@@ -80,7 +80,15 @@ enum ProgramType : uint32_t {
    DAB,     // Digital audio broadcasting
    DRMO,    // Digital Radio Mondiale
    SXM,     // SiriusXM Satellite Radio
    VENDOR,  // vendor-specific, not synced across devices

    /**
     * Vendor-specific, not synced across devices.
     *
     * If it's necessary to support multiple vendor-specific program types, the
     * type of vendor radio technology may be encoded in high bits
     * of IDENTIFIER_TYPE_VENDOR_PRIMARY.
     */
    VENDOR,
};

/**
+15 −12
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ namespace android {
namespace hardware {
namespace broadcastradio {
namespace V1_1 {
namespace implementation {
namespace utils {

using V1_0::Band;
@@ -166,26 +165,31 @@ ProgramSelector make_selector(Band band, uint32_t channel, uint32_t subChannel)
    sel.primaryId.type = static_cast<uint32_t>(IdentifierType::AMFM_FREQUENCY);
    sel.primaryId.value = channel;
    if (subChannel > 0) {
        // stating sub channel for AM/FM channel does not give any guarantees,
        // but we can't do much more without HD station ID
        /* stating sub channel for AM/FM channel does not give any guarantees,
         * but we can't do much more without HD station ID
         *
         * The legacy APIs had 1-based subChannels, while ProgramSelector is 0-based.
         */
        sel.secondaryIds = hidl_vec<ProgramIdentifier>{
            {static_cast<uint32_t>(IdentifierType::HD_SUBCHANNEL), subChannel},
            {static_cast<uint32_t>(IdentifierType::HD_SUBCHANNEL), subChannel - 1},
        };
    }

    return sel;
}

bool getLegacyChannel(const ProgramSelector& sel, uint32_t& channelOut, uint32_t& subChannelOut) {
bool getLegacyChannel(const ProgramSelector& sel, uint32_t* channelOut, uint32_t* subChannelOut) {
    if (channelOut) *channelOut = 0;
    if (subChannelOut) *subChannelOut = 0;
    if (isAmFm(getType(sel))) {
        channelOut = getId(sel, IdentifierType::AMFM_FREQUENCY);
        subChannelOut = getId(sel, IdentifierType::HD_SUBCHANNEL, 0);
        if (channelOut) *channelOut = getId(sel, IdentifierType::AMFM_FREQUENCY);
        if (subChannelOut && hasId(sel, IdentifierType::HD_SUBCHANNEL)) {
            // The legacy APIs had 1-based subChannels, while ProgramSelector is 0-based.
            *subChannelOut = getId(sel, IdentifierType::HD_SUBCHANNEL) + 1;
        }
        return true;
    } else {
        channelOut = 0;
        subChannelOut = 0;
        return false;
    }
    return false;
}

bool isDigital(const ProgramSelector& sel) {
@@ -200,7 +204,6 @@ bool isDigital(const ProgramSelector& sel) {
}

}  // namespace utils
}  // namespace implementation
}  // namespace V1_1
}  // namespace broadcastradio
}  // namespace hardware
+1 −3
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ namespace android {
namespace hardware {
namespace broadcastradio {
namespace V1_1 {
namespace implementation {
namespace utils {

/**
@@ -61,12 +60,11 @@ uint64_t getId(const ProgramSelector& sel, const IdentifierType type, uint64_t d

ProgramSelector make_selector(V1_0::Band band, uint32_t channel, uint32_t subChannel = 0);

bool getLegacyChannel(const ProgramSelector& sel, uint32_t& channelOut, uint32_t& subChannelOut);
bool getLegacyChannel(const ProgramSelector& sel, uint32_t* channelOut, uint32_t* subChannelOut);

bool isDigital(const ProgramSelector& sel);

}  // namespace utils
}  // namespace implementation
}  // namespace V1_1
}  // namespace broadcastradio
}  // namespace hardware