summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Weilin Xu <xuweilin@google.com> 2022-11-21 18:48:57 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2022-11-21 18:48:57 +0000
commit2f3f7856784566fe9ef87d13babb9ee441550abf (patch)
treecfc528fe6a46db21af56ef8e3c9af624f29be7f3
parent3ed2898d28e104e8ee7aae058e7308d7ee370b9d (diff)
parentf73eda0f2f2446c5005d8d602dea9b39b66ea871 (diff)
Merge "Fix BandConfig constructor inconsistency"
-rw-r--r--core/java/android/hardware/radio/RadioManager.java5
-rw-r--r--core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/RadioManagerTest.java36
2 files changed, 38 insertions, 3 deletions
diff --git a/core/java/android/hardware/radio/RadioManager.java b/core/java/android/hardware/radio/RadioManager.java
index 59465dbff939..9a217f9b5119 100644
--- a/core/java/android/hardware/radio/RadioManager.java
+++ b/core/java/android/hardware/radio/RadioManager.java
@@ -921,7 +921,10 @@ public class RadioManager {
@NonNull final BandDescriptor mDescriptor;
BandConfig(BandDescriptor descriptor) {
- mDescriptor = Objects.requireNonNull(descriptor);
+ Objects.requireNonNull(descriptor, "Descriptor cannot be null");
+ mDescriptor = new BandDescriptor(descriptor.getRegion(), descriptor.getType(),
+ descriptor.getLowerLimit(), descriptor.getUpperLimit(),
+ descriptor.getSpacing());
}
BandConfig(int region, int type, int lowerLimit, int upperLimit, int spacing) {
diff --git a/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/RadioManagerTest.java b/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/RadioManagerTest.java
index 365b901beb61..44aa6d19cb0a 100644
--- a/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/RadioManagerTest.java
+++ b/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/RadioManagerTest.java
@@ -187,6 +187,20 @@ public final class RadioManagerTest {
}
@Test
+ public void writeToParcel_forBandDescriptor() {
+ Parcel parcel = Parcel.obtain();
+ RadioManager.BandDescriptor bandDescriptor = createFmBandDescriptor();
+
+ bandDescriptor.writeToParcel(parcel, /* flags= */ 0);
+ parcel.setDataPosition(0);
+
+ RadioManager.BandDescriptor bandDescriptorFromParcel =
+ RadioManager.BandDescriptor.CREATOR.createFromParcel(parcel);
+ assertWithMessage("Band Descriptor created from parcel")
+ .that(bandDescriptorFromParcel).isEqualTo(bandDescriptor);
+ }
+
+ @Test
public void newArray_forBandDescriptorCreator() {
RadioManager.BandDescriptor[] bandDescriptors =
RadioManager.BandDescriptor.CREATOR.newArray(CREATOR_ARRAY_SIZE);
@@ -421,6 +435,20 @@ public final class RadioManagerTest {
}
@Test
+ public void writeToParcel_forBandConfig() {
+ Parcel parcel = Parcel.obtain();
+ RadioManager.BandConfig bandConfig = createAmBandConfig();
+
+ bandConfig.writeToParcel(parcel, /* flags= */ 0);
+ parcel.setDataPosition(0);
+
+ RadioManager.BandConfig bandConfigFromParcel =
+ RadioManager.BandConfig.CREATOR.createFromParcel(parcel);
+ assertWithMessage("Band Config created from parcel")
+ .that(bandConfigFromParcel).isEqualTo(bandConfig);
+ }
+
+ @Test
public void newArray_forBandConfigCreator() {
RadioManager.BandConfig[] bandConfigs =
RadioManager.BandConfig.CREATOR.newArray(CREATOR_ARRAY_SIZE);
@@ -520,7 +548,9 @@ public final class RadioManagerTest {
@Test
public void equals_withSameFmBandConfigs_returnsTrue() {
- RadioManager.FmBandConfig fmBandConfigCompared = createFmBandConfig();
+ RadioManager.FmBandConfig.Builder builder =
+ new RadioManager.FmBandConfig.Builder(FM_BAND_CONFIG);
+ RadioManager.FmBandConfig fmBandConfigCompared = builder.build();
assertWithMessage("The same FM Band Config")
.that(FM_BAND_CONFIG).isEqualTo(fmBandConfigCompared);
@@ -545,7 +575,9 @@ public final class RadioManagerTest {
@Test
public void equals_withSameAmBandConfigs_returnsTrue() {
- RadioManager.AmBandConfig amBandConfigCompared = createAmBandConfig();
+ RadioManager.AmBandConfig.Builder builder =
+ new RadioManager.AmBandConfig.Builder(AM_BAND_CONFIG);
+ RadioManager.AmBandConfig amBandConfigCompared = builder.build();
assertWithMessage("The same AM Band Config")
.that(AM_BAND_CONFIG).isEqualTo(amBandConfigCompared);