Merge changes from topics "a11y_text_reading_18", "a11y_text_reading_19"

* changes:
  New feature “Text and reading options” for SetupWizard, Wallpaper, and Settings (20/n).
  New feature “Text and reading options” for SetupWizard, Wallpaper, and Settings (19/n).
  New feature “Text and reading options” for SetupWizard, Wallpaper, and Settings (18/n).
  New feature “Text and reading options” for SetupWizard, Wallpaper, and Settings (17/n).
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 92dfbe5..290f84e 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2942,24 +2942,6 @@
                 android:value="true" />
         </activity>
 
-        <activity android:name=".dream.DreamSetupActivity"
-                  android:exported="true"
-                  android:immersive="true"
-                  android:theme="@style/SudThemeGlif.DayNight"
-                  android:icon="@drawable/ic_settings_display">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN"/>
-                <category android:name="com.android.settings.suggested.category.SCREEN_SAVER"/>
-            </intent-filter>
-            <meta-data android:name="com.android.settings.is_supported"
-                       android:resource="@bool/dream_setup_supported"/>
-            <meta-data android:name="com.android.settings.title"
-                       android:resource="@string/dream_setup_title"/>
-            <meta-data android:name="com.android.settings.summary"
-                       android:resource="@string/dream_setup_description"/>
-            <meta-data android:name="com.android.settings.icon_tintable" android:value="true"/>
-        </activity>
-
         <activity
             android:name="Settings$UserSettingsActivity"
             android:label="@string/user_settings_title"
diff --git a/res/layout/dream_setup_layout.xml b/res/layout/dream_setup_layout.xml
deleted file mode 100644
index 31a0fb1..0000000
--- a/res/layout/dream_setup_layout.xml
+++ /dev/null
@@ -1,39 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-  ~ Copyright (C) 2022 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.
-  -->
-
-<com.google.android.setupdesign.GlifLayout
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto"
-    android:id="@+id/setup_wizard_layout"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:icon="@drawable/ic_settings_display"
-    app:sucHeaderText="@string/dream_setup_title"
-    app:sudDescriptionText="@string/dream_setup_description">
-
-    <RelativeLayout
-        android:id="@+id/dream_container"
-        style="@style/SudContentFrame"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent">
-        <androidx.recyclerview.widget.RecyclerView
-            android:id="@+id/dream_setup_list"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent"/>
-    </RelativeLayout>
-
-</com.google.android.setupdesign.GlifLayout>
\ No newline at end of file
diff --git a/res/values/config.xml b/res/values/config.xml
index 6a7c15b..88e7c7e 100755
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -567,7 +567,19 @@
         <item>2</item>
         <item>3</item>
     </integer-array>
-    
+
+    <!-- The settings/preference description for each settable device state defined in the array
+         "config_perDeviceStateRotationLockDefaults".
+         The item in position "i" describes the auto-rotation setting for the device state also in
+         position "i" in the array "config_perDeviceStateRotationLockDefaults". -->
+    <string-array name="config_settableAutoRotationDeviceStatesDescriptions">
+        <!-- Example:
+            <item>Auto-rotate when folded</item>
+            <item>@null</item> No description for state in position 1
+            <item>Auto-rotate when unfolded</item>
+        -->
+    </string-array>
+
     <!-- Whether to aggregate for network selection list-->
     <bool name="config_network_selection_list_aggregation_enabled">false</bool>
 
@@ -593,4 +605,5 @@
 
     <!-- Whether the dream setup activity should be enabled as part of setupwizard -->
     <bool name="dream_setup_supported">false</bool>
+
 </resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index cade521..363c4e9 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -491,6 +491,12 @@
     <!-- Category for the app's locale picker activity. [CHAR LIMIT=50]-->
     <string name="all_supported_app_locales_title">All languages</string>
 
+    <!-- Title for preference of the system default locale. [CHAR LIMIT=50]-->
+    <string name="preference_of_system_locale_title">System language</string>
+
+    <!-- Summary for preference of the system default locale. [CHAR LIMIT=50]-->
+    <string name="preference_of_system_locale_summary">System default - <xliff:g id="default_language" example="English (United States)">%1$s</xliff:g></string>
+
     <!-- Description for the app without any supported languages. [CHAR LIMIT=NONE]-->
     <string name="no_multiple_language_supported">The app is set to <xliff:g id="default_language" example="English (United States)">%1$s</xliff:g> by default and doesn\u2019t support multiple languages.</string>
     <!-- The title of the confirmation dialog shown when the user selects one / several languages and tries to remove them [CHAR LIMIT=60] -->
@@ -597,7 +603,7 @@
     <string name="date_and_time_settings_title_setup_wizard">Set date and time</string>
     <!-- Main Settings screen setting option summary text for the item to go into the date and time settings. -->
     <string name="date_and_time_settings_summary">Set date, time, time zone, &amp; formats</string>
-    <!-- Date & time setting screen setting switch title: whether the system clock (UTC time) should be determined automatically [CHAR LIMIT=100] -->
+    <!-- Date & time setting screen setting switch title: whether the system clock (Unix epoch time) should be determined automatically [CHAR LIMIT=100] -->
     <string name="date_time_auto">Set time automatically</string>
     <!-- Date & time setting screen setting switch title: whether the time zone should be determined automatically [CHAR LIMIT=100]  -->
     <string name="zone_auto_title">Set time zone automatically</string>
@@ -5248,9 +5254,11 @@
     <string name="accessibility_screen_magnification_short_summary">Tap 3 times to zoom</string>
     <!-- Short summary for nav bar Magnification. Tells the user that this feature allows the user to magnify the screen using a button in the nav bar -->
     <string name="accessibility_screen_magnification_navbar_short_summary">Tap a button to zoom</string>
+    <!-- Intro for the accessibility preference screen to enable screen magnification gestures. [CHAR LIMIT=none] -->
+    <string name="accessibility_screen_magnification_intro_text">Quickly zoom in on the screen to make content larger</string>
     <!-- Summary for the accessibility preference screen to enable screen magnification gestures. [CHAR LIMIT=none] -->
     <string name="accessibility_screen_magnification_summary">
-        <![CDATA[Quickly zoom in on the screen to make content larger.<br/><br/>
+        <![CDATA[
         <b>To zoom in:</b><br/>
         {0,number,integer}. Use shortcut to start magnification<br/>
         {1,number,integer}. Tap the screen<br/>
@@ -5258,10 +5266,11 @@
         {3,number,integer}. Pinch with 2 fingers to adjust zoom<br/>
         {4,number,integer}. Use shortcut to stop magnification<br/><br/>
         <b>To zoom in temporarily:</b><br/>
-        {0,number,integer}. Use shortcut to start magnification<br/>
-        {1,number,integer}. Touch & hold anywhere on the screen<br/>
-        {2,number,integer}. Drag finger to move around screen<br/>
-        {3,number,integer}. Lift finger to stop magnification
+        {0,number,integer}. Make sure your magnification type is set to full screen<br/>
+        {1,number,integer}. Use shortcut to start magnification<br/>
+        {2,number,integer}. Touch & hold anywhere on the screen<br/>
+        {3,number,integer}. Drag finger to move around screen<br/>
+        {4,number,integer}. Lift finger to stop magnification
         ]]>
     </string>
     <!-- Summary for the accessibility preference screen to enable screen magnification via the nav bar. [CHAR LIMIT=none] -->
@@ -5386,6 +5395,8 @@
     <string name="accessibility_button_high_label">Non-transparent</string>
     <!-- Title for the accessibility preference to high contrast text. [CHAR LIMIT=35] -->
     <string name="accessibility_toggle_high_text_contrast_preference_title">High contrast text</string>
+    <!-- Summary for the accessibility preference to high contrast text. [CHAR LIMIT=NONE] -->
+    <string name="accessibility_toggle_high_text_contrast_preference_summary">Change text color to black or white. Maximizes contrast with the background.</string>
     <!-- Title for the accessibility preference to auto update screen magnification. [CHAR LIMIT=35] -->
     <string name="accessibility_toggle_screen_magnification_auto_update_preference_title">Auto
         update screen magnification</string>
@@ -5428,7 +5439,9 @@
     <!-- Title for accessibility preference to accessibility timeout. [CHAR LIMIT=35] -->
     <string name="accessibility_control_timeout_preference_title">Time to take action</string>
     <!-- Descriptive text for accessibility preference to accessibility control timeout. [CHAR LIMIT=NONE] -->
-    <string name="accessibility_control_timeout_preference_summary">Choose how long to show messages that ask you to take action, but are visible only temporarily.\n\nNot all apps support this setting.</string>
+    <string name="accessibility_control_timeout_preference_summary">This timing preference isn\u2019t supported by all apps</string>
+    <!-- Intro text for accessibility preference to accessibility control timeout. [CHAR LIMIT=NONE] -->
+    <string name="accessibility_control_timeout_preference_intro_text">Choose how long to show temporary messages that ask you to take action</string>
 
     <!-- Title for accessibility preference to choose long-press delay i.e. timeout before it is detected. [CHAR LIMIT=35] -->
     <string name="accessibility_long_press_timeout_preference_title">Touch &amp; hold delay</string>
@@ -5438,14 +5451,15 @@
     <string name="accessibility_display_inversion_switch_title">Use color inversion</string>
     <!-- Title for accessibility shortcut preference for color inversion. [CHAR LIMIT=60] -->
     <string name="accessibility_display_inversion_shortcut_title">Color inversion shortcut</string>
+    <!-- Intro for the accessibility preference to configure display color inversion. [CHAR LIMIT=NONE] -->
+    <string name="accessibility_display_inversion_preference_intro_text">Color inversion turns light screens dark. It also turns dark screens light.</string>
     <!-- Subtitle for the accessibility preference to configure display color inversion. [CHAR LIMIT=NONE] -->
     <string name="accessibility_display_inversion_preference_subtitle">
-        <![CDATA[Color inversion turns light screens dark.<br/><br/>
-        Note:
+        <![CDATA[<b>Keep in mind</b><br/>
         <ol>
-            <li>\u00a0Color inversion also turns dark screens light.</li>
-            <li>\u00a0Colors will change in media and images.</li>
-            <li>\u00a0Dark theme can be used to display a dark background. Dark theme works with supported apps. Color inversion works on all apps.</li>
+            <li>\u00a0Colors will change in media and images</li>
+            <li>\u00a0Color inversion works on all apps</li>
+            <li>\u00a0To display a dark background, Dark theme can be used instead</li>
         </ol>
         ]]>
     </string>
@@ -5455,10 +5469,12 @@
     <string name="accessibility_autoclick_about_title">About autoclick (dwell timing)</string>
     <!-- Accessibility dwell timing footer link content description [CHAR LIMIT=NONE] -->
     <string name="accessibility_autoclick_footer_learn_more_content_description">Learn more about autoclick (dwell timing)</string>
-    <!-- Footer text to explain what autoclick does -->
-    <string name="accessibility_autoclick_description">Autoclick works with a connected mouse. You can set the mouse cursor to click automatically when the cursor stops moving for a certain amount of time.</string>
+    <!-- Intro text to explain what autoclick does. [CHAR LIMIT=NONE] -->
+    <string name="accessibility_autoclick_intro_text">You can set a connected mouse to click automatically when the cursor stops moving for a certain amount of time</string>
+    <!-- Footer text to explain what autoclick does. [CHAR LIMIT=NONE] -->
+    <string name="accessibility_autoclick_description">Autoclick can be helpful if clicking the mouse is difficult</string>
     <!-- Option heading to leave the auto click requirement for accessibility users at its default level. [CHAR LIMIT=50] -->
-    <string name="accessibility_autoclick_default_title">Off</string>
+    <string name="accessibility_autoclick_default_title">Autoclick off</string>
     <!-- Option heading to leave the auto click requirement for accessibility users at its short level. [CHAR LIMIT=35] -->
     <string name="accessibility_autoclick_short_title">Short</string>
     <!-- Option summary text for the auto click delay 0.2 seconds radio button. [CHAR LIMIT=35] -->
@@ -5511,6 +5527,10 @@
     <string name="accessibility_service_quick_settings_tooltips_content"><xliff:g id="accessibility_app_name" example="TalkBack">%1$s</xliff:g> added to Quick Settings. Swipe down to turn it on or off anytime.</string>
     <!-- Used in the accessibility action for accessibility quick settings tooltips to dismiss. [CHAR LIMIT=NONE] -->
     <string name="accessibility_quick_settings_tooltips_dismiss">Dismiss</string>
+    <!-- Intro for color correction settings screen to control turning on/off the feature entirely. [CHAR LIMIT=NONE] -->
+    <string name="accessibility_daltonizer_about_intro_text" product="default">Adjust how colors display on your phone</string>
+    <!-- Intro for color correction settings screen to control turning on/off the feature entirely. [CHAR LIMIT=NONE] -->
+    <string name="accessibility_daltonizer_about_intro_text" product="tablet">Adjust how colors display on your tablet</string>
     <!-- Used in the Color correction settings screen to control turning on/off the feature entirely [CHAR LIMIT=60] -->
     <string name="accessibility_daltonizer_primary_switch_title">Use color correction</string>
     <!-- Title for accessibility shortcut preference for color correction. [CHAR LIMIT=60] -->
@@ -5590,22 +5610,20 @@
 
     <!-- Title for the preference to show a tile for a particular feature in the Quick Settings pane. [CHAR LIMIT=NONE] -->
     <string name="enable_quick_setting">Show in Quick Settings</string>
-    <!-- Title for the preference to configure the type of color space correction to apply. [CHAR LIMIT=NONE] -->
-    <string name="daltonizer_type">Correction mode</string>
     <!-- Title shown for deuteranomaly (red-green color blindness) [CHAR LIMIT=45] -->
-    <string name="daltonizer_mode_deuteranomaly_title">Deuteranomaly</string>
+    <string name="daltonizer_mode_deuteranomaly_title">Red-green</string>
     <!-- Title shown for protanomaly (red-green color blindness) [CHAR LIMIT=45] -->
-    <string name="daltonizer_mode_protanomaly_title">Protanomaly</string>
+    <string name="daltonizer_mode_protanomaly_title">Red-green</string>
     <!-- Title shown for tritanomaly (blue-yellow color blindness) [CHAR LIMIT=45] -->
-    <string name="daltonizer_mode_tritanomaly_title">Tritanomaly</string>
+    <string name="daltonizer_mode_tritanomaly_title">Blue-yellow</string>
     <!-- Title shown for grayscale [CHAR LIMIT=45] -->
     <string name="daltonizer_mode_grayscale_title">Grayscale</string>
     <!-- Summary shown for deuteranomaly (red-green color blindness) [CHAR LIMIT=45] -->
-    <string name="daltonizer_mode_deuteranomaly_summary">Red-green</string>
+    <string name="daltonizer_mode_deuteranomaly_summary">Green weak, deuteranomaly</string>
     <!-- Summary shown for protanomaly (red-green color blindness) [CHAR LIMIT=45] -->
-    <string name="daltonizer_mode_protanomaly_summary">Red-green</string>
+    <string name="daltonizer_mode_protanomaly_summary">Red weak, protanomaly</string>
     <!-- Summary shown for tritanomaly (blue-yellow color blindness) [CHAR LIMIT=45] -->
-    <string name="daltonizer_mode_tritanomaly_summary">Blue-yellow</string>
+    <string name="daltonizer_mode_tritanomaly_summary">Tritanomaly</string>
 
     <!-- Title for the accessibility preference of the Extra Dim/Reduce Brightness feature that dims your screen. [CHAR LIMIT=NONE] -->
     <string name="reduce_bright_colors_preference_title">Extra dim</string>
@@ -5619,10 +5637,11 @@
     <string name="reduce_bright_colors_preference_summary" product="default">Dim screen beyond your phone\u2019s minimum brightness</string>
     <!-- Summary for the accessibility preference to configure Reduce Brightness feature. [CHAR LIMIT=NONE] -->
     <string name="reduce_bright_colors_preference_summary" product="tablet">Dim screen beyond your tablet\u2019s minimum brightness</string>
+    <!-- Intro that describes Reduce Brightness. [CHAR LIMIT=NONE] -->
+    <string name="reduce_bright_colors_preference_intro_text">Make your screen dimmer so it\u2019s more comfortable to read</string>
     <!-- Subtitle that describes Reduce Brightness. [CHAR LIMIT=NONE] -->
     <string name="reduce_bright_colors_preference_subtitle" product="default">
-        <![CDATA[Make your screen dimmer so it\u2019s more comfortable to read.<br/><br/>
-        This can be helpful when:
+        <![CDATA[Extra dim can be helpful when:
         <ol>
             <li>\u00a0Your phone\u2019s default minimum brightness is still too bright</li>
             <li>\u00a0You\u2019re using your phone in dark situations, like at night or in a dark room before bed</li>
@@ -5631,8 +5650,7 @@
     </string>
     <!-- Subtitle that describes Reduce Brightness. [CHAR LIMIT=NONE] -->
     <string name="reduce_bright_colors_preference_subtitle" product="tablet">
-        <![CDATA[Make your screen darker so it\u2019s more comfortable to read.<br/><br/>
-        This can be helpful when:
+        <![CDATA[Extra dim can be helpful when:
         <ol>
             <li>\u00a0Your tablet\u2019s default minimum brightness is still too bright</li>
             <li>\u00a0You\u2019re using your tablet in dark situations, like at night or in a dark room before bed</li>
diff --git a/res/xml/accessibility_autoclick_settings.xml b/res/xml/accessibility_autoclick_settings.xml
index 617f22a..943bc67 100644
--- a/res/xml/accessibility_autoclick_settings.xml
+++ b/res/xml/accessibility_autoclick_settings.xml
@@ -19,18 +19,21 @@
     xmlns:settings="http://schemas.android.com/apk/res-auto"
     android:title="@string/accessibility_autoclick_preference_title">
 
+    <com.android.settingslib.widget.TopIntroPreference
+        android:key="accessibility_autoclick_intro"
+        android:persistent="false"
+        android:title="@string/accessibility_autoclick_intro_text" />
+
     <com.android.settingslib.widget.IllustrationPreference
         android:key="accessibility_autoclick_banner"
         android:persistent="false"
         android:selectable="false"
-        settings:allowDividerBelow="true"
         settings:searchable="false"
         settings:lottie_rawRes="@drawable/accessibility_dwell" />
 
     <com.android.settingslib.widget.SelectorWithWidgetPreference
         android:key="accessibility_control_autoclick_default"
-        android:title="@string/accessibility_autoclick_default_title"
-        settings:allowDividerAbove="true" />
+        android:title="@string/accessibility_autoclick_default_title" />
 
     <com.android.settingslib.widget.SelectorWithWidgetPreference
         android:key="accessibility_control_autoclick_200ms"
@@ -56,7 +59,6 @@
         android:layout="@layout/accessibility_autoclick_custom_seekbar"
         android:selectable="false"
         android:visibility="gone"
-        settings:allowDividerBelow="true"
         settings:controller="com.android.settings.accessibility.ToggleAutoclickCustomSeekbarController" />
 
     <com.android.settings.accessibility.AccessibilityFooterPreference
diff --git a/res/xml/accessibility_control_timeout_settings.xml b/res/xml/accessibility_control_timeout_settings.xml
index aaa2c06..3cd0dd6 100644
--- a/res/xml/accessibility_control_timeout_settings.xml
+++ b/res/xml/accessibility_control_timeout_settings.xml
@@ -21,6 +21,11 @@
     android:title="@string/accessibility_control_timeout_preference_title"
     android:persistent="false" >
 
+    <com.android.settingslib.widget.TopIntroPreference
+        android:key="accessibility_control_timeout_intro"
+        android:persistent="false"
+        android:title="@string/accessibility_control_timeout_preference_intro_text" />
+
     <com.android.settingslib.widget.IllustrationPreference
         android:key="accessibility_control_timeout_banner"
         settings:lottie_rawRes="@raw/accessibility_timeout_banner"/>
@@ -28,7 +33,6 @@
     <com.android.settingslib.widget.SelectorWithWidgetPreference
         android:key="accessibility_control_timeout_default"
         android:title="@string/accessibility_timeout_default"
-        settings:allowDividerAbove="true"
         android:persistent="false" />
 
     <com.android.settingslib.widget.SelectorWithWidgetPreference
diff --git a/res/xml/accessibility_daltonizer_settings.xml b/res/xml/accessibility_daltonizer_settings.xml
index 1b69dc6..91b163b 100644
--- a/res/xml/accessibility_daltonizer_settings.xml
+++ b/res/xml/accessibility_daltonizer_settings.xml
@@ -28,32 +28,27 @@
         settings:allowDividerBelow="true"
         settings:searchable="false"/>
 
-    <PreferenceCategory
-        android:title="@string/daltonizer_type"
-        android:key="daltonizer_mode_category" >
+    <com.android.settingslib.widget.SelectorWithWidgetPreference
+        android:key="daltonizer_mode_deuteranomaly"
+        android:persistent="false"
+        android:summary="@string/daltonizer_mode_deuteranomaly_summary"
+        android:title="@string/daltonizer_mode_deuteranomaly_title" />
 
-        <com.android.settingslib.widget.SelectorWithWidgetPreference
-            android:key="daltonizer_mode_deuteranomaly"
-            android:persistent="false"
-            android:summary="@string/daltonizer_mode_deuteranomaly_summary"
-            android:title="@string/daltonizer_mode_deuteranomaly_title" />
+    <com.android.settingslib.widget.SelectorWithWidgetPreference
+        android:key="daltonizer_mode_protanomaly"
+        android:persistent="false"
+        android:summary="@string/daltonizer_mode_protanomaly_summary"
+        android:title="@string/daltonizer_mode_protanomaly_title" />
 
-        <com.android.settingslib.widget.SelectorWithWidgetPreference
-            android:key="daltonizer_mode_protanomaly"
-            android:persistent="false"
-            android:summary="@string/daltonizer_mode_protanomaly_summary"
-            android:title="@string/daltonizer_mode_protanomaly_title" />
+    <com.android.settingslib.widget.SelectorWithWidgetPreference
+        android:key="daltonizer_mode_tritanomaly"
+        android:persistent="false"
+        android:summary="@string/daltonizer_mode_tritanomaly_summary"
+        android:title="@string/daltonizer_mode_tritanomaly_title" />
 
-        <com.android.settingslib.widget.SelectorWithWidgetPreference
-            android:key="daltonizer_mode_tritanomaly"
-            android:persistent="false"
-            android:summary="@string/daltonizer_mode_tritanomaly_summary"
-            android:title="@string/daltonizer_mode_tritanomaly_title" />
-        <com.android.settingslib.widget.SelectorWithWidgetPreference
-            android:key="daltonizer_mode_grayscale"
-            android:persistent="false"
-            android:title="@string/daltonizer_mode_grayscale_title" />
-
-    </PreferenceCategory>
+    <com.android.settingslib.widget.SelectorWithWidgetPreference
+        android:key="daltonizer_mode_grayscale"
+        android:persistent="false"
+        android:title="@string/daltonizer_mode_grayscale_title" />
 
 </PreferenceScreen>
diff --git a/res/xml/accessibility_system_controls.xml b/res/xml/accessibility_system_controls.xml
index 71e1143..37c4d67 100644
--- a/res/xml/accessibility_system_controls.xml
+++ b/res/xml/accessibility_system_controls.xml
@@ -42,9 +42,22 @@
         android:title="@string/accessibility_power_button_ends_call_prerefence_title"
         settings:controller="com.android.settings.accessibility.PowerButtonEndsCallPreferenceController"/>
 
+    <!-- Standard auto-rotation preference that will be shown when device state based auto-rotation
+         settings are NOT available. -->
     <SwitchPreference
         android:key="toggle_lock_screen_rotation_preference"
         android:persistent="false"
         android:title="@string/accelerometer_title"
         settings:controller="com.android.settings.accessibility.LockScreenRotationPreferenceController"/>
+
+    <!-- Auto-rotation preference that will be shown when device state based auto-rotation settings
+         are available. -->
+    <Preference
+        android:key="device_state_auto_rotate_accessibility"
+        android:persistent="false"
+        android:title="@string/accelerometer_title"
+        android:fragment="com.android.settings.display.DeviceStateAutoRotateDetailsFragment"
+        settings:keywords="@string/keywords_auto_rotate"
+        settings:controller="com.android.settings.display.DeviceStateAutoRotateOverviewController"/>
+
 </PreferenceScreen>
diff --git a/res/xml/accessibility_text_reading_options.xml b/res/xml/accessibility_text_reading_options.xml
index 7d81565..d55882d 100644
--- a/res/xml/accessibility_text_reading_options.xml
+++ b/res/xml/accessibility_text_reading_options.xml
@@ -54,6 +54,7 @@
     <SwitchPreference
         android:key="toggle_high_text_contrast_preference"
         android:persistent="false"
+        android:summary="@string/accessibility_toggle_high_text_contrast_preference_summary"
         android:title="@string/accessibility_toggle_high_text_contrast_preference_title" />
 
     <com.android.settingslib.widget.LayoutPreference
diff --git a/res/xml/app_locale_details.xml b/res/xml/app_locale_details.xml
index 8056cbf..40ca582 100644
--- a/res/xml/app_locale_details.xml
+++ b/res/xml/app_locale_details.xml
@@ -28,7 +28,14 @@
 
     <PreferenceCategory
         android:key="category_key_suggested_languages"
-        android:title="@string/suggested_app_locales_title" />
+        android:title="@string/suggested_app_locales_title" >
+
+        <com.android.settingslib.widget.RadioButtonPreference
+            android:key="system_default_locale"
+            android:title="@string/preference_of_system_locale_title"
+            android:order="-10000"/>
+
+    </PreferenceCategory>
 
     <PreferenceCategory
         android:key="category_key_all_languages"
diff --git a/res/xml/device_state_auto_rotate_settings.xml b/res/xml/device_state_auto_rotate_settings.xml
new file mode 100644
index 0000000..2ddb4c7
--- /dev/null
+++ b/res/xml/device_state_auto_rotate_settings.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2022 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.
+-->
+
+<PreferenceScreen
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:title="@string/accelerometer_title" >
+
+    <!-- Device state based auto-rotation preferences will be added programmatically here.  -->
+
+</PreferenceScreen>
diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml
index 328e15c..88f8bf1 100644
--- a/res/xml/display_settings.xml
+++ b/res/xml/display_settings.xml
@@ -103,12 +103,27 @@
     <PreferenceCategory
         android:title="@string/category_name_display_controls">
 
+        <!--
+            Standard auto-rotation preference that will be shown when device state based
+            auto-rotation settings are NOT available.
+          -->
         <SwitchPreference
             android:key="auto_rotate"
             android:title="@string/accelerometer_title"
             settings:keywords="@string/keywords_auto_rotate"
             settings:controller="com.android.settings.display.AutoRotatePreferenceController"/>
 
+        <!--
+            Auto-rotation preference that will be shown when device state based auto-rotation
+            settings are available.
+          -->
+        <Preference
+            android:key="device_state_auto_rotate"
+            android:title="@string/accelerometer_title"
+            android:fragment="com.android.settings.display.DeviceStateAutoRotateDetailsFragment"
+            settings:keywords="@string/keywords_auto_rotate"
+            settings:controller="com.android.settings.display.DeviceStateAutoRotateOverviewController"/>
+
         <SwitchPreference
             android:key="display_white_balance"
             android:title="@string/display_white_balance_title"
diff --git a/res/xml/language_and_input.xml b/res/xml/language_and_input.xml
index c99d591..770a862 100644
--- a/res/xml/language_and_input.xml
+++ b/res/xml/language_and_input.xml
@@ -25,7 +25,6 @@
         <Preference
             android:key="phone_language"
             android:title="@string/phone_language"
-            android:icon="@drawable/ic_translate_24dp"
             android:fragment="com.android.settings.localepicker.LocaleListEditor" />
 
         <Preference
diff --git a/src/com/android/settings/accessibility/LockScreenRotationPreferenceController.java b/src/com/android/settings/accessibility/LockScreenRotationPreferenceController.java
index 5ed4b5c..a1c292a 100644
--- a/src/com/android/settings/accessibility/LockScreenRotationPreferenceController.java
+++ b/src/com/android/settings/accessibility/LockScreenRotationPreferenceController.java
@@ -25,6 +25,7 @@
 import com.android.internal.view.RotationPolicy.RotationPolicyListener;
 import com.android.settings.R;
 import com.android.settings.core.TogglePreferenceController;
+import com.android.settings.display.DeviceStateAutoRotationHelper;
 import com.android.settingslib.core.lifecycle.LifecycleObserver;
 import com.android.settingslib.core.lifecycle.events.OnStart;
 import com.android.settingslib.core.lifecycle.events.OnStop;
@@ -59,7 +60,9 @@
 
     @Override
     public int getAvailabilityStatus() {
-        return RotationPolicy.isRotationSupported(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+        return RotationPolicy.isRotationSupported(mContext)
+                && !DeviceStateAutoRotationHelper.isDeviceStateRotationEnabledForA11y(mContext)
+                ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
     }
 
     @Override
diff --git a/src/com/android/settings/accessibility/MagnificationGesturesPreferenceController.java b/src/com/android/settings/accessibility/MagnificationGesturesPreferenceController.java
index 37d09a7..01ee249 100644
--- a/src/com/android/settings/accessibility/MagnificationGesturesPreferenceController.java
+++ b/src/com/android/settings/accessibility/MagnificationGesturesPreferenceController.java
@@ -100,7 +100,10 @@
         extras.putInt(AccessibilitySettings.EXTRA_TITLE_RES,
                 R.string.accessibility_screen_magnification_gestures_title);
 
-        String summary =  context.getString(R.string.accessibility_screen_magnification_summary);
+        String intro = context.getString(R.string.accessibility_screen_magnification_intro_text);
+        extras.putCharSequence(AccessibilitySettings.EXTRA_INTRO, intro);
+
+        String summary = context.getString(R.string.accessibility_screen_magnification_summary);
         final Object[] numberArguments = {1, 2, 3, 4, 5};
         summary = MessageFormat.format(summary, numberArguments);
         extras.putCharSequence(AccessibilitySettings.EXTRA_HTML_DESCRIPTION, summary);
diff --git a/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java
index 679e284..e421626 100644
--- a/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java
@@ -82,6 +82,7 @@
         mComponentName = COLOR_INVERSION_COMPONENT_NAME;
         mPackageName = getText(R.string.accessibility_display_inversion_preference_title);
         mHtmlDescription = getText(R.string.accessibility_display_inversion_preference_subtitle);
+        mTopIntroTitle = getText(R.string.accessibility_display_inversion_preference_intro_text);
         mImageUri = new Uri.Builder().scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
                 .authority(getPrefContext().getPackageName())
                 .appendPath(String.valueOf(R.raw.accessibility_color_inversion_banner))
diff --git a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
index 5d9cbe5..b1b9f81 100644
--- a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
@@ -51,7 +51,10 @@
 
     private static final String ENABLED = Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED;
     private static final String KEY_PREVIEW = "daltonizer_preview";
-    private static final String KEY_CATEGORY_MODE = "daltonizer_mode_category";
+    private static final String KEY_DEUTERANOMALY = "daltonizer_mode_deuteranomaly";
+    private static final String KEY_PROTANOMALY = "daltonizer_mode_protanomaly";
+    private static final String KEY_TRITANOMEALY = "daltonizer_mode_tritanomaly";
+    private static final String KEY_GRAYSCALE = "daltonizer_mode_grayscale";
     private static final List<AbstractPreferenceController> sControllers = new ArrayList<>();
 
     private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
@@ -82,6 +85,7 @@
         mComponentName = DALTONIZER_COMPONENT_NAME;
         mPackageName = getText(R.string.accessibility_display_daltonizer_preference_title);
         mHtmlDescription = getText(R.string.accessibility_display_daltonizer_preference_subtitle);
+        mTopIntroTitle = getText(R.string.accessibility_daltonizer_about_intro_text);
         final View view = super.onCreateView(inflater, container, savedInstanceState);
         updateFooterPreference();
         return view;
@@ -111,9 +115,13 @@
     /** Customizes the order by preference key. */
     protected List<String> getPreferenceOrderList() {
         final List<String> lists = new ArrayList<>();
+        lists.add(KEY_TOP_INTRO_PREFERENCE);
         lists.add(KEY_PREVIEW);
         lists.add(KEY_USE_SERVICE_PREFERENCE);
-        lists.add(KEY_CATEGORY_MODE);
+        lists.add(KEY_DEUTERANOMALY);
+        lists.add(KEY_PROTANOMALY);
+        lists.add(KEY_TRITANOMEALY);
+        lists.add(KEY_GRAYSCALE);
         lists.add(KEY_GENERAL_CATEGORY);
         lists.add(KEY_HTML_DESCRIPTION_PREFERENCE);
         return lists;
diff --git a/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
index 973e27c..1e2e9e5 100644
--- a/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
@@ -68,6 +68,7 @@
         mComponentName = REDUCE_BRIGHT_COLORS_COMPONENT_NAME;
         mPackageName = getText(R.string.reduce_bright_colors_preference_title);
         mHtmlDescription = getText(R.string.reduce_bright_colors_preference_subtitle);
+        mTopIntroTitle = getText(R.string.reduce_bright_colors_preference_intro_text);
         mRbcIntensityPreferenceController =
                 new ReduceBrightColorsIntensityPreferenceController(getContext(), KEY_INTENSITY);
         mRbcPersistencePreferenceController =
diff --git a/src/com/android/settings/applications/appinfo/AppLocaleDetails.java b/src/com/android/settings/applications/appinfo/AppLocaleDetails.java
index 164cfd9..8f1c212 100644
--- a/src/com/android/settings/applications/appinfo/AppLocaleDetails.java
+++ b/src/com/android/settings/applications/appinfo/AppLocaleDetails.java
@@ -38,8 +38,6 @@
 import androidx.preference.Preference;
 import androidx.preference.PreferenceGroup;
 
-import com.android.internal.app.LocalePicker;
-import com.android.internal.app.LocalePicker.LocaleInfo;
 import com.android.settings.R;
 import com.android.settings.Utils;
 import com.android.settings.applications.AppInfoBase;
@@ -48,11 +46,8 @@
 import com.android.settingslib.widget.LayoutPreference;
 import com.android.settingslib.widget.RadioButtonPreference;
 
-import com.google.common.collect.Iterables;
-
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.List;
 import java.util.Locale;
 
 /**
@@ -66,13 +61,17 @@
     private static final String CATEGORY_KEY_ALL_LANGUAGES =
             "category_key_all_languages";
     private static final String KEY_APP_DESCRIPTION = "app_locale_description";
+    @VisibleForTesting
+    static final String KEY_SYSTEM_DEFAULT_LOCALE = "system_default_locale";
 
     private boolean mCreated = false;
-    private AppLocaleDetailsHelper mAppLocaleDetailsHelper;
+    @VisibleForTesting
+    AppLocaleDetailsHelper mAppLocaleDetailsHelper;
 
     private PreferenceGroup mGroupOfSuggestedLocales;
     private PreferenceGroup mGroupOfSupportedLocales;
     private LayoutPreference mPrefOfDescription;
+    private RadioButtonPreference mDefaultPreference;
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
@@ -85,6 +84,10 @@
         mGroupOfSupportedLocales =
                 getPreferenceScreen().findPreference(CATEGORY_KEY_ALL_LANGUAGES);
         mPrefOfDescription = getPreferenceScreen().findPreference(KEY_APP_DESCRIPTION);
+
+        mDefaultPreference = (RadioButtonPreference) getPreferenceScreen()
+                .findPreference(KEY_SYSTEM_DEFAULT_LOCALE);
+        mDefaultPreference.setOnClickListener(this);
     }
 
     // Override here so we don't have an empty screen
@@ -104,30 +107,43 @@
         // Update Locales first, before refresh ui.
         mAppLocaleDetailsHelper.handleAllLocalesData();
         super.onResume();
+        mDefaultPreference.setSummary(Locale.getDefault().getDisplayName(Locale.getDefault()));
     }
 
     @Override
     protected boolean refreshUi() {
+        refreshUiInternal();
+        return true;
+    }
+
+    @VisibleForTesting
+    void refreshUiInternal() {
         if (mAppLocaleDetailsHelper.getSupportedLocales().isEmpty()) {
             Log.d(TAG, "No supported language.");
             mGroupOfSuggestedLocales.setVisible(false);
             mGroupOfSupportedLocales.setVisible(false);
             mPrefOfDescription.setVisible(true);
             TextView description = (TextView) mPrefOfDescription.findViewById(R.id.description);
-            Locale locale = mAppLocaleDetailsHelper.getCurrentSystemLocales().get(0);
             description.setText(getContext().getString(R.string.no_multiple_language_supported,
-                    locale.getDisplayName(locale)));
-            return true;
+                    Locale.getDefault().getDisplayName(Locale.getDefault())));
+            return;
         }
-
-        mGroupOfSuggestedLocales.removeAll();
-        mGroupOfSupportedLocales.removeAll();
+        resetLocalePreferences();
         Locale appLocale = AppLocaleDetailsHelper.getAppDefaultLocale(getContext(), mPackageName);
+        // Sets up default locale preference.
+        mGroupOfSuggestedLocales.addPreference(mDefaultPreference);
+        mDefaultPreference.setChecked(appLocale == null);
+        // Sets up suggested locales of per app.
         setLanguagesPreference(mGroupOfSuggestedLocales,
                 mAppLocaleDetailsHelper.getSuggestedLocales(), appLocale);
+        // Sets up supported locales of per app.
         setLanguagesPreference(mGroupOfSupportedLocales,
                 mAppLocaleDetailsHelper.getSupportedLocales(), appLocale);
-        return true;
+    }
+
+    private void resetLocalePreferences() {
+        mGroupOfSuggestedLocales.removeAll();
+        mGroupOfSupportedLocales.removeAll();
     }
 
     @Override
@@ -142,7 +158,12 @@
 
     @Override
     public void onRadioButtonClicked(RadioButtonPreference pref) {
-        mAppLocaleDetailsHelper.setAppDefaultLocale(pref.getKey());
+        String key = pref.getKey();
+        if (KEY_SYSTEM_DEFAULT_LOCALE.equals(key)) {
+            mAppLocaleDetailsHelper.setAppDefaultLocale(LocaleList.forLanguageTags(""));
+        } else {
+            mAppLocaleDetailsHelper.setAppDefaultLocale(key);
+        }
         refreshUi();
     }
 
@@ -180,7 +201,13 @@
     public static CharSequence getSummary(Context context, String packageName) {
         Locale appLocale =
                 AppLocaleDetailsHelper.getAppDefaultLocale(context, packageName);
-        return appLocale == null ? "" : appLocale.getDisplayName(appLocale);
+        if (appLocale == null) {
+            Locale systemLocale = Locale.getDefault();
+            return context.getString(R.string.preference_of_system_locale_summary,
+                    systemLocale.getDisplayName(systemLocale));
+        } else {
+            return appLocale.getDisplayName(appLocale);
+        }
     }
 
     private void setLanguagesPreference(PreferenceGroup group,
@@ -190,9 +217,15 @@
         }
 
         for (Locale locale : locales) {
+            if (locale == null) {
+                continue;
+            }
+
             RadioButtonPreference pref = new RadioButtonPreference(getContext());
             pref.setTitle(locale.getDisplayName(locale));
             pref.setKey(locale.toLanguageTag());
+            // Will never be checked if appLocale is null
+            // aka if there is no per-app locale
             pref.setChecked(locale.equals(appLocale));
             pref.setOnClickListener(this);
             group.addPreference(pref);
@@ -206,14 +239,17 @@
         private TelephonyManager mTelephonyManager;
         private LocaleManager mLocaleManager;
 
-        private Collection<Locale> mSuggestedLocales = new ArrayList<>();
-        private Collection<Locale> mSupportedLocales = new ArrayList<>();
+        private Collection<Locale> mProcessedSuggestedLocales = new ArrayList<>();
+        private Collection<Locale> mProcessedSupportedLocales = new ArrayList<>();
+
+        private Collection<Locale> mAppSupportedLocales = new ArrayList<>();
 
         AppLocaleDetailsHelper(Context context, String packageName) {
             mContext = context;
             mPackageName = packageName;
             mTelephonyManager = context.getSystemService(TelephonyManager.class);
             mLocaleManager = context.getSystemService(LocaleManager.class);
+            mAppSupportedLocales = getAppSupportedLocales();
         }
 
         /** Handle suggested and supported locales for UI display. */
@@ -225,49 +261,47 @@
 
         /** Gets suggested locales in the app. */
         public Collection<Locale> getSuggestedLocales() {
-            return mSuggestedLocales;
+            return mProcessedSuggestedLocales;
         }
 
         /** Gets supported locales in the app. */
         public Collection<Locale> getSupportedLocales() {
-            return mSupportedLocales;
+            return mProcessedSupportedLocales;
         }
 
         @VisibleForTesting
         void handleSuggestedLocales() {
-            LocaleList currentSystemLocales = getCurrentSystemLocales();
             Locale appLocale = getAppDefaultLocale(mContext, mPackageName);
+            // 1st locale in suggested languages group.
+            for (Locale supportedlocale : mAppSupportedLocales) {
+                if (compareLocale(supportedlocale, appLocale)) {
+                    mProcessedSuggestedLocales.add(appLocale);
+                    break;
+                }
+            }
+
+            // 2nd and 3rd locale in suggested languages group.
             String simCountry = mTelephonyManager.getSimCountryIso().toUpperCase(Locale.US);
             String networkCountry = mTelephonyManager.getNetworkCountryIso().toUpperCase(Locale.US);
-            // 1st locale in suggested languages group.
-            if (appLocale != null) {
-                mSuggestedLocales.add(appLocale);
-            }
-            // 2nd locale in suggested languages group.
-            final List<LocaleInfo> localeInfos = LocalePicker.getAllAssetLocales(mContext, false);
-            for (LocaleInfo localeInfo : localeInfos) {
-                Locale locale = localeInfo.getLocale();
-                String localeCountry = locale.getCountry().toUpperCase(Locale.US);
-                if (!compareLocale(locale, appLocale)
+            mAppSupportedLocales.forEach(supportedlocale -> {
+                String localeCountry = supportedlocale.getCountry().toUpperCase(Locale.US);
+                if (!compareLocale(supportedlocale, appLocale)
                         && isCountrySuggestedLocale(localeCountry, simCountry, networkCountry)) {
-                    mSuggestedLocales.add(locale);
+                    mProcessedSuggestedLocales.add(supportedlocale);
                 }
-            }
+            });
+
             // Other locales in suggested languages group.
-            for (int i = 0; i < currentSystemLocales.size(); i++) {
-                Locale locale = currentSystemLocales.get(i);
-                boolean isInSuggestedLocales = false;
-                for (int j = 0; j < mSuggestedLocales.size(); j++) {
-                    Locale suggestedLocale = Iterables.get(mSuggestedLocales, j);
-                    if (compareLocale(locale, suggestedLocale)) {
-                        isInSuggestedLocales = true;
-                        break;
+            Collection<Locale> supportedSystemLocales = new ArrayList<>();
+            getCurrentSystemLocales().forEach(systemLocale -> {
+                mAppSupportedLocales.forEach(supportedLocale -> {
+                    if (compareLocale(systemLocale, supportedLocale)) {
+                        supportedSystemLocales.add(supportedLocale);
                     }
-                }
-                if (!isInSuggestedLocales) {
-                    mSuggestedLocales.add(locale);
-                }
-            }
+                });
+            });
+            supportedSystemLocales.removeAll(mProcessedSuggestedLocales);
+            mProcessedSuggestedLocales.addAll(supportedSystemLocales);
         }
 
         @VisibleForTesting
@@ -290,26 +324,34 @@
 
         @VisibleForTesting
         void handleSupportedLocales() {
-            LocaleList localeList = getPackageLocales();
-            if (localeList == null) {
-                String[] languages = getAssetSystemLocales();
-                for (String language : languages) {
-                    mSupportedLocales.add(Locale.forLanguageTag(language));
-                }
-            } else {
-                for (int i = 0; i < localeList.size(); i++) {
-                    mSupportedLocales.add(localeList.get(i));
-                }
-            }
+            mProcessedSupportedLocales.addAll(mAppSupportedLocales);
 
-            if (mSuggestedLocales != null || !mSuggestedLocales.isEmpty()) {
-                mSupportedLocales.removeAll(mSuggestedLocales);
+            if (mProcessedSuggestedLocales != null || !mProcessedSuggestedLocales.isEmpty()) {
+                mProcessedSuggestedLocales.retainAll(mProcessedSupportedLocales);
+                mProcessedSupportedLocales.removeAll(mProcessedSuggestedLocales);
             }
         }
 
         private void clearLocalesData() {
-            mSuggestedLocales.clear();
-            mSupportedLocales.clear();
+            mProcessedSuggestedLocales.clear();
+            mProcessedSupportedLocales.clear();
+        }
+
+        private Collection<Locale> getAppSupportedLocales() {
+            Collection<Locale> appSupportedLocales = new ArrayList<>();
+            LocaleList localeList = getPackageLocales();
+
+            if (localeList != null && localeList.size() > 0) {
+                for (int i = 0; i < localeList.size(); i++) {
+                    appSupportedLocales.add(localeList.get(i));
+                }
+            } else {
+                String[] languages = getAssetLocales();
+                for (String language : languages) {
+                    appSupportedLocales.add(Locale.forLanguageTag(language));
+                }
+            }
+            return appSupportedLocales;
         }
 
         /** Gets per app's default locale */
@@ -317,8 +359,8 @@
             LocaleManager localeManager = context.getSystemService(LocaleManager.class);
             try {
                 LocaleList localeList = (localeManager == null)
-                        ? new LocaleList() : localeManager.getApplicationLocales(packageName);
-                return localeList.isEmpty() ? null : localeList.get(0);
+                        ? null : localeManager.getApplicationLocales(packageName);
+                return localeList == null ? null : localeList.get(0);
             } catch (IllegalArgumentException e) {
                 Log.w(TAG, "package name : " + packageName + " is not correct. " + e);
             }
@@ -344,12 +386,17 @@
         }
 
         @VisibleForTesting
-        LocaleList getCurrentSystemLocales() {
-            return Resources.getSystem().getConfiguration().getLocales();
+        Collection<Locale> getCurrentSystemLocales() {
+            LocaleList localeList = Resources.getSystem().getConfiguration().getLocales();
+            Collection<Locale> systemLocales = new ArrayList<>();
+            for (int i = 0; i < localeList.size(); i++) {
+                systemLocales.add(localeList.get(i));
+            }
+            return systemLocales;
         }
 
         @VisibleForTesting
-        String[] getAssetSystemLocales() {
+        String[] getAssetLocales() {
             try {
                 PackageManager packageManager = mContext.getPackageManager();
                 return packageManager.getResourcesForApplication(
diff --git a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
index cdac3b9..8ad66d2 100644
--- a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
+++ b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
@@ -171,11 +171,13 @@
                     intent.setAction(action);
                 }
                 // Register the rule for injected apps.
-                ActivityEmbeddingRulesController.registerTwoPanePairRuleForSettingsHome(
-                        mContext,
-                        new ComponentName(tile.getPackageName(), tile.getComponentName()),
-                        action,
-                        true /* clearTop */);
+                if (fragment instanceof TopLevelSettings) {
+                    ActivityEmbeddingRulesController.registerTwoPanePairRuleForSettingsHome(
+                            mContext,
+                            new ComponentName(tile.getPackageName(), tile.getComponentName()),
+                            action,
+                            true /* clearTop */);
+                }
                 pref.setOnPreferenceClickListener(preference -> {
                     TopLevelHighlightMixin highlightMixin = null;
                     if (fragment instanceof TopLevelSettings
@@ -442,11 +444,6 @@
         ProfileSelectDialog.updateUserHandlesIfNeeded(mContext, tile);
         mMetricsFeatureProvider.logStartedIntent(intent, sourceMetricCategory);
 
-        //TODO(b/201970810): Add test cases.
-        if (tile.isNewTask(mContext)) {
-            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        }
-
         if (tile.userHandle == null || tile.isPrimaryProfileOnly()) {
             activity.startActivity(intent);
         } else if (tile.userHandle.size() == 1) {
diff --git a/src/com/android/settings/dashboard/DashboardFragment.java b/src/com/android/settings/dashboard/DashboardFragment.java
index cfdfdaa..8b1d633 100644
--- a/src/com/android/settings/dashboard/DashboardFragment.java
+++ b/src/com/android/settings/dashboard/DashboardFragment.java
@@ -53,6 +53,7 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
@@ -280,6 +281,11 @@
         return null;
     }
 
+    /** Returns all controllers of type T. */
+    protected <T extends AbstractPreferenceController> List<T> useAll(Class<T> clazz) {
+        return (List<T>) mPreferenceControllers.getOrDefault(clazz, Collections.emptyList());
+    }
+
     protected void addPreferenceController(AbstractPreferenceController controller) {
         if (mPreferenceControllers.get(controller.getClass()) == null) {
             mPreferenceControllers.put(controller.getClass(), new ArrayList<>());
diff --git a/src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java b/src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java
index e0ba378..d3234dd 100644
--- a/src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java
+++ b/src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java
@@ -97,7 +97,7 @@
     public void onClick(DialogInterface dialog, int which) {
         final UserHandle user = mSelectedTile.userHandle.get(which);
         // Show menu on top level items.
-        final Intent intent = mSelectedTile.getIntent();
+        final Intent intent = new Intent(mSelectedTile.getIntent());
         FeatureFactory.getFactory(getContext()).getMetricsFeatureProvider()
                 .logStartedIntentWithProfile(intent, mSourceMetricCategory,
                         which == 1 /* isWorkProfile */);
diff --git a/src/com/android/settings/display/AutoRotatePreferenceController.java b/src/com/android/settings/display/AutoRotatePreferenceController.java
index 5dc2286..90423fb 100644
--- a/src/com/android/settings/display/AutoRotatePreferenceController.java
+++ b/src/com/android/settings/display/AutoRotatePreferenceController.java
@@ -74,6 +74,7 @@
     @Override
     public int getAvailabilityStatus() {
         return RotationPolicy.isRotationLockToggleVisible(mContext)
+                && !DeviceStateAutoRotationHelper.isDeviceStateRotationEnabled(mContext)
                 ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
     }
 
diff --git a/src/com/android/settings/display/DeviceStateAutoRotateDetailsFragment.java b/src/com/android/settings/display/DeviceStateAutoRotateDetailsFragment.java
new file mode 100644
index 0000000..fb6d9f4
--- /dev/null
+++ b/src/com/android/settings/display/DeviceStateAutoRotateDetailsFragment.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2022 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.display;
+
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+
+import com.android.settings.R;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.search.Indexable;
+import com.android.settingslib.search.SearchIndexable;
+import com.android.settingslib.search.SearchIndexableRaw;
+
+import java.util.List;
+
+/** Fragment that shows all the available device state based auto-rotation preferences. */
+@SearchIndexable
+public class DeviceStateAutoRotateDetailsFragment extends DashboardFragment {
+
+    private static final String TAG = "DeviceStateAutoRotateDetailsFragment";
+
+    @Override
+    public int getMetricsCategory() {
+        return SettingsEnums.DISPLAY_AUTO_ROTATE_SETTINGS;
+    }
+
+    @Override
+    protected int getPreferenceScreenResId() {
+        return R.xml.device_state_auto_rotate_settings;
+    }
+
+    @Override
+    public void onAttach(Context context) {
+        super.onAttach(context);
+        DeviceStateAutoRotationHelper.initControllers(
+                getLifecycle(),
+                useAll(DeviceStateAutoRotateSettingController.class)
+        );
+    }
+
+    @Override
+    protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
+        return DeviceStateAutoRotationHelper.createPreferenceControllers(context);
+    }
+
+    @Override
+    protected String getLogTag() {
+        return TAG;
+    }
+
+    public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+            new BaseSearchIndexProvider(R.xml.device_state_auto_rotate_settings) {
+
+                @Override
+                public List<SearchIndexableRaw> getRawDataToIndex(Context context,
+                        boolean enabled) {
+                    return DeviceStateAutoRotationHelper.getRawDataToIndex(context, enabled);
+                }
+            };
+}
diff --git a/src/com/android/settings/display/DeviceStateAutoRotateOverviewController.java b/src/com/android/settings/display/DeviceStateAutoRotateOverviewController.java
new file mode 100644
index 0000000..5e49bf3
--- /dev/null
+++ b/src/com/android/settings/display/DeviceStateAutoRotateOverviewController.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2022 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.display;
+
+import android.content.Context;
+import android.text.TextUtils;
+
+import com.android.settings.core.BasePreferenceController;
+
+/**
+ * The top-level preference controller for device state based auto-rotation settings.
+ *
+ * It doesn't do anything on its own besides showing/hiding. The toggling of the settings will
+ * always be done in the details screen when device state based auto-rotation is enabled.
+ */
+public class DeviceStateAutoRotateOverviewController extends BasePreferenceController {
+
+    /** Preference key for when it is used in "accessibility_system_controls.xml". */
+    private static final String ACCESSIBILITY_PREF_KEY = "device_state_auto_rotate_accessibility";
+
+    public DeviceStateAutoRotateOverviewController(Context context, String key) {
+        super(context, key);
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        return isAvailableInternal() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+    }
+
+    private boolean isAvailableInternal() {
+        return isA11yPage()
+                ? DeviceStateAutoRotationHelper.isDeviceStateRotationEnabledForA11y(mContext)
+                : DeviceStateAutoRotationHelper.isDeviceStateRotationEnabled(mContext);
+    }
+
+    private boolean isA11yPage() {
+        return TextUtils.equals(getPreferenceKey(), ACCESSIBILITY_PREF_KEY);
+    }
+}
diff --git a/src/com/android/settings/display/DeviceStateAutoRotateSettingController.java b/src/com/android/settings/display/DeviceStateAutoRotateSettingController.java
new file mode 100644
index 0000000..c8f6280
--- /dev/null
+++ b/src/com/android/settings/display/DeviceStateAutoRotateSettingController.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2022 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.display;
+
+import static androidx.lifecycle.Lifecycle.Event.ON_START;
+import static androidx.lifecycle.Lifecycle.Event.ON_STOP;
+
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+
+import androidx.lifecycle.Lifecycle;
+import androidx.lifecycle.LifecycleObserver;
+import androidx.lifecycle.OnLifecycleEvent;
+import androidx.preference.PreferenceScreen;
+import androidx.preference.SwitchPreference;
+
+import com.android.settings.R;
+import com.android.settings.core.TogglePreferenceController;
+import com.android.settings.overlay.FeatureFactory;
+import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
+import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
+import com.android.settingslib.search.SearchIndexableRaw;
+
+import java.util.List;
+
+/** Controller for device state based auto rotation preferences. */
+public class DeviceStateAutoRotateSettingController extends TogglePreferenceController implements
+        LifecycleObserver {
+
+    private SwitchPreference mPreference;
+
+    private final DeviceStateRotationLockSettingsManager mAutoRotateSettingsManager;
+    private final int mOrder;
+    private final DeviceStateRotationLockSettingsManager.DeviceStateRotationLockSettingsListener
+            mDeviceStateRotationLockSettingsListener = () -> updateState(mPreference);
+    private final int mDeviceState;
+    private final String mDeviceStateDescription;
+    private final MetricsFeatureProvider mMetricsFeatureProvider;
+
+    public DeviceStateAutoRotateSettingController(Context context, int deviceState,
+            String deviceStateDescription, int order) {
+        super(context, getPreferenceKeyForDeviceState(deviceState));
+        mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
+        mDeviceState = deviceState;
+        mDeviceStateDescription = deviceStateDescription;
+        mAutoRotateSettingsManager = DeviceStateRotationLockSettingsManager.getInstance(context);
+        mOrder = order;
+    }
+
+    void init(Lifecycle lifecycle) {
+        lifecycle.addObserver(this);
+    }
+
+    @OnLifecycleEvent(ON_START)
+    void onStart() {
+        mAutoRotateSettingsManager.registerListener(mDeviceStateRotationLockSettingsListener);
+    }
+
+    @OnLifecycleEvent(ON_STOP)
+    void onStop() {
+        mAutoRotateSettingsManager.unregisterListener(mDeviceStateRotationLockSettingsListener);
+    }
+
+    @Override
+    public void displayPreference(PreferenceScreen screen) {
+        mPreference = new SwitchPreference(mContext);
+        mPreference.setTitle(mDeviceStateDescription);
+        mPreference.setKey(getPreferenceKey());
+        mPreference.setOrder(mOrder);
+        screen.addPreference(mPreference);
+        super.displayPreference(screen);
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        return DeviceStateAutoRotationHelper.isDeviceStateRotationEnabled(mContext)
+                ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+    }
+
+    @Override
+    public String getPreferenceKey() {
+        return getPreferenceKeyForDeviceState(mDeviceState);
+    }
+
+    private static String getPreferenceKeyForDeviceState(int deviceState) {
+        return "auto_rotate_device_state_" + deviceState;
+    }
+
+    @Override
+    public boolean isChecked() {
+        return !mAutoRotateSettingsManager.isRotationLocked(mDeviceState);
+    }
+
+    @Override
+    public boolean setChecked(boolean isChecked) {
+        boolean isRotationLocked = !isChecked;
+        mMetricsFeatureProvider.action(mContext, SettingsEnums.ACTION_ROTATION_LOCK,
+                isRotationLocked);
+        mAutoRotateSettingsManager.updateSetting(mDeviceState, isRotationLocked);
+        return true;
+    }
+
+    @Override
+    public void updateRawDataToIndex(List<SearchIndexableRaw> rawData) {
+        SearchIndexableRaw indexable = new SearchIndexableRaw(mContext);
+        indexable.key = getPreferenceKey();
+        indexable.title = mDeviceStateDescription;
+        // Maybe pass screen title as param?
+        indexable.screenTitle = mContext.getString(R.string.accelerometer_title);
+        rawData.add(indexable);
+    }
+
+    @Override
+    public int getSliceHighlightMenuRes() {
+        return R.string.menu_key_display;
+    }
+
+    @Override
+    public boolean isSliceable() {
+        return true; // Maybe set to false if in accessibility settings screen
+    }
+
+    @Override
+    public boolean isPublicSlice() {
+        return true;
+    }
+}
diff --git a/src/com/android/settings/display/DeviceStateAutoRotationHelper.java b/src/com/android/settings/display/DeviceStateAutoRotationHelper.java
new file mode 100644
index 0000000..223ef1a
--- /dev/null
+++ b/src/com/android/settings/display/DeviceStateAutoRotationHelper.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2022 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.display;
+
+import android.content.Context;
+import android.util.Log;
+
+import androidx.lifecycle.Lifecycle;
+
+import com.android.internal.view.RotationPolicy;
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
+import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager.SettableDeviceState;
+import com.android.settingslib.search.SearchIndexableRaw;
+
+import com.google.common.collect.ImmutableList;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Helper class with utility methods related to device state auto-rotation that can be used in
+ * auto-rotation settings fragments and controllers.
+ */
+public class DeviceStateAutoRotationHelper {
+
+    private static final String TAG = "DeviceStateAutoRotHelpr";
+
+    static void initControllers(Lifecycle lifecycle,
+            List<DeviceStateAutoRotateSettingController> controllers) {
+        for (DeviceStateAutoRotateSettingController controller : controllers) {
+            controller.init(lifecycle);
+        }
+    }
+
+    static ImmutableList<AbstractPreferenceController> createPreferenceControllers(
+            Context context) {
+        List<SettableDeviceState> settableDeviceStates = DeviceStateRotationLockSettingsManager
+                .getInstance(context).getSettableDeviceStates();
+        int numDeviceStates = settableDeviceStates.size();
+        if (numDeviceStates == 0) {
+            return ImmutableList.of();
+        }
+        String[] deviceStateSettingDescriptions = context.getResources().getStringArray(
+                R.array.config_settableAutoRotationDeviceStatesDescriptions);
+        if (numDeviceStates != deviceStateSettingDescriptions.length) {
+            Log.wtf(TAG,
+                    "Mismatch between number of device states and device states descriptions.");
+            return ImmutableList.of();
+        }
+
+        ImmutableList.Builder<AbstractPreferenceController> controllers =
+                ImmutableList.builderWithExpectedSize(numDeviceStates);
+        for (int i = 0; i < numDeviceStates; i++) {
+            SettableDeviceState settableDeviceState = settableDeviceStates.get(i);
+            if (!settableDeviceState.isSettable()) {
+                continue;
+            }
+            // Preferences with a lower order will be showed first. Here we go below 0 to make sure
+            // we are shown before statically declared preferences in XML.
+            int order = -numDeviceStates + i;
+            controllers.add(new DeviceStateAutoRotateSettingController(
+                    context,
+                    settableDeviceState.getDeviceState(),
+                    deviceStateSettingDescriptions[i],
+                    order
+            ));
+        }
+        return controllers.build();
+    }
+
+    static List<SearchIndexableRaw> getRawDataToIndex(
+            Context context, boolean enabled) {
+        // Check what the "enabled" param is for
+        List<AbstractPreferenceController> controllers = createPreferenceControllers(context);
+        List<SearchIndexableRaw> rawData = new ArrayList<>();
+        for (AbstractPreferenceController controller : controllers) {
+            ((BasePreferenceController) controller).updateRawDataToIndex(rawData);
+        }
+        return rawData;
+    }
+
+    /** Returns whether the device state based auto-rotation settings are enabled. */
+    public static boolean isDeviceStateRotationEnabled(Context context) {
+        return RotationPolicy.isRotationLockToggleVisible(context)
+                && DeviceStateRotationLockSettingsManager.isDeviceStateRotationLockEnabled(context);
+    }
+
+    /**
+     * Returns whether the device state based auto-rotation settings are enabled for the
+     * accessibility settings page.
+     */
+    public static boolean isDeviceStateRotationEnabledForA11y(Context context) {
+        return RotationPolicy.isRotationSupported(context)
+                && DeviceStateRotationLockSettingsManager.isDeviceStateRotationLockEnabled(context);
+    }
+}
diff --git a/src/com/android/settings/display/SmartAutoRotateController.java b/src/com/android/settings/display/SmartAutoRotateController.java
index 76a222a..d29a64e 100644
--- a/src/com/android/settings/display/SmartAutoRotateController.java
+++ b/src/com/android/settings/display/SmartAutoRotateController.java
@@ -47,6 +47,7 @@
 import com.android.settings.core.TogglePreferenceController;
 import com.android.settings.overlay.FeatureFactory;
 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
+import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
 
 /**
  * SmartAutoRotateController controls whether auto rotation is enabled
@@ -54,6 +55,8 @@
 public class SmartAutoRotateController extends TogglePreferenceController implements
         Preference.OnPreferenceChangeListener, LifecycleObserver {
 
+    protected Preference mPreference;
+
     private final MetricsFeatureProvider mMetricsFeatureProvider;
     private final SensorPrivacyManager mPrivacyManager;
     private final PowerManager mPowerManager;
@@ -63,7 +66,9 @@
             updateState(mPreference);
         }
     };
-    protected Preference mPreference;
+    private final DeviceStateRotationLockSettingsManager mDeviceStateAutoRotateSettingsManager;
+    private final DeviceStateRotationLockSettingsManager.DeviceStateRotationLockSettingsListener
+            mDeviceStateRotationLockSettingsListener = () -> updateState(mPreference);
     private RotationPolicy.RotationPolicyListener mRotationPolicyListener;
 
     public SmartAutoRotateController(Context context, String preferenceKey) {
@@ -73,6 +78,8 @@
         mPrivacyManager
                 .addSensorPrivacyListener(CAMERA, (sensor, enabled) -> updateState(mPreference));
         mPowerManager = context.getSystemService(PowerManager.class);
+        mDeviceStateAutoRotateSettingsManager = DeviceStateRotationLockSettingsManager.getInstance(
+                context);
     }
 
     public void init(Lifecycle lifecycle) {
@@ -89,6 +96,9 @@
     }
 
     protected boolean isRotationLocked() {
+        if (DeviceStateAutoRotationHelper.isDeviceStateRotationEnabled(mContext)) {
+            return mDeviceStateAutoRotateSettingsManager.isRotationLockedForAllStates();
+        }
         return RotationPolicy.isRotationLocked(mContext);
     }
 
@@ -127,6 +137,8 @@
             };
         }
         RotationPolicy.registerRotationPolicyListener(mContext, mRotationPolicyListener);
+        mDeviceStateAutoRotateSettingsManager.registerListener(
+                mDeviceStateRotationLockSettingsListener);
     }
 
     @OnLifecycleEvent(ON_STOP)
@@ -136,6 +148,8 @@
             RotationPolicy.unregisterRotationPolicyListener(mContext, mRotationPolicyListener);
             mRotationPolicyListener = null;
         }
+        mDeviceStateAutoRotateSettingsManager.unregisterListener(
+                mDeviceStateRotationLockSettingsListener);
     }
 
     @Override
diff --git a/src/com/android/settings/display/SmartAutoRotatePreferenceController.java b/src/com/android/settings/display/SmartAutoRotatePreferenceController.java
index bd8ee84..d02e336 100644
--- a/src/com/android/settings/display/SmartAutoRotatePreferenceController.java
+++ b/src/com/android/settings/display/SmartAutoRotatePreferenceController.java
@@ -77,6 +77,7 @@
     @Override
     public int getAvailabilityStatus() {
         return RotationPolicy.isRotationLockToggleVisible(mContext)
+                && !DeviceStateAutoRotationHelper.isDeviceStateRotationEnabled(mContext)
                 ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
     }
 
diff --git a/src/com/android/settings/display/SmartAutoRotatePreferenceFragment.java b/src/com/android/settings/display/SmartAutoRotatePreferenceFragment.java
index 4737336..9fda03c 100644
--- a/src/com/android/settings/display/SmartAutoRotatePreferenceFragment.java
+++ b/src/com/android/settings/display/SmartAutoRotatePreferenceFragment.java
@@ -34,10 +34,14 @@
 import com.android.settings.dashboard.DashboardFragment;
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settings.widget.SettingsMainSwitchBar;
+import com.android.settingslib.core.AbstractPreferenceController;
 import com.android.settingslib.search.Indexable;
 import com.android.settingslib.search.SearchIndexable;
+import com.android.settingslib.search.SearchIndexableRaw;
 import com.android.settingslib.widget.FooterPreference;
 
+import java.util.List;
+
 /**
  * Preference fragment used for auto rotation
  */
@@ -60,6 +64,15 @@
     public void onAttach(Context context) {
         super.onAttach(context);
         use(SmartAutoRotateController.class).init(getLifecycle());
+        DeviceStateAutoRotationHelper.initControllers(
+                getLifecycle(),
+                useAll(DeviceStateAutoRotateSettingController.class)
+        );
+    }
+
+    @Override
+    protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
+        return DeviceStateAutoRotationHelper.createPreferenceControllers(context);
     }
 
     @Override
@@ -79,7 +92,9 @@
 
     @VisibleForTesting
     void createHeader(SettingsActivity activity) {
-        if (isRotationResolverServiceAvailable(activity)) {
+        boolean deviceStateRotationEnabled =
+                DeviceStateAutoRotationHelper.isDeviceStateRotationEnabled(activity);
+        if (isRotationResolverServiceAvailable(activity) && !deviceStateRotationEnabled) {
             final SettingsMainSwitchBar switchBar = activity.getSwitchBar();
             switchBar.setTitle(
                     getContext().getString(R.string.auto_rotate_settings_primary_switch_title));
@@ -127,5 +142,12 @@
     }
 
     public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
-            new BaseSearchIndexProvider(R.xml.auto_rotate_settings);
+            new BaseSearchIndexProvider(R.xml.auto_rotate_settings) {
+
+                @Override
+                public List<SearchIndexableRaw> getRawDataToIndex(
+                        Context context, boolean enabled) {
+                    return DeviceStateAutoRotationHelper.getRawDataToIndex(context, enabled);
+                }
+            };
 }
diff --git a/src/com/android/settings/dream/AutoFitGridLayoutManager.java b/src/com/android/settings/dream/AutoFitGridLayoutManager.java
index 0e5d3e1..7de0eae 100644
--- a/src/com/android/settings/dream/AutoFitGridLayoutManager.java
+++ b/src/com/android/settings/dream/AutoFitGridLayoutManager.java
@@ -24,10 +24,10 @@
 import com.android.settings.R;
 
 /** Grid layout manager that calculates the number of columns for the screen size. */
-final class AutoFitGridLayoutManager extends GridLayoutManager {
+public final class AutoFitGridLayoutManager extends GridLayoutManager {
     private final float mColumnWidth;
 
-    AutoFitGridLayoutManager(Context context) {
+    public AutoFitGridLayoutManager(Context context) {
         super(context, /* spanCount= */ 1);
         this.mColumnWidth = context
                 .getResources()
diff --git a/src/com/android/settings/dream/DreamAdapter.java b/src/com/android/settings/dream/DreamAdapter.java
index e674546..8d0e9d5 100644
--- a/src/com/android/settings/dream/DreamAdapter.java
+++ b/src/com/android/settings/dream/DreamAdapter.java
@@ -37,7 +37,7 @@
 /**
  * RecyclerView adapter which displays list of items for the user to select.
  */
-class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
+public class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
     private final List<IDreamItem> mItemList;
     private int mLastSelectedPos = -1;
 
@@ -103,7 +103,7 @@
         }
     }
 
-    DreamAdapter(List<IDreamItem> itemList) {
+    public DreamAdapter(List<IDreamItem> itemList) {
         mItemList = itemList;
     }
 
diff --git a/src/com/android/settings/dream/DreamSetupActivity.java b/src/com/android/settings/dream/DreamSetupActivity.java
deleted file mode 100644
index 6a12671..0000000
--- a/src/com/android/settings/dream/DreamSetupActivity.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * Copyright (C) 2022 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.dream;
-
-import android.app.settings.SettingsEnums;
-import android.content.Intent;
-import android.graphics.drawable.Drawable;
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-
-import androidx.recyclerview.widget.RecyclerView;
-
-import com.android.settings.R;
-import com.android.settings.SettingsActivity;
-import com.android.settings.SettingsPreferenceFragment;
-import com.android.settingslib.dream.DreamBackend;
-
-import com.google.android.setupcompat.template.FooterBarMixin;
-import com.google.android.setupcompat.template.FooterButton;
-import com.google.android.setupcompat.util.WizardManagerHelper;
-import com.google.android.setupdesign.GlifLayout;
-import com.google.android.setupdesign.util.ThemeHelper;
-import com.google.android.setupdesign.util.ThemeResolver;
-
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * The setup activity for dreams which is displayed during setup wizard.
- */
-public class DreamSetupActivity extends SettingsActivity {
-    @Override
-    public Intent getIntent() {
-        Intent modIntent = new Intent(super.getIntent());
-        modIntent.putExtra(EXTRA_SHOW_FRAGMENT, DreamSetupFragment.class.getName());
-        return modIntent;
-    }
-
-    @Override
-    protected boolean isValidFragment(String fragmentName) {
-        return DreamSetupFragment.class.getName().equals(fragmentName);
-    }
-
-    @Override
-    protected void onCreate(Bundle savedInstance) {
-        setTheme(ThemeResolver.getDefault().resolve(getIntent()));
-        ThemeHelper.trySetDynamicColor(this);
-        super.onCreate(savedInstance);
-    }
-
-    @Override
-    protected boolean isToolbarEnabled() {
-        return false;
-    }
-
-    /**
-     * Fragment used to control the active dream.
-     */
-    public static class DreamSetupFragment extends SettingsPreferenceFragment {
-        private DreamBackend mBackend;
-        private DreamBackend.DreamInfo mActiveDream;
-        private FooterButton mFooterButton;
-
-        @Override
-        public int getMetricsCategory() {
-            return SettingsEnums.DREAM;
-        }
-
-        @Override
-        public View onCreateView(LayoutInflater inflater, ViewGroup container,
-                Bundle savedInstanceState) {
-            return inflater.inflate(R.layout.dream_setup_layout, container, false);
-        }
-
-        @Override
-        public void onViewCreated(View view, Bundle savedInstanceState) {
-            super.onViewCreated(view, savedInstanceState);
-
-            mBackend = DreamBackend.getInstance(getContext());
-            final List<DreamBackend.DreamInfo> dreamInfos = mBackend.getDreamInfos();
-            mActiveDream = dreamInfos.stream().filter(d -> d.isActive).findFirst().orElse(null);
-            DreamAdapter dreamAdapter = new DreamAdapter(dreamInfos.stream()
-                    .map(DreamItem::new)
-                    .collect(Collectors.toList()));
-
-            final RecyclerView recyclerView = view.findViewById(R.id.dream_setup_list);
-            recyclerView.setLayoutManager(new AutoFitGridLayoutManager(getContext()));
-            recyclerView.setHasFixedSize(true);
-            recyclerView.setAdapter(dreamAdapter);
-
-            final GlifLayout layout = view.findViewById(R.id.setup_wizard_layout);
-            final FooterBarMixin mixin = layout.getMixin(FooterBarMixin.class);
-            mFooterButton = new FooterButton.Builder(getContext())
-                    .setListener(this::onPrimaryButtonClicked)
-                    .setButtonType(FooterButton.ButtonType.NEXT)
-                    .setTheme(R.style.SudGlifButton_Primary)
-                    .build();
-            updateFooterButtonText();
-            mixin.setPrimaryButton(mFooterButton);
-        }
-
-        private void updateFooterButtonText() {
-            final int res = canCustomizeDream() ? R.string.wizard_next : R.string.wizard_finish;
-            mFooterButton.setText(getContext().getString(res));
-        }
-
-        private boolean canCustomizeDream() {
-            return mActiveDream != null && mActiveDream.settingsComponentName != null;
-        }
-
-        private void onPrimaryButtonClicked(View view) {
-            if (canCustomizeDream()) {
-                final Intent intent = new Intent().setComponent(mActiveDream.settingsComponentName);
-                WizardManagerHelper.copyWizardManagerExtras(getIntent(), intent);
-                startActivity(intent);
-            }
-
-            // Use RESULT_CANCELED here so that the user may go back and change this if they wish.
-            setResult(RESULT_CANCELED);
-            finish();
-        }
-
-        private class DreamItem implements IDreamItem {
-            private final DreamBackend.DreamInfo mDreamInfo;
-
-            private DreamItem(DreamBackend.DreamInfo dreamInfo) {
-                mDreamInfo = dreamInfo;
-            }
-
-            @Override
-            public CharSequence getTitle() {
-                return mDreamInfo.caption;
-            }
-
-            @Override
-            public Drawable getIcon() {
-                return mDreamInfo.icon;
-            }
-
-            @Override
-            public void onItemClicked() {
-                mActiveDream = mDreamInfo;
-                mBackend.setActiveDream(mDreamInfo.componentName);
-                updateFooterButtonText();
-            }
-
-            @Override
-            public Drawable getPreviewImage() {
-                return mDreamInfo.previewImage;
-            }
-
-            @Override
-            public boolean isActive() {
-                if (mActiveDream == null) {
-                    return false;
-                }
-                return mDreamInfo.componentName.equals(mActiveDream.componentName);
-            }
-        }
-    }
-}
diff --git a/src/com/android/settings/dream/IDreamItem.java b/src/com/android/settings/dream/IDreamItem.java
index 6652857..c462fe2 100644
--- a/src/com/android/settings/dream/IDreamItem.java
+++ b/src/com/android/settings/dream/IDreamItem.java
@@ -18,7 +18,10 @@
 
 import android.graphics.drawable.Drawable;
 
-interface IDreamItem {
+/**
+ * Interface representing a dream item to be displayed.
+ */
+public interface IDreamItem {
     CharSequence getTitle();
 
     Drawable getIcon();
diff --git a/packages/apps/Settings/src/com/android/settings/dream/OWNERS b/src/com/android/settings/dream/OWNERS
similarity index 100%
rename from packages/apps/Settings/src/com/android/settings/dream/OWNERS
rename to src/com/android/settings/dream/OWNERS
diff --git a/src/com/android/settings/location/RecentLocationAccessSeeAllPreferenceController.java b/src/com/android/settings/location/RecentLocationAccessSeeAllPreferenceController.java
index e3379c7..75406f7 100644
--- a/src/com/android/settings/location/RecentLocationAccessSeeAllPreferenceController.java
+++ b/src/com/android/settings/location/RecentLocationAccessSeeAllPreferenceController.java
@@ -27,7 +27,9 @@
 
 import com.android.settings.R;
 import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
+import com.android.settings.overlay.FeatureFactory;
 import com.android.settingslib.applications.RecentAppOpsAccess;
+import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
 import com.android.settingslib.widget.AppPreference;
 
 import java.util.ArrayList;
@@ -37,8 +39,10 @@
 public class RecentLocationAccessSeeAllPreferenceController
         extends LocationBasePreferenceController {
 
-    private PreferenceScreen mCategoryAllRecentLocationAccess;
     private final RecentAppOpsAccess mRecentLocationAccesses;
+
+    private PreferenceScreen mCategoryAllRecentLocationAccess;
+    private MetricsFeatureProvider mMetricsFeatureProvider;
     private boolean mShowSystem = false;
     private Preference mPreference;
 
@@ -47,6 +51,7 @@
         mShowSystem = Settings.Secure.getInt(mContext.getContentResolver(),
                 Settings.Secure.LOCATION_SHOW_SYSTEM_OPS, 0) == 1;
         mRecentLocationAccesses = RecentAppOpsAccess.createForLocation(context);
+        mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
     }
 
     @Override
@@ -99,6 +104,7 @@
         mShowSystem = showSystem;
         if (mPreference != null) {
             updateState(mPreference);
+            mMetricsFeatureProvider.logClickedPreference(mPreference, getMetricsCategory());
         }
     }
 }
diff --git a/src/com/android/settings/nfc/PaymentDefaultDialog.java b/src/com/android/settings/nfc/PaymentDefaultDialog.java
index a888167..75746ce 100644
--- a/src/com/android/settings/nfc/PaymentDefaultDialog.java
+++ b/src/com/android/settings/nfc/PaymentDefaultDialog.java
@@ -58,7 +58,11 @@
         ComponentName component = intent.getParcelableExtra(
                 CardEmulation.EXTRA_SERVICE_COMPONENT);
         String category = intent.getStringExtra(CardEmulation.EXTRA_CATEGORY);
-        int userId = intent.getIntExtra(CardEmulation.EXTRA_USERID, UserHandle.myUserId());
+        UserHandle userHandle = intent.getParcelableExtra(Intent.EXTRA_USER);
+        if (userHandle == null) {
+            userHandle = UserHandle.CURRENT;
+        }
+        int userId = userHandle.getIdentifier();
 
         setResult(RESULT_CANCELED);
         if (!buildDialog(component, category, userId)) {
diff --git a/tests/robotests/src/com/android/settings/accessibility/LockScreenRotationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/LockScreenRotationPreferenceControllerTest.java
index ef8f569..f908b8a 100644
--- a/tests/robotests/src/com/android/settings/accessibility/LockScreenRotationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/LockScreenRotationPreferenceControllerTest.java
@@ -26,6 +26,7 @@
 
 import com.android.internal.view.RotationPolicy;
 import com.android.settings.core.BasePreferenceController;
+import com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager;
 import com.android.settings.testutils.shadow.ShadowRotationPolicy;
 
 import org.junit.Before;
@@ -50,7 +51,10 @@
     }
 
     @Test
-    @Config(shadows = {ShadowRotationPolicy.class})
+    @Config(shadows = {
+            ShadowRotationPolicy.class,
+            ShadowDeviceStateRotationLockSettingsManager.class
+    })
     public void getAvailabilityStatus_supportedRotation_shouldReturnAvailable() {
         ShadowRotationPolicy.setRotationSupported(true /* supported */);
 
@@ -59,8 +63,23 @@
     }
 
     @Test
-    @Config(shadows = {ShadowRotationPolicy.class})
-    public void getAvailabilityStatus_unsupportedRotation_shouldReturnUnsupportedOnDevice() {
+    @Config(shadows = {
+            ShadowRotationPolicy.class,
+            ShadowDeviceStateRotationLockSettingsManager.class
+    })
+    public void getAvailabilityStatus_deviceStateRotationEnabled_returnsUnsupported() {
+        ShadowRotationPolicy.setRotationSupported(true /* supported */);
+        ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
+
+        assertThat(mController.getAvailabilityStatus()).isEqualTo(
+                BasePreferenceController.UNSUPPORTED_ON_DEVICE);
+    }
+
+    @Test
+    @Config(shadows = {
+            ShadowRotationPolicy.class,
+            ShadowDeviceStateRotationLockSettingsManager.class
+    })    public void getAvailabilityStatus_unsupportedRotation_shouldReturnUnsupportedOnDevice() {
         ShadowRotationPolicy.setRotationSupported(false /* supported */);
 
         assertThat(mController.getAvailabilityStatus()).isEqualTo(
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java
index fd1c8ff..aa5f980 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java
@@ -144,6 +144,21 @@
     }
 
     @Test
+    public void useAll_returnsAllControllersOfType() {
+        final TestPreferenceController controller1 = new TestPreferenceController(mContext);
+        final TestPreferenceController controller2 = new TestPreferenceController(mContext);
+        final SubTestPreferenceController controller3 = new SubTestPreferenceController(mContext);
+        mTestFragment.addPreferenceController(controller1);
+        mTestFragment.addPreferenceController(controller2);
+        mTestFragment.addPreferenceController(controller3);
+
+        final List<TestPreferenceController> retrievedControllers = mTestFragment.useAll(
+                TestPreferenceController.class);
+
+        assertThat(retrievedControllers).containsExactly(controller1, controller2);
+    }
+
+    @Test
     public void displayTilesAsPreference_shouldAddTilesWithIntent() {
         when(mFakeFeatureFactory.dashboardFeatureProvider
                 .getTilesForCategory(nullable(String.class)))
@@ -360,6 +375,13 @@
         }
     }
 
+    public static class SubTestPreferenceController extends TestPreferenceController {
+
+        private SubTestPreferenceController(Context context) {
+            super(context);
+        }
+    }
+
     private static class TestFragment extends DashboardFragment {
 
         private final PreferenceManager mPreferenceManager;
diff --git a/tests/robotests/src/com/android/settings/display/AutoRotatePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/AutoRotatePreferenceControllerTest.java
index 1d175de..54e6b99 100644
--- a/tests/robotests/src/com/android/settings/display/AutoRotatePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/AutoRotatePreferenceControllerTest.java
@@ -30,6 +30,7 @@
 
 import androidx.preference.SwitchPreference;
 
+import com.android.internal.R;
 import com.android.internal.view.RotationPolicy;
 import com.android.settings.core.BasePreferenceController;
 import com.android.settings.testutils.FakeFeatureFactory;
@@ -64,6 +65,7 @@
         mPreference = new SwitchPreference(RuntimeEnvironment.application);
         when(mContext.getPackageManager()).thenReturn(mPackageManager);
         when(mContext.getContentResolver()).thenReturn(mContentResolver);
+        disableDeviceStateRotation();
 
         mController = new AutoRotatePreferenceController(mContext, "auto_rotate");
     }
@@ -112,6 +114,26 @@
     }
 
     @Test
+    public void getAvailabilityStatus_deviceRotationDisabled_returnsAvailable() {
+        enableAutoRotationPreference();
+        disableDeviceStateRotation();
+
+        int availability = mController.getAvailabilityStatus();
+
+        assertThat(availability).isEqualTo(BasePreferenceController.AVAILABLE);
+    }
+
+    @Test
+    public void getAvailabilityStatus_deviceRotationEnabled_returnsUnsupported() {
+        enableAutoRotationPreference();
+        enableDeviceStateRotation();
+
+        int availability = mController.getAvailabilityStatus();
+
+        assertThat(availability).isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
+    }
+
+    @Test
     public void testIsCheck() {
         assertThat(mController.isChecked()).isFalse();
 
@@ -180,4 +202,15 @@
         Settings.System.putIntForUser(mContentResolver,
                 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT);
     }
+
+    private void enableDeviceStateRotation() {
+        when(mContext.getResources().getStringArray(
+                R.array.config_perDeviceStateRotationLockDefaults)).thenReturn(
+                new String[]{"0:0", "1:1", "2:2"});
+    }
+
+    private void disableDeviceStateRotation() {
+        when(mContext.getResources().getStringArray(
+                R.array.config_perDeviceStateRotationLockDefaults)).thenReturn(new String[]{});
+    }
 }
diff --git a/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateDetailsFragmentTest.java b/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateDetailsFragmentTest.java
new file mode 100644
index 0000000..b773657
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateDetailsFragmentTest.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2022 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.display;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+import android.content.res.Resources;
+
+import com.android.settings.R;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+import java.util.List;
+
+@RunWith(RobolectricTestRunner.class)
+public class DeviceStateAutoRotateDetailsFragmentTest {
+
+    private final DeviceStateAutoRotateDetailsFragment mFragment =
+            spy(new DeviceStateAutoRotateDetailsFragment());
+    private final Context mContext = spy(RuntimeEnvironment.application);
+    private final Resources mResources = spy(mContext.getResources());
+
+    @Before
+    public void setUp() throws Exception {
+        when(mContext.getResources()).thenReturn(mResources);
+        when(mContext.getApplicationContext()).thenReturn(mContext);
+        when(mFragment.getContext()).thenReturn(mContext);
+        when(mFragment.getResources()).thenReturn(mResources);
+    }
+
+    @Test
+    public void getMetricsCategory_returnsAutoRotateSettings() {
+        assertThat(mFragment.getMetricsCategory()).isEqualTo(
+                SettingsEnums.DISPLAY_AUTO_ROTATE_SETTINGS);
+    }
+
+    @Test
+    public void getPreferenceScreenResId_returnsDeviceStateAutoRotationSettings() {
+        assertThat(mFragment.getPreferenceScreenResId()).isEqualTo(
+                R.xml.device_state_auto_rotate_settings);
+    }
+
+    @Test
+    public void createPreferenceControllers_settableDeviceStates_returnsDeviceStateControllers() {
+        enableDeviceStateSettableRotationStates(new String[]{"0:1", "1:1"},
+                new String[]{"Folded", "Unfolded"});
+
+        List<AbstractPreferenceController> preferenceControllers =
+                mFragment.createPreferenceControllers(mContext);
+
+        assertThat(preferenceControllers).hasSize(2);
+        assertThat(preferenceControllers.get(0)).isInstanceOf(
+                DeviceStateAutoRotateSettingController.class);
+        assertThat(preferenceControllers.get(1)).isInstanceOf(
+                DeviceStateAutoRotateSettingController.class);
+    }
+
+    @Test
+    public void createPreferenceControllers_noSettableDeviceStates_returnsEmptyList() {
+        enableDeviceStateSettableRotationStates(new String[]{}, new String[]{});
+
+        List<AbstractPreferenceController> preferenceControllers =
+                mFragment.createPreferenceControllers(mContext);
+
+        assertThat(preferenceControllers).isEmpty();
+    }
+
+    private void enableDeviceStateSettableRotationStates(String[] settableStates,
+            String[] settableStatesDescriptions) {
+        when(mResources.getStringArray(
+                com.android.internal.R.array.config_perDeviceStateRotationLockDefaults)).thenReturn(
+                settableStates);
+        when(mResources.getStringArray(
+                R.array.config_settableAutoRotationDeviceStatesDescriptions)).thenReturn(
+                settableStatesDescriptions);
+        DeviceStateRotationLockSettingsManager.resetInstance();
+        DeviceStateRotationLockSettingsManager.getInstance(mContext)
+                .resetStateForTesting(mResources);
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateOverviewControllerTest.java b/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateOverviewControllerTest.java
new file mode 100644
index 0000000..a5416e7
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateOverviewControllerTest.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2022 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.display;
+
+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 com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager;
+import com.android.settings.testutils.shadow.ShadowRotationPolicy;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(RobolectricTestRunner.class)
+@Config(shadows = {ShadowRotationPolicy.class, ShadowDeviceStateRotationLockSettingsManager.class})
+public class DeviceStateAutoRotateOverviewControllerTest {
+
+    private final DeviceStateAutoRotateOverviewController mController =
+            new DeviceStateAutoRotateOverviewController(
+                    RuntimeEnvironment.application, "device_state_auto_rotate");
+
+    @Test
+    public void getAvailabilityStatus_rotationAndDeviceStateRotationEnabled_returnsAvailable() {
+        ShadowRotationPolicy.setRotationSupported(true);
+        ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
+
+        int availability = mController.getAvailabilityStatus();
+
+        assertThat(availability).isEqualTo(AVAILABLE);
+    }
+
+    @Test
+    public void getAvailabilityStatus_rotationNotSupported_returnsUnsupportedOnDevice() {
+        ShadowRotationPolicy.setRotationSupported(false);
+        ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
+
+        int availability = mController.getAvailabilityStatus();
+
+        assertThat(availability).isEqualTo(UNSUPPORTED_ON_DEVICE);
+    }
+
+    @Test
+    public void getAvailabilityStatus_deviceStateRotationNotSupported_returnsUnsupportedOnDevice() {
+        ShadowRotationPolicy.setRotationSupported(true);
+        ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(false);
+
+        int availability = mController.getAvailabilityStatus();
+
+        assertThat(availability).isEqualTo(UNSUPPORTED_ON_DEVICE);
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateSettingControllerTest.java b/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateSettingControllerTest.java
new file mode 100644
index 0000000..28a071a
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateSettingControllerTest.java
@@ -0,0 +1,175 @@
+/*
+ * Copyright (C) 2022 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.display;
+
+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 android.content.Context;
+
+import androidx.preference.Preference;
+import androidx.preference.PreferenceManager;
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager;
+import com.android.settings.testutils.shadow.ShadowRotationPolicy;
+import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
+import com.android.settingslib.search.SearchIndexableRaw;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RunWith(RobolectricTestRunner.class)
+@Config(shadows = {
+        ShadowRotationPolicy.class,
+        ShadowDeviceStateRotationLockSettingsManager.class
+})
+public class DeviceStateAutoRotateSettingControllerTest {
+
+    private static final int DEFAULT_DEVICE_STATE = 1;
+    private static final String DEFAULT_DEVICE_STATE_DESCRIPTION = "Device state description";
+    private static final int DEFAULT_ORDER = -10;
+
+    private final Context mContext = RuntimeEnvironment.application;
+    private final DeviceStateAutoRotateSettingController mController =
+            new DeviceStateAutoRotateSettingController(mContext, DEFAULT_DEVICE_STATE,
+                    DEFAULT_DEVICE_STATE_DESCRIPTION, DEFAULT_ORDER);
+    private final DeviceStateRotationLockSettingsManager mAutoRotateSettingsManager =
+            DeviceStateRotationLockSettingsManager.getInstance(mContext);
+
+    @Test
+    public void displayPreference_addsPreferenceToPreferenceScreen() {
+        PreferenceScreen screen = new PreferenceManager(mContext).createPreferenceScreen(mContext);
+
+        mController.displayPreference(screen);
+
+        assertThat(screen.getPreferenceCount()).isEqualTo(1);
+        Preference preference = screen.getPreference(0);
+        assertThat(preference.getTitle().toString()).isEqualTo(DEFAULT_DEVICE_STATE_DESCRIPTION);
+        assertThat(preference.getOrder()).isEqualTo(DEFAULT_ORDER);
+        assertThat(preference.getKey()).isEqualTo(mController.getPreferenceKey());
+    }
+
+    @Test
+    public void getAvailabilityStatus_rotationAndDeviceStateRotationEnabled_returnsAvailable() {
+        ShadowRotationPolicy.setRotationSupported(true);
+        ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
+
+        int availability = mController.getAvailabilityStatus();
+
+        assertThat(availability).isEqualTo(AVAILABLE);
+    }
+
+    @Test
+    public void getAvailabilityStatus_deviceStateRotationDisabled_returnsUnsupported() {
+        ShadowRotationPolicy.setRotationSupported(true);
+        ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(false);
+
+        int availability = mController.getAvailabilityStatus();
+
+        assertThat(availability).isEqualTo(UNSUPPORTED_ON_DEVICE);
+    }
+
+    @Test
+    public void getAvailabilityStatus_rotationDisabled_returnsUnsupported() {
+        ShadowRotationPolicy.setRotationSupported(false);
+        ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
+
+        int availability = mController.getAvailabilityStatus();
+
+        assertThat(availability).isEqualTo(UNSUPPORTED_ON_DEVICE);
+    }
+
+    @Test
+    public void getPreferenceKey_returnsKeyBasedOnDeviceState() {
+        String key = mController.getPreferenceKey();
+
+        String expectedKey = "auto_rotate_device_state_" + DEFAULT_DEVICE_STATE;
+        assertThat(key).isEqualTo(expectedKey);
+    }
+
+    @Test
+    public void isChecked_settingForStateIsUnlocked_returnsTrue() {
+        mAutoRotateSettingsManager.updateSetting(DEFAULT_DEVICE_STATE, /* rotationLocked= */ false);
+
+        assertThat(mController.isChecked()).isTrue();
+    }
+
+    @Test
+    public void isChecked_settingForStateIsLocked_returnsFalse() {
+        mAutoRotateSettingsManager.updateSetting(DEFAULT_DEVICE_STATE, /* rotationLocked= */ true);
+
+        assertThat(mController.isChecked()).isFalse();
+    }
+
+    @Test
+    public void setChecked_true_deviceStateSettingIsUnlocked() {
+        mController.setChecked(true);
+
+        boolean rotationLocked = mAutoRotateSettingsManager.isRotationLocked(DEFAULT_DEVICE_STATE);
+
+        assertThat(rotationLocked).isFalse();
+    }
+
+    @Test
+    public void setChecked_false_deviceStateSettingIsLocked() {
+        mController.setChecked(false);
+
+        boolean rotationLocked = mAutoRotateSettingsManager.isRotationLocked(DEFAULT_DEVICE_STATE);
+
+        assertThat(rotationLocked).isTrue();
+    }
+
+    @Test
+    public void updateRawDataToIndex_addsItemToList() {
+        List<SearchIndexableRaw> rawData = new ArrayList<>();
+
+        mController.updateRawDataToIndex(rawData);
+
+        assertThat(rawData).hasSize(1);
+        SearchIndexableRaw item = rawData.get(0);
+        assertThat(item.key).isEqualTo(mController.getPreferenceKey());
+        assertThat(item.title).isEqualTo(DEFAULT_DEVICE_STATE_DESCRIPTION);
+        assertThat(item.screenTitle).isEqualTo(mContext.getString(R.string.accelerometer_title));
+    }
+
+    @Test
+    public void getSliceHighlightMenuRes_returnsMenuKeyDisplay() {
+        int sliceHighlightMenuRes = mController.getSliceHighlightMenuRes();
+
+        assertThat(sliceHighlightMenuRes).isEqualTo(R.string.menu_key_display);
+    }
+
+    @Test
+    public void isSliceable_returnsTrue() {
+        assertThat(mController.isSliceable()).isTrue();
+    }
+
+    @Test
+    public void isPublicSlice_returnsTrue() {
+        assertThat(mController.isPublicSlice()).isTrue();
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/display/SmartAutoRotateControllerTest.java b/tests/robotests/src/com/android/settings/display/SmartAutoRotateControllerTest.java
index 778721a..4fec38b 100644
--- a/tests/robotests/src/com/android/settings/display/SmartAutoRotateControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/SmartAutoRotateControllerTest.java
@@ -39,7 +39,10 @@
 import androidx.preference.Preference;
 
 import com.android.settings.testutils.ResolveInfoBuilder;
+import com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager;
+import com.android.settings.testutils.shadow.ShadowRotationPolicy;
 import com.android.settings.testutils.shadow.ShadowSensorPrivacyManager;
+import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -63,6 +66,8 @@
     @Mock
     private Preference mPreference;
     private ContentResolver mContentResolver;
+    private final DeviceStateRotationLockSettingsManager mDeviceStateAutoRotateSettingsManager =
+            DeviceStateRotationLockSettingsManager.getInstance(RuntimeEnvironment.application);
 
     @Before
     public void setUp() {
@@ -122,6 +127,34 @@
         assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
     }
 
+    @Test
+    @Config(shadows = {
+            ShadowDeviceStateRotationLockSettingsManager.class,
+            ShadowRotationPolicy.class
+    })
+    public void getAvailabilityStatus_deviceStateRotationLocked_returnDisableDependentSetting() {
+        enableDeviceStateRotation();
+        lockDeviceStateRotation();
+
+        int availabilityStatus = mController.getAvailabilityStatus();
+
+        assertThat(availabilityStatus).isEqualTo(DISABLED_DEPENDENT_SETTING);
+    }
+
+    @Test
+    @Config(shadows = {
+            ShadowDeviceStateRotationLockSettingsManager.class,
+            ShadowRotationPolicy.class
+    })
+    public void getAvailabilityStatus_deviceStateRotationUnlocked_returnAvailable() {
+        enableDeviceStateRotation();
+        unlockDeviceStateRotation();
+
+        int availabilityStatus = mController.getAvailabilityStatus();
+
+        assertThat(availabilityStatus).isEqualTo(AVAILABLE);
+    }
+
     private void enableAutoRotation() {
         Settings.System.putIntForUser(mContentResolver,
                 Settings.System.ACCELEROMETER_ROTATION, 1, UserHandle.USER_CURRENT);
@@ -131,4 +164,23 @@
         Settings.System.putIntForUser(mContentResolver,
                 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT);
     }
+
+    private void enableDeviceStateRotation() {
+        ShadowRotationPolicy.setRotationSupported(true);
+        ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
+    }
+
+    private void lockDeviceStateRotation() {
+        mDeviceStateAutoRotateSettingsManager.updateSetting(
+                /* deviceState= */0, /* rotationLocked= */ true);
+        mDeviceStateAutoRotateSettingsManager.updateSetting(
+                /* deviceState= */1, /* rotationLocked= */ true);
+    }
+
+    private void unlockDeviceStateRotation() {
+        mDeviceStateAutoRotateSettingsManager.updateSetting(
+                /* deviceState= */0, /* rotationLocked= */ false);
+        mDeviceStateAutoRotateSettingsManager.updateSetting(
+                /* deviceState= */1, /* rotationLocked= */ true);
+    }
 }
diff --git a/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceControllerTest.java
index 068de34..39fdb04 100644
--- a/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceControllerTest.java
@@ -40,6 +40,7 @@
 import com.android.settings.core.BasePreferenceController;
 import com.android.settings.testutils.FakeFeatureFactory;
 import com.android.settings.testutils.ResolveInfoBuilder;
+import com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager;
 import com.android.settings.testutils.shadow.ShadowSensorPrivacyManager;
 
 import org.junit.Before;
@@ -53,7 +54,10 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(RobolectricTestRunner.class)
-@Config(shadows = ShadowSensorPrivacyManager.class)
+@Config(shadows = {
+        ShadowSensorPrivacyManager.class,
+        ShadowDeviceStateRotationLockSettingsManager.class
+})
 public class SmartAutoRotatePreferenceControllerTest {
 
     private static final String PACKAGE_NAME = "package_name";
@@ -95,6 +99,7 @@
                 new SmartAutoRotatePreferenceController(mContext, "smart_auto_rotate"));
         when(mController.isCameraLocked()).thenReturn(false);
         when(mController.isPowerSaveMode()).thenReturn(false);
+        ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(false);
     }
 
     @Test
@@ -199,6 +204,16 @@
                 .UNSUPPORTED_ON_DEVICE);
     }
 
+
+    @Test
+    public void getAvailabilityStatus_deviceStateRotationEnabled_returnsUnsupported() {
+        enableAutoRotationPreference();
+        ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
+
+        assertThat(mController.getAvailabilityStatus()).isEqualTo(
+                BasePreferenceController.UNSUPPORTED_ON_DEVICE);
+    }
+
     @Test
     public void isSliceableCorrectKey_returnsTrue() {
         final AutoRotatePreferenceController controller =
diff --git a/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceFragmentTest.java
index 877d2c1..942fed6 100644
--- a/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceFragmentTest.java
@@ -18,6 +18,8 @@
 
 import static com.android.settings.display.SmartAutoRotatePreferenceFragment.AUTO_ROTATE_SWITCH_PREFERENCE_ID;
 
+import static com.google.common.truth.Truth.assertThat;
+
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyInt;
 import static org.mockito.Mockito.doReturn;
@@ -33,6 +35,7 @@
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
 import android.content.pm.ServiceInfo;
+import android.content.res.Resources;
 import android.view.View;
 
 import androidx.preference.Preference;
@@ -40,7 +43,11 @@
 import com.android.settings.R;
 import com.android.settings.SettingsActivity;
 import com.android.settings.testutils.ResolveInfoBuilder;
+import com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager;
+import com.android.settings.testutils.shadow.ShadowRotationPolicy;
 import com.android.settings.widget.SettingsMainSwitchBar;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -49,8 +56,15 @@
 import org.mockito.MockitoAnnotations;
 import org.robolectric.RobolectricTestRunner;
 import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import java.util.List;
 
 @RunWith(RobolectricTestRunner.class)
+@Config(shadows = {
+        ShadowDeviceStateRotationLockSettingsManager.class,
+        ShadowRotationPolicy.class
+})
 public class SmartAutoRotatePreferenceFragmentTest {
 
     private static final String PACKAGE_NAME = "package_name";
@@ -70,19 +84,24 @@
 
     @Mock
     private Preference mRotateSwitchPreference;
+    private Resources mResources;
+    private Context mContext;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
 
-        final Context context = spy(RuntimeEnvironment.application);
+        mContext = spy(RuntimeEnvironment.application);
         ContentResolver mContentResolver = RuntimeEnvironment.application.getContentResolver();
-        when(context.getPackageManager()).thenReturn(mPackageManager);
-        when(context.getContentResolver()).thenReturn(mContentResolver);
+        when(mContext.getPackageManager()).thenReturn(mPackageManager);
+        when(mContext.getContentResolver()).thenReturn(mContentResolver);
         doReturn(PACKAGE_NAME).when(mPackageManager).getRotationResolverPackageName();
         doReturn(PackageManager.PERMISSION_GRANTED).when(mPackageManager).checkPermission(
                 Manifest.permission.CAMERA, PACKAGE_NAME);
 
+        mResources = spy(mContext.getResources());
+        when(mContext.getResources()).thenReturn(mResources);
+
         final ResolveInfo resolveInfo = new ResolveInfoBuilder(PACKAGE_NAME).build();
         resolveInfo.serviceInfo = new ServiceInfo();
         when(mPackageManager.resolveService(any(), anyInt())).thenReturn(resolveInfo);
@@ -90,15 +109,16 @@
         mFragment = spy(new SmartAutoRotatePreferenceFragment());
         when(mActivity.getPackageManager()).thenReturn(mPackageManager);
         when(mFragment.getActivity()).thenReturn(mActivity);
-        when(mFragment.getContext()).thenReturn(context);
+        when(mFragment.getContext()).thenReturn(mContext);
         doReturn(mView).when(mFragment).getView();
 
         when(mFragment.findPreference(AUTO_ROTATE_SWITCH_PREFERENCE_ID)).thenReturn(
                 mRotateSwitchPreference);
 
-        mSwitchBar = spy(new SettingsMainSwitchBar(context));
+        mSwitchBar = spy(new SettingsMainSwitchBar(mContext));
         when(mActivity.getSwitchBar()).thenReturn(mSwitchBar);
         doReturn(mSwitchBar).when(mView).findViewById(R.id.switch_bar);
+        ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(false);
     }
 
 
@@ -111,6 +131,17 @@
     }
 
     @Test
+    public void createHeader_deviceStateRotationSupported_switchBarIsDisabled() {
+        ShadowRotationPolicy.setRotationSupported(true);
+        ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
+
+        mFragment.createHeader(mActivity);
+
+        verify(mSwitchBar, never()).show();
+        verify(mRotateSwitchPreference, never()).setVisible(false);
+    }
+
+    @Test
     public void createHeader_faceDetectionUnSupported_switchBarIsDisabled() {
         doReturn(null).when(mPackageManager).getRotationResolverPackageName();
 
@@ -120,4 +151,41 @@
         verify(mRotateSwitchPreference, never()).setVisible(false);
     }
 
+    @Test
+    public void createPreferenceControllers_noSettableDeviceStates_returnsEmptyList() {
+        enableDeviceStateSettableRotationStates(new String[]{}, new String[]{});
+
+        List<AbstractPreferenceController> preferenceControllers =
+                mFragment.createPreferenceControllers(mContext);
+
+        assertThat(preferenceControllers).isEmpty();
+    }
+
+    @Test
+    public void createPreferenceControllers_settableDeviceStates_returnsDeviceStateControllers() {
+        enableDeviceStateSettableRotationStates(new String[]{"0:1", "1:1"},
+                new String[]{"Folded", "Unfolded"});
+
+        List<AbstractPreferenceController> preferenceControllers =
+                mFragment.createPreferenceControllers(mContext);
+
+        assertThat(preferenceControllers).hasSize(2);
+        assertThat(preferenceControllers.get(0)).isInstanceOf(
+                DeviceStateAutoRotateSettingController.class);
+        assertThat(preferenceControllers.get(1)).isInstanceOf(
+                DeviceStateAutoRotateSettingController.class);
+    }
+
+    private void enableDeviceStateSettableRotationStates(String[] settableStates,
+            String[] settableStatesDescriptions) {
+        when(mResources.getStringArray(
+                com.android.internal.R.array.config_perDeviceStateRotationLockDefaults)).thenReturn(
+                settableStates);
+        when(mResources.getStringArray(
+                R.array.config_settableAutoRotationDeviceStatesDescriptions)).thenReturn(
+                settableStatesDescriptions);
+        DeviceStateRotationLockSettingsManager.resetInstance();
+        DeviceStateRotationLockSettingsManager.getInstance(mContext)
+                .resetStateForTesting(mResources);
+    }
 }
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/EligibleCardCheckerTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/EligibleCardCheckerTest.java
index e63dd80..64dbbb2 100644
--- a/tests/robotests/src/com/android/settings/homepage/contextualcards/EligibleCardCheckerTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/EligibleCardCheckerTest.java
@@ -24,20 +24,26 @@
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.spy;
 
+import android.app.Activity;
+import android.app.PendingIntent;
 import android.content.Context;
+import android.content.Intent;
 import android.net.Uri;
 
+import androidx.core.graphics.drawable.IconCompat;
 import androidx.slice.Slice;
 import androidx.slice.SliceProvider;
 import androidx.slice.widget.SliceLiveData;
+import androidx.slice.builders.ListBuilder;
+import androidx.slice.builders.SliceAction;
 
+import com.android.settings.R;
 import com.android.settings.slices.CustomSliceRegistry;
-import com.android.settings.wifi.slice.ContextualWifiSlice;
 
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.robolectric.Robolectric;
 import org.robolectric.RobolectricTestRunner;
 import org.robolectric.RuntimeEnvironment;
 
@@ -48,6 +54,7 @@
 
     private Context mContext;
     private EligibleCardChecker mEligibleCardChecker;
+    private Activity mActivity;
 
     @Before
     public void setUp() {
@@ -55,22 +62,19 @@
         mEligibleCardChecker =
                 spy(new EligibleCardChecker(mContext, getContextualCard(TEST_SLICE_URI)));
         SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
+        mActivity = Robolectric.buildActivity(Activity.class).create().get();
     }
 
     @Test
-    @Ignore
     public void isSliceToggleable_cardWithToggle_returnTrue() {
-        final ContextualWifiSlice wifiSlice = new ContextualWifiSlice(mContext);
-        final Slice slice = wifiSlice.getSlice();
+        final Slice slice = buildSlice();
 
         assertThat(mEligibleCardChecker.isSliceToggleable(slice)).isTrue();
     }
 
     @Test
-    @Ignore
     public void isCardEligibleToDisplay_toggleSlice_hasInlineActionShouldBeTrue() {
-        final ContextualWifiSlice wifiSlice = new ContextualWifiSlice(mContext);
-        final Slice slice = wifiSlice.getSlice();
+        final Slice slice = buildSlice();
         doReturn(slice).when(mEligibleCardChecker).bindSlice(any(Uri.class));
 
         mEligibleCardChecker.isCardEligibleToDisplay(getContextualCard(TEST_SLICE_URI));
@@ -118,10 +122,8 @@
     }
 
     @Test
-    @Ignore
     public void isCardEligibleToDisplay_sliceNotNull_cacheSliceToCard() {
-        final ContextualWifiSlice wifiSlice = new ContextualWifiSlice(mContext);
-        final Slice slice = wifiSlice.getSlice();
+        final Slice slice = buildSlice();
         doReturn(slice).when(mEligibleCardChecker).bindSlice(any(Uri.class));
 
         mEligibleCardChecker.isCardEligibleToDisplay(getContextualCard(TEST_SLICE_URI));
@@ -137,4 +139,23 @@
                 .setSliceUri(sliceUri)
                 .build();
     }
+
+    private Slice buildSlice() {
+        final String title = "test_title";
+        final IconCompat icon = IconCompat.createWithResource(mActivity, R.drawable.empty_icon);
+        final PendingIntent pendingIntent = PendingIntent.getActivity(
+                mActivity,
+                title.hashCode() /* requestCode */,
+                new Intent("test action"),
+                PendingIntent.FLAG_IMMUTABLE);
+        final SliceAction action
+                = SliceAction.createDeeplink(pendingIntent, icon, ListBuilder.SMALL_IMAGE, title);
+        return new ListBuilder(mActivity, TEST_SLICE_URI, ListBuilder.INFINITY)
+                .addRow(new ListBuilder.RowBuilder()
+                        .addEndItem(icon, ListBuilder.ICON_IMAGE)
+                        .setTitle(title)
+                        .setPrimaryAction(action))
+                .addAction(SliceAction.createToggle(pendingIntent, null /* actionTitle */, true))
+                .build();
+    }
 }
diff --git a/tests/robotests/src/com/android/settings/network/MobileNetworkSummaryControllerTest.java b/tests/robotests/src/com/android/settings/network/MobileNetworkSummaryControllerTest.java
index fc6481b..dcf086c 100644
--- a/tests/robotests/src/com/android/settings/network/MobileNetworkSummaryControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/MobileNetworkSummaryControllerTest.java
@@ -44,6 +44,8 @@
 import androidx.preference.PreferenceScreen;
 
 import com.android.settings.Settings.MobileNetworkActivity;
+import com.android.settings.network.helper.SubscriptionAnnotation;
+import com.android.settings.network.helper.SubscriptionGrouping;
 import com.android.settings.widget.AddPreference;
 import com.android.settingslib.RestrictedLockUtils;
 
@@ -123,7 +125,6 @@
 
 
     @Test
-    @Ignore
     public void getSummary_noSubscriptions_correctSummaryAndClickHandler() {
         mController.displayPreference(mPreferenceScreen);
         mController.onResume();
@@ -212,23 +213,6 @@
     }
 
     @Test
-    @Ignore
-    public void getSummary_providerModel_Enabled() {
-        final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
-        final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
-        when(sub1.getSubscriptionId()).thenReturn(1);
-        when(sub2.getSubscriptionId()).thenReturn(2);
-        when(sub1.getDisplayName()).thenReturn("sub1");
-        when(sub2.getDisplayName()).thenReturn("sub2");
-
-        SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1, sub2));
-        SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1, sub2));
-        mController.displayPreference(mPreferenceScreen);
-        mController.onResume();
-        assertThat(mController.getSummary()).isEqualTo("sub1, sub2");
-    }
-
-    @Test
     public void addButton_noSubscriptionsNoEuiccMgr_noAddClickListener() {
         when(mEuiccManager.isEnabled()).thenReturn(false);
         mController.displayPreference(mPreferenceScreen);
@@ -319,7 +303,6 @@
     }
 
     @Test
-    @Ignore
     public void onAirplaneModeChanged_oneSubscriptionAirplaneModeGetsTurnedOn_isDisabled() {
         final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
         SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1));
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowDeviceStateRotationLockSettingsManager.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowDeviceStateRotationLockSettingsManager.java
new file mode 100644
index 0000000..72df3cc
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowDeviceStateRotationLockSettingsManager.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2022 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.testutils.shadow;
+
+import android.content.Context;
+
+import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
+
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+
+@Implements(DeviceStateRotationLockSettingsManager.class)
+public class ShadowDeviceStateRotationLockSettingsManager {
+
+    private static boolean sDeviceStateRotationLockEnabled;
+
+    @Implementation
+    public static boolean isDeviceStateRotationLockEnabled(Context context) {
+        return sDeviceStateRotationLockEnabled;
+    }
+
+    public static void setDeviceStateRotationLockEnabled(boolean enabled) {
+        sDeviceStateRotationLockEnabled = enabled;
+    }
+}
diff --git a/tests/unit/src/com/android/settings/applications/appinfo/AppLocaleDetailsTest.java b/tests/unit/src/com/android/settings/applications/appinfo/AppLocaleDetailsTest.java
index ed4c127..0f9d54b 100644
--- a/tests/unit/src/com/android/settings/applications/appinfo/AppLocaleDetailsTest.java
+++ b/tests/unit/src/com/android/settings/applications/appinfo/AppLocaleDetailsTest.java
@@ -20,6 +20,7 @@
 import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import android.app.LocaleManager;
@@ -32,7 +33,7 @@
 import androidx.test.core.app.ApplicationProvider;
 import androidx.test.ext.junit.runners.AndroidJUnit4;
 
-import com.google.common.collect.Iterables;
+import com.android.settingslib.widget.RadioButtonPreference;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -40,8 +41,14 @@
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Locale;
 
+/**
+ * Unittest for ApplocaleDetails
+ * TODO Need to add a unittest for the UI preference component.
+ */
 @RunWith(AndroidJUnit4.class)
 public class AppLocaleDetailsTest {
     private static final String APP_PACKAGE_NAME = "app_package_name";
@@ -52,7 +59,7 @@
     private LocaleManager mLocaleManager;
 
     private Context mContext;
-    private LocaleList mSystemLocales;
+    private Collection<Locale> mSystemLocales;
     private LocaleList mAppLocale;
     private String[] mAssetLocales;
     private LocaleList mPackageLocales;
@@ -69,12 +76,48 @@
         when(mContext.getSystemService(LocaleManager.class)).thenReturn(mLocaleManager);
 
         setupInitialLocales(
-                /* appLocale= */ "en",
+                /* appLocale= */ "en-gb",
                 /* simCountry= */ "tw",
                 /* networkCountry= */ "jp",
-                /* systemLocales= */ "en, uk, jp, ne",
-                /* packageLocales= */ "pa, cn, tw, en",
-                /* assetLocales= */ new String[]{"en", "ne", "ms", "pa"});
+                /* systemLocales= */ "en-gb, ru, ja-jp, ne, zh-tw",
+                /* packageLocales= */ "pa, cn, zh-tw, en-gb, ja-jp",
+                /* assetLocales= */ new String[]{"en-gb", "ne", "ms", "pa", "zh-tw", "ja-jp"});
+    }
+
+    @Test
+    @UiThreadTest
+    public void onRadioButtonClicked_setCurrentLocaleToSystem() {
+        AppLocaleDetails appLocaleDetails = new AppLocaleDetails() {
+            @Override
+            void refreshUiInternal() {}
+        };
+        DummyAppLocaleDetailsHelper helper =
+                spy(new DummyAppLocaleDetailsHelper(mContext, APP_PACKAGE_NAME));
+        appLocaleDetails.mAppLocaleDetailsHelper = helper;
+        RadioButtonPreference pref = new RadioButtonPreference(mContext);
+        pref.setKey(AppLocaleDetails.KEY_SYSTEM_DEFAULT_LOCALE);
+
+        appLocaleDetails.onRadioButtonClicked(pref);
+
+        verify(helper).setAppDefaultLocale(LocaleList.forLanguageTags(""));
+    }
+
+    @Test
+    @UiThreadTest
+    public void onRadioButtonClicked_setCurrentLocaleForUserSelected() {
+        AppLocaleDetails appLocaleDetails = new AppLocaleDetails() {
+            @Override
+            void refreshUiInternal() {}
+        };
+        DummyAppLocaleDetailsHelper helper =
+                spy(new DummyAppLocaleDetailsHelper(mContext, APP_PACKAGE_NAME));
+        appLocaleDetails.mAppLocaleDetailsHelper = helper;
+        RadioButtonPreference pref = new RadioButtonPreference(mContext);
+        pref.setKey("en");
+
+        appLocaleDetails.onRadioButtonClicked(pref);
+
+        verify(helper).setAppDefaultLocale("en");
     }
 
     @Test
@@ -90,7 +133,7 @@
 
     @Test
     @UiThreadTest
-    public void handleAllLocalesData_1stLocaleOfSuggestedLocaleListIsAppLocale() {
+    public void handleAllLocalesData_1stLocaleIsAppLocaleAndHasSimAndNetwork() {
         Locale simCountryLocale = new Locale("zh", "TW");
         Locale networkCountryLocale = new Locale("ja", "JP");
         DummyAppLocaleDetailsHelper helper =
@@ -98,36 +141,122 @@
 
         helper.handleAllLocalesData();
 
-        Locale locale = Iterables.get(helper.getSuggestedLocales(), 0);
+        Collection<Locale> suggestedLocales = helper.getSuggestedLocales();
+        Locale locale = suggestedLocales.iterator().next();
         assertTrue(locale.equals(mAppLocale.get(0)));
-        assertTrue(helper.getSuggestedLocales().contains(simCountryLocale));
-        assertTrue(helper.getSuggestedLocales().contains(networkCountryLocale));
+        assertTrue(suggestedLocales.contains(simCountryLocale));
+        assertTrue(suggestedLocales.contains(networkCountryLocale));
     }
 
     @Test
     @UiThreadTest
-    public void handleAllLocalesData_withoutAppLocale_1stSuggestedLocaleIsSimCountryLocale() {
-        Locale simCountryLocale = new Locale("zh", "TW");
+    public void
+            handleAllLocalesData_noAppAndNoSupportedSimLocale_1stSuggestedLocaleIsAssetLocale() {
+        Locale firstAssetLocale = new Locale("en", "GB");
         setupInitialLocales(
                 /* appLocale= */ "",
                 /* simCountry= */ "tw",
                 /* networkCountry= */ "",
-                /* systemLocales= */ "en, uk, jp, ne",
+                /* systemLocales= */ "en-gb, ru, ja-jp, ne, zh-tw",
                 /* packageLocales= */ "",
-                /* assetLocales= */ new String[]{});
+                /* assetLocales= */ new String[]{"en-gb", "ne", "ms", "pa", "ja-jp"});
         DummyAppLocaleDetailsHelper helper =
                 new DummyAppLocaleDetailsHelper(mContext, APP_PACKAGE_NAME);
 
         helper.handleAllLocalesData();
 
-        Locale locale = Iterables.get(helper.getSuggestedLocales(), 0);
-        assertTrue(locale.equals(simCountryLocale));
-        assertFalse(helper.getSuggestedLocales().contains(mAppLocale.get(0)));
+        Collection<Locale> suggestedLocales = helper.getSuggestedLocales();
+        Locale locale = suggestedLocales.iterator().next();
+        assertTrue(locale.equals(firstAssetLocale));
     }
 
     @Test
     @UiThreadTest
-    public void handleAllLocalesData_withoutAppLocale_1stSuggestedLocaleIsNetworkCountryLocale() {
+    public void handleAllLocalesData_noAppButHasSupportedSimLocale_1stSuggestedLocaleIsSim() {
+        Locale simLocale = new Locale("zh", "tw");
+        setupInitialLocales(
+                /* appLocale= */ "",
+                /* simCountry= */ "tw",
+                /* networkCountry= */ "",
+                /* systemLocales= */ "en-gb, ru, ja-jp, ne, zh-tw",
+                /* packageLocales= */ "",
+                /* assetLocales= */ new String[]{"en-gb", "ne", "ms", "pa", "ja-jp", "zh-tw"});
+        DummyAppLocaleDetailsHelper helper =
+                new DummyAppLocaleDetailsHelper(mContext, APP_PACKAGE_NAME);
+
+        helper.handleAllLocalesData();
+
+        Collection<Locale> suggestedLocales = helper.getSuggestedLocales();
+        Locale locale = suggestedLocales.iterator().next();
+        assertTrue(locale.equals(simLocale));
+    }
+
+    @Test
+    @UiThreadTest
+    public void
+            handleAllLocalesData_noAppButHasSupportedNetworkLocale_1stSuggestedLocaleIsNetwork() {
+        Locale networkLocale = new Locale("ja", "JP");
+        setupInitialLocales(
+                /* appLocale= */ "",
+                /* simCountry= */ "",
+                /* networkCountry= */ "jp",
+                /* systemLocales= */ "en-gb, ru, ja-jp, ne, zh-tw",
+                /* packageLocales= */ "",
+                /* assetLocales= */ new String[]{"en-gb", "ne", "ms", "pa", "ja-jp"});
+        DummyAppLocaleDetailsHelper helper =
+                new DummyAppLocaleDetailsHelper(mContext, APP_PACKAGE_NAME);
+
+        helper.handleAllLocalesData();
+
+        Collection<Locale> suggestedLocales = helper.getSuggestedLocales();
+        Locale locale = suggestedLocales.iterator().next();
+        assertTrue(locale.equals(networkLocale));
+    }
+
+    @Test
+    @UiThreadTest
+    public void handleAllLocalesData_noAppSimOrNetworkLocale_suggestedLocalesHasSystemLocale() {
+        setupInitialLocales(
+                /* appLocale= */ "",
+                /* simCountry= */ "",
+                /* networkCountry= */ "",
+                /* systemLocales= */ "en-gb, ru, ja-jp, ne, zh-tw",
+                /* packageLocales= */ "",
+                /* assetLocales= */ new String[]{"en-gb", "ne", "ms", "pa", "zh-tw", "ja-jp"});
+        DummyAppLocaleDetailsHelper helper =
+                new DummyAppLocaleDetailsHelper(mContext, APP_PACKAGE_NAME);
+        helper.handleAllLocalesData();
+
+        Collection<Locale> suggestedLocales = helper.getSuggestedLocales();
+        assertTrue(suggestedLocales.contains(Locale.forLanguageTag("ne")));
+        // ru language is not present in the asset locales
+        assertFalse(suggestedLocales.contains(Locale.forLanguageTag("ru")));
+    }
+
+    @Test
+    @UiThreadTest
+    public void handleAllLocalesData_noAppButHasSimAndNetworkLocale_1stLocaleIsSimLocale() {
+        Locale simCountryLocale = new Locale("zh", "TW");
+        setupInitialLocales(
+                /* appLocale= */ "",
+                /* simCountry= */ "tw",
+                /* networkCountry= */ "jp",
+                /* systemLocales= */ "en-gb, ru, ja-jp, ne, zh-tw",
+                /* packageLocales= */ "",
+                /* assetLocales= */ new String[]{"en-gb", "ne", "ms", "pa", "zh-tw", "ja-jp"});
+
+        DummyAppLocaleDetailsHelper helper =
+                new DummyAppLocaleDetailsHelper(mContext, APP_PACKAGE_NAME);
+        helper.handleAllLocalesData();
+
+        Collection<Locale> suggestedLocales = helper.getSuggestedLocales();
+        Locale locale = suggestedLocales.iterator().next();
+        assertTrue(locale.equals(simCountryLocale));
+    }
+
+    @Test
+    @UiThreadTest
+    public void handleAllLocalesData_noSupportedLocale_noSuggestedLocales() {
         Locale networkCountryLocale = new Locale("en", "GB");
         setupInitialLocales(
                 /* appLocale= */ "",
@@ -141,28 +270,8 @@
 
         helper.handleAllLocalesData();
 
-        Locale locale = Iterables.get(helper.getSuggestedLocales(), 0);
-        assertTrue(locale.equals(networkCountryLocale));
-        assertFalse(helper.getSuggestedLocales().contains(mAppLocale.get(0)));
-    }
-
-    @Test
-    @UiThreadTest
-    public void handleAllLocalesData_noAppAndSimNetworkLocale_1stLocaleIsFirstOneInSystemLocales() {
-        setupInitialLocales(
-                /* appLocale= */ "",
-                /* simCountry= */ "",
-                /* networkCountry= */ "",
-                /* systemLocales= */ "en, uk, jp, ne",
-                /* packageLocales= */ "",
-                /* assetLocales= */ new String[]{});
-        DummyAppLocaleDetailsHelper helper =
-                new DummyAppLocaleDetailsHelper(mContext, APP_PACKAGE_NAME);
-
-        helper.handleAllLocalesData();
-
-        Locale locale = Iterables.get(helper.getSuggestedLocales(), 0);
-        assertTrue(locale.equals(mSystemLocales.get(0)));
+        Collection<Locale> suggestedLocales = helper.getSuggestedLocales();
+        assertTrue(suggestedLocales.size() == 0);
     }
 
     @Test
@@ -180,8 +289,10 @@
 
         helper.handleAllLocalesData();
 
-        Locale locale = Iterables.get(helper.getSuggestedLocales(), 0);
-        assertTrue(locale.equals(mSystemLocales.get(0)));
+        Collection<Locale> suggestedLocales = helper.getSuggestedLocales();
+        Locale locale = suggestedLocales.iterator().next();
+        Locale systemLocale = mSystemLocales.iterator().next();
+        assertTrue(locale.equals(systemLocale));
     }
 
     @Test
@@ -248,15 +359,23 @@
             String packageLocales,
             String[] assetLocales) {
         mAppLocale = LocaleList.forLanguageTags(appLocale);
-        mSystemLocales = LocaleList.forLanguageTags(systemLocales);
+        // forLanguageTags does not filter space to the input string. If there is any space included
+        // in string, this will make locale fail to generate.
+        systemLocales = systemLocales.replaceAll("\\s+", "");
+        LocaleList listOfSystemLocales = LocaleList.forLanguageTags(systemLocales);
+        mSystemLocales = new ArrayList<>();
+        for (int i = 0; i < listOfSystemLocales.size(); i++) {
+            mSystemLocales.add(listOfSystemLocales.get(i));
+        }
         mAssetLocales = assetLocales;
+        packageLocales = packageLocales.replaceAll("\\s+", "");
         mPackageLocales = LocaleList.forLanguageTags(packageLocales);
         when(mTelephonyManager.getSimCountryIso()).thenReturn(simCountry);
         when(mTelephonyManager.getNetworkCountryIso()).thenReturn(networkCountry);
         when(mLocaleManager.getApplicationLocales(anyString())).thenReturn(mAppLocale);
     }
 
-    private class DummyAppLocaleDetailsHelper
+    public class DummyAppLocaleDetailsHelper
             extends AppLocaleDetails.AppLocaleDetailsHelper {
 
         DummyAppLocaleDetailsHelper(Context context, String packageName) {
@@ -264,12 +383,12 @@
         }
 
         @Override
-        String[] getAssetSystemLocales() {
+        String[] getAssetLocales() {
             return mAssetLocales;
         }
 
         @Override
-        LocaleList getCurrentSystemLocales() {
+        Collection<Locale> getCurrentSystemLocales() {
             return mSystemLocales;
         }