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

Commit 58f34065 authored by Tomasz Wasilczyk's avatar Tomasz Wasilczyk
Browse files

Implement front-end API to retrieve DAB frequency table.

Bug: 69958423
Test: instrumentation (none added)
Change-Id: I7e648f988baf3b14d814588d44b18fd57c108906
parent 1d92689e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1986,6 +1986,7 @@ package android.hardware.radio {
    method public int describeContents();
    method public android.hardware.radio.RadioManager.BandDescriptor[] getBands();
    method public int getClassId();
    method public java.util.Map<java.lang.String, java.lang.Integer> getDabFrequencyTable();
    method public int getId();
    method public java.lang.String getImplementor();
    method public int getNumAudioSources();
+43 −55
Original line number Diff line number Diff line
@@ -213,6 +213,7 @@ public class RadioManager {
        private final boolean mIsBgScanSupported;
        private final Set<Integer> mSupportedProgramTypes;
        private final Set<Integer> mSupportedIdentifierTypes;
        @Nullable private final Map<String, Integer> mDabFrequencyTable;
        @NonNull private final Map<String, String> mVendorInfo;

        /** @hide */
@@ -221,6 +222,7 @@ public class RadioManager {
                boolean isCaptureSupported, BandDescriptor[] bands, boolean isBgScanSupported,
                @ProgramSelector.ProgramType int[] supportedProgramTypes,
                @ProgramSelector.IdentifierType int[] supportedIdentifierTypes,
                @Nullable Map<String, Integer> dabFrequencyTable,
                Map<String, String> vendorInfo) {
            mId = id;
            mServiceName = TextUtils.isEmpty(serviceName) ? "default" : serviceName;
@@ -236,6 +238,13 @@ public class RadioManager {
            mIsBgScanSupported = isBgScanSupported;
            mSupportedProgramTypes = arrayToSet(supportedProgramTypes);
            mSupportedIdentifierTypes = arrayToSet(supportedIdentifierTypes);
            if (dabFrequencyTable != null) {
                for (Map.Entry<String, Integer> entry : dabFrequencyTable.entrySet()) {
                    Objects.requireNonNull(entry.getKey());
                    Objects.requireNonNull(entry.getValue());
                }
            }
            mDabFrequencyTable = dabFrequencyTable;
            mVendorInfo = (vendorInfo == null) ? new HashMap<>() : vendorInfo;
        }

@@ -362,6 +371,19 @@ public class RadioManager {
            return mSupportedIdentifierTypes.contains(type);
        }

        /**
         * A frequency table for Digital Audio Broadcasting (DAB).
         *
         * The key is a channel name, i.e. 5A, 7B.
         *
         * The value is a frequency, in kHz.
         *
         * @return a frequency table, or {@code null} if the module doesn't support DAB
         */
        public @Nullable Map<String, Integer> getDabFrequencyTable() {
            return mDabFrequencyTable;
        }

        /**
         * A map of vendor-specific opaque strings, passed from HAL without changes.
         * Format of these strings can vary across vendors.
@@ -403,6 +425,7 @@ public class RadioManager {
            mIsBgScanSupported = in.readInt() == 1;
            mSupportedProgramTypes = arrayToSet(in.createIntArray());
            mSupportedIdentifierTypes = arrayToSet(in.createIntArray());
            mDabFrequencyTable = Utils.readStringIntMap(in);
            mVendorInfo = Utils.readStringMap(in);
        }

@@ -433,6 +456,7 @@ public class RadioManager {
            dest.writeInt(mIsBgScanSupported ? 1 : 0);
            dest.writeIntArray(setToArray(mSupportedProgramTypes));
            dest.writeIntArray(setToArray(mSupportedIdentifierTypes));
            Utils.writeStringIntMap(dest, mDabFrequencyTable);
            Utils.writeStringMap(dest, mVendorInfo);
        }

@@ -456,67 +480,31 @@ public class RadioManager {

        @Override
        public int hashCode() {
            final int prime = 31;
            int result = 1;
            result = prime * result + mId;
            result = prime * result + mServiceName.hashCode();
            result = prime * result + mClassId;
            result = prime * result + ((mImplementor == null) ? 0 : mImplementor.hashCode());
            result = prime * result + ((mProduct == null) ? 0 : mProduct.hashCode());
            result = prime * result + ((mVersion == null) ? 0 : mVersion.hashCode());
            result = prime * result + ((mSerial == null) ? 0 : mSerial.hashCode());
            result = prime * result + mNumTuners;
            result = prime * result + mNumAudioSources;
            result = prime * result + (mIsCaptureSupported ? 1 : 0);
            result = prime * result + Arrays.hashCode(mBands);
            result = prime * result + (mIsBgScanSupported ? 1 : 0);
            result = prime * result + mVendorInfo.hashCode();
            return result;
            return Objects.hash(mId, mServiceName, mClassId, mImplementor, mProduct, mVersion,
                mSerial, mNumTuners, mNumAudioSources, mIsCaptureSupported, mBands,
                mIsBgScanSupported, mDabFrequencyTable, mVendorInfo);
        }

        @Override
        public boolean equals(Object obj) {
            if (this == obj)
                return true;
            if (!(obj instanceof ModuleProperties))
                return false;
            if (this == obj) return true;
            if (!(obj instanceof ModuleProperties)) return false;
            ModuleProperties other = (ModuleProperties) obj;
            if (mId != other.getId())
                return false;

            if (mId != other.getId()) return false;
            if (!TextUtils.equals(mServiceName, other.mServiceName)) return false;
            if (mClassId != other.getClassId())
                return false;
            if (mImplementor == null) {
                if (other.getImplementor() != null)
                    return false;
            } else if (!mImplementor.equals(other.getImplementor()))
                return false;
            if (mProduct == null) {
                if (other.getProduct() != null)
                    return false;
            } else if (!mProduct.equals(other.getProduct()))
                return false;
            if (mVersion == null) {
                if (other.getVersion() != null)
                    return false;
            } else if (!mVersion.equals(other.getVersion()))
                return false;
            if (mSerial == null) {
                if (other.getSerial() != null)
                    return false;
            } else if (!mSerial.equals(other.getSerial()))
                return false;
            if (mNumTuners != other.getNumTuners())
                return false;
            if (mNumAudioSources != other.getNumAudioSources())
                return false;
            if (mIsCaptureSupported != other.isCaptureSupported())
                return false;
            if (!Arrays.equals(mBands, other.getBands()))
                return false;
            if (mIsBgScanSupported != other.isBackgroundScanningSupported())
                return false;
            if (!mVendorInfo.equals(other.mVendorInfo)) return false;
            if (mClassId != other.mClassId) return false;
            if (!Objects.equals(mImplementor, other.mImplementor)) return false;
            if (!Objects.equals(mProduct, other.mProduct)) return false;
            if (!Objects.equals(mVersion, other.mVersion)) return false;
            if (!Objects.equals(mSerial, other.mSerial)) return false;
            if (mNumTuners != other.mNumTuners) return false;
            if (mNumAudioSources != other.mNumAudioSources) return false;
            if (mIsCaptureSupported != other.mIsCaptureSupported) return false;
            if (!Objects.equals(mBands, other.mBands)) return false;
            if (mIsBgScanSupported != other.mIsBgScanSupported) return false;
            if (!Objects.equals(mDabFrequencyTable, other.mDabFrequencyTable)) return false;
            if (!Objects.equals(mVendorInfo, other.mVendorInfo)) return false;
            return true;
        }
    }
+23 −0
Original line number Diff line number Diff line
@@ -56,6 +56,29 @@ final class Utils {
        return map;
    }

    static void writeStringIntMap(@NonNull Parcel dest, @Nullable Map<String, Integer> map) {
        if (map == null) {
            dest.writeInt(0);
            return;
        }
        dest.writeInt(map.size());
        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            dest.writeString(entry.getKey());
            dest.writeInt(entry.getValue());
        }
    }

    static @NonNull Map<String, Integer> readStringIntMap(@NonNull Parcel in) {
        int size = in.readInt();
        Map<String, Integer> map = new HashMap<>();
        while (size-- > 0) {
            String key = in.readString();
            int value = in.readInt();
            map.put(key, value);
        }
        return map;
    }

    static <T extends Parcelable> void writeSet(@NonNull Parcel dest, @Nullable Set<T> set) {
        if (set == null) {
            dest.writeInt(0);
+1 −1
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ class Tuner extends ITuner.Stub {

    private boolean mIsClosed = false;
    private boolean mIsMuted = false;
    private int mRegion;  // TODO(b/62710330): find better solution to handle regions
    private int mRegion;
    private final boolean mWithAudio;

    Tuner(@NonNull ITunerCallback clientCallback, int halRev,
+9 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.annotation.Nullable;
import android.hardware.broadcastradio.V2_0.AmFmBandRange;
import android.hardware.broadcastradio.V2_0.AmFmRegionConfig;
import android.hardware.broadcastradio.V2_0.Announcement;
import android.hardware.broadcastradio.V2_0.DabTableEntry;
import android.hardware.broadcastradio.V2_0.IdentifierType;
import android.hardware.broadcastradio.V2_0.ProgramFilter;
import android.hardware.broadcastradio.V2_0.ProgramIdentifier;
@@ -177,9 +178,15 @@ class Convert {
        return bands.toArray(new RadioManager.BandDescriptor[bands.size()]);
    }

    private static @Nullable Map<String, Integer> dabConfigFromHal(
            @Nullable List<DabTableEntry> config) {
        if (config == null) return null;
        return config.stream().collect(Collectors.toMap(e -> e.label, e -> e.frequency));
    }

    static @NonNull RadioManager.ModuleProperties
    propertiesFromHal(int id, @NonNull String serviceName, @NonNull Properties prop,
            @Nullable AmFmRegionConfig amfmConfig) {
            @Nullable AmFmRegionConfig amfmConfig, @Nullable List<DabTableEntry> dabConfig) {
        Objects.requireNonNull(serviceName);
        Objects.requireNonNull(prop);

@@ -209,6 +216,7 @@ class Convert {
                false,  // isBgScanSupported is deprecated
                supportedProgramTypes,
                supportedIdentifierTypes,
                dabConfigFromHal(dabConfig),
                vendorInfoFromHal(prop.vendorInfo)
        );
    }
Loading