MediaRouter: Check a route's supporting control category

If a media route doesn't support remote playback, it means that the
route is for live audio / video mirroring such as A2DP speaker, headset,
and mirroring display and the media route provider does not provide
playback information such as media metadata and playing status.
See the details : android.support.v7.media.MediaControlIntent

The previous code checked if metadata or playback state is not null
to see a route's playback control availability. It caused an unwanted
bug when having a mirroring route and (non-null) empty metadata or
playback state.

Bug: 24888113
Change-Id: I7bcbbbf0139e1c653705f8054e1a3264c387fba2
diff --git a/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java b/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java
index 526230a..b141ccb 100644
--- a/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java
+++ b/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java
@@ -36,6 +36,7 @@
 import android.support.v4.media.session.PlaybackStateCompat;
 import android.support.v4.view.accessibility.AccessibilityEventCompat;
 import android.support.v7.graphics.Palette;
+import android.support.v7.media.MediaControlIntent;
 import android.support.v7.media.MediaRouteSelector;
 import android.support.v7.media.MediaRouter;
 import android.support.v7.mediarouter.R;
@@ -143,6 +144,7 @@
     private boolean mIsGroupExpanded;
     private boolean mIsGroupListAnimationNeeded;
     private int mGroupListAnimationDurationMs;
+    private boolean mIsPlaybackControlAvailable;
 
     private final AccessibilityManager mAccessibilityManager;
 
@@ -356,6 +358,9 @@
             mCustomControlLayout.addView(mCustomControlView);
             mCustomControlLayout.setVisibility(View.VISIBLE);
         }
+        // Only media routes having CATEGORY_REMOTE_PLAYBACK provide playback information.
+        mIsPlaybackControlAvailable = (mCustomControlView == null
+                && mRoute.supportsControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK));
         mCreated = true;
         updateLayout();
     }
@@ -444,10 +449,6 @@
         updatePlaybackControl();
     }
 
-    private boolean isPlaybackControlAvailable() {
-        return mCustomControlView == null && (mDescription != null || mState != null);
-    }
-
     /**
      * Returns the height of main media controller which includes playback control and master
      * volume control.
@@ -500,7 +501,7 @@
         // Measure the size of widgets and get the height of main components.
         int oldHeight = getLayoutHeight(mMediaMainControlLayout);
         setLayoutHeight(mMediaMainControlLayout, ViewGroup.LayoutParams.FILL_PARENT);
-        updateMediaControlVisibility(isPlaybackControlAvailable());
+        updateMediaControlVisibility(mIsPlaybackControlAvailable);
         View decorView = getWindow().getDecorView();
         decorView.measure(
                 MeasureSpec.makeMeasureSpec(getWindow().getAttributes().width, MeasureSpec.EXACTLY),
@@ -515,7 +516,7 @@
                         ? ImageView.ScaleType.FIT_XY : ImageView.ScaleType.FIT_CENTER);
             }
         }
-        int mainControllerHeight = getMainControllerHeight(isPlaybackControlAvailable());
+        int mainControllerHeight = getMainControllerHeight(mIsPlaybackControlAvailable);
         int volumeGroupListCount = mVolumeGroupList.getAdapter() != null
                 ? mVolumeGroupList.getAdapter().getCount() : 0;
         // Scale down volume group list items in landscape mode.
@@ -555,8 +556,7 @@
             desiredControlLayoutHeight = visibleGroupListHeight + mainControllerHeight;
         }
         // Show the playback control if it fits the screen.
-        if (mCustomControlView == null && isPlaybackControlAvailable()
-                && desiredControlLayoutHeight <= maximumControlViewHeight) {
+        if (mIsPlaybackControlAvailable && desiredControlLayoutHeight <= maximumControlViewHeight) {
             mPlaybackControl.setVisibility(View.VISIBLE);
         } else {
             mPlaybackControl.setVisibility(View.GONE);
@@ -669,7 +669,7 @@
     }
 
     private void updatePlaybackControl() {
-        if (isPlaybackControlAvailable()) {
+        if (mIsPlaybackControlAvailable) {
             CharSequence title = mDescription == null ? null : mDescription.getTitle();
             boolean hasTitle = !TextUtils.isEmpty(title);