Merge "Show different tooltips for QS features auto-added and non-auto-added"
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/color-check-baseline.xml b/color-check-baseline.xml
index 16658f8..ba4d2f6 100644
--- a/color-check-baseline.xml
+++ b/color-check-baseline.xml
@@ -3736,7 +3736,7 @@
         errorLine1="            android:color=&quot;@color/accessibility_feature_background&quot;/>"
         errorLine2="            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
         <location
-            file="res/drawable/ic_text_and_display.xml"
+            file="res/drawable/ic_color_and_motion.xml"
             line="22"
             column="13"/>
     </issue>
diff --git a/res/color/dream_card_color_state_list.xml b/res/color/dream_card_color_state_list.xml
index b5de7b4..b0c86bb 100644
--- a/res/color/dream_card_color_state_list.xml
+++ b/res/color/dream_card_color_state_list.xml
@@ -17,6 +17,6 @@
 
 <selector xmlns:android="http://schemas.android.com/apk/res/android"
           xmlns:androidprv="http://schemas.android.com/apk/prv/res/android">
-    <item android:state_selected="true" android:color="?androidprv:attr/colorSurfaceVariant"/>
-    <item android:color="?androidprv:attr/colorSurfaceHighlight"/>
+    <item android:state_selected="true" android:color="?androidprv:attr/colorAccentPrimary"/>
+    <item android:color="?androidprv:attr/colorSurface"/>
 </selector>
\ No newline at end of file
diff --git a/res/color/dream_card_text_color_state_list.xml b/res/color/dream_card_text_color_state_list.xml
new file mode 100644
index 0000000..438855f
--- /dev/null
+++ b/res/color/dream_card_text_color_state_list.xml
@@ -0,0 +1,22 @@
+<?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.
+  -->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android"
+          xmlns:androidprv="http://schemas.android.com/apk/prv/res/android">
+    <item android:state_selected="true" android:color="?androidprv:attr/textColorOnAccent"/>
+    <item android:color="?android:attr/textColorPrimary"/>
+</selector>
\ No newline at end of file
diff --git a/res/drawable/dream_default_preview_icon.xml b/res/drawable/dream_default_preview_icon.xml
new file mode 100644
index 0000000..7d247bb
--- /dev/null
+++ b/res/drawable/dream_default_preview_icon.xml
@@ -0,0 +1,24 @@
+<!--
+  ~ 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.
+  -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24"
+        android:viewportHeight="24">
+    <path android:fillColor="?android:attr/textColorSecondary"
+          android:pathData="M3,19Q2.175,19 1.588,18.413Q1,17.825 1,17V7Q1,6.175 1.588,5.588Q2.175,5 3,5H13Q13.825,5 14.413,5.588Q15,6.175 15,7V17Q15,17.825 14.413,18.413Q13.825,19 13,19ZM3,17H13Q13,17 13,17Q13,17 13,17V7Q13,7 13,7Q13,7 13,7H3Q3,7 3,7Q3,7 3,7V17Q3,17 3,17Q3,17 3,17ZM17,19V5H19V19ZM21,19V5H23V19ZM4,15H12L9.4,11.5L7.5,14L6.1,12.15ZM3,7Q3,7 3,7Q3,7 3,7V17Q3,17 3,17Q3,17 3,17Q3,17 3,17Q3,17 3,17V7Q3,7 3,7Q3,7 3,7Z"/>
+</vector>
\ No newline at end of file
diff --git a/res/drawable/dream_preview_rounded_bg.xml b/res/drawable/dream_preview_rounded_bg.xml
new file mode 100644
index 0000000..4da0c7c1
--- /dev/null
+++ b/res/drawable/dream_preview_rounded_bg.xml
@@ -0,0 +1,22 @@
+<!--
+  ~ 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.
+  -->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+       xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
+       android:shape="rectangle">
+    <solid android:color="?androidprv:attr/colorSurfaceHighlight" />
+    <corners android:radius="@dimen/dream_item_corner_radius"/>
+</shape>
\ No newline at end of file
diff --git a/res/drawable/ic_text_and_display.xml b/res/drawable/ic_color_and_motion.xml
similarity index 100%
rename from res/drawable/ic_text_and_display.xml
rename to res/drawable/ic_color_and_motion.xml
diff --git a/res/layout/dream_picker_layout.xml b/res/layout/dream_picker_layout.xml
index 6de7ff6..68e2051 100644
--- a/res/layout/dream_picker_layout.xml
+++ b/res/layout/dream_picker_layout.xml
@@ -15,32 +15,25 @@
     limitations under the License.
 -->
 
-<LinearLayout
+
+<androidx.constraintlayout.widget.ConstraintLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="wrap_content">
 
-    <androidx.cardview.widget.CardView
-        android:id="@+id/dream_picker_container"
-        android:layout_width="match_parent"
+    <androidx.recyclerview.widget.RecyclerView
+        android:id="@+id/dream_list"
+        android:layout_width="0dp"
         android:layout_height="wrap_content"
-        style="@style/DreamPickerBackgroundStyle">
+        android:clipToPadding="true"
+        android:nestedScrollingEnabled="false"
+        android:paddingStart="?android:attr/listPreferredItemPaddingStart"
+        android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
+        android:paddingBottom="@dimen/dream_preference_card_padding"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintBottom_toBottomOf="parent"/>
 
-        <androidx.constraintlayout.widget.ConstraintLayout
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content">
-
-            <androidx.recyclerview.widget.RecyclerView
-                android:id="@+id/dream_list"
-                android:layout_width="0dp"
-                android:layout_height="wrap_content"
-                android:clipToPadding="true"
-                android:nestedScrollingEnabled="false"
-                app:layout_constraintStart_toStartOf="parent"
-                app:layout_constraintEnd_toEndOf="parent"/>
-
-        </androidx.constraintlayout.widget.ConstraintLayout>
-
-    </androidx.cardview.widget.CardView>
-</LinearLayout>
+</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
diff --git a/res/layout/dream_preference_layout.xml b/res/layout/dream_preference_layout.xml
index 2bc67ba..9528f4d 100644
--- a/res/layout/dream_preference_layout.xml
+++ b/res/layout/dream_preference_layout.xml
@@ -17,7 +17,6 @@
 
 <androidx.cardview.widget.CardView
     xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:id="@+id/container"
     android:layout_width="match_parent"
@@ -30,21 +29,26 @@
         android:layout_height="wrap_content"
         android:minHeight="?android:attr/listPreferredItemHeight">
 
-        <androidx.cardview.widget.CardView
-            android:id="@+id/preview_container"
-            android:layout_width="match_parent"
+        <ImageView
+            android:id="@+id/preview"
+            android:layout_width="0dp"
             android:layout_height="0dp"
-            app:cardCornerRadius="@dimen/dream_item_corner_radius"
-            app:cardElevation="0dp"
+            android:background="@drawable/dream_preview_rounded_bg"
             app:layout_constraintDimensionRatio="1:1"
             app:layout_constraintTop_toTopOf="parent"
-            app:layout_constraintStart_toStartOf="parent">
-            <ImageView
-                android:id="@+id/preview"
-                android:layout_width="match_parent"
-                android:layout_height="match_parent"
-                android:scaleType="centerCrop"/>
-        </androidx.cardview.widget.CardView>
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"/>
+
+        <ImageView
+            android:id="@+id/preview_placeholder"
+            android:layout_width="@dimen/dream_preview_placeholder_width"
+            android:layout_height="0dp"
+            android:src="@drawable/dream_default_preview_icon"
+            app:layout_constraintDimensionRatio="1:1"
+            app:layout_constraintTop_toTopOf="@+id/preview"
+            app:layout_constraintBottom_toBottomOf="@+id/preview"
+            app:layout_constraintStart_toStartOf="@+id/preview"
+            app:layout_constraintEnd_toEndOf="@+id/preview"/>
 
         <Button
             android:id="@+id/customize_button"
@@ -53,10 +57,10 @@
             android:layout_height="wrap_content"
             android:visibility="gone"
             android:text="@string/customize_button_title"
-            app:layout_constraintTop_toTopOf="@+id/preview_container"
-            app:layout_constraintBottom_toBottomOf="@+id/preview_container"
-            app:layout_constraintStart_toStartOf="@+id/preview_container"
-            app:layout_constraintEnd_toEndOf="@+id/preview_container"/>
+            app:layout_constraintTop_toTopOf="@+id/preview"
+            app:layout_constraintBottom_toBottomOf="@+id/preview"
+            app:layout_constraintStart_toStartOf="@+id/preview"
+            app:layout_constraintEnd_toEndOf="@+id/preview"/>
 
         <ImageView
             android:id="@+id/icon"
@@ -68,7 +72,7 @@
             android:gravity="center_vertical"
             app:layout_constraintDimensionRatio="1:1"
             app:layout_constraintHorizontal_chainStyle="packed"
-            app:layout_constraintTop_toBottomOf="@+id/preview_container"
+            app:layout_constraintTop_toBottomOf="@+id/preview"
             app_layout_constraintEnd_toStartOf="@+id/title_text"
             app:layout_constraintStart_toStartOf="parent"/>
 
@@ -82,8 +86,9 @@
             android:gravity="center_vertical"
             android:maxLines="1"
             android:ellipsize="end"
-            android:textAppearance="?android:attr/textAppearanceListItemSmall"
-            app:layout_constraintTop_toBottomOf="@+id/preview_container"
+            android:textSize="16sp"
+            android:textColor="@color/dream_card_text_color_state_list"
+            app:layout_constraintTop_toBottomOf="@+id/preview"
             app:layout_constraintEnd_toEndOf="parent"
             app:layout_constraintStart_toEndOf="@+id/icon"/>
 
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/layout/lockscreen_remote_input.xml b/res/layout/lockscreen_remote_input.xml
deleted file mode 100644
index 4fa44ce..0000000
--- a/res/layout/lockscreen_remote_input.xml
+++ /dev/null
@@ -1,46 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-  ~ Copyright (C) 2016 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
-  -->
-
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content">
-
-    <CheckBox
-            android:id="@+id/lockscreen_remote_input"
-            android:layout_width="0dp"
-            android:layout_height="wrap_content"
-            android:layout_weight="1"
-            android:layout_marginStart="20dp"
-            android:paddingStart="20dp"
-            android:paddingEnd="?android:attr/dialogPreferredPadding"
-            android:minHeight="?android:attr/listPreferredItemHeightSmall"
-            android:textAppearance="?android:attr/textAppearanceMedium"
-            android:textColor="?android:attr/textColorAlertDialogListItem"
-            android:gravity="center_vertical"
-            android:text="@string/lockscreen_remote_input"
-        />
-
-    <ImageView
-            android:id="@+id/restricted_lock_icon_remote_input"
-            android:layout_width="@*android:dimen/config_restrictedIconSize"
-            android:layout_height="@*android:dimen/config_restrictedIconSize"
-            android:tint="?android:attr/colorAccent"
-            android:src="@*android:drawable/ic_info"
-            android:layout_marginEnd="?android:attr/dialogPreferredPadding"
-            android:layout_gravity="center_vertical"
-            android:scaleType="centerInside" />
-</LinearLayout>
diff --git a/res/layout/restricted_dialog_singlechoice.xml b/res/layout/restricted_dialog_singlechoice.xml
index a9984a8..9b19884 100644
--- a/res/layout/restricted_dialog_singlechoice.xml
+++ b/res/layout/restricted_dialog_singlechoice.xml
@@ -35,14 +35,4 @@
             android:drawableStart="?android:attr/listChoiceIndicatorSingle"
             android:drawablePadding="20dp"
             android:ellipsize="marquee" />
-    <ImageView
-            android:id="@+id/restricted_lock_icon"
-            android:layout_width="@*android:dimen/config_restrictedIconSize"
-            android:layout_height="@*android:dimen/config_restrictedIconSize"
-            android:tint="?android:attr/colorAccent"
-            android:src="@*android:drawable/ic_info"
-            android:layout_marginLeft="@dimen/restricted_icon_padding"
-            android:baselineAlignBottom="true"
-            android:scaleType="centerInside"
-            android:visibility="gone" />
 </com.android.settings.CheckableLinearLayout>
diff --git a/res/layout/restricted_preference_dropdown.xml b/res/layout/restricted_preference_dropdown.xml
deleted file mode 100644
index 8930e24..0000000
--- a/res/layout/restricted_preference_dropdown.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-  ~ Copyright (C) 2016 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
-  -->
-<FrameLayout
-        xmlns:android="http://schemas.android.com/apk/res/android"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content">
-
-    <view android:id="@+id/spinner"
-            class="com.android.settings.notification.RestrictedDropDownPreference$ReselectionSpinner"
-            android:layout_width="0dp"
-            android:layout_height="wrap_content"
-            android:visibility="invisible"
-            android:layout_marginStart="@dimen/preference_no_icon_padding_start"/>
-
-    <include layout="@layout/settingslib_preference" />
-
-</FrameLayout>
\ No newline at end of file
diff --git a/res/layout/restricted_radio_with_summary.xml b/res/layout/restricted_radio_with_summary.xml
deleted file mode 100644
index 5e7fcd8..0000000
--- a/res/layout/restricted_radio_with_summary.xml
+++ /dev/null
@@ -1,63 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-     Copyright (C) 2016 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.android.settings.CheckableLinearLayout
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
-    android:layout_height="wrap_content"
-    android:orientation="vertical"
-    android:background="?android:attr/selectableItemBackground"
-    android:minHeight="?android:attr/listPreferredItemHeightSmall">
-
-    <com.android.settings.CheckableLinearLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:orientation="horizontal"
-        android:paddingStart="20dp"
-        android:paddingEnd="?android:attr/dialogPreferredPadding">
-        <CheckedTextView
-            android:id="@android:id/title"
-            android:layout_width="0dp"
-            android:layout_height="wrap_content"
-            android:layout_weight="1"
-            android:textAppearance="?android:attr/textAppearanceMedium"
-            android:textColor="?android:attr/textColorAlertDialogListItem"
-            android:gravity="center_vertical"
-            android:drawableStart="?android:attr/listChoiceIndicatorSingle"
-            android:ellipsize="marquee" />
-        <ImageView
-            android:id="@+id/restricted_icon"
-            android:layout_width="@*android:dimen/config_restrictedIconSize"
-            android:layout_height="match_parent"
-            android:scaleType="centerInside"
-            android:tint="?android:attr/colorAccent"
-            android:src="@*android:drawable/ic_info"
-            android:layout_marginLeft="@dimen/restricted_icon_padding"
-            android:visibility="gone" />
-    </com.android.settings.CheckableLinearLayout>
-
-
-    <TextView android:id="@android:id/summary"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:paddingBottom="8dp"
-        android:paddingStart="52dp"
-        android:textAppearance="?android:attr/textAppearanceListItemSecondary"
-        android:textColor="?android:attr/textColorSecondary"
-        android:maxLines="10" />
-
-</com.android.settings.CheckableLinearLayout>
diff --git a/res/layout/spinner_dropdown_restricted_item.xml b/res/layout/spinner_dropdown_restricted_item.xml
deleted file mode 100644
index d95e4be..0000000
--- a/res/layout/spinner_dropdown_restricted_item.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2016 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.
--->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:orientation="horizontal"
-        android:gravity="center_vertical">
-    <TextView android:id="@android:id/text1"
-            style="?android:attr/spinnerDropDownItemStyle"
-            android:singleLine="true"
-            android:layout_width="0dp"
-            android:layout_weight="1"
-            android:layout_height="?android:attr/listPreferredItemHeightSmall"
-            android:ellipsize="marquee" />
-    <ImageView android:id="@+id/restricted_icon"
-            android:layout_width="@*android:dimen/config_restrictedIconSize"
-            android:layout_height="@*android:dimen/config_restrictedIconSize"
-            android:tint="?android:attr/colorAccent"
-            android:src="@*android:drawable/ic_info"
-            android:baselineAlignBottom="true"
-            android:layout_marginEnd="@dimen/restricted_icon_padding"
-            android:gravity="end|center_vertical"
-            android:visibility="gone" />
-</LinearLayout>
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/dimens.xml b/res/values/dimens.xml
index be1ba5b..78dbcce 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -441,7 +441,7 @@
     <dimen name="chartview_trapezoid_margin_bottom">2dp</dimen>
 
     <!-- Dimensions for Dream settings cards -->
-    <dimen name="dream_item_min_column_width">210dp</dimen>
+    <dimen name="dream_item_min_column_width">174dp</dimen>
     <dimen name="dream_item_corner_radius">28dp</dimen>
     <dimen name="dream_item_content_padding">8dp</dimen>
     <dimen name="dream_item_icon_size">20dp</dimen>
@@ -449,9 +449,10 @@
     <dimen name="dream_item_title_margin_bottom">8dp</dimen>
     <dimen name="dream_item_title_margin_start">18dp</dimen>
     <dimen name="dream_item_icon_margin_start">10dp</dimen>
-    <dimen name="dream_preference_margin_horizontal">10dp</dimen>
+    <dimen name="dream_preference_card_padding">16dp</dimen>
     <dimen name="dream_preference_margin_bottom">20dp</dimen>
     <dimen name="dream_picker_margin_horizontal">48dp</dimen>
+    <dimen name="dream_preview_placeholder_width">52dp</dimen>
 
     <!-- Sims/Data mobile/Calls/SMS select dialog-->
     <dimen name="sims_select_margin_bottom">24dp</dimen>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 2d0b2d3..6f86803 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -603,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>
@@ -5156,8 +5156,8 @@
     <string name="general_category_title">General</string>
     <!-- Title for the accessibility preference category of display services and settings. [CHAR LIMIT=50] -->
     <string name="display_category_title">Display</string>
-    <!-- Title for the accessibility text options page. [CHAR LIMIT=50] -->
-    <string name="accessibility_text_and_display_title">Text and display</string>
+    <!-- Title for the accessibility color and motion page. [CHAR LIMIT=50] -->
+    <string name="accessibility_color_and_motion_title">Color and motion</string>
     <!-- Title for the accessibility text options page. [CHAR LIMIT=50] -->
     <string name="accessibility_turn_screen_darker_title">Turn screen darker</string>
     <!-- Title for the accessibility preference category of interaction control services and settings. [CHAR LIMIT=50] -->
@@ -7677,8 +7677,8 @@
     <string name="nfc_default_payment_workapp_confirmation_message_title">To make a payment using a work app:</string>
     <!-- Text string in the dialog [CHAR LIMIT=60] -->
     <string name="nfc_default_payment_workapp_confirmation_message_1">work profile must be turned on.</string>
-    <!-- Text string in the dialog [CHAR LIMIT=60] -->
-    <string name="nfc_default_payment_workapp_confirmation_message_2">you\u2019ll need to enter your work profile lock if you have one.</string>
+    <!-- Text string in the dialog [CHAR LIMIT=80] -->
+    <string name="nfc_default_payment_workapp_confirmation_message_2">you\u2019ll need to enter your work PIN, pattern, or password if you have one.</string>
 
     <!-- Caption for button linking to a page explaining how Tap and Pay works-->
     <string name="nfc_payment_how_it_works">How it works</string>
@@ -13907,11 +13907,13 @@
     <!-- TARE dialog button to proceed with a value change [CHAR LIMIT=none] -->
     <string name="tare_dialog_confirm_button_title">Confirm</string>
     <!-- Button to preview the selected screensaver in settings [CHAR LIMIT=40] -->
-    <string name="dream_preview_button_title">Preview screensaver</string>
+    <string name="dream_preview_button_title">Preview screen saver</string>
     <!-- The title of the category to show for the screensaver selector in settings [CHAR LIMIT=none] -->
-    <string name="dream_picker_category">Choose an image</string>
-    <!-- The title of the category to show for the screensaver overlay selector in settings [CHAR LIMIT=none] -->
-    <string name="dream_complications_picker_category">Choose more options</string>
+    <string name="dream_picker_category">Choose a background</string>
+    <!-- The title of the toggle which enables/disables overlays on top of the screen saver [CHAR LIMIT=none] -->
+    <string name="dream_complications_toggle_title">Show additional information</string>
+    <!-- The summary of what overlays this toggle controls [CHAR LIMIT=none] -->
+    <string name="dream_complications_toggle_summary">Display data time, date and weather on the screen saver</string>
     <!-- The title of the category to show for the screensaver miscellaneous settings [CHAR LIMIT=none] -->
     <string name="dream_more_settings_category">More settings</string>
     <!-- The title of the screen saver setup page [CHAR LIMIT=none] -->
diff --git a/res/values/styles.xml b/res/values/styles.xml
index a64eb1f..ebaea6b 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -944,23 +944,10 @@
     </style>
 
     <style name="DreamCardStyle">
-        <item name="android:layout_marginBottom">@dimen/dream_preference_margin_bottom</item>
-        <item name="android:layout_marginStart">@dimen/dream_preference_margin_horizontal</item>
-        <item name="android:layout_marginEnd">@dimen/dream_preference_margin_horizontal</item>
         <item name="cardBackgroundColor">@color/dream_card_color_state_list</item>
         <item name="cardCornerRadius">@dimen/dream_item_corner_radius</item>
         <item name="cardElevation">0dp</item>
         <item name="rippleColor">?android:attr/colorControlHighlight</item>
         <item name="contentPadding">@dimen/dream_item_content_padding</item>
     </style>
-
-    <style name="DreamPickerBackgroundStyle">
-        <item name="android:layout_marginBottom">48dp</item>
-        <item name="android:layout_marginStart">@dimen/dream_picker_margin_horizontal</item>
-        <item name="android:layout_marginEnd">@dimen/dream_picker_margin_horizontal</item>
-        <item name="cardBackgroundColor">?androidprv:attr/colorSurface</item>
-        <item name="cardCornerRadius">24dp</item>
-        <item name="cardElevation">0dp</item>
-        <item name="contentPadding">32dp</item>
-    </style>
 </resources>
diff --git a/res/xml/accessibility_text_and_display.xml b/res/xml/accessibility_color_and_motion.xml
similarity index 62%
rename from res/xml/accessibility_text_and_display.xml
rename to res/xml/accessibility_color_and_motion.xml
index 659acab..f251d1e 100644
--- a/res/xml/accessibility_text_and_display.xml
+++ b/res/xml/accessibility_color_and_motion.xml
@@ -17,34 +17,9 @@
 <PreferenceScreen
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:settings="http://schemas.android.com/apk/res-auto"
-    android:key="accessibility_text_and_display"
+    android:key="accessibility_color_and_motion"
     android:persistent="false"
-    android:title="@string/accessibility_text_and_display_title">
-
-    <Preference
-        android:fragment="com.android.settings.display.ToggleFontSizePreferenceFragment"
-        android:icon="@drawable/ic_font_size"
-        android:key="font_size_preference_screen"
-        android:persistent="false"
-        android:title="@string/title_font_size"
-        settings:controller="com.android.settings.display.FontSizePreferenceController"
-        settings:searchable="false"/>
-
-    <com.android.settings.display.ScreenZoomPreference
-        android:fragment="com.android.settings.display.ScreenZoomSettings"
-        android:icon="@drawable/ic_screen_zoom"
-        android:key="accessibility_settings_screen_zoom"
-        android:persistent="false"
-        android:title="@string/screen_zoom_title"
-        settings:searchable="false"/>
-
-    <SwitchPreference
-        android:key="toggle_force_bold_text"
-        android:icon="@drawable/ic_force_bold"
-        android:persistent="false"
-        android:title="@string/force_bold_text"
-        settings:keywords="@string/keywords_bold_text"
-        settings:controller="com.android.settings.accessibility.FontWeightAdjustmentPreferenceController"/>
+    android:title="@string/accessibility_color_and_motion_title">
 
     <Preference
         android:fragment="com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment"
@@ -76,12 +51,6 @@
         android:title="@string/accessibility_toggle_large_pointer_icon_title"
         settings:controller="com.android.settings.accessibility.LargePointerIconPreferenceController"/>
 
-    <SwitchPreference
-        android:key="toggle_high_text_contrast_preference"
-        android:persistent="false"
-        android:title="@string/accessibility_toggle_high_text_contrast_preference_title"
-        settings:controller="com.android.settings.accessibility.HighTextContrastPreferenceController"/>
-
     <PreferenceCategory
         android:key="experimental_category"
         android:persistent="false"
diff --git a/res/xml/accessibility_settings.xml b/res/xml/accessibility_settings.xml
index fcdf47b..22226a1 100644
--- a/res/xml/accessibility_settings.xml
+++ b/res/xml/accessibility_settings.xml
@@ -36,21 +36,19 @@
         android:persistent="false"
         android:title="@string/display_category_title">
 
-        <!-- After completely finishing the Text and reading options feature, it will be visible. -->
         <Preference
             android:fragment="com.android.settings.accessibility.TextReadingPreferenceFragment"
             android:icon="@drawable/ic_adaptive_font_download"
             android:key="text_reading_options"
             android:persistent="false"
-            android:title="@string/accessibility_text_reading_options_title"
-            settings:isPreferenceVisible="false"/>
+            android:title="@string/accessibility_text_reading_options_title" />
 
         <Preference
-            android:fragment="com.android.settings.accessibility.TextAndDisplayFragment"
-            android:key="text_and_display_preference_screen"
-            android:icon="@drawable/ic_text_and_display"
+            android:fragment="com.android.settings.accessibility.ColorAndMotionFragment"
+            android:key="color_and_motion"
+            android:icon="@drawable/ic_color_and_motion"
             android:persistent="false"
-            android:title="@string/accessibility_text_and_display_title"
+            android:title="@string/accessibility_color_and_motion_title"
             settings:searchable="true"/>
 
         <com.android.settingslib.PrimarySwitchPreference
diff --git a/res/xml/accessibility_settings_for_setup_wizard.xml b/res/xml/accessibility_settings_for_setup_wizard.xml
index 3272ae5..78d8f72 100644
--- a/res/xml/accessibility_settings_for_setup_wizard.xml
+++ b/res/xml/accessibility_settings_for_setup_wizard.xml
@@ -26,24 +26,9 @@
         android:key="text_reading_options"
         android:persistent="false"
         android:title="@string/accessibility_text_reading_options_title"
-        settings:isPreferenceVisible="false"
         settings:keywords="text_reading_options" />
 
     <Preference
-        android:key="font_size_preference"
-        android:icon="@drawable/ic_font_size"
-        android:summary="@string/short_summary_font_size"
-        android:title="@string/title_font_size"
-        settings:controller="com.android.settings.accessibility.FontSizePreferenceController" />
-
-    <com.android.settings.display.ScreenZoomPreference
-        android:key="force_density_preference"
-        android:icon="@drawable/ic_screen_zoom"
-        android:summary="@string/screen_zoom_short_summary"
-        android:title="@string/screen_zoom_title"
-        settings:controller="com.android.settings.accessibility.ScreenSizePreferenceController" />
-
-    <Preference
         android:fragment="com.android.settings.accessibility.ToggleScreenMagnificationPreferenceFragmentForSetupWizard"
         android:key="screen_magnification_preference"
         android:icon="@drawable/ic_accessibility_magnification"
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/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/dream_fragment_overview.xml b/res/xml/dream_fragment_overview.xml
index 9dfa105..105cec4 100644
--- a/res/xml/dream_fragment_overview.xml
+++ b/res/xml/dream_fragment_overview.xml
@@ -29,18 +29,12 @@
     </PreferenceCategory>
 
     <PreferenceCategory
-        android:key="dream_complication_category"
-        android:title="@string/dream_complications_picker_category"
-        settings:controller="com.android.settings.dream.DreamComplicationCategoryController">
-        <com.android.settingslib.widget.LayoutPreference
-            android:key="dream_complication_picker"
-            android:selectable="false"
-            android:layout="@layout/dream_picker_layout"
-            settings:controller="com.android.settings.dream.DreamComplicationPickerController"/>
-    </PreferenceCategory>
-
-    <PreferenceCategory
         android:title="@string/dream_more_settings_category">
+        <SwitchPreference
+            android:key="dream_complications_toggle"
+            android:title="@string/dream_complications_toggle_title"
+            android:summary="@string/dream_complications_toggle_summary"
+            settings:controller="com.android.settings.dream.DreamComplicationPreferenceController"/>
         <Preference
             android:key="when_to_start"
             android:title="@string/screensaver_settings_when_to_dream"
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/RestrictedListPreference.java b/src/com/android/settings/RestrictedListPreference.java
index bd3cd17..d75f1b8 100644
--- a/src/com/android/settings/RestrictedListPreference.java
+++ b/src/com/android/settings/RestrictedListPreference.java
@@ -30,7 +30,6 @@
 import android.widget.AdapterView;
 import android.widget.ArrayAdapter;
 import android.widget.CheckedTextView;
-import android.widget.ImageView;
 import android.widget.ListAdapter;
 import android.widget.ListView;
 
@@ -53,7 +52,6 @@
 
     public RestrictedListPreference(Context context, AttributeSet attrs) {
         super(context, attrs);
-        setWidgetLayoutResource(R.layout.restricted_icon);
         mHelper = new RestrictedPreferenceHelper(context, this, attrs);
     }
 
@@ -67,10 +65,6 @@
     public void onBindViewHolder(PreferenceViewHolder holder) {
         super.onBindViewHolder(holder);
         mHelper.onBindViewHolder(holder);
-        final View restrictedIcon = holder.findViewById(R.id.restricted_icon);
-        if (restrictedIcon != null) {
-            restrictedIcon.setVisibility(isDisabledByAdmin() ? View.VISIBLE : View.GONE);
-        }
     }
 
     @Override
@@ -187,11 +181,9 @@
             View root = super.getView(position, convertView, parent);
             CharSequence entry = getItem(position);
             CheckedTextView text = (CheckedTextView) root.findViewById(R.id.text1);
-            ImageView padlock = (ImageView) root.findViewById(R.id.restricted_lock_icon);
             if (isRestrictedForEntry(entry)) {
                 text.setEnabled(false);
                 text.setChecked(false);
-                padlock.setVisibility(View.VISIBLE);
             } else {
                 if (mSelectedIndex != -1) {
                     text.setChecked(position == mSelectedIndex);
@@ -199,7 +191,6 @@
                 if (!text.isEnabled()) {
                     text.setEnabled(true);
                 }
-                padlock.setVisibility(View.GONE);
             }
             return root;
         }
diff --git a/src/com/android/settings/accessibility/TextAndDisplayFragment.java b/src/com/android/settings/accessibility/ColorAndMotionFragment.java
similarity index 91%
rename from src/com/android/settings/accessibility/TextAndDisplayFragment.java
rename to src/com/android/settings/accessibility/ColorAndMotionFragment.java
index e81dded..7f55053 100644
--- a/src/com/android/settings/accessibility/TextAndDisplayFragment.java
+++ b/src/com/android/settings/accessibility/ColorAndMotionFragment.java
@@ -30,11 +30,11 @@
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settingslib.search.SearchIndexable;
 
-/** Accessibility settings for text and display. */
+/** Accessibility settings for color and motion. */
 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
-public class TextAndDisplayFragment extends DashboardFragment {
+public class ColorAndMotionFragment extends DashboardFragment {
 
-    private static final String TAG = "TextAndDisplayFragment";
+    private static final String TAG = "ColorAndMotionFragment";
 
     private static final String CATEGORY_EXPERIMENTAL = "experimental_category";
 
@@ -49,7 +49,7 @@
 
     @Override
     public int getMetricsCategory() {
-        return SettingsEnums.ACCESSIBILITY_TEXT_AND_DISPLAY;
+        return SettingsEnums.ACCESSIBILITY_COLOR_AND_MOTION;
     }
 
 
@@ -62,7 +62,7 @@
 
     @Override
     protected int getPreferenceScreenResId() {
-        return R.xml.accessibility_text_and_display;
+        return R.xml.accessibility_color_and_motion;
     }
 
     @Override
@@ -104,5 +104,5 @@
     }
 
     public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
-            new BaseSearchIndexProvider(R.xml.accessibility_text_and_display);
+            new BaseSearchIndexProvider(R.xml.accessibility_color_and_motion);
 }
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/bluetooth/BluetoothDetailsMacAddressController.java b/src/com/android/settings/bluetooth/BluetoothDetailsMacAddressController.java
index ec3e11f..d80512e 100644
--- a/src/com/android/settings/bluetooth/BluetoothDetailsMacAddressController.java
+++ b/src/com/android/settings/bluetooth/BluetoothDetailsMacAddressController.java
@@ -46,21 +46,22 @@
     protected void init(PreferenceScreen screen) {
         mFooterPreference = screen.findPreference(KEY_DEVICE_DETAILS_FOOTER);
         mFooterPreference.setTitle(mContext.getString(
-                R.string.bluetooth_device_mac_address, mCachedDevice.getAddress()));
+                R.string.bluetooth_device_mac_address, mCachedDevice.getIdentityAddress()));
     }
 
     @Override
     protected void refresh() {
         if (mCachedDevice.getGroupId() != BluetoothCsipSetCoordinator.GROUP_ID_INVALID) {
             StringBuilder title = new StringBuilder(mContext.getString(
-                R.string.bluetooth_multuple_devices_mac_address, mCachedDevice.getAddress()));
+                    R.string.bluetooth_multuple_devices_mac_address,
+                            mCachedDevice.getIdentityAddress()));
             for (CachedBluetoothDevice member: mCachedDevice.getMemberDevice()) {
-                title.append("\n").append(member.getAddress());
+                title.append("\n").append(member.getIdentityAddress());
             }
             mFooterPreference.setTitle(title);
         } else {
             mFooterPreference.setTitle(mContext.getString(
-                R.string.bluetooth_device_mac_address, mCachedDevice.getAddress()));
+                    R.string.bluetooth_device_mac_address, mCachedDevice.getIdentityAddress()));
         }
     }
 
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/datausage/UnrestrictedDataAccessPreference.java b/src/com/android/settings/datausage/UnrestrictedDataAccessPreference.java
index ceba8be..08e523c 100644
--- a/src/com/android/settings/datausage/UnrestrictedDataAccessPreference.java
+++ b/src/com/android/settings/datausage/UnrestrictedDataAccessPreference.java
@@ -48,7 +48,6 @@
             ApplicationsState applicationsState, DataSaverBackend dataSaverBackend,
             DashboardFragment parentFragment) {
         super(context);
-        setWidgetLayoutResource(R.layout.restricted_switch_widget);
         mHelper = new RestrictedPreferenceHelper(context, this, null);
         mEntry = entry;
         mDataUsageState = (AppStateDataUsageBridge.DataUsageState) mEntry.extraInfo;
@@ -131,10 +130,6 @@
         super.onBindViewHolder(holder);
 
         mHelper.onBindViewHolder(holder);
-        holder.findViewById(R.id.restricted_icon).setVisibility(
-                disabledByAdmin ? View.VISIBLE : View.GONE);
-        holder.findViewById(android.R.id.switch_widget).setVisibility(
-                disabledByAdmin ? View.GONE : View.VISIBLE);
     }
 
     @Override
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..4e16ccb 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;
 
@@ -48,6 +48,7 @@
         private final ImageView mIconView;
         private final TextView mTitleView;
         private final ImageView mPreviewView;
+        private final ImageView mPreviewPlaceholderView;
         private final Button mCustomizeButton;
         private final Context mContext;
 
@@ -55,6 +56,7 @@
             super(view);
             mContext = context;
             mPreviewView = view.findViewById(R.id.preview);
+            mPreviewPlaceholderView = view.findViewById(R.id.preview_placeholder);
             mIconView = view.findViewById(R.id.icon);
             mTitleView = view.findViewById(R.id.title_text);
             mCustomizeButton = view.findViewById(R.id.customize_button);
@@ -68,10 +70,9 @@
 
             final Drawable previewImage = item.getPreviewImage();
             if (previewImage != null) {
-                mPreviewView.setVisibility(View.VISIBLE);
                 mPreviewView.setImageDrawable(previewImage);
-            } else {
-                mPreviewView.setVisibility(View.GONE);
+                mPreviewView.setClipToOutline(true);
+                mPreviewPlaceholderView.setVisibility(View.GONE);
             }
 
             final Drawable icon = item.isActive()
@@ -103,7 +104,7 @@
         }
     }
 
-    DreamAdapter(List<IDreamItem> itemList) {
+    public DreamAdapter(List<IDreamItem> itemList) {
         mItemList = itemList;
     }
 
diff --git a/src/com/android/settings/dream/DreamComplicationPickerController.java b/src/com/android/settings/dream/DreamComplicationPickerController.java
deleted file mode 100644
index 09ed8da..0000000
--- a/src/com/android/settings/dream/DreamComplicationPickerController.java
+++ /dev/null
@@ -1,113 +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.content.Context;
-import android.graphics.drawable.Drawable;
-
-import androidx.preference.PreferenceScreen;
-import androidx.recyclerview.widget.RecyclerView;
-
-import com.android.settings.R;
-import com.android.settings.core.BasePreferenceController;
-import com.android.settingslib.dream.DreamBackend;
-import com.android.settingslib.widget.LayoutPreference;
-
-import java.util.Set;
-import java.util.stream.Collectors;
-
-/**
- * Controller for the component allowing a user to select overlays to show on top of dreams.
- */
-public class DreamComplicationPickerController extends BasePreferenceController {
-    private static final String KEY = "dream_complication_picker";
-
-    private final DreamBackend mBackend;
-    private final Set<Integer> mSupportedComplications;
-
-    private class ComplicationItem implements IDreamItem {
-        private final int mComplicationType;
-        private boolean mEnabled;
-
-        ComplicationItem(@DreamBackend.ComplicationType int complicationType) {
-            mComplicationType = complicationType;
-            mEnabled = mBackend.isComplicationEnabled(mComplicationType);
-        }
-
-        @Override
-        public CharSequence getTitle() {
-            return mBackend.getComplicationTitle(mComplicationType);
-        }
-
-        @Override
-        public Drawable getIcon() {
-            // TODO(b/215703483): add icon for each complication
-            return null;
-        }
-
-        @Override
-        public void onItemClicked() {
-            mEnabled = !mEnabled;
-            mBackend.setComplicationEnabled(mComplicationType, mEnabled);
-        }
-
-        @Override
-        public Drawable getPreviewImage() {
-            // TODO(b/215703483): add preview image for each complication
-            return null;
-        }
-
-        @Override
-        public boolean isActive() {
-            return mEnabled;
-        }
-    }
-
-    public DreamComplicationPickerController(Context context) {
-        super(context, KEY);
-        mBackend = DreamBackend.getInstance(context);
-        mSupportedComplications = mBackend.getSupportedComplications();
-    }
-
-    @Override
-    public String getPreferenceKey() {
-        return KEY;
-    }
-
-    @Override
-    public int getAvailabilityStatus() {
-        return mSupportedComplications.size() > 0 ? AVAILABLE
-                : CONDITIONALLY_UNAVAILABLE;
-    }
-
-    @Override
-    public void displayPreference(PreferenceScreen screen) {
-        super.displayPreference(screen);
-
-        DreamAdapter adapter = new DreamAdapter(mSupportedComplications.stream()
-                .map(ComplicationItem::new)
-                .collect(Collectors.toList()));
-
-        LayoutPreference pref = screen.findPreference(getPreferenceKey());
-        if (pref != null) {
-            final RecyclerView recyclerView = pref.findViewById(R.id.dream_list);
-            recyclerView.setLayoutManager(new AutoFitGridLayoutManager(mContext));
-            recyclerView.setHasFixedSize(true);
-            recyclerView.setAdapter(adapter);
-        }
-    }
-}
diff --git a/src/com/android/settings/dream/DreamComplicationPreferenceController.java b/src/com/android/settings/dream/DreamComplicationPreferenceController.java
new file mode 100644
index 0000000..d9c4fb3
--- /dev/null
+++ b/src/com/android/settings/dream/DreamComplicationPreferenceController.java
@@ -0,0 +1,60 @@
+/*
+ * 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.content.Context;
+
+import com.android.settings.R;
+import com.android.settings.core.TogglePreferenceController;
+import com.android.settingslib.dream.DreamBackend;
+
+/**
+ * Controller for the {@link androidx.preference.SwitchPreference} which controls if dream
+ * overlays should be enabled.
+ */
+public class DreamComplicationPreferenceController extends TogglePreferenceController {
+    private final DreamBackend mBackend;
+
+    public DreamComplicationPreferenceController(Context context, String key) {
+        super(context, key);
+        mBackend = DreamBackend.getInstance(context);
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        return mBackend.getSupportedComplications().isEmpty() ? CONDITIONALLY_UNAVAILABLE
+                : AVAILABLE;
+    }
+
+    @Override
+    public boolean isChecked() {
+        return mBackend.getEnabledComplications().containsAll(mBackend.getSupportedComplications());
+    }
+
+    @Override
+    public boolean setChecked(boolean isChecked) {
+        for (int complication : mBackend.getSupportedComplications()) {
+            mBackend.setComplicationEnabled(complication, isChecked);
+        }
+        return true;
+    }
+
+    @Override
+    public int getSliceHighlightMenuRes() {
+        return R.string.menu_key_display;
+    }
+}
diff --git a/src/com/android/settings/dream/DreamPickerController.java b/src/com/android/settings/dream/DreamPickerController.java
index 6d5463c..b7ba614 100644
--- a/src/com/android/settings/dream/DreamPickerController.java
+++ b/src/com/android/settings/dream/DreamPickerController.java
@@ -21,7 +21,7 @@
 import android.graphics.drawable.Drawable;
 
 import androidx.annotation.Nullable;
-import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
 import androidx.recyclerview.widget.RecyclerView;
 
 import com.android.settings.R;
@@ -71,16 +71,21 @@
     }
 
     @Override
-    public void updateState(Preference preference) {
-        super.updateState(preference);
+    public void displayPreference(PreferenceScreen screen) {
+        super.displayPreference(screen);
 
         mAdapter = new DreamAdapter(mDreamInfos.stream()
                 .map(DreamItem::new)
                 .collect(Collectors.toList()));
 
-        final RecyclerView recyclerView =
-                ((LayoutPreference) preference).findViewById(R.id.dream_list);
+        final LayoutPreference pref = screen.findPreference(getPreferenceKey());
+        if (pref == null) {
+            return;
+        }
+        final RecyclerView recyclerView = pref.findViewById(R.id.dream_list);
         recyclerView.setLayoutManager(new AutoFitGridLayoutManager(mContext));
+        recyclerView.addItemDecoration(
+                new GridSpacingItemDecoration(mContext, R.dimen.dream_preference_card_padding));
         recyclerView.setHasFixedSize(true);
         recyclerView.setAdapter(mAdapter);
     }
diff --git a/src/com/android/settings/dream/DreamSettings.java b/src/com/android/settings/dream/DreamSettings.java
index 2acce07..bfa19a9 100644
--- a/src/com/android/settings/dream/DreamSettings.java
+++ b/src/com/android/settings/dream/DreamSettings.java
@@ -34,14 +34,12 @@
 import com.android.settings.R;
 import com.android.settings.dashboard.DashboardFragment;
 import com.android.settings.search.BaseSearchIndexProvider;
-import com.android.settings.widget.PreferenceCategoryController;
 import com.android.settingslib.core.AbstractPreferenceController;
 import com.android.settingslib.dream.DreamBackend;
 import com.android.settingslib.dream.DreamBackend.WhenToDream;
 import com.android.settingslib.search.SearchIndexable;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 
 @SearchIndexable
@@ -52,7 +50,6 @@
     static final String WHILE_DOCKED_ONLY = "while_docked_only";
     static final String EITHER_CHARGING_OR_DOCKED = "either_charging_or_docked";
     static final String NEVER_DREAM = "never";
-    private static final String COMPLICATIONS_CATEGORY_KEY = "dream_complication_category";
 
     @WhenToDream
     static int getSettingFromPrefKey(String key) {
@@ -138,14 +135,8 @@
 
     private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
         final List<AbstractPreferenceController> controllers = new ArrayList<>();
-        final DreamComplicationPickerController complicationPickerController =
-                new DreamComplicationPickerController(context);
-
-        controllers.add(complicationPickerController);
-        controllers.add(new WhenToDreamPreferenceController(context));
         controllers.add(new DreamPickerController(context));
-        controllers.add(new PreferenceCategoryController(context, COMPLICATIONS_CATEGORY_KEY)
-                .setChildren(Collections.singletonList(complicationPickerController)));
+        controllers.add(new WhenToDreamPreferenceController(context));
         return controllers;
     }
 
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/GridSpacingItemDecoration.java b/src/com/android/settings/dream/GridSpacingItemDecoration.java
new file mode 100644
index 0000000..6e6a551
--- /dev/null
+++ b/src/com/android/settings/dream/GridSpacingItemDecoration.java
@@ -0,0 +1,63 @@
+/*
+ * 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.content.Context;
+import android.graphics.Rect;
+import android.view.View;
+
+import androidx.annotation.DimenRes;
+import androidx.recyclerview.widget.GridLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+/**
+ * RecyclerView item decorator to be used with {@link GridLayoutManager} for applying padding to
+ * only the inner elements of the grid.
+ */
+public class GridSpacingItemDecoration extends RecyclerView.ItemDecoration {
+    private final int mSpacing;
+    private final boolean mRtl;
+
+    public GridSpacingItemDecoration(Context context, @DimenRes int spacingId) {
+        mSpacing = context.getResources().getDimensionPixelSize(spacingId);
+        mRtl = context.getResources().getConfiguration().getLayoutDirection()
+                == View.LAYOUT_DIRECTION_RTL;
+    }
+
+    @Override
+    public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
+            RecyclerView.State state) {
+        final RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
+
+        if (!(layoutManager instanceof GridLayoutManager)) {
+            return;
+        }
+
+        final int spanCount = ((GridLayoutManager) layoutManager).getSpanCount();
+        final int position = parent.getChildAdapterPosition(view);
+        final int column = position % spanCount;
+
+        final int startPadding = column * mSpacing / spanCount;
+        final int endPadding = mSpacing - (column + 1) * mSpacing / spanCount;
+
+        outRect.left = mRtl ? endPadding : startPadding;
+        outRect.right = mRtl ? startPadding : endPadding;
+        if (position >= spanCount) {
+            outRect.top = mSpacing;
+        }
+    }
+}
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/network/PrivateDnsModeDialogPreference.java b/src/com/android/settings/network/PrivateDnsModeDialogPreference.java
index 442af38..5c7c54e 100644
--- a/src/com/android/settings/network/PrivateDnsModeDialogPreference.java
+++ b/src/com/android/settings/network/PrivateDnsModeDialogPreference.java
@@ -97,23 +97,19 @@
 
     public PrivateDnsModeDialogPreference(Context context) {
         super(context);
-        initialize();
     }
 
     public PrivateDnsModeDialogPreference(Context context, AttributeSet attrs) {
         super(context, attrs);
-        initialize();
     }
 
     public PrivateDnsModeDialogPreference(Context context, AttributeSet attrs, int defStyleAttr) {
         super(context, attrs, defStyleAttr);
-        initialize();
     }
 
     public PrivateDnsModeDialogPreference(Context context, AttributeSet attrs, int defStyleAttr,
             int defStyleRes) {
         super(context, attrs, defStyleAttr, defStyleRes);
-        initialize();
     }
 
     private final AnnotationSpan.LinkInfo mUrlLinkInfo = new AnnotationSpan.LinkInfo(
@@ -131,12 +127,6 @@
         }
     });
 
-    private void initialize() {
-        // Add the "Restricted" icon resource so that if the preference is disabled by the
-        // admin, an information button will be shown.
-        setWidgetLayoutResource(R.layout.restricted_icon);
-    }
-
     @Override
     public void onBindViewHolder(PreferenceViewHolder holder) {
         super.onBindViewHolder(holder);
@@ -146,13 +136,6 @@
             // by the controller.
             holder.itemView.setEnabled(true);
         }
-
-        final View restrictedIcon = holder.findViewById(R.id.restricted_icon);
-        if (restrictedIcon != null) {
-            // Show the "Restricted" icon if, and only if, the preference was disabled by
-            // the admin.
-            restrictedIcon.setVisibility(isDisabledByAdmin() ? View.VISIBLE : View.GONE);
-        }
     }
 
     @Override
diff --git a/src/com/android/settings/nfc/PaymentBackend.java b/src/com/android/settings/nfc/PaymentBackend.java
index 0cfed20..021d673 100644
--- a/src/com/android/settings/nfc/PaymentBackend.java
+++ b/src/com/android/settings/nfc/PaymentBackend.java
@@ -133,7 +133,9 @@
                     appInfo.settingsComponent = null;
                 }
                 appInfo.description = service.getDescription();
-                appInfo.icon = pm.getUserBadgedIcon(service.loadIcon(pm), appInfo.userHandle);
+                Drawable icon = (service.loadBanner(pm) != null)
+                        ? service.loadBanner(pm) : service.loadIcon(pm);
+                appInfo.icon = pm.getUserBadgedIcon(icon, appInfo.userHandle);
 
                 appInfos.add(appInfo);
             }
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/src/com/android/settings/notification/NotificationLockscreenPreference.java b/src/com/android/settings/notification/NotificationLockscreenPreference.java
deleted file mode 100644
index b236014..0000000
--- a/src/com/android/settings/notification/NotificationLockscreenPreference.java
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- * Copyright (C) 2016 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.notification;
-
-import android.app.Dialog;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.os.Bundle;
-import android.os.UserHandle;
-import android.os.UserManager;
-import android.provider.Settings;
-import android.util.AttributeSet;
-import android.view.View;
-import android.widget.CheckBox;
-import android.widget.CompoundButton;
-import android.widget.ListView;
-
-import androidx.appcompat.app.AlertDialog;
-import androidx.appcompat.app.AlertDialog.Builder;
-
-import com.android.settings.R;
-import com.android.settings.RestrictedListPreference;
-import com.android.settings.Utils;
-import com.android.settingslib.RestrictedLockUtils;
-
-public class NotificationLockscreenPreference extends RestrictedListPreference {
-
-    private boolean mAllowRemoteInput;
-    private Listener mListener;
-    private boolean mShowRemoteInput;
-    private boolean mRemoteInputCheckBoxEnabled = true;
-    private int mUserId = UserHandle.myUserId();
-    private RestrictedLockUtils.EnforcedAdmin mAdminRestrictingRemoteInput;
-
-    public NotificationLockscreenPreference(Context context, AttributeSet attrs) {
-        super(context, attrs);
-    }
-
-    public void setRemoteInputCheckBoxEnabled(boolean enabled) {
-        mRemoteInputCheckBoxEnabled = enabled;
-    }
-
-    public void setRemoteInputRestricted(RestrictedLockUtils.EnforcedAdmin admin) {
-        mAdminRestrictingRemoteInput = admin;
-    }
-
-    @Override
-    protected void onClick() {
-        final Context context = getContext();
-        if (!Utils.startQuietModeDialogIfNecessary(context, UserManager.get(context), mUserId)) {
-            // Call super to create preference dialog only when work mode is on
-            // startQuietModeDialogIfNecessary will return false if mUserId is not a managed user
-            super.onClick();
-        }
-    }
-
-    public void setUserId(int userId) {
-        mUserId = userId;
-    }
-
-    @Override
-    protected void onPrepareDialogBuilder(Builder builder,
-            DialogInterface.OnClickListener innerListener) {
-
-        mListener = new Listener(innerListener);
-        builder.setSingleChoiceItems(createListAdapter(builder.getContext()), getSelectedValuePos(),
-                mListener);
-        mShowRemoteInput = getEntryValues().length == 3;
-        mAllowRemoteInput = Settings.Secure.getInt(getContext().getContentResolver(),
-                Settings.Secure.LOCK_SCREEN_ALLOW_REMOTE_INPUT, 0) != 0;
-        builder.setView(R.layout.lockscreen_remote_input);
-    }
-
-    @Override
-    protected void onDialogCreated(Dialog dialog) {
-        super.onDialogCreated(dialog);
-        dialog.create();
-        CheckBox checkbox = (CheckBox) dialog.findViewById(R.id.lockscreen_remote_input);
-        checkbox.setChecked(!mAllowRemoteInput);
-        checkbox.setOnCheckedChangeListener(mListener);
-        checkbox.setEnabled(mAdminRestrictingRemoteInput == null);
-
-        View restricted = dialog.findViewById(R.id.restricted_lock_icon_remote_input);
-        restricted.setVisibility(mAdminRestrictingRemoteInput == null ? View.GONE : View.VISIBLE);
-
-        if (mAdminRestrictingRemoteInput != null) {
-            checkbox.setClickable(false);
-            dialog.findViewById(com.android.internal.R.id.customPanel)
-                    .setOnClickListener(mListener);
-        }
-    }
-
-    @Override
-    protected void onDialogStateRestored(Dialog dialog, Bundle savedInstanceState) {
-        super.onDialogStateRestored(dialog, savedInstanceState);
-        ListView listView = ((AlertDialog) dialog).getListView();
-        int selectedPosition = listView.getCheckedItemPosition();
-
-        View panel = dialog.findViewById(com.android.internal.R.id.customPanel);
-        panel.setVisibility(checkboxVisibilityForSelectedIndex(selectedPosition,
-                mShowRemoteInput));
-        mListener.setView(panel);
-    }
-
-    @Override
-    protected void onDialogClosed(boolean positiveResult) {
-        super.onDialogClosed(positiveResult);
-        Settings.Secure.putInt(getContext().getContentResolver(),
-                Settings.Secure.LOCK_SCREEN_ALLOW_REMOTE_INPUT, mAllowRemoteInput ? 1 : 0);
-    }
-
-    @Override
-    protected boolean isAutoClosePreference() {
-        return false;
-    }
-
-    private int checkboxVisibilityForSelectedIndex(int selected,
-            boolean showRemoteAtAll) {
-        return selected == 1 && showRemoteAtAll && mRemoteInputCheckBoxEnabled ? View.VISIBLE
-                : View.GONE;
-    }
-
-    private class Listener implements DialogInterface.OnClickListener,
-            CompoundButton.OnCheckedChangeListener, View.OnClickListener {
-
-        private final DialogInterface.OnClickListener mInner;
-        private View mView;
-
-        public Listener(DialogInterface.OnClickListener inner) {
-            mInner = inner;
-        }
-
-        @Override
-        public void onClick(DialogInterface dialog, int which) {
-            mInner.onClick(dialog, which);
-            ListView listView = ((AlertDialog) dialog).getListView();
-            int selectedPosition = listView.getCheckedItemPosition();
-            if (mView != null) {
-                mView.setVisibility(
-                        checkboxVisibilityForSelectedIndex(selectedPosition, mShowRemoteInput));
-            }
-        }
-
-        @Override
-        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
-            mAllowRemoteInput = !isChecked;
-        }
-
-        public void setView(View view) {
-            mView = view;
-        }
-
-        @Override
-        public void onClick(View v) {
-            if (v.getId() == com.android.internal.R.id.customPanel) {
-                RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getContext(),
-                        mAdminRestrictingRemoteInput);
-            }
-        }
-    }
-}
diff --git a/src/com/android/settings/safetycenter/SafetySourceBroadcastReceiver.java b/src/com/android/settings/safetycenter/SafetySourceBroadcastReceiver.java
index 55e8bba..0fd0c0d 100644
--- a/src/com/android/settings/safetycenter/SafetySourceBroadcastReceiver.java
+++ b/src/com/android/settings/safetycenter/SafetySourceBroadcastReceiver.java
@@ -33,15 +33,17 @@
             return;
         }
 
-        ImmutableList<String> sourceIds =
-                ImmutableList.copyOf(intent.getStringArrayExtra(EXTRA_REFRESH_SAFETY_SOURCE_IDS));
+        String[] sourceIdsExtra = intent.getStringArrayExtra(EXTRA_REFRESH_SAFETY_SOURCE_IDS);
+        if (sourceIdsExtra != null && sourceIdsExtra.length > 0) {
+            ImmutableList<String> sourceIds = ImmutableList.copyOf(sourceIdsExtra);
 
-        if (sourceIds.contains(LockScreenSafetySource.SAFETY_SOURCE_ID)) {
-            LockScreenSafetySource.sendSafetyData(context);
-        }
+            if (sourceIds.contains(LockScreenSafetySource.SAFETY_SOURCE_ID)) {
+                LockScreenSafetySource.sendSafetyData(context);
+            }
 
-        if (sourceIds.contains(BiometricsSafetySource.SAFETY_SOURCE_ID)) {
-            BiometricsSafetySource.sendSafetyData(context);
+            if (sourceIds.contains(BiometricsSafetySource.SAFETY_SOURCE_ID)) {
+                BiometricsSafetySource.sendSafetyData(context);
+            }
         }
     }
 }
diff --git a/src/com/android/settings/widget/RestrictedAppPreference.java b/src/com/android/settings/widget/RestrictedAppPreference.java
index cd95357..f93b935 100644
--- a/src/com/android/settings/widget/RestrictedAppPreference.java
+++ b/src/com/android/settings/widget/RestrictedAppPreference.java
@@ -20,12 +20,10 @@
 import android.os.UserHandle;
 import android.text.TextUtils;
 import android.util.AttributeSet;
-import android.view.View;
 
 import androidx.preference.PreferenceManager;
 import androidx.preference.PreferenceViewHolder;
 
-import com.android.settings.R;
 import com.android.settingslib.RestrictedLockUtils;
 import com.android.settingslib.RestrictedPreferenceHelper;
 import com.android.settingslib.widget.AppPreference;
@@ -55,7 +53,6 @@
     }
 
     private void initialize(AttributeSet attrs, String userRestriction) {
-        setWidgetLayoutResource(R.layout.restricted_icon);
         mHelper = new RestrictedPreferenceHelper(getContext(), this, attrs);
         this.userRestriction = userRestriction;
     }
@@ -64,10 +61,6 @@
     public void onBindViewHolder(PreferenceViewHolder holder) {
         super.onBindViewHolder(holder);
         mHelper.onBindViewHolder(holder);
-        final View restrictedIcon = holder.findViewById(R.id.restricted_icon);
-        if (restrictedIcon != null) {
-            restrictedIcon.setVisibility(isDisabledByAdmin() ? View.VISIBLE : View.GONE);
-        }
     }
 
     @Override
diff --git a/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java b/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
index dd0c20a..6f26826 100644
--- a/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
+++ b/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
@@ -100,7 +100,6 @@
     @Override
     public void onCreate(Bundle icicle) {
         super.onCreate(icicle);
-        setIfOnlyAvailableForAdmins(true);
         mIsUiRestricted = isUiRestricted();
     }
 
diff --git a/tests/robotests/src/com/android/settings/accessibility/TextAndDisplayFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/ColorAndMotionFragmentTest.java
similarity index 89%
rename from tests/robotests/src/com/android/settings/accessibility/TextAndDisplayFragmentTest.java
rename to tests/robotests/src/com/android/settings/accessibility/ColorAndMotionFragmentTest.java
index 96756ecd..0bb227e 100644
--- a/tests/robotests/src/com/android/settings/accessibility/TextAndDisplayFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/ColorAndMotionFragmentTest.java
@@ -32,17 +32,17 @@
 import java.util.List;
 
 @RunWith(RobolectricTestRunner.class)
-public class TextAndDisplayFragmentTest {
+public class ColorAndMotionFragmentTest {
 
     private Context mContext = ApplicationProvider.getApplicationContext();
 
     @Test
     public void getNonIndexableKeys_existInXmlLayout() {
-        final List<String> niks = TextAndDisplayFragment.SEARCH_INDEX_DATA_PROVIDER
+        final List<String> niks = ColorAndMotionFragment.SEARCH_INDEX_DATA_PROVIDER
                 .getNonIndexableKeys(mContext);
         final List<String> keys =
                 XmlTestUtils.getKeysFromPreferenceXml(mContext,
-                        R.xml.accessibility_text_and_display);
+                        R.xml.accessibility_color_and_motion);
 
         assertThat(keys).containsAtLeastElementsIn(niks);
     }
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/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java
index 31687c6..6087ef2 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java
@@ -99,6 +99,7 @@
         mController.mBluetoothAdapter = mBluetoothAdapter;
         when(mCachedDevice.getDevice()).thenReturn(mBluetoothDevice);
         when(mCachedDevice.getAddress()).thenReturn(MAC_ADDRESS);
+        when(mCachedDevice.getIdentityAddress()).thenReturn(MAC_ADDRESS);
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsControllerTestBase.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsControllerTestBase.java
index 6401388..6ecbf2e 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsControllerTestBase.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsControllerTestBase.java
@@ -155,6 +155,7 @@
         mDevice = mBluetoothAdapter.getRemoteDevice(config.getAddress());
         when(mCachedDevice.getDevice()).thenReturn(mDevice);
         when(mCachedDevice.getAddress()).thenReturn(config.getAddress());
+        when(mCachedDevice.getIdentityAddress()).thenReturn(config.getAddress());
     }
 
     /**
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragmentTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragmentTest.java
index ce41a8d..fac8b58 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragmentTest.java
@@ -89,6 +89,7 @@
         when(fragmentManager.beginTransaction()).thenReturn(mFragmentTransaction);
 
         when(mCachedDevice.getAddress()).thenReturn(TEST_ADDRESS);
+        when(mCachedDevice.getIdentityAddress()).thenReturn(TEST_ADDRESS);
         Bundle args = new Bundle();
         args.putString(BluetoothDeviceDetailsFragment.KEY_DEVICE_ADDRESS, TEST_ADDRESS);
         mFragment.setArguments(args);
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingDetailTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingDetailTest.java
index ea841fa..bac868f 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingDetailTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingDetailTest.java
@@ -305,6 +305,7 @@
         when(cachedDevice.isConnected()).thenReturn(true);
         when(cachedDevice.getDevice()).thenReturn(device2);
         when(cachedDevice.getAddress()).thenReturn(TEST_DEVICE_ADDRESS_B);
+        when(cachedDevice.getIdentityAddress()).thenReturn(TEST_DEVICE_ADDRESS_B);
 
         mFragment.onProfileConnectionStateChanged(cachedDevice, BluetoothProfile.A2DP,
                 BluetoothAdapter.STATE_CONNECTED);
diff --git a/tests/robotests/src/com/android/settings/bluetooth/ForgetDeviceDialogFragmentTest.java b/tests/robotests/src/com/android/settings/bluetooth/ForgetDeviceDialogFragmentTest.java
index 5c23238..9c266c1 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/ForgetDeviceDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/ForgetDeviceDialogFragmentTest.java
@@ -73,6 +73,7 @@
         FakeFeatureFactory.setupForTest();
         String deviceAddress = "55:66:77:88:99:AA";
         when(mCachedDevice.getAddress()).thenReturn(deviceAddress);
+        when(mCachedDevice.getIdentityAddress()).thenReturn(deviceAddress);
         when(mCachedDevice.getDevice()).thenReturn(mBluetoothDevice);
         when(mCachedDevice.getName()).thenReturn(DEVICE_NAME);
         mFragment = spy(ForgetDeviceDialogFragment.newInstance(deviceAddress));
diff --git a/tests/robotests/src/com/android/settings/bluetooth/RemoteDeviceNameDialogFragmentTest.java b/tests/robotests/src/com/android/settings/bluetooth/RemoteDeviceNameDialogFragmentTest.java
index c8467b2..ad5b70c 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/RemoteDeviceNameDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/RemoteDeviceNameDialogFragmentTest.java
@@ -62,6 +62,7 @@
 
         String deviceAddress = "55:66:77:88:99:AA";
         when(mCachedDevice.getAddress()).thenReturn(deviceAddress);
+        when(mCachedDevice.getIdentityAddress()).thenReturn(deviceAddress);
         mFragment = spy(RemoteDeviceNameDialogFragment.newInstance(mCachedDevice));
         doReturn(mCachedDevice).when(mFragment).getDevice(any());
     }
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/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/safetycenter/SafetySourceBroadcastReceiverTest.java b/tests/unit/src/com/android/settings/safetycenter/SafetySourceBroadcastReceiverTest.java
index 581286b..8806e50 100644
--- a/tests/unit/src/com/android/settings/safetycenter/SafetySourceBroadcastReceiverTest.java
+++ b/tests/unit/src/com/android/settings/safetycenter/SafetySourceBroadcastReceiverTest.java
@@ -80,6 +80,16 @@
     }
 
     @Test
+    public void sendSafetyData_whenSafetyCenterIsEnabled_withNullSourceIds_sendsNoData() {
+        when(mSafetyCenterStatusHolder.isEnabled(mApplicationContext)).thenReturn(true);
+        Intent intent = new Intent();
+
+        new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
+
+        verify(mSafetyCenterManagerWrapper, never()).sendSafetyCenterUpdate(any(), any());
+    }
+
+    @Test
     public void sendSafetyData_whenSafetyCenterIsEnabled_withNoSourceIds_sendsNoData() {
         when(mSafetyCenterStatusHolder.isEnabled(mApplicationContext)).thenReturn(true);
         Intent intent = new Intent().putExtra(EXTRA_REFRESH_SAFETY_SOURCE_IDS, new String[]{});