Merge "Add ContentStyle to media, implement with radio" into pi-dev
diff --git a/car-broadcastradio-support/Android.mk b/car-broadcastradio-support/Android.mk
index 3184f72..11b01ae 100644
--- a/car-broadcastradio-support/Android.mk
+++ b/car-broadcastradio-support/Android.mk
@@ -31,6 +31,7 @@
 LOCAL_USE_AAPT2 := true
 
 LOCAL_STATIC_ANDROID_LIBRARIES := \
-    android-support-v4
+    android-support-v4 \
+    car-media-common
 
 include $(BUILD_STATIC_JAVA_LIBRARY)
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 347bb82..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
@@ -39,6 +39,7 @@
 import com.android.car.broadcastradio.support.platform.ProgramInfoExt;
 import com.android.car.broadcastradio.support.platform.ProgramSelectorExt;
 import com.android.car.broadcastradio.support.platform.RadioMetadataExt;
+import com.android.car.media.common.ContentStyleMediaConstants;
 
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -175,6 +176,11 @@
             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,
+                ContentStyleMediaConstants.CONTENT_STYLE_LIST_ITEM_HINT_VALUE);
+        extras.putInt(ContentStyleMediaConstants.CONTENT_STYLE_BROWSABLE_HINT,
+                ContentStyleMediaConstants.CONTENT_STYLE_LIST_ITEM_HINT_VALUE);
 
         MediaDescriptionCompat desc = descBuilder
                 .setMediaId(mediaId).setTitle(title).setExtras(extras).build();
diff --git a/car-media-common/src/com/android/car/media/common/ContentStyleMediaConstants.java b/car-media-common/src/com/android/car/media/common/ContentStyleMediaConstants.java
new file mode 100644
index 0000000..52a854d
--- /dev/null
+++ b/car-media-common/src/com/android/car/media/common/ContentStyleMediaConstants.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.car.media.common;
+
+/**
+ * Holds constants used when dealing with MediaBrowserServices that support the
+ * content style API for media.
+ */
+public final class ContentStyleMediaConstants {
+
+    /** Declares that ContentStyle is supported */
+    public static final String CONTENT_STYLE_SUPPORTED =
+            "android.auto.media.CONTENT_STYLE_SUPPORTED";
+
+    /**
+     * Bundle extra indicating the presentation hint for playable media items. See {@link
+     * #CONTENT_STYLE_LIST_ITEM_HINT_VALUE} or {@link #CONTENT_STYLE_GRID_ITEM_HINT_VALUE}
+     */
+    public static final String CONTENT_STYLE_PLAYABLE_HINT =
+            "android.auto.media.CONTENT_STYLE_PLAYABLE_HINT";
+
+    /**
+     * Bundle extra indicating the presentation hint for browsable media items. See {@link
+     * #CONTENT_STYLE_LIST_ITEM_HINT_VALUE} or {@link #CONTENT_STYLE_GRID_ITEM_HINT_VALUE}
+     */
+    public static final String CONTENT_STYLE_BROWSABLE_HINT =
+            "android.auto.media.CONTENT_STYLE_BROWSABLE_HINT";
+
+    /**
+     * Value for {@link #CONTENT_STYLE_PLAYABLE_HINT} and {@link #CONTENT_STYLE_BROWSABLE_HINT} that
+     * hints the corresponding items should be presented as lists.
+     */
+    public static final int CONTENT_STYLE_LIST_ITEM_HINT_VALUE = 1;
+
+    /**
+     * Value for {@link #CONTENT_STYLE_PLAYABLE_HINT} and {@link #CONTENT_STYLE_BROWSABLE_HINT} that
+     * hints the corresponding items should be presented as grids.
+     */
+    public static final int CONTENT_STYLE_GRID_ITEM_HINT_VALUE = 2;
+}
diff --git a/car-media-common/src/com/android/car/media/common/MediaItemMetadata.java b/car-media-common/src/com/android/car/media/common/MediaItemMetadata.java
index 6d14e70..639f6bf 100644
--- a/car-media-common/src/com/android/car/media/common/MediaItemMetadata.java
+++ b/car-media-common/src/com/android/car/media/common/MediaItemMetadata.java
@@ -27,6 +27,7 @@
 import android.media.browse.MediaBrowser;
 import android.media.session.MediaSession;
 import android.net.Uri;
+import android.os.Bundle;
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.widget.ImageView;
@@ -240,10 +241,36 @@
         return mIsBrowsable;
     }
 
+    /**
+     * @return Content style hint for browsable items, if provided as an extra, or
+     * 0 as default value if not provided.
+     */
+    public int getBrowsableContentStyleHint() {
+        Bundle extras = mMediaDescription.getExtras();
+        if (extras != null && extras.getBoolean(
+                ContentStyleMediaConstants.CONTENT_STYLE_SUPPORTED, false)) {
+            return extras.getInt(ContentStyleMediaConstants.CONTENT_STYLE_BROWSABLE_HINT, 0);
+        }
+        return 0;
+    }
+
     public boolean isPlayable() {
         return mIsPlayable;
     }
 
+    /**
+     * @return Content style hint for playable items, if provided as an extra, or
+     * 0 as default value if not provided.
+     */
+    public int getPlayableContentStyleHint() {
+        Bundle extras = mMediaDescription.getExtras();
+        if (extras != null && extras.getBoolean(
+                ContentStyleMediaConstants.CONTENT_STYLE_SUPPORTED, false)) {
+            return extras.getInt(ContentStyleMediaConstants.CONTENT_STYLE_PLAYABLE_HINT, 0);
+        }
+        return 0;
+    }
+
     @Override
     public boolean equals(Object o) {
         if (this == o) return true;