Merge "Import translations. DO NOT MERGE" into rvc-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index dc220f2..ef38240 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -123,7 +123,8 @@
                   android:label="@string/settings_label_launcher"
                   android:theme="@style/Theme.Settings.Home"
                   android:taskAffinity="com.android.settings.root"
-                  android:launchMode="singleTask">
+                  android:launchMode="singleTask"
+                  android:configChanges="keyboard|keyboardHidden">
             <intent-filter android:priority="1">
                 <action android:name="android.settings.SETTINGS" />
                 <category android:name="android.intent.category.DEFAULT" />
diff --git a/res/layout/accessibility_edit_shortcut_magnification.xml b/res/layout/accessibility_edit_shortcut_magnification.xml
index afb1ec8..0253edf 100644
--- a/res/layout/accessibility_edit_shortcut_magnification.xml
+++ b/res/layout/accessibility_edit_shortcut_magnification.xml
@@ -44,19 +44,21 @@
             android:id="@+id/advanced_shortcut"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
+            android:minHeight="?android:attr/listPreferredItemHeightSmall"
             android:orientation="horizontal">
 
             <ImageView
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:scaleType="fitCenter"
+                android:layout_gravity="center"
+                android:contentDescription="@null"
+                android:scaleType="centerCrop"
                 android:src="@drawable/ic_keyboard_arrow_down" />
 
             <TextView
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
                 android:gravity="center_vertical"
-                android:minHeight="?android:attr/listPreferredItemHeightSmall"
                 android:paddingStart="12dp"
                 android:text="@string/accessibility_shortcut_edit_dialog_title_advance"
                 android:textAppearance="?android:attr/textAppearanceListItem"
diff --git a/src/com/android/settings/accessibility/AccessibilityUtil.java b/src/com/android/settings/accessibility/AccessibilityUtil.java
index 76fb3ff..ce0b5fb 100644
--- a/src/com/android/settings/accessibility/AccessibilityUtil.java
+++ b/src/com/android/settings/accessibility/AccessibilityUtil.java
@@ -73,7 +73,7 @@
     /**
      * Annotation for different user shortcut type UI type.
      *
-     * {@code DEFAULT} for displaying default value.
+     * {@code EMPTY} for displaying default value.
      * {@code SOFTWARE} for displaying specifying the accessibility services or features which
      * choose accessibility button in the navigation bar as preferred shortcut.
      * {@code HARDWARE} for displaying specifying the accessibility services or features which
@@ -83,7 +83,7 @@
      */
     @Retention(RetentionPolicy.SOURCE)
     @IntDef({
-            UserShortcutType.DEFAULT,
+            UserShortcutType.EMPTY,
             UserShortcutType.SOFTWARE,
             UserShortcutType.HARDWARE,
             UserShortcutType.TRIPLETAP,
@@ -91,7 +91,7 @@
 
     /** Denotes the user shortcut type. */
     public @interface UserShortcutType {
-        int DEFAULT = 0;
+        int EMPTY = 0;
         int SOFTWARE = 1; // 1 << 0
         int HARDWARE = 2; // 1 << 1
         int TRIPLETAP = 4; // 1 << 2
@@ -323,7 +323,7 @@
      */
     static int getUserShortcutTypesFromSettings(Context context,
             @NonNull ComponentName componentName) {
-        int shortcutTypes = UserShortcutType.DEFAULT;
+        int shortcutTypes = UserShortcutType.EMPTY;
         if (hasValuesInSettings(context, UserShortcutType.SOFTWARE, componentName)) {
             shortcutTypes |= UserShortcutType.SOFTWARE;
         }
diff --git a/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java
index d61be67..08be8b3 100644
--- a/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java
@@ -417,6 +417,8 @@
         AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes, mComponentName);
 
         mDialog.dismiss();
+
+        mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
     }
 
     private void onDenyButtonFromShortcutToggleClicked() {
diff --git a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
index 0b8353e..ec2617a 100644
--- a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
@@ -90,9 +90,9 @@
     private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
     private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type";
     private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener;
-    private int mUserShortcutType = UserShortcutType.DEFAULT;
+    private int mUserShortcutType = UserShortcutType.EMPTY;
     // Used to restore the edit dialog status.
-    private int mUserShortcutTypeCache = UserShortcutType.DEFAULT;
+    private int mUserShortcutTypeCache = UserShortcutType.EMPTY;
     private CheckBox mSoftwareTypeCheckBox;
     private CheckBox mHardwareTypeCheckBox;
 
@@ -413,18 +413,18 @@
                 new TextUtils.SimpleStringSplitter(COMPONENT_NAME_SEPARATOR);
 
         private String mComponentName;
-        private int mUserShortcutType;
+        private int mType;
 
-        AccessibilityUserShortcutType(String componentName, int userShortcutType) {
+        AccessibilityUserShortcutType(String componentName, int type) {
             this.mComponentName = componentName;
-            this.mUserShortcutType = userShortcutType;
+            this.mType = type;
         }
 
         AccessibilityUserShortcutType(String flattenedString) {
             sStringColonSplitter.setString(flattenedString);
             if (sStringColonSplitter.hasNext()) {
                 this.mComponentName = sStringColonSplitter.next();
-                this.mUserShortcutType = Integer.parseInt(sStringColonSplitter.next());
+                this.mType = Integer.parseInt(sStringColonSplitter.next());
             }
         }
 
@@ -436,18 +436,18 @@
             this.mComponentName = componentName;
         }
 
-        int getUserShortcutType() {
-            return mUserShortcutType;
+        int getType() {
+            return mType;
         }
 
-        void setUserShortcutType(int userShortcutType) {
-            this.mUserShortcutType = userShortcutType;
+        void setType(int type) {
+            this.mType = type;
         }
 
         String flattenToString() {
             final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR));
             joiner.add(mComponentName);
-            joiner.add(String.valueOf(mUserShortcutType));
+            joiner.add(String.valueOf(mType));
             return joiner.toString();
         }
     }
@@ -459,7 +459,6 @@
         final View dialogHardwareView = dialog.findViewById(R.id.hardware_shortcut);
         mHardwareTypeCheckBox = dialogHardwareView.findViewById(R.id.checkbox);
         updateAlertDialogCheckState();
-        updateAlertDialogEnableState();
     }
 
     private void updateAlertDialogCheckState() {
@@ -467,36 +466,28 @@
         updateCheckStatus(mHardwareTypeCheckBox, UserShortcutType.HARDWARE);
     }
 
-    private void updateAlertDialogEnableState() {
-        if (!mSoftwareTypeCheckBox.isChecked()) {
-            mHardwareTypeCheckBox.setEnabled(false);
-        } else if (!mHardwareTypeCheckBox.isChecked()) {
-            mSoftwareTypeCheckBox.setEnabled(false);
-        } else {
-            mSoftwareTypeCheckBox.setEnabled(true);
-            mHardwareTypeCheckBox.setEnabled(true);
-        }
-    }
-
     private void updateCheckStatus(CheckBox checkBox, @UserShortcutType int type) {
         checkBox.setChecked((mUserShortcutTypeCache & type) == type);
         checkBox.setOnClickListener(v -> {
             updateUserShortcutType(/* saveChanges= */ false);
-            updateAlertDialogEnableState();
         });
     }
 
     private void updateUserShortcutType(boolean saveChanges) {
-        mUserShortcutTypeCache = UserShortcutType.DEFAULT;
+        mUserShortcutTypeCache = UserShortcutType.EMPTY;
         if (mSoftwareTypeCheckBox.isChecked()) {
             mUserShortcutTypeCache |= UserShortcutType.SOFTWARE;
         }
         if (mHardwareTypeCheckBox.isChecked()) {
             mUserShortcutTypeCache |= UserShortcutType.HARDWARE;
         }
+
         if (saveChanges) {
+            final boolean isChanged = (mUserShortcutTypeCache != UserShortcutType.EMPTY);
+            if (isChanged) {
+                setUserShortcutType(getPrefContext(), mUserShortcutTypeCache);
+            }
             mUserShortcutType = mUserShortcutTypeCache;
-            setUserShortcutType(getPrefContext(), mUserShortcutType);
         }
     }
 
@@ -573,7 +564,7 @@
 
         final String str = (String) filtered.toArray()[0];
         final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(str);
-        return shortcut.getUserShortcutType();
+        return shortcut.getType();
     }
 
     private void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) {
@@ -582,13 +573,11 @@
         }
 
         updateUserShortcutType(/* saveChanges= */ true);
-        if (mShortcutPreference.isChecked()) {
-            AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), mUserShortcutType,
-                    mComponentName);
-            AccessibilityUtil.optOutAllValuesFromSettings(getPrefContext(), ~mUserShortcutType,
-                    mComponentName);
-        }
-        mShortcutPreference.setChecked(true);
+        AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), mUserShortcutType,
+                mComponentName);
+        AccessibilityUtil.optOutAllValuesFromSettings(getPrefContext(), ~mUserShortcutType,
+                mComponentName);
+        mShortcutPreference.setChecked(mUserShortcutType != UserShortcutType.EMPTY);
         mShortcutPreference.setSummary(
                 getShortcutTypeSummary(getPrefContext()));
     }
@@ -601,7 +590,7 @@
         // Get the user shortcut type from settings provider.
         mUserShortcutType = AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(),
                 mComponentName);
-        if (mUserShortcutType != UserShortcutType.DEFAULT) {
+        if (mUserShortcutType != UserShortcutType.EMPTY) {
             setUserShortcutType(getPrefContext(), mUserShortcutType);
         } else {
             //  Get the user shortcut type from shared_prefs if cannot get from settings provider.
@@ -613,7 +602,7 @@
         // Restore the user shortcut type.
         if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_SHORTCUT_TYPE)) {
             mUserShortcutTypeCache = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE,
-                    UserShortcutType.DEFAULT);
+                    UserShortcutType.EMPTY);
         }
 
         // Initial the shortcut preference.
diff --git a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
index 6716234..292e931 100644
--- a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
@@ -70,9 +70,9 @@
     private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type";
     private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
     private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener;
-    private int mUserShortcutType = UserShortcutType.DEFAULT;
+    private int mUserShortcutType = UserShortcutType.EMPTY;
     // Used to restore the edit dialog status.
-    private int mUserShortcutTypeCache = UserShortcutType.DEFAULT;
+    private int mUserShortcutTypeCache = UserShortcutType.EMPTY;
     private CheckBox mSoftwareTypeCheckBox;
     private CheckBox mHardwareTypeCheckBox;
     private CheckBox mTripleTapTypeCheckBox;
@@ -255,7 +255,6 @@
         mTripleTapTypeCheckBox = dialogTripleTapView.findViewById(R.id.checkbox);
         final View advancedView = dialog.findViewById(R.id.advanced_shortcut);
         updateAlertDialogCheckState();
-        updateAlertDialogEnableState();
 
         // Window magnification mode doesn't support advancedView.
         if (isWindowMagnification(getPrefContext())) {
@@ -275,30 +274,15 @@
         updateCheckStatus(mTripleTapTypeCheckBox, UserShortcutType.TRIPLETAP);
     }
 
-    private void updateAlertDialogEnableState() {
-        if (!mSoftwareTypeCheckBox.isChecked() && !mTripleTapTypeCheckBox.isChecked()) {
-            mHardwareTypeCheckBox.setEnabled(false);
-        } else if (!mHardwareTypeCheckBox.isChecked() && !mTripleTapTypeCheckBox.isChecked()) {
-            mSoftwareTypeCheckBox.setEnabled(false);
-        } else if (!mSoftwareTypeCheckBox.isChecked() && !mHardwareTypeCheckBox.isChecked()) {
-            mTripleTapTypeCheckBox.setEnabled(false);
-        } else {
-            mSoftwareTypeCheckBox.setEnabled(true);
-            mHardwareTypeCheckBox.setEnabled(true);
-            mTripleTapTypeCheckBox.setEnabled(true);
-        }
-    }
-
     private void updateCheckStatus(CheckBox checkBox, @UserShortcutType int type) {
         checkBox.setChecked((mUserShortcutTypeCache & type) == type);
         checkBox.setOnClickListener(v -> {
             updateUserShortcutType(/* saveChanges= */ false);
-            updateAlertDialogEnableState();
         });
     }
 
     private void updateUserShortcutType(boolean saveChanges) {
-        mUserShortcutTypeCache = UserShortcutType.DEFAULT;
+        mUserShortcutTypeCache = UserShortcutType.EMPTY;
         if (mSoftwareTypeCheckBox.isChecked()) {
             mUserShortcutTypeCache |= UserShortcutType.SOFTWARE;
         }
@@ -308,9 +292,13 @@
         if (mTripleTapTypeCheckBox.isChecked()) {
             mUserShortcutTypeCache |= UserShortcutType.TRIPLETAP;
         }
+
         if (saveChanges) {
+            final boolean isChanged = (mUserShortcutTypeCache != UserShortcutType.EMPTY);
+            if (isChanged) {
+                setUserShortcutType(getPrefContext(), mUserShortcutTypeCache);
+            }
             mUserShortcutType = mUserShortcutTypeCache;
-            setUserShortcutType(getPrefContext(), mUserShortcutType);
         }
     }
 
@@ -336,7 +324,7 @@
             return context.getText(R.string.switch_off_text);
         }
 
-        final int shortcutType = getUserShortcutType(context, UserShortcutType.DEFAULT);
+        final int shortcutType = getUserShortcutType(context, UserShortcutType.EMPTY);
         int resId = R.string.accessibility_shortcut_edit_summary_software;
         if (AccessibilityUtil.isGestureNavigateEnabled(context)) {
             resId = AccessibilityUtil.isTouchExploreEnabled(context)
@@ -381,16 +369,14 @@
 
         final String str = (String) filtered.toArray()[0];
         final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(str);
-        return shortcut.getUserShortcutType();
+        return shortcut.getType();
     }
 
     private void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) {
         updateUserShortcutType(/* saveChanges= */ true);
-        if (mShortcutPreference.isChecked()) {
-            optInAllMagnificationValuesToSettings(getPrefContext(), mUserShortcutType);
-            optOutAllMagnificationValuesFromSettings(getPrefContext(), ~mUserShortcutType);
-        }
-        mShortcutPreference.setChecked(true);
+        optInAllMagnificationValuesToSettings(getPrefContext(), mUserShortcutType);
+        optOutAllMagnificationValuesFromSettings(getPrefContext(), ~mUserShortcutType);
+        mShortcutPreference.setChecked(mUserShortcutType != UserShortcutType.EMPTY);
         mShortcutPreference.setSummary(
                 getShortcutTypeSummary(getPrefContext()));
     }
@@ -467,7 +453,7 @@
     private void updateShortcutPreferenceData() {
         // Get the user shortcut type from settings provider.
         mUserShortcutType = getUserShortcutTypeFromSettings(getPrefContext());
-        if (mUserShortcutType != UserShortcutType.DEFAULT) {
+        if (mUserShortcutType != UserShortcutType.EMPTY) {
             setUserShortcutType(getPrefContext(), mUserShortcutType);
         } else {
             //  Get the user shortcut type from shared_prefs if cannot get from settings provider.
@@ -626,7 +612,7 @@
     }
 
     private static int getUserShortcutTypeFromSettings(Context context) {
-        int shortcutTypes = UserShortcutType.DEFAULT;
+        int shortcutTypes = UserShortcutType.EMPTY;
         if (hasMagnificationValuesInSettings(context, UserShortcutType.SOFTWARE)) {
             shortcutTypes |= UserShortcutType.SOFTWARE;
         }
diff --git a/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java
index 3778862..21312a5 100644
--- a/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java
+++ b/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java
@@ -69,18 +69,17 @@
 
     public BluetoothDeviceUpdater(Context context, DashboardFragment fragment,
             DevicePreferenceCallback devicePreferenceCallback) {
-        this(fragment, devicePreferenceCallback, Utils.getLocalBtManager(context));
+        this(context, fragment, devicePreferenceCallback, Utils.getLocalBtManager(context));
     }
 
     @VisibleForTesting
-    BluetoothDeviceUpdater(DashboardFragment fragment,
+    BluetoothDeviceUpdater(Context context, DashboardFragment fragment,
             DevicePreferenceCallback devicePreferenceCallback, LocalBluetoothManager localManager) {
         mFragment = fragment;
         mDevicePreferenceCallback = devicePreferenceCallback;
         mPreferenceMap = new HashMap<>();
         mLocalManager = localManager;
-        mMetricsFeatureProvider = FeatureFactory.getFactory(mFragment.getContext())
-                .getMetricsFeatureProvider();
+        mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
     }
 
     /**
diff --git a/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSlice.java b/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSlice.java
index 53782e5..14a93b8 100644
--- a/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSlice.java
+++ b/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSlice.java
@@ -39,8 +39,10 @@
 import com.android.settings.R;
 import com.android.settings.SubSettings;
 import com.android.settings.Utils;
+import com.android.settings.bluetooth.AvailableMediaBluetoothDeviceUpdater;
 import com.android.settings.bluetooth.BluetoothDeviceDetailsFragment;
 import com.android.settings.bluetooth.BluetoothPairingDetail;
+import com.android.settings.bluetooth.SavedBluetoothDeviceUpdater;
 import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
 import com.android.settings.core.SubSettingLauncher;
 import com.android.settings.slices.CustomSliceRegistry;
@@ -78,9 +80,15 @@
     private static final String TAG = "BluetoothDevicesSlice";
 
     private final Context mContext;
+    private final AvailableMediaBluetoothDeviceUpdater mAvailableMediaBtDeviceUpdater;
+    private final SavedBluetoothDeviceUpdater mSavedBtDeviceUpdater;
 
     public BluetoothDevicesSlice(Context context) {
         mContext = context;
+        mAvailableMediaBtDeviceUpdater = new AvailableMediaBluetoothDeviceUpdater(mContext,
+                null /* fragment */, null /* devicePreferenceCallback */);
+        mSavedBtDeviceUpdater = new SavedBluetoothDeviceUpdater(mContext,
+                null /* fragment */, null /* devicePreferenceCallback */);
     }
 
     @Override
@@ -123,10 +131,10 @@
         final List<ListBuilder.RowBuilder> rows = getBluetoothRowBuilder();
 
         // Get displayable device count.
-        final int deviceCount = Math.min(rows.size(), DEFAULT_EXPANDED_ROW_COUNT);
+        final int displayableCount = Math.min(rows.size(), DEFAULT_EXPANDED_ROW_COUNT);
 
         // According to the displayable device count to add bluetooth device rows.
-        for (int i = 0; i < deviceCount; i++) {
+        for (int i = 0; i < displayableCount; i++) {
             listBuilder.addRow(rows.get(i));
         }
 
@@ -148,11 +156,14 @@
 
     @Override
     public void onNotifyChange(Intent intent) {
-        // Activate available media device.
         final int bluetoothDeviceHashCode = intent.getIntExtra(BLUETOOTH_DEVICE_HASH_CODE, -1);
-        for (CachedBluetoothDevice cachedBluetoothDevice : getConnectedBluetoothDevices()) {
-            if (cachedBluetoothDevice.hashCode() == bluetoothDeviceHashCode) {
-                cachedBluetoothDevice.setActive();
+        for (CachedBluetoothDevice device : getPairedBluetoothDevices()) {
+            if (device.hashCode() == bluetoothDeviceHashCode) {
+                if (device.isConnected()) {
+                    device.setActive();
+                } else if (!device.isBusy()) {
+                    device.connect();
+                }
                 return;
             }
         }
@@ -164,7 +175,7 @@
     }
 
     @VisibleForTesting
-    List<CachedBluetoothDevice> getConnectedBluetoothDevices() {
+    List<CachedBluetoothDevice> getPairedBluetoothDevices() {
         final List<CachedBluetoothDevice> bluetoothDeviceList = new ArrayList<>();
 
         // If Bluetooth is disable, skip to get the Bluetooth devices.
@@ -174,19 +185,18 @@
         }
 
         // Get the Bluetooth devices from LocalBluetoothManager.
-        final LocalBluetoothManager bluetoothManager =
+        final LocalBluetoothManager localBtManager =
                 com.android.settings.bluetooth.Utils.getLocalBtManager(mContext);
-        if (bluetoothManager == null) {
+        if (localBtManager == null) {
             Log.i(TAG, "Cannot get Bluetooth devices, Bluetooth is unsupported.");
             return bluetoothDeviceList;
         }
         final Collection<CachedBluetoothDevice> cachedDevices =
-                bluetoothManager.getCachedDeviceManager().getCachedDevicesCopy();
+                localBtManager.getCachedDeviceManager().getCachedDevicesCopy();
 
-        // Get all connected devices and sort them.
+        // Get all paired devices and sort them.
         return cachedDevices.stream()
-                .filter(device -> device.getDevice().getBondState() == BluetoothDevice.BOND_BONDED
-                        && device.getDevice().isConnected())
+                .filter(device -> device.getDevice().getBondState() == BluetoothDevice.BOND_BONDED)
                 .sorted(COMPARATOR).collect(Collectors.toList());
     }
 
@@ -242,21 +252,21 @@
     private List<ListBuilder.RowBuilder> getBluetoothRowBuilder() {
         // According to Bluetooth devices to create row builders.
         final List<ListBuilder.RowBuilder> bluetoothRows = new ArrayList<>();
-        final List<CachedBluetoothDevice> bluetoothDevices = getConnectedBluetoothDevices();
-        for (CachedBluetoothDevice bluetoothDevice : bluetoothDevices) {
+        for (CachedBluetoothDevice device : getPairedBluetoothDevices()) {
             final ListBuilder.RowBuilder rowBuilder = new ListBuilder.RowBuilder()
-                    .setTitleItem(getBluetoothDeviceIcon(bluetoothDevice), ListBuilder.ICON_IMAGE)
-                    .setTitle(bluetoothDevice.getName())
-                    .setSubtitle(bluetoothDevice.getConnectionSummary());
+                    .setTitleItem(getBluetoothDeviceIcon(device), ListBuilder.ICON_IMAGE)
+                    .setTitle(device.getName())
+                    .setSubtitle(device.getConnectionSummary());
 
-            if (bluetoothDevice.isConnectedA2dpDevice()) {
-                // For available media devices, the primary action is to activate audio stream and
-                // add setting icon to the end to link detail page.
-                rowBuilder.setPrimaryAction(buildMediaBluetoothAction(bluetoothDevice));
-                rowBuilder.addEndItem(buildBluetoothDetailDeepLinkAction(bluetoothDevice));
+            if (mAvailableMediaBtDeviceUpdater.isFilterMatched(device)
+                    || mSavedBtDeviceUpdater.isFilterMatched(device)) {
+                // For all available media devices and previously connected devices, the primary
+                // action is to activate or connect, and the end gear icon links to detail page.
+                rowBuilder.setPrimaryAction(buildPrimaryBluetoothAction(device));
+                rowBuilder.addEndItem(buildBluetoothDetailDeepLinkAction(device));
             } else {
-                // For other devices, the primary action is to link detail page.
-                rowBuilder.setPrimaryAction(buildBluetoothDetailDeepLinkAction(bluetoothDevice));
+                // For other devices, the primary action is to link to detail page.
+                rowBuilder.setPrimaryAction(buildBluetoothDetailDeepLinkAction(device));
             }
 
             bluetoothRows.add(rowBuilder);
@@ -266,8 +276,7 @@
     }
 
     @VisibleForTesting
-    SliceAction buildMediaBluetoothAction(CachedBluetoothDevice bluetoothDevice) {
-        // Send broadcast to activate available media device.
+    SliceAction buildPrimaryBluetoothAction(CachedBluetoothDevice bluetoothDevice) {
         final Intent intent = new Intent(getUri().toString())
                 .setClass(mContext, SliceBroadcastReceiver.class)
                 .putExtra(BLUETOOTH_DEVICE_HASH_CODE, bluetoothDevice.hashCode());
diff --git a/src/com/android/settings/media/MediaOutputIndicatorSlice.java b/src/com/android/settings/media/MediaOutputIndicatorSlice.java
index de2f85f..860a933 100644
--- a/src/com/android/settings/media/MediaOutputIndicatorSlice.java
+++ b/src/com/android/settings/media/MediaOutputIndicatorSlice.java
@@ -20,51 +20,33 @@
 
 import android.annotation.ColorInt;
 import android.app.PendingIntent;
-import android.bluetooth.BluetoothDevice;
 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;
 
 import androidx.core.graphics.drawable.IconCompat;
 import androidx.slice.Slice;
 import androidx.slice.builders.ListBuilder;
 import androidx.slice.builders.SliceAction;
 
-import com.android.internal.util.CollectionUtils;
 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;
-import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
 import com.android.settingslib.media.MediaOutputSliceConstants;
 
-import java.util.ArrayList;
-import java.util.List;
-
 public class MediaOutputIndicatorSlice implements CustomSliceable {
 
-    private static final String TAG = "MediaOutputIndicatorSlice";
+    private static final String TAG = "MediaOutputIndSlice";
 
     private Context mContext;
-    private LocalBluetoothManager mLocalBluetoothManager;
-    private LocalBluetoothProfileManager mProfileManager;
     private MediaOutputIndicatorWorker mWorker;
 
     public MediaOutputIndicatorSlice(Context context) {
         mContext = context;
-        mLocalBluetoothManager = com.android.settings.bluetooth.Utils.getLocalBtManager(context);
-        if (mLocalBluetoothManager == null) {
-            Log.e(TAG, "Bluetooth is not supported on this device");
-            return;
-        }
-        mProfileManager = mLocalBluetoothManager.getProfileManager();
     }
 
     @Override
@@ -86,7 +68,7 @@
                 .addRow(new ListBuilder.RowBuilder()
                         .setTitle(title)
                         .setTitleItem(createEmptyIcon(), ListBuilder.ICON_IMAGE)
-                        .setSubtitle(findActiveDeviceName())
+                        .setSubtitle(getWorker().getCurrentConnectedMediaDevice().getName())
                         .setPrimaryAction(primarySliceAction));
         return listBuilder.build();
     }
@@ -146,63 +128,10 @@
         // To decide Slice's visibility.
         // Return true if
         // 1. AudioMode is not in on-going call
-        // 2. Bluetooth device is connected
-        return (!CollectionUtils.isEmpty(getConnectedA2dpDevices())
-                || !CollectionUtils.isEmpty(getConnectedHearingAidDevices()))
-                && !com.android.settingslib.Utils.isAudioModeOngoingCall(mContext);
-    }
-
-    private List<BluetoothDevice> getConnectedA2dpDevices() {
-        // Get A2dp devices on states
-        // (STATE_CONNECTING, STATE_CONNECTED,  STATE_DISCONNECTING)
-        final A2dpProfile a2dpProfile = mProfileManager.getA2dpProfile();
-        if (a2dpProfile == null) {
-            return new ArrayList<>();
-        }
-        return a2dpProfile.getConnectedDevices();
-    }
-
-    private List<BluetoothDevice> getConnectedHearingAidDevices() {
-        // Get hearing aid profile devices on states
-        // (STATE_CONNECTING, STATE_CONNECTED,  STATE_DISCONNECTING)
-        final HearingAidProfile hapProfile = mProfileManager.getHearingAidProfile();
-        if (hapProfile == null) {
-            return new ArrayList<>();
-        }
-
-        return hapProfile.getConnectedDevices();
-    }
-
-    private CharSequence findActiveDeviceName() {
-        // Return Hearing Aid device name if it is active
-        BluetoothDevice activeDevice = findActiveHearingAidDevice();
-        if (activeDevice != null) {
-            return activeDevice.getAlias();
-        }
-        // Return A2DP device name if it is active
-        final A2dpProfile a2dpProfile = mProfileManager.getA2dpProfile();
-        if (a2dpProfile != null) {
-            activeDevice = a2dpProfile.getActiveDevice();
-            if (activeDevice != null) {
-                return activeDevice.getAlias();
-            }
-        }
-        // No active device, return default summary
-        return mContext.getText(R.string.media_output_default_summary);
-    }
-
-    private BluetoothDevice findActiveHearingAidDevice() {
-        final HearingAidProfile hearingAidProfile = mProfileManager.getHearingAidProfile();
-        if (hearingAidProfile == null) {
-            return null;
-        }
-
-        final List<BluetoothDevice> activeDevices = hearingAidProfile.getActiveDevices();
-        for (BluetoothDevice btDevice : activeDevices) {
-            if (btDevice != null) {
-                return btDevice;
-            }
-        }
-        return null;
+        // 2. worker is not null
+        // 3. Available devices are more than 1
+        return getWorker() != null
+                && !com.android.settingslib.Utils.isAudioModeOngoingCall(mContext)
+                && getWorker().getMediaDevices().size() > 1;
     }
 }
diff --git a/src/com/android/settings/media/MediaOutputIndicatorWorker.java b/src/com/android/settings/media/MediaOutputIndicatorWorker.java
index 4ceeade..6daa745 100644
--- a/src/com/android/settings/media/MediaOutputIndicatorWorker.java
+++ b/src/com/android/settings/media/MediaOutputIndicatorWorker.java
@@ -18,7 +18,6 @@
 
 import static android.media.AudioManager.STREAM_DEVICES_CHANGED_ACTION;
 
-import android.bluetooth.BluetoothProfile;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
@@ -36,21 +35,33 @@
 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 com.android.settingslib.media.LocalMediaManager;
+import com.android.settingslib.media.MediaDevice;
+
+import com.google.common.annotations.VisibleForTesting;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 /**
  * Listener for background change from {@code BluetoothCallback} to update media output indicator.
  */
-public class MediaOutputIndicatorWorker extends SliceBackgroundWorker implements BluetoothCallback {
+public class MediaOutputIndicatorWorker extends SliceBackgroundWorker implements BluetoothCallback,
+        LocalMediaManager.DeviceCallback {
 
-    private static final String TAG = "MediaOutputIndicatorWorker";
+    private static final String TAG = "MediaOutputIndWorker";
 
     private final DevicesChangedBroadcastReceiver mReceiver;
     private final Context mContext;
+    private final Collection<MediaDevice> mMediaDevices = new CopyOnWriteArrayList<>();
 
     private LocalBluetoothManager mLocalBluetoothManager;
 
+    @VisibleForTesting
+    LocalMediaManager mLocalMediaManager;
+
     public MediaOutputIndicatorWorker(Context context, Uri uri) {
         super(context, uri);
         mReceiver = new DevicesChangedBroadcastReceiver();
@@ -59,6 +70,7 @@
 
     @Override
     protected void onSlicePinned() {
+        mMediaDevices.clear();
         mLocalBluetoothManager = Utils.getLocalBtManager(getContext());
         if (mLocalBluetoothManager == null) {
             Log.e(TAG, "Bluetooth is not supported on this device");
@@ -67,10 +79,25 @@
         final IntentFilter intentFilter = new IntentFilter(STREAM_DEVICES_CHANGED_ACTION);
         mContext.registerReceiver(mReceiver, intentFilter);
         mLocalBluetoothManager.getEventManager().registerCallback(this);
+
+        if (mLocalMediaManager == null) {
+            final MediaController controller = getActiveLocalMediaController();
+            String packageName = null;
+            if (controller != null) {
+                packageName = controller.getPackageName();
+            }
+            mLocalMediaManager = new LocalMediaManager(mContext, packageName, null);
+        }
+
+        mLocalMediaManager.registerCallback(this);
+        mLocalMediaManager.startScan();
     }
 
     @Override
     protected void onSliceUnpinned() {
+        mLocalMediaManager.unregisterCallback(this);
+        mLocalMediaManager.stopScan();
+
         if (mLocalBluetoothManager == null) {
             Log.e(TAG, "Bluetooth is not supported on this device");
             return;
@@ -82,20 +109,7 @@
     @Override
     public void close() {
         mLocalBluetoothManager = null;
-    }
-
-    @Override
-    public void onBluetoothStateChanged(int bluetoothState) {
-        // To handle the case that Bluetooth on and no connected devices
-        notifySliceChange();
-    }
-
-    @Override
-    public void onActiveDeviceChanged(CachedBluetoothDevice activeDevice, int bluetoothProfile) {
-        if (bluetoothProfile == BluetoothProfile.A2DP ||
-                bluetoothProfile == BluetoothProfile.HEARING_AID) {
-            notifySliceChange();
-        }
+        mLocalMediaManager = null;
     }
 
     @Override
@@ -124,6 +138,36 @@
         }
         return null;
     }
+
+    @Override
+    public void onDeviceListUpdate(List<MediaDevice> devices) {
+        buildMediaDevices(devices);
+        notifySliceChange();
+    }
+
+    private void buildMediaDevices(List<MediaDevice> devices) {
+        mMediaDevices.clear();
+        mMediaDevices.addAll(devices);
+    }
+
+    @Override
+    public void onSelectedDeviceStateChanged(MediaDevice device, int state) {
+        notifySliceChange();
+    }
+
+    @Override
+    public void onDeviceAttributesChanged() {
+        notifySliceChange();
+    }
+
+    Collection<MediaDevice> getMediaDevices() {
+        return mMediaDevices;
+    }
+
+    MediaDevice getCurrentConnectedMediaDevice() {
+        return mLocalMediaManager.getCurrentConnectedDevice();
+    }
+
     private class DevicesChangedBroadcastReceiver extends BroadcastReceiver {
         @Override
         public void onReceive(Context context, Intent intent) {
diff --git a/src/com/android/settings/media/MediaOutputSlice.java b/src/com/android/settings/media/MediaOutputSlice.java
index 92fa843..eff838d 100644
--- a/src/com/android/settings/media/MediaOutputSlice.java
+++ b/src/com/android/settings/media/MediaOutputSlice.java
@@ -22,7 +22,6 @@
 import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_SLICE_URI;
 
 import android.app.PendingIntent;
-import android.bluetooth.BluetoothAdapter;
 import android.content.Context;
 import android.content.Intent;
 import android.graphics.Color;
@@ -246,11 +245,10 @@
         // Return true if
         // 1. AudioMode is not in on-going call
         // 2. worker is not null
-        // 3. Bluetooth is enabled
-        final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
-
-        return adapter.isEnabled()
+        // 3. Available devices are more than 1
+        return getWorker() != null
                 && !com.android.settingslib.Utils.isAudioModeOngoingCall(mContext)
-                && getWorker() != null;
+                && getWorker().getMediaDevices().size() > 1;
+
     }
 }
diff --git a/src/com/android/settings/network/WifiTetherDisablePreferenceController.java b/src/com/android/settings/network/WifiTetherDisablePreferenceController.java
index 26c3acb..2650b8b 100644
--- a/src/com/android/settings/network/WifiTetherDisablePreferenceController.java
+++ b/src/com/android/settings/network/WifiTetherDisablePreferenceController.java
@@ -137,6 +137,7 @@
     public void updateState(Preference preference) {
         super.updateState(preference);
         setVisible(mScreen, mPreferenceKey, shouldShow());
+        refreshSummary(preference);
     }
 
     @Override
diff --git a/src/com/android/settings/network/telephony/Enhanced4gBasePreferenceController.java b/src/com/android/settings/network/telephony/Enhanced4gBasePreferenceController.java
index efbbbf8..d3fb437 100644
--- a/src/com/android/settings/network/telephony/Enhanced4gBasePreferenceController.java
+++ b/src/com/android/settings/network/telephony/Enhanced4gBasePreferenceController.java
@@ -48,8 +48,6 @@
 
     @VisibleForTesting
     Preference mPreference;
-    private CarrierConfigManager mCarrierConfigManager;
-    private PersistableBundle mCarrierConfig;
     private PhoneCallStateListener mPhoneStateListener;
     @VisibleForTesting
     Integer mCallState;
@@ -63,21 +61,23 @@
 
     public Enhanced4gBasePreferenceController(Context context, String key) {
         super(context, key);
-        mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
         m4gLteListeners = new ArrayList<>();
         mPhoneStateListener = new PhoneCallStateListener();
     }
 
     public Enhanced4gBasePreferenceController init(int subId) {
-        if (SubscriptionManager.isValidSubscriptionId(mSubId) && mSubId == subId) {
+        if (mSubId == subId) {
             return this;
         }
         mSubId = subId;
-        mCarrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId);
+        final PersistableBundle carrierConfig = getCarrierConfigForSubId(subId);
+        if (carrierConfig == null) {
+            return this;
+        }
 
-        final boolean show4GForLTE = mCarrierConfig.getBoolean(
+        final boolean show4GForLTE = carrierConfig.getBoolean(
                 CarrierConfigManager.KEY_SHOW_4G_FOR_LTE_DATA_ICON_BOOL);
-        m4gCurrentMode = mCarrierConfig.getInt(
+        m4gCurrentMode = carrierConfig.getInt(
                 CarrierConfigManager.KEY_ENHANCED_4G_LTE_TITLE_VARIANT_INT);
         if (m4gCurrentMode != MODE_ADVANCED_CALL) {
             m4gCurrentMode = show4GForLTE ? MODE_4G_CALLING : MODE_VOLTE;
@@ -91,10 +91,7 @@
         if (!isModeMatched()) {
             return CONDITIONALLY_UNAVAILABLE;
         }
-        if (!SubscriptionManager.isValidSubscriptionId(subId)) {
-            return CONDITIONALLY_UNAVAILABLE;
-        }
-        final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(subId);
+        final PersistableBundle carrierConfig = getCarrierConfigForSubId(subId);
         if ((carrierConfig == null)
                 || carrierConfig.getBoolean(CarrierConfigManager.KEY_HIDE_ENHANCED_4G_LTE_BOOL)) {
             return CONDITIONALLY_UNAVAILABLE;
@@ -103,7 +100,7 @@
         if (!queryState.isReadyToVoLte()) {
             return CONDITIONALLY_UNAVAILABLE;
         }
-        return (isUserControlAllowed() && queryState.isAllowUserControl())
+        return (isUserControlAllowed(carrierConfig) && queryState.isAllowUserControl())
                 ? AVAILABLE : AVAILABLE_UNSEARCHABLE;
     }
 
@@ -129,7 +126,7 @@
         final SwitchPreference switchPreference = (SwitchPreference) preference;
 
         final VolteQueryImsState queryState = queryImsState(mSubId);
-        switchPreference.setEnabled(isUserControlAllowed()
+        switchPreference.setEnabled(isUserControlAllowed(getCarrierConfigForSubId(mSubId))
                 && queryState.isAllowUserControl());
         switchPreference.setChecked(queryState.isEnabledByUser()
                 && queryState.isAllowUserControl());
@@ -180,9 +177,10 @@
         return new VolteQueryImsState(mContext, subId);
     }
 
-    private boolean isUserControlAllowed() {
+    private boolean isUserControlAllowed(final PersistableBundle carrierConfig) {
         return (mCallState != null) && (mCallState == TelephonyManager.CALL_STATE_IDLE)
-                && mCarrierConfig.getBoolean(
+                && (carrierConfig != null)
+                && carrierConfig.getBoolean(
                 CarrierConfigManager.KEY_EDITABLE_ENHANCED_4G_LTE_BOOL);
     }
 
diff --git a/src/com/android/settings/network/telephony/TelephonyBasePreferenceController.java b/src/com/android/settings/network/telephony/TelephonyBasePreferenceController.java
index e4ff5c4..241dc5d 100644
--- a/src/com/android/settings/network/telephony/TelephonyBasePreferenceController.java
+++ b/src/com/android/settings/network/telephony/TelephonyBasePreferenceController.java
@@ -17,6 +17,8 @@
 package com.android.settings.network.telephony;
 
 import android.content.Context;
+import android.os.PersistableBundle;
+import android.telephony.CarrierConfigManager;
 import android.telephony.SubscriptionManager;
 
 import com.android.settings.core.BasePreferenceController;
@@ -37,4 +39,20 @@
     public int getAvailabilityStatus() {
         return MobileNetworkUtils.getAvailability(mContext, mSubId, this::getAvailabilityStatus);
     }
+
+    /**
+     * Get carrier config based on specific subscription id.
+     *
+     * @param subId is the subscription id
+     * @return {@link PersistableBundle} of carrier config, or {@code null} when carrier config
+     * is not available.
+     */
+    public PersistableBundle getCarrierConfigForSubId(int subId) {
+        if (!SubscriptionManager.isValidSubscriptionId(subId)) {
+            return null;
+        }
+        final CarrierConfigManager carrierConfigMgr =
+                mContext.getSystemService(CarrierConfigManager.class);
+        return carrierConfigMgr.getConfigForSubId(subId);
+    }
 }
diff --git a/src/com/android/settings/network/telephony/TelephonyTogglePreferenceController.java b/src/com/android/settings/network/telephony/TelephonyTogglePreferenceController.java
index 71efc57..fc30030 100644
--- a/src/com/android/settings/network/telephony/TelephonyTogglePreferenceController.java
+++ b/src/com/android/settings/network/telephony/TelephonyTogglePreferenceController.java
@@ -17,6 +17,8 @@
 package com.android.settings.network.telephony;
 
 import android.content.Context;
+import android.os.PersistableBundle;
+import android.telephony.CarrierConfigManager;
 import android.telephony.SubscriptionManager;
 
 import com.android.settings.core.TogglePreferenceController;
@@ -37,4 +39,20 @@
     public int getAvailabilityStatus() {
         return MobileNetworkUtils.getAvailability(mContext, mSubId, this::getAvailabilityStatus);
     }
+
+    /**
+     * Get carrier config based on specific subscription id.
+     *
+     * @param subId is the subscription id
+     * @return {@link PersistableBundle} of carrier config, or {@code null} when carrier config
+     * is not available.
+     */
+    public PersistableBundle getCarrierConfigForSubId(int subId) {
+        if (!SubscriptionManager.isValidSubscriptionId(subId)) {
+            return null;
+        }
+        final CarrierConfigManager carrierConfigMgr =
+                mContext.getSystemService(CarrierConfigManager.class);
+        return carrierConfigMgr.getConfigForSubId(subId);
+    }
 }
diff --git a/src/com/android/settings/widget/VideoPreference.java b/src/com/android/settings/widget/VideoPreference.java
index 949ba9b..6356378 100644
--- a/src/com/android/settings/widget/VideoPreference.java
+++ b/src/com/android/settings/widget/VideoPreference.java
@@ -39,12 +39,18 @@
 public class VideoPreference extends Preference {
 
     private static final String TAG = "VideoPreference";
+    private static final int DEFAULT_BACKGROUND_RESOURCE_ID = -1;
     private final Context mContext;
 
     @VisibleForTesting
     AnimationController mAnimationController;
     @VisibleForTesting
     boolean mAnimationAvailable;
+    @VisibleForTesting
+    LinearLayout mAnimationView;
+    @VisibleForTesting
+    int mBackgroundResId = DEFAULT_BACKGROUND_RESOURCE_ID;
+
     private float mAspectRatio = 1.0f;
     private int mPreviewId;
     private int mAnimationId;
@@ -114,6 +120,7 @@
         mVideo = (TextureView) holder.findViewById(R.id.video_texture_view);
         mPreviewImage = (ImageView) holder.findViewById(R.id.video_preview_image);
         mPlayButton = (ImageView) holder.findViewById(R.id.video_play_button);
+        mAnimationView = (LinearLayout) holder.itemView;
         final AspectRatioFrameLayout layout = (AspectRatioFrameLayout) holder.findViewById(
                 R.id.video_container);
 
@@ -123,6 +130,9 @@
             layout.setLayoutParams(new LinearLayout.LayoutParams(
                     LinearLayout.LayoutParams.MATCH_PARENT, mHeight));
         }
+        if (mBackgroundResId != DEFAULT_BACKGROUND_RESOURCE_ID) {
+            mAnimationView.setBackgroundResource(mBackgroundResId);
+        }
         if (mAnimationController != null) {
             mAnimationController.attachView(mVideo, mPreviewImage, mPlayButton);
         }
@@ -203,6 +213,14 @@
     }
 
     /**
+     * Set the background color of the video preference
+     * @param resId resource id of color
+     */
+    public void setBackgroundColor(int resId) {
+        mBackgroundResId = resId;
+    }
+
+    /**
      * Handle animation operations.
      */
     interface AnimationController {
diff --git a/src/com/android/settings/wifi/ConnectedWifiEntryPreference.java b/src/com/android/settings/wifi/ConnectedWifiEntryPreference.java
index f79499a..afba0d8 100644
--- a/src/com/android/settings/wifi/ConnectedWifiEntryPreference.java
+++ b/src/com/android/settings/wifi/ConnectedWifiEntryPreference.java
@@ -38,15 +38,6 @@
         setWidgetLayoutResource(R.layout.preference_widget_gear_optional_background);
     }
 
-    @Override
-    public void refresh() {
-        super.refresh();
-
-        if (getWifiEntry().canSignIn()) {
-            setSummary(R.string.wifi_tap_to_sign_in);
-        }
-    }
-
     /**
      * Set gear icon click callback listener.
      */
diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java
index 5264e10..54026a5 100644
--- a/src/com/android/settings/wifi/WifiConfigController.java
+++ b/src/com/android/settings/wifi/WifiConfigController.java
@@ -28,8 +28,6 @@
 import android.net.StaticIpConfiguration;
 import android.net.Uri;
 import android.net.wifi.WifiConfiguration;
-import android.net.wifi.WifiConfiguration.AuthAlgorithm;
-import android.net.wifi.WifiConfiguration.KeyMgmt;
 import android.net.wifi.WifiEnterpriseConfig;
 import android.net.wifi.WifiEnterpriseConfig.Eap;
 import android.net.wifi.WifiEnterpriseConfig.Phase2;
@@ -638,13 +636,11 @@
 
         switch (mAccessPointSecurity) {
             case AccessPoint.SECURITY_NONE:
-                config.allowedKeyManagement.set(KeyMgmt.NONE);
+                config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_OPEN);
                 break;
 
             case AccessPoint.SECURITY_WEP:
-                config.allowedKeyManagement.set(KeyMgmt.NONE);
-                config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
-                config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
+                config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_WEP);
                 if (mPasswordView.length() != 0) {
                     int length = mPasswordView.length();
                     String password = mPasswordView.getText().toString();
@@ -659,7 +655,7 @@
                 break;
 
             case AccessPoint.SECURITY_PSK:
-                config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
+                config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_PSK);
                 if (mPasswordView.length() != 0) {
                     String password = mPasswordView.getText().toString();
                     if (password.matches("[0-9A-Fa-f]{64}")) {
@@ -672,16 +668,11 @@
 
             case AccessPoint.SECURITY_EAP:
             case AccessPoint.SECURITY_EAP_SUITE_B:
-                config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
-                config.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
                 if (mAccessPointSecurity == AccessPoint.SECURITY_EAP_SUITE_B) {
-                    config.allowedKeyManagement.set(KeyMgmt.SUITE_B_192);
-                    config.requirePmf = true;
-                    config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.GCMP_256);
-                    config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.GCMP_256);
-                    config.allowedGroupManagementCiphers.set(WifiConfiguration.GroupMgmtCipher
-                            .BIP_GMAC_256);
                     // allowedSuiteBCiphers will be set according to certificate type
+                    config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_EAP_SUITE_B);
+                } else {
+                    config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_EAP);
                 }
                 config.enterpriseConfig = new WifiEnterpriseConfig();
                 int eapMethod = mEapMethodSpinner.getSelectedItemPosition();
@@ -815,8 +806,7 @@
                 }
                 break;
             case AccessPoint.SECURITY_SAE:
-                config.allowedKeyManagement.set(KeyMgmt.SAE);
-                config.requirePmf = true;
+                config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_SAE);
                 if (mPasswordView.length() != 0) {
                     String password = mPasswordView.getText().toString();
                     config.preSharedKey = '"' + password + '"';
@@ -824,8 +814,7 @@
                 break;
 
             case AccessPoint.SECURITY_OWE:
-                config.allowedKeyManagement.set(KeyMgmt.OWE);
-                config.requirePmf = true;
+                config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_OWE);
                 break;
 
             default:
diff --git a/src/com/android/settings/wifi/WifiConfigController2.java b/src/com/android/settings/wifi/WifiConfigController2.java
index 830f061..4df0dfd 100644
--- a/src/com/android/settings/wifi/WifiConfigController2.java
+++ b/src/com/android/settings/wifi/WifiConfigController2.java
@@ -27,8 +27,6 @@
 import android.net.StaticIpConfiguration;
 import android.net.Uri;
 import android.net.wifi.WifiConfiguration;
-import android.net.wifi.WifiConfiguration.AuthAlgorithm;
-import android.net.wifi.WifiConfiguration.KeyMgmt;
 import android.net.wifi.WifiEnterpriseConfig;
 import android.net.wifi.WifiEnterpriseConfig.Eap;
 import android.net.wifi.WifiEnterpriseConfig.Phase2;
@@ -633,13 +631,11 @@
 
         switch (mWifiEntrySecurity) {
             case WifiEntry.SECURITY_NONE:
-                config.allowedKeyManagement.set(KeyMgmt.NONE);
+                config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_OPEN);
                 break;
 
             case WifiEntry.SECURITY_WEP:
-                config.allowedKeyManagement.set(KeyMgmt.NONE);
-                config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
-                config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
+                config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_WEP);
                 if (mPasswordView.length() != 0) {
                     int length = mPasswordView.length();
                     String password = mPasswordView.getText().toString();
@@ -654,7 +650,7 @@
                 break;
 
             case WifiEntry.SECURITY_PSK:
-                config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
+                config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_PSK);
                 if (mPasswordView.length() != 0) {
                     String password = mPasswordView.getText().toString();
                     if (password.matches("[0-9A-Fa-f]{64}")) {
@@ -667,16 +663,11 @@
 
             case WifiEntry.SECURITY_EAP:
             case WifiEntry.SECURITY_EAP_SUITE_B:
-                config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
-                config.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
                 if (mWifiEntrySecurity == WifiEntry.SECURITY_EAP_SUITE_B) {
-                    config.allowedKeyManagement.set(KeyMgmt.SUITE_B_192);
-                    config.requirePmf = true;
-                    config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.GCMP_256);
-                    config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.GCMP_256);
-                    config.allowedGroupManagementCiphers.set(WifiConfiguration.GroupMgmtCipher
-                            .BIP_GMAC_256);
                     // allowedSuiteBCiphers will be set according to certificate type
+                    config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_EAP_SUITE_B);
+                } else {
+                    config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_EAP);
                 }
                 config.enterpriseConfig = new WifiEnterpriseConfig();
                 int eapMethod = mEapMethodSpinner.getSelectedItemPosition();
@@ -809,8 +800,7 @@
                 }
                 break;
             case WifiEntry.SECURITY_SAE:
-                config.allowedKeyManagement.set(KeyMgmt.SAE);
-                config.requirePmf = true;
+                config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_SAE);
                 if (mPasswordView.length() != 0) {
                     String password = mPasswordView.getText().toString();
                     config.preSharedKey = '"' + password + '"';
@@ -818,8 +808,7 @@
                 break;
 
             case WifiEntry.SECURITY_OWE:
-                config.allowedKeyManagement.set(KeyMgmt.OWE);
-                config.requirePmf = true;
+                config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_OWE);
                 break;
 
             default:
diff --git a/src/com/android/settings/wifi/WifiUtils.java b/src/com/android/settings/wifi/WifiUtils.java
index 08ba441..c73e6a2 100644
--- a/src/com/android/settings/wifi/WifiUtils.java
+++ b/src/com/android/settings/wifi/WifiUtils.java
@@ -157,13 +157,11 @@
 
         switch (security) {
             case AccessPoint.SECURITY_NONE:
-                config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
+                config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_OPEN);
                 break;
 
             case AccessPoint.SECURITY_WEP:
-                config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
-                config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
-                config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
+                config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_WEP);
                 if (!TextUtils.isEmpty(password)) {
                     int length = password.length();
                     // WEP-40, WEP-104, and 256-bit WEP (WEP-232?)
@@ -177,7 +175,7 @@
                 break;
 
             case AccessPoint.SECURITY_PSK:
-                config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
+                config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_PSK);
                 if (!TextUtils.isEmpty(password)) {
                     if (password.matches("[0-9A-Fa-f]{64}")) {
                         config.preSharedKey = password;
@@ -189,16 +187,11 @@
 
             case AccessPoint.SECURITY_EAP:
             case AccessPoint.SECURITY_EAP_SUITE_B:
-                config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);
-                config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.IEEE8021X);
                 if (security == AccessPoint.SECURITY_EAP_SUITE_B) {
-                    config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.SUITE_B_192);
-                    config.requirePmf = true;
-                    config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.GCMP_256);
-                    config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.GCMP_256);
-                    config.allowedGroupManagementCiphers.set(WifiConfiguration.GroupMgmtCipher
-                            .BIP_GMAC_256);
                     // allowedSuiteBCiphers will be set according to certificate type
+                    config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_EAP_SUITE_B);
+                } else {
+                    config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_EAP);
                 }
 
                 if (!TextUtils.isEmpty(password)) {
@@ -206,16 +199,14 @@
                 }
                 break;
             case AccessPoint.SECURITY_SAE:
-                config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.SAE);
-                config.requirePmf = true;
+                config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_SAE);
                 if (!TextUtils.isEmpty(password)) {
                     config.preSharedKey = '"' + password + '"';
                 }
                 break;
 
             case AccessPoint.SECURITY_OWE:
-                config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.OWE);
-                config.requirePmf = true;
+                config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_OWE);
                 break;
 
             default:
diff --git a/src/com/android/settings/wifi/dpp/WifiNetworkConfig.java b/src/com/android/settings/wifi/dpp/WifiNetworkConfig.java
index fdd0bbe..e6195d1 100644
--- a/src/com/android/settings/wifi/dpp/WifiNetworkConfig.java
+++ b/src/com/android/settings/wifi/dpp/WifiNetworkConfig.java
@@ -24,7 +24,6 @@
 import android.content.Context;
 import android.content.Intent;
 import android.net.wifi.WifiConfiguration;
-import android.net.wifi.WifiConfiguration.AuthAlgorithm;
 import android.net.wifi.WifiConfiguration.KeyMgmt;
 import android.net.wifi.WifiManager;
 import android.text.TextUtils;
@@ -252,17 +251,15 @@
 
             final WifiConfiguration enhancedOpenNetworkWifiConfiguration =
                     getBasicWifiConfiguration();
-            enhancedOpenNetworkWifiConfiguration.allowedKeyManagement.set(KeyMgmt.OWE);
-            enhancedOpenNetworkWifiConfiguration.requirePmf = true;
+            enhancedOpenNetworkWifiConfiguration
+                    .setSecurityParams(WifiConfiguration.SECURITY_TYPE_OWE);
             wifiConfigurations.add(enhancedOpenNetworkWifiConfiguration);
             return wifiConfigurations;
         }
 
         final WifiConfiguration wifiConfiguration = getBasicWifiConfiguration();
         if (mSecurity.startsWith(SECURITY_WEP)) {
-            wifiConfiguration.allowedKeyManagement.set(KeyMgmt.NONE);
-            wifiConfiguration.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
-            wifiConfiguration.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
+            wifiConfiguration.setSecurityParams(WifiConfiguration.SECURITY_TYPE_WEP);
 
             // WEP-40, WEP-104, and 256-bit WEP (WEP-232?)
             final int length = mPreSharedKey.length();
@@ -273,7 +270,7 @@
                 wifiConfiguration.wepKeys[0] = addQuotationIfNeeded(mPreSharedKey);
             }
         } else if (mSecurity.startsWith(SECURITY_WPA_PSK)) {
-            wifiConfiguration.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
+            wifiConfiguration.setSecurityParams(WifiConfiguration.SECURITY_TYPE_PSK);
 
             if (mPreSharedKey.matches("[0-9A-Fa-f]{64}")) {
                 wifiConfiguration.preSharedKey = mPreSharedKey;
@@ -281,8 +278,7 @@
                 wifiConfiguration.preSharedKey = addQuotationIfNeeded(mPreSharedKey);
             }
         } else if (mSecurity.startsWith(SECURITY_SAE)) {
-            wifiConfiguration.allowedKeyManagement.set(KeyMgmt.SAE);
-            wifiConfiguration.requirePmf = true;
+            wifiConfiguration.setSecurityParams(WifiConfiguration.SECURITY_TYPE_SAE);
             if (mPreSharedKey.length() != 0) {
                 wifiConfiguration.preSharedKey = addQuotationIfNeeded(mPreSharedKey);
             }
diff --git a/tests/robotests/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java
index 35a2d19..e476c21 100644
--- a/tests/robotests/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java
@@ -60,7 +60,7 @@
                 TEST_SERVICE_KEY_1);
 
         assertThat(shortcut.getComponentName()).isEqualTo(TEST_SERVICE_NAME_1);
-        assertThat(shortcut.getUserShortcutType()).isEqualTo(TEST_SERVICE_VALUE_1);
+        assertThat(shortcut.getType()).isEqualTo(TEST_SERVICE_VALUE_1);
     }
 
     @Test
@@ -69,7 +69,7 @@
                 TEST_SERVICE_KEY_2);
 
         shortcut.setComponentName(TEST_SERVICE_NAME_1);
-        shortcut.setUserShortcutType(TEST_SERVICE_VALUE_1);
+        shortcut.setType(TEST_SERVICE_VALUE_1);
 
         assertThat(shortcut.flattenToString()).isEqualTo(TEST_SERVICE_KEY_1);
     }
@@ -103,7 +103,7 @@
 
         final String str = (String) filtered.toArray()[0];
         final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(str);
-        final int type = shortcut.getUserShortcutType();
+        final int type = shortcut.getType();
         assertThat(type).isEqualTo(TEST_SERVICE_VALUE_1);
     }
 
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java
index 260fc41..fcc7f51 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java
@@ -102,7 +102,7 @@
         mPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice,
                 false, BluetoothDevicePreference.SortType.TYPE_DEFAULT);
         mBluetoothDeviceUpdater =
-            new BluetoothDeviceUpdater(mDashboardFragment, mDevicePreferenceCallback,
+            new BluetoothDeviceUpdater(mContext, mDashboardFragment, mDevicePreferenceCallback,
                     mLocalManager) {
                 @Override
                 public boolean isFilterMatched(CachedBluetoothDevice cachedBluetoothDevice) {
diff --git a/tests/robotests/src/com/android/settings/development/WirelessDebuggingEnablerTest.java b/tests/robotests/src/com/android/settings/development/WirelessDebuggingEnablerTest.java
index 7f4f530..56e898f 100644
--- a/tests/robotests/src/com/android/settings/development/WirelessDebuggingEnablerTest.java
+++ b/tests/robotests/src/com/android/settings/development/WirelessDebuggingEnablerTest.java
@@ -27,7 +27,6 @@
 
 import androidx.lifecycle.LifecycleOwner;
 
-import com.android.settings.SettingsActivity;
 import com.android.settings.testutils.shadow.ShadowUtils;
 import com.android.settings.widget.SwitchBar;
 import com.android.settings.widget.SwitchBarController;
@@ -48,8 +47,6 @@
 public class WirelessDebuggingEnablerTest {
 
     @Mock
-    private SettingsActivity mActivity;
-    @Mock
     private SwitchBar mSwitchBar;
     @Mock
     private WirelessDebuggingEnabler.OnEnabledListener mListener;
@@ -133,8 +130,6 @@
 
         mWirelessDebuggingEnabler.onSwitchToggled(true);
 
-        verify(mSwitchBar).setChecked(true);
-        verify(mListener).onEnabled(true);
         assertThat(Global.getInt(mContext.getContentResolver(),
                 Global.ADB_WIFI_ENABLED, -1)).isEqualTo(1);
         // Should also get a callback
@@ -151,8 +146,6 @@
 
         mWirelessDebuggingEnabler.onSwitchToggled(false);
 
-        verify(mSwitchBar).setChecked(false);
-        verify(mListener).onEnabled(false);
         assertThat(Global.getInt(mContext.getContentResolver(),
             Global.ADB_WIFI_ENABLED, -1)).isEqualTo(0);
         // Should also get a callback
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSliceTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSliceTest.java
index cec3bee..a0b2141 100644
--- a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSliceTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSliceTest.java
@@ -23,12 +23,15 @@
 
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doReturn;
+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;
 
 import android.app.PendingIntent;
 import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
 import android.content.Context;
 import android.content.Intent;
 
@@ -62,6 +65,7 @@
 import java.util.List;
 
 @RunWith(RobolectricTestRunner.class)
+@Config(shadows = ShadowBluetoothAdapter.class)
 public class BluetoothDevicesSliceTest {
 
     private static final String BLUETOOTH_MOCK_ADDRESS = "00:11:00:11:00:11";
@@ -96,6 +100,13 @@
 
         // Initial Bluetooth device list.
         mBluetoothDeviceList = new ArrayList<>();
+
+        final BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter();
+        if (defaultAdapter != null) {
+            final ShadowBluetoothAdapter shadowBluetoothAdapter = Shadow.extract(defaultAdapter);
+            shadowBluetoothAdapter.setEnabled(true);
+            shadowBluetoothAdapter.setState(BluetoothAdapter.STATE_ON);
+        }
     }
 
     @After
@@ -114,7 +125,6 @@
     }
 
     @Test
-    @Config(shadows = ShadowBluetoothAdapter.class)
     public void getSlice_hasBluetoothHardware_shouldHaveBluetoothDevicesTitleAndPairNewDevice() {
         final Slice slice = mBluetoothDevicesSlice.getSlice();
 
@@ -127,12 +137,9 @@
     }
 
     @Test
-    @Config(shadows = ShadowBluetoothAdapter.class)
     public void getSlice_hasBluetoothDevices_shouldMatchBluetoothMockTitle() {
-        final ShadowBluetoothAdapter adapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
-        adapter.setState(BluetoothAdapter.STATE_ON);
         mockBluetoothDeviceList(1);
-        doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getConnectedBluetoothDevices();
+        doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getPairedBluetoothDevices();
 
         final Slice slice = mBluetoothDevicesSlice.getSlice();
 
@@ -141,39 +148,43 @@
     }
 
     @Test
-    @Config(shadows = ShadowBluetoothAdapter.class)
-    public void getSlice_hasMediaBluetoothDevice_shouldBuildMediaBluetoothAction() {
-        final ShadowBluetoothAdapter adapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
-        adapter.setState(BluetoothAdapter.STATE_ON);
-        mockBluetoothDeviceList(1 /* deviceCount */);
-        doReturn(true).when(mBluetoothDeviceList.get(0)).isConnectedA2dpDevice();
-        doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getConnectedBluetoothDevices();
+    public void getSlice_hasAvailableMediaDevice_shouldBuildPrimaryBluetoothAction() {
+        mockBluetoothDeviceList(1);
+        when(mBluetoothDeviceList.get(0).getDevice().isConnected()).thenReturn(true);
+        doReturn(true).when(mBluetoothDeviceList.get(0)).isConnectedHearingAidDevice();
+        doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getPairedBluetoothDevices();
 
         mBluetoothDevicesSlice.getSlice();
 
-        verify(mBluetoothDevicesSlice).buildMediaBluetoothAction(any());
+        verify(mBluetoothDevicesSlice).buildPrimaryBluetoothAction(any());
     }
 
     @Test
-    @Config(shadows = ShadowBluetoothAdapter.class)
-    public void getSlice_noMediaBluetoothDevice_shouldNotBuildMediaBluetoothAction() {
-        final ShadowBluetoothAdapter adapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
-        adapter.setState(BluetoothAdapter.STATE_ON);
-        mockBluetoothDeviceList(1 /* deviceCount */);
-        doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getConnectedBluetoothDevices();
+    public void getSlice_hasPreviouslyConnectedDevice_shouldBuildPrimaryBluetoothAction() {
+        mockBluetoothDeviceList(1);
+        when(mBluetoothDeviceList.get(0).getDevice().isConnected()).thenReturn(false);
+        doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getPairedBluetoothDevices();
 
         mBluetoothDevicesSlice.getSlice();
 
-        verify(mBluetoothDevicesSlice, never()).buildMediaBluetoothAction(any());
+        verify(mBluetoothDevicesSlice).buildPrimaryBluetoothAction(any());
     }
 
     @Test
-    @Config(shadows = ShadowBluetoothAdapter.class)
+    public void getSlice_hasNonMediaDeviceConnected_shouldNotBuildPrimaryBluetoothAction() {
+        mockBluetoothDeviceList(1);
+        when(mBluetoothDeviceList.get(0).getDevice().isConnected()).thenReturn(true);
+        doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getPairedBluetoothDevices();
+
+        mBluetoothDevicesSlice.getSlice();
+
+        verify(mBluetoothDevicesSlice, never()).buildPrimaryBluetoothAction(any());
+    }
+
+    @Test
     public void getSlice_exceedDefaultRowCount_shouldOnlyShowDefaultRows() {
-        final ShadowBluetoothAdapter adapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
-        adapter.setState(BluetoothAdapter.STATE_ON);
         mockBluetoothDeviceList(BluetoothDevicesSlice.DEFAULT_EXPANDED_ROW_COUNT + 1);
-        doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getConnectedBluetoothDevices();
+        doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getPairedBluetoothDevices();
 
         final Slice slice = mBluetoothDevicesSlice.getSlice();
 
@@ -183,9 +194,10 @@
     }
 
     @Test
-    public void onNotifyChange_mediaDevice_shouldActivateDevice() {
+    public void onNotifyChange_connectedDevice_shouldActivateDevice() {
         mockBluetoothDeviceList(1);
-        doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getConnectedBluetoothDevices();
+        doReturn(true).when(mBluetoothDeviceList.get(0)).isConnected();
+        doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getPairedBluetoothDevices();
         final Intent intent = new Intent().putExtra(
                 BluetoothDevicesSlice.BLUETOOTH_DEVICE_HASH_CODE,
                 mCachedBluetoothDevice.hashCode());
@@ -195,7 +207,41 @@
         verify(mCachedBluetoothDevice).setActive();
     }
 
+    @Test
+    public void onNotifyChange_availableDisconnectedDevice_shouldConnectToDevice() {
+        mockBluetoothDeviceList(1);
+        doReturn(false).when(mBluetoothDeviceList.get(0)).isConnected();
+        doReturn(false).when(mBluetoothDeviceList.get(0)).isBusy();
+        doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getPairedBluetoothDevices();
+        final Intent intent = new Intent().putExtra(
+                BluetoothDevicesSlice.BLUETOOTH_DEVICE_HASH_CODE,
+                mCachedBluetoothDevice.hashCode());
+
+        mBluetoothDevicesSlice.onNotifyChange(intent);
+
+        verify(mCachedBluetoothDevice).connect();
+    }
+
+    @Test
+    public void onNotifyChange_busyDisconnectedDevice_shouldDoNothing() {
+        mockBluetoothDeviceList(1);
+        doReturn(false).when(mBluetoothDeviceList.get(0)).isConnected();
+        doReturn(true).when(mBluetoothDeviceList.get(0)).isBusy();
+        doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getPairedBluetoothDevices();
+        final Intent intent = new Intent().putExtra(
+                BluetoothDevicesSlice.BLUETOOTH_DEVICE_HASH_CODE,
+                mCachedBluetoothDevice.hashCode());
+
+        mBluetoothDevicesSlice.onNotifyChange(intent);
+
+        verify(mCachedBluetoothDevice, never()).setActive();
+        verify(mCachedBluetoothDevice, never()).connect();
+    }
+
     private void mockBluetoothDeviceList(int deviceCount) {
+        final BluetoothDevice device = mock(BluetoothDevice.class);
+        doReturn(BluetoothDevice.BOND_BONDED).when(device).getBondState();
+        doReturn(device).when(mCachedBluetoothDevice).getDevice();
         doReturn(BLUETOOTH_MOCK_TITLE).when(mCachedBluetoothDevice).getName();
         doReturn(BLUETOOTH_MOCK_SUMMARY).when(mCachedBluetoothDevice).getConnectionSummary();
         doReturn(BLUETOOTH_MOCK_ADDRESS).when(mCachedBluetoothDevice).getAddress();
diff --git a/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorSliceTest.java b/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorSliceTest.java
index 7097889..cc4a870 100644
--- a/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorSliceTest.java
+++ b/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorSliceTest.java
@@ -26,11 +26,9 @@
 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.graphics.drawable.Drawable;
 import android.media.AudioManager;
 import android.media.session.MediaController;
 import android.media.session.MediaSession;
@@ -46,14 +44,12 @@
 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.LocalMediaManager;
+import com.android.settingslib.media.MediaDevice;
 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;
@@ -73,31 +69,28 @@
         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_DEVICE_1_NAME = "test_device_1_name";
+    private static final String TEST_DEVICE_2_NAME = "test_device_2_name";
     private static final String TEST_PACKAGE_NAME = "com.test";
 
     private static MediaOutputIndicatorWorker sMediaOutputIndicatorWorker;
 
-    @Mock
-    private A2dpProfile mA2dpProfile;
-    @Mock
-    private HearingAidProfile mHearingAidProfile;
+    private final List<MediaDevice> mDevices = new ArrayList<>();
+
     @Mock
     private LocalBluetoothManager mLocalBluetoothManager;
     @Mock
-    private LocalBluetoothProfileManager mLocalBluetoothProfileManager;
-    @Mock
     private MediaController mMediaController;
+    @Mock
+    private LocalMediaManager mLocalMediaManager;
+    @Mock
+    private MediaDevice mDevice1;
+    @Mock
+    private MediaDevice mDevice2;
+    @Mock
+    private Drawable mTestDrawable;
 
-    private BluetoothAdapter mBluetoothAdapter;
-    private BluetoothDevice mA2dpDevice;
-    private BluetoothDevice mHapDevice;
-    private BluetoothManager mBluetoothManager;
     private Context mContext;
-    private List<BluetoothDevice> mDevicesList;
     private MediaOutputIndicatorSlice mMediaOutputIndicatorSlice;
     private AudioManager mAudioManager;
     private MediaSession.Token mToken;
@@ -107,7 +100,6 @@
         MockitoAnnotations.initMocks(this);
         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(Process.myUid(), null);
@@ -115,109 +107,86 @@
         SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
         // Setup Bluetooth environment
         ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager;
-        mBluetoothManager = new BluetoothManager(mContext);
-        mBluetoothAdapter = mBluetoothManager.getAdapter();
-        when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
-        when(mLocalBluetoothProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile);
-        when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile);
-
-        // Setup A2dp device
-        mA2dpDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_A2DP_DEVICE_ADDRESS));
-        when(mA2dpDevice.getName()).thenReturn(TEST_A2DP_DEVICE_NAME);
-        when(mA2dpDevice.isConnected()).thenReturn(true);
-        // Setup HearingAid device
-        mHapDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_HAP_DEVICE_ADDRESS));
-        when(mHapDevice.getName()).thenReturn(TEST_HAP_DEVICE_NAME);
-        when(mHapDevice.isConnected()).thenReturn(true);
+        // Setup mock devices
+        when(mDevice1.getName()).thenReturn(TEST_DEVICE_1_NAME);
+        when(mDevice1.getIcon()).thenReturn(mTestDrawable);
+        when(mDevice1.getMaxVolume()).thenReturn(100);
+        when(mDevice1.isConnected()).thenReturn(true);
+        when(mDevice2.getName()).thenReturn(TEST_DEVICE_2_NAME);
+        when(mDevice2.getIcon()).thenReturn(mTestDrawable);
+        when(mDevice2.getMaxVolume()).thenReturn(100);
+        when(mDevice2.isConnected()).thenReturn(false);
 
         mMediaOutputIndicatorSlice = new MediaOutputIndicatorSlice(mContext);
-        mDevicesList = new ArrayList<>();
+    }
+
+    @Test
+    public void getSlice_withConnectedDevice_verifyMetadata() {
+        mDevices.add(mDevice1);
+        mDevices.add(mDevice2);
+        when(sMediaOutputIndicatorWorker.getMediaDevices()).thenReturn(mDevices);
+        doReturn(mDevice1).when(sMediaOutputIndicatorWorker).getCurrentConnectedMediaDevice();
+        mAudioManager.setMode(AudioManager.MODE_NORMAL);
+
+        final Slice mediaSlice = mMediaOutputIndicatorSlice.getSlice();
+        final SliceMetadata metadata = SliceMetadata.from(mContext, mediaSlice);
+
+        assertThat(metadata.getTitle()).isEqualTo(mContext.getText(R.string.media_output_title));
+        assertThat(metadata.getSubtitle()).isEqualTo(TEST_DEVICE_1_NAME);
+        assertThat(metadata.isErrorSlice()).isFalse();
     }
 
     @Test
     public void getSlice_noConnectedDevice_returnErrorSlice() {
-        mDevicesList.clear();
-        when(mA2dpProfile.getConnectedDevices()).thenReturn(mDevicesList);
+        mDevices.clear();
+        when(sMediaOutputIndicatorWorker.getMediaDevices()).thenReturn(mDevices);
+        mAudioManager.setMode(AudioManager.MODE_NORMAL);
 
         final Slice mediaSlice = mMediaOutputIndicatorSlice.getSlice();
         final SliceMetadata metadata = SliceMetadata.from(mContext, mediaSlice);
+
         assertThat(metadata.isErrorSlice()).isTrue();
     }
 
     @Test
-    public void getSlice_noActiveDevice_verifyDefaultName() {
-        mDevicesList.add(mA2dpDevice);
-        when(mA2dpProfile.getConnectedDevices()).thenReturn(mDevicesList);
-        when(mA2dpProfile.getActiveDevice()).thenReturn(null);
-
-        // Verify slice title and subtitle
-        final Slice mediaSlice = mMediaOutputIndicatorSlice.getSlice();
-        final SliceMetadata metadata = SliceMetadata.from(mContext, mediaSlice);
-        assertThat(metadata.getTitle()).isEqualTo(mContext.getText(R.string.media_output_title));
-        assertThat(metadata.getSubtitle()).isEqualTo(mContext.getText(
-                R.string.media_output_default_summary));
-        assertThat(metadata.isErrorSlice()).isFalse();
-    }
-
-    @Test
-    @Ignore
-    public void getSlice_A2dpDeviceActive_verifyName() {
-        mDevicesList.add(mA2dpDevice);
-        when(mA2dpProfile.getConnectedDevices()).thenReturn(mDevicesList);
-        when(mA2dpProfile.getActiveDevice()).thenReturn(mA2dpDevice);
-
-        final Slice mediaSlice = mMediaOutputIndicatorSlice.getSlice();
-        final SliceMetadata metadata = SliceMetadata.from(mContext, mediaSlice);
-        assertThat(metadata.getTitle()).isEqualTo(mContext.getText(R.string.media_output_title));
-        assertThat(metadata.getSubtitle()).isEqualTo(TEST_A2DP_DEVICE_NAME);
-        assertThat(metadata.isErrorSlice()).isFalse();
-    }
-
-    @Test
-    @Ignore
-    public void getSlice_HADeviceActive_verifyName() {
-        mDevicesList.add(mHapDevice);
-        when(mHearingAidProfile.getConnectedDevices()).thenReturn(mDevicesList);
-        when(mHearingAidProfile.getActiveDevices()).thenReturn(mDevicesList);
-
-        // Verify slice title and subtitle
-        final Slice mediaSlice = mMediaOutputIndicatorSlice.getSlice();
-        final SliceMetadata metadata = SliceMetadata.from(mContext, mediaSlice);
-        assertThat(metadata.getTitle()).isEqualTo(mContext.getText(R.string.media_output_title));
-        assertThat(metadata.getSubtitle()).isEqualTo(TEST_HAP_DEVICE_NAME);
-        assertThat(metadata.isErrorSlice()).isFalse();
-    }
-
-    @Test
     public void getSlice_audioModeIsInCommunication_returnErrorSlice() {
-        mDevicesList.add(mA2dpDevice);
-        when(mA2dpProfile.getConnectedDevices()).thenReturn(mDevicesList);
+        mDevices.add(mDevice1);
+        mDevices.add(mDevice2);
+        when(sMediaOutputIndicatorWorker.getMediaDevices()).thenReturn(mDevices);
+        doReturn(mDevice1).when(sMediaOutputIndicatorWorker).getCurrentConnectedMediaDevice();
         mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
 
         final Slice mediaSlice = mMediaOutputIndicatorSlice.getSlice();
         final SliceMetadata metadata = SliceMetadata.from(mContext, mediaSlice);
+
         assertThat(metadata.isErrorSlice()).isTrue();
     }
 
     @Test
     public void getSlice_audioModeIsRingtone_returnErrorSlice() {
-        mDevicesList.add(mA2dpDevice);
-        when(mA2dpProfile.getConnectedDevices()).thenReturn(mDevicesList);
+        mDevices.add(mDevice1);
+        mDevices.add(mDevice2);
+        when(sMediaOutputIndicatorWorker.getMediaDevices()).thenReturn(mDevices);
+        doReturn(mDevice1).when(sMediaOutputIndicatorWorker).getCurrentConnectedMediaDevice();
         mAudioManager.setMode(AudioManager.MODE_RINGTONE);
 
         final Slice mediaSlice = mMediaOutputIndicatorSlice.getSlice();
         final SliceMetadata metadata = SliceMetadata.from(mContext, mediaSlice);
+
         assertThat(metadata.isErrorSlice()).isTrue();
     }
 
     @Test
     public void getSlice_audioModeIsInCall_returnErrorSlice() {
-        mDevicesList.add(mA2dpDevice);
-        when(mA2dpProfile.getConnectedDevices()).thenReturn(mDevicesList);
+        mDevices.add(mDevice1);
+        mDevices.add(mDevice2);
+        when(sMediaOutputIndicatorWorker.getMediaDevices()).thenReturn(mDevices);
+        doReturn(mDevice1).when(sMediaOutputIndicatorWorker).getCurrentConnectedMediaDevice();
         mAudioManager.setMode(AudioManager.MODE_IN_CALL);
 
         final Slice mediaSlice = mMediaOutputIndicatorSlice.getSlice();
         final SliceMetadata metadata = SliceMetadata.from(mContext, mediaSlice);
+
         assertThat(metadata.isErrorSlice()).isTrue();
     }
 
diff --git a/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorWorkerTest.java b/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorWorkerTest.java
index b6231a3..d96541d 100644
--- a/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorWorkerTest.java
+++ b/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorWorkerTest.java
@@ -22,6 +22,7 @@
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
@@ -38,9 +39,11 @@
 import android.media.session.PlaybackState;
 import android.net.Uri;
 
+import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
 import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
 import com.android.settingslib.bluetooth.BluetoothEventManager;
 import com.android.settingslib.bluetooth.LocalBluetoothManager;
+import com.android.settingslib.media.LocalMediaManager;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -56,7 +59,7 @@
 import java.util.List;
 
 @RunWith(RobolectricTestRunner.class)
-@Config(shadows = {ShadowBluetoothUtils.class})
+@Config(shadows = {ShadowBluetoothAdapter.class, ShadowBluetoothUtils.class})
 public class MediaOutputIndicatorWorkerTest {
     private static final Uri URI = Uri.parse("content://com.android.settings.slices/test");
 
@@ -68,6 +71,8 @@
     private MediaSessionManager mMediaSessionManager;
     @Mock
     private MediaController mMediaController;
+    @Mock
+    private LocalMediaManager mLocalMediaManager;
 
     private Context mContext;
     private MediaOutputIndicatorWorker mMediaOutputIndicatorWorker;
@@ -95,29 +100,40 @@
 
     @Test
     public void onSlicePinned_registerCallback() {
+        mMediaOutputIndicatorWorker.mLocalMediaManager = mLocalMediaManager;
         mMediaOutputIndicatorWorker.onSlicePinned();
+
         verify(mBluetoothEventManager).registerCallback(mMediaOutputIndicatorWorker);
         verify(mContext).registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class));
+        verify(mLocalMediaManager).registerCallback(mMediaOutputIndicatorWorker);
+        verify(mLocalMediaManager).startScan();
     }
 
     @Test
     public void onSliceUnpinned_unRegisterCallback() {
+        mMediaOutputIndicatorWorker.mLocalMediaManager = mLocalMediaManager;
         mMediaOutputIndicatorWorker.onSlicePinned();
         mMediaOutputIndicatorWorker.onSliceUnpinned();
+
         verify(mBluetoothEventManager).unregisterCallback(mMediaOutputIndicatorWorker);
         verify(mContext).unregisterReceiver(any(BroadcastReceiver.class));
+        verify(mLocalMediaManager).unregisterCallback(mMediaOutputIndicatorWorker);
+        verify(mLocalMediaManager).stopScan();
     }
 
     @Test
     public void onReceive_shouldNotifyChange() {
         mMediaOutputIndicatorWorker.onSlicePinned();
+        // onSlicePinned will registerCallback() and get first callback. Callback triggers this at
+        // the first time.
+        verify(mResolver, times(1)).notifyChange(URI, null);
 
         final Intent intent = new Intent(AudioManager.STREAM_DEVICES_CHANGED_ACTION);
         for (BroadcastReceiver receiver : mShadowApplication.getReceiversForIntent(intent)) {
             receiver.onReceive(mContext, intent);
         }
-
-        verify(mResolver).notifyChange(URI, null);
+        // Intent receiver triggers notifyChange() again
+        verify(mResolver, times(2)).notifyChange(URI, null /* observer */);
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/widget/VideoPreferenceTest.java b/tests/robotests/src/com/android/settings/widget/VideoPreferenceTest.java
index 3439ca4..720ad20 100644
--- a/tests/robotests/src/com/android/settings/widget/VideoPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/widget/VideoPreferenceTest.java
@@ -32,6 +32,7 @@
 import android.view.TextureView;
 import android.view.View;
 import android.widget.ImageView;
+import android.widget.LinearLayout;
 
 import androidx.preference.PreferenceFragmentCompat;
 import androidx.preference.PreferenceViewHolder;
@@ -60,6 +61,9 @@
     private ImageView fakePreview;
     @Mock
     private ImageView fakePlayButton;
+    @Mock
+    private LinearLayout mAnimationView;
+
     private Context mContext;
     private VideoPreference mVideoPreference;
     private PreferenceViewHolder mPreferenceViewHolder;
@@ -73,6 +77,7 @@
                 new MediaAnimationController(mContext, R.raw.accessibility_screen_magnification));
         mVideoPreference = new VideoPreference(mContext, null /* attrs */);
         mVideoPreference.mAnimationController = mAnimationController;
+        mVideoPreference.mAnimationView = mAnimationView;
         when(mAnimationController.getVideoWidth()).thenReturn(VIDEO_WIDTH);
         when(mAnimationController.getVideoHeight()).thenReturn(VIDEO_HEIGHT);
 
@@ -157,6 +162,13 @@
         assertThat(vp2.mAnimationController instanceof VectorAnimationController).isTrue();
     }
 
+    @Test
+    public void setBackgroundColor_shouldBeCalled() {
+        mVideoPreference.setBackgroundColor(1111);
+
+        assertThat(mVideoPreference.mBackgroundResId).isEqualTo(1111);
+    }
+
     public static class TestFragment extends PreferenceFragmentCompat {
         @Override
         public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {