Merge "Add ContentStyle to media, implement with radio" into pi-dev
diff --git a/car-broadcastradio-support/src/com/android/car/broadcastradio/support/Program.java b/car-broadcastradio-support/src/com/android/car/broadcastradio/support/Program.java
index 4d1de73..af57c90 100644
--- a/car-broadcastradio-support/src/com/android/car/broadcastradio/support/Program.java
+++ b/car-broadcastradio-support/src/com/android/car/broadcastradio/support/Program.java
@@ -53,7 +53,7 @@
 
     /** @hide */
     public @Nullable Bitmap getIcon() {
-        // TODO(b/75970985): implement saving icons
+        // TODO(b/73950974): implement saving icons
         return null;
     }
 
diff --git a/car-broadcastradio-support/src/com/android/car/broadcastradio/support/media/BrowseTree.java b/car-broadcastradio-support/src/com/android/car/broadcastradio/support/media/BrowseTree.java
index 6687476..f898f18 100644
--- a/car-broadcastradio-support/src/com/android/car/broadcastradio/support/media/BrowseTree.java
+++ b/car-broadcastradio-support/src/com/android/car/broadcastradio/support/media/BrowseTree.java
@@ -96,6 +96,29 @@
      */
     public static final long BCRADIO_FOLDER_TYPE_BAND = 3;
 
+    /**
+     * Non-localized name of the band.
+     *
+     * For now, it can only take one of the following values:
+     *  - AM;
+     *  - FM;
+     *  - DAB;
+     *  - SXM.
+     *
+     * However, in future releases the list might get extended.
+     */
+    public static final String EXTRA_BCRADIO_BAND_NAME_EN =
+            "android.media.extra.EXTRA_BCRADIO_BAND_NAME_EN";
+
+    /**
+     * General play intent action.
+     *
+     * MediaBrowserService of the radio app must handle this command to perform general
+     * "play" command. It usually means starting playback of recently tuned station.
+     */
+    public static final String ACTION_PLAY_BROADCASTRADIO =
+            "android.car.intent.action.PLAY_BROADCASTRADIO";
+
     private static final String NODE_ROOT = "root_id";
     private static final String NODE_PROGRAMS = "programs_id";
     private static final String NODE_FAVORITES = "favorites_id";
@@ -113,9 +136,9 @@
     private List<MediaItem> mRootChildren;
 
     private final AmFmChannelList mAmChannels = new AmFmChannelList(
-            NODEPREFIX_BAND + "am", R.string.radio_am_text);
+            NODEPREFIX_BAND + "am", R.string.radio_am_text, "AM");
     private final AmFmChannelList mFmChannels = new AmFmChannelList(
-            NODEPREFIX_BAND + "fm", R.string.radio_fm_text);
+            NODEPREFIX_BAND + "fm", R.string.radio_fm_text, "FM");
 
     private final ProgramList.OnCompleteListener mProgramListCompleteListener =
             this::onProgramListUpdated;
@@ -150,8 +173,8 @@
     }
 
     private static MediaItem createFolder(MediaDescriptionCompat.Builder descBuilder,
-            String mediaId, String title, boolean isPlayable, long folderType) {
-        Bundle extras = new Bundle();
+            String mediaId, String title, boolean isPlayable, long folderType, Bundle extras) {
+        if (extras == null) extras = new Bundle();
         extras.putLong(EXTRA_BCRADIO_FOLDER_TYPE, folderType);
         extras.putBoolean(ContentStyleMediaConstants.CONTENT_STYLE_SUPPORTED, true);
         extras.putInt(ContentStyleMediaConstants.CONTENT_STYLE_PLAYABLE_HINT,
@@ -323,12 +346,12 @@
             if (mProgramList != null) {
                 mRootChildren.add(createFolder(dbld, NODE_PROGRAMS,
                         mBrowserService.getString(R.string.program_list_text),
-                        false, BCRADIO_FOLDER_TYPE_PROGRAMS));
+                        false, BCRADIO_FOLDER_TYPE_PROGRAMS, null));
             }
             if (mFavorites != null) {
                 mRootChildren.add(createFolder(dbld, NODE_FAVORITES,
                         mBrowserService.getString(R.string.favorites_list_text),
-                        true, BCRADIO_FOLDER_TYPE_FAVORITES));
+                        true, BCRADIO_FOLDER_TYPE_FAVORITES, null));
             }
 
             MediaItem amRoot = mAmChannels.getBandRoot();
@@ -343,12 +366,15 @@
     private class AmFmChannelList {
         public final @NonNull String mMediaId;
         private final @StringRes int mBandName;
+        private final @NonNull String mBandNameEn;
         private @Nullable List<BandDescriptor> mBands;
         private @Nullable List<MediaItem> mChannels;
 
-        private AmFmChannelList(@NonNull String mediaId, @StringRes int bandName) {
+        private AmFmChannelList(@NonNull String mediaId, @StringRes int bandName,
+                @NonNull String bandNameEn) {
             mMediaId = Objects.requireNonNull(mediaId);
             mBandName = bandName;
+            mBandNameEn = Objects.requireNonNull(bandNameEn);
         }
 
         public void setBands(List<BandDescriptor> bands) {
@@ -369,8 +395,10 @@
 
         public @Nullable MediaItem getBandRoot() {
             if (isEmpty()) return null;
+            Bundle extras = new Bundle();
+            extras.putString(EXTRA_BCRADIO_BAND_NAME_EN, mBandNameEn);
             return createFolder(new MediaDescriptionCompat.Builder(), mMediaId,
-                    mBrowserService.getString(mBandName), true, BCRADIO_FOLDER_TYPE_BAND);
+                    mBrowserService.getString(mBandName), true, BCRADIO_FOLDER_TYPE_BAND, extras);
         }
 
         public List<MediaItem> getChannels() {
diff --git a/car-media-common/src/com/android/car/media/common/MediaSource.java b/car-media-common/src/com/android/car/media/common/MediaSource.java
index 78bbd64..fe393e7 100644
--- a/car-media-common/src/com/android/car/media/common/MediaSource.java
+++ b/car-media-common/src/com/android/car/media/common/MediaSource.java
@@ -92,9 +92,6 @@
      * Custom media sources which should not be templatized.
      */
     private static final Set<String> CUSTOM_MEDIA_SOURCES = new HashSet<>();
-    static {
-        CUSTOM_MEDIA_SOURCES.add("com.android.car.radio");
-    }
 
     /**
      * An observer of this media source.
diff --git a/car-media-common/src/com/android/car/media/common/PlaybackModel.java b/car-media-common/src/com/android/car/media/common/PlaybackModel.java
index c472911..6206afe 100644
--- a/car-media-common/src/com/android/car/media/common/PlaybackModel.java
+++ b/car-media-common/src/com/android/car/media/common/PlaybackModel.java
@@ -320,6 +320,15 @@
     }
 
     /**
+     * Prepares the current media source for playback.
+     */
+    public void onPrepare() {
+        if (mMediaController != null) {
+            mMediaController.getTransportControls().prepare();
+        }
+    }
+
+    /**
      * Possible main actions.
      */
     @IntDef({ACTION_PLAY, ACTION_STOP, ACTION_PAUSE, ACTION_DISABLED})