Merge "Refine fold setting" into main
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 06d5800..c64187f 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -4405,20 +4405,6 @@
         </service>
 
         <service
-            android:name=".development.qstile.DevelopmentTiles$WinscopeTrace"
-            android:label="@string/winscope_trace_quick_settings_title"
-            android:icon="@drawable/tile_icon_winscope_trace"
-            android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
-            android:exported="true"
-            android:enabled="false">
-            <intent-filter>
-                <action android:name="android.service.quicksettings.action.QS_TILE" />
-            </intent-filter>
-            <meta-data android:name="android.service.quicksettings.TOGGLEABLE_TILE"
-                       android:value="true"/>
-        </service>
-
-        <service
             android:name=".development.qstile.DevelopmentTiles$SensorsOff"
             android:label="@string/sensors_off_quick_settings_title"
             android:icon="@drawable/tile_icon_sensors_off"
diff --git a/res/drawable/tile_icon_winscope_trace.xml b/res/drawable/tile_icon_winscope_trace.xml
deleted file mode 100644
index 2563049..0000000
--- a/res/drawable/tile_icon_winscope_trace.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<!--
-    Copyright (C) 2018 The Android Open Source Project
-
-    Licensed under the Apache License, Version 2.0 (the "License");
-    you may not use this file except in compliance with the License.
-    You may obtain a copy of the License at
-
-         http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing, software
-    distributed under the License is distributed on an "AS IS" BASIS,
-    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-    See the License for the specific language governing permissions and
-    limitations under the License.
--->
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
-        android:width="24dp"
-        android:height="24dp"
-        android:viewportWidth="24.0"
-        android:viewportHeight="24.0"
-        android:tint="?android:attr/colorControlNormal">
-    <path
-        android:pathData="M17.115,1.535L9.984,1.535C9.38,1.535 8.887,2.029 8.887,2.632L8.887,5.923L7.241,5.923C6.638,5.923 6.144,6.417 6.144,7.021l0,5.486c0,0.603 0.494,1.097 1.097,1.097l7.131,0c0.603,0 1.097,-0.494 1.097,-1.097l0,-3.291l1.646,0c0.603,0 1.097,-0.494 1.097,-1.097L18.212,2.632C18.212,2.029 17.718,1.535 17.115,1.535ZM14.372,12.506L7.241,12.506l0,-4.388l7.131,0zM17.115,8.118L15.469,8.118L15.469,7.021C15.469,6.417 14.976,5.923 14.372,5.923L9.984,5.923L9.984,3.729l7.131,0z"
-        android:fillColor="#FFFFFFFF"/>
-    <path
-        android:pathData="m20.27,15.235c0,0.82 -0.671,1.491 -1.491,1.491 -0.134,0 -0.261,-0.015 -0.38,-0.052l-2.654,2.646C15.782,19.439 15.797,19.573 15.797,19.708c0,0.82 -0.671,1.491 -1.491,1.491 -0.82,0 -1.491,-0.671 -1.491,-1.491 0,-0.134 0.015,-0.268 0.052,-0.388L10.966,17.419C10.847,17.456 10.713,17.471 10.579,17.471 10.444,17.471 10.31,17.456 10.191,17.419L6.799,20.818C6.836,20.938 6.851,21.064 6.851,21.199 6.851,22.019 6.18,22.689 5.36,22.689 4.54,22.689 3.869,22.019 3.869,21.199c0,-0.82 0.671,-1.491 1.491,-1.491 0.134,0 0.261,0.015 0.38,0.052L9.14,16.368C9.103,16.249 9.088,16.114 9.088,15.98 9.088,15.16 9.759,14.489 10.579,14.489c0.82,0 1.491,0.671 1.491,1.491 0,0.134 -0.015,0.268 -0.052,0.388l1.901,1.901C14.038,18.232 14.172,18.217 14.306,18.217c0.134,0 0.268,0.015 0.388,0.052L17.34,15.615C17.303,15.496 17.288,15.369 17.288,15.235c0,-0.82 0.671,-1.491 1.491,-1.491 0.82,0 1.491,0.671 1.491,1.491z"
-        android:fillColor="#FFFFFFFF"/>
-</vector>
-
diff --git a/res/layout/wifi_network_config.xml b/res/layout/wifi_network_config.xml
index 6fe39bf..77afedc 100644
--- a/res/layout/wifi_network_config.xml
+++ b/res/layout/wifi_network_config.xml
@@ -413,7 +413,8 @@
         <LinearLayout android:id="@+id/metered_settings_fields"
                       android:layout_width="match_parent"
                       android:layout_height="wrap_content"
-                      style="@style/wifi_item">
+                      style="@style/wifi_item"
+                      android:visibility="gone">
 
             <TextView android:id="@+id/metered_settings_title"
                       android:layout_width="wrap_content"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index f1ce36a..9d106f4 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -268,6 +268,8 @@
 
     <!-- Title to see all the previous connected devices [CHAR LIMIT=50] -->
     <string name="previous_connected_see_all">See all</string>
+    <!-- Title to see all fast pair devices [CHAR LIMIT=none]-->
+    <string name="connected_device_fast_pair_device_see_all">See all</string>
 
     <!-- Title for stylus device details page [CHAR LIMIT=50] -->
     <string name="stylus_device_details_title">Stylus</string>
@@ -9975,9 +9977,6 @@
     <!-- [CHAR LIMIT=NONE] Setting summary explaining the disablement of the automatic adb authorization timeout. -->
     <string name="adb_authorization_timeout_summary">Disable automatic revocation of adb authorizations for systems that have not reconnected within the default (7 days) or user-configured (minimum 1 day) amount of time.</string>
 
-    <!-- [CHAR LIMIT=25] Title of developer tile to toggle winscope trace -->
-    <string name="winscope_trace_quick_settings_title">Winscope Trace</string>
-
     <!-- [CHAR LIMIT=25] Title of developer tile to toggle sensors -->
     <string name="sensors_off_quick_settings_title">Sensors Off</string>
 
diff --git a/res/xml/connected_devices.xml b/res/xml/connected_devices.xml
index a0e0a1f..5d7e0a8 100644
--- a/res/xml/connected_devices.xml
+++ b/res/xml/connected_devices.xml
@@ -61,6 +61,22 @@
             android:fragment="com.android.settings.connecteddevice.PreviouslyConnectedDeviceDashboardFragment"/>
     </PreferenceCategory>
 
+    <PreferenceCategory
+        android:key="fast_pair_devices"
+        android:title="TODO(296507968): Placeholder"
+        settings:controller=
+            "com.android.settings.connecteddevice.fastpair.FastPairDevicePreferenceController">
+
+        <Preference
+            android:key="fast_pair_devices_see_all"
+            android:title="@string/connected_device_fast_pair_device_see_all"
+            android:icon="@drawable/ic_chevron_right_24dp"
+            android:order="10"
+            settings:searchable="false"
+            android:fragment=
+                "com.android.settings.connecteddevice.fastpair.FastPairDeviceDashboardFragment"/>
+    </PreferenceCategory>
+
     <Preference
         android:key="connection_preferences"
         android:title="@string/connected_device_connections_title"
diff --git a/src/com/android/settings/accessibility/AccessibilityHearingAidPreferenceController.java b/src/com/android/settings/accessibility/AccessibilityHearingAidPreferenceController.java
index e4611fe..3aad141 100644
--- a/src/com/android/settings/accessibility/AccessibilityHearingAidPreferenceController.java
+++ b/src/com/android/settings/accessibility/AccessibilityHearingAidPreferenceController.java
@@ -184,7 +184,8 @@
         }
 
         if (bluetoothProfile == BluetoothProfile.HEARING_AID) {
-            HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, activeDevice);
+            HearingAidUtils.launchHearingAidPairingDialog(
+                    mFragmentManager, activeDevice, getMetricsCategory());
         }
     }
 
diff --git a/src/com/android/settings/accessibility/AvailableHearingDevicePreferenceController.java b/src/com/android/settings/accessibility/AvailableHearingDevicePreferenceController.java
index 076432c..c8692a1 100644
--- a/src/com/android/settings/accessibility/AvailableHearingDevicePreferenceController.java
+++ b/src/com/android/settings/accessibility/AvailableHearingDevicePreferenceController.java
@@ -103,7 +103,8 @@
         }
 
         if (bluetoothProfile == BluetoothProfile.HEARING_AID) {
-            HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, activeDevice);
+            HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, activeDevice,
+                    getMetricsCategory());
         }
     }
 }
diff --git a/src/com/android/settings/accessibility/HearingAidUtils.java b/src/com/android/settings/accessibility/HearingAidUtils.java
index 4315093..4734c55 100644
--- a/src/com/android/settings/accessibility/HearingAidUtils.java
+++ b/src/com/android/settings/accessibility/HearingAidUtils.java
@@ -38,9 +38,10 @@
      *
      * @param fragmentManager The {@link FragmentManager} used to show dialog fragment
      * @param device The {@link CachedBluetoothDevice} need to be hearing aid device
+     * @param launchPage The page id where the dialog is launched
      */
     public static void launchHearingAidPairingDialog(FragmentManager fragmentManager,
-            @NonNull CachedBluetoothDevice device) {
+            @NonNull CachedBluetoothDevice device, int launchPage) {
         // No need to show the pair another ear dialog if the device supports and enables CSIP.
         // CSIP will pair other devices in the same set automatically.
         if (isCsipSupportedAndEnabled(device)) {
@@ -49,18 +50,18 @@
         if (device.isConnectedAshaHearingAidDevice()
                 && device.getDeviceMode() == HearingAidInfo.DeviceMode.MODE_BINAURAL
                 && device.getSubDevice() == null) {
-            launchHearingAidPairingDialogInternal(fragmentManager, device);
+            launchHearingAidPairingDialogInternal(fragmentManager, device, launchPage);
         }
     }
 
     private static void launchHearingAidPairingDialogInternal(FragmentManager fragmentManager,
-            @NonNull CachedBluetoothDevice device) {
+            @NonNull CachedBluetoothDevice device, int launchPage) {
         if (device.getDeviceSide() == HearingAidInfo.DeviceSide.SIDE_INVALID) {
             Log.w(TAG, "Can not launch hearing aid pairing dialog for invalid side");
             return;
         }
-        HearingAidPairingDialogFragment.newInstance(device.getAddress()).show(fragmentManager,
-                HearingAidPairingDialogFragment.TAG);
+        HearingAidPairingDialogFragment.newInstance(device.getAddress(), launchPage)
+                .show(fragmentManager, HearingAidPairingDialogFragment.TAG);
     }
 
     private static boolean isCsipSupportedAndEnabled(@NonNull CachedBluetoothDevice device) {
diff --git a/src/com/android/settings/applications/appcompat/RadioWithImagePreference.java b/src/com/android/settings/applications/appcompat/RadioWithImagePreference.java
index 77cd86c..b47b679 100644
--- a/src/com/android/settings/applications/appcompat/RadioWithImagePreference.java
+++ b/src/com/android/settings/applications/appcompat/RadioWithImagePreference.java
@@ -127,7 +127,7 @@
     }
 
     private void init() {
-        setWidgetLayoutResource(com.android.settingslib.R.layout.preference_widget_radiobutton);
+        setWidgetLayoutResource(R.layout.preference_widget_radiobutton);
         setLayoutResource(R.layout.radio_with_image_preference);
         setIconSpaceReserved(false);
     }
diff --git a/src/com/android/settings/applications/appcompat/UserAspectRatioManager.java b/src/com/android/settings/applications/appcompat/UserAspectRatioManager.java
index 7c16ed6..6bc9658 100644
--- a/src/com/android/settings/applications/appcompat/UserAspectRatioManager.java
+++ b/src/com/android/settings/applications/appcompat/UserAspectRatioManager.java
@@ -51,10 +51,10 @@
             new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
 
     // TODO(b/288142656): Enable user aspect ratio settings by default
-    private static final boolean DEFAULT_VALUE_ENABLE_USER_ASPECT_RATIO_SETTINGS = false;
+    private static final boolean DEFAULT_VALUE_ENABLE_USER_ASPECT_RATIO_SETTINGS = true;
     @VisibleForTesting
     static final String KEY_ENABLE_USER_ASPECT_RATIO_SETTINGS =
-            "enable_app_compat_user_aspect_ratio_settings";
+            "enable_app_compat_aspect_ratio_user_settings";
     static final String KEY_ENABLE_USER_ASPECT_RATIO_FULLSCREEN =
             "enable_app_compat_user_aspect_ratio_fullscreen";
     private static final boolean DEFAULT_VALUE_ENABLE_USER_ASPECT_RATIO_FULLSCREEN = true;
diff --git a/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java b/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java
index dca005b..c38e340 100644
--- a/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java
+++ b/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java
@@ -167,6 +167,10 @@
     }
 
     private void registerBluetoothDevice() {
+        if (mBluetoothAdapter == null) {
+            Log.d(TAG, "No mBluetoothAdapter");
+            return;
+        }
         if (mBluetoothDevices == null) {
             mBluetoothDevices = new HashSet<>();
         }
@@ -180,23 +184,52 @@
             }
         });
         if (mBluetoothDevices.isEmpty()) {
-            Log.d(TAG, "No BT devcie to register.");
+            Log.d(TAG, "No BT device to register.");
             return;
         }
         mCachedDevice.registerCallback(this);
-        mBluetoothDevices.forEach(bd ->
-                mBluetoothAdapter.addOnMetadataChangedListener(bd,
-                        mContext.getMainExecutor(), mMetadataListener));
+        Set<BluetoothDevice> errorDevices = new HashSet<>();
+        mBluetoothDevices.forEach(bd -> {
+            try {
+                boolean isSuccess = mBluetoothAdapter.addOnMetadataChangedListener(bd,
+                        mContext.getMainExecutor(), mMetadataListener);
+                if (!isSuccess) {
+                    Log.e(TAG, bd.getAnonymizedAddress() + ": add into Listener failed");
+                    errorDevices.add(bd);
+                }
+            } catch (NullPointerException e) {
+                errorDevices.add(bd);
+                Log.e(TAG, bd.getAnonymizedAddress() + ":" + e.toString());
+            } catch (IllegalArgumentException e) {
+                errorDevices.add(bd);
+                Log.e(TAG, bd.getAnonymizedAddress() + ":" + e.toString());
+            }
+        });
+        for (BluetoothDevice errorDevice : errorDevices) {
+            mBluetoothDevices.remove(errorDevice);
+            Log.d(TAG, "mBluetoothDevices remove " + errorDevice.getAnonymizedAddress());
+        }
     }
 
     private void unRegisterBluetoothDevice() {
+        if (mBluetoothAdapter == null) {
+            Log.d(TAG, "No mBluetoothAdapter");
+            return;
+        }
         if (mBluetoothDevices == null || mBluetoothDevices.isEmpty()) {
-            Log.d(TAG, "No BT devcie to unregister.");
+            Log.d(TAG, "No BT device to unregister.");
             return;
         }
         mCachedDevice.unregisterCallback(this);
-        mBluetoothDevices.forEach(bd -> mBluetoothAdapter.removeOnMetadataChangedListener(bd,
-                mMetadataListener));
+        mBluetoothDevices.forEach(bd -> {
+            try {
+                mBluetoothAdapter.removeOnMetadataChangedListener(bd, mMetadataListener);
+            } catch (NullPointerException e) {
+                Log.e(TAG, bd.getAnonymizedAddress() + ":" + e.toString());
+            } catch (IllegalArgumentException e) {
+                Log.e(TAG, bd.getAnonymizedAddress() + ":" + e.toString());
+            }
+        });
         mBluetoothDevices.clear();
     }
 
diff --git a/src/com/android/settings/bluetooth/BluetoothDevicePreference.java b/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
index 014a02b..98d78f2 100644
--- a/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
+++ b/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
@@ -196,6 +196,10 @@
     }
 
     private void registerMetadataChangedListener() {
+        if (mBluetoothAdapter == null) {
+            Log.d(TAG, "No mBluetoothAdapter");
+            return;
+        }
         if (mBluetoothDevices == null) {
             mBluetoothDevices = new HashSet<>();
         }
@@ -210,18 +214,47 @@
             Log.d(TAG, "No BT device to register.");
             return;
         }
-        mBluetoothDevices.forEach(bd ->
-                mBluetoothAdapter.addOnMetadataChangedListener(bd,
-                        getContext().getMainExecutor(), mMetadataListener));
+        Set<BluetoothDevice> errorDevices = new HashSet<>();
+        mBluetoothDevices.forEach(bd -> {
+            try {
+                boolean isSuccess = mBluetoothAdapter.addOnMetadataChangedListener(bd,
+                        getContext().getMainExecutor(), mMetadataListener);
+                if (!isSuccess) {
+                    Log.e(TAG, bd.getAnonymizedAddress() + ": add into Listener failed");
+                    errorDevices.add(bd);
+                }
+            } catch (NullPointerException e) {
+                errorDevices.add(bd);
+                Log.e(TAG, bd.getAnonymizedAddress() + ":" + e.toString());
+            } catch (IllegalArgumentException e) {
+                errorDevices.add(bd);
+                Log.e(TAG, bd.getAnonymizedAddress() + ":" + e.toString());
+            }
+        });
+        for (BluetoothDevice errorDevice : errorDevices) {
+            mBluetoothDevices.remove(errorDevice);
+            Log.d(TAG, "mBluetoothDevices remove " + errorDevice.getAnonymizedAddress());
+        }
     }
 
     private void unregisterMetadataChangedListener() {
+        if (mBluetoothAdapter == null) {
+            Log.d(TAG, "No mBluetoothAdapter");
+            return;
+        }
         if (mBluetoothDevices == null || mBluetoothDevices.isEmpty()) {
             Log.d(TAG, "No BT device to unregister.");
             return;
         }
-        mBluetoothDevices.forEach(
-                bd -> mBluetoothAdapter.removeOnMetadataChangedListener(bd, mMetadataListener));
+        mBluetoothDevices.forEach(bd -> {
+            try {
+                mBluetoothAdapter.removeOnMetadataChangedListener(bd, mMetadataListener);
+            } catch (NullPointerException e) {
+                Log.e(TAG, bd.getAnonymizedAddress() + ":" + e.toString());
+            } catch (IllegalArgumentException e) {
+                Log.e(TAG, bd.getAnonymizedAddress() + ":" + e.toString());
+            }
+        });
         mBluetoothDevices.clear();
     }
 
diff --git a/src/com/android/settings/bluetooth/BluetoothFindBroadcastsFragment.java b/src/com/android/settings/bluetooth/BluetoothFindBroadcastsFragment.java
index f9d083d..cffd68c 100644
--- a/src/com/android/settings/bluetooth/BluetoothFindBroadcastsFragment.java
+++ b/src/com/android/settings/bluetooth/BluetoothFindBroadcastsFragment.java
@@ -30,10 +30,16 @@
 import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
+import android.text.Editable;
+import android.text.InputFilter;
+import android.text.InputType;
+import android.text.Spanned;
+import android.text.TextWatcher;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.WindowManager;
+import android.widget.Button;
 import android.widget.EditText;
 import android.widget.TextView;
 import android.widget.Toast;
@@ -474,9 +480,64 @@
                 .create();
 
         alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
+        addTextWatcher(alertDialog, editText);
         alertDialog.show();
+        updateBtnState(alertDialog, false);
     }
 
+    private void addTextWatcher(AlertDialog alertDialog, EditText editText) {
+        if (alertDialog == null || editText == null) {
+            return;
+        }
+        final InputFilter[] filter = new InputFilter[] {mInputFilter};
+        editText.setFilters(filter);
+        editText.setInputType(InputType.TYPE_CLASS_TEXT
+                | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
+        TextWatcher bCodeTextWatcher = new TextWatcher() {
+            @Override
+            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+                // Do nothing
+            }
+
+            @Override
+            public void onTextChanged(CharSequence s, int start, int before, int count) {
+                // Do nothing
+            }
+
+            @Override
+            public void afterTextChanged(Editable s) {
+                boolean breakBroadcastCodeRuleTextLengthLessThanMin =
+                        s.length() > 0 && s.toString().getBytes().length < 4;
+                boolean breakBroadcastCodeRuleTextLengthMoreThanMax =
+                        s.toString().getBytes().length > 16;
+                boolean breakRule = breakBroadcastCodeRuleTextLengthLessThanMin
+                        || breakBroadcastCodeRuleTextLengthMoreThanMax;
+                updateBtnState(alertDialog, !breakRule);
+            }
+        };
+        editText.addTextChangedListener(bCodeTextWatcher);
+    }
+
+    private void updateBtnState(AlertDialog alertDialog, boolean isEnable) {
+        Button positiveBtn = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
+        if (positiveBtn != null) {
+            positiveBtn.setEnabled(isEnable ? true : false);
+        }
+    }
+
+    private InputFilter mInputFilter = new InputFilter() {
+        @Override
+        public CharSequence filter(CharSequence source, int start, int end,
+                Spanned dest, int dstart, int dend) {
+            byte[] bytes = source.toString().getBytes(StandardCharsets.UTF_8);
+            if (bytes.length == source.length()) {
+                return source;
+            } else {
+                return "";
+            }
+        }
+    };
+
     private void handleSearchStarted() {
         cacheRemoveAllPrefs(mBroadcastSourceListCategory);
         addConnectedSourcePreference();
diff --git a/src/com/android/settings/bluetooth/HearingAidPairingDialogFragment.java b/src/com/android/settings/bluetooth/HearingAidPairingDialogFragment.java
index acbfd92..12cbd58 100644
--- a/src/com/android/settings/bluetooth/HearingAidPairingDialogFragment.java
+++ b/src/com/android/settings/bluetooth/HearingAidPairingDialogFragment.java
@@ -28,6 +28,7 @@
 import androidx.appcompat.app.AlertDialog;
 
 import com.android.settings.R;
+import com.android.settings.accessibility.HearingDevicePairingDetail;
 import com.android.settings.core.SubSettingLauncher;
 import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
 import com.android.settingslib.bluetooth.CachedBluetoothDevice;
@@ -41,6 +42,8 @@
         CachedBluetoothDevice.Callback {
     public static final String TAG = "HearingAidPairingDialogFragment";
     private static final String KEY_DEVICE_ADDRESS = "device_address";
+    private static final String KEY_LAUNCH_PAGE = "launch_page";
+
     private LocalBluetoothManager mLocalBluetoothManager;
     private CachedBluetoothDevice mDevice;
 
@@ -50,11 +53,17 @@
      *
      * @param deviceAddress The remote Bluetooth device address, that needs to be a hearing aid
      *                      device.
+     * @param launchPage The id of the page where this dialog launch from. Should be one of
+     *                   {@link SettingsEnums#ACCESSIBILITY},
+     *                   {@link SettingsEnums#ACCESSIBILITY_HEARING_AID_SETTINGS}, or
+     *                   {@link SettingsEnums#SETTINGS_CONNECTED_DEVICE_CATEGORY}
      * @return a DialogFragment
      */
-    public static HearingAidPairingDialogFragment newInstance(String deviceAddress) {
+    public static HearingAidPairingDialogFragment newInstance(String deviceAddress,
+            int launchPage) {
         Bundle args = new Bundle(1);
         args.putString(KEY_DEVICE_ADDRESS, deviceAddress);
+        args.putInt(KEY_LAUNCH_PAGE, launchPage);
         final HearingAidPairingDialogFragment fragment = new HearingAidPairingDialogFragment();
         fragment.setArguments(args);
         return fragment;
@@ -111,8 +120,14 @@
     }
 
     private void positiveButtonListener() {
+        final int launchPage = getArguments().getInt(KEY_LAUNCH_PAGE);
+        final boolean launchFromA11y = (launchPage == SettingsEnums.ACCESSIBILITY)
+                || (launchPage == SettingsEnums.ACCESSIBILITY_HEARING_AID_SETTINGS);
+        final String destination = launchFromA11y
+                ? HearingDevicePairingDetail.class.getName()
+                : BluetoothPairingDetail.class.getName();
         new SubSettingLauncher(getActivity())
-                .setDestination(BluetoothPairingDetail.class.getName())
+                .setDestination(destination)
                 .setSourceMetricsCategory(getMetricsCategory())
                 .launch();
     }
diff --git a/src/com/android/settings/connecteddevice/AvailableMediaDeviceGroupController.java b/src/com/android/settings/connecteddevice/AvailableMediaDeviceGroupController.java
index a340015..7eabf01 100644
--- a/src/com/android/settings/connecteddevice/AvailableMediaDeviceGroupController.java
+++ b/src/com/android/settings/connecteddevice/AvailableMediaDeviceGroupController.java
@@ -152,7 +152,8 @@
         }
 
         if (bluetoothProfile == BluetoothProfile.HEARING_AID) {
-            HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, activeDevice);
+            HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, activeDevice,
+                    getMetricsCategory());
         }
     }
 
diff --git a/src/com/android/settings/connecteddevice/fastpair/FastPairDevicePreferenceController.java b/src/com/android/settings/connecteddevice/fastpair/FastPairDevicePreferenceController.java
new file mode 100644
index 0000000..47b2dae
--- /dev/null
+++ b/src/com/android/settings/connecteddevice/fastpair/FastPairDevicePreferenceController.java
@@ -0,0 +1,201 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.connecteddevice.fastpair;
+
+import android.bluetooth.BluetoothAdapter;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.PackageManager;
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.VisibleForTesting;
+import androidx.lifecycle.DefaultLifecycleObserver;
+import androidx.lifecycle.LifecycleOwner;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceGroup;
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.connecteddevice.DevicePreferenceCallback;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.flags.Flags;
+import com.android.settings.overlay.FeatureFactory;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Controller to maintain the {@link PreferenceGroup} for all Fast Pair devices and a "See all"
+ * Preference. It uses {@link DevicePreferenceCallback} to add/remove {@link Preference}.
+ */
+public class FastPairDevicePreferenceController extends BasePreferenceController
+        implements DefaultLifecycleObserver, DevicePreferenceCallback {
+
+    private static final String TAG = "FastPairDevicePrefCtr";
+    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
+
+    private static final int MAX_DEVICE_NUM = 3;
+    private static final String KEY_SEE_ALL = "fast_pair_devices_see_all";
+
+    private final List<Preference> mPreferenceList = new ArrayList<>();
+
+    private PreferenceGroup mPreferenceGroup;
+    private FastPairDeviceUpdater mFastPairDeviceUpdater;
+    private BluetoothAdapter mBluetoothAdapter;
+
+    @VisibleForTesting Preference mSeeAllPreference;
+    @VisibleForTesting IntentFilter mIntentFilter;
+
+    @VisibleForTesting
+    BroadcastReceiver mReceiver =
+            new BroadcastReceiver() {
+                @Override
+                public void onReceive(Context context, Intent intent) {
+                    updatePreferenceVisibility();
+                }
+            };
+
+    public FastPairDevicePreferenceController(Context context, String preferenceKey) {
+        super(context, preferenceKey);
+
+        if (Flags.enableSubsequentPairSettingsIntegration()) {
+            FastPairFeatureProvider fastPairFeatureProvider =
+                    FeatureFactory.getFeatureFactory().getFastPairFeatureProvider();
+            mFastPairDeviceUpdater =
+                    fastPairFeatureProvider.getFastPairDeviceUpdater(context, this);
+        } else {
+            mFastPairDeviceUpdater = null;
+        }
+        mIntentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
+        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+    }
+
+    @Override
+    public void onStart(@NonNull LifecycleOwner owner) {
+        if (mFastPairDeviceUpdater != null) {
+            mFastPairDeviceUpdater.registerCallback();
+        }
+        mContext.registerReceiver(mReceiver, mIntentFilter, Context.RECEIVER_EXPORTED_UNAUDITED);
+    }
+
+    @Override
+    public void onStop(@NonNull LifecycleOwner owner) {
+        if (mFastPairDeviceUpdater != null) {
+            mFastPairDeviceUpdater.unregisterCallback();
+        }
+        mContext.unregisterReceiver(mReceiver);
+    }
+
+    @Override
+    public void displayPreference(PreferenceScreen screen) {
+        super.displayPreference(screen);
+        mPreferenceGroup = screen.findPreference(getPreferenceKey());
+        mSeeAllPreference = mPreferenceGroup.findPreference(KEY_SEE_ALL);
+        updatePreferenceVisibility();
+
+        if (isAvailable()) {
+            final Context context = screen.getContext();
+            mFastPairDeviceUpdater.setPreferenceContext(context);
+            mFastPairDeviceUpdater.forceUpdate();
+        }
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        return (mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)
+                        && mFastPairDeviceUpdater != null)
+                ? AVAILABLE
+                : UNSUPPORTED_ON_DEVICE;
+    }
+
+    @Override
+    public void onDeviceAdded(Preference preference) {
+        if (preference == null) {
+            if (DEBUG) {
+                Log.d(TAG, "onDeviceAdd receives null preference. Ignore.");
+            }
+            return;
+        }
+
+        // Keep showing the latest MAX_DEVICE_NUM devices.
+        // The preference for the latest device has top preference order.
+        int idx = Collections.binarySearch(mPreferenceList, preference);
+        // Binary search returns the index of the search key if it is contained in the list;
+        // otherwise, (-(insertion point) - 1).
+        // The insertion point is defined as the point at which the key would be inserted into the
+        // list: the index of the first element greater than the key, or list.size() if all elements
+        // in the list are less than the specified key.
+        if (idx > 0) {
+            if (DEBUG) {
+                Log.d(TAG, "onDeviceAdd receives duplicate preference. Ignore.");
+            }
+            return;
+        }
+        idx = -1 * (idx + 1);
+        mPreferenceList.add(idx, preference);
+        if (idx < MAX_DEVICE_NUM) {
+            if (mPreferenceList.size() > MAX_DEVICE_NUM) {
+                mPreferenceGroup.removePreference(mPreferenceList.get(MAX_DEVICE_NUM));
+            }
+            mPreferenceGroup.addPreference(preference);
+        }
+        updatePreferenceVisibility();
+    }
+
+    @Override
+    public void onDeviceRemoved(Preference preference) {
+        if (preference == null) {
+            if (DEBUG) {
+                Log.d(TAG, "onDeviceRemoved receives null preference. Ignore.");
+            }
+            return;
+        }
+
+        // Keep showing the latest MAX_DEVICE_NUM devices.
+        // The preference for the latest device has top preference order.
+        final int idx = mPreferenceList.indexOf(preference);
+        mPreferenceList.remove(preference);
+        if (idx < MAX_DEVICE_NUM) {
+            mPreferenceGroup.removePreference(preference);
+            if (mPreferenceList.size() >= MAX_DEVICE_NUM) {
+                mPreferenceGroup.addPreference(mPreferenceList.get(MAX_DEVICE_NUM - 1));
+            }
+        }
+        updatePreferenceVisibility();
+    }
+
+    @VisibleForTesting
+    void setPreferenceGroup(PreferenceGroup preferenceGroup) {
+        mPreferenceGroup = preferenceGroup;
+    }
+
+    @VisibleForTesting
+    void updatePreferenceVisibility() {
+        if (mBluetoothAdapter != null
+                && mBluetoothAdapter.isEnabled()
+                && mPreferenceList.size() > 0) {
+            mPreferenceGroup.setVisible(true);
+            mSeeAllPreference.setVisible(mPreferenceList.size() > MAX_DEVICE_NUM);
+        } else {
+            mPreferenceGroup.setVisible(false);
+            mSeeAllPreference.setVisible(false);
+        }
+    }
+}
diff --git a/src/com/android/settings/core/SettingsUIDeviceConfig.java b/src/com/android/settings/core/SettingsUIDeviceConfig.java
index 404b0b4..4d96385 100644
--- a/src/com/android/settings/core/SettingsUIDeviceConfig.java
+++ b/src/com/android/settings/core/SettingsUIDeviceConfig.java
@@ -47,4 +47,9 @@
      */
     public static final String BT_LE_AUDIO_DEVICE_DETAIL_ENABLED =
             "bt_le_audio_device_detail_enabled";
+    /**
+     * {@code true} if long press home button to search is enabled.
+     */
+    public static final String LONG_PRESS_HOME_BUTTON_TO_SEARCH =
+            "long_press_home_button_to_search";
 }
diff --git a/src/com/android/settings/development/qstile/DevelopmentTiles.java b/src/com/android/settings/development/qstile/DevelopmentTiles.java
index a5bbd4a..cf0d4d1 100644
--- a/src/com/android/settings/development/qstile/DevelopmentTiles.java
+++ b/src/com/android/settings/development/qstile/DevelopmentTiles.java
@@ -29,9 +29,7 @@
 import android.hardware.SensorPrivacyManager;
 import android.net.Uri;
 import android.os.Handler;
-import android.os.IBinder;
 import android.os.Looper;
-import android.os.Parcel;
 import android.os.RemoteException;
 import android.os.ServiceManager;
 import android.os.SystemProperties;
@@ -45,10 +43,7 @@
 import android.view.WindowManagerGlobal;
 import android.widget.Toast;
 
-import androidx.annotation.VisibleForTesting;
-
 import com.android.internal.app.LocalePicker;
-import com.android.internal.inputmethod.ImeTracing;
 import com.android.internal.statusbar.IStatusBarService;
 import com.android.settings.development.WirelessDebuggingPreferenceController;
 import com.android.settings.overlay.FeatureFactory;
@@ -204,173 +199,6 @@
     }
 
     /**
-     * Tile to toggle Winscope trace which consists of Window and Layer traces.
-     */
-    public static class WinscopeTrace extends DevelopmentTiles {
-        @VisibleForTesting
-        static final int SURFACE_FLINGER_LAYER_TRACE_CONTROL_CODE = 1025;
-        @VisibleForTesting
-        static final int SURFACE_FLINGER_LAYER_TRACE_STATUS_CODE = 1026;
-        private static final String VIEW_CAPTURE_ENABLED = "view_capture_enabled";
-        private IBinder mSurfaceFlinger;
-        private IWindowManager mWindowManager;
-        private ImeTracing mImeTracing;
-        private Toast mToast;
-
-        @Override
-        public void onCreate() {
-            super.onCreate();
-            mWindowManager = WindowManagerGlobal.getWindowManagerService();
-            mSurfaceFlinger = ServiceManager.getService("SurfaceFlinger");
-            mImeTracing = ImeTracing.getInstance();
-            Context context = getApplicationContext();
-            CharSequence text = "Trace files written to /data/misc/wmtrace";
-            mToast = Toast.makeText(context, text, Toast.LENGTH_LONG);
-        }
-
-        private boolean isWindowTraceEnabled() {
-            try {
-                return mWindowManager.isWindowTraceEnabled();
-            } catch (RemoteException e) {
-                Log.e(TAG,
-                        "Could not get window trace status, defaulting to false." + e.toString());
-            }
-            return false;
-        }
-
-        private boolean isLayerTraceEnabled() {
-            boolean layerTraceEnabled = false;
-            Parcel reply = null;
-            Parcel data = null;
-            try {
-                if (mSurfaceFlinger != null) {
-                    reply = Parcel.obtain();
-                    data = Parcel.obtain();
-                    data.writeInterfaceToken("android.ui.ISurfaceComposer");
-                    mSurfaceFlinger.transact(SURFACE_FLINGER_LAYER_TRACE_STATUS_CODE,
-                            data, reply, 0 /* flags */);
-                    layerTraceEnabled = reply.readBoolean();
-                }
-            } catch (RemoteException e) {
-                Log.e(TAG, "Could not get layer trace status, defaulting to false." + e.toString());
-            } finally {
-                if (data != null) {
-                    data.recycle();
-                    reply.recycle();
-                }
-            }
-            return layerTraceEnabled;
-        }
-
-        private boolean isSystemUiTracingEnabled() {
-            try {
-                final IStatusBarService statusBarService = IStatusBarService.Stub.asInterface(
-                        ServiceManager.checkService(Context.STATUS_BAR_SERVICE));
-                if (statusBarService != null) {
-                    return statusBarService.isTracing();
-                }
-            } catch (RemoteException e) {
-                Log.e(TAG, "Could not get system ui tracing status." + e.toString());
-            }
-            return false;
-        }
-
-        private boolean isImeTraceEnabled() {
-            return mImeTracing.isEnabled();
-        }
-
-        private boolean isViewCaptureEnabled() {
-            // Add null checking to avoid test case failure.
-            if (getApplicationContext() != null) {
-                return Settings.Global.getInt(getApplicationContext().getContentResolver(),
-                    VIEW_CAPTURE_ENABLED, 0) != 0;
-            }
-            return false;
-        }
-
-        @Override
-        protected boolean isEnabled() {
-            return isWindowTraceEnabled() || isLayerTraceEnabled() || isSystemUiTracingEnabled()
-                    || isImeTraceEnabled() || isViewCaptureEnabled();
-        }
-
-        private void setWindowTraceEnabled(boolean isEnabled) {
-            try {
-                if (isEnabled) {
-                    mWindowManager.startWindowTrace();
-                } else {
-                    mWindowManager.stopWindowTrace();
-                }
-            } catch (RemoteException e) {
-                Log.e(TAG, "Could not set window trace status." + e.toString());
-            }
-        }
-
-        private void setLayerTraceEnabled(boolean isEnabled) {
-            Parcel data = null;
-            try {
-                if (mSurfaceFlinger != null) {
-                    data = Parcel.obtain();
-                    data.writeInterfaceToken("android.ui.ISurfaceComposer");
-                    data.writeInt(isEnabled ? 1 : 0);
-                    mSurfaceFlinger.transact(SURFACE_FLINGER_LAYER_TRACE_CONTROL_CODE,
-                            data, null, 0 /* flags */);
-                }
-            } catch (RemoteException e) {
-                Log.e(TAG, "Could not set layer tracing." + e.toString());
-            } finally {
-                if (data != null) {
-                    data.recycle();
-                }
-            }
-        }
-
-        private void setSystemUiTracing(boolean isEnabled) {
-            try {
-                final IStatusBarService statusBarService = IStatusBarService.Stub.asInterface(
-                        ServiceManager.checkService(Context.STATUS_BAR_SERVICE));
-                if (statusBarService != null) {
-                    if (isEnabled) {
-                        statusBarService.startTracing();
-                    } else {
-                        statusBarService.stopTracing();
-                    }
-                }
-            } catch (RemoteException e) {
-                Log.e(TAG, "Could not set system ui tracing." + e.toString());
-            }
-        }
-
-        private void setImeTraceEnabled(boolean isEnabled) {
-            if (isEnabled) {
-                mImeTracing.startImeTrace();
-            } else {
-                mImeTracing.stopImeTrace();
-            }
-        }
-
-        private void setViewCaptureEnabled(boolean isEnabled) {
-            // Add null checking to avoid test case failure.
-            if (getApplicationContext() != null) {
-                Settings.Global.putInt(getApplicationContext()
-                        .getContentResolver(), VIEW_CAPTURE_ENABLED, isEnabled ? 1 : 0);
-            }
-        }
-
-        @Override
-        protected void setIsEnabled(boolean isEnabled) {
-            setWindowTraceEnabled(isEnabled);
-            setLayerTraceEnabled(isEnabled);
-            setSystemUiTracing(isEnabled);
-            setImeTraceEnabled(isEnabled);
-            setViewCaptureEnabled(isEnabled);
-            if (!isEnabled) {
-                mToast.show();
-            }
-        }
-    }
-
-    /**
      * Tile to toggle sensors off to control camera, mic, and sensors managed by the SensorManager.
      */
     public static class SensorsOff extends DevelopmentTiles {
diff --git a/src/com/android/settings/fuelgauge/BatteryInfo.java b/src/com/android/settings/fuelgauge/BatteryInfo.java
index 4cc1b1b..9a19e85 100644
--- a/src/com/android/settings/fuelgauge/BatteryInfo.java
+++ b/src/com/android/settings/fuelgauge/BatteryInfo.java
@@ -24,6 +24,7 @@
 import android.os.BatteryStatsManager;
 import android.os.BatteryUsageStats;
 import android.os.SystemClock;
+import android.provider.Settings;
 import android.text.format.Formatter;
 import android.util.Log;
 import android.util.SparseIntArray;
@@ -43,6 +44,7 @@
 
 public class BatteryInfo {
     private static final String TAG = "BatteryInfo";
+    private static final String GLOBAL_TIME_TO_FULL_MILLIS = "time_to_full_millis";
 
     public CharSequence chargeLabel;
     public CharSequence remainingLabel;
@@ -147,6 +149,12 @@
         BatteryInfo.getBatteryInfo(context, callback,  /* batteryUsageStats */ null, shortString);
     }
 
+    static long getSettingsChargeTimeRemaining(final Context context) {
+        return Settings.Global.getLong(
+                context.getContentResolver(),
+                GLOBAL_TIME_TO_FULL_MILLIS, -1);
+    }
+
     public static void getBatteryInfo(final Context context, final Callback callback,
             @Nullable final BatteryUsageStats batteryUsageStats,
             boolean shortString) {
@@ -276,6 +284,13 @@
             BatteryUsageStats stats, BatteryInfo info, boolean compactStatus) {
         final Resources resources = context.getResources();
         final long chargeTimeMs = stats.getChargeTimeRemainingMs();
+        if (getSettingsChargeTimeRemaining(context) != chargeTimeMs) {
+            Settings.Global.putLong(
+                    context.getContentResolver(),
+                    GLOBAL_TIME_TO_FULL_MILLIS,
+                    chargeTimeMs);
+        }
+
         final int status = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_STATUS,
                 BatteryManager.BATTERY_STATUS_UNKNOWN);
         info.discharging = false;
diff --git a/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java b/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
index 30eabfa..4253ca6 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
@@ -44,11 +44,6 @@
     boolean isBatteryTipsEnabled();
 
     /**
-     * Check whether the feedback card is enabled in the battery tips card
-     */
-    boolean isBatteryTipsFeedbackEnabled();
-
-    /**
      * Returns a threshold (in milliseconds) for the minimal screen on time in battery usage list
      */
     double getBatteryUsageListScreenOnTimeThresholdInMs();
diff --git a/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java b/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
index 127178a..5931e206 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
@@ -81,11 +81,6 @@
     }
 
     @Override
-    public boolean isBatteryTipsFeedbackEnabled() {
-        return false;
-    }
-
-    @Override
     public double getBatteryUsageListScreenOnTimeThresholdInMs() {
         return 0;
     }
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceController.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceController.java
index fc0137b..19454d7 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceController.java
@@ -374,9 +374,6 @@
             }
             mOnBatteryUsageUpdatedListener.onBatteryUsageUpdated(
                     slotUsageData, getSlotInformation(), isBatteryUsageMapNullOrEmpty());
-
-            Log.d(TAG, "isBatteryTipsEnabled = "
-                    + mPowerUsageFeatureProvider.isBatteryTipsEnabled());
             if (mOnBatteryTipsUpdatedListener != null) {
                 mExecutor.execute(() -> {
                     final PowerAnomalyEventList anomalyEventList = mPowerUsageFeatureProvider
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsCardPreference.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsCardPreference.java
index 97bae5a..65cca7c 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsCardPreference.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsCardPreference.java
@@ -22,7 +22,6 @@
 import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.view.View;
-import android.widget.ImageButton;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
@@ -34,7 +33,6 @@
 import com.android.settings.R;
 import com.android.settings.SettingsActivity;
 import com.android.settings.core.SubSettingLauncher;
-import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
 import com.android.settings.overlay.FeatureFactory;
 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
 
@@ -47,7 +45,6 @@
 
     private static final String TAG = "BatteryTipsCardPreference";
 
-    private final PowerUsageFeatureProvider mPowerUsageFeatureProvider;
     private final MetricsFeatureProvider mMetricsFeatureProvider;
 
     private String mAnomalyEventId;
@@ -71,7 +68,6 @@
         setLayoutResource(R.layout.battery_tips_card);
         setSelectable(false);
         final FeatureFactory featureFactory = FeatureFactory.getFeatureFactory();
-        mPowerUsageFeatureProvider =  featureFactory.getPowerUsageFeatureProvider();
         mMetricsFeatureProvider = featureFactory.getMetricsFeatureProvider();
         mPowerAnomalyKey = null;
     }
@@ -191,17 +187,5 @@
         if (mIconResourceId != 0) {
             ((ImageView) view.findViewById(R.id.icon)).setImageResource(mIconResourceId);
         }
-
-        if (!mPowerUsageFeatureProvider.isBatteryTipsFeedbackEnabled()) {
-            return;
-        }
-        view.findViewById(R.id.tips_card)
-                .setBackgroundResource(R.drawable.battery_tips_half_rounded_top_bg);
-        view.findViewById(R.id.feedback_card).setVisibility(View.VISIBLE);
-
-        ImageButton thumbUpButton = (ImageButton) view.findViewById(R.id.thumb_up);
-        thumbUpButton.setOnClickListener(this);
-        ImageButton thumbDownButton = (ImageButton) view.findViewById(R.id.thumb_down);
-        thumbDownButton.setOnClickListener(this);
     }
 }
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsController.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsController.java
index 33c61e6..625d9e5 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsController.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsController.java
@@ -25,7 +25,6 @@
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.settings.R;
 import com.android.settings.core.BasePreferenceController;
-import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
 import com.android.settings.overlay.FeatureFactory;
 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
 
@@ -38,7 +37,6 @@
     private static final String ROOT_PREFERENCE_KEY = "battery_tips_category";
     private static final String CARD_PREFERENCE_KEY = "battery_tips_card";
 
-    private final PowerUsageFeatureProvider mPowerUsageFeatureProvider;
     private final MetricsFeatureProvider mMetricsFeatureProvider;
 
     @VisibleForTesting
@@ -47,14 +45,9 @@
     public BatteryTipsController(Context context) {
         super(context, ROOT_PREFERENCE_KEY);
         final FeatureFactory featureFactory = FeatureFactory.getFeatureFactory();
-        mPowerUsageFeatureProvider =  featureFactory.getPowerUsageFeatureProvider();
         mMetricsFeatureProvider = featureFactory.getMetricsFeatureProvider();
     }
 
-    private boolean isTipsCardVisible() {
-        return mPowerUsageFeatureProvider.isBatteryTipsEnabled();
-    }
-
     @Override
     public int getAvailabilityStatus() {
         return AVAILABLE;
@@ -102,12 +95,7 @@
                 : getStringFromResource(resourceId, resourceIndex);
     }
 
-    @VisibleForTesting
     void handleBatteryTipsCardUpdated(PowerAnomalyEvent powerAnomalyEvent) {
-        if (!isTipsCardVisible()) {
-            mCardPreference.setVisible(false);
-            return;
-        }
         if (powerAnomalyEvent == null) {
             mCardPreference.setVisible(false);
             return;
diff --git a/src/com/android/settings/fuelgauge/batteryusage/PowerUsageAdvanced.java b/src/com/android/settings/fuelgauge/batteryusage/PowerUsageAdvanced.java
index f13f34c..ae74689 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/PowerUsageAdvanced.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/PowerUsageAdvanced.java
@@ -35,8 +35,6 @@
 import com.android.settings.R;
 import com.android.settings.SettingsActivity;
 import com.android.settings.fuelgauge.BatteryBroadcastReceiver;
-import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
-import com.android.settings.overlay.FeatureFactory;
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settingslib.core.AbstractPreferenceController;
 import com.android.settingslib.search.SearchIndexable;
@@ -138,30 +136,25 @@
         mBatteryChartPreferenceController =
                 new BatteryChartPreferenceController(
                         context, getSettingsLifecycle(), (SettingsActivity) getActivity());
-        ScreenOnTimeController screenOnTimeController = new ScreenOnTimeController(context);
-        BatteryUsageBreakdownController batteryUsageBreakdownController =
+        final ScreenOnTimeController screenOnTimeController = new ScreenOnTimeController(context);
+        final BatteryUsageBreakdownController batteryUsageBreakdownController =
                 new BatteryUsageBreakdownController(
                         context, getSettingsLifecycle(), (SettingsActivity) getActivity(), this);
+        final BatteryTipsController batteryTipsController = new BatteryTipsController(context);
 
         mBatteryChartPreferenceController.setOnScreenOnTimeUpdatedListener(
                 screenOnTimeController::handleSceenOnTimeUpdated);
         mBatteryChartPreferenceController.setOnBatteryUsageUpdatedListener(
                 batteryUsageBreakdownController::handleBatteryUsageUpdated);
+        mBatteryChartPreferenceController.setOnBatteryTipsUpdatedListener(
+                batteryTipsController::handleBatteryTipsCardUpdated);
 
         controllers.add(mBatteryChartPreferenceController);
         controllers.add(screenOnTimeController);
         controllers.add(batteryUsageBreakdownController);
+        controllers.add(batteryTipsController);
         setBatteryChartPreferenceController();
 
-        final PowerUsageFeatureProvider powerUsageFeatureProvider =
-                FeatureFactory.getFeatureFactory().getPowerUsageFeatureProvider();
-        if (powerUsageFeatureProvider.isBatteryTipsEnabled()) {
-            BatteryTipsController batteryTipsController = new BatteryTipsController(context);
-            mBatteryChartPreferenceController.setOnBatteryTipsUpdatedListener(
-                    batteryTipsController::handleBatteryTipsCardUpdated);
-            controllers.add(batteryTipsController);
-        }
-
         return controllers;
     }
 
diff --git a/src/com/android/settings/shortcut/CreateShortcutPreferenceController.java b/src/com/android/settings/shortcut/CreateShortcutPreferenceController.java
index 0d4ea76..8f74bd9 100644
--- a/src/com/android/settings/shortcut/CreateShortcutPreferenceController.java
+++ b/src/com/android/settings/shortcut/CreateShortcutPreferenceController.java
@@ -45,11 +45,14 @@
 
 import com.android.settings.R;
 import com.android.settings.Settings;
+import com.android.settings.Settings.DataUsageSummaryActivity;
 import com.android.settings.Settings.TetherSettingsActivity;
 import com.android.settings.Settings.WifiTetherSettingsActivity;
 import com.android.settings.activityembedding.ActivityEmbeddingUtils;
 import com.android.settings.core.BasePreferenceController;
 import com.android.settings.gestures.OneHandedSettingsUtils;
+import com.android.settings.network.SubscriptionUtil;
+import com.android.settings.network.telephony.MobileNetworkUtils;
 import com.android.settings.overlay.FeatureFactory;
 import com.android.settings.wifi.WifiUtils;
 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
@@ -204,6 +207,12 @@
                 Log.d(TAG, "Skipping non-system app: " + info.activityInfo);
                 continue;
             }
+            if (info.activityInfo.name.endsWith(DataUsageSummaryActivity.class.getSimpleName())) {
+                if (!canShowDataUsage()) {
+                    Log.d(TAG, "Skipping data usage settings:" + info.activityInfo);
+                    continue;
+                }
+            }
             shortcuts.add(info);
         }
         Collections.sort(shortcuts, SHORTCUT_COMPARATOR);
@@ -211,6 +220,12 @@
     }
 
     @VisibleForTesting
+    boolean canShowDataUsage() {
+        return SubscriptionUtil.isSimHardwareVisible(mContext)
+                && !MobileNetworkUtils.isMobileNetworkUserRestricted(mContext);
+    }
+
+    @VisibleForTesting
     boolean canShowWifiHotspot() {
         return WifiUtils.canShowWifiHotspot(mContext);
     }
diff --git a/src/com/android/settings/wifi/WifiConfigController2.java b/src/com/android/settings/wifi/WifiConfigController2.java
index 48b52e4..b2353f0 100644
--- a/src/com/android/settings/wifi/WifiConfigController2.java
+++ b/src/com/android/settings/wifi/WifiConfigController2.java
@@ -64,6 +64,7 @@
 import android.widget.Spinner;
 import android.widget.TextView;
 
+import androidx.annotation.Nullable;
 import androidx.annotation.VisibleForTesting;
 
 import com.android.net.module.util.NetUtils;
@@ -200,8 +201,10 @@
     private TextView mDns2View;
 
     private Spinner mProxySettingsSpinner;
+    @Nullable
     private Spinner mMeteredSettingsSpinner;
     private Spinner mHiddenSettingsSpinner;
+    @Nullable
     private Spinner mPrivacySettingsSpinner;
     private TextView mHiddenWarningView;
     private TextView mProxyHostView;
@@ -216,48 +219,51 @@
     private StaticIpConfiguration mStaticIpConfiguration = null;
 
     private String[] mLevels;
-    private int mMode;
+    private final int mMode;
+    private final boolean mHideMeteredAndPrivacy;
+    private final WifiManager mWifiManager;
+    private final AndroidKeystoreAliasLoader mAndroidKeystoreAliasLoader;
     private TextView mSsidView;
 
-    private Context mContext;
+    private final Context mContext;
 
     @VisibleForTesting
     Integer[] mSecurityInPosition;
 
-    private final WifiManager mWifiManager;
     private boolean mIsTrustOnFirstUseSupported;
 
     private final ArrayMap<Integer, SubscriptionInfo> mActiveSubscriptionInfos = new ArrayMap<>();
 
     public WifiConfigController2(WifiConfigUiBase2 parent, View view, WifiEntry wifiEntry,
             int mode) {
-        mConfigUi = parent;
-        mView = view;
-        mWifiEntry = wifiEntry;
-        mContext = mConfigUi.getContext();
+        this(parent, view, wifiEntry, mode, false);
+    }
 
-        // Init Wi-Fi manager
-        mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
-        initWifiConfigController2(wifiEntry, mode);
+    public WifiConfigController2(WifiConfigUiBase2 parent, View view, WifiEntry wifiEntry,
+            int mode, boolean hideMeteredAndPrivacy) {
+        this(parent, view, wifiEntry, mode, hideMeteredAndPrivacy,
+                parent.getContext().getSystemService(WifiManager.class),
+                new AndroidKeystoreAliasLoader(KeyProperties.NAMESPACE_WIFI));
     }
 
     @VisibleForTesting
     public WifiConfigController2(WifiConfigUiBase2 parent, View view, WifiEntry wifiEntry,
-            int mode, WifiManager wifiManager) {
+            int mode, boolean hideMeteredAndPrivacy, WifiManager wifiManager,
+            AndroidKeystoreAliasLoader androidKeystoreAliasLoader) {
         mConfigUi = parent;
-
         mView = view;
         mWifiEntry = wifiEntry;
+        mMode = mode;
+        mHideMeteredAndPrivacy = hideMeteredAndPrivacy;
         mContext = mConfigUi.getContext();
         mWifiManager = wifiManager;
-        initWifiConfigController2(wifiEntry, mode);
+        mAndroidKeystoreAliasLoader = androidKeystoreAliasLoader;
+        initWifiConfigController2(wifiEntry);
     }
 
-    private void initWifiConfigController2(WifiEntry wifiEntry, int mode) {
-
+    private void initWifiConfigController2(WifiEntry wifiEntry) {
         mWifiEntrySecurity = (wifiEntry == null) ? WifiEntry.SECURITY_NONE :
                 wifiEntry.getSecurity();
-        mMode = mode;
         mIsTrustOnFirstUseSupported = mWifiManager.isTrustOnFirstUseSupported();
 
         final Resources res = mContext.getResources();
@@ -287,12 +293,14 @@
         mProxySettingsSpinner = (Spinner) mView.findViewById(R.id.proxy_settings);
         mProxySettingsSpinner.setOnItemSelectedListener(this);
         mSharedCheckBox = (CheckBox) mView.findViewById(R.id.shared);
-        mMeteredSettingsSpinner = mView.findViewById(R.id.metered_settings);
+        if (!mHideMeteredAndPrivacy) {
+            mMeteredSettingsSpinner = mView.findViewById(R.id.metered_settings);
+            mView.findViewById(R.id.metered_settings_fields).setVisibility(View.VISIBLE);
+        }
         mHiddenSettingsSpinner = mView.findViewById(R.id.hidden_settings);
-        mPrivacySettingsSpinner = mView.findViewById(R.id.privacy_settings);
-        if (mWifiManager.isConnectedMacRandomizationSupported()) {
-            View privacySettingsLayout = mView.findViewById(R.id.privacy_settings_fields);
-            privacySettingsLayout.setVisibility(View.VISIBLE);
+        if (!mHideMeteredAndPrivacy && mWifiManager.isConnectedMacRandomizationSupported()) {
+            mPrivacySettingsSpinner = mView.findViewById(R.id.privacy_settings);
+            mView.findViewById(R.id.privacy_settings_fields).setVisibility(View.VISIBLE);
         }
         mHiddenSettingsSpinner.setOnItemSelectedListener(this);
         mHiddenWarningView = mView.findViewById(R.id.hidden_settings_warning);
@@ -313,14 +321,18 @@
             boolean showAdvancedFields = false;
             if (mWifiEntry.isSaved()) {
                 WifiConfiguration config = mWifiEntry.getWifiConfiguration();
-                mMeteredSettingsSpinner.setSelection(config.meteredOverride);
+                if (mMeteredSettingsSpinner != null) {
+                    mMeteredSettingsSpinner.setSelection(config.meteredOverride);
+                }
                 mHiddenSettingsSpinner.setSelection(config.hiddenSSID
                         ? HIDDEN_NETWORK
                         : NOT_HIDDEN_NETWORK);
 
-                final int prefMacValue = WifiPrivacyPreferenceController2
-                        .translateMacRandomizedValueToPrefValue(config.macRandomizationSetting);
-                mPrivacySettingsSpinner.setSelection(prefMacValue);
+                if (mPrivacySettingsSpinner != null) {
+                    final int prefMacValue = WifiPrivacyPreferenceController2
+                            .translateMacRandomizedValueToPrefValue(config.macRandomizationSetting);
+                    mPrivacySettingsSpinner.setSelection(prefMacValue);
+                }
 
                 if (config.getIpConfiguration().getIpAssignment() == IpAssignment.STATIC) {
                     mIpSettingsSpinner.setSelection(STATIC_IP);
@@ -1063,17 +1075,15 @@
         if (refreshCertificates) {
             loadSims();
 
-            final AndroidKeystoreAliasLoader androidKeystoreAliasLoader =
-                    getAndroidKeystoreAliasLoader();
             loadCertificates(
                     mEapCaCertSpinner,
-                    androidKeystoreAliasLoader.getCaCertAliases(),
+                    mAndroidKeystoreAliasLoader.getCaCertAliases(),
                     null /* noCertificateString */,
                     false /* showMultipleCerts */,
                     true /* showUsePreinstalledCertOption */);
             loadCertificates(
                     mEapUserCertSpinner,
-                    androidKeystoreAliasLoader.getKeyCertAliases(),
+                    mAndroidKeystoreAliasLoader.getKeyCertAliases(),
                     mDoNotProvideEapUserCertString,
                     false /* showMultipleCerts */,
                     false /* showUsePreinstalledCertOption */);
@@ -1158,11 +1168,9 @@
                     setSelection(mEapCaCertSpinner, caCerts[0]);
                 } else {
                     // Reload the cert spinner with an extra "multiple certificates added" item.
-                    final AndroidKeystoreAliasLoader androidKeystoreAliasLoader =
-                            getAndroidKeystoreAliasLoader();
                     loadCertificates(
                             mEapCaCertSpinner,
-                            androidKeystoreAliasLoader.getCaCertAliases(),
+                            mAndroidKeystoreAliasLoader.getCaCertAliases(),
                             null /* noCertificateString */,
                             true /* showMultipleCerts */,
                             true /* showUsePreinstalledCertOption */);
@@ -1502,11 +1510,6 @@
     }
 
     @VisibleForTesting
-    AndroidKeystoreAliasLoader getAndroidKeystoreAliasLoader() {
-        return new AndroidKeystoreAliasLoader(KeyProperties.NAMESPACE_WIFI);
-    }
-
-    @VisibleForTesting
     void loadSims() {
         List<SubscriptionInfo> activeSubscriptionInfos = mContext
                 .getSystemService(SubscriptionManager.class).getActiveSubscriptionInfoList();
diff --git a/src/com/android/settings/wifi/WifiDialog2.kt b/src/com/android/settings/wifi/WifiDialog2.kt
index c2822ec..3e5f6fe 100644
--- a/src/com/android/settings/wifi/WifiDialog2.kt
+++ b/src/com/android/settings/wifi/WifiDialog2.kt
@@ -41,6 +41,7 @@
     private val mode: Int,
     @StyleRes style: Int = 0,
     private val hideSubmitButton: Boolean = mode == WifiConfigUiBase2.MODE_VIEW,
+    private val hideMeteredAndPrivacy: Boolean = false,
 ) : AlertDialog(context, style), WifiConfigUiBase2, DialogInterface.OnClickListener {
     /**
      * Host UI component of WifiDialog2 can receive callbacks by this interface.
@@ -71,7 +72,7 @@
         setWindowsOverlay()
         view = layoutInflater.inflate(R.layout.wifi_dialog, null)
         setView(view)
-        controller = WifiConfigController2(this, view, wifiEntry, mode)
+        controller = WifiConfigController2(this, view, wifiEntry, mode, hideMeteredAndPrivacy)
         super.onCreate(savedInstanceState)
         if (hideSubmitButton) {
             controller.hideSubmitButton()
diff --git a/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java b/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
index 6004e0f..65f2705 100644
--- a/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
+++ b/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
@@ -42,6 +42,7 @@
 import android.view.MenuInflater;
 import android.view.MenuItem;
 
+import androidx.annotation.NonNull;
 import androidx.annotation.VisibleForTesting;
 import androidx.preference.Preference;
 import androidx.preference.PreferenceScreen;
@@ -180,8 +181,14 @@
         }
 
         final WifiEntry wifiEntry = mNetworkDetailsTracker.getWifiEntry();
-        return new WifiDialog2(getActivity(), this, wifiEntry,
-                WifiConfigUiBase2.MODE_MODIFY);
+        return new WifiDialog2(
+                getActivity(),
+                this,
+                wifiEntry,
+                WifiConfigUiBase2.MODE_MODIFY,
+                0,
+                false,
+                true);
     }
 
     @Override
@@ -276,14 +283,12 @@
 
         // Sets callback listener for wifi dialog.
         mWifiDialogListeners.add(mWifiDetailPreferenceController2);
-        mWifiDialogListeners.add(privacyController2);
-        mWifiDialogListeners.add(meteredPreferenceController2);
 
         return mControllers;
     }
 
     @Override
-    public void onSubmit(WifiDialog2 dialog) {
+    public void onSubmit(@NonNull WifiDialog2 dialog) {
         for (WifiDialog2.WifiDialog2Listener listener : mWifiDialogListeners) {
             listener.onSubmit(dialog);
         }
diff --git a/src/com/android/settings/wifi/details2/WifiMeteredPreferenceController2.java b/src/com/android/settings/wifi/details2/WifiMeteredPreferenceController2.java
index 85dc2e4..193bbd4 100644
--- a/src/com/android/settings/wifi/details2/WifiMeteredPreferenceController2.java
+++ b/src/com/android/settings/wifi/details2/WifiMeteredPreferenceController2.java
@@ -18,26 +18,23 @@
 
 import android.app.backup.BackupManager;
 import android.content.Context;
-import android.net.wifi.WifiConfiguration;
 
+import androidx.annotation.NonNull;
 import androidx.annotation.VisibleForTesting;
 import androidx.preference.ListPreference;
 import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
 
 import com.android.settings.core.BasePreferenceController;
-import com.android.settings.wifi.WifiDialog2;
 import com.android.wifitrackerlib.WifiEntry;
 
 /**
  * A controller that controls whether the Wi-Fi network is metered or not.
  */
 public class WifiMeteredPreferenceController2 extends BasePreferenceController implements
-        Preference.OnPreferenceChangeListener, WifiDialog2.WifiDialog2Listener {
+        Preference.OnPreferenceChangeListener {
 
     private static final String KEY_WIFI_METERED = "metered";
     private final WifiEntry mWifiEntry;
-    private Preference mPreference;
 
     public WifiMeteredPreferenceController2(Context context, WifiEntry wifiEntry) {
         super(context, KEY_WIFI_METERED);
@@ -59,7 +56,7 @@
     }
 
     @Override
-    public boolean onPreferenceChange(Preference preference, Object newValue) {
+    public boolean onPreferenceChange(@NonNull Preference preference, Object newValue) {
         if (mWifiEntry.isSaved() || mWifiEntry.isSubscription()) {
             mWifiEntry.setMeteredChoice(Integer.parseInt((String) newValue));
         }
@@ -82,36 +79,4 @@
     private void updateSummary(ListPreference preference, int meteredOverride) {
         preference.setSummary(preference.getEntries()[meteredOverride]);
     }
-
-    @Override
-    public void displayPreference(PreferenceScreen screen) {
-        super.displayPreference(screen);
-        mPreference = screen.findPreference(getPreferenceKey());
-    }
-
-    @Override
-    public void onSubmit(WifiDialog2 dialog) {
-        if (dialog.getController() != null && mWifiEntry.canSetMeteredChoice()) {
-            final WifiConfiguration newConfig = dialog.getController().getConfig();
-            if (newConfig == null) {
-                return;
-            }
-
-            if (getWifiEntryMeteredChoice(newConfig) != mWifiEntry.getMeteredChoice()) {
-                mWifiEntry.setMeteredChoice(getWifiEntryMeteredChoice(newConfig));
-                onPreferenceChange(mPreference, String.valueOf(newConfig.meteredOverride));
-            }
-        }
-    }
-
-    private int getWifiEntryMeteredChoice(WifiConfiguration wifiConfiguration) {
-        switch (wifiConfiguration.meteredOverride) {
-            case WifiConfiguration.METERED_OVERRIDE_METERED:
-                return WifiEntry.METERED_CHOICE_METERED;
-            case WifiConfiguration.METERED_OVERRIDE_NOT_METERED:
-                return WifiEntry.METERED_CHOICE_UNMETERED;
-            default:
-                return WifiEntry.METERED_CHOICE_AUTO;
-        }
-    }
 }
diff --git a/src/com/android/settings/wifi/details2/WifiPrivacyPreferenceController2.java b/src/com/android/settings/wifi/details2/WifiPrivacyPreferenceController2.java
index 632a562..76fed9b 100644
--- a/src/com/android/settings/wifi/details2/WifiPrivacyPreferenceController2.java
+++ b/src/com/android/settings/wifi/details2/WifiPrivacyPreferenceController2.java
@@ -17,29 +17,26 @@
 package com.android.settings.wifi.details2;
 
 import android.content.Context;
-import android.net.wifi.WifiConfiguration;
 import android.net.wifi.WifiManager;
 
+import androidx.annotation.NonNull;
 import androidx.annotation.VisibleForTesting;
 import androidx.preference.ListPreference;
 import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
 
 import com.android.settings.R;
 import com.android.settings.core.BasePreferenceController;
-import com.android.settings.wifi.WifiDialog2;
 import com.android.wifitrackerlib.WifiEntry;
 
 /**
  * A controller that controls whether the Wi-Fi network is mac randomized or not.
  */
 public class WifiPrivacyPreferenceController2 extends BasePreferenceController implements
-        Preference.OnPreferenceChangeListener, WifiDialog2.WifiDialog2Listener {
+        Preference.OnPreferenceChangeListener {
 
     private static final String KEY_WIFI_PRIVACY = "privacy";
     private final WifiManager mWifiManager;
     private WifiEntry mWifiEntry;
-    private Preference mPreference;
 
     public WifiPrivacyPreferenceController2(Context context) {
         super(context, KEY_WIFI_PRIVACY);
@@ -58,12 +55,6 @@
     }
 
     @Override
-    public void displayPreference(PreferenceScreen screen) {
-        super.displayPreference(screen);
-        mPreference = screen.findPreference(getPreferenceKey());
-    }
-
-    @Override
     public void updateState(Preference preference) {
         final ListPreference listPreference = (ListPreference) preference;
         final int randomizationLevel = getRandomizationValue();
@@ -79,7 +70,7 @@
     }
 
     @Override
-    public boolean onPreferenceChange(Preference preference, Object newValue) {
+    public boolean onPreferenceChange(@NonNull Preference preference, Object newValue) {
         final int privacy = Integer.parseInt((String) newValue);
         mWifiEntry.setPrivacy(privacy);
 
@@ -128,30 +119,4 @@
         final int prefMacRandomized = translateMacRandomizedValueToPrefValue(macRandomized);
         preference.setSummary(preference.getEntries()[prefMacRandomized]);
     }
-
-    @Override
-    public void onSubmit(WifiDialog2 dialog) {
-        if (dialog.getController() != null) {
-            final WifiConfiguration newConfig = dialog.getController().getConfig();
-            if (newConfig == null) {
-                return;
-            }
-
-            if (getWifiEntryPrivacy(newConfig) != mWifiEntry.getPrivacy()) {
-                mWifiEntry.setPrivacy(getWifiEntryPrivacy(newConfig));
-                onPreferenceChange(mPreference, String.valueOf(newConfig.macRandomizationSetting));
-            }
-        }
-    }
-
-    private int getWifiEntryPrivacy(WifiConfiguration wifiConfiguration) {
-        switch (wifiConfiguration.macRandomizationSetting) {
-            case WifiConfiguration.RANDOMIZATION_NONE:
-                return WifiEntry.PRIVACY_DEVICE_MAC;
-            case WifiConfiguration.RANDOMIZATION_PERSISTENT:
-                return WifiEntry.PRIVACY_RANDOMIZED_MAC;
-            default:
-                return WifiEntry.PRIVACY_UNKNOWN;
-        }
-    }
 }
diff --git a/tests/robotests/src/com/android/settings/accessibility/HearingAidPairingDialogFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/HearingAidPairingDialogFragmentTest.java
index a16f15f..e632f97 100644
--- a/tests/robotests/src/com/android/settings/accessibility/HearingAidPairingDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/HearingAidPairingDialogFragmentTest.java
@@ -79,6 +79,7 @@
     public final MockitoRule mockito = MockitoJUnit.rule();
 
     private static final String TEST_DEVICE_ADDRESS = "00:A1:A1:A1:A1:A1";
+    private static final int TEST_LAUNCH_PAGE = SettingsEnums.SETTINGS_CONNECTED_DEVICE_CATEGORY;
 
     private final Context mContext = ApplicationProvider.getApplicationContext();
     @Mock
@@ -99,13 +100,7 @@
     @Before
     public void setUp() {
         setupEnvironment();
-        mFragment = spy(HearingAidPairingDialogFragment.newInstance(TEST_DEVICE_ADDRESS));
-        mActivity = (FragmentActivity) ActivityControllerWrapper.setup(
-                Robolectric.buildActivity(FragmentActivity.class)).get();
-        mFragmentManager = mActivity.getSupportFragmentManager();
-        when(mFragment.getActivity()).thenReturn(mActivity);
-        doReturn(mFragmentManager).when(mFragment).getParentFragmentManager();
-        mFragment.onAttach(mContext);
+        setupDialog(TEST_LAUNCH_PAGE);
     }
 
     @Test
@@ -122,7 +117,8 @@
     }
 
     @Test
-    public void dialogPositiveButtonClick_intentToExpectedClass() {
+    public void dialogPositiveButtonClick_intentToBluetoothPairingPage() {
+        setupDialog(SettingsEnums.SETTINGS_CONNECTED_DEVICE_CATEGORY);
         final AlertDialog dialog = (AlertDialog) mFragment.onCreateDialog(Bundle.EMPTY);
         dialog.show();
 
@@ -134,6 +130,19 @@
     }
 
     @Test
+    public void dialogPositiveButtonClick_intentToA11yPairingPage() {
+        setupDialog(SettingsEnums.ACCESSIBILITY);
+        final AlertDialog dialog = (AlertDialog) mFragment.onCreateDialog(Bundle.EMPTY);
+        dialog.show();
+
+        dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
+
+        final Intent intent = shadowOf(mActivity).getNextStartedActivity();
+        assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
+                .isEqualTo(HearingDevicePairingDetail.class.getName());
+    }
+
+    @Test
     public void dialogNegativeButtonClick_dismissDialog() {
         final AlertDialog dialog = (AlertDialog) mFragment.onCreateDialog(Bundle.EMPTY);
         dialog.show();
@@ -159,6 +168,17 @@
         verify(mFragment).dismiss();
     }
 
+    private void setupDialog(int launchPage) {
+        mFragment = spy(
+                HearingAidPairingDialogFragment.newInstance(TEST_DEVICE_ADDRESS, launchPage));
+        mActivity = (FragmentActivity) ActivityControllerWrapper.setup(
+                Robolectric.buildActivity(FragmentActivity.class)).get();
+        mFragmentManager = mActivity.getSupportFragmentManager();
+        when(mFragment.getActivity()).thenReturn(mActivity);
+        doReturn(mFragmentManager).when(mFragment).getParentFragmentManager();
+        mFragment.onAttach(mContext);
+    }
+
     private void setupEnvironment() {
         ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager;
         mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
diff --git a/tests/robotests/src/com/android/settings/accessibility/HearingAidUtilsTest.java b/tests/robotests/src/com/android/settings/accessibility/HearingAidUtilsTest.java
index eefeb60..9863087 100644
--- a/tests/robotests/src/com/android/settings/accessibility/HearingAidUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/HearingAidUtilsTest.java
@@ -72,6 +72,7 @@
     private final Context mContext = ApplicationProvider.getApplicationContext();
 
     private static final String TEST_DEVICE_ADDRESS = "00:A1:A1:A1:A1:A1";
+    private static final int TEST_LAUNCH_PAGE = 1;
 
     @Mock
     private CachedBluetoothDevice mCachedBluetoothDevice;
@@ -103,7 +104,8 @@
     public void launchHearingAidPairingDialog_deviceIsNotConnectedAshaHearingAid_noDialog() {
         when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(false);
 
-        HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice);
+        HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice,
+                TEST_LAUNCH_PAGE);
 
         shadowMainLooper().idle();
         final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
@@ -116,7 +118,8 @@
         when(mCachedBluetoothDevice.getDeviceMode()).thenReturn(
                 HearingAidInfo.DeviceMode.MODE_MONAURAL);
 
-        HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice);
+        HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice,
+                TEST_LAUNCH_PAGE);
 
         shadowMainLooper().idle();
         final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
@@ -130,7 +133,8 @@
                 HearingAidInfo.DeviceMode.MODE_BINAURAL);
         when(mCachedBluetoothDevice.getSubDevice()).thenReturn(mSubCachedBluetoothDevice);
 
-        HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice);
+        HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice,
+                TEST_LAUNCH_PAGE);
 
         shadowMainLooper().idle();
         final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
@@ -145,7 +149,8 @@
         when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
                 HearingAidInfo.DeviceSide.SIDE_INVALID);
 
-        HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice);
+        HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice,
+                TEST_LAUNCH_PAGE);
 
         shadowMainLooper().idle();
         final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
@@ -162,7 +167,8 @@
         makeDeviceSupportCsip();
         makeDeviceEnableCsip(true);
 
-        HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice);
+        HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice,
+                TEST_LAUNCH_PAGE);
 
         shadowMainLooper().idle();
         final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
@@ -179,7 +185,8 @@
         makeDeviceSupportCsip();
         makeDeviceEnableCsip(false);
 
-        HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice);
+        HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice,
+                TEST_LAUNCH_PAGE);
 
         shadowMainLooper().idle();
         final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
@@ -194,7 +201,8 @@
         when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
                 HearingAidInfo.DeviceSide.SIDE_LEFT);
 
-        HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice);
+        HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice,
+                TEST_LAUNCH_PAGE);
 
         shadowMainLooper().idle();
         final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/fastpair/FastPairDeviceGroupControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/fastpair/FastPairDeviceGroupControllerTest.java
index bf40bd2..9241d8b 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/fastpair/FastPairDeviceGroupControllerTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/fastpair/FastPairDeviceGroupControllerTest.java
@@ -25,11 +25,13 @@
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
+import static org.robolectric.Shadows.shadowOf;
 
 import android.bluetooth.BluetoothAdapter;
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.PackageManager;
+import android.os.Looper;
 import android.platform.test.annotations.RequiresFlagsDisabled;
 import android.platform.test.annotations.RequiresFlagsEnabled;
 import android.platform.test.flag.junit.CheckFlagsRule;
@@ -38,11 +40,13 @@
 import androidx.lifecycle.LifecycleOwner;
 import androidx.preference.PreferenceCategory;
 import androidx.preference.PreferenceGroup;
+import androidx.preference.PreferenceManager;
 
 import com.android.settings.dashboard.DashboardFragment;
 import com.android.settings.flags.Flags;
 import com.android.settings.testutils.FakeFeatureFactory;
 import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
+import com.android.settings.widget.GearPreference;
 import com.android.settingslib.core.lifecycle.Lifecycle;
 
 import org.junit.Before;
@@ -69,6 +73,7 @@
     @Mock private DashboardFragment mDashboardFragment;
     @Mock private FastPairDeviceUpdater mFastPairDeviceUpdater;
     @Mock private PackageManager mPackageManager;
+    @Mock private PreferenceManager mPreferenceManager;
     private ShadowBluetoothAdapter mShadowBluetoothAdapter;
     private Context mContext;
     private FastPairDeviceGroupController mFastPairDeviceGroupController;
@@ -88,6 +93,7 @@
         doReturn(mFastPairDeviceUpdater).when(provider).getFastPairDeviceUpdater(any(), any());
         mFastPairDeviceGroupController = new FastPairDeviceGroupController(mContext);
         mPreferenceGroup = spy(new PreferenceCategory(mContext));
+        doReturn(mPreferenceManager).when(mPreferenceGroup).getPreferenceManager();
         mPreferenceGroup.setVisible(false);
         mFastPairDeviceGroupController.setPreferenceGroup(mPreferenceGroup);
         mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
@@ -109,7 +115,7 @@
     @Test
     @RequiresFlagsEnabled(Flags.FLAG_ENABLE_SUBSEQUENT_PAIR_SETTINGS_INTEGRATION)
     public void testUnregister() {
-        // register it first
+        // register broadcast first
         mContext.registerReceiver(
                 mFastPairDeviceGroupController.mReceiver, null, Context.RECEIVER_EXPORTED);
 
@@ -148,10 +154,21 @@
     @Test
     @RequiresFlagsEnabled(Flags.FLAG_ENABLE_SUBSEQUENT_PAIR_SETTINGS_INTEGRATION)
     public void testUpdatePreferenceVisibility_bluetoothIsDisable_shouldHidePreference() {
+        mShadowBluetoothAdapter.setEnabled(true);
+        final GearPreference preference1 = new GearPreference(mContext, null /* AttributeSet */);
+        mFastPairDeviceGroupController.onDeviceAdded(preference1);
+        assertThat(mPreferenceGroup.isVisible()).isTrue();
+
         mShadowBluetoothAdapter.setEnabled(false);
+        // register broadcast first
+        mContext.registerReceiver(
+                mFastPairDeviceGroupController.mReceiver,
+                mFastPairDeviceGroupController.mIntentFilter,
+                Context.RECEIVER_EXPORTED_UNAUDITED);
         Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
         mContext.sendBroadcast(intent);
 
+        shadowOf(Looper.getMainLooper()).idle();
         assertThat(mPreferenceGroup.isVisible()).isFalse();
     }
 }
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/fastpair/FastPairDevicePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/fastpair/FastPairDevicePreferenceControllerTest.java
new file mode 100644
index 0000000..8a7fc73
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/connecteddevice/fastpair/FastPairDevicePreferenceControllerTest.java
@@ -0,0 +1,260 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.connecteddevice.fastpair;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
+
+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.spy;
+import static org.mockito.Mockito.verify;
+import static org.robolectric.Shadows.shadowOf;
+
+import android.bluetooth.BluetoothAdapter;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.os.Looper;
+import android.platform.test.annotations.RequiresFlagsDisabled;
+import android.platform.test.annotations.RequiresFlagsEnabled;
+import android.platform.test.flag.junit.CheckFlagsRule;
+import android.platform.test.flag.junit.DeviceFlagsValueProvider;
+
+import androidx.lifecycle.LifecycleOwner;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceCategory;
+import androidx.preference.PreferenceGroup;
+import androidx.preference.PreferenceManager;
+
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.flags.Flags;
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
+import com.android.settings.widget.GearPreference;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadow.api.Shadow;
+
+@RunWith(RobolectricTestRunner.class)
+@Config(shadows = ShadowBluetoothAdapter.class)
+public class FastPairDevicePreferenceControllerTest {
+
+    private static final String KEY = "test_key";
+
+    @Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule();
+
+    @Rule
+    public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
+
+    @Mock private DashboardFragment mDashboardFragment;
+    @Mock private FastPairDeviceUpdater mFastPairDeviceUpdater;
+    @Mock private PackageManager mPackageManager;
+    @Mock private PreferenceManager mPreferenceManager;
+    private Context mContext;
+    private FastPairDevicePreferenceController mFastPairDevicePrefController;
+    private PreferenceGroup mPreferenceGroup;
+    private Preference mSeeAllPreference;
+    private ShadowBluetoothAdapter mShadowBluetoothAdapter;
+    private LifecycleOwner mLifecycleOwner;
+    private Lifecycle mLifecycle;
+
+    @Before
+    public void setUp() {
+        mContext = spy(RuntimeEnvironment.application);
+        mLifecycleOwner = () -> mLifecycle;
+        mLifecycle = new Lifecycle(mLifecycleOwner);
+        doReturn(mContext).when(mDashboardFragment).getContext();
+        doReturn(mPackageManager).when(mContext).getPackageManager();
+        FastPairFeatureProvider provider =
+                FakeFeatureFactory.setupForTest().getFastPairFeatureProvider();
+        doReturn(mFastPairDeviceUpdater).when(provider).getFastPairDeviceUpdater(any(), any());
+        mFastPairDevicePrefController = new FastPairDevicePreferenceController(mContext, KEY);
+        mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
+
+        mPreferenceGroup = spy(new PreferenceCategory(mContext));
+        doReturn(mPreferenceManager).when(mPreferenceGroup).getPreferenceManager();
+        mSeeAllPreference = spy(new Preference(mContext));
+        mPreferenceGroup.setVisible(false);
+        mSeeAllPreference.setVisible(false);
+        mFastPairDevicePrefController.setPreferenceGroup(mPreferenceGroup);
+        mFastPairDevicePrefController.mSeeAllPreference = mSeeAllPreference;
+    }
+
+    @Test
+    @RequiresFlagsEnabled(Flags.FLAG_ENABLE_SUBSEQUENT_PAIR_SETTINGS_INTEGRATION)
+    public void onStart_registerCallback() {
+        // register the callback in onStart()
+        mFastPairDevicePrefController.onStart(mLifecycleOwner);
+        verify(mFastPairDeviceUpdater).registerCallback();
+        verify(mContext)
+                .registerReceiver(
+                        mFastPairDevicePrefController.mReceiver,
+                        mFastPairDevicePrefController.mIntentFilter,
+                        Context.RECEIVER_EXPORTED_UNAUDITED);
+    }
+
+    @Test
+    @RequiresFlagsEnabled(Flags.FLAG_ENABLE_SUBSEQUENT_PAIR_SETTINGS_INTEGRATION)
+    public void onStop_unregisterCallback() {
+        // register broadcast first
+        mContext.registerReceiver(
+                mFastPairDevicePrefController.mReceiver, null, Context.RECEIVER_EXPORTED_UNAUDITED);
+
+        // unregister the callback in onStop()
+        mFastPairDevicePrefController.onStop(mLifecycleOwner);
+        verify(mFastPairDeviceUpdater).unregisterCallback();
+        verify(mContext).unregisterReceiver(mFastPairDevicePrefController.mReceiver);
+    }
+
+    @Test
+    @RequiresFlagsEnabled(Flags.FLAG_ENABLE_SUBSEQUENT_PAIR_SETTINGS_INTEGRATION)
+    public void getAvailabilityStatus_noBluetoothFeature_returnUnsupported() {
+        doReturn(false).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
+
+        assertThat(mFastPairDevicePrefController.getAvailabilityStatus())
+                .isEqualTo(UNSUPPORTED_ON_DEVICE);
+    }
+
+    @Test
+    @RequiresFlagsDisabled(Flags.FLAG_ENABLE_SUBSEQUENT_PAIR_SETTINGS_INTEGRATION)
+    public void getAvailabilityStatus_noFastPairFeature_returnUnsupported() {
+        doReturn(true).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
+
+        assertThat(mFastPairDevicePrefController.getAvailabilityStatus())
+                .isEqualTo(UNSUPPORTED_ON_DEVICE);
+    }
+
+    @Test
+    @RequiresFlagsEnabled(Flags.FLAG_ENABLE_SUBSEQUENT_PAIR_SETTINGS_INTEGRATION)
+    public void getAvailabilityStatus_bothBluetoothFastPairFeature_returnSupported() {
+        doReturn(true).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
+
+        assertThat(mFastPairDevicePrefController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+    }
+
+    @Test
+    @RequiresFlagsEnabled(Flags.FLAG_ENABLE_SUBSEQUENT_PAIR_SETTINGS_INTEGRATION)
+    public void onDeviceAdded_addThreeFastPairDevicePreference_displayThreeNoSeeAll() {
+        mShadowBluetoothAdapter.setEnabled(true);
+        final GearPreference preference1 = new GearPreference(mContext, null /* AttributeSet */);
+        final GearPreference preference2 = new GearPreference(mContext, null /* AttributeSet */);
+        final GearPreference preference3 = new GearPreference(mContext, null /* AttributeSet */);
+
+        mFastPairDevicePrefController.onDeviceAdded(preference1);
+        mFastPairDevicePrefController.onDeviceAdded(preference2);
+        mFastPairDevicePrefController.onDeviceAdded(preference3);
+
+        assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(3);
+        assertThat(mPreferenceGroup.isVisible()).isTrue();
+        assertThat(mSeeAllPreference.isVisible()).isFalse();
+    }
+
+    @Test
+    @RequiresFlagsEnabled(Flags.FLAG_ENABLE_SUBSEQUENT_PAIR_SETTINGS_INTEGRATION)
+    public void onDeviceAdded_addFourDevicePreference_onlyDisplayThreeWithSeeAll() {
+        mShadowBluetoothAdapter.setEnabled(true);
+        final GearPreference preference1 = new GearPreference(mContext, null /* AttributeSet */);
+        preference1.setOrder(4);
+        final GearPreference preference2 = new GearPreference(mContext, null /* AttributeSet */);
+        preference2.setOrder(3);
+        final GearPreference preference3 = new GearPreference(mContext, null /* AttributeSet */);
+        preference3.setOrder(1);
+        final GearPreference preference4 = new GearPreference(mContext, null /* AttributeSet */);
+        preference4.setOrder(2);
+        final GearPreference preference5 = new GearPreference(mContext, null /* AttributeSet */);
+        preference5.setOrder(5);
+
+        mFastPairDevicePrefController.onDeviceAdded(preference1);
+        mFastPairDevicePrefController.onDeviceAdded(preference2);
+        mFastPairDevicePrefController.onDeviceAdded(preference3);
+        mFastPairDevicePrefController.onDeviceAdded(preference4);
+        mFastPairDevicePrefController.onDeviceAdded(preference5);
+
+        // 3 GearPreference and 1 see all preference
+        assertThat(mPreferenceGroup.getPreference(0)).isEqualTo(preference3);
+        assertThat(mPreferenceGroup.getPreference(1)).isEqualTo(preference4);
+        assertThat(mPreferenceGroup.getPreference(2)).isEqualTo(preference2);
+        assertThat(mPreferenceGroup.isVisible()).isTrue();
+        assertThat(mSeeAllPreference.isVisible()).isTrue();
+    }
+
+    @Test
+    @RequiresFlagsEnabled(Flags.FLAG_ENABLE_SUBSEQUENT_PAIR_SETTINGS_INTEGRATION)
+    public void onDeviceRemoved_removeFourthDevice_hideSeeAll() {
+        mShadowBluetoothAdapter.setEnabled(true);
+        final GearPreference preference1 = new GearPreference(mContext, null /* AttributeSet */);
+        preference1.setOrder(1);
+        final GearPreference preference2 = new GearPreference(mContext, null /* AttributeSet */);
+        preference2.setOrder(2);
+        final GearPreference preference3 = new GearPreference(mContext, null /* AttributeSet */);
+        preference3.setOrder(3);
+        final GearPreference preference4 = new GearPreference(mContext, null /* AttributeSet */);
+        preference4.setOrder(4);
+        final GearPreference preference5 = new GearPreference(mContext, null /* AttributeSet */);
+        preference5.setOrder(5);
+
+        mFastPairDevicePrefController.onDeviceAdded(preference1);
+        mFastPairDevicePrefController.onDeviceAdded(preference2);
+        mFastPairDevicePrefController.onDeviceAdded(preference3);
+        mFastPairDevicePrefController.onDeviceAdded(preference4);
+        mFastPairDevicePrefController.onDeviceAdded(preference5);
+
+        mFastPairDevicePrefController.onDeviceRemoved(preference4);
+        mFastPairDevicePrefController.onDeviceRemoved(preference2);
+
+        // 3 GearPreference and no see all preference
+        assertThat(mPreferenceGroup.getPreference(0)).isEqualTo(preference1);
+        assertThat(mPreferenceGroup.getPreference(1)).isEqualTo(preference3);
+        assertThat(mPreferenceGroup.getPreference(2)).isEqualTo(preference5);
+        assertThat(mPreferenceGroup.isVisible()).isTrue();
+        assertThat(mSeeAllPreference.isVisible()).isFalse();
+    }
+
+    @Test
+    @RequiresFlagsEnabled(Flags.FLAG_ENABLE_SUBSEQUENT_PAIR_SETTINGS_INTEGRATION)
+    public void updatePreferenceVisibility_bluetoothIsDisable_shouldHidePreference() {
+        mShadowBluetoothAdapter.setEnabled(true);
+        final GearPreference preference1 = new GearPreference(mContext, null /* AttributeSet */);
+        mFastPairDevicePrefController.onDeviceAdded(preference1);
+        assertThat(mPreferenceGroup.isVisible()).isTrue();
+
+        mShadowBluetoothAdapter.setEnabled(false);
+        // register broadcast first
+        mContext.registerReceiver(
+                mFastPairDevicePrefController.mReceiver,
+                mFastPairDevicePrefController.mIntentFilter,
+                Context.RECEIVER_EXPORTED_UNAUDITED);
+        Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
+        mContext.sendBroadcast(intent);
+
+        shadowOf(Looper.getMainLooper()).idle();
+        assertThat(mPreferenceGroup.isVisible()).isFalse();
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/development/qstile/WinscopeTraceTest.java b/tests/robotests/src/com/android/settings/development/qstile/WinscopeTraceTest.java
deleted file mode 100644
index ad495c7..0000000
--- a/tests/robotests/src/com/android/settings/development/qstile/WinscopeTraceTest.java
+++ /dev/null
@@ -1,259 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.development.qstile;
-
-import static com.android.settings.development.qstile.DevelopmentTiles.WinscopeTrace.SURFACE_FLINGER_LAYER_TRACE_CONTROL_CODE;
-import static com.android.settings.development.qstile.DevelopmentTiles.WinscopeTrace.SURFACE_FLINGER_LAYER_TRACE_STATUS_CODE;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.ArgumentMatchers.isNull;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-
-import android.os.IBinder;
-import android.os.RemoteException;
-import android.view.IWindowManager;
-import android.widget.Toast;
-
-import androidx.test.core.app.ApplicationProvider;
-
-import com.android.internal.inputmethod.ImeTracing;
-import com.android.settings.testutils.shadow.ShadowParcel;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.annotation.Config;
-import org.robolectric.util.ReflectionHelpers;
-
-@RunWith(RobolectricTestRunner.class)
-public class WinscopeTraceTest {
-
-    @Mock
-    private IWindowManager mWindowManager;
-    @Mock
-    private ImeTracing mImeTracing;
-    @Mock
-    private IBinder mSurfaceFlinger;
-    @Mock
-    private Toast mToast;
-
-    private DevelopmentTiles.WinscopeTrace mWinscopeTrace;
-
-    @Before
-    public void setUp() {
-        MockitoAnnotations.initMocks(this);
-        mWinscopeTrace = spy(new DevelopmentTiles.WinscopeTrace());
-        doReturn(ApplicationProvider.getApplicationContext()).when(
-                mWinscopeTrace).getApplicationContext();
-
-        ReflectionHelpers.setField(mWinscopeTrace, "mWindowManager", mWindowManager);
-        ReflectionHelpers.setField(mWinscopeTrace, "mImeTracing", mImeTracing);
-        ReflectionHelpers.setField(mWinscopeTrace, "mSurfaceFlinger", mSurfaceFlinger);
-        ReflectionHelpers.setField(mWinscopeTrace, "mToast", mToast);
-    }
-
-    @After
-    public void teardown() {
-        verifyNoMoreInteractions(mToast);
-    }
-
-    @Test
-    @Config(shadows = ShadowParcel.class)
-    public void wmReturnsTraceEnabled_shouldReturnEnabled() throws RemoteException {
-        // Assume Surface Trace and Input Method Manager are disabled.
-        ShadowParcel.sReadBoolResult = false;
-        doReturn(true).when(mWindowManager).isWindowTraceEnabled();
-        assertThat(mWinscopeTrace.isEnabled()).isTrue();
-    }
-
-    @Test
-    @Config(shadows = ShadowParcel.class)
-    public void sfReturnsTraceEnabled_shouldReturnEnabled() throws RemoteException {
-        // Assume Window Trace and Input Method Manager are disabled.
-        doReturn(false).when(mWindowManager).isWindowTraceEnabled();
-        doReturn(false).when(mImeTracing).isEnabled();
-        ShadowParcel.sReadBoolResult = true;
-        assertThat(mWinscopeTrace.isEnabled()).isTrue();
-        verify(mSurfaceFlinger)
-                .transact(eq(SURFACE_FLINGER_LAYER_TRACE_STATUS_CODE), any(), any(),
-                        eq(0 /* flags */));
-        verifyNoMoreInteractions(mSurfaceFlinger);
-    }
-
-    @Test
-    @Config(shadows = ShadowParcel.class)
-    public void sfAndWmReturnsTraceEnabled_shouldReturnEnabled() throws RemoteException {
-        ShadowParcel.sReadBoolResult = true;
-        doReturn(true).when(mWindowManager).isWindowTraceEnabled();
-        assertThat(mWinscopeTrace.isEnabled()).isTrue();
-    }
-
-    @Test
-    public void wmAndSfAndImmReturnTraceDisabled_shouldReturnDisabled() throws RemoteException {
-        ShadowParcel.sReadBoolResult = false;
-        doReturn(false).when(mWindowManager).isWindowTraceEnabled();
-        doReturn(false).when(mImeTracing).isEnabled();
-        assertThat(mWinscopeTrace.isEnabled()).isFalse();
-        verify(mSurfaceFlinger)
-                .transact(eq(SURFACE_FLINGER_LAYER_TRACE_STATUS_CODE), any(), any(),
-                        eq(0 /* flags */));
-        verifyNoMoreInteractions(mSurfaceFlinger);
-    }
-
-    @Test
-    public void wmAndSfReturnTraceDisabled_immReturnsTraceEnabled_shouldReturnEnabled()
-            throws RemoteException {
-        ShadowParcel.sReadBoolResult = false;
-        doReturn(false).when(mWindowManager).isWindowTraceEnabled();
-        doReturn(true).when(mImeTracing).isEnabled();
-        assertThat(mWinscopeTrace.isEnabled()).isTrue();
-        verify(mSurfaceFlinger)
-                .transact(eq(SURFACE_FLINGER_LAYER_TRACE_STATUS_CODE), any(), any(),
-                        eq(0 /* flags */));
-        verifyNoMoreInteractions(mSurfaceFlinger);
-    }
-
-    @Test
-    @Config(shadows = ShadowParcel.class)
-    public void immReturnsTraceEnabled_shouldReturnEnabled() throws RemoteException {
-        // Assume Window Manager and Surface Trace are disabled.
-        ShadowParcel.sReadBoolResult = false;
-        doReturn(true).when(mImeTracing).isEnabled();
-        assertThat(mWinscopeTrace.isEnabled()).isTrue();
-    }
-
-    @Test
-    @Config(shadows = ShadowParcel.class)
-    public void immReturnsTraceDisabled_shouldReturnDisabled() throws RemoteException {
-        // Assume Window Manager and Surface Trace are disabled.
-        ShadowParcel.sReadBoolResult = false;
-        doReturn(false).when(mImeTracing).isEnabled();
-        assertThat(mWinscopeTrace.isEnabled()).isFalse();
-    }
-
-    @Test
-    @Config(shadows = ShadowParcel.class)
-    public void wmThrowsRemoteExAndSfReturnsTraceDisabled_shouldReturnDisabled()
-            throws RemoteException {
-        ShadowParcel.sReadBoolResult = false;
-        doThrow(new RemoteException("Unknown"))
-                .when(mWindowManager).isWindowTraceEnabled();
-        assertThat(mWinscopeTrace.isEnabled()).isFalse();
-    }
-
-    @Test
-    public void sfUnavailableAndWmAndImmReturnTraceDisabled_shouldReturnDisabled()
-            throws RemoteException {
-        doReturn(false).when(mWindowManager).isWindowTraceEnabled();
-        doReturn(false).when(mImeTracing).isEnabled();
-        ReflectionHelpers.setField(mWinscopeTrace, "mSurfaceFlinger", null);
-        assertThat(mWinscopeTrace.isEnabled()).isFalse();
-    }
-
-    @Test
-    public void setIsEnableTrue_shouldEnableWindowTrace() throws RemoteException {
-        mWinscopeTrace.setIsEnabled(true);
-        verify(mWindowManager).startWindowTrace();
-        verifyNoMoreInteractions(mWindowManager);
-    }
-
-    @Test
-    public void setIsEnableTrue_shouldEnableImeTrace() throws RemoteException {
-        mWinscopeTrace.setIsEnabled(true);
-        verify(mImeTracing).startImeTrace();
-        verifyNoMoreInteractions(mImeTracing);
-    }
-
-    @Test
-    @Config(shadows = ShadowParcel.class)
-    public void setIsEnableTrue_shouldEnableLayerTrace() throws RemoteException {
-        mWinscopeTrace.setIsEnabled(true);
-        assertThat(ShadowParcel.sWriteIntResult).isEqualTo(1);
-        verify(mSurfaceFlinger)
-                .transact(eq(SURFACE_FLINGER_LAYER_TRACE_CONTROL_CODE), any(), isNull(),
-                        eq(0 /* flags */));
-        verifyNoMoreInteractions(mSurfaceFlinger);
-    }
-
-    @Test
-    @Config(shadows = ShadowParcel.class)
-    public void setIsEnableFalse_shouldDisableWindowTrace() throws RemoteException {
-        mWinscopeTrace.setIsEnabled(false);
-        verify(mWindowManager).stopWindowTrace();
-        verifyNoMoreInteractions(mWindowManager);
-        verify(mToast).show();
-    }
-
-    @Test
-    @Config(shadows = ShadowParcel.class)
-    public void setIsEnableFalse_shouldDisableImeTrace() throws RemoteException {
-        mWinscopeTrace.setIsEnabled(false);
-        verify(mImeTracing).stopImeTrace();
-        verifyNoMoreInteractions(mImeTracing);
-        verify(mToast).show();
-    }
-
-    @Test
-    @Config(shadows = ShadowParcel.class)
-    public void setIsEnableFalse_shouldDisableLayerTrace() throws RemoteException {
-        mWinscopeTrace.setIsEnabled(false);
-        assertThat(ShadowParcel.sWriteIntResult).isEqualTo(0);
-        verify(mSurfaceFlinger)
-                .transact(eq(SURFACE_FLINGER_LAYER_TRACE_CONTROL_CODE), any(), isNull(),
-                        eq(0 /* flags */));
-        verifyNoMoreInteractions(mSurfaceFlinger);
-        verify(mToast).show();
-    }
-
-    @Test
-    public void setIsEnableFalse_shouldShowToast() {
-        mWinscopeTrace.setIsEnabled(false);
-        verify(mToast).show();
-    }
-
-    /**
-     * Verify when window manager call throws a remote exception, it is handled without
-     * re-throwing the exception.
-     */
-    @Test
-    public void setIsEnableAndWmThrowsRemoteException_shouldFailGracefully()
-            throws RemoteException {
-        doThrow(new RemoteException("Unknown")).when(mWindowManager).isWindowTraceEnabled();
-        mWinscopeTrace.setIsEnabled(true);
-    }
-
-    /**
-     * Verify is surface flinger is not available not calls are made to it.
-     */
-    @Test
-    public void setIsEnableAndSfUnavailable_shouldFailGracefully() {
-        ReflectionHelpers.setField(mWinscopeTrace, "mSurfaceFlinger", null);
-        mWinscopeTrace.setIsEnabled(true);
-        verifyNoMoreInteractions(mSurfaceFlinger);
-    }
-}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
index b0d6da6..2ba9f33 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
@@ -230,6 +230,37 @@
     }
 
     @Test
+    public void testGetBatteryInfo_getChargeTimeRemaining_updateSettingsGlobal() {
+        doReturn(TEST_CHARGE_TIME_REMAINING)
+                .when(mBatteryUsageStats)
+                .getChargeTimeRemainingMs();
+
+        BatteryInfo.getBatteryInfo(mContext, mChargingBatteryBroadcast,
+                mBatteryUsageStats, MOCK_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
+                false /* shortString */);
+
+        assertThat(BatteryInfo.getSettingsChargeTimeRemaining(mContext)).isEqualTo(
+                TEST_CHARGE_TIME_REMAINING);
+    }
+
+    @Test
+    public void testGetBatteryInfo_differentChargeTimeRemaining_updateSettingsGlobal() {
+        doReturn(TEST_CHARGE_TIME_REMAINING)
+                .when(mBatteryUsageStats)
+                .getChargeTimeRemainingMs();
+        final long newTimeToFull = 300L;
+        doReturn(newTimeToFull)
+                .when(mBatteryUsageStats)
+                .getChargeTimeRemainingMs();
+
+        BatteryInfo.getBatteryInfo(mContext, mChargingBatteryBroadcast,
+                mBatteryUsageStats, MOCK_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
+                false /* shortString */);
+
+        assertThat(BatteryInfo.getSettingsChargeTimeRemaining(mContext)).isEqualTo(newTimeToFull);
+    }
+
+    @Test
     public void testGetBatteryInfo_dockDefenderActive_updateChargeString() {
         doReturn(TEST_CHARGE_TIME_REMAINING / 1000)
                 .when(mBatteryUsageStats).getChargeTimeRemainingMs();
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
index bf4e893..a0b449a 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
@@ -73,10 +73,6 @@
     }
 
     @Test
-    public void testIsBatteryTipsFeedbackEnabled_returnFalse() {
-        assertThat(mPowerFeatureProvider.isBatteryTipsFeedbackEnabled()).isFalse();
-    }
-    @Test
     public void testGetBatteryUsageListConsumePowerThreshold_return0() {
         assertThat(mPowerFeatureProvider.getBatteryUsageListConsumePowerThreshold()).isEqualTo(0.0);
     }
diff --git a/tests/robotests/src/com/android/settings/shortcut/CreateShortcutPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/shortcut/CreateShortcutPreferenceControllerTest.java
index 85cf299..4aba895 100644
--- a/tests/robotests/src/com/android/settings/shortcut/CreateShortcutPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/shortcut/CreateShortcutPreferenceControllerTest.java
@@ -36,8 +36,11 @@
 import android.content.pm.ResolveInfo;
 import android.content.pm.ShortcutInfo;
 import android.content.pm.ShortcutManager;
+import android.content.res.Resources;
 import android.os.SystemProperties;
+import android.os.UserManager;
 
+import com.android.settings.R;
 import com.android.settings.Settings;
 import com.android.settings.testutils.shadow.ShadowConnectivityManager;
 
@@ -69,6 +72,10 @@
     private ShortcutManager mShortcutManager;
     @Mock
     private Activity mHost;
+    @Mock
+    private Resources mResources;
+    @Mock
+    private UserManager mUserManager;
 
     private Context mContext;
     private ShadowConnectivityManager mShadowConnectivityManager;
@@ -192,6 +199,70 @@
         assertThat(mController.queryShortcuts()).hasSize(0);
     }
 
+    @Test
+    public void queryShortcuts_configShowDataUsage_ShouldEnableShortcuts() {
+        doReturn(true).when(mController).canShowDataUsage();
+        setupActivityInfo(Settings.DataUsageSummaryActivity.class.getSimpleName());
+
+        assertThat(mController.queryShortcuts()).hasSize(1);
+    }
+
+    @Test
+    public void queryShortcuts_configNotShowDataUsage_ShouldDisableShortcuts() {
+        doReturn(false).when(mController).canShowDataUsage();
+        setupActivityInfo(Settings.DataUsageSummaryActivity.class.getSimpleName());
+
+        assertThat(mController.queryShortcuts()).hasSize(0);
+    }
+
+    @Test
+    public void canShowDataUsage_configShowDataUsage_returnTrue() {
+        when(mContext.getResources()).thenReturn(mResources);
+        when(mResources.getBoolean(R.bool.config_show_sim_info)).thenReturn(true);
+        when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
+        when(mUserManager.isGuestUser()).thenReturn(false);
+        when(mUserManager.hasUserRestriction(
+                UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)).thenReturn(false);
+
+        assertThat(mController.canShowDataUsage()).isTrue();
+    }
+
+    @Test
+    public void canShowDataUsage_noSimCapability_returnFalse() {
+        when(mContext.getResources()).thenReturn(mResources);
+        when(mResources.getBoolean(R.bool.config_show_sim_info)).thenReturn(false);
+        when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
+        when(mUserManager.isGuestUser()).thenReturn(false);
+        when(mUserManager.hasUserRestriction(
+                UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)).thenReturn(false);
+
+        assertThat(mController.canShowDataUsage()).isFalse();
+    }
+
+    @Test
+    public void canShowDataUsage_isGuestUser_returnFalse() {
+        when(mContext.getResources()).thenReturn(mResources);
+        when(mResources.getBoolean(R.bool.config_show_sim_info)).thenReturn(true);
+        when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
+        when(mUserManager.isGuestUser()).thenReturn(true);
+        when(mUserManager.hasUserRestriction(
+                UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)).thenReturn(false);
+
+        assertThat(mController.canShowDataUsage()).isFalse();
+    }
+
+    @Test
+    public void canShowDataUsage_isMobileNetworkUserRestricted_returnFalse() {
+        when(mContext.getResources()).thenReturn(mResources);
+        when(mResources.getBoolean(R.bool.config_show_sim_info)).thenReturn(true);
+        when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
+        when(mUserManager.isGuestUser()).thenReturn(false);
+        when(mUserManager.hasUserRestriction(
+                UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)).thenReturn(true);
+
+        assertThat(mController.canShowDataUsage()).isFalse();
+    }
+
     private void setupActivityInfo(String name) {
         ResolveInfo ri = new ResolveInfo();
         ri.activityInfo = new ActivityInfo();
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiConfigController2Test.java b/tests/robotests/src/com/android/settings/wifi/WifiConfigController2Test.java
index dc60714..d17414d 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiConfigController2Test.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiConfigController2Test.java
@@ -53,7 +53,6 @@
 
 import com.android.settings.R;
 import com.android.settings.network.SubscriptionUtil;
-import com.android.settings.testutils.shadow.ShadowConnectivityManager;
 import com.android.settings.utils.AndroidKeystoreAliasLoader;
 import com.android.settings.wifi.details2.WifiPrivacyPreferenceController2;
 import com.android.wifitrackerlib.WifiEntry;
@@ -69,7 +68,6 @@
 import org.robolectric.RobolectricTestRunner;
 import org.robolectric.RuntimeEnvironment;
 import org.robolectric.Shadows;
-import org.robolectric.annotation.Config;
 import org.robolectric.shadows.ShadowInputMethodManager;
 import org.robolectric.shadows.ShadowSubscriptionManager;
 
@@ -79,7 +77,6 @@
 import java.util.stream.IntStream;
 
 @RunWith(RobolectricTestRunner.class)
-@Config(shadows = ShadowConnectivityManager.class)
 public class WifiConfigController2Test {
 
     static final String WIFI_EAP_TLS_V1_3 = "TLS v1.3";
@@ -138,6 +135,7 @@
         MockitoAnnotations.initMocks(this);
         mContext = spy(RuntimeEnvironment.application);
         when(mContext.getSystemService(eq(WifiManager.class))).thenReturn(mWifiManager);
+        when(mWifiManager.isConnectedMacRandomizationSupported()).thenReturn(true);
         when(mConfigUiBase.getContext()).thenReturn(mContext);
         when(mWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_PSK);
         mView = LayoutInflater.from(mContext).inflate(R.layout.wifi_dialog, null);
@@ -152,15 +150,17 @@
         ipSettingsSpinner.setSelection(DHCP);
         mShadowSubscriptionManager = shadowOf(mContext.getSystemService(SubscriptionManager.class));
         when(mEapMethodSimSpinner.getSelectedItemPosition()).thenReturn(WIFI_EAP_METHOD_SIM);
+    }
 
-        mController = new TestWifiConfigController2(mConfigUiBase, mView, mWifiEntry,
-                WifiConfigUiBase2.MODE_CONNECT);
+    private void createController(
+            WifiEntry mWifiEntry, int modeConnect, boolean hideMeteredAndPrivacy) {
+        mController = new WifiConfigController2(mConfigUiBase, mView, mWifiEntry,
+                modeConnect, hideMeteredAndPrivacy, mWifiManager, mAndroidKeystoreAliasLoader);
     }
 
     @Test
     public void ssidExceeds32Bytes_shouldShowSsidTooLongWarning() {
-        mController = new TestWifiConfigController2(mConfigUiBase, mView, null /* wifiEntry */,
-                WifiConfigUiBase2.MODE_CONNECT);
+        createController(null, WifiConfigUiBase2.MODE_CONNECT, false);
         final TextView ssid = mView.findViewById(R.id.ssid);
         assertThat(ssid).isNotNull();
         ssid.setText("☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎");
@@ -172,8 +172,7 @@
 
     @Test
     public void ssidShorterThan32Bytes_shouldNotShowSsidTooLongWarning() {
-        mController = new TestWifiConfigController2(mConfigUiBase, mView, null /* wifiEntry */,
-                WifiConfigUiBase2.MODE_CONNECT);
+        createController(null, WifiConfigUiBase2.MODE_CONNECT, false);
 
         final TextView ssid = mView.findViewById(R.id.ssid);
         assertThat(ssid).isNotNull();
@@ -192,6 +191,7 @@
 
     @Test
     public void isSubmittable_noSSID_shouldReturnFalse() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         final TextView ssid = mView.findViewById(R.id.ssid);
         assertThat(ssid).isNotNull();
         ssid.setText("");
@@ -200,6 +200,7 @@
 
     @Test
     public void isSubmittable_longPsk_shouldReturnFalse() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         final TextView password = mView.findViewById(R.id.password);
         assertThat(password).isNotNull();
         password.setText(LONG_PSK);
@@ -208,6 +209,7 @@
 
     @Test
     public void isSubmittable_shortPsk_shouldReturnFalse() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         final TextView password = mView.findViewById(R.id.password);
         assertThat(password).isNotNull();
         password.setText(SHORT_PSK);
@@ -216,6 +218,7 @@
 
     @Test
     public void isSubmittable_goodPsk_shouldReturnTrue() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         final TextView password = mView.findViewById(R.id.password);
         assertThat(password).isNotNull();
         password.setText(GOOD_PSK);
@@ -224,6 +227,7 @@
 
     @Test
     public void isSubmittable_hexPsk_shouldReturnTrue() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         final TextView password = mView.findViewById(R.id.password);
         assertThat(password).isNotNull();
         password.setText(HEX_PSK);
@@ -232,6 +236,7 @@
 
     @Test
     public void isSubmittable_savedConfigZeroLengthPassword_shouldReturnTrue() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         final TextView password = mView.findViewById(R.id.password);
         assertThat(password).isNotNull();
         password.setText("");
@@ -241,15 +246,13 @@
 
     @Test
     public void isSubmittable_nullWifiEntry_noException() {
-        mController = new TestWifiConfigController2(mConfigUiBase, mView, null,
-                WifiConfigUiBase2.MODE_CONNECT);
+        createController(null, WifiConfigUiBase2.MODE_CONNECT, false);
         mController.isSubmittable();
     }
 
     @Test
     public void isSubmittable_EapToPskWithValidPassword_shouldReturnTrue() {
-        mController = new TestWifiConfigController2(mConfigUiBase, mView, null,
-                WifiConfigUiBase2.MODE_CONNECT);
+        createController(null, WifiConfigUiBase2.MODE_CONNECT, false);
         final TextView ssid = mView.findViewById(R.id.ssid);
         final TextView password = mView.findViewById(R.id.password);
         final Spinner securitySpinner = mView.findViewById(R.id.security);
@@ -268,6 +271,7 @@
 
     @Test
     public void isSubmittable_EapWithAkaMethod_shouldReturnTrue() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         when(mWifiEntry.isSaved()).thenReturn(true);
         mController.mWifiEntrySecurity = WifiEntry.SECURITY_EAP;
         mView.findViewById(R.id.l_ca_cert).setVisibility(View.GONE);
@@ -278,8 +282,7 @@
     @Test
     public void isSubmittable_caCertWithoutDomain_shouldReturnFalse() {
         when(mWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_EAP);
-        mController = new TestWifiConfigController2(mConfigUiBase, mView, mWifiEntry,
-                WifiConfigUiBase2.MODE_CONNECT);
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         mView.findViewById(R.id.l_ca_cert).setVisibility(View.VISIBLE);
         final Spinner eapCaCertSpinner = mView.findViewById(R.id.ca_cert);
         eapCaCertSpinner.setAdapter(mController.getSpinnerAdapter(new String[]{"certificate"}));
@@ -292,8 +295,7 @@
     @Test
     public void isSubmittable_caCertWithDomain_shouldReturnTrue() {
         when(mWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_EAP);
-        mController = new TestWifiConfigController2(mConfigUiBase, mView, mWifiEntry,
-                WifiConfigUiBase2.MODE_CONNECT);
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         mView.findViewById(R.id.l_ca_cert).setVisibility(View.VISIBLE);
         final Spinner eapCaCertSpinner = mView.findViewById(R.id.ca_cert);
         eapCaCertSpinner.setAdapter(mController.getSpinnerAdapter(new String[]{"certificate"}));
@@ -306,6 +308,7 @@
 
     @Test
     public void getSignalString_notReachable_shouldHaveNoSignalString() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         when(mWifiEntry.getLevel()).thenReturn(WifiEntry.WIFI_LEVEL_UNREACHABLE);
 
         assertThat(mController.getSignalString()).isNull();
@@ -313,6 +316,7 @@
 
     @Test
     public void loadCertificates_undesiredCertificates_shouldNotLoadUndesiredCertificates() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         final Spinner spinner = new Spinner(mContext);
 
         mController.loadCertificates(spinner,
@@ -326,8 +330,7 @@
 
     @Test
     public void ssidGetFocus_addNewNetwork_shouldReturnTrue() {
-        mController = new TestWifiConfigController2(mConfigUiBase, mView, null /* wifiEntry */,
-                WifiConfigUiBase2.MODE_CONNECT);
+        createController(null, WifiConfigUiBase2.MODE_CONNECT, false);
         final TextView ssid = mView.findViewById(R.id.ssid);
         // Verify ssid text get focus when add new network (wifiEntry is null)
         assertThat(ssid.isFocused()).isTrue();
@@ -335,6 +338,7 @@
 
     @Test
     public void passwordGetFocus_connectSecureWifi_shouldReturnTrue() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         final TextView password = mView.findViewById(R.id.password);
         // Verify password get focus when connect to secure wifi without eap type
         assertThat(password.isFocused()).isTrue();
@@ -342,6 +346,7 @@
 
     @Test
     public void hiddenWarning_warningVisibilityProperlyUpdated() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         View warningView = mView.findViewById(R.id.hidden_settings_warning);
         mController.onItemSelected(mHiddenSettingsSpinner, null, mController.HIDDEN_NETWORK, 0);
         assertThat(warningView.getVisibility()).isEqualTo(View.VISIBLE);
@@ -355,8 +360,7 @@
         View hiddenField = mView.findViewById(R.id.hidden_settings_field);
         assertThat(hiddenField.getVisibility()).isEqualTo(View.GONE);
 
-        mController = new TestWifiConfigController2(mConfigUiBase, mView, null /* wifiEntry */,
-                WifiConfigUiBase2.MODE_CONNECT);
+        createController(null, WifiConfigUiBase2.MODE_CONNECT, false);
         assertThat(hiddenField.getVisibility()).isEqualTo(View.VISIBLE);
     }
 
@@ -382,13 +386,11 @@
 
     private void securitySpinnerTestHelper(boolean saeVisible, boolean suitebVisible,
             boolean oweVisible) {
-        WifiManager wifiManager = mock(WifiManager.class);
-        when(wifiManager.isWpa3SaeSupported()).thenReturn(saeVisible);
-        when(wifiManager.isWpa3SuiteBSupported()).thenReturn(suitebVisible);
-        when(wifiManager.isEnhancedOpenSupported()).thenReturn(oweVisible);
+        when(mWifiManager.isWpa3SaeSupported()).thenReturn(saeVisible);
+        when(mWifiManager.isWpa3SuiteBSupported()).thenReturn(suitebVisible);
+        when(mWifiManager.isEnhancedOpenSupported()).thenReturn(oweVisible);
 
-        mController = new TestWifiConfigController2(mConfigUiBase, mView, null /* wifiEntry */,
-                WifiConfigUiBase2.MODE_MODIFY, wifiManager);
+        createController(null, WifiConfigUiBase2.MODE_MODIFY, false);
 
         final Spinner securitySpinner = mView.findViewById(R.id.security);
         final ArrayAdapter<String> adapter = (ArrayAdapter) securitySpinner.getAdapter();
@@ -431,23 +433,22 @@
         }
     }
 
-    public class TestWifiConfigController2 extends WifiConfigController2 {
+    @Test
+    public void whenHideMeteredAndPrivacy_shouldHideMetered() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, true);
 
-        private TestWifiConfigController2(
-                WifiConfigUiBase2 parent, View view, WifiEntry wifiEntry, int mode) {
-            super(parent, view, wifiEntry, mode, mWifiManager);
-        }
+        View view = mView.findViewById(R.id.metered_settings_fields);
 
-        private TestWifiConfigController2(
-                WifiConfigUiBase2 parent, View view, WifiEntry wifiEntry, int mode,
-                    WifiManager wifiManager) {
-            super(parent, view, wifiEntry, mode, wifiManager);
-        }
+        assertThat(view.getVisibility()).isEqualTo(View.GONE);
+    }
 
-        @Override
-        AndroidKeystoreAliasLoader getAndroidKeystoreAliasLoader() {
-            return mAndroidKeystoreAliasLoader;
-        }
+    @Test
+    public void whenHideMeteredAndPrivacy_shouldHidePrivacy() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, true);
+
+        View view = mView.findViewById(R.id.privacy_settings_fields);
+
+        assertThat(view.getVisibility()).isEqualTo(View.GONE);
     }
 
     @Test
@@ -477,8 +478,7 @@
         when(mockWifiConfig.getIpConfiguration()).thenReturn(mock(IpConfiguration.class));
         when(mWifiEntry.getWifiConfiguration()).thenReturn(mockWifiConfig);
         mockWifiConfig.macRandomizationSetting = macRandomizedValue;
-        mController = new TestWifiConfigController2(mConfigUiBase, mView, mWifiEntry,
-                WifiConfigUiBase2.MODE_CONNECT);
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
 
         final Spinner privacySetting = mView.findViewById(R.id.privacy_settings);
         final int expectedPrefValue =
@@ -491,6 +491,7 @@
 
     @Test
     public void saveMacRandomizedValue_noChanged_shouldPersistentAsDefault() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         WifiConfiguration config = mController.getConfig();
         assertThat(config.macRandomizationSetting).isEqualTo(
                 WifiConfiguration.RANDOMIZATION_PERSISTENT);
@@ -498,6 +499,7 @@
 
     @Test
     public void saveMacRandomizedValue_ChangedToNone_shouldGetNone() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         final Spinner privacySetting = mView.findViewById(R.id.privacy_settings);
         final int prefMacNone =
                 WifiPrivacyPreferenceController2.translateMacRandomizedValueToPrefValue(
@@ -510,6 +512,7 @@
 
     @Test
     public void replaceTtsString_whenTargetMatched_shouldSuccess() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         final CharSequence[] display = {"PEAP", "AKA1", "AKA2'"};
         final CharSequence[] target = {"AKA1", "AKA2'"};
         final CharSequence[] ttsString = {"AKA1_TTS", "AKA2_TTS"};
@@ -524,6 +527,7 @@
 
     @Test
     public void replaceTtsString_whenNoTargetStringMatched_originalStringShouldNotChanged() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         final CharSequence[] display = {"PEAP", "AKA1", "AKA2"};
         final CharSequence[] target = {"WEP1", "WEP2'"};
         final CharSequence[] ttsString = {"WEP1_TTS", "WEP2_TTS"};
@@ -549,10 +553,8 @@
 
     @Test
     public void selectSecurity_wpa3Eap192bit_eapMethodTls() {
-        final WifiManager wifiManager = mock(WifiManager.class);
-        when(wifiManager.isWpa3SuiteBSupported()).thenReturn(true);
-        mController = new TestWifiConfigController2(mConfigUiBase, mView, null /* wifiEntry */,
-                WifiConfigUiBase2.MODE_MODIFY, wifiManager);
+        when(mWifiManager.isWpa3SuiteBSupported()).thenReturn(true);
+        createController(null, WifiConfigUiBase2.MODE_MODIFY, false);
         final Spinner securitySpinner = mView.findViewById(R.id.security);
         final Spinner eapMethodSpinner = mView.findViewById(R.id.method);
         int wpa3Eap192bitPosition = -1;
@@ -573,6 +575,7 @@
 
     @Test
     public void checkImeStatus_whenAdvancedToggled_shouldBeHide() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         final InputMethodManager inputMethodManager = mContext
                 .getSystemService(InputMethodManager.class);
         final ShadowInputMethodManager shadowImm = Shadows.shadowOf(inputMethodManager);
@@ -586,6 +589,7 @@
 
     @Test
     public void selectEapMethod_savedWifiEntry_shouldGetCorrectPosition() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         setUpModifyingSavedPeapConfigController();
         final Spinner eapMethodSpinner = mView.findViewById(R.id.method);
         final Spinner phase2Spinner = mView.findViewById(R.id.phase2);
@@ -630,6 +634,7 @@
 
     @Test
     public void getWepConfig_withNumberAndCharacterKey_shouldContainTheSameKey() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         final TextView password = mView.findViewById(R.id.password);
         password.setText(NUMBER_AND_CHARACTER_KEY);
         mController.mWifiEntrySecurity = WifiEntry.SECURITY_WEP;
@@ -641,6 +646,7 @@
 
     @Test
     public void getWepConfig_withPartialNumberAndCharacterKey_shouldContainDifferentKey() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         final TextView password = mView.findViewById(R.id.password);
         password.setText(PARTIAL_NUMBER_AND_CHARACTER_KEY);
         mController.mWifiEntrySecurity = WifiEntry.SECURITY_WEP;
@@ -652,6 +658,7 @@
 
     @Test
     public void getPskConfig_withValidHexKey_shouldContainTheSameKey() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         final TextView password = mView.findViewById(R.id.password);
         password.setText(VALID_HEX_PSK);
         mController.mWifiEntrySecurity = WifiEntry.SECURITY_PSK;
@@ -663,6 +670,7 @@
 
     @Test
     public void getPskConfig_withInvalidHexKey_shouldContainDifferentKey() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         final TextView password = mView.findViewById(R.id.password);
         password.setText(INVALID_HEX_PSK);
         mController.mWifiEntrySecurity = WifiEntry.SECURITY_PSK;
@@ -674,6 +682,7 @@
 
     @Test
     public void getEapConfig_withPhase2Gtc_shouldContainGtcMethod() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         setUpModifyingSavedPeapConfigController();
 
         // Test EAP method PEAP
@@ -691,6 +700,7 @@
 
     @Test
     public void getEapConfig_withPhase2Sim_shouldContainSimMethod() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         setUpModifyingSavedPeapConfigController();
 
         // Test EAP method PEAP
@@ -708,6 +718,7 @@
 
     @Test
     public void getEapConfig_withPhase2Aka_shouldContainAkaMethod() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         setUpModifyingSavedPeapConfigController();
 
         // Test EAP method PEAP
@@ -725,6 +736,7 @@
 
     @Test
     public void getEapConfig_withPhase2AkaPrime_shouldContainAkaPrimeMethod() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         setUpModifyingSavedPeapConfigController();
 
         // Test EAP method PEAP
@@ -743,6 +755,7 @@
 
     @Test
     public void getEapConfig_withPeapPhase2Unknown_shouldContainNoneMethod() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         setUpModifyingSavedPeapConfigController();
 
         // Test EAP method PEAP
@@ -760,6 +773,7 @@
 
     @Test
     public void getEapConfig_withTTLSPhase2Pap_shouldContainPapMethod() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         setUpModifyingSavedPeapConfigController();
 
         // Test EAP method TTLS
@@ -777,6 +791,7 @@
 
     @Test
     public void getEapConfig_withTTLSPhase2Mschap_shouldContainMschapMethod() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         setUpModifyingSavedPeapConfigController();
 
         // Test EAP method TTLS
@@ -794,6 +809,7 @@
 
     @Test
     public void getEapConfig_withTTLSPhase2Gtc_shouldContainGtcMethod() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         setUpModifyingSavedPeapConfigController();
 
         // Test EAP method TTLS
@@ -819,15 +835,13 @@
         when(mockWifiEnterpriseConfig.getEapMethod()).thenReturn(Eap.PEAP);
         mockWifiConfig.enterpriseConfig = mockWifiEnterpriseConfig;
         when(mWifiEntry.getWifiConfiguration()).thenReturn(mockWifiConfig);
-        mController = new TestWifiConfigController2(mConfigUiBase, mView, mWifiEntry,
-                WifiConfigUiBase2.MODE_MODIFY);
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_MODIFY, false);
     }
 
     @Test
     public void loadSims_noSim_simSpinnerDefaultNoSim() {
         when(mWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_EAP);
-        mController = new TestWifiConfigController2(mConfigUiBase, mView, mWifiEntry,
-                WifiConfigUiBase2.MODE_CONNECT);
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         mController.mEapMethodSpinner = mEapMethodSimSpinner;
 
         mController.loadSims();
@@ -847,8 +861,7 @@
         when(subscriptionInfo.getCarrierName()).thenReturn("FAKE-CARRIER");
         SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(subscriptionInfo));
         mShadowSubscriptionManager.setActiveSubscriptionInfoList(Arrays.asList(subscriptionInfo));
-        mController = new TestWifiConfigController2(mConfigUiBase, mView, mWifiEntry,
-                WifiConfigUiBase2.MODE_CONNECT);
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         mController.mEapMethodSpinner = mEapMethodSimSpinner;
 
         mController.loadSims();
@@ -864,8 +877,7 @@
         SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1, sub2));
         mShadowSubscriptionManager.setActiveSubscriptionInfoList(Arrays.asList(sub1, sub2));
         when(mWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_EAP);
-        mController = new TestWifiConfigController2(mConfigUiBase, mView, mWifiEntry,
-                WifiConfigUiBase2.MODE_CONNECT);
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         mController.mEapMethodSpinner = mEapMethodSimSpinner;
         ShadowSubscriptionManager.setDefaultDataSubscriptionId(1);
 
@@ -881,8 +893,7 @@
         SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1, sub2));
         mShadowSubscriptionManager.setActiveSubscriptionInfoList(Arrays.asList(sub1, sub2));
         when(mWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_EAP);
-        mController = new TestWifiConfigController2(mConfigUiBase, mView, mWifiEntry,
-                WifiConfigUiBase2.MODE_CONNECT);
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         mController.mEapMethodSpinner = mEapMethodSimSpinner;
         ShadowSubscriptionManager.setDefaultDataSubscriptionId(1);
 
@@ -909,6 +920,7 @@
 
     @Test
     public void onItemSelected_shouldPersistentInstallCertsAndStartInstallActivity() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         String installCertsString = "install_certs";
         Spinner eapCaCertSpinner = mock(Spinner.class);
         AdapterView view = mock(AdapterView.class);
@@ -950,6 +962,7 @@
 
     @Test
     public void getEapMinTlsVerSpinner_isTlsV13Supported_containsTlsV13() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         Spinner spinner = mController.getEapMinTlsVerSpinner(true /* isTlsV13Supported */);
 
         List<Object> list = IntStream.range(0, spinner.getAdapter().getCount())
@@ -960,6 +973,7 @@
 
     @Test
     public void getEapMinTlsVerSpinner_isNotTlsV13Supported_doesNotContainTlsV13() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         Spinner spinner = mController.getEapMinTlsVerSpinner(false /* isTlsV13Supported */);
 
         List<Object> list = IntStream.range(0, spinner.getAdapter().getCount())
@@ -970,6 +984,7 @@
 
     @Test
     public void setAnonymousIdVisible_showAnonymousIdAndSetDefaultId() {
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         View anonymousLayout = mView.findViewById(R.id.l_anonymous);
         TextView anonymousId = mView.findViewById(R.id.anonymous);
         mController.mEapAnonymousView = anonymousId;
@@ -1008,8 +1023,7 @@
                     .thenReturn(ImmutableList.of(savedUserCertificate));
         }
 
-        mController = new TestWifiConfigController2(mConfigUiBase, mView, mWifiEntry,
-                WifiConfigUiBase2.MODE_MODIFY);
+        createController(mWifiEntry, WifiConfigUiBase2.MODE_MODIFY, false);
 
         //  Because Robolectric has a different behavior from normal flow.
         //
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowDeviceConfig.java b/tests/robotests/testutils/com/android/settings/testutils/shadow/ShadowDeviceConfig.java
similarity index 100%
rename from tests/robotests/src/com/android/settings/testutils/shadow/ShadowDeviceConfig.java
rename to tests/robotests/testutils/com/android/settings/testutils/shadow/ShadowDeviceConfig.java
diff --git a/tests/spa_unit/src/com/android/settings/spa/app/appcompat/UserAspectRatioAppPreferenceTest.kt b/tests/spa_unit/src/com/android/settings/spa/app/appcompat/UserAspectRatioAppPreferenceTest.kt
index 0235a7b..265d92d 100644
--- a/tests/spa_unit/src/com/android/settings/spa/app/appcompat/UserAspectRatioAppPreferenceTest.kt
+++ b/tests/spa_unit/src/com/android/settings/spa/app/appcompat/UserAspectRatioAppPreferenceTest.kt
@@ -72,7 +72,7 @@
     private val resources = context.resources
 
     private val aspectRatioEnabledConfig =
-        TestDeviceConfig(NAMESPACE_WINDOW_MANAGER, "enable_app_compat_user_aspect_ratio_settings")
+        TestDeviceConfig(NAMESPACE_WINDOW_MANAGER, "enable_app_compat_aspect_ratio_user_settings")
 
     @Mock
     private lateinit var packageManager: PackageManager
diff --git a/tests/unit/Android.bp b/tests/unit/Android.bp
index 2ba9a29..f6a9583 100644
--- a/tests/unit/Android.bp
+++ b/tests/unit/Android.bp
@@ -21,7 +21,7 @@
     ],
 
     static_libs: [
-	"androidx.arch.core_core-testing",
+        "androidx.arch.core_core-testing",
         "androidx.test.core",
         "androidx.test.rules",
         "androidx.test.espresso.core",