summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/hardware/radio/RadioManager.java60
-rw-r--r--core/tests/BroadcastRadioTests/src/android/hardware/radio/RadioManagerTest.java107
2 files changed, 158 insertions, 9 deletions
diff --git a/core/java/android/hardware/radio/RadioManager.java b/core/java/android/hardware/radio/RadioManager.java
index a8a2276570d8..c6fa9c2f99c1 100644
--- a/core/java/android/hardware/radio/RadioManager.java
+++ b/core/java/android/hardware/radio/RadioManager.java
@@ -1556,6 +1556,30 @@ public class RadioManager {
@Nullable Collection<ProgramSelector.Identifier> relatedContent,
int infoFlags, int signalQuality, @Nullable RadioMetadata metadata,
@Nullable Map<String, String> vendorInfo) {
+ this(selector, logicallyTunedTo, physicallyTunedTo, relatedContent, infoFlags,
+ signalQuality, metadata, vendorInfo, /* alert= */ null);
+ }
+
+ /**
+ * Constructor for program info.
+ *
+ * @param selector Program selector
+ * @param logicallyTunedTo Program identifier logically tuned to
+ * @param physicallyTunedTo Program identifier physically tuned to
+ * @param relatedContent Related content
+ * @param infoFlags Program info flags
+ * @param signalQuality Signal quality
+ * @param metadata Radio metadata
+ * @param vendorInfo Vendor parameters
+ * @param alert Radio alert
+ * @hide
+ */
+ public ProgramInfo(@NonNull ProgramSelector selector,
+ @Nullable ProgramSelector.Identifier logicallyTunedTo,
+ @Nullable ProgramSelector.Identifier physicallyTunedTo,
+ @Nullable Collection<ProgramSelector.Identifier> relatedContent,
+ int infoFlags, int signalQuality, @Nullable RadioMetadata metadata,
+ @Nullable Map<String, String> vendorInfo, @Nullable RadioAlert alert) {
mSelector = Objects.requireNonNull(selector);
mLogicallyTunedTo = logicallyTunedTo;
mPhysicallyTunedTo = physicallyTunedTo;
@@ -1569,8 +1593,7 @@ public class RadioManager {
mSignalQuality = signalQuality;
mMetadata = metadata;
mVendorInfo = (vendorInfo == null) ? new HashMap<>() : vendorInfo;
- // TODO(361348719): implement alert in the constructor
- mAlert = null;
+ mAlert = alert;
}
/**
@@ -1802,7 +1825,12 @@ public class RadioManager {
mSignalQuality = in.readInt();
mMetadata = in.readTypedObject(RadioMetadata.CREATOR);
mVendorInfo = Utils.readStringMap(in);
- mAlert = null;
+ if (Flags.hdRadioEmergencyAlertSystem()) {
+ boolean hasNonNullAlert = in.readBoolean();
+ mAlert = hasNonNullAlert ? in.readTypedObject(RadioAlert.CREATOR) : null;
+ } else {
+ mAlert = null;
+ }
}
public static final @android.annotation.NonNull Parcelable.Creator<ProgramInfo> CREATOR
@@ -1826,6 +1854,14 @@ public class RadioManager {
dest.writeInt(mSignalQuality);
dest.writeTypedObject(mMetadata, flags);
Utils.writeStringMap(dest, mVendorInfo);
+ if (Flags.hdRadioEmergencyAlertSystem()) {
+ if (mAlert == null) {
+ dest.writeBoolean(false);
+ } else {
+ dest.writeBoolean(true);
+ dest.writeTypedObject(mAlert, flags);
+ }
+ }
}
@Override
@@ -1836,19 +1872,28 @@ public class RadioManager {
@NonNull
@Override
public String toString() {
- return "ProgramInfo"
+ String prorgamInfoString = "ProgramInfo"
+ " [selector=" + mSelector
+ ", logicallyTunedTo=" + Objects.toString(mLogicallyTunedTo)
+ ", physicallyTunedTo=" + Objects.toString(mPhysicallyTunedTo)
+ ", relatedContent=" + mRelatedContent.size()
+ ", infoFlags=" + mInfoFlags
+ ", signalQuality=" + mSignalQuality
- + ", metadata=" + Objects.toString(mMetadata)
- + "]";
+ + ", metadata=" + Objects.toString(mMetadata);
+ if (Flags.hdRadioEmergencyAlertSystem()) {
+ prorgamInfoString += ", alert=" + Objects.toString(mAlert);
+ }
+ prorgamInfoString += "]";
+ return prorgamInfoString;
}
@Override
public int hashCode() {
+ if (Flags.hdRadioEmergencyAlertSystem()) {
+ return Objects.hash(mSelector, mLogicallyTunedTo, mPhysicallyTunedTo,
+ mRelatedContent, mInfoFlags, mSignalQuality, mMetadata, mVendorInfo,
+ mAlert);
+ }
return Objects.hash(mSelector, mLogicallyTunedTo, mPhysicallyTunedTo,
mRelatedContent, mInfoFlags, mSignalQuality, mMetadata, mVendorInfo);
}
@@ -1868,6 +1913,9 @@ public class RadioManager {
if (!Objects.equals(mMetadata, other.mMetadata)) return false;
if (!Objects.equals(mVendorInfo, other.mVendorInfo)) return false;
+ if (Flags.hdRadioEmergencyAlertSystem()) {
+ return Objects.equals(mAlert, other.mAlert);
+ }
return true;
}
}
diff --git a/core/tests/BroadcastRadioTests/src/android/hardware/radio/RadioManagerTest.java b/core/tests/BroadcastRadioTests/src/android/hardware/radio/RadioManagerTest.java
index 4c3d4e3af99f..7609d0d50f46 100644
--- a/core/tests/BroadcastRadioTests/src/android/hardware/radio/RadioManagerTest.java
+++ b/core/tests/BroadcastRadioTests/src/android/hardware/radio/RadioManagerTest.java
@@ -31,6 +31,8 @@ import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.os.Parcel;
import android.os.RemoteException;
+import android.platform.test.annotations.DisableFlags;
+import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.util.ArrayMap;
@@ -142,10 +144,13 @@ public final class RadioManagerTest {
new ProgramSelector.Identifier[]{}, /* vendorIds= */ null);
private static final RadioMetadata METADATA = createMetadata();
+ private static final RadioAlert HD_ALERT = createRadioAlert();
private static final RadioManager.ProgramInfo DAB_PROGRAM_INFO =
createDabProgramInfo(DAB_SELECTOR);
private static final RadioManager.ProgramInfo HD_PROGRAM_INFO = createHdProgramInfo(
- HD_SELECTOR);
+ HD_SELECTOR, /* alert= */ null);
+ private static final RadioManager.ProgramInfo HD_PROGRAM_INFO_WITH_ALERT = createHdProgramInfo(
+ HD_SELECTOR, HD_ALERT);
private static final int EVENT_ANNOUNCEMENT_TYPE = Announcement.TYPE_EVENT;
private static final List<Announcement> TEST_ANNOUNCEMENT_LIST = Arrays.asList(
@@ -1163,6 +1168,20 @@ public final class RadioManagerTest {
}
@Test
+ @EnableFlags(Flags.FLAG_HD_RADIO_EMERGENCY_ALERT_SYSTEM)
+ public void getAlert() {
+ mExpect.withMessage("Alert in HD program info")
+ .that(HD_PROGRAM_INFO_WITH_ALERT.getAlert()).isEqualTo(HD_ALERT);
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_HD_RADIO_EMERGENCY_ALERT_SYSTEM)
+ public void getAlert_withNullAlert() {
+ mExpect.withMessage("Null alert in HD program info")
+ .that(HD_PROGRAM_INFO.getAlert()).isNull();
+ }
+
+ @Test
public void describeContents_forProgramInfo() {
mExpect.withMessage("Program info contents")
.that(DAB_PROGRAM_INFO.describeContents()).isEqualTo(0);
@@ -1190,6 +1209,69 @@ public final class RadioManagerTest {
}
@Test
+ @DisableFlags(Flags.FLAG_HD_RADIO_EMERGENCY_ALERT_SYSTEM)
+ public void equals_forProgramInfoWithAlertAndFlagDisabled() {
+ mExpect.withMessage("Program info with alert and flag disabled")
+ .that(HD_PROGRAM_INFO_WITH_ALERT).isEqualTo(HD_PROGRAM_INFO);
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_HD_RADIO_EMERGENCY_ALERT_SYSTEM)
+ public void equals_forProgramInfoWithAlertAndFlagEnabled() {
+ RadioManager.ProgramInfo sameProgramInfoWithAlert = createHdProgramInfo(HD_SELECTOR,
+ HD_ALERT);
+
+ mExpect.withMessage("Program info with alert and flag enabled")
+ .that(HD_PROGRAM_INFO_WITH_ALERT).isEqualTo(sameProgramInfoWithAlert);
+ }
+
+ @Test
+ @DisableFlags(Flags.FLAG_HD_RADIO_EMERGENCY_ALERT_SYSTEM)
+ public void hashcode_forProgramInfoWithAlertAndFlagDisabled() {
+ mExpect.withMessage("Hash code of program info with alert and flag disabled")
+ .that(HD_PROGRAM_INFO_WITH_ALERT.hashCode()).isEqualTo(HD_PROGRAM_INFO.hashCode());
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_HD_RADIO_EMERGENCY_ALERT_SYSTEM)
+ public void hashcode_forProgramInfoWithAlertAndFlagEnabled() {
+ RadioManager.ProgramInfo sameProgramInfoWithAlert = createHdProgramInfo(HD_SELECTOR,
+ HD_ALERT);
+
+ mExpect.withMessage("Hash code of program info with alert and flag enabled")
+ .that(HD_PROGRAM_INFO_WITH_ALERT.hashCode())
+ .isEqualTo(sameProgramInfoWithAlert.hashCode());
+ }
+
+ @Test
+ @DisableFlags(Flags.FLAG_HD_RADIO_EMERGENCY_ALERT_SYSTEM)
+ public void writeToParcel_forProgramInfoWithAlertAndFlagDisabled() {
+ Parcel parcel = Parcel.obtain();
+
+ HD_PROGRAM_INFO_WITH_ALERT.writeToParcel(parcel, /* flags= */ 0);
+ parcel.setDataPosition(0);
+
+ RadioManager.ProgramInfo programInfoFromParcel =
+ RadioManager.ProgramInfo.CREATOR.createFromParcel(parcel);
+ mExpect.withMessage("Program info created from parcel with alert and flag disabled")
+ .that(programInfoFromParcel).isEqualTo(HD_PROGRAM_INFO);
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_HD_RADIO_EMERGENCY_ALERT_SYSTEM)
+ public void writeToParcel_forProgramInfoWithAlertAndFlagEnabled() {
+ Parcel parcel = Parcel.obtain();
+
+ HD_PROGRAM_INFO_WITH_ALERT.writeToParcel(parcel, /* flags= */ 0);
+ parcel.setDataPosition(0);
+
+ RadioManager.ProgramInfo programInfoFromParcel =
+ RadioManager.ProgramInfo.CREATOR.createFromParcel(parcel);
+ mExpect.withMessage("Program info created from parcel with alert and flag enabled")
+ .that(programInfoFromParcel).isEqualTo(HD_PROGRAM_INFO_WITH_ALERT);
+ }
+
+ @Test
public void equals_withSameProgramInfo_returnsTrue() {
RadioManager.ProgramInfo dabProgramInfoCompared = createDabProgramInfo(DAB_SELECTOR);
@@ -1210,6 +1292,13 @@ public final class RadioManagerTest {
}
@Test
+ @EnableFlags(Flags.FLAG_HD_RADIO_EMERGENCY_ALERT_SYSTEM)
+ public void equals_withDifferentAlert_returnsFalse() {
+ mExpect.withMessage("Program info with different alerts")
+ .that(HD_PROGRAM_INFO).isNotEqualTo(HD_PROGRAM_INFO_WITH_ALERT);
+ }
+
+ @Test
public void listModules_forRadioManager() throws Exception {
createRadioManager();
List<RadioManager.ModuleProperties> modules = new ArrayList<>();
@@ -1399,19 +1488,31 @@ public final class RadioManagerTest {
return metadataBuilder.putString(RadioMetadata.METADATA_KEY_ARTIST, "artistTest").build();
}
+ private static RadioAlert createRadioAlert() {
+ RadioAlert.AlertArea alertArea = new RadioAlert.AlertArea(new ArrayList<>(),
+ List.of(new RadioAlert.Geocode("SAME", "006109")));
+ RadioAlert.AlertInfo alertInfo = new RadioAlert.AlertInfo(
+ new int[]{RadioAlert.CATEGORY_FIRE}, RadioAlert.URGENCY_EXPECTED,
+ RadioAlert.SEVERITY_MODERATE, RadioAlert.CERTAINTY_OBSERVED,
+ "alert description", List.of(alertArea), "en-US");
+ return new RadioAlert(RadioAlert.STATUS_ACTUAL, RadioAlert.MESSAGE_TYPE_ALERT,
+ List.of(alertInfo));
+ }
+
private static RadioManager.ProgramInfo createDabProgramInfo(ProgramSelector selector) {
return new RadioManager.ProgramInfo(selector, selector.getPrimaryId(),
DAB_FREQUENCY_IDENTIFIER, Arrays.asList(DAB_SID_EXT_IDENTIFIER_RELATED),
INFO_FLAGS_DAB, SIGNAL_QUALITY, METADATA, /* vendorInfo= */ null);
}
- private static RadioManager.ProgramInfo createHdProgramInfo(ProgramSelector selector) {
+ private static RadioManager.ProgramInfo createHdProgramInfo(ProgramSelector selector,
+ RadioAlert alert) {
long frequency = (selector.getPrimaryId().getValue() >> 32);
ProgramSelector.Identifier physicallyTunedToId = new ProgramSelector.Identifier(
ProgramSelector.IDENTIFIER_TYPE_AMFM_FREQUENCY, frequency);
return new RadioManager.ProgramInfo(selector, selector.getPrimaryId(), physicallyTunedToId,
Collections.emptyList(), INFO_FLAGS_HD, SIGNAL_QUALITY, METADATA,
- /* vendorInfo= */ null);
+ /* vendorInfo= */ null, alert);
}
private void createRadioManager() throws RemoteException {