Merge "Reorder battery tips priority" into sc-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index e678983..da43847 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2631,7 +2631,7 @@
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
             <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
-                       android:value="com.android.settings.notification.NotificationAssistantPicker" />
+                       android:value="com.android.settings.notification.ConfigureNotificationSettings" />
         </activity>
 
         <activity
diff --git a/color-check-baseline.xml b/color-check-baseline.xml
index 462f828..34aaf49 100644
--- a/color-check-baseline.xml
+++ b/color-check-baseline.xml
@@ -2293,6 +2293,102 @@
         priority="4"
         summary="Using hardcoded color"
         explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+        errorLine1="        &lt;item android:offset=&quot;0&quot; android:color=&quot;#33263238&quot;/>"
+        errorLine2="                                 ~~~~~~~~~~~~~~~~~~~~~~~~~">
+        <location
+            file="res/drawable/ic_files_go_round.xml"
+            line="46"
+            column="34"/>
+    </issue>
+
+    <issue
+        id="HardCodedColor"
+        severity="Error"
+        message="Avoid using hardcoded color"
+        category="Correctness"
+        priority="4"
+        summary="Using hardcoded color"
+        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+        errorLine1="        &lt;item android:offset=&quot;1&quot; android:color=&quot;#00263238&quot;/>"
+        errorLine2="                                 ~~~~~~~~~~~~~~~~~~~~~~~~~">
+        <location
+            file="res/drawable/ic_files_go_round.xml"
+            line="47"
+            column="34"/>
+    </issue>
+
+    <issue
+        id="HardCodedColor"
+        severity="Error"
+        message="Avoid using hardcoded color"
+        category="Correctness"
+        priority="4"
+        summary="Using hardcoded color"
+        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+        errorLine1="        &lt;item android:offset=&quot;0&quot; android:color=&quot;#281A237E&quot;/>"
+        errorLine2="                                 ~~~~~~~~~~~~~~~~~~~~~~~~~">
+        <location
+            file="res/drawable/ic_files_go_round.xml"
+            line="71"
+            column="34"/>
+    </issue>
+
+    <issue
+        id="HardCodedColor"
+        severity="Error"
+        message="Avoid using hardcoded color"
+        category="Correctness"
+        priority="4"
+        summary="Using hardcoded color"
+        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+        errorLine1="        &lt;item android:offset=&quot;1&quot; android:color=&quot;#051A237E&quot;/>"
+        errorLine2="                                 ~~~~~~~~~~~~~~~~~~~~~~~~~">
+        <location
+            file="res/drawable/ic_files_go_round.xml"
+            line="72"
+            column="34"/>
+    </issue>
+
+    <issue
+        id="HardCodedColor"
+        severity="Error"
+        message="Avoid using hardcoded color"
+        category="Correctness"
+        priority="4"
+        summary="Using hardcoded color"
+        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+        errorLine1="        &lt;item android:offset=&quot;0.0029046&quot; android:color=&quot;#19FFFFFF&quot;/>"
+        errorLine2="                                         ~~~~~~~~~~~~~~~~~~~~~~~~~">
+        <location
+            file="res/drawable/ic_files_go_round.xml"
+            line="116"
+            column="42"/>
+    </issue>
+
+    <issue
+        id="HardCodedColor"
+        severity="Error"
+        message="Avoid using hardcoded color"
+        category="Correctness"
+        priority="4"
+        summary="Using hardcoded color"
+        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+        errorLine1="        &lt;item android:offset=&quot;1&quot; android:color=&quot;#00FFFFFF&quot;/>"
+        errorLine2="                                 ~~~~~~~~~~~~~~~~~~~~~~~~~">
+        <location
+            file="res/drawable/ic_files_go_round.xml"
+            line="117"
+            column="34"/>
+    </issue>
+
+    <issue
+        id="HardCodedColor"
+        severity="Error"
+        message="Avoid using hardcoded color"
+        category="Correctness"
+        priority="4"
+        summary="Using hardcoded color"
+        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
         errorLine1="            android:color=&quot;@color/homepage_about_background&quot; />"
         errorLine2="            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
         <location
@@ -2677,54 +2773,6 @@
         priority="4"
         summary="Using hardcoded color"
         explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
-        errorLine1="            android:fillColor=&quot;@color/homepage_generic_icon_background&quot; />"
-        errorLine2="            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
-        <location
-            file="res/drawable/ic_network_signal_blue.xml"
-            line="23"
-            column="11"/>
-    </issue>
-
-    <issue
-        id="HardCodedColor"
-        severity="Error"
-        message="Avoid using hardcoded color"
-        category="Correctness"
-        priority="4"
-        summary="Using hardcoded color"
-        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
-        errorLine1="            android:fillColor=&quot;@color/homepage_generic_icon_background&quot; />"
-        errorLine2="            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
-        <location
-            file="res/drawable/ic_network_signal_blue.xml"
-            line="25"
-            column="11"/>
-    </issue>
-
-    <issue
-        id="HardCodedColor"
-        severity="Error"
-        message="Avoid using hardcoded color"
-        category="Correctness"
-        priority="4"
-        summary="Using hardcoded color"
-        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
-        errorLine1="            android:fillColor=&quot;@color/homepage_generic_icon_background&quot; />"
-        errorLine2="            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
-        <location
-            file="res/drawable/ic_network_signal_blue.xml"
-            line="27"
-            column="11"/>
-    </issue>
-
-    <issue
-        id="HardCodedColor"
-        severity="Error"
-        message="Avoid using hardcoded color"
-        category="Correctness"
-        priority="4"
-        summary="Using hardcoded color"
-        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
         errorLine1="            android:color=&quot;@color/homepage_notification_background&quot; />"
         errorLine2="            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
         <location
@@ -2997,12 +3045,28 @@
         priority="4"
         summary="Using hardcoded color"
         explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
-        errorLine1="    &lt;path"
-        errorLine2="        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+        errorLine1="    &lt;path android:fillColor=&quot;@color/homepage_generic_icon_background&quot;"
+        errorLine2="          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+        <location
+            file="res/drawable/ic_network_signal_blue.xml"
+            line="23"
+            column="11"/>
+    </issue>
+
+    <issue
+        id="HardCodedColor"
+        severity="Error"
+        message="Avoid using hardcoded color"
+        category="Correctness"
+        priority="4"
+        summary="Using hardcoded color"
+        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+        errorLine1="    &lt;path android:fillColor=&quot;@color/homepage_generic_icon_background&quot;"
+        errorLine2="          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
         <location
             file="res/drawable/ic_network_signal_blue.xml"
             line="25"
-            column="9"/>
+            column="11"/>
     </issue>
 
     <issue
@@ -3013,28 +3077,12 @@
         priority="4"
         summary="Using hardcoded color"
         explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
-        errorLine1="C6.67,19.26,7.26,18.67,8,18.67z&quot; />"
-        errorLine2="        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+        errorLine1="    &lt;path android:fillColor=&quot;@color/homepage_generic_icon_background&quot;"
+        errorLine2="          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
         <location
             file="res/drawable/ic_network_signal_blue.xml"
-            line="32"
-            column="9"/>
-    </issue>
-
-    <issue
-        id="HardCodedColor"
-        severity="Error"
-        message="Avoid using hardcoded color"
-        category="Correctness"
-        priority="4"
-        summary="Using hardcoded color"
-        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
-        errorLine1="        android:pathData=&quot;M16,12h1.33c0.74,0,1.33,0.6,1.33,1.33v12c0,0.74-0.6,1.33-1.33,1.33H16c-0.74,0-1.33-0.6-1.33-1.33v-12"
-        errorLine2="^">
-        <location
-            file="res/drawable/ic_network_signal_blue.xml"
-            line="35"
-            column="1"/>
+            line="27"
+            column="11"/>
     </issue>
 
     <issue
@@ -3077,22 +3125,6 @@
         priority="4"
         summary="Using hardcoded color"
         explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
-        errorLine1="                android:color=&quot;@color/notification_silence_color&quot; />"
-        errorLine2="                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
-        <location
-            file="res/drawable/ic_notification_silence.xml"
-            line="22"
-            column="17"/>
-    </issue>
-
-    <issue
-        id="HardCodedColor"
-        severity="Error"
-        message="Avoid using hardcoded color"
-        category="Correctness"
-        priority="4"
-        summary="Using hardcoded color"
-        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
         errorLine1="                android:color=&quot;@color/homepage_location_background&quot;/>"
         errorLine2="                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
         <location
@@ -3365,6 +3397,54 @@
         priority="4"
         summary="Using hardcoded color"
         explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+        errorLine1="          &lt;item android:offset=&quot;0&quot; android:color=&quot;#FF4285F4&quot;/>"
+        errorLine2="                                   ~~~~~~~~~~~~~~~~~~~~~~~~~">
+        <location
+            file="res/drawable/one_handed_guideline.xml"
+            line="34"
+            column="36"/>
+    </issue>
+
+    <issue
+        id="HardCodedColor"
+        severity="Error"
+        message="Avoid using hardcoded color"
+        category="Correctness"
+        priority="4"
+        summary="Using hardcoded color"
+        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+        errorLine1="          &lt;item android:offset=&quot;1&quot; android:color=&quot;#004385F5&quot;/>"
+        errorLine2="                                   ~~~~~~~~~~~~~~~~~~~~~~~~~">
+        <location
+            file="res/drawable/one_handed_guideline.xml"
+            line="35"
+            column="36"/>
+    </issue>
+
+    <issue
+        id="HardCodedColor"
+        severity="Error"
+        message="Avoid using hardcoded color"
+        category="Correctness"
+        priority="4"
+        summary="Using hardcoded color"
+        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+        errorLine1="            android:background=&quot;@color/homepage_emergency_background&quot;>"
+        errorLine2="            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+        <location
+            file="res/layout/preference_battery_error.xml"
+            line="35"
+            column="13"/>
+    </issue>
+
+    <issue
+        id="HardCodedColor"
+        severity="Error"
+        message="Avoid using hardcoded color"
+        category="Correctness"
+        priority="4"
+        summary="Using hardcoded color"
+        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
         errorLine1="            android:src=&quot;@color/running_processes_system_ram&quot;"
         errorLine2="            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
         <location
@@ -3573,11 +3653,27 @@
         priority="4"
         summary="Using hardcoded color"
         explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+        errorLine1="    &lt;string name=&quot;sync_plug&quot; msgid=&quot;7956982719077985381&quot;>&quot;‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‎‏‎‎‏‎‎‎‏‎‏‏‏‏‏‏‏‏‎‏‏‏‎‎‏‏‎‏‏‎‎‏‏‏‎‎‎‎‏‏‎‏‎‎‎‎‎‎‎‎‎‎‏‏‎‏‎‎‏‎‎‎‎‏‎‏‎‏‏‎‎‎‏‏‎‎‏‎‏‎‎‏‎‎‏‏‎&quot;&lt;font fgcolor=&quot;#ffffffff&quot;>&quot;‎‏‎‎‏‏‏‎Welcome to Google sync!‎‏‎‎‏‏‎&quot;&lt;/font>&quot;‎‏‎‎‏‏‏‎ ‎‏‎‎‏‏‎\n‎‏‎‎‏‏‏‎A Google approach to syncing data to allow access to your contacts, appointments, and more from wherever you are.‎‏‎‎‏‎&quot;&lt;/string>"
+        errorLine2="                                                                                                                                                                         ~~~~~~~~~~~~~~~~~~~">
+        <location
+            file="res/values-en-rXC/strings.xml"
+            line="2930"
+            column="170"/>
+    </issue>
+
+    <issue
+        id="HardCodedColor"
+        severity="Error"
+        message="Avoid using hardcoded color"
+        category="Correctness"
+        priority="4"
+        summary="Using hardcoded color"
+        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
         errorLine1="    &lt;string name=&quot;sync_plug&quot; msgid=&quot;7956982719077985381&quot;>&lt;font fgcolor=&quot;#ffffffff&quot;>&quot;Welcome to Google sync!&quot;&lt;/font>&quot; \nA Google approach to syncing data to allow access to your contacts, appointments and more from wherever you are.&quot;&lt;/string>"
         errorLine2="                                                               ~~~~~~~~~~~~~~~~~~~">
         <location
             file="res/values-en-rAU/strings.xml"
-            line="2821"
+            line="2940"
             column="64"/>
     </issue>
 
@@ -3593,7 +3689,7 @@
         errorLine2="                                                               ~~~~~~~~~~~~~~~~~~~">
         <location
             file="res/values-en-rCA/strings.xml"
-            line="2821"
+            line="2940"
             column="64"/>
     </issue>
 
@@ -3609,7 +3705,7 @@
         errorLine2="                                                               ~~~~~~~~~~~~~~~~~~~">
         <location
             file="res/values-en-rGB/strings.xml"
-            line="2821"
+            line="2940"
             column="64"/>
     </issue>
 
@@ -3625,7 +3721,7 @@
         errorLine2="                                                               ~~~~~~~~~~~~~~~~~~~">
         <location
             file="res/values-en-rIN/strings.xml"
-            line="2821"
+            line="2940"
             column="64"/>
     </issue>
 
@@ -3637,27 +3733,11 @@
         priority="4"
         summary="Using hardcoded color"
         explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
-        errorLine1="    &lt;string name=&quot;sync_plug&quot; msgid=&quot;7956982719077985381&quot;>&quot;‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‎‏‎‎‏‎‎‎‏‎‏‏‏‏‏‏‏‏‎‏‏‏‎‎‏‏‎‏‏‎‎‏‏‏‎‎‎‎‏‏‎‏‎‎‎‎‎‎‎‎‎‎‏‏‎‏‎‎‏‎‎‎‎‏‎‏‎‏‏‎‎‎‏‏‎‎‏‎‏‎‎‏‎‎‏‏‎&quot;&lt;font fgcolor=&quot;#ffffffff&quot;>&quot;‎‏‎‎‏‏‏‎Welcome to Google sync!‎‏‎‎‏‏‎&quot;&lt;/font>&quot;‎‏‎‎‏‏‏‎ ‎‏‎‎‏‏‎\n‎‏‎‎‏‏‏‎A Google approach to syncing data to allow access to your contacts, appointments, and more from wherever you are.‎‏‎‎‏‎&quot;&lt;/string>"
-        errorLine2="                                                                                                                                                                         ~~~~~~~~~~~~~~~~~~~">
-        <location
-            file="res/values-en-rXC/strings.xml"
-            line="2821"
-            column="170"/>
-    </issue>
-
-    <issue
-        id="HardCodedColor"
-        severity="Error"
-        message="Avoid using hardcoded color"
-        category="Correctness"
-        priority="4"
-        summary="Using hardcoded color"
-        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
         errorLine1="    &lt;string name=&quot;sync_plug&quot;>&lt;font fgcolor=&quot;#ffffffff&quot;>Welcome to Google sync!&lt;/font>"
         errorLine2="                                   ~~~~~~~~~~~~~~~~~~~">
         <location
             file="res/values/strings.xml"
-            line="6543"
+            line="6823"
             column="36"/>
     </issue>
 
@@ -3689,7 +3769,7 @@
         errorLine2="                                           ^">
         <location
             file="res/values/styles.xml"
-            line="435"
+            line="439"
             column="44"/>
     </issue>
 
@@ -3705,7 +3785,7 @@
         errorLine2="                                           ^">
         <location
             file="res/values/styles.xml"
-            line="441"
+            line="445"
             column="44"/>
     </issue>
 
@@ -3721,7 +3801,7 @@
         errorLine2="                                           ^">
         <location
             file="res/values/styles.xml"
-            line="442"
+            line="446"
             column="44"/>
     </issue>
 
@@ -3737,7 +3817,7 @@
         errorLine2="                                 ^">
         <location
             file="res/values/styles.xml"
-            line="478"
+            line="482"
             column="34"/>
     </issue>
 
@@ -3753,7 +3833,7 @@
         errorLine2="                                       ^">
         <location
             file="res/values/themes.xml"
-            line="106"
+            line="103"
             column="40"/>
     </issue>
 
@@ -3769,7 +3849,7 @@
         errorLine2="                                       ^">
         <location
             file="res/values/themes.xml"
-            line="106"
+            line="103"
             column="40"/>
     </issue>
 
@@ -3785,7 +3865,7 @@
         errorLine2="                                            ^">
         <location
             file="res/values/themes.xml"
-            line="191"
+            line="188"
             column="45"/>
     </issue>
 
@@ -3801,7 +3881,7 @@
         errorLine2="                                                ^">
         <location
             file="res/values/themes.xml"
-            line="192"
+            line="189"
             column="49"/>
     </issue>
 
@@ -3817,7 +3897,7 @@
         errorLine2="                                            ^">
         <location
             file="res/values/themes.xml"
-            line="200"
+            line="197"
             column="45"/>
     </issue>
 
@@ -3833,7 +3913,7 @@
         errorLine2="                                                ^">
         <location
             file="res/values/themes.xml"
-            line="201"
+            line="198"
             column="49"/>
     </issue>
 
@@ -3849,7 +3929,7 @@
         errorLine2="                                         ^">
         <location
             file="res/values/themes.xml"
-            line="272"
+            line="268"
             column="42"/>
     </issue>
 
@@ -4013,132 +4093,4 @@
             column="5"/>
     </issue>
 
-    <issue
-        id="HardCodedColor"
-        severity="Error"
-        message="Avoid using hardcoded color"
-        category="Correctness"
-        priority="4"
-        summary="Using hardcoded color"
-        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
-        errorLine1="          &lt;item android:offset=&quot;0&quot; android:color=&quot;#FF4285F4&quot;/>"
-        errorLine2="                                   ~~~~~~~~~~~~~~~~~~~~~~~~~">
-        <location
-            file="res/drawable/one_handed_guideline.xml"
-            line="34"
-            column="36"/>
-    </issue>
-
-    <issue
-        id="HardCodedColor"
-        severity="Error"
-        message="Avoid using hardcoded color"
-        category="Correctness"
-        priority="4"
-        summary="Using hardcoded color"
-        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
-        errorLine1="          &lt;item android:offset=&quot;1&quot; android:color=&quot;#004385F5&quot;/>"
-        errorLine2="                                   ~~~~~~~~~~~~~~~~~~~~~~~~~">
-        <location
-            file="res/drawable/one_handed_guideline.xml"
-            line="35"
-            column="36"/>
-    </issue>
-
-    <issue
-        id="HardCodedColor"
-        severity="Error"
-        message="Avoid using hardcoded color"
-        category="Correctness"
-        priority="4"
-        summary="Using hardcoded color"
-        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
-        errorLine1="        &lt;item android:offset=&quot;0&quot; android:color=&quot;#33263238&quot;/>"
-        errorLine2="        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
-        <location
-            file="res/drawable/ic_files_go_round.xml"
-            line="46"
-            column="34"/>
-    </issue>
-
-    <issue
-        id="HardCodedColor"
-        severity="Error"
-        message="Avoid using hardcoded color"
-        category="Correctness"
-        priority="4"
-        summary="Using hardcoded color"
-        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
-        errorLine1="        &lt;item android:offset=&quot;1&quot; android:color=&quot;#00263238&quot;/>"
-        errorLine2="        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
-        <location
-            file="res/drawable/ic_files_go_round.xml"
-            line="47"
-            column="34"/>
-    </issue>
-
-    <issue
-        id="HardCodedColor"
-        severity="Error"
-        message="Avoid using hardcoded color"
-        category="Correctness"
-        priority="4"
-        summary="Using hardcoded color"
-        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
-        errorLine1="        &lt;item android:offset=&quot;0&quot; android:color=&quot;#281A237E&quot;/>"
-        errorLine2="        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
-        <location
-            file="res/drawable/ic_files_go_round.xml"
-            line="71"
-            column="34"/>
-    </issue>
-
-    <issue
-        id="HardCodedColor"
-        severity="Error"
-        message="Avoid using hardcoded color"
-        category="Correctness"
-        priority="4"
-        summary="Using hardcoded color"
-        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
-        errorLine1="        &lt;item android:offset=&quot;1&quot; android:color=&quot;#051A237E&quot;/>"
-        errorLine2="        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
-        <location
-            file="res/drawable/ic_files_go_round.xml"
-            line="72"
-            column="34"/>
-    </issue>
-
-    <issue
-        id="HardCodedColor"
-        severity="Error"
-        message="Avoid using hardcoded color"
-        category="Correctness"
-        priority="4"
-        summary="Using hardcoded color"
-        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
-        errorLine1="        &lt;item android:offset=&quot;0.0029046&quot; android:color=&quot;#19FFFFFF&quot;/>"
-        errorLine2="        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
-        <location
-            file="res/drawable/ic_files_go_round.xml"
-            line="116"
-            column="42"/>
-    </issue>
-
-    <issue
-        id="HardCodedColor"
-        severity="Error"
-        message="Avoid using hardcoded color"
-        category="Correctness"
-        priority="4"
-        summary="Using hardcoded color"
-        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
-        errorLine1="        &lt;item android:offset=&quot;1&quot; android:color=&quot;#00FFFFFF&quot;/>"
-        errorLine2="        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
-        <location
-            file="res/drawable/ic_files_go_round.xml"
-            line="117"
-            column="34"/>
-    </issue>
-
 </issues>
diff --git a/res/layout/preview_seek_bar_view_pager.xml b/res/layout/preview_seek_bar_view_pager.xml
index 6ddff13..fa9f550 100644
--- a/res/layout/preview_seek_bar_view_pager.xml
+++ b/res/layout/preview_seek_bar_view_pager.xml
@@ -27,7 +27,7 @@
         android:layout_width="match_parent"
         android:layout_height="400dp"
         android:layout_weight="1"
-        android:background="?android:attr/colorBackgroundFloating"
+        android:background="?android:attr/colorBackground"
         android:contentDescription="@string/preview_pager_content_description" />
 
     <TextView
diff --git a/res/layout/screen_zoom_preview_1.xml b/res/layout/screen_zoom_preview_1.xml
index 9290df9..a0ee532 100644
--- a/res/layout/screen_zoom_preview_1.xml
+++ b/res/layout/screen_zoom_preview_1.xml
@@ -29,7 +29,7 @@
         <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="match_parent"
-            android:background="?android:attr/colorBackgroundFloating"
+            android:background="?android:attr/colorBackground"
             android:paddingTop="@dimen/conversation_message_list_padding"
             android:paddingStart="@dimen/conversation_message_list_padding"
             android:paddingEnd="@dimen/conversation_message_list_padding"
diff --git a/res/layout/screen_zoom_preview_settings.xml b/res/layout/screen_zoom_preview_settings.xml
index de16392..998d221 100644
--- a/res/layout/screen_zoom_preview_settings.xml
+++ b/res/layout/screen_zoom_preview_settings.xml
@@ -19,7 +19,7 @@
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:fillViewport="true"
-    android:background="?android:attr/colorBackgroundFloating"
+    android:background="?android:attr/colorBackground"
     android:importantForAccessibility="noHideDescendants">
 
     <view class="com.android.settings.TouchBlockingFrameLayout"
diff --git a/res/layout/settings_collapsing_base_layout.xml b/res/layout/settings_collapsing_base_layout.xml
index 7ebf433..ca9c132 100644
--- a/res/layout/settings_collapsing_base_layout.xml
+++ b/res/layout/settings_collapsing_base_layout.xml
@@ -20,24 +20,29 @@
     android:id="@+id/content_parent"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:transitionGroup="true">
+    android:fitsSystemWindows="true">
 
     <com.google.android.material.appbar.AppBarLayout
         android:id="@+id/app_bar"
         android:layout_width="match_parent"
-        android:layout_height="180dp"
+        android:layout_height="wrap_content"
+        android:fitsSystemWindows="true"
+        android:outlineAmbientShadowColor="@android:color/transparent"
+        android:outlineSpotShadowColor="@android:color/transparent"
+        android:background="?android:attr/colorPrimary"
         android:theme="@style/Theme.CollapsingToolbar.Settings">
 
         <com.google.android.material.appbar.CollapsingToolbarLayout
             android:id="@+id/collapsing_toolbar"
-            android:background="?android:attr/colorPrimary"
             android:layout_width="match_parent"
-            android:layout_height="match_parent"
+            android:layout_height="226dp"
             app:maxLines="3"
-            app:contentScrim="?android:attr/colorPrimary"
+            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
+            app:scrimAnimationDuration="150"
+            app:scrimVisibleHeightTrigger="174dp"
+            app:statusBarScrim="@empty"
+            app:titleCollapseMode="fade"
             app:collapsedTitleTextAppearance="@style/ToolbarText.Collapsed"
-            app:statusBarScrim="?android:attr/colorPrimary"
-            app:layout_scrollFlags="scroll|exitUntilCollapsed"
             app:expandedTitleMarginStart="18dp"
             app:expandedTitleMarginEnd="16dp"
             app:toolbarId="@id/action_bar">
diff --git a/res/layout/storage_item.xml b/res/layout/storage_item.xml
index cefb399..6de2d510 100644
--- a/res/layout/storage_item.xml
+++ b/res/layout/storage_item.xml
@@ -15,6 +15,7 @@
 -->
 
 <LinearLayout 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"
               android:orientation="vertical"
@@ -51,20 +52,20 @@
                 android:maxHeight="24dp"/>
         </LinearLayout>
 
-        <RelativeLayout
+        <androidx.constraintlayout.widget.ConstraintLayout
             android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:gravity="center_vertical" >
+            android:layout_height="wrap_content">
 
             <TextView
                 android:id="@android:id/title"
-                android:layout_width="wrap_content"
+                android:layout_width="0dp"
                 android:layout_height="wrap_content"
                 android:singleLine="true"
                 android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Subhead"
                 android:textAlignment="viewStart"
                 android:ellipsize="marquee"
-                android:fadingEdge="horizontal" />
+                app:layout_constraintStart_toStartOf="parent"
+                app:layout_constraintEnd_toStartOf="@android:id/summary"/>
 
             <TextView
                 android:id="@android:id/summary"
@@ -74,7 +75,8 @@
                 android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Body1"
                 android:textColor="?android:attr/textColorSecondary"
                 android:maxLines="10"
-                android:layout_alignParentEnd="true"/>
+                app:layout_constraintBaseline_toBaselineOf="@android:id/title"
+                app:layout_constraintEnd_toEndOf="parent"/>
 
             <ProgressBar
                 android:id="@android:id/progress"
@@ -84,8 +86,8 @@
                 android:layout_marginBottom="4dp"
                 android:max="100"
                 android:layout_below="@android:id/title"
-                android:layout_alignStart="@android:id/title"
+                app:layout_constraintTop_toBottomOf="@android:id/title"
                 style="?android:attr/progressBarStyleHorizontal" />
-        </RelativeLayout>
+        </androidx.constraintlayout.widget.ConstraintLayout>
     </LinearLayout>
 </LinearLayout>
diff --git a/res/values-night/themes.xml b/res/values-night/themes.xml
index a4f495a..604610d 100644
--- a/res/values-night/themes.xml
+++ b/res/values-night/themes.xml
@@ -45,8 +45,9 @@
         <item name="colorPrimary">@*android:color/edge_effect_device_default_dark</item>
     </style>
 
-    <style name="Theme.CollapsingToolbar.Settings"
-           parent="@style/Theme.MaterialComponents.DayNight">
+    <style name="Theme.CollapsingToolbar.Settings" parent="@style/Theme.MaterialComponents.DayNight">
+        <item name="elevationOverlayEnabled">true</item>
+        <item name="elevationOverlayColor">?attr/colorPrimary</item>
         <item name="colorPrimary">@*android:color/primary_dark_device_default_settings</item>
         <item name="colorAccent">@*android:color/accent_device_default_dark</item>
     </style>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 2688b32..2a05a4d 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -5890,6 +5890,21 @@
     <!-- Dialog message when app can't been restricted because it is not optimized [CHAR_LIMIT=120] -->
     <string name="background_activity_disabled_dialog_text">Since this app is not set to optimize battery, you can\u2019t restrict it.\n\nTo restrict the app, first turn on battery optimization.</string>
 
+    <!-- Title for the battery unrestricted settings [CHAR_LIMIT=40] -->
+    <string name="manager_battery_usage_unrestricted_title">Unrestricted</string>
+    <!-- Title for the battery optimized settings [CHAR_LIMIT=40] -->
+    <string name="manager_battery_usage_optimized_title">Optimized</string>
+    <!-- Summary for the battery unrestricted settings [CHAR_LIMIT=NONE] -->
+    <string name="manager_battery_usage_unrestricted_summary">Allow battery usage in background without restrictions. May use more battery.</string>
+    <!-- Summary for the battery optimized settings [CHAR_LIMIT=NONE] -->
+    <string name="manager_battery_usage_optimized_summary">Optimize based on your usage. Recommended for most apps.</string>
+    <!-- Summary for the battery restricted settings [CHAR_LIMIT=NONE] -->
+    <string name="manager_battery_usage_restricted_summary">Restrict battery usage while in background. App may not work as expected. Notifications may be delayed.</string>
+    <!-- Footer for the manage battery usage page [CHAR_LIMIT=NONE] -->
+    <string name="manager_battery_usage_footer">Changing how an app uses your battery can affect its performance.</string>
+    <!-- Footer for the manage battery usage page when app is limited to specific option (e.g This app requires restricted battery usage) [CHAR_LIMIT=NONE] -->
+    <string name="manager_battery_usage_footer_limited">This app requires <xliff:g id="state" example="restricted">%1$s</xliff:g> battery usage.</string>
+
     <!-- Title for the screen usage in power use UI [CHAR_LIMIT=60] -->
     <string name="device_screen_usage">Screen usage since full charge</string>
     <!-- Label for list of apps using battery in power use UI. Note: ^1 should be used in all translations[CHAR_LIMIT=120] -->
@@ -6298,6 +6313,8 @@
     <string name ="battery_detail_info_title">Since full charge</string>
     <!-- Title for the battery management group [CHAR LIMIT=40] -->
     <string name ="battery_detail_manage_title">Manage battery usage</string>
+    <!-- Description for battery total and background usage time for an app, i.e. 1 hr 15 min total • 39 min background for past 24 hr. Note: ^1 and ^2 should be used in all translations [CHAR LIMIT=120] -->
+    <string name="battery_total_and_background_usage"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> total • <xliff:g id="time" example="39 min">^2</xliff:g> background for past 24 hr</string>
 
     <!-- Graph subtext displayed to user when enhanced battery estimate is being used [CHAR LIMIT=120] -->
     <string name="advanced_battery_graph_subtext">Battery left estimate is based on your device usage</string>
@@ -7221,7 +7238,7 @@
     <string name="vpn_require_connection_title">Require VPN connection?</string>
 
     <!-- Dialog subtitle warning for a VPN app that has an insecure type. [CHAR LIMIT=100]  -->
-    <string name="vpn_insecure_dialog_subtitle">This VPN is not secure. Update to an IKEv2 VPN</string>
+    <string name="vpn_insecure_dialog_subtitle">Not secure. Update to an IKEv2 VPN</string>
 
     <!-- Summary describing the always-on VPN feature. [CHAR LIMIT=NONE] -->
     <string name="vpn_lockdown_summary">Select a VPN profile to always remain connected to. Network traffic will only be allowed when connected to this VPN.</string>
@@ -9032,8 +9049,10 @@
         <item quantity="other">%d apps can read notifications</item>
     </plurals>
 
-    <!-- Title for Notification Assistant Picker screen [CHAR LIMIT=30]-->
-    <string name="notification_assistant_title">Adaptive Notifications</string>
+    <!-- Title for Notification Assistant setting  [CHAR LIMIT=30]-->
+    <string name="notification_assistant_title">Enhanced notifications</string>
+    <!-- Summary of Notification Assistant provided features [CHAR LIMIT=NONE]-->
+    <string name="notification_assistant_summary">Get suggested actions, replies, and more</string>
 
     <!-- Label for no NotificationAssistantService [CHAR_LIMIT=NONE] -->
     <string name="no_notification_assistant">None</string>
@@ -9051,10 +9070,11 @@
     <!-- Summary for a warning message about security implications of enabling a notification
           listener, displayed as a dialog message. [CHAR LIMIT=NONE] -->
     <string name="notification_assistant_security_warning_summary">
-        <xliff:g id="notification_assistant_name" example="Notification Assistant">%1$s</xliff:g> will be able to read all notifications,
-        including personal information such as contact names and the text of messages you receive.
-        This app will also be able to dismiss notifications or take action on buttons in notifications, including answering phone calls.
-        \n\nThis will also give the app the ability to turn Do Not Disturb on or off and change related settings.
+        Enhanced notifications can read all notification content,
+        including personal information like contact names and messages.
+        This feature can also dismiss notifications or take actions on buttons in notifications,
+        such as answering phone calls.
+        \n\nThis feature can also turn Priority mode on or off and change related settings.
     </string>
 
     <!-- Title for a warning message about security implications of enabling a notification
@@ -9769,6 +9789,11 @@
     <string name="switch_on_text">On</string>
     <string name="switch_off_text">Off</string>
 
+
+    <!-- The subtext when screen pinning feature is enabled. [CHAR LIMIT=28] -->
+    <string name="screen_pinning_switch_on_text">On</string>
+    <!-- The subtext when screen pinning feature is disabled. [CHAR LIMIT=28] -->
+    <string name="screen_pinning_switch_off_text">Off</string>
     <!-- [CHAR LIMIT=28] Screen pinning title -->
     <string name="screen_pinning_title">App pinning</string>
     <!-- [CHAR LIMIT=none] Screen pinning introduction -->
@@ -13095,17 +13120,17 @@
     <string name="apps_dashboard_title">Apps</string>
 
     <!-- Bluetooth message permission alert for notification content [CHAR LIMIT=none] -->
-    <string name="bluetooth_message_access_notification_content">Untrusted device wants to access your messages. Tap for details.</string>
+    <string name="bluetooth_message_access_notification_content">A device wants to access your messages. Tap for details.</string>
     <!-- Bluetooth message permission alert for dialog title [CHAR LIMIT=none] -->
     <string name="bluetooth_message_access_dialog_title">Allow access to messages?</string>
     <!-- Bluetooth message permission alert for dialog content [CHAR LIMIT=none] -->
-    <string name="bluetooth_message_access_dialog_content">An untrusted Bluetooth device, <xliff:g id="device_name" example="My device">%1$s</xliff:g>, wants to access your messages.\n\nYou haven\u2019t connected to <xliff:g id="device_name" example="My device">%2$s</xliff:g> before.</string>
+    <string name="bluetooth_message_access_dialog_content">A Bluetooth device, <xliff:g id="device_name" example="My device">%1$s</xliff:g>, wants to access your messages.\n\nYou haven\u2019t connected to <xliff:g id="device_name" example="My device">%2$s</xliff:g> before.</string>
     <!-- Bluetooth phonebook permission alert for notification content [CHAR LIMIT=none] -->
-    <string name="bluetooth_phonebook_access_notification_content">Untrusted device wants to access your contacts and call log. Tap for details.</string>
+    <string name="bluetooth_phonebook_access_notification_content">A device wants to access your contacts and call log. Tap for details.</string>
     <!-- Bluetooth phonebook permission alert for dialog title [CHAR LIMIT=none] -->
     <string name="bluetooth_phonebook_access_dialog_title">Allow access to contacts and call log?</string>
     <!-- Bluetooth phonebook permission alert for dialog content [CHAR LIMIT=none] -->
-    <string name="bluetooth_phonebook_access_dialog_content">An untrusted Bluetooth device, <xliff:g id="device_name" example="My device">%1$s</xliff:g>, wants to access your contacts and call log. This includes data about incoming and outgoing calls.\n\nYou haven\u2019t connected to <xliff:g id="device_name" example="My device">%2$s</xliff:g> before.</string>
+    <string name="bluetooth_phonebook_access_dialog_content">A Bluetooth device, <xliff:g id="device_name" example="My device">%1$s</xliff:g>, wants to access your contacts and call log. This includes data about incoming and outgoing calls.\n\nYou haven\u2019t connected to <xliff:g id="device_name" example="My device">%2$s</xliff:g> before.</string>
 
     <!-- Brightness category name in Display Settings [CHAR LIMIT=none] -->
     <string name="category_name_brightness">Brightness</string>
@@ -13203,4 +13228,7 @@
 
     <!-- All apps screen title, entry name on Apps page for the user to go to the all apps page. [CHAR LIMIT=30] -->
     <string name="all_apps">All apps</string>
+
+    <!-- Label for button to not allow grant the permission for remote devices. [CHAR_LIMIT=50] -->
+    <string name="request_manage_bluetooth_permission_dont_allow">Don\u2019t allow</string>
 </resources>
diff --git a/res/values/themes.xml b/res/values/themes.xml
index d7b3257..4df4a78 100644
--- a/res/values/themes.xml
+++ b/res/values/themes.xml
@@ -74,6 +74,8 @@
         <item name="android:actionBarStyle">@style/Widget.ActionBar.SubSettings</item>
 
         <item name="switchBarTheme">@style/ThemeOverlay.SwitchBar.Settings</item>
+        <item name="android:navigationBarColor">@android:color/transparent</item>
+        <item name="android:statusBarColor">@android:color/transparent</item>
     </style>
 
     <style name="Theme.SubSettings" parent="Theme.SubSettings.Base"/>
@@ -272,8 +274,9 @@
         <item name="colorPrimary">@*android:color/edge_effect_device_default_light</item>
     </style>
 
-    <style name="Theme.CollapsingToolbar.Settings"
-           parent="@style/Theme.MaterialComponents.DayNight">
+    <style name="Theme.CollapsingToolbar.Settings" parent="@style/Theme.MaterialComponents.DayNight">
+        <item name="elevationOverlayEnabled">true</item>
+        <item name="elevationOverlayColor">?attr/colorPrimary</item>
         <item name="colorPrimary">@*android:color/primary_device_default_settings_light</item>
         <item name="colorAccent">@*android:color/accent_device_default_light</item>
     </style>
diff --git a/res/xml/configure_notification_settings.xml b/res/xml/configure_notification_settings.xml
index c7925fb..529fbea 100644
--- a/res/xml/configure_notification_settings.xml
+++ b/res/xml/configure_notification_settings.xml
@@ -115,6 +115,11 @@
             android:title="@string/snooze_options_title"
             settings:controller="com.android.settings.notification.SnoozeNotificationPreferenceController" />
 
+        <SwitchPreference
+            android:key="notification_assistant"
+            android:title="@string/notification_assistant_title"
+            android:summary="@string/notification_assistant_summary"/>
+
         <!-- Notification badging -->
         <SwitchPreference
             android:key="notification_badging"
diff --git a/res/xml/configure_notification_settings_v2.xml b/res/xml/configure_notification_settings_v2.xml
index b7cc2c8..98768f8 100644
--- a/res/xml/configure_notification_settings_v2.xml
+++ b/res/xml/configure_notification_settings_v2.xml
@@ -155,5 +155,11 @@
             android:order="22"
             android:title="@string/notification_pulse_title"
             settings:controller="com.android.settings.notification.PulseNotificationPreferenceController"/>
+
+        <SwitchPreference
+            android:key="notification_assistant"
+            android:order="23"
+            android:title="@string/notification_assistant_title"
+            android:summary="@string/notification_assistant_summary"/>
     </PreferenceCategory>
 </PreferenceScreen>
diff --git a/res/xml/special_access.xml b/res/xml/special_access.xml
index 83c23b5..892c3eb 100644
--- a/res/xml/special_access.xml
+++ b/res/xml/special_access.xml
@@ -80,13 +80,6 @@
             android:value="com.android.settings.Settings$WriteSettingsActivity" />
     </Preference>
 
-    <com.android.settingslib.widget.AppPreference
-        android:key="notification_assistant"
-        android:title="@string/notification_assistant_title"
-        android:summary="@string/summary_placeholder"
-        settings:fragment="com.android.settings.notification.NotificationAssistantPicker"
-        settings:controller="com.android.settings.notification.NotificationAssistantPreferenceController"/>
-
     <Preference
         android:key="notification_access"
         android:title="@string/manage_notification_access_title"
diff --git a/src/com/android/settings/bluetooth/BluetoothPermissionActivity.java b/src/com/android/settings/bluetooth/BluetoothPermissionActivity.java
index e40e30d..10acdb5 100644
--- a/src/com/android/settings/bluetooth/BluetoothPermissionActivity.java
+++ b/src/com/android/settings/bluetooth/BluetoothPermissionActivity.java
@@ -16,6 +16,8 @@
 
 package com.android.settings.bluetooth;
 
+import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
+
 import android.bluetooth.BluetoothDevice;
 import android.content.BroadcastReceiver;
 import android.content.Context;
@@ -34,8 +36,6 @@
 import com.android.internal.app.AlertController;
 import com.android.settings.R;
 
-import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
-
 /**
  * BluetoothPermissionActivity shows a dialog for accepting incoming
  * profile connection request from untrusted devices.
@@ -138,7 +138,7 @@
         }
         p.mPositiveButtonText = getString(R.string.allow);
         p.mPositiveButtonListener = this;
-        p.mNegativeButtonText = getString(R.string.deny);
+        p.mNegativeButtonText = getString(R.string.request_manage_bluetooth_permission_dont_allow);
         p.mNegativeButtonListener = this;
         mOkButton = mAlert.getButton(DialogInterface.BUTTON_POSITIVE);
         setupAlert();
diff --git a/src/com/android/settings/notification/ConfigureNotificationSettings.java b/src/com/android/settings/notification/ConfigureNotificationSettings.java
index dcba273..22b4311 100644
--- a/src/com/android/settings/notification/ConfigureNotificationSettings.java
+++ b/src/com/android/settings/notification/ConfigureNotificationSettings.java
@@ -22,6 +22,7 @@
 import android.app.Application;
 import android.app.settings.SettingsEnums;
 import android.app.usage.IUsageStatsManager;
+import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
@@ -62,6 +63,7 @@
     private static final int REQUEST_CODE = 200;
     private static final String SELECTED_PREFERENCE_KEY = "selected_preference";
     private static final String KEY_ADVANCED_CATEGORY = "configure_notifications_advanced";
+    private static final String KEY_NAS = "notification_assistant";
 
     private RingtonePreference mRequestPreference;
 
@@ -116,6 +118,8 @@
             }
 
         });
+        controllers.add(new NotificationAssistantPreferenceController(context,
+                new NotificationBackend(), host, KEY_NAS));
 
         if (FeatureFlagUtils.isEnabled(context, FeatureFlags.SILKY_HOME)) {
             controllers.add(new EmergencyBroadcastPreferenceController(context,
@@ -199,4 +203,14 @@
                     return keys;
                 }
             };
+
+    // Dialogs only have access to the parent fragment, not the controller, so pass the information
+    // along to keep business logic out of this file
+    protected void enableNAS(ComponentName cn) {
+        final PreferenceScreen screen = getPreferenceScreen();
+        NotificationAssistantPreferenceController napc =
+                use(NotificationAssistantPreferenceController.class);
+        napc.setNotificationAssistantGranted(cn);
+        napc.updateState(screen.findPreference(napc.getPreferenceKey()));
+    }
 }
diff --git a/src/com/android/settings/notification/NotificationAssistantDialogFragment.java b/src/com/android/settings/notification/NotificationAssistantDialogFragment.java
new file mode 100644
index 0000000..48b1cd9
--- /dev/null
+++ b/src/com/android/settings/notification/NotificationAssistantDialogFragment.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2021 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.app.settings.SettingsEnums;
+import android.content.ComponentName;
+import android.content.DialogInterface;
+import android.os.Bundle;
+
+import androidx.appcompat.app.AlertDialog;
+import androidx.fragment.app.Fragment;
+
+import com.android.settings.R;
+import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
+
+public class NotificationAssistantDialogFragment extends InstrumentedDialogFragment
+        implements DialogInterface.OnClickListener {
+    static final String KEY_COMPONENT = "c";
+
+    public static NotificationAssistantDialogFragment newInstance(Fragment target,
+            ComponentName cn) {
+        final NotificationAssistantDialogFragment dialogFragment =
+                new NotificationAssistantDialogFragment();
+        final Bundle args = new Bundle();
+        args.putString(KEY_COMPONENT, cn.flattenToString());
+        dialogFragment.setArguments(args);
+        dialogFragment.setTargetFragment(target, 0);
+
+        return dialogFragment;
+    }
+
+    @Override
+    public Dialog onCreateDialog(Bundle savedInstanceState) {
+        final String summary = getResources()
+                .getString(R.string.notification_assistant_security_warning_summary);
+        return new AlertDialog.Builder(getContext())
+                .setMessage(summary)
+                .setCancelable(true)
+                .setPositiveButton(R.string.okay, this)
+                .create();
+    }
+
+    @Override
+    public int getMetricsCategory() {
+        return SettingsEnums.DEFAULT_NOTIFICATION_ASSISTANT;
+    }
+
+    @Override
+    public void onClick(DialogInterface dialog, int which) {
+        final Bundle args = getArguments();
+        final ComponentName cn = ComponentName.unflattenFromString(args
+                .getString(KEY_COMPONENT));
+        ConfigureNotificationSettings parent = (ConfigureNotificationSettings) getTargetFragment();
+        parent.enableNAS(cn);
+    }
+}
diff --git a/src/com/android/settings/notification/NotificationAssistantPreferenceController.java b/src/com/android/settings/notification/NotificationAssistantPreferenceController.java
index 66f27fe..637e4b0 100644
--- a/src/com/android/settings/notification/NotificationAssistantPreferenceController.java
+++ b/src/com/android/settings/notification/NotificationAssistantPreferenceController.java
@@ -18,44 +18,72 @@
 
 import android.content.ComponentName;
 import android.content.Context;
-import android.content.pm.PackageManager;
 import android.os.UserHandle;
+import android.provider.Settings;
 
-import com.android.settings.core.BasePreferenceController;
-import com.android.settingslib.applications.DefaultAppInfo;
-import com.android.settingslib.widget.CandidateInfo;
+import androidx.fragment.app.Fragment;
+
+import com.android.settings.core.TogglePreferenceController;
 
 import com.google.common.annotations.VisibleForTesting;
 
-public class NotificationAssistantPreferenceController extends BasePreferenceController {
+public class NotificationAssistantPreferenceController extends TogglePreferenceController {
+    private static final String TAG = "NASPreferenceController";
+    private static final int AVAILABLE = 1;
+    private Fragment mFragment;
+    private int mUserId = UserHandle.myUserId();
 
     @VisibleForTesting
     protected NotificationBackend mNotificationBackend;
-    private PackageManager mPackageManager;
 
-    public NotificationAssistantPreferenceController(Context context, String preferenceKey) {
+    public NotificationAssistantPreferenceController(Context context, NotificationBackend backend,
+            Fragment fragment, String preferenceKey) {
         super(context, preferenceKey);
-        mNotificationBackend = new NotificationBackend();
-        mPackageManager = mContext.getPackageManager();
+        mNotificationBackend = backend;
+        mFragment = fragment;
     }
 
     @Override
     public int getAvailabilityStatus() {
-        return BasePreferenceController.AVAILABLE;
+        return AVAILABLE;
     }
 
     @Override
-    public CharSequence getSummary() {
-        CandidateInfo appSelected = new NotificationAssistantPicker.CandidateNone(mContext);
-        ComponentName assistant = mNotificationBackend.getAllowedNotificationAssistant();
-        if (assistant != null) {
-            appSelected = createCandidateInfo(assistant);
-        }
-        return appSelected.loadLabel();
+    public boolean isChecked() {
+        ComponentName acn = mNotificationBackend.getAllowedNotificationAssistant();
+        ComponentName dcn = mNotificationBackend.getDefaultNotificationAssistant();
+        return (acn != null && acn.equals(dcn));
     }
 
-    @VisibleForTesting
-    protected CandidateInfo createCandidateInfo(ComponentName cn) {
-        return new DefaultAppInfo(mContext, mPackageManager, UserHandle.myUserId(), cn);
+    @Override
+    public boolean setChecked(boolean isChecked) {
+        ComponentName cn = isChecked
+                ? mNotificationBackend.getDefaultNotificationAssistant() : null;
+        if (isChecked) {
+            if (mFragment == null) {
+                throw new IllegalStateException("No fragment to start activity");
+            }
+            showDialog(cn);
+            return false;
+        } else {
+            setNotificationAssistantGranted(null);
+            return true;
+        }
     }
-}
+
+    protected void setNotificationAssistantGranted(ComponentName cn) {
+        if (Settings.Secure.getIntForUser(mContext.getContentResolver(),
+                Settings.Secure.NAS_SETTINGS_UPDATED, 0, mUserId) == 0) {
+            Settings.Secure.putIntForUser(mContext.getContentResolver(),
+                    Settings.Secure.NAS_SETTINGS_UPDATED, 1, mUserId);
+            mNotificationBackend.resetDefaultNotificationAssistant(cn != null);
+        }
+        mNotificationBackend.setNotificationAssistantGranted(cn);
+    }
+
+    protected void showDialog(ComponentName cn) {
+        NotificationAssistantDialogFragment dialogFragment =
+                NotificationAssistantDialogFragment.newInstance(mFragment, cn);
+        dialogFragment.show(mFragment.getFragmentManager(), TAG);
+    }
+}
\ No newline at end of file
diff --git a/src/com/android/settings/notification/NotificationBackend.java b/src/com/android/settings/notification/NotificationBackend.java
index 4347ca5..b08d02c 100644
--- a/src/com/android/settings/notification/NotificationBackend.java
+++ b/src/com/android/settings/notification/NotificationBackend.java
@@ -19,7 +19,6 @@
 import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
 import static android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_CACHED;
 import static android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_DYNAMIC;
-import static android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED;
 import static android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED_BY_ANY_LAUNCHER;
 
 import android.app.INotificationManager;
@@ -50,7 +49,6 @@
 import android.text.format.DateUtils;
 import android.util.IconDrawableFactory;
 import android.util.Log;
-import android.util.Slog;
 
 import androidx.annotation.VisibleForTesting;
 
@@ -563,6 +561,23 @@
         }
     }
 
+    public ComponentName getDefaultNotificationAssistant() {
+        try {
+            return sINM.getDefaultNotificationAssistant();
+        } catch (Exception e) {
+            Log.w(TAG, "Error calling NoMan", e);
+            return null;
+        }
+    }
+
+    public void resetDefaultNotificationAssistant(boolean loadFromConfig) {
+        try {
+            sINM.resetDefaultNotificationAssistant(loadFromConfig);
+        } catch (Exception e) {
+            Log.w(TAG, "Error calling NoMan", e);
+        }
+    }
+
     public boolean setNotificationAssistantGranted(ComponentName cn) {
         try {
             sINM.setNotificationAssistantAccessGranted(cn, true);
diff --git a/src/com/android/settings/notification/history/NotificationHistoryActivity.java b/src/com/android/settings/notification/history/NotificationHistoryActivity.java
index 4958f1b..7fb4a48 100644
--- a/src/com/android/settings/notification/history/NotificationHistoryActivity.java
+++ b/src/com/android/settings/notification/history/NotificationHistoryActivity.java
@@ -83,6 +83,22 @@
     private PackageManager mPm;
     private CountDownLatch mCountdownLatch;
     private Future mCountdownFuture;
+    private final ViewOutlineProvider mOutlineProvider = new ViewOutlineProvider() {
+        @Override
+        public void getOutline(View view, Outline outline) {
+            final TypedArray ta = NotificationHistoryActivity.this.obtainStyledAttributes(
+                    new int[]{android.R.attr.dialogCornerRadius});
+            final float dialogCornerRadius = ta.getDimension(0, 0);
+            ta.recycle();
+            TypedValue v = new TypedValue();
+            NotificationHistoryActivity.this.getTheme().resolveAttribute(
+                    com.android.internal.R.attr.listDivider, v, true);
+            int bottomPadding = NotificationHistoryActivity.this.getDrawable(v.resourceId)
+                    .getIntrinsicHeight();
+            outline.setRoundRect(0, 0, view.getWidth(), (view.getHeight() - bottomPadding),
+                    dialogCornerRadius);
+        }
+    };
     private UiEventLogger mUiEventLogger = new UiEventLoggerImpl();
 
     enum NotificationHistoryEvent implements UiEventLogger.UiEventEnum {
@@ -133,22 +149,7 @@
                 notifications.isEmpty() ? View.GONE : View.VISIBLE);
         mCountdownLatch.countDown();
         mTodayView.setClipToOutline(true);
-        mTodayView.setOutlineProvider(new ViewOutlineProvider() {
-            @Override
-            public void getOutline(View view, Outline outline) {
-                final TypedArray ta = NotificationHistoryActivity.this.obtainStyledAttributes(
-                        new int[]{android.R.attr.dialogCornerRadius});
-                final float dialogCornerRadius = ta.getDimension(0, 0);
-                ta.recycle();
-                TypedValue v = new TypedValue();
-                NotificationHistoryActivity.this.getTheme().resolveAttribute(
-                        com.android.internal.R.attr.listDivider, v, true);
-                int bottomPadding = NotificationHistoryActivity.this.getDrawable(v.resourceId)
-                        .getIntrinsicHeight();
-                outline.setRoundRect(0, 0, view.getWidth(), (view.getHeight() - bottomPadding),
-                        dialogCornerRadius);
-            }
-        });
+        mTodayView.setOutlineProvider(mOutlineProvider);
         // for each package, new header and recycler view
         for (int i = 0, notificationsSize = notifications.size(); i < notificationsSize; i++) {
             NotificationHistoryPackage nhp = notifications.get(i);
@@ -216,6 +217,8 @@
         mTodayView = findViewById(R.id.apps);
         mSnoozeView = findViewById(R.id.snoozed_list);
         mDismissView = findViewById(R.id.recently_dismissed_list);
+        mDismissView.setClipToOutline(true);
+        mDismissView.setOutlineProvider(mOutlineProvider);
         mHistoryOff = findViewById(R.id.history_off);
         mHistoryOn = findViewById(R.id.history_on);
         mHistoryEmpty = findViewById(R.id.history_on_empty);
diff --git a/src/com/android/settings/security/ScreenPinningPreferenceController.java b/src/com/android/settings/security/ScreenPinningPreferenceController.java
index 37a3f9c..442380d 100644
--- a/src/com/android/settings/security/ScreenPinningPreferenceController.java
+++ b/src/com/android/settings/security/ScreenPinningPreferenceController.java
@@ -40,7 +40,7 @@
     public CharSequence getSummary() {
         return Settings.System.getInt(mContext.getContentResolver(),
                 Settings.System.LOCK_TO_APP_ENABLED, 0) != 0
-                ? mContext.getText(R.string.switch_on_text)
-                : mContext.getText(R.string.switch_off_text);
+                ? mContext.getText(R.string.screen_pinning_switch_on_text)
+                : mContext.getText(R.string.screen_pinning_switch_off_text);
     }
 }
diff --git a/src/com/android/settings/vpn2/ConfigDialog.java b/src/com/android/settings/vpn2/ConfigDialog.java
index 24fb576..a88be03 100644
--- a/src/com/android/settings/vpn2/ConfigDialog.java
+++ b/src/com/android/settings/vpn2/ConfigDialog.java
@@ -153,7 +153,7 @@
         mL2tpSecret.setTextAppearance(android.R.style.TextAppearance_DeviceDefault_Medium);
         mIpsecIdentifier.setText(mProfile.ipsecIdentifier);
         mIpsecSecret.setText(mProfile.ipsecSecret);
-        AndroidKeystoreAliasLoader androidKeystoreAliasLoader =
+        final AndroidKeystoreAliasLoader androidKeystoreAliasLoader =
                 new AndroidKeystoreAliasLoader(null);
         loadCertificates(mIpsecUserCert, androidKeystoreAliasLoader.getKeyCertAliases(), 0,
                 mProfile.ipsecUserCert);
diff --git a/src/com/android/settings/vpn2/VpnSettings.java b/src/com/android/settings/vpn2/VpnSettings.java
index cdc6537..181b78f 100644
--- a/src/com/android/settings/vpn2/VpnSettings.java
+++ b/src/com/android/settings/vpn2/VpnSettings.java
@@ -304,7 +304,9 @@
                 LegacyVpnPreference p = mSettings.findOrCreatePreference(stubProfile, false);
                 p.setState(vpn.state);
                 p.setAlwaysOn(lockdownVpnKey != null && lockdownVpnKey.equals(vpn.key));
-                p.setInsecureVpn(VpnProfile.isLegacyType(stubProfile.type));
+                // (b/184921649) do not call setInsecureVpn() for connectedLegacyVpns, since the
+                // LegacyVpnInfo does not contain VPN type information, and the profile already
+                // exists within vpnProfiles.
                 updates.add(p);
             }
 
diff --git a/src/com/android/settings/wifi/tether/WifiTetherSettings.java b/src/com/android/settings/wifi/tether/WifiTetherSettings.java
index e342550..088356b 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherSettings.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherSettings.java
@@ -294,13 +294,4 @@
             screen.setInitialExpandedChildrenCount(getInitialExpandedChildCount());
         }
     }
-
-    @Override
-    public int getInitialExpandedChildCount() {
-        if (mSecurityPreferenceController != null && mSecurityPreferenceController.getSecurityType()
-                == SoftApConfiguration.SECURITY_TYPE_OPEN) {
-            return (EXPANDED_CHILD_COUNT_DEFAULT - 1);
-        }
-        return EXPANDED_CHILD_COUNT_DEFAULT;
-    }
 }
diff --git a/tests/robotests/src/com/android/settings/notification/NotificationAssistantDialogFragmentTest.java b/tests/robotests/src/com/android/settings/notification/NotificationAssistantDialogFragmentTest.java
new file mode 100644
index 0000000..eef3f04
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/NotificationAssistantDialogFragmentTest.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2021 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 static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.DialogInterface;
+
+import androidx.fragment.app.FragmentActivity;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class NotificationAssistantDialogFragmentTest {
+
+    private Context mContext;
+    @Mock
+    private ConfigureNotificationSettings mFragment;
+    private NotificationAssistantDialogFragment mDialogFragment;
+    @Mock
+    private FragmentActivity mActivity;
+
+    ComponentName mComponentName = new ComponentName("a", "b");
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mContext = spy(RuntimeEnvironment.application);
+        mDialogFragment =
+                spy(NotificationAssistantDialogFragment.newInstance(mFragment, mComponentName));
+        doReturn(mActivity).when(mDialogFragment).getActivity();
+        doReturn(mContext).when(mDialogFragment).getContext();
+
+    }
+
+
+    @Test
+    public void testClickOK_callEnableNAS() {
+        mDialogFragment.onClick(null, DialogInterface.BUTTON_POSITIVE);
+
+        verify(mFragment, times(1)).enableNAS(eq(mComponentName));
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/NotificationAssistantPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/NotificationAssistantPreferenceControllerTest.java
index b2f65e0..4f2145c 100644
--- a/tests/robotests/src/com/android/settings/notification/NotificationAssistantPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/NotificationAssistantPreferenceControllerTest.java
@@ -16,17 +16,25 @@
 
 package com.android.settings.notification;
 
-import static junit.framework.TestCase.assertEquals;
-
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import android.content.ComponentName;
 import android.content.Context;
-import android.content.pm.PackageManager;
-import android.graphics.drawable.Drawable;
-import android.os.Debug;
+import android.provider.Settings;
 
-import com.android.settingslib.widget.CandidateInfo;
+import androidx.fragment.app.FragmentManager;
+import androidx.fragment.app.FragmentTransaction;
+import androidx.test.core.app.ApplicationProvider;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -35,7 +43,6 @@
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
 
 @RunWith(RobolectricTestRunner.class)
 public class NotificationAssistantPreferenceControllerTest {
@@ -44,57 +51,86 @@
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private Context mContext;
     @Mock
+    private ConfigureNotificationSettings mFragment;
+    @Mock
+    private FragmentManager mFragmentManager;
+    @Mock
+    private FragmentTransaction mFragmentTransaction;
+    @Mock
     private NotificationBackend mBackend;
     private NotificationAssistantPreferenceController mPreferenceController;
+    ComponentName mNASComponent = new ComponentName("a", "b");
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        mContext = RuntimeEnvironment.application;
-        mPreferenceController = new TestPreferenceController(mContext, mBackend);
+        mContext = spy(ApplicationProvider.getApplicationContext());
+        doReturn(mContext).when(mFragment).getContext();
+        when(mFragment.getFragmentManager()).thenReturn(mFragmentManager);
+        when(mFragmentManager.beginTransaction()).thenReturn(mFragmentTransaction);
+        when(mBackend.getDefaultNotificationAssistant()).thenReturn(mNASComponent);
+        mPreferenceController = new NotificationAssistantPreferenceController(mContext,
+                mBackend, mFragment, KEY);
     }
 
     @Test
-    public void testGetSummary_noAssistant() {
+    public void testIsChecked() throws Exception {
+        when(mBackend.getAllowedNotificationAssistant()).thenReturn(mNASComponent);
+        assertTrue(mPreferenceController.isChecked());
+
         when(mBackend.getAllowedNotificationAssistant()).thenReturn(null);
-        CharSequence noneLabel = new NotificationAssistantPicker.CandidateNone(mContext)
-                .loadLabel();
-        assertEquals(noneLabel, mPreferenceController.getSummary());
+        assertFalse(mPreferenceController.isChecked());
     }
 
     @Test
-    public void testGetSummary_TestAssistant() {
-        String testName = "test_pkg/test_cls";
-        when(mBackend.getAllowedNotificationAssistant()).thenReturn(
-                ComponentName.unflattenFromString(testName));
-        assertEquals(testName, mPreferenceController.getSummary());
+    public void testSetChecked() throws Exception {
+        // Verify a dialog is shown when the switch is to be enabled.
+        assertFalse(mPreferenceController.setChecked(true));
+        verify(mFragmentTransaction).add(
+                any(NotificationAssistantDialogFragment.class), anyString());
+        verify(mBackend, times(0)).setNotificationAssistantGranted(any());
+
+        // Verify no dialog is shown and NAS set to null when disabled
+        assertTrue(mPreferenceController.setChecked(false));
+        verify(mBackend, times(1)).setNotificationAssistantGranted(null);
     }
 
-    private final class TestPreferenceController extends NotificationAssistantPreferenceController {
+    @Test
+    public void testMigrationFromSetting_userEnable() throws Exception {
+        Settings.Secure.putIntForUser(mContext.getContentResolver(),
+                Settings.Secure.NAS_SETTINGS_UPDATED, 0, 0);
 
-        private TestPreferenceController(Context context, NotificationBackend backend) {
-            super(context, KEY);
-            mNotificationBackend = backend;
-        }
+        //Test user enable for the first time
+        mPreferenceController.setNotificationAssistantGranted(mNASComponent);
+        assertEquals(1, Settings.Secure.getIntForUser(mContext.getContentResolver(),
+                Settings.Secure.NAS_SETTINGS_UPDATED, 0, 0));
+        verify(mBackend, times(1))
+                .resetDefaultNotificationAssistant(eq(true));
 
-        @Override
-        public String getPreferenceKey() {
-            return KEY;
-        }
+        //Test user enable again, migration should not happen
+        mPreferenceController.setNotificationAssistantGranted(mNASComponent);
+        //Number of invocations should not increase
+        verify(mBackend, times(1))
+                .resetDefaultNotificationAssistant(eq(true));
+    }
 
-        @Override
-        protected CandidateInfo createCandidateInfo(ComponentName cn) {
-            return new CandidateInfo(true) {
-                @Override
-                public CharSequence loadLabel() { return cn.flattenToString(); }
+    @Test
+    public void testMigrationFromSetting_userDisable() throws Exception {
+        Settings.Secure.putIntForUser(mContext.getContentResolver(),
+                Settings.Secure.NAS_SETTINGS_UPDATED, 0, 0);
 
-                @Override
-                public Drawable loadIcon() { return null; }
+        //Test user disable for the first time
+        mPreferenceController.setChecked(false);
+        assertEquals(1, Settings.Secure.getIntForUser(mContext.getContentResolver(),
+                Settings.Secure.NAS_SETTINGS_UPDATED, 0, 0));
+        verify(mBackend, times(1))
+                .resetDefaultNotificationAssistant(eq(false));
 
-                @Override
-                public String getKey() { return null; }
-            };
-        }
+        //Test user disable again, migration should not happen
+        mPreferenceController.setChecked(false);
+        //Number of invocations should not increase
+        verify(mBackend, times(1))
+                .resetDefaultNotificationAssistant(eq(false));
     }
 
 }