From 4e156d7e18c196f489c3743d6d86c8ed2136b1e2 Mon Sep 17 00:00:00 2001 From: Mark Stanford Date: Sat, 28 Jan 2023 01:47:01 +0000 Subject: Add toMediaMetadata and getProgramName that take list of program name keys as paramter Current API does not allow user of API to supply list of program name keys. Bug: 259997283 Test: manual. CarRadioApp Change-Id: I6a980c7455a07cfce5e77968021890b003bc2d54 --- .../support/platform/ProgramInfoExt.java | 110 ++++++++++++++++++--- 1 file changed, 98 insertions(+), 12 deletions(-) (limited to 'car-broadcastradio-support') diff --git a/car-broadcastradio-support/src/com/android/car/broadcastradio/support/platform/ProgramInfoExt.java b/car-broadcastradio-support/src/com/android/car/broadcastradio/support/platform/ProgramInfoExt.java index ce3d014..d377dbd 100644 --- a/car-broadcastradio-support/src/com/android/car/broadcastradio/support/platform/ProgramInfoExt.java +++ b/car-broadcastradio-support/src/com/android/car/broadcastradio/support/platform/ProgramInfoExt.java @@ -21,6 +21,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.graphics.Bitmap; import android.hardware.radio.ProgramSelector; +import android.hardware.radio.RadioManager; import android.hardware.radio.RadioManager.ProgramInfo; import android.hardware.radio.RadioMetadata; import android.media.MediaMetadata; @@ -29,6 +30,7 @@ import android.util.Log; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.util.Objects; /** * Proposed extensions to android.hardware.radio.RadioManager.ProgramInfo. @@ -71,13 +73,23 @@ public class ProgramInfoExt { /** * Returns program name suitable to display. * - * If there is no program name, it falls back to channel name. Flags related to + *

If there is no program name, it falls back to channel name. Flags related to * the channel name display will be forwarded to the channel name generation method. + * + * @param info {@link ProgramInfo} to get name from + * @param flags Fallback method + * @param programNameOrder {@link RadioMetadata} metadata keys to pull from {@link ProgramInfo} + * for the program name */ - public static @NonNull String getProgramName(@NonNull ProgramInfo info, @NameFlag int flags) { + @NonNull + public static String getProgramName(@NonNull ProgramInfo info, @NameFlag int flags, + @NonNull String[] programNameOrder) { + Objects.requireNonNull(info, "info can not be null."); + Objects.requireNonNull(programNameOrder, "programNameOrder can not be null"); + RadioMetadata meta = info.getMetadata(); if (meta != null) { - for (String key : PROGRAM_NAME_ORDER) { + for (String key : programNameOrder) { String value = meta.getString(key); if (value != null) return value; } @@ -103,6 +115,17 @@ public class ProgramInfoExt { return ""; } + /** + * Returns program name suitable to display. + * + *

If there is no program name, it falls back to channel name. Flags related to + * the channel name display will be forwarded to the channel name generation method. + */ + @NonNull + public static String getProgramName(@NonNull ProgramInfo info, @NameFlag int flags) { + return getProgramName(info, flags, PROGRAM_NAME_ORDER); + } + /** * Proposed reimplementation of {@link RadioManager#ProgramInfo#getMetadata}. * @@ -118,12 +141,69 @@ public class ProgramInfoExt { } /** - * Converts {@ProgramInfo} to {@MediaMetadata}. + * Converts {@link ProgramInfo} to {@link MediaMetadata} for displaying. * - * This method is meant to be used for currently playing station in {@link MediaSession}. + *

This method is meant to be used for displaying the currently playing station in + * {@link MediaSession}, only a subset of keys populated in {@link ProgramInfo#toMediaMetadata} + * will be populated in this method. + * + *