Merge "[Output Switcher] Fix SASS device update in U" into udc-dev
diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputAdapter.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputAdapter.java
index d949cf56f..1627662 100644
--- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputAdapter.java
+++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputAdapter.java
@@ -207,10 +207,10 @@
                         updateTitleIcon(R.drawable.media_output_icon_volume,
                                 mController.getColorItemContent());
                     }
-                    initMutingExpectedDevice();
                     mCurrentActivePosition = position;
                     updateFullItemClickListener(v -> onItemClick(v, device));
                     setSingleLineLayout(getItemTitle(device));
+                    initMutingExpectedDevice();
                 } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
                         && mController.isSubStatusSupported()
                         && mController.isAdvancedLayoutSupported() && device.hasSubtext()) {
diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseAdapter.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseAdapter.java
index 151dbb2..6ebda40 100644
--- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseAdapter.java
+++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseAdapter.java
@@ -47,7 +47,6 @@
 import androidx.annotation.VisibleForTesting;
 import androidx.recyclerview.widget.RecyclerView;
 
-import com.android.settingslib.Utils;
 import com.android.settingslib.media.MediaDevice;
 import com.android.settingslib.utils.ThreadUtils;
 import com.android.systemui.R;
@@ -277,9 +276,10 @@
                 backgroundDrawable = mContext.getDrawable(
                         showSeekBar || isFakeActive ? R.drawable.media_output_item_background_active
                                 : R.drawable.media_output_item_background).mutate();
-                backgroundDrawable.setTint(
+                mItemLayout.setBackgroundTintList(ColorStateList.valueOf(
                         showSeekBar || isFakeActive ? mController.getColorConnectedItemBackground()
-                                : mController.getColorItemBackground());
+                                : mController.getColorItemBackground()
+                ));
                 mIconAreaLayout.setBackgroundTintList(
                         ColorStateList.valueOf(showProgressBar || isFakeActive
                                 ? mController.getColorConnectedItemBackground()
@@ -299,7 +299,8 @@
                 backgroundDrawable = mContext.getDrawable(
                                 R.drawable.media_output_item_background)
                         .mutate();
-                backgroundDrawable.setTint(mController.getColorItemBackground());
+                mItemLayout.setBackgroundTintList(
+                        ColorStateList.valueOf(mController.getColorItemBackground()));
             }
             mItemLayout.setBackground(backgroundDrawable);
             mProgressBar.setVisibility(showProgressBar ? View.VISIBLE : View.GONE);
@@ -455,11 +456,16 @@
 
         void initMutingExpectedDevice() {
             disableSeekBar();
+            updateTitleIcon(R.drawable.media_output_icon_volume,
+                    mController.getColorItemContent());
             final Drawable backgroundDrawable = mContext.getDrawable(
                                     R.drawable.media_output_item_background_active)
                             .mutate();
-            backgroundDrawable.setTint(mController.getColorConnectedItemBackground());
             mItemLayout.setBackground(backgroundDrawable);
+            mItemLayout.setBackgroundTintList(
+                    ColorStateList.valueOf(mController.getColorConnectedItemBackground()));
+            mIconAreaLayout.setBackgroundTintList(
+                    ColorStateList.valueOf(mController.getColorConnectedItemBackground()));
         }
 
         private void animateCornerAndVolume(int fromProgress, int toProgress) {
@@ -530,14 +536,6 @@
             });
         }
 
-        Drawable getSpeakerDrawable() {
-            final Drawable drawable = mContext.getDrawable(R.drawable.ic_speaker_group_black_24dp)
-                    .mutate();
-            drawable.setTint(Utils.getColorStateListDefaultColor(mContext,
-                    R.color.media_dialog_item_main_content));
-            return drawable;
-        }
-
         protected void disableSeekBar() {
             mSeekBar.setEnabled(false);
             mSeekBar.setOnTouchListener((v, event) -> true);
@@ -574,7 +572,6 @@
                         return;
                     }
                     mTitleIcon.setImageIcon(icon);
-                    icon.setTint(mController.getColorItemContent());
                     mTitleIcon.setImageTintList(
                             ColorStateList.valueOf(mController.getColorItemContent()));
                 });
diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputAdapterTest.java b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputAdapterTest.java
index faca8a91d..9b26d9c 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputAdapterTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputAdapterTest.java
@@ -347,10 +347,13 @@
     }
 
     @Test
-    public void onBindViewHolder_isMutingExpectedDevice_verifyView() {
+    public void advanced_onBindViewHolder_isMutingExpectedDevice_verifyView() {
+        when(mMediaOutputController.isAdvancedLayoutSupported()).thenReturn(true);
         when(mMediaDevice1.isMutingExpectedDevice()).thenReturn(true);
         when(mMediaOutputController.isCurrentConnectedDeviceRemote()).thenReturn(false);
         when(mMediaOutputController.isActiveRemoteDevice(mMediaDevice1)).thenReturn(false);
+        mViewHolder = (MediaOutputAdapter.MediaDeviceViewHolder) mMediaOutputAdapter
+                .onCreateViewHolder(new LinearLayout(mContext), 0);
         mMediaOutputAdapter.onBindViewHolder(mViewHolder, 0);
 
         assertThat(mViewHolder.mTwoLineLayout.getVisibility()).isEqualTo(View.GONE);