Merge "Move rename button next to the device name" into main
diff --git a/src/com/android/settings/accessibility/ScreenFlashNotificationColorDialogFragment.java b/src/com/android/settings/accessibility/ScreenFlashNotificationColorDialogFragment.java
index 5094154..2be843c 100644
--- a/src/com/android/settings/accessibility/ScreenFlashNotificationColorDialogFragment.java
+++ b/src/com/android/settings/accessibility/ScreenFlashNotificationColorDialogFragment.java
@@ -28,11 +28,13 @@
 import android.graphics.Color;
 import android.os.Bundle;
 import android.os.UserHandle;
+import android.provider.Settings;
 import android.view.View;
 
 import androidx.annotation.ColorInt;
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
+import androidx.annotation.VisibleForTesting;
 import androidx.appcompat.app.AlertDialog;
 import androidx.fragment.app.DialogFragment;
 
@@ -40,8 +42,6 @@
 
 import java.util.Timer;
 import java.util.TimerTask;
-import java.util.function.Consumer;
-
 
 /**
  * DialogFragment for Screen flash notification color picker.
@@ -49,29 +49,33 @@
 public class ScreenFlashNotificationColorDialogFragment extends DialogFragment implements
         ColorSelectorLayout.OnCheckedChangeListener {
 
+    private static final int DEFAULT_COLOR = Color.TRANSPARENT;
     private static final int PREVIEW_LONG_TIME_MS = 5000;
     private static final int BETWEEN_STOP_AND_START_DELAY_MS = 250;
     private static final int MARGIN_FOR_STOP_DELAY_MS = 100;
 
+    @VisibleForTesting
+    static final String EXTRA_COLOR = "extra_color";
     @ColorInt
-    private int mCurrentColor = Color.TRANSPARENT;
-    private Consumer<Integer> mConsumer;
+    private int mCurrentColor = DEFAULT_COLOR;
 
     private Timer mTimer = null;
     private Boolean mIsPreview = false;
 
-    static ScreenFlashNotificationColorDialogFragment getInstance(int initialColor,
-            Consumer<Integer> colorConsumer) {
+    static ScreenFlashNotificationColorDialogFragment getInstance(int initialColor) {
         final ScreenFlashNotificationColorDialogFragment result =
                 new ScreenFlashNotificationColorDialogFragment();
-        result.mCurrentColor = initialColor;
-        result.mConsumer = colorConsumer != null ? colorConsumer : i -> {};
+        Bundle bundle = new Bundle();
+        bundle.putInt(EXTRA_COLOR, initialColor);
+        result.setArguments(bundle);
         return result;
     }
 
     @NonNull
     @Override
     public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
+        mCurrentColor = getArguments().getInt(EXTRA_COLOR, DEFAULT_COLOR);
+
         final View dialogView = getLayoutInflater().inflate(R.layout.layout_color_selector_dialog,
                 null);
 
@@ -90,7 +94,8 @@
                 })
                 .setPositiveButton(R.string.color_selector_dialog_save, (dialog, which) -> {
                     mCurrentColor = colorSelectorLayout.getCheckedColor(DEFAULT_SCREEN_FLASH_COLOR);
-                    mConsumer.accept(mCurrentColor);
+                    Settings.System.putInt(getContext().getContentResolver(),
+                            Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR, mCurrentColor);
                 })
                 .create();
         createdDialog.setOnShowListener(
diff --git a/src/com/android/settings/accessibility/ScreenFlashNotificationPreferenceController.java b/src/com/android/settings/accessibility/ScreenFlashNotificationPreferenceController.java
index bd54aca..3ebcd1c 100644
--- a/src/com/android/settings/accessibility/ScreenFlashNotificationPreferenceController.java
+++ b/src/com/android/settings/accessibility/ScreenFlashNotificationPreferenceController.java
@@ -21,10 +21,17 @@
 import static com.android.settings.accessibility.FlashNotificationsUtil.DEFAULT_SCREEN_FLASH_COLOR;
 
 import android.content.Context;
+import android.database.ContentObserver;
 import android.graphics.Color;
+import android.net.Uri;
+import android.os.Handler;
 import android.provider.Settings;
 
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
 import androidx.fragment.app.Fragment;
+import androidx.lifecycle.DefaultLifecycleObserver;
+import androidx.lifecycle.LifecycleOwner;
 import androidx.preference.Preference;
 import androidx.preference.PreferenceScreen;
 
@@ -32,18 +39,21 @@
 import com.android.settings.core.TogglePreferenceController;
 import com.android.settings.overlay.FeatureFactory;
 
-import java.util.function.Consumer;
-
 /**
  * Controller for Screen flash notification.
  */
-public class ScreenFlashNotificationPreferenceController extends TogglePreferenceController {
+public class ScreenFlashNotificationPreferenceController extends
+        TogglePreferenceController implements DefaultLifecycleObserver {
+
+    private final FlashNotificationColorContentObserver mFlashNotificationColorContentObserver;
 
     private Fragment mParentFragment;
     private Preference mPreference;
 
     public ScreenFlashNotificationPreferenceController(Context context, String preferenceKey) {
         super(context, preferenceKey);
+        mFlashNotificationColorContentObserver = new FlashNotificationColorContentObserver(
+                new Handler(mContext.getMainLooper()));
     }
 
     public void setParentFragment(Fragment parentFragment) {
@@ -51,6 +61,16 @@
     }
 
     @Override
+    public void onStart(@NonNull LifecycleOwner owner) {
+        mFlashNotificationColorContentObserver.register(mContext);
+    }
+
+    @Override
+    public void onStop(@NonNull LifecycleOwner owner) {
+        mFlashNotificationColorContentObserver.unregister(mContext);
+    }
+
+    @Override
     public int getAvailabilityStatus() {
         return AVAILABLE;
     }
@@ -100,14 +120,8 @@
                     Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR,
                     DEFAULT_SCREEN_FLASH_COLOR);
 
-            final Consumer<Integer> consumer = color -> {
-                Settings.System.putInt(mContext.getContentResolver(),
-                        Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR, color);
-                refreshColorSummary();
-            };
-
             ScreenFlashNotificationColorDialogFragment
-                    .getInstance(initialColor, consumer)
+                    .getInstance(initialColor)
                     .show(mParentFragment.getParentFragmentManager(),
                             ScreenFlashNotificationColorDialogFragment.class.getSimpleName());
             return true;
@@ -128,4 +142,37 @@
     private void refreshColorSummary() {
         if (mPreference != null) mPreference.setSummary(getSummary());
     }
+
+    private final class FlashNotificationColorContentObserver extends ContentObserver {
+        private final Uri mColorUri = Settings.System.getUriFor(
+                Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR);
+
+        FlashNotificationColorContentObserver(Handler handler) {
+            super(handler);
+        }
+
+        /**
+         * Register this observer to given {@link Context}, to be called from lifecycle
+         * {@code onStart} method.
+         */
+        public void register(@NonNull Context context) {
+            context.getContentResolver().registerContentObserver(
+                    mColorUri, /* notifyForDescendants= */ false, this);
+        }
+
+        /**
+         * Unregister this observer from given {@link Context}, to be called from lifecycle
+         * {@code onStop} method.
+         */
+        public void unregister(@NonNull Context context) {
+            context.getContentResolver().unregisterContentObserver(this);
+        }
+
+        @Override
+        public void onChange(boolean selfChange, @Nullable Uri uri) {
+            if (mColorUri.equals(uri)) {
+                refreshColorSummary();
+            }
+        }
+    }
 }
diff --git a/src/com/android/settings/network/SubscriptionsPreferenceController.java b/src/com/android/settings/network/SubscriptionsPreferenceController.java
index b7ed31e..cdbf456 100644
--- a/src/com/android/settings/network/SubscriptionsPreferenceController.java
+++ b/src/com/android/settings/network/SubscriptionsPreferenceController.java
@@ -241,6 +241,8 @@
         if (mSubsGearPref == null) {
             mPreferenceGroup.removeAll();
             mSubsGearPref = new MutableGearPreference(mContext, null);
+            mSubsGearPref
+                    .checkRestrictionAndSetDisabled(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS);
             mSubsGearPref.setOnPreferenceClickListener(preference -> {
                 connectCarrierNetwork();
                 return true;
diff --git a/src/com/android/settings/network/telephony/MobileNetworkSettings.java b/src/com/android/settings/network/telephony/MobileNetworkSettings.java
index ee1485e..a5cdb95 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkSettings.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkSettings.java
@@ -202,7 +202,6 @@
     @Override
     public void onAttach(Context context) {
         super.onAttach(context);
-
         if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
             Log.d(LOG_TAG, "Invalid subId, get the default subscription to show.");
             SubscriptionInfo info = SubscriptionUtil.getSubscriptionOrDefault(context, mSubId);
@@ -341,6 +340,11 @@
                 setTelephonyAvailabilityStatus(getPreferenceControllersAsList());
 
         super.onCreate(icicle);
+        if (isUiRestricted()) {
+            Log.d(LOG_TAG, "Mobile network page is disallowed.");
+            finish();
+            return;
+        }
         final Context context = getContext();
         mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
         mTelephonyManager = context.getSystemService(TelephonyManager.class)
diff --git a/src/com/android/settings/system/reset/ResetNetworkConfirm.kt b/src/com/android/settings/system/reset/ResetNetworkConfirm.kt
index 34b9909..e040356 100644
--- a/src/com/android/settings/system/reset/ResetNetworkConfirm.kt
+++ b/src/com/android/settings/system/reset/ResetNetworkConfirm.kt
@@ -18,6 +18,7 @@
 
 import android.app.ProgressDialog
 import android.app.settings.SettingsEnums
+import android.content.DialogInterface
 import android.os.Bundle
 import android.os.Looper
 import android.telephony.SubscriptionManager
@@ -56,7 +57,8 @@
  * This is the confirmation screen.
  */
 class ResetNetworkConfirm : InstrumentedFragment() {
-    @VisibleForTesting lateinit var resetNetworkRequest: ResetNetworkRequest
+    @VisibleForTesting
+    lateinit var resetNetworkRequest: ResetNetworkRequest
     private var progressDialog: ProgressDialog? = null
     private var alertDialog: AlertDialog? = null
     private var resetStarted = false
@@ -87,10 +89,7 @@
     /** Configure the UI for the final confirmation interaction */
     private fun View.establishFinalConfirmationState() {
         requireViewById<View>(R.id.execute_reset_network).setOnClickListener {
-            if (!Utils.isMonkeyRunning() && !resetStarted) {
-                resetStarted = true
-                viewLifecycleOwner.lifecycleScope.launch { onResetClicked() }
-            }
+            showResetInternetDialog();
         }
     }
 
@@ -118,10 +117,10 @@
     private fun invalidSubIdFlow(): Flow<Int> {
         val subIdsInRequest =
             listOf(
-                    resetNetworkRequest.resetTelephonyAndNetworkPolicyManager,
-                    resetNetworkRequest.resetApnSubId,
-                    resetNetworkRequest.resetImsSubId,
-                )
+                resetNetworkRequest.resetTelephonyAndNetworkPolicyManager,
+                resetNetworkRequest.resetApnSubId,
+                resetNetworkRequest.resetImsSubId,
+            )
                 .distinct()
                 .filter(SubscriptionManager::isUsableSubscriptionId)
 
@@ -162,6 +161,24 @@
         }
     }
 
+    private fun showResetInternetDialog() {
+        val builder = AlertDialog.Builder(requireContext())
+        val resetInternetClickListener =
+            DialogInterface.OnClickListener { dialog, which ->
+                if (!Utils.isMonkeyRunning() && !resetStarted) {
+                    resetStarted = true
+                    viewLifecycleOwner.lifecycleScope.launch { onResetClicked() }
+                }
+            }
+
+        builder.setTitle(R.string.reset_your_internet_title)
+            .setMessage(R.string.reset_internet_text)
+            .setPositiveButton(R.string.tts_reset, resetInternetClickListener)
+            .setNegativeButton(android.R.string.cancel, null)
+            .create()
+            .show()
+    }
+
     /**
      * Do all reset task.
      *
@@ -173,7 +190,8 @@
         withContext(Dispatchers.Default) {
             val builder =
                 resetNetworkRequest.toResetNetworkOperationBuilder(
-                    requireContext(), Looper.getMainLooper())
+                    requireContext(), Looper.getMainLooper()
+                )
             resetNetworkRequest.resetEsimPackageName?.let { resetEsimPackageName ->
                 builder.resetEsim(resetEsimPackageName)
                 builder.resetEsimResultCallback { resetEsimSuccess = it }
@@ -199,8 +217,8 @@
         } else {
             Toast.makeText(activity, R.string.reset_network_complete_toast, Toast.LENGTH_SHORT)
                 .show()
+            activity.finish()
         }
-        activity.finish()
     }
 
     override fun onDestroy() {
diff --git a/src/com/android/settings/widget/MutableGearPreference.java b/src/com/android/settings/widget/MutableGearPreference.java
index b0804eb..73491f0 100644
--- a/src/com/android/settings/widget/MutableGearPreference.java
+++ b/src/com/android/settings/widget/MutableGearPreference.java
@@ -41,11 +41,13 @@
 
     @Override
     public void setGearEnabled(boolean enabled) {
+        boolean state = false;
         if (mGear != null) {
-            mGear.setEnabled(enabled);
-            mGear.setImageAlpha(enabled ? VALUE_ENABLED_ALPHA : mDisabledAlphaValue);
+            state = enabled && !(isDisabledByAdmin() || isDisabledByEcm());
+            mGear.setEnabled(state);
+            mGear.setImageAlpha(state ? VALUE_ENABLED_ALPHA : mDisabledAlphaValue);
         }
-        mGearState = enabled;
+        mGearState = state;
     }
 
     @Override
diff --git a/src/com/android/settings/wifi/tether/WifiTetherSettings.java b/src/com/android/settings/wifi/tether/WifiTetherSettings.java
index 74671b5..980dee5 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherSettings.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherSettings.java
@@ -371,12 +371,20 @@
                     || !mWifiRestriction.isHotspotAvailable(context)) {
                 keys.add(KEY_WIFI_TETHER_NETWORK_NAME);
                 keys.add(KEY_WIFI_TETHER_SECURITY);
+                keys.add(KEY_WIFI_HOTSPOT_SECURITY);
                 keys.add(KEY_WIFI_TETHER_NETWORK_PASSWORD);
                 keys.add(KEY_WIFI_TETHER_AUTO_OFF);
                 keys.add(KEY_WIFI_TETHER_MAXIMIZE_COMPATIBILITY);
+                keys.add(KEY_WIFI_HOTSPOT_SPEED);
                 keys.add(KEY_INSTANT_HOTSPOT);
-            } else if (!mIsInstantHotspotEnabled) {
-                keys.add(KEY_INSTANT_HOTSPOT);
+            } else {
+                if (!isSpeedFeatureAvailable()) {
+                    keys.add(KEY_WIFI_HOTSPOT_SECURITY);
+                    keys.add(KEY_WIFI_HOTSPOT_SPEED);
+                }
+                if (!mIsInstantHotspotEnabled) {
+                    keys.add(KEY_INSTANT_HOTSPOT);
+                }
             }
 
             // Remove duplicate
@@ -400,6 +408,12 @@
         public List<AbstractPreferenceController> createPreferenceControllers(Context context) {
             return buildPreferenceControllers(context, null /* listener */);
         }
+
+        @VisibleForTesting
+        boolean isSpeedFeatureAvailable() {
+            return FeatureFactory.getFeatureFactory().getWifiFeatureProvider()
+                    .getWifiHotspotRepository().isSpeedFeatureAvailable();
+        }
     }
 
     @VisibleForTesting
diff --git a/tests/robotests/src/com/android/settings/accessibility/ScreenFlashNotificationColorDialogFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/ScreenFlashNotificationColorDialogFragmentTest.java
index f3fa69d..ea48253 100644
--- a/tests/robotests/src/com/android/settings/accessibility/ScreenFlashNotificationColorDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/ScreenFlashNotificationColorDialogFragmentTest.java
@@ -37,10 +37,13 @@
 
 import android.content.Intent;
 import android.graphics.Color;
+import android.os.Bundle;
+import android.provider.Settings;
 
 import androidx.appcompat.app.AlertDialog;
 import androidx.fragment.app.testing.FragmentScenario;
 import androidx.lifecycle.Lifecycle;
+import androidx.test.core.app.ApplicationProvider;
 
 import com.android.settings.R;
 import com.android.settings.testutils.FakeTimer;
@@ -56,23 +59,26 @@
 
 import java.util.List;
 import java.util.Timer;
-import java.util.function.Consumer;
 
 @RunWith(RobolectricTestRunner.class)
 public class ScreenFlashNotificationColorDialogFragmentTest {
 
+    private static final int DEFAULT_COLOR = ROSE.mColorInt;
+
     private FragmentScenario<TestScreenFlashNotificationColorDialogFragment> mFragmentScenario;
     private ScreenFlashNotificationColorDialogFragment mDialogFragment;
     private AlertDialog mAlertDialog;
     private ColorSelectorLayout mColorSelectorLayout;
-    private int mCurrentColor;
 
     @Before
     public void setUp() {
-        mCurrentColor = ROSE.mColorInt;
+        Settings.System.putInt(ApplicationProvider.getApplicationContext().getContentResolver(),
+                Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR, DEFAULT_COLOR);
+        Bundle fragmentArgs = new Bundle();
+        fragmentArgs.putInt(ScreenFlashNotificationColorDialogFragment.EXTRA_COLOR, DEFAULT_COLOR);
         mFragmentScenario = FragmentScenario.launch(
                 TestScreenFlashNotificationColorDialogFragment.class,
-                /* fragmentArgs= */ null,
+                fragmentArgs,
                 R.style.Theme_AlertDialog_SettingsLib,
                 Lifecycle.State.INITIALIZED);
         setupFragment();
@@ -99,7 +105,7 @@
         performClickOnDialog(BUTTON_NEUTRAL);
         getTimerFromFragment().runOneTask();
 
-        assertStartPreview(ROSE.mColorInt);
+        assertStartPreview(DEFAULT_COLOR);
     }
 
     @Test
@@ -168,20 +174,26 @@
     }
 
     @Test
-    public void clickColorAndClickNegative_assertColor() {
+    public void clickColorAndClickNegative_assertDefaultColor() {
         checkColorButton(AZURE);
         performClickOnDialog(BUTTON_NEGATIVE);
 
         assertThat(getTimerFromFragment()).isNull();
-        assertThat(mCurrentColor).isEqualTo(ROSE.mColorInt);
+        assertThat(Settings.System.getInt(
+                ApplicationProvider.getApplicationContext().getContentResolver(),
+                Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR, AZURE.mColorInt)).isEqualTo(
+                DEFAULT_COLOR);
     }
 
     @Test
-    public void clickColorAndClickPositive_assertColor() {
+    public void clickColorAndClickPositive_assertSameColor() {
         checkColorButton(BLUE);
         performClickOnDialog(BUTTON_POSITIVE);
 
-        assertThat(mCurrentColor).isEqualTo(BLUE.mColorInt);
+        assertThat(Settings.System.getInt(
+                ApplicationProvider.getApplicationContext().getContentResolver(),
+                Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR, DEFAULT_COLOR)).isEqualTo(
+                BLUE.mColorInt);
     }
 
     private void checkColorButton(ScreenFlashNotificationColor color) {
@@ -201,11 +213,6 @@
     }
 
     private void setupFragment() {
-        mFragmentScenario.onFragment(fragment -> {
-            ReflectionHelpers.setField(fragment, "mCurrentColor", mCurrentColor);
-            ReflectionHelpers.setField(fragment, "mConsumer",
-                    (Consumer<Integer>) selectedColor -> mCurrentColor = selectedColor);
-        });
         mFragmentScenario.moveToState(Lifecycle.State.RESUMED);
 
         mFragmentScenario.onFragment(fragment -> {
diff --git a/tests/robotests/src/com/android/settings/accessibility/ScreenFlashNotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/ScreenFlashNotificationPreferenceControllerTest.java
index 95a9438..d7c1a0f 100644
--- a/tests/robotests/src/com/android/settings/accessibility/ScreenFlashNotificationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/ScreenFlashNotificationPreferenceControllerTest.java
@@ -57,8 +57,6 @@
 import org.robolectric.annotation.Implements;
 import org.robolectric.annotation.Resetter;
 
-import java.util.function.Consumer;
-
 @RunWith(RobolectricTestRunner.class)
 @Config(shadows = {
         ScreenFlashNotificationPreferenceControllerTest
@@ -83,7 +81,6 @@
     private FragmentManager mFragmentManager;
     @Mock
     private ScreenFlashNotificationColorDialogFragment mDialogFragment;
-
     private ScreenFlashNotificationPreferenceController mController;
     private ContentResolver mContentResolver;
 
@@ -92,6 +89,7 @@
         MockitoAnnotations.initMocks(this);
         FragmentActivity fragmentActivity = Robolectric.setupActivity(FragmentActivity.class);
         Context context = fragmentActivity.getApplicationContext();
+
         ShadowScreenFlashNotificationColorDialogFragment.setInstance(mDialogFragment);
         ShadowFlashNotificationsUtils.setColorDescriptionText(COLOR_DESCRIPTION_TEXT);
 
@@ -99,8 +97,9 @@
         mController = new ScreenFlashNotificationPreferenceController(context, PREFERENCE_KEY);
         when(mPreferenceScreen.findPreference(PREFERENCE_KEY)).thenReturn(mPreference);
         when(mPreference.getKey()).thenReturn(PREFERENCE_KEY);
-        mController.setParentFragment(mParentFragment);
         when(mParentFragment.getParentFragmentManager()).thenReturn(mFragmentManager);
+
+        mController.setParentFragment(mParentFragment);
     }
 
     @After
@@ -181,6 +180,7 @@
     @Test
     public void handlePreferenceTreeClick() {
         mController.handlePreferenceTreeClick(mPreference);
+
         verify(mDialogFragment).show(any(FragmentManager.class), anyString());
     }
 
@@ -194,7 +194,7 @@
 
         @Implementation
         protected static ScreenFlashNotificationColorDialogFragment getInstance(
-                int initialColor, Consumer<Integer> colorConsumer) {
+                int initialColor) {
             return sInstance;
         }
 
diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
index 299d545..0bc0a32 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
@@ -263,91 +263,114 @@
 
     @Test
     public void getNonIndexableKeys_tetherAvailable_keysNotReturned() {
-        when(mWifiRestriction.isTetherAvailable(mContext)).thenReturn(true);
-        when(mWifiRestriction.isHotspotAvailable(mContext)).thenReturn(true);
-        WifiTetherSettings.SearchIndexProvider searchIndexProvider =
-                new WifiTetherSettings.SearchIndexProvider(XML_RES, mWifiRestriction,
-                        true /* isInstantHotspotEnabled */);
+        WifiTetherSettings.SearchIndexProvider searchIndexProvider = createSearchIndexProvider(
+                true /* isTetherAvailable */, true /* isHotspotAvailable */,
+                true /* isInstantHotspotEnabled */, true /* isSpeedFeatureAvailable */);
 
         final List<String> keys = searchIndexProvider.getNonIndexableKeys(mContext);
 
         assertThat(keys).doesNotContain(WifiTetherSettings.KEY_WIFI_TETHER_NETWORK_NAME);
         assertThat(keys).doesNotContain(WifiTetherSettings.KEY_WIFI_TETHER_SECURITY);
+        assertThat(keys).doesNotContain(WifiTetherSettings.KEY_WIFI_HOTSPOT_SECURITY);
+        assertThat(keys).doesNotContain(WifiTetherSettings.KEY_WIFI_TETHER_NETWORK_PASSWORD);
+        assertThat(keys).doesNotContain(WifiTetherSettings.KEY_WIFI_TETHER_AUTO_OFF);
+        assertThat(keys).doesNotContain(WifiTetherSettings.KEY_WIFI_TETHER_MAXIMIZE_COMPATIBILITY);
+        assertThat(keys).doesNotContain(WifiTetherSettings.KEY_WIFI_HOTSPOT_SPEED);
+        assertThat(keys).doesNotContain(WifiTetherSettings.KEY_INSTANT_HOTSPOT);
+    }
+
+    @Test
+    public void getNonIndexableKeys_tetherNotAvailable_keysReturned() {
+        WifiTetherSettings.SearchIndexProvider searchIndexProvider = createSearchIndexProvider(
+                false /* isTetherAvailable */, true /* isHotspotAvailable */,
+                true /* isInstantHotspotEnabled */, true /* isSpeedFeatureAvailable */);
+
+        final List<String> keys = searchIndexProvider.getNonIndexableKeys(mContext);
+
+        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_NETWORK_NAME);
+        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_SECURITY);
+        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_HOTSPOT_SECURITY);
+        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_NETWORK_PASSWORD);
+        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_AUTO_OFF);
+        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_MAXIMIZE_COMPATIBILITY);
+        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_HOTSPOT_SPEED);
+        assertThat(keys).contains(WifiTetherSettings.KEY_INSTANT_HOTSPOT);
+    }
+
+    @Test
+    public void getNonIndexableKeys_hotspotNotAvailable_keysReturned() {
+        WifiTetherSettings.SearchIndexProvider searchIndexProvider = createSearchIndexProvider(
+                true /* isTetherAvailable */, false /* isHotspotAvailable */,
+                true /* isInstantHotspotEnabled */, true /* isSpeedFeatureAvailable */);
+
+        final List<String> keys = searchIndexProvider.getNonIndexableKeys(mContext);
+
+        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_NETWORK_NAME);
+        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_SECURITY);
+        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_HOTSPOT_SECURITY);
+        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_NETWORK_PASSWORD);
+        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_AUTO_OFF);
+        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_MAXIMIZE_COMPATIBILITY);
+        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_HOTSPOT_SPEED);
+        assertThat(keys).contains(WifiTetherSettings.KEY_INSTANT_HOTSPOT);
+    }
+
+    @Test
+    public void getNonIndexableKeys_tetherAndHotspotNotAvailable_keysReturned() {
+        WifiTetherSettings.SearchIndexProvider searchIndexProvider = createSearchIndexProvider(
+                false /* isTetherAvailable */, false /* isHotspotAvailable */,
+                true /* isInstantHotspotEnabled */, true /* isSpeedFeatureAvailable */);
+
+        final List<String> keys = searchIndexProvider.getNonIndexableKeys(mContext);
+
+        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_NETWORK_NAME);
+        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_SECURITY);
+        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_HOTSPOT_SECURITY);
+        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_NETWORK_PASSWORD);
+        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_AUTO_OFF);
+        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_MAXIMIZE_COMPATIBILITY);
+        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_HOTSPOT_SPEED);
+        assertThat(keys).contains(WifiTetherSettings.KEY_INSTANT_HOTSPOT);
+    }
+
+    @Test
+    public void getNonIndexableKeys_instantHotspotNotAvailableOnly_keysContainInstantHotspotOnly() {
+        WifiTetherSettings.SearchIndexProvider searchIndexProvider = createSearchIndexProvider(
+                true /* isTetherAvailable */, true /* isHotspotAvailable */,
+                false /* isInstantHotspotEnabled */, true /* isSpeedFeatureAvailable */);
+
+        final List<String> keys = searchIndexProvider.getNonIndexableKeys(mContext);
+
+        // doesNotContain
+        assertThat(keys).doesNotContain(WifiTetherSettings.KEY_WIFI_TETHER_NETWORK_NAME);
+        assertThat(keys).doesNotContain(WifiTetherSettings.KEY_WIFI_TETHER_SECURITY);
+        assertThat(keys).doesNotContain(WifiTetherSettings.KEY_WIFI_HOTSPOT_SECURITY);
+        assertThat(keys).doesNotContain(WifiTetherSettings.KEY_WIFI_TETHER_NETWORK_PASSWORD);
+        assertThat(keys).doesNotContain(WifiTetherSettings.KEY_WIFI_TETHER_AUTO_OFF);
+        assertThat(keys).doesNotContain(WifiTetherSettings.KEY_WIFI_TETHER_MAXIMIZE_COMPATIBILITY);
+        assertThat(keys).doesNotContain(WifiTetherSettings.KEY_WIFI_HOTSPOT_SPEED);
+        // contains
+        assertThat(keys).contains(WifiTetherSettings.KEY_INSTANT_HOTSPOT);
+    }
+
+    @Test
+    public void getNonIndexableKeys_speedFeatureNotAvailableOnly_keysContainInstantHotspotOnly() {
+        WifiTetherSettings.SearchIndexProvider searchIndexProvider = createSearchIndexProvider(
+                true /* isTetherAvailable */, true /* isHotspotAvailable */,
+                true /* isInstantHotspotEnabled */, false /* isSpeedFeatureAvailable */);
+
+        final List<String> keys = searchIndexProvider.getNonIndexableKeys(mContext);
+
+        // doesNotContain
+        assertThat(keys).doesNotContain(WifiTetherSettings.KEY_WIFI_TETHER_NETWORK_NAME);
+        assertThat(keys).doesNotContain(WifiTetherSettings.KEY_WIFI_TETHER_SECURITY);
         assertThat(keys).doesNotContain(WifiTetherSettings.KEY_WIFI_TETHER_NETWORK_PASSWORD);
         assertThat(keys).doesNotContain(WifiTetherSettings.KEY_WIFI_TETHER_AUTO_OFF);
         assertThat(keys).doesNotContain(WifiTetherSettings.KEY_WIFI_TETHER_MAXIMIZE_COMPATIBILITY);
         assertThat(keys).doesNotContain(WifiTetherSettings.KEY_INSTANT_HOTSPOT);
-    }
-
-    @Test
-    public void getNonIndexableKeys_tetherNotAvailable_keysReturned() {
-        when(mWifiRestriction.isTetherAvailable(mContext)).thenReturn(false);
-        when(mWifiRestriction.isHotspotAvailable(mContext)).thenReturn(true);
-        WifiTetherSettings.SearchIndexProvider searchIndexProvider =
-                new WifiTetherSettings.SearchIndexProvider(XML_RES, mWifiRestriction,
-                        true /* isInstantHotspotEnabled */);
-
-        final List<String> keys = searchIndexProvider.getNonIndexableKeys(mContext);
-
-        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_NETWORK_NAME);
-        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_SECURITY);
-        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_NETWORK_PASSWORD);
-        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_AUTO_OFF);
-        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_MAXIMIZE_COMPATIBILITY);
-        assertThat(keys).contains(WifiTetherSettings.KEY_INSTANT_HOTSPOT);
-    }
-
-    @Test
-    public void getNonIndexableKeys_hotspotNotAvailable_keysReturned() {
-        when(mWifiRestriction.isTetherAvailable(mContext)).thenReturn(true);
-        when(mWifiRestriction.isHotspotAvailable(mContext)).thenReturn(false);
-        WifiTetherSettings.SearchIndexProvider searchIndexProvider =
-                new WifiTetherSettings.SearchIndexProvider(XML_RES, mWifiRestriction,
-                        true /* isInstantHotspotEnabled */);
-
-        final List<String> keys = searchIndexProvider.getNonIndexableKeys(mContext);
-
-        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_NETWORK_NAME);
-        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_SECURITY);
-        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_NETWORK_PASSWORD);
-        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_AUTO_OFF);
-        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_MAXIMIZE_COMPATIBILITY);
-        assertThat(keys).contains(WifiTetherSettings.KEY_INSTANT_HOTSPOT);
-    }
-
-    @Test
-    public void getNonIndexableKeys_tetherAndHotspotNotAvailable_keysReturned() {
-        when(mWifiRestriction.isTetherAvailable(mContext)).thenReturn(false);
-        when(mWifiRestriction.isHotspotAvailable(mContext)).thenReturn(false);
-        WifiTetherSettings.SearchIndexProvider searchIndexProvider =
-                new WifiTetherSettings.SearchIndexProvider(XML_RES, mWifiRestriction,
-                        true /* isInstantHotspotEnabled */);
-
-        final List<String> keys = searchIndexProvider.getNonIndexableKeys(mContext);
-
-        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_NETWORK_NAME);
-        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_SECURITY);
-        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_NETWORK_PASSWORD);
-        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_AUTO_OFF);
-        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_MAXIMIZE_COMPATIBILITY);
-    }
-
-    @Test
-    public void getNonIndexableKeys_instantHotspotNotAvailableOnly_keysContainInstantHotspotOnly() {
-        when(mWifiRestriction.isTetherAvailable(mContext)).thenReturn(true);
-        when(mWifiRestriction.isHotspotAvailable(mContext)).thenReturn(true);
-        WifiTetherSettings.SearchIndexProvider searchIndexProvider =
-                new WifiTetherSettings.SearchIndexProvider(XML_RES, mWifiRestriction,
-                        false /* isInstantHotspotEnabled */);
-
-        final List<String> keys = searchIndexProvider.getNonIndexableKeys(mContext);
-
-        assertThat(keys).doesNotContain(WifiTetherSettings.KEY_WIFI_TETHER_NETWORK_NAME);
-        assertThat(keys).doesNotContain(WifiTetherSettings.KEY_WIFI_TETHER_SECURITY);
-        assertThat(keys).doesNotContain(WifiTetherSettings.KEY_WIFI_TETHER_NETWORK_PASSWORD);
-        assertThat(keys).doesNotContain(WifiTetherSettings.KEY_WIFI_TETHER_AUTO_OFF);
-        assertThat(keys).doesNotContain(WifiTetherSettings.KEY_WIFI_TETHER_MAXIMIZE_COMPATIBILITY);
-        assertThat(keys).contains(WifiTetherSettings.KEY_INSTANT_HOTSPOT);
+        // contains
+        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_HOTSPOT_SECURITY);
+        assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_HOTSPOT_SPEED);
     }
 
     @Test
@@ -506,6 +529,18 @@
         mSettings.onCreate(Bundle.EMPTY);
     }
 
+    private WifiTetherSettings.SearchIndexProvider createSearchIndexProvider(
+            boolean isTetherAvailable, boolean isHotspotAvailable, boolean isInstantHotspotEnabled,
+            boolean isSpeedFeatureAvailable) {
+        when(mWifiRestriction.isTetherAvailable(mContext)).thenReturn(isTetherAvailable);
+        when(mWifiRestriction.isHotspotAvailable(mContext)).thenReturn(isHotspotAvailable);
+        WifiTetherSettings.SearchIndexProvider provider =
+                spy(new WifiTetherSettings.SearchIndexProvider(XML_RES, mWifiRestriction,
+                        isInstantHotspotEnabled));
+        when(provider.isSpeedFeatureAvailable()).thenReturn(isSpeedFeatureAvailable);
+        return provider;
+    }
+
     @Implements(RestrictedDashboardFragment.class)
     public static final class ShadowRestrictedDashboardFragment {
 
diff --git a/tests/unit/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivityTest.java b/tests/unit/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivityTest.java
index 4d723dc1..34c8602 100644
--- a/tests/unit/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivityTest.java
+++ b/tests/unit/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivityTest.java
@@ -20,15 +20,33 @@
 
 import static com.google.common.truth.Truth.assertThat;
 
+import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.anyInt;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.mock;
 
 import android.content.Context;
+import android.content.Intent;
 import android.os.UserManager;
+import android.platform.test.annotations.DisableFlags;
+import android.platform.test.annotations.EnableFlags;
+import android.platform.test.flag.junit.SetFlagsRule;
 
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentManager;
+import androidx.fragment.app.FragmentTransaction;
 import androidx.test.annotation.UiThreadTest;
 import androidx.test.core.app.ApplicationProvider;
 import androidx.test.ext.junit.runners.AndroidJUnit4;
 
+import com.android.settings.flags.Flags;
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.wifi.factory.WifiFeatureProvider;
+
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -44,18 +62,36 @@
 
     @Rule
     public final MockitoRule mMockitoRule = MockitoJUnit.rule();
+    @Rule
+    public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
+
     @Spy
     private final Context mContext = ApplicationProvider.getApplicationContext();
     @Mock
     private UserManager mUserManager;
+    @Mock
+    private FragmentManager mFragmentManager;
 
+    // Mock, created by FakeFeatureFactory
+    private WifiFeatureProvider mWifiFeatureProviderMock;
+
+    @Spy
     private WifiDppConfiguratorActivity mActivity;
 
     @Before
     public void setUp() {
         when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
 
-        mActivity = new WifiDppConfiguratorActivity();
+        mActivity.mFragmentManager = mFragmentManager;
+        doReturn(mContext).when(mActivity).getApplicationContext();
+
+        FragmentTransaction mockTransaction = mock(FragmentTransaction.class);
+        when(mFragmentManager.beginTransaction()).thenReturn(mockTransaction);
+        when(mockTransaction.replace(anyInt(), any(Fragment.class), anyString()))
+                .thenReturn(mockTransaction);
+
+        FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest();
+        mWifiFeatureProviderMock = featureFactory.mWifiFeatureProvider;
     }
 
     @Test
@@ -71,4 +107,37 @@
 
         assertThat(mActivity.isAddWifiConfigAllowed(mContext)).isFalse();
     }
+
+
+    @Test
+    @EnableFlags(Flags.FLAG_ENABLE_WIFI_SHARING_RUNTIME_FRAGMENT)
+    public void showQrCodeGeneratorFragment_shouldUseFeatureFactory() {
+        when(mUserManager.isGuestUser()).thenReturn(false);
+        when(mWifiFeatureProviderMock.getWifiDppQrCodeGeneratorFragment())
+                .thenReturn(new WifiDppQrCodeGeneratorFragment());
+
+        mActivity.handleIntent(createQrCodeGeneratorIntent());
+
+        verify(mWifiFeatureProviderMock).getWifiDppQrCodeGeneratorFragment();
+    }
+
+    @Test
+    @DisableFlags(Flags.FLAG_ENABLE_WIFI_SHARING_RUNTIME_FRAGMENT)
+    public void showQrCodeGeneratorFragment_shouldNotUseFeatureFactory() {
+        when(mUserManager.isGuestUser()).thenReturn(false);
+
+        mActivity.handleIntent(createQrCodeGeneratorIntent());
+
+        verify(mWifiFeatureProviderMock, never())
+                .getWifiDppQrCodeGeneratorFragment();
+    }
+
+    private static Intent createQrCodeGeneratorIntent() {
+        Intent intent = new Intent(
+                WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_GENERATOR);
+        intent.putExtra(WifiDppUtils.EXTRA_WIFI_SSID, "GoogleGuest");
+        intent.putExtra(WifiDppUtils.EXTRA_WIFI_SECURITY, "WPA");
+        intent.putExtra(WifiDppUtils.EXTRA_WIFI_PRE_SHARED_KEY, "\\012345678,");
+        return intent;
+    }
 }