MediaRouter: Add an API to set the receiver device type of the route

Used to determine the default icon of a given route when a custom icon
is not specified.

Bug: 23116379
Change-Id: I1188c10b679e4693ae1aab9ced0f842d4fc80881
diff --git a/v7/mediarouter/src/android/support/v7/app/MediaRouteChooserDialog.java b/v7/mediarouter/src/android/support/v7/app/MediaRouteChooserDialog.java
index 9b7f990..4e2f9cc 100644
--- a/v7/mediarouter/src/android/support/v7/app/MediaRouteChooserDialog.java
+++ b/v7/mediarouter/src/android/support/v7/app/MediaRouteChooserDialog.java
@@ -304,6 +304,14 @@
         }
 
         private Drawable getDefaultIconDrawable(MediaRouter.RouteInfo route) {
+            // If the type of the receiver device is specified, use it.
+            int deviceType = route.getDeviceType();
+            if (deviceType == MediaRouter.RouteInfo.DEVICE_TYPE_SPEAKER) {
+                return mSpeakerIcon;
+            } else if (deviceType == MediaRouter.RouteInfo.DEVICE_TYPE_BLUETOOTH) {
+                return mBluetoothIcon;
+            }
+            // Otherwise, make the best guess based on other route information.
             if (route instanceof MediaRouter.RouteGroup) {
                 // Only speakers can be grouped for now.
                 return mSpeakerGroupIcon;
diff --git a/v7/mediarouter/src/android/support/v7/media/MediaRouteDescriptor.java b/v7/mediarouter/src/android/support/v7/media/MediaRouteDescriptor.java
index 8e5ad25..fcb4236 100644
--- a/v7/mediarouter/src/android/support/v7/media/MediaRouteDescriptor.java
+++ b/v7/mediarouter/src/android/support/v7/media/MediaRouteDescriptor.java
@@ -48,6 +48,7 @@
     private static final String KEY_CONTROL_FILTERS = "controlFilters";
     private static final String KEY_PLAYBACK_TYPE = "playbackType";
     private static final String KEY_PLAYBACK_STREAM = "playbackStream";
+    private static final String KEY_DEVICE_TYPE = "deviceType";
     private static final String KEY_VOLUME = "volume";
     private static final String KEY_VOLUME_MAX = "volumeMax";
     private static final String KEY_VOLUME_HANDLING = "volumeHandling";
@@ -209,6 +210,16 @@
     }
 
     /**
+     * Gets the route's receiver device type.
+     *
+     * @hide
+     * STOPSHIP: Unhide or remove.
+     */
+    public int getDeviceType() {
+        return mBundle.getInt(KEY_DEVICE_TYPE);
+    }
+
+    /**
      * Gets the route's current volume, or 0 if unknown.
      */
     public int getVolume() {
@@ -275,6 +286,7 @@
         result.append(", controlFilters=").append(Arrays.toString(getControlFilters().toArray()));
         result.append(", playbackType=").append(getPlaybackType());
         result.append(", playbackStream=").append(getPlaybackStream());
+        result.append(", deviceType=").append(getDeviceType());
         result.append(", volume=").append(getVolume());
         result.append(", volumeMax=").append(getVolumeMax());
         result.append(", volumeHandling=").append(getVolumeHandling());
@@ -447,7 +459,6 @@
             return this;
         }
 
-
         /**
          * Sets whether the route is enabled.
          * <p>
@@ -547,6 +558,17 @@
         }
 
         /**
+         * Sets the route's receiver device type.
+         *
+         * @hide
+         * STOPSHIP: Unhide or remove.
+         */
+        public Builder setDeviceType(int deviceType) {
+            mBundle.putInt(KEY_DEVICE_TYPE, deviceType);
+            return this;
+        }
+
+        /**
          * Sets the route's current volume, or 0 if unknown.
          */
         public Builder setVolume(int volume) {
diff --git a/v7/mediarouter/src/android/support/v7/media/MediaRouter.java b/v7/mediarouter/src/android/support/v7/media/MediaRouter.java
index 170ee65..2a2a9b3 100644
--- a/v7/mediarouter/src/android/support/v7/media/MediaRouter.java
+++ b/v7/mediarouter/src/android/support/v7/media/MediaRouter.java
@@ -780,6 +780,7 @@
         private final ArrayList<IntentFilter> mControlFilters = new ArrayList<>();
         private int mPlaybackType;
         private int mPlaybackStream;
+        private int mDeviceType;
         private int mVolumeHandling;
         private int mVolume;
         private int mVolumeMax;
@@ -846,6 +847,51 @@
         public static final int PLAYBACK_TYPE_REMOTE = 1;
 
         /** @hide */
+        @IntDef({DEVICE_TYPE_UNKNOWN, DEVICE_TYPE_TV, DEVICE_TYPE_SPEAKER, DEVICE_TYPE_BLUETOOTH})
+        @Retention(RetentionPolicy.SOURCE)
+        private @interface DeviceType {}
+
+        /**
+         * The default receiver device type of the route indicating the type is unknown.
+         *
+         * @see #getDeviceType
+         * @hide
+         * STOPSHIP: Unhide or remove.
+         */
+        public static final int DEVICE_TYPE_UNKNOWN = 0;
+
+
+        /**
+         * A receiver device type of the route indicating the presentation of the media is happening
+         * on a bluetooth device such as a bluetooth speaker.
+         *
+         * @see #getDeviceType
+         * @hide
+         * STOPSHIP: Unhide or remove.
+         */
+        public static final int DEVICE_TYPE_BLUETOOTH = -1;
+
+        /**
+         * A receiver device type of the route indicating the presentation of the media is happening
+         * on a TV.
+         *
+         * @see #getDeviceType
+         * @hide
+         * STOPSHIP: Unhide or remove.
+         */
+        public static final int DEVICE_TYPE_TV = 1;
+
+        /**
+         * A receiver device type of the route indicating the presentation of the media is happening
+         * on a speaker.
+         *
+         * @see #getDeviceType
+         * @hide
+         * STOPSHIP: Unhide or remove.
+         */
+        public static final int DEVICE_TYPE_SPEAKER = 2;
+
+        /** @hide */
         @IntDef({PLAYBACK_VOLUME_FIXED,PLAYBACK_VOLUME_VARIABLE})
         @Retention(RetentionPolicy.SOURCE)
         private @interface PlaybackVolume {}
@@ -1188,6 +1234,18 @@
         }
 
         /**
+         * Gets the type of the receiver device associated with this route.
+         *
+         * @return The type of the receiver device associated with this route:
+         * {@link #DEVICE_TYPE_TV}, {@link #DEVICE_TYPE_SPEAKER} or {@link #DEVICE_TYPE_BLUETOOTH}.
+         * @hide
+         * STOPSHIP: Unhide or remove.
+         */
+        public int getDeviceType() {
+            return mDeviceType;
+        }
+
+        /**
          * Gets information about how volume is handled on the route.
          *
          * @return How volume is handled on the route: {@link #PLAYBACK_VOLUME_FIXED}
@@ -1343,6 +1401,7 @@
                     + ", canDisconnect=" + mCanDisconnect
                     + ", playbackType=" + mPlaybackType
                     + ", playbackStream=" + mPlaybackStream
+                    + ", deviceType=" + mDeviceType
                     + ", volumeHandling=" + mVolumeHandling
                     + ", volume=" + mVolume
                     + ", volumeMax=" + mVolumeMax
@@ -1402,6 +1461,10 @@
                     mPlaybackStream = descriptor.getPlaybackStream();
                     changes |= CHANGE_GENERAL;
                 }
+                if (mDeviceType != descriptor.getDeviceType()) {
+                    mDeviceType = descriptor.getDeviceType();
+                    changes |= CHANGE_GENERAL;
+                }
                 if (mVolumeHandling != descriptor.getVolumeHandling()) {
                     mVolumeHandling = descriptor.getVolumeHandling();
                     changes |= CHANGE_GENERAL | CHANGE_VOLUME;