Loading core/java/android/hardware/radio/RadioManager.java +4 −2 Original line number Diff line number Diff line Loading @@ -251,7 +251,8 @@ public class RadioManager { Objects.requireNonNull(entry.getValue()); } } mDabFrequencyTable = dabFrequencyTable; mDabFrequencyTable = (dabFrequencyTable == null || dabFrequencyTable.isEmpty()) ? null : dabFrequencyTable; mVendorInfo = (vendorInfo == null) ? new HashMap<>() : vendorInfo; } Loading Loading @@ -446,7 +447,8 @@ public class RadioManager { mIsBgScanSupported = in.readInt() == 1; mSupportedProgramTypes = arrayToSet(in.createIntArray()); mSupportedIdentifierTypes = arrayToSet(in.createIntArray()); mDabFrequencyTable = Utils.readStringIntMap(in); Map<String, Integer> dabFrequencyTableIn = Utils.readStringIntMap(in); mDabFrequencyTable = (dabFrequencyTableIn.isEmpty()) ? null : dabFrequencyTableIn; mVendorInfo = Utils.readStringMap(in); } Loading core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/RadioManagerTest.java +49 −7 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.annotation.Nullable; import android.content.Context; import android.hardware.radio.Announcement; import android.hardware.radio.IAnnouncementListener; Loading @@ -46,6 +47,7 @@ import org.mockito.junit.MockitoJUnitRunner; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Set; @RunWith(MockitoJUnitRunner.class) Loading Loading @@ -89,7 +91,8 @@ public final class RadioManagerTest { createAmBandDescriptor(); private static final RadioManager.FmBandConfig FM_BAND_CONFIG = createFmBandConfig(); private static final RadioManager.AmBandConfig AM_BAND_CONFIG = createAmBandConfig(); private static final RadioManager.ModuleProperties AMFM_PROPERTIES = createAmFmProperties(); private static final RadioManager.ModuleProperties AMFM_PROPERTIES = createAmFmProperties(/* dabFrequencyTable= */ null); /** * Info flags with live, tuned and stereo enabled Loading Loading @@ -709,11 +712,19 @@ public final class RadioManagerTest { } @Test public void getDabFrequencyTable_forModuleProperties() { public void getDabFrequencyTable_forModulePropertiesInitializedWithNullTable() { assertWithMessage("Properties DAB frequency table") .that(AMFM_PROPERTIES.getDabFrequencyTable()).isNull(); } @Test public void getDabFrequencyTable_forModulePropertiesInitializedWithEmptyTable() { RadioManager.ModuleProperties properties = createAmFmProperties(new ArrayMap<>()); assertWithMessage("Properties DAB frequency table") .that(properties.getDabFrequencyTable()).isNull(); } @Test public void getVendorInfo_forModuleProperties() { assertWithMessage("Properties vendor info") Loading @@ -733,9 +744,38 @@ public final class RadioManagerTest { .that(AMFM_PROPERTIES.describeContents()).isEqualTo(0); } @Test public void writeToParcel_forModulePropertiesWithNullDabFrequencyTable() { Parcel parcel = Parcel.obtain(); AMFM_PROPERTIES.writeToParcel(parcel, /* flags= */ 0); parcel.setDataPosition(0); RadioManager.ModuleProperties modulePropertiesFromParcel = RadioManager.ModuleProperties.CREATOR.createFromParcel(parcel); assertWithMessage("Module properties created from parcel") .that(modulePropertiesFromParcel).isEqualTo(AMFM_PROPERTIES); } @Test public void writeToParcel_forModulePropertiesWithNonnullDabFrequencyTable() { Parcel parcel = Parcel.obtain(); RadioManager.ModuleProperties propertiesToParcel = createAmFmProperties( Map.of("5A", 174928, "12D", 229072)); propertiesToParcel.writeToParcel(parcel, /* flags= */ 0); parcel.setDataPosition(0); RadioManager.ModuleProperties modulePropertiesFromParcel = RadioManager.ModuleProperties.CREATOR.createFromParcel(parcel); assertWithMessage("Module properties created from parcel") .that(modulePropertiesFromParcel).isEqualTo(propertiesToParcel); } @Test public void equals_withSameProperties_returnsTrue() { RadioManager.ModuleProperties propertiesCompared = createAmFmProperties(); RadioManager.ModuleProperties propertiesCompared = createAmFmProperties(/* dabFrequencyTable= */ null); assertWithMessage("The same module properties") .that(AMFM_PROPERTIES).isEqualTo(propertiesCompared); Loading @@ -747,7 +787,7 @@ public final class RadioManagerTest { PROPERTIES_ID + 1, SERVICE_NAME, CLASS_ID, IMPLEMENTOR, PRODUCT, VERSION, SERIAL, NUM_TUNERS, NUM_AUDIO_SOURCES, IS_INITIALIZATION_REQUIRED, IS_CAPTURE_SUPPORTED, /* bands= */ null, IS_BG_SCAN_SUPPORTED, SUPPORTED_PROGRAM_TYPES, SUPPORTED_IDENTIFIERS_TYPES, /* dabFrequencyTable= */ null, SUPPORTED_PROGRAM_TYPES, SUPPORTED_IDENTIFIERS_TYPES, Map.of("5A", 174928), /* vendorInfo= */ null); assertWithMessage("Module properties of different id") Loading @@ -756,7 +796,8 @@ public final class RadioManagerTest { @Test public void hashCode_withSameModuleProperties_equals() { RadioManager.ModuleProperties propertiesCompared = createAmFmProperties(); RadioManager.ModuleProperties propertiesCompared = createAmFmProperties(/* dabFrequencyTable= */ null); assertWithMessage("Hash code of the same module properties") .that(propertiesCompared.hashCode()).isEqualTo(AMFM_PROPERTIES.hashCode()); Loading Loading @@ -989,13 +1030,14 @@ public final class RadioManagerTest { verify(mCloseHandleMock).close(); } private static RadioManager.ModuleProperties createAmFmProperties() { private static RadioManager.ModuleProperties createAmFmProperties( @Nullable Map<String, Integer> dabFrequencyTable) { return new RadioManager.ModuleProperties(PROPERTIES_ID, SERVICE_NAME, CLASS_ID, IMPLEMENTOR, PRODUCT, VERSION, SERIAL, NUM_TUNERS, NUM_AUDIO_SOURCES, IS_INITIALIZATION_REQUIRED, IS_CAPTURE_SUPPORTED, new RadioManager.BandDescriptor[]{AM_BAND_DESCRIPTOR, FM_BAND_DESCRIPTOR}, IS_BG_SCAN_SUPPORTED, SUPPORTED_PROGRAM_TYPES, SUPPORTED_IDENTIFIERS_TYPES, /* dabFrequencyTable= */ null, /* vendorInfo= */ null); dabFrequencyTable, /* vendorInfo= */ null); } private static RadioManager.FmBandDescriptor createFmBandDescriptor() { Loading Loading
core/java/android/hardware/radio/RadioManager.java +4 −2 Original line number Diff line number Diff line Loading @@ -251,7 +251,8 @@ public class RadioManager { Objects.requireNonNull(entry.getValue()); } } mDabFrequencyTable = dabFrequencyTable; mDabFrequencyTable = (dabFrequencyTable == null || dabFrequencyTable.isEmpty()) ? null : dabFrequencyTable; mVendorInfo = (vendorInfo == null) ? new HashMap<>() : vendorInfo; } Loading Loading @@ -446,7 +447,8 @@ public class RadioManager { mIsBgScanSupported = in.readInt() == 1; mSupportedProgramTypes = arrayToSet(in.createIntArray()); mSupportedIdentifierTypes = arrayToSet(in.createIntArray()); mDabFrequencyTable = Utils.readStringIntMap(in); Map<String, Integer> dabFrequencyTableIn = Utils.readStringIntMap(in); mDabFrequencyTable = (dabFrequencyTableIn.isEmpty()) ? null : dabFrequencyTableIn; mVendorInfo = Utils.readStringMap(in); } Loading
core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/RadioManagerTest.java +49 −7 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.annotation.Nullable; import android.content.Context; import android.hardware.radio.Announcement; import android.hardware.radio.IAnnouncementListener; Loading @@ -46,6 +47,7 @@ import org.mockito.junit.MockitoJUnitRunner; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Set; @RunWith(MockitoJUnitRunner.class) Loading Loading @@ -89,7 +91,8 @@ public final class RadioManagerTest { createAmBandDescriptor(); private static final RadioManager.FmBandConfig FM_BAND_CONFIG = createFmBandConfig(); private static final RadioManager.AmBandConfig AM_BAND_CONFIG = createAmBandConfig(); private static final RadioManager.ModuleProperties AMFM_PROPERTIES = createAmFmProperties(); private static final RadioManager.ModuleProperties AMFM_PROPERTIES = createAmFmProperties(/* dabFrequencyTable= */ null); /** * Info flags with live, tuned and stereo enabled Loading Loading @@ -709,11 +712,19 @@ public final class RadioManagerTest { } @Test public void getDabFrequencyTable_forModuleProperties() { public void getDabFrequencyTable_forModulePropertiesInitializedWithNullTable() { assertWithMessage("Properties DAB frequency table") .that(AMFM_PROPERTIES.getDabFrequencyTable()).isNull(); } @Test public void getDabFrequencyTable_forModulePropertiesInitializedWithEmptyTable() { RadioManager.ModuleProperties properties = createAmFmProperties(new ArrayMap<>()); assertWithMessage("Properties DAB frequency table") .that(properties.getDabFrequencyTable()).isNull(); } @Test public void getVendorInfo_forModuleProperties() { assertWithMessage("Properties vendor info") Loading @@ -733,9 +744,38 @@ public final class RadioManagerTest { .that(AMFM_PROPERTIES.describeContents()).isEqualTo(0); } @Test public void writeToParcel_forModulePropertiesWithNullDabFrequencyTable() { Parcel parcel = Parcel.obtain(); AMFM_PROPERTIES.writeToParcel(parcel, /* flags= */ 0); parcel.setDataPosition(0); RadioManager.ModuleProperties modulePropertiesFromParcel = RadioManager.ModuleProperties.CREATOR.createFromParcel(parcel); assertWithMessage("Module properties created from parcel") .that(modulePropertiesFromParcel).isEqualTo(AMFM_PROPERTIES); } @Test public void writeToParcel_forModulePropertiesWithNonnullDabFrequencyTable() { Parcel parcel = Parcel.obtain(); RadioManager.ModuleProperties propertiesToParcel = createAmFmProperties( Map.of("5A", 174928, "12D", 229072)); propertiesToParcel.writeToParcel(parcel, /* flags= */ 0); parcel.setDataPosition(0); RadioManager.ModuleProperties modulePropertiesFromParcel = RadioManager.ModuleProperties.CREATOR.createFromParcel(parcel); assertWithMessage("Module properties created from parcel") .that(modulePropertiesFromParcel).isEqualTo(propertiesToParcel); } @Test public void equals_withSameProperties_returnsTrue() { RadioManager.ModuleProperties propertiesCompared = createAmFmProperties(); RadioManager.ModuleProperties propertiesCompared = createAmFmProperties(/* dabFrequencyTable= */ null); assertWithMessage("The same module properties") .that(AMFM_PROPERTIES).isEqualTo(propertiesCompared); Loading @@ -747,7 +787,7 @@ public final class RadioManagerTest { PROPERTIES_ID + 1, SERVICE_NAME, CLASS_ID, IMPLEMENTOR, PRODUCT, VERSION, SERIAL, NUM_TUNERS, NUM_AUDIO_SOURCES, IS_INITIALIZATION_REQUIRED, IS_CAPTURE_SUPPORTED, /* bands= */ null, IS_BG_SCAN_SUPPORTED, SUPPORTED_PROGRAM_TYPES, SUPPORTED_IDENTIFIERS_TYPES, /* dabFrequencyTable= */ null, SUPPORTED_PROGRAM_TYPES, SUPPORTED_IDENTIFIERS_TYPES, Map.of("5A", 174928), /* vendorInfo= */ null); assertWithMessage("Module properties of different id") Loading @@ -756,7 +796,8 @@ public final class RadioManagerTest { @Test public void hashCode_withSameModuleProperties_equals() { RadioManager.ModuleProperties propertiesCompared = createAmFmProperties(); RadioManager.ModuleProperties propertiesCompared = createAmFmProperties(/* dabFrequencyTable= */ null); assertWithMessage("Hash code of the same module properties") .that(propertiesCompared.hashCode()).isEqualTo(AMFM_PROPERTIES.hashCode()); Loading Loading @@ -989,13 +1030,14 @@ public final class RadioManagerTest { verify(mCloseHandleMock).close(); } private static RadioManager.ModuleProperties createAmFmProperties() { private static RadioManager.ModuleProperties createAmFmProperties( @Nullable Map<String, Integer> dabFrequencyTable) { return new RadioManager.ModuleProperties(PROPERTIES_ID, SERVICE_NAME, CLASS_ID, IMPLEMENTOR, PRODUCT, VERSION, SERIAL, NUM_TUNERS, NUM_AUDIO_SOURCES, IS_INITIALIZATION_REQUIRED, IS_CAPTURE_SUPPORTED, new RadioManager.BandDescriptor[]{AM_BAND_DESCRIPTOR, FM_BAND_DESCRIPTOR}, IS_BG_SCAN_SUPPORTED, SUPPORTED_PROGRAM_TYPES, SUPPORTED_IDENTIFIERS_TYPES, /* dabFrequencyTable= */ null, /* vendorInfo= */ null); dabFrequencyTable, /* vendorInfo= */ null); } private static RadioManager.FmBandDescriptor createFmBandDescriptor() { Loading