Don't crash system process on empty onTuneFailed
This change:
- modifies internal programSelectorFromHal to return null instead of
throwing NPE on empty input
- throws NPE on two of its usages where null is unexpected
- *does not* throw NPE on one usage where program selector is optional
(onTuneFailed in RadioModule.java)
Bug: 147522441
Test: boots, but have no quick way to trigger onTuneFailed(Result::error, {})
Change-Id: I6317da3fbde2bce90079b61bb0839e893e1c4712
(cherry picked from commit dc8a5683a149b4f5ce3d9a9f6198fbe310547dbf)
diff --git a/services/core/java/com/android/server/broadcastradio/hal2/Convert.java b/services/core/java/com/android/server/broadcastradio/hal2/Convert.java
index 9730c9a..ab5bef8 100644
--- a/services/core/java/com/android/server/broadcastradio/hal2/Convert.java
+++ b/services/core/java/com/android/server/broadcastradio/hal2/Convert.java
@@ -275,8 +275,18 @@
return hwSel;
}
- static @NonNull ProgramSelector programSelectorFromHal(
+ private static boolean isEmpty(
@NonNull android.hardware.broadcastradio.V2_0.ProgramSelector sel) {
+ if (sel.primaryId.type != 0) return false;
+ if (sel.primaryId.value != 0) return false;
+ if (sel.secondaryIds.size() != 0) return false;
+ return true;
+ }
+
+ static @Nullable ProgramSelector programSelectorFromHal(
+ @NonNull android.hardware.broadcastradio.V2_0.ProgramSelector sel) {
+ if (isEmpty(sel)) return null;
+
ProgramSelector.Identifier[] secondaryIds = sel.secondaryIds.stream().
map(Convert::programIdentifierFromHal).map(Objects::requireNonNull).
toArray(ProgramSelector.Identifier[]::new);
@@ -364,7 +374,7 @@
collect(Collectors.toList());
return new RadioManager.ProgramInfo(
- programSelectorFromHal(info.selector),
+ Objects.requireNonNull(programSelectorFromHal(info.selector)),
programIdentifierFromHal(info.logicallyTunedTo),
programIdentifierFromHal(info.physicallyTunedTo),
relatedContent,
@@ -402,7 +412,7 @@
public static @NonNull android.hardware.radio.Announcement announcementFromHal(
@NonNull Announcement hwAnnouncement) {
return new android.hardware.radio.Announcement(
- programSelectorFromHal(hwAnnouncement.selector),
+ Objects.requireNonNull(programSelectorFromHal(hwAnnouncement.selector)),
hwAnnouncement.type,
vendorInfoFromHal(hwAnnouncement.vendorInfo)
);