Show "Device" for remote playback device.

Since we currently don't have access to the name of a remote device,
show a default string "Device" for the device name. In addition,
disable tap on the output switcher.

Fixes: 151486245
Test: manual - cast GPM to home mini and check output switcher in player
for correct icon and string. Additionally, check that tap is disabled.

Change-Id: I31d81f00f0b506b1e2ddc3158043e93cc6db35a8
diff --git a/packages/SystemUI/res/drawable/ic_hardware_speaker.xml b/packages/SystemUI/res/drawable/ic_hardware_speaker.xml
new file mode 100644
index 0000000..0081e56
--- /dev/null
+++ b/packages/SystemUI/res/drawable/ic_hardware_speaker.xml
@@ -0,0 +1,24 @@
+<!--
+    Copyright (C) 2020 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.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="18dp"
+    android:height="18dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+  <path
+      android:pathData="M17,2L7,2c-1.1,0 -2,0.9 -2,2v16c0,1.1 0.9,1.99 2,1.99L17,22c1.1,0 2,-0.9 2,-2L19,4c0,-1.1 -0.9,-2 -2,-2zM7,20L7,4h10v16L7,20zM12,9c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2c-1.11,0 -2,0.9 -2,2s0.89,2 2,2zM12,11c-2.21,0 -4,1.79 -4,4s1.79,4 4,4 4,-1.79 4,-4 -1.79,-4 -4,-4zM12,17c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2z"
+      android:fillColor="#000000"/>
+</vector>
diff --git a/packages/SystemUI/res/layout/qs_media_panel.xml b/packages/SystemUI/res/layout/qs_media_panel.xml
index e5ac5f8..a194569 100644
--- a/packages/SystemUI/res/layout/qs_media_panel.xml
+++ b/packages/SystemUI/res/layout/qs_media_panel.xml
@@ -119,6 +119,7 @@
                 android:id="@+id/media_seamless"
                 android:background="@*android:drawable/media_seamless_background"
                 android:layout_weight="1"
+                android:forceHasOverlappingRendering="false"
             >
                 <ImageView
                     android:layout_width="@dimen/qs_seamless_icon_size"
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index d639ed0..9f0f482 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -1021,6 +1021,9 @@
     <!-- QuickSettings: Text to prompt the user to stop an ongoing recording [CHAR LIMIT=20] -->
     <string name="quick_settings_screen_record_stop">Stop</string>
 
+    <!-- Default name for the media device shown in the output switcher when the name is not available [CHAR LIMIT=30] -->
+    <string name="media_seamless_remote_device">Device</string>
+
     <!-- Recents: Text that shows above the navigation bar after launching a few apps. [CHAR LIMIT=NONE] -->
     <string name="recents_swipe_up_onboarding">Swipe up to switch apps</string>
     <!-- Recents: Text that shows above the navigation bar after launching several apps. [CHAR LIMIT=NONE] -->
diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java b/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java
index ddc9c9d..b12d02d 100644
--- a/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java
+++ b/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java
@@ -36,6 +36,7 @@
 import android.media.MediaMetadata;
 import android.media.ThumbnailUtils;
 import android.media.session.MediaController;
+import android.media.session.MediaController.PlaybackInfo;
 import android.media.session.MediaSession;
 import android.media.session.PlaybackState;
 import android.net.Uri;
@@ -96,6 +97,7 @@
     public static final String MEDIA_PREFERENCE_KEY = "browser_components";
     private SharedPreferences mSharedPrefs;
     private boolean mCheckedForResumption = false;
+    private boolean mIsRemotePlayback;
 
     // Button IDs used in notifications
     protected static final int[] NOTIF_ACTION_IDS = {
@@ -300,6 +302,13 @@
                 Log.d(TAG, "LocalMediaManager is null. Not binding output chip for pkg=" + pkgName);
             }
         }
+        PlaybackInfo playbackInfo = mController.getPlaybackInfo();
+        if (playbackInfo != null) {
+            mIsRemotePlayback = playbackInfo.getPlaybackType() == PlaybackInfo.PLAYBACK_TYPE_REMOTE;
+        } else {
+            Log.d(TAG, "PlaybackInfo was null. Defaulting to local playback.");
+            mIsRemotePlayback = false;
+        }
 
         makeActive();
 
@@ -545,7 +554,16 @@
         TextView deviceName = mSeamless.findViewById(R.id.media_seamless_text);
         deviceName.setTextColor(fgTintList);
 
-        if (device != null) {
+        if (mIsRemotePlayback) {
+            mSeamless.setEnabled(false);
+            mSeamless.setAlpha(0.38f);
+            iconView.setImageResource(R.drawable.ic_hardware_speaker);
+            iconView.setVisibility(View.VISIBLE);
+            iconView.setImageTintList(fgTintList);
+            deviceName.setText(R.string.media_seamless_remote_device);
+        } else if (device != null) {
+            mSeamless.setEnabled(true);
+            mSeamless.setAlpha(1f);
             Drawable icon = device.getIcon();
             iconView.setVisibility(View.VISIBLE);
             iconView.setImageTintList(fgTintList);
@@ -561,6 +579,8 @@
         } else {
             // Reset to default
             Log.d(TAG, "device is null. Not binding output chip.");
+            mSeamless.setEnabled(true);
+            mSeamless.setAlpha(1f);
             iconView.setVisibility(View.GONE);
             deviceName.setText(com.android.internal.R.string.ext_media_seamless_action);
         }