Merge "Import translations. DO NOT MERGE ANYWHERE" into tm-qpr-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 1e45bf3..8334466 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1744,6 +1744,8 @@
             </intent-filter>
             <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
                        android:value="com.android.settings.security.SecurityAdvancedSettings" />
+            <meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
+                       android:value="@string/menu_key_security"/>
         </activity>
 
         <activity android:name="MonitoringCertInfoActivity"
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index a8bd35c..f8b7f00 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -1216,6 +1216,20 @@
         <item>90</item>
     </string-array>
 
+    <!-- Options for screensaver "When to start" for devices that do not support screensavers
+         while on battery -->
+    <string-array name="when_to_start_screensaver_entries_no_battery" translatable="false">
+        <item>@string/screensaver_settings_summary_sleep</item>
+        <item>@string/screensaver_settings_summary_dock_and_charging</item>
+    </string-array>
+
+    <!-- Values for screensaver "When to start" for devices that do not support screensavers
+         while on battery -->
+    <string-array name="when_to_start_screensaver_values_no_battery" translatable="false">
+        <item>while_charging_only</item>
+        <item>while_docked_only</item>
+    </string-array>
+
     <string-array name="when_to_start_screensaver_entries" translatable="false">
         <item>@string/screensaver_settings_summary_sleep</item>
         <item>@string/screensaver_settings_summary_dock</item>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index dfb9964..03a103e 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -3365,6 +3365,8 @@
     <string name="screensaver_settings_toggle_title">Use screen saver</string>
     <!-- Display settings screen, summary fragment for screen saver options, activated when docked or asleep and charging [CHAR LIMIT=35] -->
     <string name="screensaver_settings_summary_either_long">While charging or docked</string>
+    <!-- Display settings screen, summary fragment for screen saver options, actived while docked and charging [CHAR LIMIT=35] -->
+    <string name="screensaver_settings_summary_dock_and_charging">While docked and charging</string>
     <!-- Display settings screen, summary fragment for screen saver options, activated when asleep and charging [CHAR LIMIT=35] -->
     <string name="screensaver_settings_summary_sleep">While charging</string>
     <!-- Display settings screen, summary fragment for screen saver options, activated when docked [CHAR LIMIT=35] -->
diff --git a/src/com/android/settings/TetherSettings.java b/src/com/android/settings/TetherSettings.java
index 012996b..18c7855 100644
--- a/src/com/android/settings/TetherSettings.java
+++ b/src/com/android/settings/TetherSettings.java
@@ -20,6 +20,7 @@
 import static android.net.ConnectivityManager.TETHERING_USB;
 import static android.net.TetheringManager.TETHERING_ETHERNET;
 
+import static com.android.settings.wifi.WifiUtils.canShowWifiHotspot;
 import static com.android.settingslib.RestrictedLockUtilsInternal.checkIfUsbDataSignalingIsDisabled;
 
 import android.app.Activity;
@@ -589,6 +590,9 @@
 
                     if (!TetherUtil.isTetherAvailable(context)) {
                         keys.add(KEY_TETHER_PREFS_SCREEN);
+                    }
+
+                    if (!canShowWifiHotspot(context) || !TetherUtil.isTetherAvailable(context)) {
                         keys.add(KEY_WIFI_TETHER);
                     }
 
diff --git a/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragment.java b/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragment.java
index 999e34d..fa15b5c 100644
--- a/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragment.java
+++ b/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragment.java
@@ -153,8 +153,11 @@
                 controlUri = null;
             }
         }
-        use(SlicePreferenceController.class).setSliceUri(sliceEnabled ? controlUri : null);
-        use(SlicePreferenceController.class).onStart();
+        final SlicePreferenceController slicePreferenceController = use(
+                SlicePreferenceController.class);
+        slicePreferenceController.setSliceUri(sliceEnabled ? controlUri : null);
+        slicePreferenceController.onStart();
+        slicePreferenceController.displayPreference(getPreferenceScreen());
     }
 
     private final ViewTreeObserver.OnGlobalLayoutListener mOnGlobalLayoutListener =
diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
index d92fb7f..70fbefc 100644
--- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
+++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
@@ -60,6 +60,7 @@
 import com.android.settings.development.bluetooth.BluetoothSampleRateDialogPreferenceController;
 import com.android.settings.development.qstile.DevelopmentTiles;
 import com.android.settings.development.storage.SharedDataPreferenceController;
+import com.android.settings.overlay.FeatureFactory;
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settings.search.actionbar.SearchMenuController;
 import com.android.settings.widget.SettingsMainSwitchBar;
@@ -308,6 +309,8 @@
                     DisableDevSettingsDialogFragment.show(this /* host */);
                 }
             }
+            FeatureFactory.getFactory(
+                    getContext()).getSearchFeatureProvider().sendPreIndexIntent(getContext());
         }
     }
 
@@ -369,12 +372,12 @@
 
         final BluetoothLeAudioHwOffloadPreferenceController leAudioController =
                 getDevelopmentOptionsController(
-                    BluetoothLeAudioHwOffloadPreferenceController.class);
+                        BluetoothLeAudioHwOffloadPreferenceController.class);
         leAudioController.onRebootDialogConfirmed();
 
         final BluetoothLeAudioPreferenceController leAudioFeatureController =
                 getDevelopmentOptionsController(
-                    BluetoothLeAudioPreferenceController.class);
+                        BluetoothLeAudioPreferenceController.class);
         leAudioFeatureController.onRebootDialogConfirmed();
     }
 
@@ -386,12 +389,12 @@
 
         final BluetoothLeAudioHwOffloadPreferenceController leAudioController =
                 getDevelopmentOptionsController(
-                    BluetoothLeAudioHwOffloadPreferenceController.class);
+                        BluetoothLeAudioHwOffloadPreferenceController.class);
         leAudioController.onRebootDialogCanceled();
 
         final BluetoothLeAudioPreferenceController leAudioFeatureController =
                 getDevelopmentOptionsController(
-                    BluetoothLeAudioPreferenceController.class);
+                        BluetoothLeAudioPreferenceController.class);
         leAudioFeatureController.onRebootDialogCanceled();
     }
 
diff --git a/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java b/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java
index 7ddca79..6af58b5 100644
--- a/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java
@@ -240,6 +240,8 @@
         mDevHitToast = Toast.makeText(mContext, R.string.show_dev_on,
                 Toast.LENGTH_LONG);
         mDevHitToast.show();
+
+        FeatureFactory.getFactory(mContext).getSearchFeatureProvider().sendPreIndexIntent(mContext);
     }
 
     @VisibleForTesting
diff --git a/src/com/android/settings/dream/DreamSettings.java b/src/com/android/settings/dream/DreamSettings.java
index 1d12c1a..580211a 100644
--- a/src/com/android/settings/dream/DreamSettings.java
+++ b/src/com/android/settings/dream/DreamSettings.java
@@ -90,12 +90,14 @@
         }
     }
 
-    static int getDreamSettingDescriptionResId(@WhenToDream int dreamSetting) {
+    static int getDreamSettingDescriptionResId(@WhenToDream int dreamSetting,
+            boolean enabledOnBattery) {
         switch (dreamSetting) {
             case WHILE_CHARGING:
                 return R.string.screensaver_settings_summary_sleep;
             case WHILE_DOCKED:
-                return R.string.screensaver_settings_summary_dock;
+                return enabledOnBattery ? R.string.screensaver_settings_summary_dock
+                        : R.string.screensaver_settings_summary_dock_and_charging;
             case EITHER:
                 return R.string.screensaver_settings_summary_either_long;
             case NEVER:
diff --git a/src/com/android/settings/dream/WhenToDreamPicker.java b/src/com/android/settings/dream/WhenToDreamPicker.java
index 1c5e25e..13cdadf 100644
--- a/src/com/android/settings/dream/WhenToDreamPicker.java
+++ b/src/com/android/settings/dream/WhenToDreamPicker.java
@@ -32,12 +32,15 @@
 
     private static final String TAG = "WhenToDreamPicker";
     private DreamBackend mBackend;
+    private boolean mDreamsSupportedOnBattery;
 
     @Override
     public void onAttach(Context context) {
         super.onAttach(context);
 
         mBackend = DreamBackend.getInstance(context);
+        mDreamsSupportedOnBattery = getResources().getBoolean(
+                com.android.internal.R.bool.config_dreamsEnabledOnBattery);
     }
 
     @Override
@@ -69,11 +72,17 @@
     }
 
     private String[] entries() {
-        return getResources().getStringArray(R.array.when_to_start_screensaver_entries);
+        if (mDreamsSupportedOnBattery) {
+            return getResources().getStringArray(R.array.when_to_start_screensaver_entries);
+        }
+        return getResources().getStringArray(R.array.when_to_start_screensaver_entries_no_battery);
     }
 
     private String[] keys() {
-        return getResources().getStringArray(R.array.when_to_start_screensaver_values);
+        if (mDreamsSupportedOnBattery) {
+            return getResources().getStringArray(R.array.when_to_start_screensaver_values);
+        }
+        return getResources().getStringArray(R.array.when_to_start_screensaver_values_no_battery);
     }
 
     @Override
diff --git a/src/com/android/settings/dream/WhenToDreamPreferenceController.java b/src/com/android/settings/dream/WhenToDreamPreferenceController.java
index 02ae6a7..c3bae00 100644
--- a/src/com/android/settings/dream/WhenToDreamPreferenceController.java
+++ b/src/com/android/settings/dream/WhenToDreamPreferenceController.java
@@ -33,19 +33,24 @@
     private static final String WHEN_TO_START = "when_to_start";
     private final DreamBackend mBackend;
     private final boolean mDreamsDisabledByAmbientModeSuppression;
+    private final boolean mDreamsEnabledOnBattery;
 
     WhenToDreamPreferenceController(Context context) {
         this(context, context.getResources().getBoolean(
-                com.android.internal.R.bool.config_dreamsDisabledByAmbientModeSuppressionConfig));
+                com.android.internal.R.bool.config_dreamsDisabledByAmbientModeSuppressionConfig),
+                context.getResources().getBoolean(
+                        com.android.internal.R.bool.config_dreamsEnabledOnBattery));
     }
 
     @VisibleForTesting
     WhenToDreamPreferenceController(Context context,
-            boolean dreamsDisabledByAmbientModeSuppression) {
+            boolean dreamsDisabledByAmbientModeSuppression,
+            boolean dreamsEnabledOnBattery) {
         super(context);
 
         mBackend = DreamBackend.getInstance(context);
         mDreamsDisabledByAmbientModeSuppression = dreamsDisabledByAmbientModeSuppression;
+        mDreamsEnabledOnBattery = dreamsEnabledOnBattery;
     }
 
     @Override
@@ -57,7 +62,7 @@
             preference.setSummary(R.string.screensaver_settings_when_to_dream_bedtime);
         } else {
             final int resId = DreamSettings.getDreamSettingDescriptionResId(
-                    mBackend.getWhenToDreamSetting());
+                    mBackend.getWhenToDreamSetting(), mDreamsEnabledOnBattery);
             preference.setSummary(resId);
         }
     }
diff --git a/src/com/android/settings/homepage/SettingsHomepageActivity.java b/src/com/android/settings/homepage/SettingsHomepageActivity.java
index 8e14c5a..6739084 100644
--- a/src/com/android/settings/homepage/SettingsHomepageActivity.java
+++ b/src/com/android/settings/homepage/SettingsHomepageActivity.java
@@ -43,6 +43,7 @@
 import android.widget.ImageView;
 import android.widget.Toolbar;
 
+import androidx.annotation.VisibleForTesting;
 import androidx.core.graphics.Insets;
 import androidx.core.view.ViewCompat;
 import androidx.core.view.WindowCompat;
@@ -65,6 +66,7 @@
 import com.android.settings.core.FeatureFlags;
 import com.android.settings.homepage.contextualcards.ContextualCardsFragment;
 import com.android.settings.overlay.FeatureFactory;
+import com.android.settings.safetycenter.SafetyCenterManagerWrapper;
 import com.android.settingslib.Utils;
 import com.android.settingslib.core.lifecycle.HideNonSystemOverlayMixin;
 
@@ -241,10 +243,21 @@
         if (isFinishing()) {
             return;
         }
+
+        if (ActivityEmbeddingUtils.isEmbeddingActivityEnabled(this)
+                && (intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) {
+            initSplitPairRules();
+        }
+
         // Launch the intent from deep link for large screen devices.
         launchDeepLinkIntentToRight();
     }
 
+    @VisibleForTesting
+    void initSplitPairRules() {
+        new ActivityEmbeddingRulesController(getApplicationContext()).initRules();
+    }
+
     @Override
     public void onConfigurationChanged(Configuration newConfig) {
         super.onConfigurationChanged(newConfig);
@@ -479,13 +492,30 @@
             final String menuKey = intent.getStringExtra(
                     EXTRA_SETTINGS_EMBEDDED_DEEP_LINK_HIGHLIGHT_MENU_KEY);
             if (!TextUtils.isEmpty(menuKey)) {
-                return menuKey;
+                return maybeRemapMenuKey(menuKey);
             }
         }
         return getString(DEFAULT_HIGHLIGHT_MENU_KEY);
     }
 
-    private void reloadHighlightMenuKey() {
+    private String maybeRemapMenuKey(String menuKey) {
+        boolean isPrivacyOrSecurityMenuKey =
+                getString(R.string.menu_key_privacy).equals(menuKey)
+                        || getString(R.string.menu_key_security).equals(menuKey);
+        boolean isSafetyCenterMenuKey = getString(R.string.menu_key_safety_center).equals(menuKey);
+
+        if (isPrivacyOrSecurityMenuKey && SafetyCenterManagerWrapper.get().isEnabled(this)) {
+            return getString(R.string.menu_key_safety_center);
+        }
+        if (isSafetyCenterMenuKey && !SafetyCenterManagerWrapper.get().isEnabled(this)) {
+            // We don't know if security or privacy, default to security as it is above.
+            return getString(R.string.menu_key_security);
+        }
+        return menuKey;
+    }
+
+    @VisibleForTesting
+    void reloadHighlightMenuKey() {
         mMainFragment.getArguments().putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY,
                 getHighlightMenuKey());
         mMainFragment.reloadHighlightMenuKey();
diff --git a/src/com/android/settings/homepage/TopLevelSettings.java b/src/com/android/settings/homepage/TopLevelSettings.java
index 70530fc..8c122ef 100644
--- a/src/com/android/settings/homepage/TopLevelSettings.java
+++ b/src/com/android/settings/homepage/TopLevelSettings.java
@@ -43,6 +43,7 @@
 import com.android.settings.activityembedding.ActivityEmbeddingUtils;
 import com.android.settings.core.SubSettingLauncher;
 import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.overlay.FeatureFactory;
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settings.support.SupportPreferenceController;
 import com.android.settings.widget.HomepagePreference;
@@ -157,6 +158,8 @@
     public void onStart() {
         if (mFirstStarted) {
             mFirstStarted = false;
+            FeatureFactory.getFactory(getContext()).getSearchFeatureProvider().sendPreIndexIntent(
+                    getContext());
         } else if (mIsEmbeddingActivityEnabled && isOnlyOneActivityInTask()
                 && !SplitController.getInstance().isActivityEmbedded(getActivity())) {
             // Set default highlight menu key for 1-pane homepage since it will show the placeholder
@@ -346,7 +349,9 @@
     }
 
     private interface PreferenceJob {
-        default void init() {}
+        default void init() {
+        }
+
         void doForEach(Preference preference);
     }
 
diff --git a/src/com/android/settings/notification/VibrateIconPreferenceController.java b/src/com/android/settings/notification/VibrateIconPreferenceController.java
index 25d2326..d772b47 100644
--- a/src/com/android/settings/notification/VibrateIconPreferenceController.java
+++ b/src/com/android/settings/notification/VibrateIconPreferenceController.java
@@ -19,6 +19,7 @@
 import static com.android.settings.notification.SettingPref.TYPE_SECURE;
 
 import android.content.Context;
+import android.os.Vibrator;
 import android.provider.Settings.Secure;
 
 import com.android.settings.SettingsPreferenceFragment;
@@ -27,16 +28,18 @@
 public class VibrateIconPreferenceController extends SettingPrefController {
 
     private static final String KEY_VIBRATE_ICON = "vibrate_icon";
+    private final boolean mHasVibrator;
 
     public VibrateIconPreferenceController(Context context, SettingsPreferenceFragment parent,
             Lifecycle lifecycle) {
         super(context, parent, lifecycle);
+        mHasVibrator = context.getSystemService(Vibrator.class).hasVibrator();
         mPreference = new SettingPref(
             TYPE_SECURE, KEY_VIBRATE_ICON, Secure.STATUS_BAR_SHOW_VIBRATE_ICON, 0 /*default off*/);
     }
 
     @Override
     public boolean isAvailable() {
-        return true;
+        return mHasVibrator;
     }
 }
diff --git a/src/com/android/settings/search/SearchFeatureProvider.java b/src/com/android/settings/search/SearchFeatureProvider.java
index 1785361..b14a4d7 100644
--- a/src/com/android/settings/search/SearchFeatureProvider.java
+++ b/src/com/android/settings/search/SearchFeatureProvider.java
@@ -72,6 +72,12 @@
     }
 
     /**
+     * Send the pre-index intent.
+     */
+    default void sendPreIndexIntent(Context context){
+    }
+
+    /**
      * Initializes the search toolbar.
      */
     default void initSearchToolbar(FragmentActivity activity, Toolbar toolbar, int pageId) {
diff --git a/src/com/android/settings/wifi/tether/WifiTetherSettings.java b/src/com/android/settings/wifi/tether/WifiTetherSettings.java
index 1ff7746..a7ce16f 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherSettings.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherSettings.java
@@ -41,6 +41,7 @@
 import com.android.settings.dashboard.RestrictedDashboardFragment;
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settings.widget.SettingsMainSwitchBar;
+import com.android.settings.wifi.WifiUtils;
 import com.android.settingslib.TetherUtil;
 import com.android.settingslib.core.AbstractPreferenceController;
 import com.android.settingslib.search.SearchIndexable;
@@ -292,12 +293,12 @@
 
         @Override
         protected boolean isPageSearchEnabled(Context context) {
+            if (context == null || !WifiUtils.canShowWifiHotspot(context)) return false;
             return !FeatureFlagUtils.isEnabled(context, FeatureFlags.TETHER_ALL_IN_ONE);
         }
 
         @Override
-        public List<AbstractPreferenceController> createPreferenceControllers(
-                Context context) {
+        public List<AbstractPreferenceController> createPreferenceControllers(Context context) {
             return buildPreferenceControllers(context, null /* listener */);
         }
     }
diff --git a/tests/robotests/src/com/android/settings/TetherSettingsTest.java b/tests/robotests/src/com/android/settings/TetherSettingsTest.java
index 71cb9d2..79814b3 100644
--- a/tests/robotests/src/com/android/settings/TetherSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/TetherSettingsTest.java
@@ -20,6 +20,8 @@
 import static android.content.Intent.ACTION_MEDIA_UNSHARED;
 import static android.hardware.usb.UsbManager.ACTION_USB_STATE;
 
+import static com.android.settings.wifi.WifiUtils.setCanShowWifiHotspotCached;
+
 import static com.google.common.truth.Truth.assertThat;
 
 import static org.mockito.ArgumentMatchers.any;
@@ -93,6 +95,7 @@
                 any(String.class), anyInt(), any(UserHandle.class));
 
         setupIsTetherAvailable(true);
+        setCanShowWifiHotspotCached(true);
 
         when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
         when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[0]);
@@ -124,6 +127,16 @@
     }
 
     @Test
+    public void getNonIndexableKeys_canNotShowWifiHotspot_containsWifiTether() {
+        setCanShowWifiHotspotCached(false);
+        setupIsTetherAvailable(true);
+
+        List<String> keys = TetherSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
+
+        assertThat(keys).contains(TetherSettings.KEY_WIFI_TETHER);
+    }
+
+    @Test
     public void testTetherNonIndexableKeys_usbNotAvailable_usbKeyReturned() {
         when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
 
diff --git a/tests/robotests/src/com/android/settings/dream/DreamSettingsTest.java b/tests/robotests/src/com/android/settings/dream/DreamSettingsTest.java
index a554564..c1cc6ae 100644
--- a/tests/robotests/src/com/android/settings/dream/DreamSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/dream/DreamSettingsTest.java
@@ -29,33 +29,40 @@
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
 
 import java.util.Arrays;
 import java.util.List;
-import org.robolectric.RobolectricTestRunner;
 
 @RunWith(RobolectricTestRunner.class)
 public class DreamSettingsTest {
 
     private static final List<String> KEYS = Arrays.asList(
-        DreamSettings.WHILE_CHARGING_ONLY,
-        DreamSettings.WHILE_DOCKED_ONLY,
-        DreamSettings.EITHER_CHARGING_OR_DOCKED,
-        DreamSettings.NEVER_DREAM
+            DreamSettings.WHILE_CHARGING_ONLY,
+            DreamSettings.WHILE_DOCKED_ONLY,
+            DreamSettings.EITHER_CHARGING_OR_DOCKED,
+            DreamSettings.NEVER_DREAM
     );
 
     private static final @WhenToDream int[] SETTINGS = {
-        DreamBackend.WHILE_CHARGING,
-        DreamBackend.WHILE_DOCKED,
-        DreamBackend.EITHER,
-        DreamBackend.NEVER,
+            DreamBackend.WHILE_CHARGING,
+            DreamBackend.WHILE_DOCKED,
+            DreamBackend.EITHER,
+            DreamBackend.NEVER,
     };
 
     private static final int[] RES_IDS = {
-        R.string.screensaver_settings_summary_sleep,
-        R.string.screensaver_settings_summary_dock,
-        R.string.screensaver_settings_summary_either_long,
-        R.string.screensaver_settings_summary_never
+            R.string.screensaver_settings_summary_sleep,
+            R.string.screensaver_settings_summary_dock,
+            R.string.screensaver_settings_summary_either_long,
+            R.string.screensaver_settings_summary_never
+    };
+
+    private static final int[] RES_IDS_NO_BATTERY = {
+            R.string.screensaver_settings_summary_sleep,
+            R.string.screensaver_settings_summary_dock_and_charging,
+            R.string.screensaver_settings_summary_either_long,
+            R.string.screensaver_settings_summary_never
     };
 
     @Test
@@ -81,11 +88,17 @@
     @Test
     public void getDreamSettingDescriptionResId() {
         for (int i = 0; i < SETTINGS.length; i++) {
-            assertThat(DreamSettings.getDreamSettingDescriptionResId(SETTINGS[i]))
+            assertThat(DreamSettings.getDreamSettingDescriptionResId(
+                    SETTINGS[i], /* enabledOnBattery= */ false))
+                    .isEqualTo(RES_IDS_NO_BATTERY[i]);
+            assertThat(DreamSettings.getDreamSettingDescriptionResId(
+                    SETTINGS[i], /* enabledOnBattery= */ true))
                     .isEqualTo(RES_IDS[i]);
         }
         // Default
-        assertThat(DreamSettings.getDreamSettingDescriptionResId(-1))
+        assertThat(DreamSettings.getDreamSettingDescriptionResId(-1, /* enabledOnBattery= */ false))
+                .isEqualTo(R.string.screensaver_settings_summary_never);
+        assertThat(DreamSettings.getDreamSettingDescriptionResId(-1, /* enabledOnBattery= */ true))
                 .isEqualTo(R.string.screensaver_settings_summary_never);
     }
 
diff --git a/tests/robotests/src/com/android/settings/dream/WhenToDreamPickerTest.java b/tests/robotests/src/com/android/settings/dream/WhenToDreamPickerTest.java
index 16f8599..91ec299 100644
--- a/tests/robotests/src/com/android/settings/dream/WhenToDreamPickerTest.java
+++ b/tests/robotests/src/com/android/settings/dream/WhenToDreamPickerTest.java
@@ -28,6 +28,7 @@
 import androidx.test.core.app.ApplicationProvider;
 
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.shadow.SettingsShadowResources;
 import com.android.settingslib.dream.DreamBackend;
 
 import org.junit.Before;
@@ -37,9 +38,11 @@
 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)
+@Config(shadows = SettingsShadowResources.class)
 public class WhenToDreamPickerTest {
 
     private WhenToDreamPicker mPicker;
@@ -53,10 +56,15 @@
         MockitoAnnotations.initMocks(this);
         final Context context = spy(ApplicationProvider.getApplicationContext());
 
+        SettingsShadowResources.overrideResource(
+                com.android.internal.R.bool.config_dreamsEnabledOnBattery,
+                true);
+
         when(context.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
         FakeFeatureFactory.setupForTest();
 
-        mPicker = new WhenToDreamPicker();
+        mPicker = spy(new WhenToDreamPicker());
+        when(mPicker.getContext()).thenReturn(context);
         mPicker.onAttach(context);
 
         ReflectionHelpers.setField(mPicker, "mBackend", mBackend);
diff --git a/tests/robotests/src/com/android/settings/dream/WhenToDreamPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/dream/WhenToDreamPreferenceControllerTest.java
index 458c5c6..6e687bb 100644
--- a/tests/robotests/src/com/android/settings/dream/WhenToDreamPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/dream/WhenToDreamPreferenceControllerTest.java
@@ -64,7 +64,7 @@
     public void setup() throws Exception {
         MockitoAnnotations.initMocks(this);
         mContext = spy(ApplicationProvider.getApplicationContext());
-        mController = new WhenToDreamPreferenceController(mContext, true);
+        mController = new WhenToDreamPreferenceController(mContext, true, true);
         ReflectionHelpers.setField(mController, "mBackend", mBackend);
         when(mContext.getSystemService(PowerManager.class)).thenReturn(mPowerManager);
         when(mPowerManager.isAmbientDisplaySuppressedForTokenByApp(anyString(), anyInt()))
@@ -88,7 +88,7 @@
         final Preference mockPref = mock(Preference.class);
         when(mockPref.getContext()).thenReturn(mContext);
         when(mBackend.getWhenToDreamSetting()).thenReturn(testSetting);
-        final int expectedResId = DreamSettings.getDreamSettingDescriptionResId(testSetting);
+        final int expectedResId = DreamSettings.getDreamSettingDescriptionResId(testSetting, true);
 
         mController.updateState(mockPref);
         verify(mockPref).setSummary(expectedResId);
diff --git a/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java b/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java
index 4d203a8..86d6e12 100644
--- a/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java
@@ -20,12 +20,15 @@
 
 import static com.google.common.truth.Truth.assertThat;
 
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import android.app.ActivityManager;
+import android.content.Intent;
 import android.os.Build;
 import android.view.View;
 import android.view.Window;
@@ -37,6 +40,7 @@
 import com.android.settings.R;
 import com.android.settings.dashboard.suggestions.SuggestionFeatureProviderImpl;
 import com.android.settings.homepage.contextualcards.slices.BatteryFixSliceTest;
+import com.android.settings.testutils.shadow.ShadowActivityEmbeddingUtils;
 import com.android.settings.testutils.shadow.ShadowUserManager;
 import com.android.settingslib.core.lifecycle.HideNonSystemOverlayMixin;
 
@@ -195,6 +199,22 @@
                 & SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS).isEqualTo(0);
     }
 
+    /** This test is for large screen devices Activity embedding. */
+    @Test
+    @Config(shadows = ShadowActivityEmbeddingUtils.class)
+    public void onNewIntent_flagClearTop_shouldInitRules() {
+        ShadowActivityEmbeddingUtils.setIsEmbeddingActivityEnabled(true);
+        SettingsHomepageActivity activity =
+                spy(Robolectric.buildActivity(SettingsHomepageActivity.class).get());
+        doNothing().when(activity).reloadHighlightMenuKey();
+        TopLevelSettings topLevelSettings = mock(TopLevelSettings.class);
+        doReturn(topLevelSettings).when(activity).getMainFragment();
+
+        activity.onNewIntent(new Intent().setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
+
+        verify(activity).initSplitPairRules();
+    }
+
     @Implements(SuggestionFeatureProviderImpl.class)
     public static class ShadowSuggestionFeatureProviderImpl {
 
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 6d3b879..7f8a06d 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
@@ -37,6 +37,7 @@
 import android.net.wifi.WifiManager;
 import android.os.Bundle;
 import android.os.UserManager;
+import android.util.FeatureFlagUtils;
 import android.widget.TextView;
 
 import androidx.fragment.app.FragmentActivity;
@@ -44,6 +45,7 @@
 import androidx.test.core.app.ApplicationProvider;
 
 import com.android.settings.R;
+import com.android.settings.core.FeatureFlags;
 import com.android.settings.dashboard.RestrictedDashboardFragment;
 import com.android.settings.testutils.FakeFeatureFactory;
 import com.android.settings.testutils.shadow.ShadowFragment;
@@ -93,6 +95,7 @@
 
     @Before
     public void setUp() {
+        FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, false);
         setCanShowWifiHotspotCached(true);
         doReturn(mWifiManager).when(mContext).getSystemService(WifiManager.class);
         doReturn(mConnectivityManager)
@@ -218,6 +221,22 @@
         assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_MAXIMIZE_COMPATIBILITY);
     }
 
+    @Test
+    public void isPageSearchEnabled_canShowWifiHotspot_returnTrue() {
+        setCanShowWifiHotspotCached(true);
+
+        assertThat(WifiTetherSettings.SEARCH_INDEX_DATA_PROVIDER.isPageSearchEnabled(mContext))
+                .isTrue();
+    }
+
+    @Test
+    public void isPageSearchEnabled_canNotShowWifiHotspot_returnFalse() {
+        setCanShowWifiHotspotCached(false);
+
+        assertThat(WifiTetherSettings.SEARCH_INDEX_DATA_PROVIDER.isPageSearchEnabled(mContext))
+                .isFalse();
+    }
+
     private void spyWifiTetherSettings() {
         mWifiTetherSettings = spy(new WifiTetherSettings(mWifiRestriction));
         final FragmentActivity activity = mock(FragmentActivity.class);