Merge "Accessibility Service & Shortcut Redesign - Remove “volume key shortcut” setting (5/n)" into rvc-dev
diff --git a/res/layout/zen_rule_name.xml b/res/layout/zen_rule_name.xml
index 90b4fbe..afa97ac 100755
--- a/res/layout/zen_rule_name.xml
+++ b/res/layout/zen_rule_name.xml
@@ -21,7 +21,7 @@
     <EditText
         android:id="@+id/zen_mode_rule_name"
         android:layout_width="match_parent"
-        android:layout_height="wrap_content"
+        android:layout_height="48dp"
         android:singleLine="true"
         android:inputType="textCapSentences"
         android:hint="@string/zen_mode_rule_name_hint"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 81c76e4..9b80808 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2031,8 +2031,10 @@
     <string name="wifi_ip_settings">IP settings</string>
     <!-- Label for the spinner to show Wifi MAC randomization [CHAR LIMIT=25] -->
     <string name="wifi_privacy_settings">Privacy</string>
-    <!-- Label for the subscription detail preference. [CHAR LIMIT=32] -->
-    <string name="wifi_subscription_detail">Subscription details</string>
+    <!-- Label for the subscription preference. [CHAR LIMIT=32] -->
+    <string name="wifi_subscription">Subscription</string>
+    <!-- Summary text for the subscription preference. [CHAR LIMIT=NONE] -->
+    <string name="wifi_subscription_summary">View or change subscription</string>
     <!-- Summary for Wifi MAC randomization option when it is ephemeral network [CHAR LIMIT=50] -->
     <string name="wifi_privacy_settings_ephemeral_summary">Randomized MAC</string>
     <!-- Title for the fragment to add a device into the wifi network [CHAR LIMIT=50]  -->
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 85b25e4..dee8176 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -590,6 +590,7 @@
 
     <style name="TextAppearance.Tab" parent="@android:style/TextAppearance.DeviceDefault.Medium">
         <item name="android:textAllCaps">false</item>
+        <item name="android:textSize">14sp</item>
         <item name="android:fontFamily">@*android:string/config_headlineFontFamilyMedium</item>
     </style>
 
diff --git a/res/xml/battery_saver_settings.xml b/res/xml/battery_saver_settings.xml
index 6009f6a..29b82ef 100644
--- a/res/xml/battery_saver_settings.xml
+++ b/res/xml/battery_saver_settings.xml
@@ -45,7 +45,7 @@
 
     <com.android.settingslib.widget.FooterPreference
         android:key="battery_saver_footer_preference"
-        android:selectable="false"
+        android:selectable="true"
         android:title="@*android:string/battery_saver_description"
         settings:allowDividerAbove="true"
         settings:searchable="false"/>
diff --git a/res/xml/wifi_network_details_fragment2.xml b/res/xml/wifi_network_details_fragment2.xml
index 156b744..30a7f67 100644
--- a/res/xml/wifi_network_details_fragment2.xml
+++ b/res/xml/wifi_network_details_fragment2.xml
@@ -69,6 +69,12 @@
         android:entries="@array/wifi_privacy_entries"
         android:entryValues="@array/wifi_privacy_values"/>
 
+    <Preference
+        android:key="subscription_detail"
+        android:title="@string/wifi_subscription"
+        android:summary="@string/wifi_subscription_summary"
+        settings:allowDividerAbove="true"/>
+
     <SwitchPreference
         android:key="auto_connect"
         android:title="@string/wifi_auto_connect_title"
@@ -139,9 +145,4 @@
                 settings:enableCopying="true"/>
     </PreferenceCategory>
 
-    <Preference
-        android:key="subscription_detail"
-        android:title="@string/wifi_subscription_detail"
-        settings:allowDividerAbove="true"/>
-
 </PreferenceScreen>
diff --git a/src/com/android/settings/accessibility/AccessibilityUtil.java b/src/com/android/settings/accessibility/AccessibilityUtil.java
index 8da6fbb..76fb3ff 100644
--- a/src/com/android/settings/accessibility/AccessibilityUtil.java
+++ b/src/com/android/settings/accessibility/AccessibilityUtil.java
@@ -21,9 +21,11 @@
 import android.accessibilityservice.AccessibilityServiceInfo;
 import android.content.ComponentName;
 import android.content.Context;
+import android.content.res.Resources;
 import android.os.Build;
 import android.provider.Settings;
 import android.text.TextUtils;
+import android.util.TypedValue;
 import android.view.accessibility.AccessibilityManager;
 
 import androidx.annotation.IntDef;
@@ -350,4 +352,32 @@
                         "Unsupported userShortcutType " + shortcutType);
         }
     }
+
+    /**
+     * Gets the width of the screen.
+     *
+     * @param context the current context.
+     * @return the width of the screen in terms of pixels.
+     */
+    public static int getScreenWidthPixels(Context context) {
+        final Resources resources = context.getResources();
+        final int screenWidthDp = resources.getConfiguration().screenWidthDp;
+
+        return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, screenWidthDp,
+                resources.getDisplayMetrics()));
+    }
+
+    /**
+     * Gets the height of the screen.
+     *
+     * @param context the current context.
+     * @return the height of the screen in terms of pixels.
+     */
+    public static int getScreenHeightPixels(Context context) {
+        final Resources resources = context.getResources();
+        final int screenHeightDp = resources.getConfiguration().screenHeightDp;
+
+        return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, screenHeightDp,
+                resources.getDisplayMetrics()));
+    }
 }
diff --git a/src/com/android/settings/accessibility/AnimatedImagePreference.java b/src/com/android/settings/accessibility/AnimatedImagePreference.java
index 1609a3c..61e439f 100644
--- a/src/com/android/settings/accessibility/AnimatedImagePreference.java
+++ b/src/com/android/settings/accessibility/AnimatedImagePreference.java
@@ -34,6 +34,7 @@
 public class AnimatedImagePreference extends Preference {
 
     private Uri mImageUri;
+    private int mMaxHeight = -1;
 
     AnimatedImagePreference(Context context) {
         super(context);
@@ -45,20 +46,26 @@
         super.onBindViewHolder(holder);
 
         final ImageView imageView = holder.itemView.findViewById(R.id.animated_img);
-        if (imageView != null && mImageUri != null) {
+        if (imageView == null) {
+            return;
+        }
+
+        if (mImageUri != null) {
             imageView.setImageURI(mImageUri);
 
             final Drawable drawable = imageView.getDrawable();
-            if (drawable != null) {
-                if (drawable instanceof AnimatedImageDrawable) {
-                    ((AnimatedImageDrawable) drawable).start();
-                }
+            if (drawable instanceof AnimatedImageDrawable) {
+                ((AnimatedImageDrawable) drawable).start();
             }
         }
+
+        if (mMaxHeight > -1) {
+            imageView.setMaxWidth(mMaxHeight);
+        }
     }
 
     /**
-     * Set image uri to display image in {@link ImageView}
+     * Sets image uri to display image in {@link ImageView}
      *
      * @param imageUri the Uri of an image
      */
@@ -68,4 +75,16 @@
             notifyChanged();
         }
     }
+
+    /**
+     * Sets the maximum height of the view.
+     *
+     * @param maxHeight the maximum height of ImageView in terms of pixels.
+     */
+    public void setMaxHeight(int maxHeight) {
+        if (maxHeight != mMaxHeight) {
+            mMaxHeight = maxHeight;
+            notifyChanged();
+        }
+    }
 }
diff --git a/src/com/android/settings/accessibility/HtmlTextPreference.java b/src/com/android/settings/accessibility/HtmlTextPreference.java
index fcf4725..4c528a3 100644
--- a/src/com/android/settings/accessibility/HtmlTextPreference.java
+++ b/src/com/android/settings/accessibility/HtmlTextPreference.java
@@ -23,9 +23,6 @@
 
 import androidx.preference.PreferenceViewHolder;
 
-import java.util.List;
-import java.util.regex.Pattern;
-
 /**
  * A custom {@link android.widget.TextView} preference that shows html text with a custom tag
  * filter.
@@ -35,7 +32,6 @@
     private int mFlag = Html.FROM_HTML_MODE_COMPACT;
     private Html.ImageGetter mImageGetter;
     private Html.TagHandler mTagHandler;
-    private List<String> mUnsupportedTagList;
 
     HtmlTextPreference(Context context) {
         super(context);
@@ -47,8 +43,8 @@
 
         final TextView summaryView = holder.itemView.findViewById(android.R.id.summary);
         if (summaryView != null && !TextUtils.isEmpty(getSummary())) {
-            final String filteredText = getFilteredText(getSummary().toString());
-            summaryView.setText(Html.fromHtml(filteredText, mFlag, mImageGetter, mTagHandler));
+            summaryView.setText(
+                    Html.fromHtml(getSummary().toString(), mFlag, mImageGetter, mTagHandler));
         }
     }
 
@@ -87,39 +83,4 @@
             notifyChanged();
         }
     }
-
-    /**
-     * Sets unsupported tag list, the text will be filtered though this list in advanced.
-     *
-     * @param unsupportedTagList the list of unsupported tags
-     */
-    public void setUnsupportedTagList(List<String> unsupportedTagList) {
-        if (unsupportedTagList != null && !unsupportedTagList.equals(mUnsupportedTagList)) {
-            mUnsupportedTagList = unsupportedTagList;
-            notifyChanged();
-        }
-    }
-
-    private String getFilteredText(String text) {
-        if (mUnsupportedTagList == null) {
-            return text;
-        }
-
-        int i = 1;
-        for (String tag : mUnsupportedTagList) {
-            if (!TextUtils.isEmpty(text)) {
-                final String index = String.valueOf(i++);
-                final String targetStart1 = "(?i)<" + tag + " ";
-                final String targetStart2 = "(?i)<" + tag + ">";
-                final String replacementStart1 = "<unsupportedtag" + index + " ";
-                final String replacementStart2 = "<unsupportedtag" + index + ">";
-                final String targetEnd = "(?i)</" + tag + ">";
-                final String replacementEnd = "</unsupportedtag" + index + ">";
-                text = Pattern.compile(targetStart1).matcher(text).replaceAll(replacementStart1);
-                text = Pattern.compile(targetStart2).matcher(text).replaceAll(replacementStart2);
-                text = Pattern.compile(targetEnd).matcher(text).replaceAll(replacementEnd);
-            }
-        }
-        return text;
-    }
 }
diff --git a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
index 19a0f2b..838a758 100644
--- a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
@@ -16,6 +16,9 @@
 
 package com.android.settings.accessibility;
 
+import static com.android.settings.accessibility.AccessibilityUtil.getScreenHeightPixels;
+import static com.android.settings.accessibility.AccessibilityUtil.getScreenWidthPixels;
+
 import android.app.Dialog;
 import android.app.settings.SettingsEnums;
 import android.content.ComponentName;
@@ -80,7 +83,6 @@
     protected CharSequence mPackageName;
     protected Uri mImageUri;
     protected CharSequence mHtmlDescription;
-    private static final String ANCHOR_TAG = "a";
     private static final String DRAWABLE_FOLDER = "drawable";
     protected static final String KEY_USE_SERVICE_PREFERENCE = "use_service";
     protected static final String KEY_GENERAL_CATEGORY = "general_categories";
@@ -94,9 +96,8 @@
     private CheckBox mSoftwareTypeCheckBox;
     private CheckBox mHardwareTypeCheckBox;
 
-    // For html description of accessibility service, third party developer must follow the rule,
-    // such as <img src="R.drawable.fileName"/>, a11y settings will get third party resources
-    // by this.
+    // For html description of accessibility service, must follow the rule, such as
+    // <img src="R.drawable.fileName"/>, a11y settings will get the resources successfully.
     private static final String IMG_PREFIX = "R.drawable.";
 
     private ImageView mImageGetterCacheView;
@@ -147,10 +148,12 @@
 
         PreferenceScreen preferenceScreen = getPreferenceScreen();
         if (mImageUri != null) {
+            final int screenHalfHeight = getScreenHeightPixels(getPrefContext()) / /* half */ 2;
             final AnimatedImagePreference animatedImagePreference = new AnimatedImagePreference(
                     getPrefContext());
             animatedImagePreference.setImageUri(mImageUri);
             animatedImagePreference.setSelectable(false);
+            animatedImagePreference.setMaxHeight(screenHalfHeight);
             preferenceScreen.addPreference(animatedImagePreference);
         }
 
@@ -195,14 +198,9 @@
             introductionCategory.setTitle(title);
             preferenceScreen.addPreference(introductionCategory);
 
-            // For accessibility service, avoid malicious links made by third party developer.
-            final List<String> unsupportedTagList = new ArrayList<>();
-            unsupportedTagList.add(ANCHOR_TAG);
-
             final HtmlTextPreference htmlTextPreference = new HtmlTextPreference(getPrefContext());
             htmlTextPreference.setSummary(mHtmlDescription);
             htmlTextPreference.setImageGetter(mImageGetter);
-            htmlTextPreference.setUnsupportedTagList(unsupportedTagList);
             htmlTextPreference.setSelectable(false);
             introductionCategory.addPreference(htmlTextPreference);
         }
@@ -383,14 +381,24 @@
         mImageGetterCacheView.setAdjustViewBounds(true);
         mImageGetterCacheView.setImageURI(imageUri);
 
-        final Drawable drawable = mImageGetterCacheView.getDrawable().mutate();
-        if (drawable != null) {
-            drawable.setBounds(/* left= */0, /* top= */0, drawable.getIntrinsicWidth(),
-                    drawable.getIntrinsicHeight());
+        if (mImageGetterCacheView.getDrawable() == null) {
+            return null;
         }
 
+        final Drawable drawable =
+                mImageGetterCacheView.getDrawable().mutate().getConstantState().newDrawable();
         mImageGetterCacheView.setImageURI(null);
-        mImageGetterCacheView.setImageDrawable(null);
+        final int imageWidth = drawable.getIntrinsicWidth();
+        final int imageHeight = drawable.getIntrinsicHeight();
+        final int screenHalfHeight = getScreenHeightPixels(getPrefContext()) / /* half */ 2;
+        if ((imageWidth > getScreenWidthPixels(getPrefContext()))
+                || (imageHeight > screenHalfHeight)) {
+            return null;
+        }
+
+        drawable.setBounds(/* left= */0, /* top= */0, drawable.getIntrinsicWidth(),
+                drawable.getIntrinsicHeight());
+
         return drawable;
     }
 
diff --git a/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogController.java b/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogController.java
index 2ee77d9..2048be0 100644
--- a/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogController.java
+++ b/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogController.java
@@ -118,7 +118,8 @@
 
         mDialog.setText(ID_PRL_VERSION_VALUE, getCdmaPrlVersion());
 
-        if (mSubscriptionInfo != null && isCdmaLteEnabled()) {
+        if ((mSubscriptionInfo != null && isCdmaLteEnabled()) ||
+                    (mSubscriptionInfo == null && isSimPresent(mSlotId))) {
             // Show IMEI for LTE device
             mDialog.setText(ID_IMEI_VALUE,
                     getTextAsDigits(mTelephonyManager.getImei(mSlotId)));
@@ -149,6 +150,15 @@
         return mTelephonyManager.isGlobalModeEnabled();
     }
 
+    boolean isSimPresent(int slotId) {
+        final int simState = mTelephonyManager.getSimState(slotId);
+        if ((simState != TelephonyManager.SIM_STATE_ABSENT) &&
+                (simState != TelephonyManager.SIM_STATE_UNKNOWN)) {
+            return true;
+        }
+        return false;
+    }
+
     @VisibleForTesting
     String getMeid() {
         return mTelephonyManager.getMeid(mSlotId);
diff --git a/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java b/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java
index d7e07d9..30ba084 100644
--- a/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java
+++ b/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java
@@ -152,7 +152,11 @@
     private final BroadcastReceiver mAreaInfoReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
-            updateAreaInfoText();
+            if (CellBroadcastIntents.ACTION_AREA_INFO_UPDATED.equals(intent.getAction())
+                    && intent.getIntExtra(SubscriptionManager.EXTRA_SLOT_INDEX, 0)
+                    == mSlotIndex) {
+                updateAreaInfoText();
+            }
         }
     };
 
@@ -337,8 +341,7 @@
         if (cellBroadcastService == null) return;
         try {
             mDialog.setText(OPERATOR_INFO_VALUE_ID,
-                    cellBroadcastService.getCellBroadcastAreaInfo(
-                            SimStatusDialogController.this.mSlotIndex));
+                    cellBroadcastService.getCellBroadcastAreaInfo(mSlotIndex));
 
         } catch (RemoteException e) {
             Log.d(TAG, "Can't get area info. e=" + e);
diff --git a/src/com/android/settings/display/AdaptiveSleepPreferenceController.java b/src/com/android/settings/display/AdaptiveSleepPreferenceController.java
index 8faae30..9f5b49e 100644
--- a/src/com/android/settings/display/AdaptiveSleepPreferenceController.java
+++ b/src/com/android/settings/display/AdaptiveSleepPreferenceController.java
@@ -39,13 +39,13 @@
 
     @Override
     public boolean isChecked() {
-        return hasSufficientPermission(mContext.getPackageManager()) && Settings.System.getInt(
+        return hasSufficientPermission(mContext.getPackageManager()) && Settings.Secure.getInt(
                 mContext.getContentResolver(), SYSTEM_KEY, DEFAULT_VALUE) != DEFAULT_VALUE;
     }
 
     @Override
     public boolean setChecked(boolean isChecked) {
-        Settings.System.putInt(mContext.getContentResolver(), SYSTEM_KEY,
+        Settings.Secure.putInt(mContext.getContentResolver(), SYSTEM_KEY,
                 isChecked ? 1 : DEFAULT_VALUE);
         return true;
     }
diff --git a/src/com/android/settings/media/MediaOutputIndicatorSlice.java b/src/com/android/settings/media/MediaOutputIndicatorSlice.java
index 17d7cee..de2f85f 100644
--- a/src/com/android/settings/media/MediaOutputIndicatorSlice.java
+++ b/src/com/android/settings/media/MediaOutputIndicatorSlice.java
@@ -24,6 +24,7 @@
 import android.content.Context;
 import android.content.Intent;
 import android.graphics.Bitmap;
+import android.media.session.MediaController;
 import android.net.Uri;
 import android.util.Log;
 
@@ -36,6 +37,8 @@
 import com.android.settings.R;
 import com.android.settings.Utils;
 import com.android.settings.slices.CustomSliceable;
+import com.android.settings.slices.SliceBackgroundWorker;
+import com.android.settings.slices.SliceBroadcastReceiver;
 import com.android.settingslib.bluetooth.A2dpProfile;
 import com.android.settingslib.bluetooth.HearingAidProfile;
 import com.android.settingslib.bluetooth.LocalBluetoothManager;
@@ -52,6 +55,7 @@
     private Context mContext;
     private LocalBluetoothManager mLocalBluetoothManager;
     private LocalBluetoothProfileManager mProfileManager;
+    private MediaOutputIndicatorWorker mWorker;
 
     public MediaOutputIndicatorSlice(Context context) {
         mContext = context;
@@ -66,22 +70,18 @@
     @Override
     public Slice getSlice() {
         if (!isVisible()) {
-            return new ListBuilder(mContext, MEDIA_OUTPUT_INDICATOR_SLICE_URI, ListBuilder.INFINITY)
+            return new ListBuilder(mContext, getUri(), ListBuilder.INFINITY)
                     .setIsError(true)
                     .build();
         }
         final IconCompat icon = IconCompat.createWithResource(mContext,
                 com.android.internal.R.drawable.ic_settings_bluetooth);
         final CharSequence title = mContext.getText(R.string.media_output_title);
-        final PendingIntent primaryActionIntent = PendingIntent.getActivity(mContext,
-                0 /* requestCode */, getMediaOutputSliceIntent(), 0 /* flags */);
         final SliceAction primarySliceAction = SliceAction.createDeeplink(
-                primaryActionIntent, icon, ListBuilder.ICON_IMAGE, title);
+                getBroadcastIntent(), icon, ListBuilder.ICON_IMAGE, title);
         @ColorInt final int color = Utils.getColorAccentDefaultColor(mContext);
         // To set an empty icon to indent the row
-        final ListBuilder listBuilder = new ListBuilder(mContext,
-                MEDIA_OUTPUT_INDICATOR_SLICE_URI,
-                ListBuilder.INFINITY)
+        final ListBuilder listBuilder = new ListBuilder(mContext, getUri(), ListBuilder.INFINITY)
                 .setAccentColor(color)
                 .addRow(new ListBuilder.RowBuilder()
                         .setTitle(title)
@@ -96,11 +96,11 @@
         return IconCompat.createWithBitmap(bitmap);
     }
 
-    private Intent getMediaOutputSliceIntent() {
-        final Intent intent = new Intent()
-                .setAction(MediaOutputSliceConstants.ACTION_MEDIA_OUTPUT)
-                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        return intent;
+    private PendingIntent getBroadcastIntent() {
+        final Intent intent = new Intent(getUri().toString());
+        intent.setClass(mContext, SliceBroadcastReceiver.class);
+        return PendingIntent.getBroadcast(mContext, 0, intent,
+                PendingIntent.FLAG_UPDATE_CURRENT);
     }
 
     @Override
@@ -120,6 +120,28 @@
         return MediaOutputIndicatorWorker.class;
     }
 
+    @Override
+    public void onNotifyChange(Intent i) {
+        final MediaController mediaController = getWorker().getActiveLocalMediaController();
+        final Intent intent = new Intent()
+                .setAction(MediaOutputSliceConstants.ACTION_MEDIA_OUTPUT)
+                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        if (mediaController != null) {
+            intent.putExtra(MediaOutputSliceConstants.KEY_MEDIA_SESSION_TOKEN,
+                    mediaController.getSessionToken());
+            intent.putExtra(MediaOutputSliceConstants.EXTRA_PACKAGE_NAME,
+                    mediaController.getPackageName());
+        }
+        mContext.startActivity(intent);
+    }
+
+    private MediaOutputIndicatorWorker getWorker() {
+        if (mWorker == null) {
+            mWorker = SliceBackgroundWorker.getInstance(getUri());
+        }
+        return mWorker;
+    }
+
     private boolean isVisible() {
         // To decide Slice's visibility.
         // Return true if
diff --git a/src/com/android/settings/media/MediaOutputIndicatorWorker.java b/src/com/android/settings/media/MediaOutputIndicatorWorker.java
index 6498dd6..4ceeade 100644
--- a/src/com/android/settings/media/MediaOutputIndicatorWorker.java
+++ b/src/com/android/settings/media/MediaOutputIndicatorWorker.java
@@ -24,18 +24,21 @@
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.media.AudioManager;
+import android.media.session.MediaController;
+import android.media.session.MediaSessionManager;
+import android.media.session.PlaybackState;
 import android.net.Uri;
 import android.text.TextUtils;
 import android.util.Log;
 
+import androidx.annotation.Nullable;
+
 import com.android.settings.bluetooth.Utils;
 import com.android.settings.slices.SliceBackgroundWorker;
 import com.android.settingslib.bluetooth.BluetoothCallback;
 import com.android.settingslib.bluetooth.CachedBluetoothDevice;
 import com.android.settingslib.bluetooth.LocalBluetoothManager;
 
-import java.io.IOException;
-
 /**
  * Listener for background change from {@code BluetoothCallback} to update media output indicator.
  */
@@ -100,6 +103,27 @@
         notifySliceChange();
     }
 
+    @Nullable
+    MediaController getActiveLocalMediaController() {
+        final MediaSessionManager mMediaSessionManager = mContext.getSystemService(
+                MediaSessionManager.class);
+
+        for (MediaController controller : mMediaSessionManager.getActiveSessions(null)) {
+            final MediaController.PlaybackInfo pi = controller.getPlaybackInfo();
+            if (pi == null) {
+                return null;
+            }
+            final PlaybackState playbackState = controller.getPlaybackState();
+            if (playbackState == null) {
+                return null;
+            }
+            if (pi.getPlaybackType() == MediaController.PlaybackInfo.PLAYBACK_TYPE_LOCAL
+                    && playbackState.getState() == PlaybackState.STATE_PLAYING) {
+                return controller;
+            }
+        }
+        return null;
+    }
     private class DevicesChangedBroadcastReceiver extends BroadcastReceiver {
         @Override
         public void onReceive(Context context, Intent intent) {
diff --git a/src/com/android/settings/notification/app/ConversationPromotePreferenceController.java b/src/com/android/settings/notification/app/ConversationPromotePreferenceController.java
index 5ef9246..766e4aa 100644
--- a/src/com/android/settings/notification/app/ConversationPromotePreferenceController.java
+++ b/src/com/android/settings/notification/app/ConversationPromotePreferenceController.java
@@ -62,7 +62,7 @@
 
     @Override
     public boolean handlePreferenceTreeClick(Preference preference) {
-        if (mChannel == null) {
+        if (mChannel == null || !KEY.equals(preference.getKey())) {
             return false;
         }
         mChannel.setDemoted(false);
diff --git a/src/com/android/settings/notification/history/NotificationHistoryActivity.java b/src/com/android/settings/notification/history/NotificationHistoryActivity.java
index 9f8a07f..fbbda21 100644
--- a/src/com/android/settings/notification/history/NotificationHistoryActivity.java
+++ b/src/com/android/settings/notification/history/NotificationHistoryActivity.java
@@ -236,39 +236,44 @@
             };
 
     private final NotificationListenerService mListener = new NotificationListenerService() {
+        private RecyclerView mDismissedRv;
+        private RecyclerView mSnoozedRv;
 
         @Override
         public void onListenerConnected() {
             StatusBarNotification[] snoozed = getSnoozedNotifications();
+            mSnoozedRv = mSnoozeView.findViewById(R.id.notification_list);
+            LinearLayoutManager lm = new LinearLayoutManager(NotificationHistoryActivity.this);
+            mSnoozedRv.setLayoutManager(lm);
+            mSnoozedRv.setAdapter(
+                    new NotificationSbnAdapter(NotificationHistoryActivity.this, mPm));
+            DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(
+                    mSnoozedRv.getContext(), lm.getOrientation());
+            mSnoozedRv.addItemDecoration(dividerItemDecoration);
+            mSnoozedRv.setNestedScrollingEnabled(false);
+
             if (snoozed == null || snoozed.length == 0) {
                 mSnoozeView.setVisibility(View.GONE);
             } else {
-                RecyclerView rv = mSnoozeView.findViewById(R.id.notification_list);
-                LinearLayoutManager lm = new LinearLayoutManager(NotificationHistoryActivity.this);
-                rv.setLayoutManager(lm);
-                rv.setAdapter(new NotificationSbnAdapter(NotificationHistoryActivity.this, mPm));
-                DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(
-                        rv.getContext(), lm.getOrientation());
-                rv.addItemDecoration(dividerItemDecoration);
-                rv.setNestedScrollingEnabled(false);
-
-                ((NotificationSbnAdapter) rv.getAdapter()).onRebuildComplete(
+                ((NotificationSbnAdapter) mSnoozedRv.getAdapter()).onRebuildComplete(
                         new ArrayList<>(Arrays.asList(snoozed)));
             }
 
             try {
                 StatusBarNotification[] dismissed = mNm.getHistoricalNotifications(
                         NotificationHistoryActivity.this.getPackageName(), 6, false);
-                RecyclerView rv = mDismissView.findViewById(R.id.notification_list);
-                LinearLayoutManager lm = new LinearLayoutManager(NotificationHistoryActivity.this);
-                rv.setLayoutManager(lm);
-                rv.setAdapter(new NotificationSbnAdapter(NotificationHistoryActivity.this, mPm));
-                DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(
-                        rv.getContext(), lm.getOrientation());
-                rv.addItemDecoration(dividerItemDecoration);
-                rv.setNestedScrollingEnabled(false);
+                mDismissedRv = mDismissView.findViewById(R.id.notification_list);
+                LinearLayoutManager dismissLm =
+                        new LinearLayoutManager(NotificationHistoryActivity.this);
+                mDismissedRv.setLayoutManager(dismissLm);
+                mDismissedRv.setAdapter(
+                        new NotificationSbnAdapter(NotificationHistoryActivity.this, mPm));
+                DividerItemDecoration dismissDivider = new DividerItemDecoration(
+                        mDismissedRv.getContext(), dismissLm.getOrientation());
+                mDismissedRv.addItemDecoration(dismissDivider);
+                mDismissedRv.setNestedScrollingEnabled(false);
 
-                ((NotificationSbnAdapter) rv.getAdapter()).onRebuildComplete(
+                ((NotificationSbnAdapter) mDismissedRv.getAdapter()).onRebuildComplete(
                         new ArrayList<>(Arrays.asList(dismissed)));
                 mDismissView.setVisibility(View.VISIBLE);
             } catch (Exception e) {
@@ -276,5 +281,22 @@
                 mDismissView.setVisibility(View.GONE);
             }
         }
+
+        @Override
+        public void onNotificationPosted(StatusBarNotification sbn) {
+            // making lint happy
+        }
+
+        @Override
+        public void onNotificationRemoved(StatusBarNotification sbn, RankingMap rankingMap,
+                int reason) {
+            if (reason == REASON_SNOOZED) {
+                ((NotificationSbnAdapter) mSnoozedRv.getAdapter()).addSbn(sbn);
+                mSnoozeView.setVisibility(View.VISIBLE);
+            } else {
+                ((NotificationSbnAdapter) mDismissedRv.getAdapter()).addSbn(sbn);
+                mDismissView.setVisibility(View.VISIBLE);
+            }
+        }
     };
 }
diff --git a/src/com/android/settings/notification/history/NotificationSbnAdapter.java b/src/com/android/settings/notification/history/NotificationSbnAdapter.java
index f1dcf47..f7a747b 100644
--- a/src/com/android/settings/notification/history/NotificationSbnAdapter.java
+++ b/src/com/android/settings/notification/history/NotificationSbnAdapter.java
@@ -108,6 +108,14 @@
         notifyDataSetChanged();
     }
 
+    public void addSbn(StatusBarNotification sbn) {
+        if (sbn.isGroup() && sbn.getNotification().isGroupSummary()) {
+            return;
+        }
+        mValues.add(0, sbn);
+        notifyDataSetChanged();
+    }
+
     private @NonNull CharSequence loadPackageName(String pkg) {
         try {
             ApplicationInfo info = mPm.getApplicationInfo(pkg,
diff --git a/src/com/android/settings/panel/MediaOutputPanel.java b/src/com/android/settings/panel/MediaOutputPanel.java
index 7b69fe3..6735375 100644
--- a/src/com/android/settings/panel/MediaOutputPanel.java
+++ b/src/com/android/settings/panel/MediaOutputPanel.java
@@ -186,6 +186,7 @@
 
     @Override
     public void onClickCustomizedButton() {
+        mLocalMediaManager.releaseSession();
     }
 
     @Override
diff --git a/src/com/android/settings/wifi/addappnetworks/AddAppNetworksFragment.java b/src/com/android/settings/wifi/addappnetworks/AddAppNetworksFragment.java
index 05c7b4e..7a5677f 100644
--- a/src/com/android/settings/wifi/addappnetworks/AddAppNetworksFragment.java
+++ b/src/com/android/settings/wifi/addappnetworks/AddAppNetworksFragment.java
@@ -349,7 +349,7 @@
              * If specified is passpoint network, need to check with the existing passpoint
              * networks.
              */
-            final PasspointConfiguration passpointConfig = suggestion.getPasspointConfiguration();
+            final PasspointConfiguration passpointConfig = suggestion.getPasspointConfig();
             if (passpointConfig != null) {
                 foundInSavedList = isSavedPasspointConfiguration(passpointConfig);
                 displayedName = passpointConfig.getHomeSp().getFriendlyName();
@@ -600,7 +600,7 @@
      */
     private void saveNetwork(int index) {
         final PasspointConfiguration passpointConfig =
-                mUiToRequestedList.get(index).mWifiNetworkSuggestion.getPasspointConfiguration();
+                mUiToRequestedList.get(index).mWifiNetworkSuggestion.getPasspointConfig();
         if (passpointConfig != null) {
             // Save passpoint, if no IllegalArgumentException, then treat it as success.
             try {
diff --git a/src/com/android/settings/wifi/details2/AddDevicePreferenceController2.java b/src/com/android/settings/wifi/details2/AddDevicePreferenceController2.java
index f1c24c3..fc7b5ce 100644
--- a/src/com/android/settings/wifi/details2/AddDevicePreferenceController2.java
+++ b/src/com/android/settings/wifi/details2/AddDevicePreferenceController2.java
@@ -51,11 +51,8 @@
 
     @Override
     public int getAvailabilityStatus() {
-        if (!WifiDppUtils.isSupportConfiguratorQrCodeScanner(mContext, mWifiEntry)
-                || mWifiEntry.canManageSubscription()) {
-            return CONDITIONALLY_UNAVAILABLE;
-        }
-        return AVAILABLE;
+        return WifiDppUtils.isSupportConfiguratorQrCodeScanner(mContext, mWifiEntry) ? AVAILABLE
+                : CONDITIONALLY_UNAVAILABLE;
     }
 
     @Override
diff --git a/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java b/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java
index c12f8d3..803b828 100644
--- a/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java
+++ b/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java
@@ -145,7 +145,6 @@
     static final String KEY_IPV6_CATEGORY = "ipv6_category";
     @VisibleForTesting
     static final String KEY_IPV6_ADDRESSES_PREF = "ipv6_addresses";
-    static final String KEY_IP_DETAILS_CATEGORY = "ip_details_category";
 
     private final WifiEntry mWifiEntry;
     private final ConnectivityManager mConnectivityManager;
@@ -165,7 +164,6 @@
     private ActionButtonsPreference mButtonsPref;
     private EntityHeaderController mEntityHeaderController;
     private Preference mSignalStrengthPref;
-    private PreferenceCategory mIpDetailsCategory;
     private Preference mTxLinkSpeedPref;
     private Preference mRxLinkSpeedPref;
     private Preference mFrequencyPref;
@@ -196,9 +194,7 @@
                 mLinkProperties = lp;
                 refreshEntityHeader();
                 refreshButtons();
-                if (!mWifiEntry.canManageSubscription()) {
-                    refreshIpLayerInfo();
-                }
+                refreshIpLayerInfo();
             }
         }
 
@@ -238,9 +234,7 @@
                 }
                 mNetworkCapabilities = nc;
                 refreshButtons();
-                if (!mWifiEntry.canManageSubscription()) {
-                    refreshIpLayerInfo();
-                }
+                refreshIpLayerInfo();
             }
         }
 
@@ -335,7 +329,6 @@
         updateCaptivePortalButton();
 
         mSignalStrengthPref = screen.findPreference(KEY_SIGNAL_STRENGTH_PREF);
-        mIpDetailsCategory = screen.findPreference(KEY_IP_DETAILS_CATEGORY);
         mTxLinkSpeedPref = screen.findPreference(KEY_TX_LINK_SPEED);
         mRxLinkSpeedPref = screen.findPreference(KEY_RX_LINK_SPEED);
         mFrequencyPref = screen.findPreference(KEY_FREQUENCY_PREF);
@@ -351,13 +344,6 @@
         mIpv6Category = screen.findPreference(KEY_IPV6_CATEGORY);
         mIpv6AddressPref = screen.findPreference(KEY_IPV6_ADDRESSES_PREF);
 
-        if (mWifiEntry.canManageSubscription()) {
-            mIpDetailsCategory.setVisible(false);
-            mIpv6Category.setVisible(false);
-            mSignalStrengthPref.setVisible(false);
-            mFrequencyPref.setVisible(false);
-            mSecurityPref.setVisible(false);
-        }
         mSecurityPref.setSummary(mWifiEntry.getSecurityString(false /* concise */));
     }
 
@@ -505,16 +491,10 @@
 
         // refresh header
         refreshEntityHeader();
-        refreshEntityHeaderIcon();
+
         // refresh Buttons
         refreshButtons();
 
-        // When support manage subscription, there won't have any detail information, so don't
-        // need to update those detail UIs.
-        if (mWifiEntry.canManageSubscription()) {
-            return;
-        }
-
         // Update Connection Header icon and Signal Strength Preference
         refreshRssiViews();
         // Frequency Pref
@@ -531,11 +511,7 @@
         refreshMacAddress();
     }
 
-    private void refreshEntityHeaderIcon() {
-        if (mEntityHeaderController == null) {
-            return;
-        }
-
+    private void refreshRssiViews() {
         int signalLevel = mWifiEntry.getLevel();
 
         // Disappears signal view if not in range. e.g. for saved networks.
@@ -550,23 +526,13 @@
         }
         mRssiSignalLevel = signalLevel;
         Drawable wifiIcon = mIconInjector.getIcon(mRssiSignalLevel);
-        mEntityHeaderController
-                .setIcon(redrawIconForHeader(wifiIcon)).done(mFragment.getActivity(),
-                    true /* rebind */);
-    }
 
-    private void refreshRssiViews() {
-        int signalLevel = mWifiEntry.getLevel();
-
-        // Disappears signal view if not in range. e.g. for saved networks.
-        if (signalLevel == WifiEntry.WIFI_LEVEL_UNREACHABLE) {
-            mSignalStrengthPref.setVisible(false);
-            mRssiSignalLevel = -1;
-            return;
+        if (mEntityHeaderController != null) {
+            mEntityHeaderController
+                    .setIcon(redrawIconForHeader(wifiIcon)).done(mFragment.getActivity(),
+                            true /* rebind */);
         }
 
-        mRssiSignalLevel = signalLevel;
-        Drawable wifiIcon = mIconInjector.getIcon(mRssiSignalLevel);
         Drawable wifiIconDark = wifiIcon.getConstantState().newDrawable().mutate();
         wifiIconDark.setTintList(Utils.getColorAttr(mContext, android.R.attr.colorControlNormal));
         mSignalStrengthPref.setIcon(wifiIconDark);
diff --git a/src/com/android/settings/wifi/details2/WifiMeteredPreferenceController2.java b/src/com/android/settings/wifi/details2/WifiMeteredPreferenceController2.java
index df205a3..b4909e2 100644
--- a/src/com/android/settings/wifi/details2/WifiMeteredPreferenceController2.java
+++ b/src/com/android/settings/wifi/details2/WifiMeteredPreferenceController2.java
@@ -55,7 +55,7 @@
 
     @Override
     public int getAvailabilityStatus() {
-        return mWifiEntry.canManageSubscription() ? CONDITIONALLY_UNAVAILABLE : AVAILABLE;
+        return AVAILABLE;
     }
 
     @Override
diff --git a/src/com/android/settings/wifi/details2/WifiNetworkDetailsFragment2.java b/src/com/android/settings/wifi/details2/WifiNetworkDetailsFragment2.java
index a11cadf..07bd5a4 100644
--- a/src/com/android/settings/wifi/details2/WifiNetworkDetailsFragment2.java
+++ b/src/com/android/settings/wifi/details2/WifiNetworkDetailsFragment2.java
@@ -115,10 +115,6 @@
 
     @Override
     public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
-        if (mNetworkDetailsTracker.getWifiEntry().canManageSubscription()) {
-            return;
-        }
-
         MenuItem item = menu.add(0, Menu.FIRST, 0, R.string.wifi_modify);
         item.setIcon(com.android.internal.R.drawable.ic_mode_edit);
         item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
diff --git a/src/com/android/settings/wifi/details2/WifiPrivacyPreferenceController2.java b/src/com/android/settings/wifi/details2/WifiPrivacyPreferenceController2.java
index 479848c..b87b05d 100644
--- a/src/com/android/settings/wifi/details2/WifiPrivacyPreferenceController2.java
+++ b/src/com/android/settings/wifi/details2/WifiPrivacyPreferenceController2.java
@@ -55,11 +55,8 @@
 
     @Override
     public int getAvailabilityStatus() {
-        if (!mWifiManager.isConnectedMacRandomizationSupported()
-                || mWifiEntry.canManageSubscription()) {
-            return CONDITIONALLY_UNAVAILABLE;
-        }
-        return AVAILABLE;
+        return mWifiManager.isConnectedMacRandomizationSupported()
+                ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
     }
 
     @Override
diff --git a/src/com/android/settings/wifi/details2/WifiSubscriptionDetailPreferenceController2.java b/src/com/android/settings/wifi/details2/WifiSubscriptionDetailPreferenceController2.java
index 7c93327..2598fb3 100644
--- a/src/com/android/settings/wifi/details2/WifiSubscriptionDetailPreferenceController2.java
+++ b/src/com/android/settings/wifi/details2/WifiSubscriptionDetailPreferenceController2.java
@@ -41,11 +41,7 @@
 
     @Override
     public int getAvailabilityStatus() {
-        if (mWifiEntry.canManageSubscription()) {
-            return AVAILABLE;
-        }
-
-        return CONDITIONALLY_UNAVAILABLE;
+        return mWifiEntry.canManageSubscription() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
     }
 
     @Override
diff --git a/tests/robotests/src/com/android/settings/accessibility/HtmlTextPreferenceTest.java b/tests/robotests/src/com/android/settings/accessibility/HtmlTextPreferenceTest.java
index 5ac5bad..63c7da1 100644
--- a/tests/robotests/src/com/android/settings/accessibility/HtmlTextPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/HtmlTextPreferenceTest.java
@@ -23,7 +23,6 @@
 import android.text.Html;
 import android.view.LayoutInflater;
 import android.view.View;
-import android.widget.TextView;
 
 import androidx.preference.PreferenceViewHolder;
 
@@ -36,9 +35,6 @@
 import org.robolectric.RuntimeEnvironment;
 import org.xml.sax.XMLReader;
 
-import java.util.ArrayList;
-import java.util.List;
-
 /** Tests for {@link HtmlTextPreference} */
 @RunWith(RobolectricTestRunner.class)
 public final class HtmlTextPreferenceTest {
@@ -65,21 +61,13 @@
     }
 
     @Test
-    public void testUnsupportedTagList_keepRealContentWithoutTag() {
-        final List<String> testUnsupportedTagList = new ArrayList<>();
-        testUnsupportedTagList.add("testTag");
+    public void testTagHandler() {
         final String testStr = "<testTag>Real description</testTag>";
-        final String expectedStr = "Real description";
-        final String expectedTag = "unsupportedtag1";
 
-        mHtmlTextPreference.setUnsupportedTagList(testUnsupportedTagList);
         mHtmlTextPreference.setSummary(testStr);
         mHtmlTextPreference.setTagHandler(mTagHandler);
         mHtmlTextPreference.onBindViewHolder(mPreferenceViewHolder);
 
-        final TextView summaryView = mPreferenceViewHolder.itemView.findViewById(
-                android.R.id.summary);
-        assertThat(summaryView.getText().toString()).isEqualTo(expectedStr);
-        assertThat(mHandledTag).isEqualTo(expectedTag);
+        assertThat(mHandledTag).isEqualTo("testTag");
     }
 }
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogControllerTest.java
index 7ad8d63..2fb2a3d 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogControllerTest.java
@@ -142,6 +142,37 @@
         verify(mDialog).removeViewFromScreen(ID_GSM_SETTINGS);
     }
 
+
+    @Test
+    public void populateImeiInfo_cdmaSimPresent_shouldSetImeiInfoAndSetAllCdmaSetting() {
+        ReflectionHelpers.setField(mController, "mSubscriptionInfo", null);
+        when(mTelephonyManager.getPhoneType()).thenReturn(TelephonyManager.PHONE_TYPE_CDMA);
+        when(mTelephonyManager.getSimState(anyInt())).thenReturn(
+                TelephonyManager.SIM_STATE_PRESENT);
+
+        mController.populateImeiInfo();
+
+        verify(mDialog).setText(ID_MEID_NUMBER_VALUE, MEID_NUMBER);
+        verify(mDialog).setText(ID_MIN_NUMBER_VALUE, "");
+        verify(mDialog).setText(ID_PRL_VERSION_VALUE, "");
+        verify(mDialog).setText(eq(ID_IMEI_VALUE), any());
+        verify(mDialog).setText(eq(ID_IMEI_SV_VALUE), any());
+    }
+
+    @Test
+    public void populateImeiInfo_cdmaSimABSENT_shouldSetImeiInfoAndSetAllCdmaSetting() {
+        ReflectionHelpers.setField(mController, "mSubscriptionInfo", null);
+        when(mTelephonyManager.getPhoneType()).thenReturn(TelephonyManager.PHONE_TYPE_CDMA);
+        when(mTelephonyManager.getSimState(anyInt())).thenReturn(TelephonyManager.SIM_STATE_ABSENT);
+
+        mController.populateImeiInfo();
+
+        verify(mDialog).setText(ID_MEID_NUMBER_VALUE, MEID_NUMBER);
+        verify(mDialog).setText(ID_MIN_NUMBER_VALUE, "");
+        verify(mDialog).setText(ID_PRL_VERSION_VALUE, "");
+        verify(mDialog).removeViewFromScreen(ID_GSM_SETTINGS);
+    }
+
     @Test
     public void populateImeiInfo_gsmSimDisabled_shouldSetImeiAndRemoveCdmaSettings() {
         ReflectionHelpers.setField(mController, "mSubscriptionInfo", null);
diff --git a/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorSliceTest.java b/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorSliceTest.java
index 3b5e828..fa926df 100644
--- a/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorSliceTest.java
+++ b/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorSliceTest.java
@@ -17,16 +17,25 @@
 
 package com.android.settings.media;
 
+import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_INDICATOR_SLICE_URI;
+
 import static com.google.common.truth.Truth.assertThat;
 
+import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import android.bluetooth.BluetoothAdapter;
 import android.bluetooth.BluetoothDevice;
 import android.bluetooth.BluetoothManager;
 import android.content.Context;
+import android.content.Intent;
 import android.media.AudioManager;
+import android.media.session.MediaController;
+import android.media.session.MediaSession;
+import android.net.Uri;
+import android.text.TextUtils;
 
 import androidx.slice.Slice;
 import androidx.slice.SliceMetadata;
@@ -34,33 +43,42 @@
 import androidx.slice.widget.SliceLiveData;
 
 import com.android.settings.R;
+import com.android.settings.slices.SliceBackgroundWorker;
 import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
 import com.android.settingslib.bluetooth.A2dpProfile;
 import com.android.settingslib.bluetooth.HearingAidProfile;
 import com.android.settingslib.bluetooth.LocalBluetoothManager;
 import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
+import com.android.settingslib.media.MediaOutputSliceConstants;
 
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.RobolectricTestRunner;
 import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
 
 import java.util.ArrayList;
 import java.util.List;
 
 @RunWith(RobolectricTestRunner.class)
-@Config(shadows = {ShadowBluetoothUtils.class})
+@Config(shadows = {ShadowBluetoothUtils.class,
+        MediaOutputIndicatorSliceTest.ShadowSliceBackgroundWorker.class})
 public class MediaOutputIndicatorSliceTest {
 
     private static final String TEST_A2DP_DEVICE_NAME = "Test_A2DP_BT_Device_NAME";
     private static final String TEST_HAP_DEVICE_NAME = "Test_HAP_BT_Device_NAME";
     private static final String TEST_A2DP_DEVICE_ADDRESS = "00:A1:A1:A1:A1:A1";
     private static final String TEST_HAP_DEVICE_ADDRESS = "00:B2:B2:B2:B2:B2";
+    private static final String TEST_PACKAGE_NAME = "com.test";
+
+    private static MediaOutputIndicatorWorker sMediaOutputIndicatorWorker;
 
     @Mock
     private A2dpProfile mA2dpProfile;
@@ -70,6 +88,8 @@
     private LocalBluetoothManager mLocalBluetoothManager;
     @Mock
     private LocalBluetoothProfileManager mLocalBluetoothProfileManager;
+    @Mock
+    private MediaController mMediaController;
 
     private BluetoothAdapter mBluetoothAdapter;
     private BluetoothDevice mA2dpDevice;
@@ -79,6 +99,7 @@
     private List<BluetoothDevice> mDevicesList;
     private MediaOutputIndicatorSlice mMediaOutputIndicatorSlice;
     private AudioManager mAudioManager;
+    private MediaSession.Token mToken;
 
     @Before
     public void setUp() throws Exception {
@@ -86,9 +107,11 @@
         mContext = spy(RuntimeEnvironment.application);
         mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
         mAudioManager.setMode(AudioManager.MODE_NORMAL);
+        sMediaOutputIndicatorWorker = spy(new MediaOutputIndicatorWorker(mContext,
+                MEDIA_OUTPUT_INDICATOR_SLICE_URI));
+        mToken = new MediaSession.Token(null);
         // Set-up specs for SliceMetadata.
         SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
-
         // Setup Bluetooth environment
         ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager;
         mBluetoothManager = new BluetoothManager(mContext);
@@ -196,4 +219,45 @@
         final SliceMetadata metadata = SliceMetadata.from(mContext, mediaSlice);
         assertThat(metadata.isErrorSlice()).isTrue();
     }
+
+    @Test
+    public void onNotifyChange_withActiveLocalMedia_verifyIntentExtra() {
+        when(mMediaController.getSessionToken()).thenReturn(mToken);
+        when(mMediaController.getPackageName()).thenReturn(TEST_PACKAGE_NAME);
+        doReturn(mMediaController).when(sMediaOutputIndicatorWorker)
+                .getActiveLocalMediaController();
+
+        final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
+        mMediaOutputIndicatorSlice.onNotifyChange(new Intent());
+        verify(mContext).startActivity(intentCaptor.capture());
+
+        assertThat(TextUtils.equals(TEST_PACKAGE_NAME, intentCaptor.getValue().getStringExtra(
+                MediaOutputSliceConstants.EXTRA_PACKAGE_NAME))).isTrue();
+        assertThat(mToken == intentCaptor.getValue().getExtras().getParcelable(
+                MediaOutputSliceConstants.KEY_MEDIA_SESSION_TOKEN)).isTrue();
+    }
+
+    @Test
+    public void onNotifyChange_withoutActiveLocalMedia_verifyIntentExtra() {
+        doReturn(mMediaController).when(sMediaOutputIndicatorWorker)
+                .getActiveLocalMediaController();
+
+        final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
+        mMediaOutputIndicatorSlice.onNotifyChange(new Intent());
+        verify(mContext).startActivity(intentCaptor.capture());
+
+        assertThat(TextUtils.isEmpty(intentCaptor.getValue().getStringExtra(
+                MediaOutputSliceConstants.EXTRA_PACKAGE_NAME))).isTrue();
+        assertThat(intentCaptor.getValue().getExtras().getParcelable(
+                MediaOutputSliceConstants.KEY_MEDIA_SESSION_TOKEN) == null).isTrue();
+    }
+
+    @Implements(SliceBackgroundWorker.class)
+    public static class ShadowSliceBackgroundWorker {
+
+        @Implementation
+        public static SliceBackgroundWorker getInstance(Uri uri) {
+            return sMediaOutputIndicatorWorker;
+        }
+    }
 }
diff --git a/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorWorkerTest.java b/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorWorkerTest.java
index 78658fd..b6231a3 100644
--- a/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorWorkerTest.java
+++ b/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorWorkerTest.java
@@ -16,6 +16,8 @@
 
 package com.android.settings.media;
 
+import static com.google.common.truth.Truth.assertThat;
+
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
@@ -28,7 +30,12 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
+import android.media.AudioAttributes;
 import android.media.AudioManager;
+import android.media.VolumeProvider;
+import android.media.session.MediaController;
+import android.media.session.MediaSessionManager;
+import android.media.session.PlaybackState;
 import android.net.Uri;
 
 import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
@@ -45,6 +52,9 @@
 import org.robolectric.annotation.Config;
 import org.robolectric.shadows.ShadowApplication;
 
+import java.util.ArrayList;
+import java.util.List;
+
 @RunWith(RobolectricTestRunner.class)
 @Config(shadows = {ShadowBluetoothUtils.class})
 public class MediaOutputIndicatorWorkerTest {
@@ -54,10 +64,18 @@
     private BluetoothEventManager mBluetoothEventManager;
     @Mock
     private LocalBluetoothManager mLocalBluetoothManager;
+    @Mock
+    private MediaSessionManager mMediaSessionManager;
+    @Mock
+    private MediaController mMediaController;
+
     private Context mContext;
-    private MediaOutputIndicatorWorker mMediaDeviceUpdateWorker;
+    private MediaOutputIndicatorWorker mMediaOutputIndicatorWorker;
     private ShadowApplication mShadowApplication;
     private ContentResolver mResolver;
+    private List<MediaController> mMediaControllers = new ArrayList<>();
+    private PlaybackState mPlaybackState;
+    private MediaController.PlaybackInfo mPlaybackInfo;
 
     @Before
     public void setUp() {
@@ -66,7 +84,10 @@
         mContext = spy(RuntimeEnvironment.application);
         ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager;
         when(mLocalBluetoothManager.getEventManager()).thenReturn(mBluetoothEventManager);
-        mMediaDeviceUpdateWorker = new MediaOutputIndicatorWorker(mContext, URI);
+        mMediaOutputIndicatorWorker = new MediaOutputIndicatorWorker(mContext, URI);
+        when(mContext.getSystemService(MediaSessionManager.class)).thenReturn(mMediaSessionManager);
+        mMediaControllers.add(mMediaController);
+        when(mMediaSessionManager.getActiveSessions(any())).thenReturn(mMediaControllers);
 
         mResolver = mock(ContentResolver.class);
         doReturn(mResolver).when(mContext).getContentResolver();
@@ -74,22 +95,22 @@
 
     @Test
     public void onSlicePinned_registerCallback() {
-        mMediaDeviceUpdateWorker.onSlicePinned();
-        verify(mBluetoothEventManager).registerCallback(mMediaDeviceUpdateWorker);
+        mMediaOutputIndicatorWorker.onSlicePinned();
+        verify(mBluetoothEventManager).registerCallback(mMediaOutputIndicatorWorker);
         verify(mContext).registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class));
     }
 
     @Test
     public void onSliceUnpinned_unRegisterCallback() {
-        mMediaDeviceUpdateWorker.onSlicePinned();
-        mMediaDeviceUpdateWorker.onSliceUnpinned();
-        verify(mBluetoothEventManager).unregisterCallback(mMediaDeviceUpdateWorker);
+        mMediaOutputIndicatorWorker.onSlicePinned();
+        mMediaOutputIndicatorWorker.onSliceUnpinned();
+        verify(mBluetoothEventManager).unregisterCallback(mMediaOutputIndicatorWorker);
         verify(mContext).unregisterReceiver(any(BroadcastReceiver.class));
     }
 
     @Test
     public void onReceive_shouldNotifyChange() {
-        mMediaDeviceUpdateWorker.onSlicePinned();
+        mMediaOutputIndicatorWorker.onSlicePinned();
 
         final Intent intent = new Intent(AudioManager.STREAM_DEVICES_CHANGED_ACTION);
         for (BroadcastReceiver receiver : mShadowApplication.getReceiversForIntent(intent)) {
@@ -98,4 +119,62 @@
 
         verify(mResolver).notifyChange(URI, null);
     }
+
+    @Test
+    public void getActiveLocalMediaController_localMediaPlaying_returnController() {
+        mPlaybackInfo = new MediaController.PlaybackInfo(
+                MediaController.PlaybackInfo.PLAYBACK_TYPE_LOCAL,
+                VolumeProvider.VOLUME_CONTROL_ABSOLUTE,
+                100,
+                10,
+                new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA).build(),
+                null);
+        mPlaybackState = new PlaybackState.Builder()
+                .setState(PlaybackState.STATE_PLAYING, 0, 1)
+                .build();
+
+        when(mMediaController.getPlaybackInfo()).thenReturn(mPlaybackInfo);
+        when(mMediaController.getPlaybackState()).thenReturn(mPlaybackState);
+
+        assertThat(mMediaOutputIndicatorWorker.getActiveLocalMediaController()).isEqualTo(
+                mMediaController);
+    }
+
+    @Test
+    public void getActiveLocalMediaController_remoteMediaPlaying_returnNull() {
+        mPlaybackInfo = new MediaController.PlaybackInfo(
+                MediaController.PlaybackInfo.PLAYBACK_TYPE_REMOTE,
+                VolumeProvider.VOLUME_CONTROL_ABSOLUTE,
+                100,
+                10,
+                new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA).build(),
+                null);
+        mPlaybackState = new PlaybackState.Builder()
+                .setState(PlaybackState.STATE_PLAYING, 0, 1)
+                .build();
+
+        when(mMediaController.getPlaybackInfo()).thenReturn(mPlaybackInfo);
+        when(mMediaController.getPlaybackState()).thenReturn(mPlaybackState);
+
+        assertThat(mMediaOutputIndicatorWorker.getActiveLocalMediaController()).isNull();
+    }
+
+    @Test
+    public void getActiveLocalMediaController_localMediaStopped_returnNull() {
+        mPlaybackInfo = new MediaController.PlaybackInfo(
+                MediaController.PlaybackInfo.PLAYBACK_TYPE_LOCAL,
+                VolumeProvider.VOLUME_CONTROL_ABSOLUTE,
+                100,
+                10,
+                new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA).build(),
+                null);
+        mPlaybackState = new PlaybackState.Builder()
+                .setState(PlaybackState.STATE_STOPPED, 0, 1)
+                .build();
+
+        when(mMediaController.getPlaybackInfo()).thenReturn(mPlaybackInfo);
+        when(mMediaController.getPlaybackState()).thenReturn(mPlaybackState);
+
+        assertThat(mMediaOutputIndicatorWorker.getActiveLocalMediaController()).isNull();
+    }
 }
diff --git a/tests/robotests/src/com/android/settings/notification/app/ConversationPromotePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/ConversationPromotePreferenceControllerTest.java
index 725be3d..9b60c97 100644
--- a/tests/robotests/src/com/android/settings/notification/app/ConversationPromotePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/ConversationPromotePreferenceControllerTest.java
@@ -20,9 +20,11 @@
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyInt;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -122,4 +124,20 @@
 
         verify(mFragment).getActivity();
     }
+
+    @Test
+    public void testHandlePreferenceClick_wrongKey() {
+        NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+        NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
+        channel.setConversationId("a", "a");
+        channel.setDemoted(true);
+        mController.onResume(appRow, channel, null, null, null, null);
+
+        Preference pref = mock(Preference.class);
+        when(pref.getKey()).thenReturn("wrong");
+        assertFalse(mController.handlePreferenceTreeClick(pref));
+
+        verify(mBackend, never()).updateChannel(eq(null), anyInt(), any());
+        verify(mFragment, never()).getActivity();
+    }
 }
diff --git a/tests/robotests/src/com/android/settings/panel/MediaOutputPanelTest.java b/tests/robotests/src/com/android/settings/panel/MediaOutputPanelTest.java
index a4c94ca..ea77485 100644
--- a/tests/robotests/src/com/android/settings/panel/MediaOutputPanelTest.java
+++ b/tests/robotests/src/com/android/settings/panel/MediaOutputPanelTest.java
@@ -236,4 +236,11 @@
         assertThat(mPanel.getSubTitle()).isEqualTo(mContext.getText(
                 R.string.media_output_panel_title));
     }
+
+    @Test
+    public void onClickCustomizedButton_shouldReleaseSession() {
+        mPanel.onClickCustomizedButton();
+
+        verify(mLocalMediaManager).releaseSession();
+    }
 }