Merge "[Provider Model] Remove the footer of WFC" into sc-dev
diff --git a/Android.bp b/Android.bp
index 2dfe3fd..2d4c42c 100644
--- a/Android.bp
+++ b/Android.bp
@@ -110,3 +110,21 @@
     name: "contextualcards",
     aars: ["libs/contextualcards.aar"],
 }
+
+filegroup {
+    name: "Settings_proguard_flags",
+    srcs: ["proguard.flags"],
+}
+
+// The sources for Settings need to be exposed to SettingsGoogle, etc.
+// so they can run the com.android.settingslib.search.IndexableProcessor
+// over all the sources together.
+filegroup {
+    name: "Settings_srcs",
+    srcs: ["src/**/*.java"],
+}
+
+filegroup {
+    name: "Settings_manifest",
+    srcs: ["AndroidManifest.xml"],
+}
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index cfda9b7..86d7992 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1272,6 +1272,7 @@
         <activity
             android:name=".notification.history.NotificationHistoryActivity"
             android:exported="true"
+            android:theme="@style/Theme.SubSettings"
             android:label="@string/notification_history_title">
             <intent-filter android:priority="1">
                 <action android:name="android.settings.NOTIFICATION_HISTORY" />
@@ -1315,7 +1316,7 @@
         </activity>
         <activity
             android:name="Settings$ScanningSettingsActivity"
-            android:label="@string/location_scanning_screen_title"
+            android:label="@string/location_services_screen_title"
             android:icon="@drawable/ic_homepage_location"
             android:exported="true"
             android:configChanges="orientation|keyboardHidden|screenSize">
@@ -1324,7 +1325,7 @@
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
             <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
-                android:value="com.android.settings.location.ScanningSettings" />
+                android:value="com.android.settings.location.LocationServices" />
             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
                 android:value="true" />
         </activity>
@@ -3065,6 +3066,33 @@
         </activity>
 
         <activity
+            android:name="Settings$AlarmsAndRemindersActivity"
+            android:exported="true"
+            android:label="@string/alarms_and_reminders_label">
+            <intent-filter android:priority="1">
+                <action android:name="android.settings.REQUEST_SCHEDULE_EXACT_ALARM" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+            <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+                       android:value="com.android.settings.applications.manageapplications.ManageApplications" />
+            <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
+                       android:value="true" />
+        </activity>
+
+        <activity
+            android:name="Settings$AlarmsAndRemindersAppActivity"
+            android:exported="true"
+            android:label="@string/alarms_and_reminders_label">
+            <intent-filter android:priority="1">
+                <action android:name="android.settings.REQUEST_SCHEDULE_EXACT_ALARM" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <data android:scheme="package" />
+            </intent-filter>
+            <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+                       android:value="com.android.settings.applications.appinfo.AlarmsAndRemindersDetails" />
+        </activity>
+
+        <activity
             android:name="Settings$ManageExternalSourcesActivity"
             android:exported="true"
             android:label="@string/install_other_apps">
diff --git a/color-check-baseline.xml b/color-check-baseline.xml
index 4aa67ab..b94da0d 100644
--- a/color-check-baseline.xml
+++ b/color-check-baseline.xml
@@ -2997,6 +2997,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;path"
+        errorLine2="        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+        <location
+            file="res/drawable/ic_network_signal_blue.xml"
+            line="25"
+            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="C6.67,19.26,7.26,18.67,8,18.67z&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"/>
+    </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/notification_block_color&quot;/>"
         errorLine2="                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
         <location
@@ -3525,27 +3573,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="2816"
-            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="2818"
+            line="2821"
             column="64"/>
     </issue>
 
@@ -3561,7 +3593,7 @@
         errorLine2="                                                               ~~~~~~~~~~~~~~~~~~~">
         <location
             file="res/values-en-rCA/strings.xml"
-            line="2818"
+            line="2821"
             column="64"/>
     </issue>
 
@@ -3577,7 +3609,7 @@
         errorLine2="                                                               ~~~~~~~~~~~~~~~~~~~">
         <location
             file="res/values-en-rGB/strings.xml"
-            line="2818"
+            line="2821"
             column="64"/>
     </issue>
 
@@ -3593,7 +3625,7 @@
         errorLine2="                                                               ~~~~~~~~~~~~~~~~~~~">
         <location
             file="res/values-en-rIN/strings.xml"
-            line="2818"
+            line="2821"
             column="64"/>
     </issue>
 
@@ -3605,11 +3637,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="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="6537"
+            line="6543"
             column="36"/>
     </issue>
 
@@ -3641,7 +3689,7 @@
         errorLine2="                                           ^">
         <location
             file="res/values/styles.xml"
-            line="434"
+            line="435"
             column="44"/>
     </issue>
 
@@ -3657,7 +3705,7 @@
         errorLine2="                                           ^">
         <location
             file="res/values/styles.xml"
-            line="440"
+            line="441"
             column="44"/>
     </issue>
 
@@ -3673,7 +3721,7 @@
         errorLine2="                                           ^">
         <location
             file="res/values/styles.xml"
-            line="441"
+            line="442"
             column="44"/>
     </issue>
 
@@ -3689,7 +3737,7 @@
         errorLine2="                                 ^">
         <location
             file="res/values/styles.xml"
-            line="477"
+            line="478"
             column="34"/>
     </issue>
 
@@ -3801,7 +3849,7 @@
         errorLine2="                                         ^">
         <location
             file="res/values/themes.xml"
-            line="273"
+            line="272"
             column="42"/>
     </issue>
 
@@ -3913,7 +3961,7 @@
         errorLine2="                                          ^">
         <location
             file="res/values/themes_suw.xml"
-            line="188"
+            line="196"
             column="43"/>
     </issue>
 
@@ -3929,7 +3977,7 @@
         errorLine2="                                         ^">
         <location
             file="res/values/themes_suw.xml"
-            line="189"
+            line="197"
             column="42"/>
     </issue>
 
@@ -3945,7 +3993,7 @@
         errorLine2="                                            ^">
         <location
             file="res/values/themes_suw.xml"
-            line="190"
+            line="198"
             column="45"/>
     </issue>
 
diff --git a/res/layout/enable_accessibility_service_dialog_content.xml b/res/layout/enable_accessibility_service_dialog_content.xml
index 59cb6dd..6b3220b 100644
--- a/res/layout/enable_accessibility_service_dialog_content.xml
+++ b/res/layout/enable_accessibility_service_dialog_content.xml
@@ -134,6 +134,11 @@
                 android:text="@string/accessibility_dialog_button_deny"
                 style="@style/AccessibilityDialogButton" />
 
+            <Button
+                android:id="@+id/permission_enable_uninstall_button"
+                android:text="@string/uninstall_text"
+                android:visibility="gone"
+                style="@style/AccessibilityDialogButton" />
         </LinearLayout>
     </LinearLayout>
 
diff --git a/res/layout/preference_widget_dialog_summary.xml b/res/layout/preference_widget_dialog_summary.xml
index 2978efb..e37be71 100644
--- a/res/layout/preference_widget_dialog_summary.xml
+++ b/res/layout/preference_widget_dialog_summary.xml
@@ -18,7 +18,6 @@
 
 <TextView
     xmlns:android="http://schemas.android.com/apk/res/android"
-    android:text="@string/bluetooth_select_a2dp_codec_type_help_info"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_marginTop="@dimen/developer_option_dialog_margin_top"
diff --git a/res/layout/wifi_calling_settings_preferences.xml b/res/layout/wifi_calling_settings_preferences.xml
index 7e411e1..98acd95 100644
--- a/res/layout/wifi_calling_settings_preferences.xml
+++ b/res/layout/wifi_calling_settings_preferences.xml
@@ -21,11 +21,11 @@
     android:layout_height="match_parent"
     android:orientation="vertical">
 
-    <com.android.settings.widget.SwitchBar
+    <com.android.settings.widget.SettingsMainSwitchBar
         android:id="@+id/switch_bar"
-        android:layout_height="?android:attr/actionBarSize"
-        android:layout_width="match_parent"
-        android:theme="?attr/switchBarTheme" />
+        android:title="@string/wifi_calling_main_switch_title"
+        android:layout_height="wrap_content"
+        android:layout_width="match_parent" />
 
     <FrameLayout
         android:id="@android:id/tabcontent"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 107ca38..48350d6 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -3359,6 +3359,22 @@
     <!-- Section header above list of external storage devices [CHAR LIMIT=30]-->
     <string name="storage_external_title">Portable storage</string>
 
+    <!-- Label for the settings activity for controlling apps that can schedule alarms [CHAR LIMIT=30] -->
+    <string name="alarms_and_reminders_label">Alarms and reminders</string>
+    <!-- Label for the switch to toggler the permission for scheduling alarms [CHAR LIMIT=50] -->
+    <string name="alarms_and_reminders_switch_title">Allow to set alarms or reminders</string>
+    <!-- Title for the setting screen for controlling apps that can schedule alarms [CHAR LIMIT=30] -->
+    <string name="alarms_and_reminders_title">Alarms and reminders</string>
+    <!-- Description that appears below the alarms_and_reminders switch [CHAR LIMIT=NONE] -->
+    <string name="alarms_and_reminders_footer_title">
+        Allow this app to schedule alarms or other timing based events.
+        This will allow the app to wake up and run even when you are not using the device.
+        Note that revoking this permission may cause the app to malfunction, specifically any alarms
+        that the app has scheduled will no longer work.
+    </string>
+    <!-- Keywords for setting screen for controlling apps that can schedule alarms [CHAR LIMIT=100] -->
+    <string name="keywords_alarms_and_reminders">schedule, alarm, reminder, event</string>
+
     <!-- Summary of a single storage volume, constrasting available and total storage space. [CHAR LIMIT=48]-->
     <string name="storage_volume_summary"><xliff:g id="used" example="1.2GB">%1$s</xliff:g> used of <xliff:g id="total" example="32GB">%2$s</xliff:g></string>
     <!-- Summary of a single storage volume used space. [CHAR LIMIT=24] -->
@@ -4007,8 +4023,6 @@
     <string name="location_high_battery_use">High battery use</string>
     <!-- [CHAR LIMIT=30] Location settings screen, recent location requests low battery use-->
     <string name="location_low_battery_use">Low battery use</string>
-    <!-- [CHAR LIMIT=60] Wireless background scanning settings screen, screen title -->
-    <string name="location_scanning_screen_title">Wi\u2011Fi and Bluetooth scanning</string>
     <!-- [CHAR LIMIT=130] Preference title for Wi-Fi always scanning -->
     <string name="location_scanning_wifi_always_scanning_title">Wi\u2011Fi scanning</string>
     <!-- Preference description text for Wi-Fi always scanning -->
@@ -4017,6 +4031,8 @@
     <string name="location_scanning_bluetooth_always_scanning_title">Bluetooth scanning</string>
     <!-- Description text for Bluetooth always scanning -->
     <string name="location_scanning_bluetooth_always_scanning_description">Allow apps and services to scan for nearby devices at any time, even when Bluetooth is off. This can be used, for example, to improve location-based features and services.</string>
+    <!-- [CHAR LIMIT=60] Location Services screen, screen title -->
+    <string name="location_services_screen_title">Location Services</string>
     <!-- [CHAR LIMIT=50] Location settings screen, sub category for location services for managed profile -->
     <string name="managed_profile_location_services">Location services for work</string>
 
@@ -4965,6 +4981,8 @@
     <string name="captions_category_title">Captions</string>
     <!-- Title for the accessibility preference category of audio services and settings. [CHAR LIMIT=50] -->
     <string name="audio_category_title">Audio</string>
+    <!-- Title for the accessibility preference category of general services and settings. [CHAR LIMIT=50] -->
+    <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] -->
@@ -7304,6 +7322,8 @@
     <string name="help_uri_printing" translatable="false"></string>
     <!-- Help URI, About phone [DO NOT TRANSLATE] -->
     <string name="help_uri_about" translatable="false"></string>
+    <!-- Help URI, manage apps that can set alarms and reminders [DO NOT TRANSLATE] -->
+    <string name="help_uri_alarms_and_reminders" translatable="false"></string>
 
     <!-- Help URL, WiFi [DO NOT TRANSLATE] -->
     <string name="help_url_wifi" translatable="false"></string>
@@ -12086,7 +12106,7 @@
     <string name="carrier_settings_euicc">Carrier</string>
     <!-- Mobile network settings screen, a string showing the version of carrier settings for this
          subscription [CHAR LIMIT=NONE] -->
-    <string name="carrier_settings_version">Settings version</string>
+    <string name="carrier_settings_version">Carrier settings version</string>
 
     <!-- Mobile network settings screen, name for call settings category [CHAR LIMIT=NONE] -->
     <string name="call_category">Calling</string>
@@ -12753,6 +12773,8 @@
     <string name="adaptive_battery_main_switch_title" translatable="false">Use adaptive battery</string>
     <!-- Do not translate. Title for adaptive brightness main switch preferences. [CHAR LIMIT=50] -->
     <string name="adaptive_brightness_main_switch_title" translatable="false">Use adaptive brightness</string>
+    <!-- Do not translate. Title for wifi calling main switch preferences. [CHAR LIMIT=50] -->
+    <string name="wifi_calling_main_switch_title" translatable="false">Use Wi-Fi calling</string>
 
     <!-- Default preference title for showing all apps on device [CHAR_LIMIT=50]-->
     <string name="default_see_all_apps_title">See all apps</string>
diff --git a/res/xml/accessibility_settings.xml b/res/xml/accessibility_settings.xml
index 67b1211..1743f9b 100644
--- a/res/xml/accessibility_settings.xml
+++ b/res/xml/accessibility_settings.xml
@@ -128,8 +128,9 @@
 
     </PreferenceCategory>
 
-    <!-- TODO(b/174829936): Add title for shortcuts settings category. -->
-    <PreferenceCategory android:persistent="false">
+    <PreferenceCategory
+        android:persistent="false"
+        android:title="@string/general_category_title">
 
         <Preference
             android:fragment="com.android.settings.accessibility.ShortcutsSettingsFragment"
diff --git a/res/xml/alarms_and_reminders.xml b/res/xml/alarms_and_reminders.xml
new file mode 100644
index 0000000..a9d4323
--- /dev/null
+++ b/res/xml/alarms_and_reminders.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ 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.
+  -->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+                  android:title="@string/alarms_and_reminders_title">
+
+    <com.android.settings.widget.FilterTouchesRestrictedSwitchPreference
+        android:key="alarms_and_reminders_switch"
+        android:title="@string/alarms_and_reminders_switch_title" />
+
+    <com.android.settingslib.widget.FooterPreference
+        android:key="alarms_and_reminders_description"
+        android:title="@string/alarms_and_reminders_footer_title"
+        android:selectable="false" />
+
+</PreferenceScreen>
diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml
index 8df5696..27bf0ba 100644
--- a/res/xml/display_settings.xml
+++ b/res/xml/display_settings.xml
@@ -20,7 +20,7 @@
     android:key="display_settings_screen"
     android:title="@string/display_settings"
     settings:keywords="@string/keywords_display"
-    settings:initialExpandedChildrenCount="5">
+    settings:initialExpandedChildrenCount="6">
 
     <com.android.settingslib.RestrictedPreference
         android:key="brightness"
diff --git a/res/xml/location_scanning.xml b/res/xml/location_services.xml
similarity index 77%
rename from res/xml/location_scanning.xml
rename to res/xml/location_services.xml
index f82500b..7096d2c 100644
--- a/res/xml/location_scanning.xml
+++ b/res/xml/location_services.xml
@@ -15,7 +15,8 @@
 -->
 
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
-        android:title="@string/location_scanning_screen_title">
+                  xmlns:settings="http://schemas.android.com/apk/res-auto"
+        android:title="@string/location_services_screen_title">
 
         <SwitchPreference
             android:title="@string/location_scanning_wifi_always_scanning_title"
@@ -29,4 +30,9 @@
             android:defaultValue="true"
             android:key="bluetooth_always_scanning" />
 
+        <PreferenceCategory
+            android:key="location_services"
+            android:layout="@layout/preference_category_no_label"
+            settings:controller="com.android.settings.location.LocationServicePreferenceController"/>
+
 </PreferenceScreen>
diff --git a/res/xml/location_settings.xml b/res/xml/location_settings.xml
index fb03f4c..7a79136 100644
--- a/res/xml/location_settings.xml
+++ b/res/xml/location_settings.xml
@@ -22,16 +22,10 @@
     settings:keywords="@string/keywords_location">
 
     <PreferenceCategory
-        android:key="recent_location_requests"
-        android:title="@string/location_category_recent_location_requests"
-        settings:controller="com.android.settings.location.RecentLocationRequestPreferenceController"/>
-
-    <Preference
-        android:key="recent_location_requests_see_all_button"
-        android:title="@string/location_recent_location_requests_see_all"
-        android:icon="@drawable/ic_chevron_right_24dp"
-        android:fragment="com.android.settings.location.RecentLocationRequestSeeAllFragment"
-        settings:searchable="false"/>
+        android:key="recent_location_access"
+        android:title="@string/location_category_recent_location_access"
+        settings:controller=
+            "com.android.settings.location.RecentLocationAccessPreferenceController"/>
 
     <PreferenceCategory
         android:key="location_advanced_settings"
@@ -50,9 +44,9 @@
         </Preference>
 
         <Preference
-            android:fragment="com.android.settings.location.ScanningSettings"
-            android:key="location_scanning"
-            android:title="@string/location_scanning_screen_title"
+            android:fragment="com.android.settings.location.LocationServices"
+            android:key="location_services"
+            android:title="@string/location_services_screen_title"
             settings:controller="com.android.settings.location.LocationScanningPreferenceController"/>
 
         <!-- This preference gets removed if there is no managed profile -->
@@ -65,11 +59,6 @@
             settings:forWork="true"
             settings:useAdminDisabledSummary="true"/>
 
-        <PreferenceCategory
-            android:key="location_services"
-            android:layout="@layout/preference_category_no_label"
-            settings:controller="com.android.settings.location.LocationServicePreferenceController"/>
-
         <!-- This preference gets removed if there is no managed profile -->
         <PreferenceCategory
             android:key="location_services_managed_profile"
diff --git a/res/xml/location_settings_personal.xml b/res/xml/location_settings_personal.xml
index de8ed81..2e1cb7e 100644
--- a/res/xml/location_settings_personal.xml
+++ b/res/xml/location_settings_personal.xml
@@ -25,14 +25,8 @@
     <PreferenceCategory
         android:key="recent_location_requests"
         android:title="@string/location_category_recent_location_requests"
-        settings:controller="com.android.settings.location.RecentLocationRequestPreferenceController"/>
-
-    <Preference
-        android:key="recent_location_requests_see_all_button"
-        android:title="@string/location_recent_location_requests_see_all"
-        android:icon="@drawable/ic_chevron_right_24dp"
-        android:fragment="com.android.settings.location.RecentLocationRequestSeeAllFragment"
-        settings:searchable="false"/>
+        settings:controller=
+            "com.android.settings.location.RecentLocationAccessPreferenceController"/>
 
     <!-- This preference category gets removed if new_recent_location_ui is disabled -->
     <Preference
@@ -46,15 +40,10 @@
     </Preference>
 
     <Preference
-        android:key="location_scanning"
-        android:title="@string/location_scanning_screen_title"
-        android:fragment="com.android.settings.location.ScanningSettings"
-        settings:controller="com.android.settings.location.LocationScanningPreferenceController"/>
-
-    <PreferenceCategory
         android:key="location_services"
-        android:layout="@layout/preference_category_no_label"
-        settings:controller="com.android.settings.location.LocationServicePreferenceController"/>
+        android:title="@string/location_services_screen_title"
+        android:fragment="com.android.settings.location.LocationServices"
+        settings:controller="com.android.settings.location.LocationScanningPreferenceController"/>
 
     <PreferenceCategory
         android:key="location_footer"
diff --git a/res/xml/location_settings_workprofile.xml b/res/xml/location_settings_workprofile.xml
index f15c8d8..f6f2d96 100644
--- a/res/xml/location_settings_workprofile.xml
+++ b/res/xml/location_settings_workprofile.xml
@@ -25,16 +25,8 @@
     <PreferenceCategory
         android:key="recent_location_requests"
         android:title="@string/location_category_recent_location_requests"
-        settings:controller="com.android.settings.location.RecentLocationRequestPreferenceController"/>
-
-    <Preference
-        android:key="recent_location_requests_see_all_button"
-        android:title="@string/location_recent_location_requests_see_all"
-        android:icon="@drawable/ic_chevron_right_24dp"
-        android:fragment="com.android.settings.location.RecentLocationRequestSeeAllFragment"
-        settings:controller="com.android.settings.core.WorkPreferenceController"
-        settings:forWork="true"
-        settings:searchable="false"/>
+        settings:controller=
+            "com.android.settings.location.RecentLocationAccessPreferenceController"/>
 
     <com.android.settingslib.RestrictedSwitchPreference
         android:key="managed_profile_location_switch"
diff --git a/res/xml/special_access.xml b/res/xml/special_access.xml
index 150c1e6..671d882 100644
--- a/res/xml/special_access.xml
+++ b/res/xml/special_access.xml
@@ -29,17 +29,6 @@
     </Preference>
 
     <Preference
-        android:key="high_power_apps"
-        android:title="@string/high_power_apps"
-        android:fragment="com.android.settings.applications.manageapplications.ManageApplications"
-        settings:keywords="@string/keywords_ignore_optimizations"
-        settings:controller="com.android.settings.applications.specialaccess.HighPowerAppsController">
-        <extra
-            android:name="classname"
-            android:value="com.android.settings.Settings$HighPowerApplicationsActivity" />
-    </Preference>
-
-    <Preference
         android:key="interact_across_profiles"
         android:title="@string/interact_across_profiles_title"
         android:fragment="com.android.settings.applications.specialaccess.interactacrossprofiles.InteractAcrossProfilesSettings"
@@ -124,6 +113,16 @@
     </Preference>
 
     <Preference
+        android:key="alarms_and_reminders"
+        android:title="@string/alarms_and_reminders_title"
+        android:fragment="com.android.settings.applications.manageapplications.ManageApplications"
+        settings:keywords="@string/keywords_alarms_and_reminders">
+        <extra
+            android:name="classname"
+            android:value="com.android.settings.Settings$AlarmsAndRemindersActivity" />
+    </Preference>
+
+    <Preference
         android:key="special_app_usage_access"
         android:title="@string/usage_access"
         android:fragment="com.android.settings.applications.manageapplications.ManageApplications"
diff --git a/res/xml/transcode_settings.xml b/res/xml/transcode_settings.xml
index b142d31..c5a9763 100644
--- a/res/xml/transcode_settings.xml
+++ b/res/xml/transcode_settings.xml
@@ -35,4 +35,9 @@
         android:key="transcode_default"
         android:title="@string/transcode_default"
         settings:controller="com.android.settings.development.transcode.TranscodeDefaultOptionPreferenceController" />
+
+    <SwitchPreference
+        android:key="transcode_notification"
+        android:title="@string/transcode_notification"
+        settings:controller="com.android.settings.development.transcode.TranscodeNotificationPreferenceController" />
 </PreferenceScreen>
diff --git a/src/com/android/settings/AllInOneTetherSettings.java b/src/com/android/settings/AllInOneTetherSettings.java
index 34d723f..d41c07b 100644
--- a/src/com/android/settings/AllInOneTetherSettings.java
+++ b/src/com/android/settings/AllInOneTetherSettings.java
@@ -16,8 +16,8 @@
 
 package com.android.settings;
 
-import static android.net.ConnectivityManager.ACTION_TETHER_STATE_CHANGED;
 import static android.net.ConnectivityManager.TETHERING_WIFI;
+import static android.net.TetheringManager.ACTION_TETHER_STATE_CHANGED;
 import static android.net.wifi.WifiManager.WIFI_AP_STATE_CHANGED_ACTION;
 
 import android.app.settings.SettingsEnums;
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index 1008888..f351d26 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -204,6 +204,10 @@
     public static class ManagedProfileSettingsActivity extends SettingsActivity { /* empty */ }
     public static class DeletionHelperActivity extends SettingsActivity { /* empty */ }
 
+    /** Actviity to manage apps with {@link android.Manifest.permission#SCHEDULE_EXACT_ALARM} */
+    public static class AlarmsAndRemindersActivity extends SettingsActivity {/* empty */ }
+    /** App specific version of {@link AlarmsAndRemindersActivity} */
+    public static class AlarmsAndRemindersAppActivity extends SettingsActivity {/* empty */ }
 
     public static class ApnEditorActivity extends SettingsActivity { /* empty */ }
     public static class ChooseAccountActivity extends SettingsActivity { /* empty */ }
diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java
index 2c628f6..0c1ace9 100644
--- a/src/com/android/settings/SettingsPreferenceFragment.java
+++ b/src/com/android/settings/SettingsPreferenceFragment.java
@@ -57,6 +57,8 @@
 import com.android.settingslib.search.Indexable;
 import com.android.settingslib.widget.LayoutPreference;
 
+import com.google.android.material.appbar.AppBarLayout;
+
 import java.util.UUID;
 
 /**
@@ -112,9 +114,8 @@
 
     @VisibleForTesting
     ViewGroup mPinnedHeaderFrameLayout;
-
+    private AppBarLayout mAppBarLayout;
     private LayoutPreference mHeader;
-
     private View mEmptyView;
     private LinearLayoutManager mLayoutManager;
     private ArrayMap<String, Preference> mPreferenceCache;
@@ -145,6 +146,7 @@
             Bundle savedInstanceState) {
         final View root = super.onCreateView(inflater, container, savedInstanceState);
         mPinnedHeaderFrameLayout = root.findViewById(R.id.pinned_header);
+        mAppBarLayout = getActivity().findViewById(R.id.app_bar);
         return root;
     }
 
@@ -250,7 +252,7 @@
             return;
         }
         if (mAdapter != null) {
-            mAdapter.requestHighlight(getView(), getListView());
+            mAdapter.requestHighlight(getView(), getListView(), mAppBarLayout);
         }
     }
 
diff --git a/src/com/android/settings/TetherSettings.java b/src/com/android/settings/TetherSettings.java
index 48dd218..6d98f36 100644
--- a/src/com/android/settings/TetherSettings.java
+++ b/src/com/android/settings/TetherSettings.java
@@ -167,8 +167,8 @@
         mEm = (EthernetManager) getSystemService(Context.ETHERNET_SERVICE);
         mTm = (TetheringManager) getSystemService(Context.TETHERING_SERVICE);
 
-        mUsbRegexs = mCm.getTetherableUsbRegexs();
-        mBluetoothRegexs = mCm.getTetherableBluetoothRegexs();
+        mUsbRegexs = mTm.getTetherableUsbRegexs();
+        mBluetoothRegexs = mTm.getTetherableBluetoothRegexs();
         mEthernetRegex = getContext().getResources().getString(
                 com.android.internal.R.string.config_ethernet_iface_regex);
 
@@ -251,14 +251,14 @@
         public void onReceive(Context content, Intent intent) {
             String action = intent.getAction();
             // TODO: stop using ACTION_TETHER_STATE_CHANGED and use mTetheringEventCallback instead.
-            if (action.equals(ConnectivityManager.ACTION_TETHER_STATE_CHANGED)) {
+            if (action.equals(TetheringManager.ACTION_TETHER_STATE_CHANGED)) {
                 // TODO - this should understand the interface types
                 ArrayList<String> available = intent.getStringArrayListExtra(
-                        ConnectivityManager.EXTRA_AVAILABLE_TETHER);
+                        TetheringManager.EXTRA_AVAILABLE_TETHER);
                 ArrayList<String> active = intent.getStringArrayListExtra(
-                        ConnectivityManager.EXTRA_ACTIVE_TETHER);
+                        TetheringManager.EXTRA_ACTIVE_TETHER);
                 ArrayList<String> errored = intent.getStringArrayListExtra(
-                        ConnectivityManager.EXTRA_ERRORED_TETHER);
+                        TetheringManager.EXTRA_ERRORED_TETHER);
                 updateState(available.toArray(new String[available.size()]),
                         active.toArray(new String[active.size()]),
                         errored.toArray(new String[errored.size()]));
@@ -345,7 +345,7 @@
         final Activity activity = getActivity();
 
         mTetherChangeReceiver = new TetherChangeReceiver();
-        IntentFilter filter = new IntentFilter(ConnectivityManager.ACTION_TETHER_STATE_CHANGED);
+        IntentFilter filter = new IntentFilter(TetheringManager.ACTION_TETHER_STATE_CHANGED);
         final Intent intent = activity.registerReceiver(mTetherChangeReceiver, filter);
 
         filter = new IntentFilter();
@@ -367,11 +367,10 @@
     }
 
     private void updateState() {
-        final ConnectivityManager cm =
-                (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
-        final String[] available = cm.getTetherableIfaces();
-        final String[] tethered = cm.getTetheredIfaces();
-        final String[] errored = cm.getTetheringErroredIfaces();
+        final TetheringManager tm = getContext().getSystemService(TetheringManager.class);
+        final String[] available = tm.getTetherableIfaces();
+        final String[] tethered = tm.getTetheredIfaces();
+        final String[] errored = tm.getTetheringErroredIfaces();
         updateState(available, tethered, errored);
     }
 
@@ -391,7 +390,7 @@
             for (String regex : mUsbRegexs) {
                 if (s.matches(regex)) {
                     if (usbError == ConnectivityManager.TETHER_ERROR_NO_ERROR) {
-                        usbError = mCm.getLastTetherError(s);
+                        usbError = mTm.getLastTetherError(s);
                     }
                 }
             }
@@ -558,8 +557,8 @@
                 @Override
                 public List<String> getNonIndexableKeys(Context context) {
                     final List<String> keys = super.getNonIndexableKeys(context);
-                    final ConnectivityManager cm =
-                            context.getSystemService(ConnectivityManager.class);
+                    final TetheringManager tm =
+                            context.getSystemService(TetheringManager.class);
 
                     if (!TetherUtil.isTetherAvailable(context)) {
                         keys.add(KEY_TETHER_PREFS_SCREEN);
@@ -567,13 +566,13 @@
                     }
 
                     final boolean usbAvailable =
-                            cm.getTetherableUsbRegexs().length != 0;
+                            tm.getTetherableUsbRegexs().length != 0;
                     if (!usbAvailable || Utils.isMonkeyRunning()) {
                         keys.add(KEY_USB_TETHER_SETTINGS);
                     }
 
                     final boolean bluetoothAvailable =
-                            cm.getTetherableBluetoothRegexs().length != 0;
+                            tm.getTetherableBluetoothRegexs().length != 0;
                     if (!bluetoothAvailable) {
                         keys.add(KEY_ENABLE_BLUETOOTH_TETHERING);
                     }
diff --git a/src/com/android/settings/accessibility/AccessibilityServiceWarning.java b/src/com/android/settings/accessibility/AccessibilityServiceWarning.java
index 2206e81..dcf7897 100644
--- a/src/com/android/settings/accessibility/AccessibilityServiceWarning.java
+++ b/src/com/android/settings/accessibility/AccessibilityServiceWarning.java
@@ -35,6 +35,7 @@
 import android.widget.TextView;
 import android.widget.Toast;
 
+import androidx.annotation.NonNull;
 import androidx.appcompat.app.AlertDialog;
 import androidx.core.content.ContextCompat;
 
@@ -60,11 +61,19 @@
         return false;
     };
 
+    /**
+     * The interface to execute the uninstallation action.
+     */
+    interface UninstallActionPerformer {
+        void uninstallPackage();
+    }
+
     /** Returns a {@link Dialog} to be shown to confirm that they want to enable a service. */
-    public static Dialog createCapabilitiesDialog(Context context,
-            AccessibilityServiceInfo info, View.OnClickListener listener) {
+    public static Dialog createCapabilitiesDialog(@NonNull Context context,
+            @NonNull AccessibilityServiceInfo info, @NonNull View.OnClickListener listener,
+            @NonNull UninstallActionPerformer performer) {
         final AlertDialog ad = new AlertDialog.Builder(context)
-                .setView(createEnableDialogContentView(context, info, listener))
+                .setView(createEnableDialogContentView(context, info, listener, performer))
                 .create();
 
         Window window = ad.getWindow();
@@ -88,7 +97,8 @@
     }
 
     private static View createEnableDialogContentView(Context context,
-            AccessibilityServiceInfo info, View.OnClickListener listener) {
+            @NonNull AccessibilityServiceInfo info, View.OnClickListener listener,
+            UninstallActionPerformer performer) {
         LayoutInflater inflater = (LayoutInflater) context.getSystemService(
                 Context.LAYOUT_INFLATER_SERVICE);
 
@@ -129,6 +139,14 @@
         permissionAllowButton.setOnTouchListener(filterTouchListener);
         permissionDenyButton.setOnClickListener(listener);
 
+        final Button uninstallButton = content.findViewById(
+                R.id.permission_enable_uninstall_button);
+        // Shows an uninstall button to help users quickly remove the non-system App due to the
+        // required permissions.
+        if (!AccessibilityUtil.isSystemApp(info)) {
+            uninstallButton.setVisibility(View.VISIBLE);
+            uninstallButton.setOnClickListener(v -> performer.uninstallPackage());
+        }
         return content;
     }
 
diff --git a/src/com/android/settings/accessibility/AccessibilityUtil.java b/src/com/android/settings/accessibility/AccessibilityUtil.java
index eb202b5..f547209 100644
--- a/src/com/android/settings/accessibility/AccessibilityUtil.java
+++ b/src/com/android/settings/accessibility/AccessibilityUtil.java
@@ -381,4 +381,13 @@
         return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, screenHeightDp,
                 resources.getDisplayMetrics()));
     }
+
+    /**
+     * Indicates if the accessibility service belongs to a system App.
+     * @param info AccessibilityServiceInfo
+     * @return {@code true} if the App is a system App.
+     */
+    public static boolean isSystemApp(@NonNull AccessibilityServiceInfo info) {
+        return info.getResolveInfo().serviceInfo.applicationInfo.isSystemApp();
+    }
 }
diff --git a/src/com/android/settings/accessibility/InvisibleToggleAccessibilityServicePreferenceFragment.java b/src/com/android/settings/accessibility/InvisibleToggleAccessibilityServicePreferenceFragment.java
index 6b44a0a..0c1876f 100644
--- a/src/com/android/settings/accessibility/InvisibleToggleAccessibilityServicePreferenceFragment.java
+++ b/src/com/android/settings/accessibility/InvisibleToggleAccessibilityServicePreferenceFragment.java
@@ -38,7 +38,7 @@
     @Override
     protected void onInstallSwitchPreferenceToggleSwitch() {
         super.onInstallSwitchPreferenceToggleSwitch();
-        mToggleServiceDividerSwitchPreference.setVisible(false);
+        mToggleServiceSwitchPreference.setVisible(false);
     }
 
     /**
diff --git a/src/com/android/settings/accessibility/LaunchAccessibilityActivityPreferenceFragment.java b/src/com/android/settings/accessibility/LaunchAccessibilityActivityPreferenceFragment.java
index b2c3c4d..4db7857 100644
--- a/src/com/android/settings/accessibility/LaunchAccessibilityActivityPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/LaunchAccessibilityActivityPreferenceFragment.java
@@ -36,15 +36,14 @@
 import android.view.accessibility.AccessibilityManager;
 
 import androidx.annotation.Nullable;
-import androidx.preference.SwitchPreference;
 
 import com.android.settings.R;
+import com.android.settings.widget.SettingsMainSwitchPreference;
 
 import java.util.List;
 
 /** Fragment for providing open activity button. */
-public class LaunchAccessibilityActivityPreferenceFragment extends
-        ToggleFeaturePreferenceFragment {
+public class LaunchAccessibilityActivityPreferenceFragment extends ToggleFeaturePreferenceFragment {
     private static final String TAG = "LaunchA11yActivity";
     private static final String EMPTY_STRING = "";
 
@@ -52,7 +51,7 @@
     public void onViewCreated(View view, Bundle savedInstanceState) {
         super.onViewCreated(view, savedInstanceState);
 
-        mToggleServiceDividerSwitchPreference.setSwitchVisibility(View.GONE);
+        mToggleServiceSwitchPreference.hide();
     }
 
     @Override
@@ -62,16 +61,6 @@
     }
 
     @Override
-    protected void onInstallSwitchPreferenceToggleSwitch() {
-        super.onInstallSwitchPreferenceToggleSwitch();
-        mToggleServiceDividerSwitchPreference.setOnPreferenceClickListener((preference) -> {
-            final boolean checked = ((DividerSwitchPreference) preference).isChecked();
-            onPreferenceToggled(mPreferenceKey, checked);
-            return false;
-        });
-    }
-
-    @Override
     protected void onProcessArguments(Bundle arguments) {
         super.onProcessArguments(arguments);
 
@@ -111,7 +100,7 @@
     }
 
     @Override
-    protected void updateToggleServiceTitle(SwitchPreference switchPreference) {
+    protected void updateToggleServiceTitle(SettingsMainSwitchPreference switchPreference) {
         final AccessibilityShortcutInfo info = getAccessibilityShortcutInfo();
         final String switchBarText = (info == null) ? EMPTY_STRING : getString(
                 R.string.accessibility_service_primary_open_title,
diff --git a/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java
index 04491cc..7902ec6 100644
--- a/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java
@@ -24,10 +24,14 @@
 import android.app.Dialog;
 import android.app.admin.DevicePolicyManager;
 import android.app.settings.SettingsEnums;
+import android.content.BroadcastReceiver;
 import android.content.ComponentName;
 import android.content.ContentResolver;
+import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.ApplicationInfo;
 import android.content.pm.ResolveInfo;
 import android.content.pm.ServiceInfo;
 import android.net.Uri;
@@ -37,18 +41,21 @@
 import android.os.storage.StorageManager;
 import android.provider.Settings;
 import android.text.TextUtils;
+import android.util.Log;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.View;
 import android.view.accessibility.AccessibilityManager;
+import android.widget.Switch;
 
+import androidx.annotation.Nullable;
 import androidx.preference.Preference;
-import androidx.preference.SwitchPreference;
 
 import com.android.internal.widget.LockPatternUtils;
 import com.android.settings.R;
 import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
 import com.android.settings.password.ConfirmDeviceCredentialActivity;
+import com.android.settings.widget.SettingsMainSwitchPreference;
 import com.android.settingslib.accessibility.AccessibilityUtils;
 
 import java.util.List;
@@ -58,7 +65,8 @@
 public class ToggleAccessibilityServicePreferenceFragment extends
         ToggleFeaturePreferenceFragment {
 
-    public static final int ACTIVITY_REQUEST_CONFIRM_CREDENTIAL_FOR_WEAKER_ENCRYPTION = 1;
+    private static final String TAG = "ToggleAccessibilityServicePreferenceFragment";
+    private static final int ACTIVITY_REQUEST_CONFIRM_CREDENTIAL_FOR_WEAKER_ENCRYPTION = 1;
     private LockPatternUtils mLockPatternUtils;
     private AtomicBoolean mIsDialogShown = new AtomicBoolean(/* initialValue= */ false);
 
@@ -73,6 +81,7 @@
             };
 
     private Dialog mDialog;
+    private BroadcastReceiver mPackageRemovedReceiver;
 
     @Override
     public int getMetricsCategory() {
@@ -93,6 +102,17 @@
     }
 
     @Override
+    public void onStart() {
+        super.onStart();
+        final AccessibilityServiceInfo serviceInfo = getAccessibilityServiceInfo();
+        if (serviceInfo == null) {
+            getActivity().finishAndRemoveTask();
+        } else if (!AccessibilityUtil.isSystemApp(serviceInfo)) {
+            registerPackageRemoveReceiver();
+        }
+    }
+
+    @Override
     public void onResume() {
         super.onResume();
         updateSwitchBarToggleSwitch();
@@ -110,6 +130,7 @@
     // capabilities. For
     // example, before JellyBean MR2 the user was granting the explore by touch
     // one.
+    @Nullable
     AccessibilityServiceInfo getAccessibilityServiceInfo() {
         final List<AccessibilityServiceInfo> infos = AccessibilityManager.getInstance(
                 getPrefContext()).getInstalledAccessibilityServiceList();
@@ -135,7 +156,8 @@
                 }
                 mDialog = AccessibilityServiceWarning
                         .createCapabilitiesDialog(getPrefContext(), info,
-                                this::onDialogButtonFromEnableToggleClicked);
+                                this::onDialogButtonFromEnableToggleClicked,
+                                this::onDialogButtonFromUninstallClicked);
                 break;
             }
             case DialogEnums.ENABLE_WARNING_FROM_SHORTCUT_TOGGLE: {
@@ -145,7 +167,8 @@
                 }
                 mDialog = AccessibilityServiceWarning
                         .createCapabilitiesDialog(getPrefContext(), info,
-                                this::onDialogButtonFromShortcutToggleClicked);
+                                this::onDialogButtonFromShortcutToggleClicked,
+                                this::onDialogButtonFromUninstallClicked);
                 break;
             }
             case DialogEnums.ENABLE_WARNING_FROM_SHORTCUT: {
@@ -155,7 +178,8 @@
                 }
                 mDialog = AccessibilityServiceWarning
                         .createCapabilitiesDialog(getPrefContext(), info,
-                                this::onDialogButtonFromShortcutClicked);
+                                this::onDialogButtonFromShortcutClicked,
+                                this::onDialogButtonFromUninstallClicked);
                 break;
             }
             case DialogEnums.DISABLE_WARNING_FROM_TOGGLE: {
@@ -198,7 +222,7 @@
     }
 
     @Override
-    protected void updateToggleServiceTitle(SwitchPreference switchPreference) {
+    protected void updateToggleServiceTitle(SettingsMainSwitchPreference switchPreference) {
         final AccessibilityServiceInfo info = getAccessibilityServiceInfo();
         final String switchBarText = (info == null) ? "" :
                 getString(R.string.accessibility_service_primary_switch_title,
@@ -206,13 +230,14 @@
         switchPreference.setTitle(switchBarText);
     }
 
-    private void updateSwitchBarToggleSwitch() {
+    @Override
+    protected void updateSwitchBarToggleSwitch() {
         final boolean checked = AccessibilityUtils.getEnabledServicesFromSettings(getPrefContext())
                 .contains(mComponentName);
-        if (mToggleServiceDividerSwitchPreference.isChecked() == checked) {
+        if (mToggleServiceSwitchPreference.isChecked() == checked) {
             return;
         }
-        mToggleServiceDividerSwitchPreference.setChecked(checked);
+        mToggleServiceSwitchPreference.setChecked(checked);
     }
 
     /**
@@ -244,6 +269,32 @@
         }
     }
 
+    private void registerPackageRemoveReceiver() {
+        if (mPackageRemovedReceiver != null || getContext() == null) {
+            return;
+        }
+        mPackageRemovedReceiver = new BroadcastReceiver() {
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                final String packageName = intent.getData().getSchemeSpecificPart();
+                if (TextUtils.equals(mComponentName.getPackageName(), packageName)) {
+                    getActivity().finishAndRemoveTask();
+                }
+            }
+        };
+        final IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_REMOVED);
+        filter.addDataScheme("package");
+        getContext().registerReceiver(mPackageRemovedReceiver, filter);
+    }
+
+    private void unregisterPackageRemoveReceiver() {
+        if (mPackageRemovedReceiver == null || getContext() == null) {
+            return;
+        }
+        getContext().unregisterReceiver(mPackageRemovedReceiver);
+        mPackageRemovedReceiver = null;
+    }
+
     private boolean isServiceSupportAccessibilityButton() {
         final AccessibilityManager ams = getPrefContext().getSystemService(
                 AccessibilityManager.class);
@@ -263,7 +314,7 @@
     }
 
     private void handleConfirmServiceEnabled(boolean confirmed) {
-        mToggleServiceDividerSwitchPreference.setChecked(confirmed);
+        mToggleServiceSwitchPreference.setChecked(confirmed);
         getArguments().putBoolean(AccessibilitySettings.EXTRA_CHECKED, confirmed);
         onPreferenceToggled(mPreferenceKey, confirmed);
     }
@@ -286,9 +337,10 @@
     }
 
     @Override
-    protected void onInstallSwitchPreferenceToggleSwitch() {
-        super.onInstallSwitchPreferenceToggleSwitch();
-        mToggleServiceDividerSwitchPreference.setOnPreferenceClickListener(this::onPreferenceClick);
+    public void onSwitchChanged(Switch switchView, boolean isChecked) {
+        if (isChecked != mToggleServiceSwitchPreference.isChecked()) {
+            onPreferenceClick(mToggleServiceSwitchPreference);
+        }
     }
 
     @Override
@@ -296,7 +348,7 @@
         final int shortcutTypes = retrieveUserShortcutType(getPrefContext(),
                 mComponentName.flattenToString(), UserShortcutType.SOFTWARE);
         if (preference.isChecked()) {
-            if (!mToggleServiceDividerSwitchPreference.isChecked()) {
+            if (!mToggleServiceSwitchPreference.isChecked()) {
                 preference.setChecked(false);
                 showPopupDialog(DialogEnums.ENABLE_WARNING_FROM_SHORTCUT_TOGGLE);
             } else {
@@ -314,7 +366,7 @@
     @Override
     public void onSettingsClicked(ShortcutPreference preference) {
         final boolean isServiceOnOrShortcutAdded = mShortcutPreference.isChecked()
-                || mToggleServiceDividerSwitchPreference.isChecked();
+                || mToggleServiceSwitchPreference.isChecked();
         showPopupDialog(isServiceOnOrShortcutAdded ? DialogEnums.EDIT_SHORTCUT
                 : DialogEnums.ENABLE_WARNING_FROM_SHORTCUT);
     }
@@ -375,6 +427,35 @@
         }
     }
 
+    private void onDialogButtonFromUninstallClicked() {
+        mDialog.dismiss();
+        final Intent uninstallIntent = createUninstallPackageActivityIntent();
+        if (uninstallIntent == null) {
+            return;
+        }
+        startActivity(uninstallIntent);
+    }
+
+    @Nullable
+    private Intent createUninstallPackageActivityIntent() {
+        final AccessibilityServiceInfo a11yServiceInfo = getAccessibilityServiceInfo();
+        if (a11yServiceInfo == null) {
+            Log.w(TAG, "createUnInstallIntent -- invalid a11yServiceInfo");
+            return null;
+        }
+        final ApplicationInfo appInfo =
+                a11yServiceInfo.getResolveInfo().serviceInfo.applicationInfo;
+        final Uri packageUri = Uri.parse("package:" + appInfo.packageName);
+        final Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri);
+        return uninstallIntent;
+    }
+
+    @Override
+    public void onStop() {
+        super.onStop();
+        unregisterPackageRemoveReceiver();
+    }
+
     private void onAllowButtonFromEnableToggleClicked() {
         if (isFullDiskEncrypted()) {
             final String title = createConfirmCredentialReasonMessage();
@@ -453,9 +534,14 @@
     }
 
     private boolean onPreferenceClick(Preference preference) {
-        boolean checked = ((DividerSwitchPreference) preference).isChecked();
+        boolean checked = ((SettingsMainSwitchPreference) preference).isChecked();
         if (checked) {
-            mToggleServiceDividerSwitchPreference.setChecked(false);
+            mToggleServiceSwitchPreference.setChecked(true);
+            getArguments().putBoolean(AccessibilitySettings.EXTRA_CHECKED,
+                    /* enableService */ true);
+            showDialog(DialogEnums.DISABLE_WARNING_FROM_TOGGLE);
+        } else {
+            mToggleServiceSwitchPreference.setChecked(false);
             getArguments().putBoolean(AccessibilitySettings.EXTRA_CHECKED,
                     /* disableService */ false);
             if (!mShortcutPreference.isChecked()) {
@@ -466,11 +552,6 @@
                     showPopupDialog(DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL);
                 }
             }
-        } else {
-            mToggleServiceDividerSwitchPreference.setChecked(true);
-            getArguments().putBoolean(AccessibilitySettings.EXTRA_CHECKED,
-                    /* enableService */ true);
-            showDialog(DialogEnums.DISABLE_WARNING_FROM_TOGGLE);
         }
         return true;
     }
diff --git a/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java
index a45cd49..7fd30c6 100644
--- a/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java
@@ -31,15 +31,15 @@
 import android.view.View;
 import android.view.ViewGroup;
 
-import androidx.preference.SwitchPreference;
-
 import com.android.settings.R;
+import com.android.settings.widget.SettingsMainSwitchPreference;
 
 import java.util.ArrayList;
 import java.util.List;
 
 /** Settings page for color inversion. */
-public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePreferenceFragment {
+public class ToggleColorInversionPreferenceFragment extends
+        ToggleFeaturePreferenceFragment {
 
     private static final String ENABLED = Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED;
     private final Handler mHandler = new Handler();
@@ -64,26 +64,15 @@
     @Override
     protected void onRemoveSwitchPreferenceToggleSwitch() {
         super.onRemoveSwitchPreferenceToggleSwitch();
-        mToggleServiceDividerSwitchPreference.setOnPreferenceClickListener(null);
+        mToggleServiceSwitchPreference.setOnPreferenceClickListener(null);
     }
 
     @Override
-    protected void updateToggleServiceTitle(SwitchPreference switchPreference) {
+    protected void updateToggleServiceTitle(SettingsMainSwitchPreference switchPreference) {
         switchPreference.setTitle(R.string.accessibility_display_inversion_switch_title);
     }
 
     @Override
-    protected void onInstallSwitchPreferenceToggleSwitch() {
-        super.onInstallSwitchPreferenceToggleSwitch();
-        updateSwitchBarToggleSwitch();
-        mToggleServiceDividerSwitchPreference.setOnPreferenceClickListener((preference) -> {
-            boolean checked = ((SwitchPreference) preference).isChecked();
-            onPreferenceToggled(mPreferenceKey, checked);
-            return false;
-        });
-    }
-
-    @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
             Bundle savedInstanceState) {
         mComponentName = COLOR_INVERSION_COMPONENT_NAME;
@@ -128,11 +117,12 @@
                 mComponentName);
     }
 
-    private void updateSwitchBarToggleSwitch() {
+    @Override
+    protected void updateSwitchBarToggleSwitch() {
         final boolean checked = Settings.Secure.getInt(getContentResolver(), ENABLED, OFF) == ON;
-        if (mToggleServiceDividerSwitchPreference.isChecked() == checked) {
+        if (mToggleServiceSwitchPreference.isChecked() == checked) {
             return;
         }
-        mToggleServiceDividerSwitchPreference.setChecked(checked);
+        mToggleServiceSwitchPreference.setChecked(checked);
     }
 }
diff --git a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
index 3fb9b38..c12884b 100644
--- a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
@@ -33,11 +33,10 @@
 import android.view.ViewGroup;
 
 import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
-import androidx.preference.SwitchPreference;
 
 import com.android.settings.R;
 import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.widget.SettingsMainSwitchPreference;
 import com.android.settingslib.core.AbstractPreferenceController;
 import com.android.settingslib.core.lifecycle.Lifecycle;
 import com.android.settingslib.search.SearchIndexable;
@@ -99,34 +98,19 @@
     @Override
     public void onViewCreated(View view, Bundle savedInstanceState) {
         super.onViewCreated(view, savedInstanceState);
-        updatePreferenceOrder();
     }
 
     /** Customizes the order by preference key. */
-    private List<String> getPreferenceOrderList() {
-        List<String> lists = new ArrayList<>();
-        lists.add(KEY_PREVIEW);
+    protected List<String> getPreferenceOrderList() {
+        final List<String> lists = new ArrayList<>();
         lists.add(KEY_USE_SERVICE_PREFERENCE);
+        lists.add(KEY_PREVIEW);
         lists.add(KEY_CATEGORY_MODE);
         lists.add(KEY_GENERAL_CATEGORY);
         lists.add(KEY_INTRODUCTION_CATEGORY);
         return lists;
     }
 
-    private void updatePreferenceOrder() {
-        List<String> lists = getPreferenceOrderList();
-        final PreferenceScreen preferenceScreen = getPreferenceScreen();
-        preferenceScreen.setOrderingAsAdded(false);
-
-        final int size = lists.size();
-        for (int i = 0; i < size; i++) {
-            final Preference preference = preferenceScreen.findPreference(lists.get(i));
-            if (preference != null) {
-                preference.setOrder(i);
-            }
-        }
-    }
-
     @Override
     public void onResume() {
         super.onResume();
@@ -175,37 +159,27 @@
     @Override
     protected void onRemoveSwitchPreferenceToggleSwitch() {
         super.onRemoveSwitchPreferenceToggleSwitch();
-        mToggleServiceDividerSwitchPreference.setOnPreferenceClickListener(null);
+        mToggleServiceSwitchPreference.setOnPreferenceClickListener(null);
     }
 
     @Override
-    protected void updateToggleServiceTitle(SwitchPreference switchPreference) {
+    protected void updateToggleServiceTitle(SettingsMainSwitchPreference switchPreference) {
         switchPreference.setTitle(R.string.accessibility_daltonizer_primary_switch_title);
     }
 
     @Override
-    protected void onInstallSwitchPreferenceToggleSwitch() {
-        super.onInstallSwitchPreferenceToggleSwitch();
-        updateSwitchBarToggleSwitch();
-        mToggleServiceDividerSwitchPreference.setOnPreferenceClickListener((preference) -> {
-            boolean checked = ((SwitchPreference) preference).isChecked();
-            onPreferenceToggled(mPreferenceKey, checked);
-            return false;
-        });
-    }
-
-    @Override
     int getUserShortcutTypes() {
         return AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(),
                 mComponentName);
     }
 
-    private void updateSwitchBarToggleSwitch() {
+    @Override
+    protected void updateSwitchBarToggleSwitch() {
         final boolean checked = Settings.Secure.getInt(getContentResolver(), ENABLED, OFF) == ON;
-        if (mToggleServiceDividerSwitchPreference.isChecked() == checked) {
+        if (mToggleServiceSwitchPreference.isChecked() == checked) {
             return;
         }
-        mToggleServiceDividerSwitchPreference.setChecked(checked);
+        mToggleServiceSwitchPreference.setChecked(checked);
     }
 
     public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
diff --git a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
index 87d07a8..ec22a28 100644
--- a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
@@ -40,20 +40,22 @@
 import android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener;
 import android.widget.CheckBox;
 import android.widget.ImageView;
+import android.widget.Switch;
 
 import androidx.annotation.VisibleForTesting;
 import androidx.preference.Preference;
 import androidx.preference.PreferenceCategory;
 import androidx.preference.PreferenceScreen;
-import androidx.preference.SwitchPreference;
 
 import com.android.settings.R;
 import com.android.settings.SettingsActivity;
 import com.android.settings.SettingsPreferenceFragment;
 import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
 import com.android.settings.widget.SettingsMainSwitchBar;
+import com.android.settings.widget.SettingsMainSwitchPreference;
 import com.android.settingslib.accessibility.AccessibilityUtils;
 import com.android.settingslib.widget.FooterPreference;
+import com.android.settingslib.widget.OnMainSwitchChangeListener;
 
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
@@ -66,9 +68,9 @@
  * and dialog management.
  */
 public abstract class ToggleFeaturePreferenceFragment extends SettingsPreferenceFragment
-        implements ShortcutPreference.OnClickCallback {
+        implements ShortcutPreference.OnClickCallback, OnMainSwitchChangeListener {
 
-    protected DividerSwitchPreference mToggleServiceDividerSwitchPreference;
+    protected SettingsMainSwitchPreference mToggleServiceSwitchPreference;
     protected ShortcutPreference mShortcutPreference;
     protected Preference mSettingsPreference;
     protected String mPreferenceKey;
@@ -88,6 +90,7 @@
     protected static final String KEY_INTRODUCTION_CATEGORY = "introduction_categories";
     private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
     protected static final String KEY_SAVED_USER_SHORTCUT_TYPE = "shortcut_type";
+    protected static final String KEY_ANIMATED_IMAGE = "animated_image";
 
     private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener;
     private SettingsContentObserver mSettingsContentObserver;
@@ -153,7 +156,7 @@
         onProcessArguments(getArguments());
 
         initAnimatedImagePreference();
-        initToggleServiceDividerSwitchPreference();
+        initToggleServiceSwitchPreference();
         initGeneralCategory();
         initShortcutPreference();
         initSettingsPreference();
@@ -162,7 +165,7 @@
 
         installActionBarToggleSwitch();
 
-        updateToggleServiceTitle(mToggleServiceDividerSwitchPreference);
+        updateToggleServiceTitle(mToggleServiceSwitchPreference);
 
         mTouchExplorationStateChangeListener = isTouchExplorationEnabled -> {
             removeDialog(DialogEnums.EDIT_SHORTCUT);
@@ -178,6 +181,8 @@
         final SettingsActivity activity = (SettingsActivity) getActivity();
         final SettingsMainSwitchBar switchBar = activity.getSwitchBar();
         switchBar.hide();
+
+        updatePreferenceOrder();
     }
 
     @Override
@@ -305,12 +310,17 @@
         removeActionBarToggleSwitch();
     }
 
+    @Override
+    public void onSwitchChanged(Switch switchView, boolean isChecked) {
+        onPreferenceToggled(mPreferenceKey, isChecked);
+    }
+
     /**
      * Returns the shortcut type list which has been checked by user.
      */
     abstract int getUserShortcutTypes();
 
-    protected void updateToggleServiceTitle(SwitchPreference switchPreference) {
+    protected void updateToggleServiceTitle(SettingsMainSwitchPreference switchPreference) {
         switchPreference.setTitle(R.string.accessibility_service_primary_switch_title);
     }
 
@@ -318,18 +328,24 @@
 
     protected void onInstallSwitchPreferenceToggleSwitch() {
         // Implement this to set a checked listener.
+        updateSwitchBarToggleSwitch();
+        mToggleServiceSwitchPreference.addOnSwitchChangeListener(this);
     }
 
     protected void onRemoveSwitchPreferenceToggleSwitch() {
         // Implement this to reset a checked listener.
     }
 
+    protected void updateSwitchBarToggleSwitch() {
+        // Implement this to update the state of switch.
+    }
+
     private void installActionBarToggleSwitch() {
         onInstallSwitchPreferenceToggleSwitch();
     }
 
     private void removeActionBarToggleSwitch() {
-        mToggleServiceDividerSwitchPreference.setOnPreferenceClickListener(null);
+        mToggleServiceSwitchPreference.setOnPreferenceClickListener(null);
         onRemoveSwitchPreferenceToggleSwitch();
     }
 
@@ -361,6 +377,31 @@
         }
     }
 
+    /** Customizes the order by preference key. */
+    protected List<String> getPreferenceOrderList() {
+        final List<String> lists = new ArrayList<>();
+        lists.add(KEY_USE_SERVICE_PREFERENCE);
+        lists.add(KEY_ANIMATED_IMAGE);
+        lists.add(KEY_GENERAL_CATEGORY);
+        lists.add(KEY_INTRODUCTION_CATEGORY);
+        return lists;
+    }
+
+    private void updatePreferenceOrder() {
+        final List<String> lists = getPreferenceOrderList();
+
+        final PreferenceScreen preferenceScreen = getPreferenceScreen();
+        preferenceScreen.setOrderingAsAdded(false);
+
+        final int size = lists.size();
+        for (int i = 0; i < size; i++) {
+            final Preference preference = preferenceScreen.findPreference(lists.get(i));
+            if (preference != null) {
+                preference.setOrder(i);
+            }
+        }
+    }
+
     private Drawable getDrawableFromUri(Uri imageUri) {
         if (mImageGetterCacheView == null) {
             mImageGetterCacheView = new ImageView(getPrefContext());
@@ -401,19 +442,20 @@
         animatedImagePreference.setImageUri(mImageUri);
         animatedImagePreference.setSelectable(false);
         animatedImagePreference.setMaxHeight(screenHalfHeight);
+        animatedImagePreference.setKey(KEY_ANIMATED_IMAGE);
 
         getPreferenceScreen().addPreference(animatedImagePreference);
     }
 
-    private void initToggleServiceDividerSwitchPreference() {
-        mToggleServiceDividerSwitchPreference = new DividerSwitchPreference(getPrefContext());
-        mToggleServiceDividerSwitchPreference.setKey(KEY_USE_SERVICE_PREFERENCE);
+    private void initToggleServiceSwitchPreference() {
+        mToggleServiceSwitchPreference = new SettingsMainSwitchPreference(getPrefContext());
+        mToggleServiceSwitchPreference.setKey(KEY_USE_SERVICE_PREFERENCE);
         if (getArguments().containsKey(AccessibilitySettings.EXTRA_CHECKED)) {
             final boolean enabled = getArguments().getBoolean(AccessibilitySettings.EXTRA_CHECKED);
-            mToggleServiceDividerSwitchPreference.setChecked(enabled);
+            mToggleServiceSwitchPreference.setChecked(enabled);
         }
 
-        getPreferenceScreen().addPreference(mToggleServiceDividerSwitchPreference);
+        getPreferenceScreen().addPreference(mToggleServiceSwitchPreference);
     }
 
     private void initGeneralCategory() {
@@ -598,7 +640,7 @@
      * This method will be invoked when a button in the edit shortcut dialog is clicked.
      *
      * @param dialog The dialog that received the click
-     * @param which The button that was clicked
+     * @param which  The button that was clicked
      */
     protected void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) {
         if (mComponentName == null) {
@@ -676,7 +718,7 @@
     }
 
     /**
-     *  Setups a configurable default if the setting has never been set.
+     * Setups a configurable default if the setting has never been set.
      */
     private static void setupDefaultShortcutIfNecessary(Context context) {
         final String targetKey = Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE;
diff --git a/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
index ca19681..09690d9 100644
--- a/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
@@ -29,13 +29,10 @@
 import android.view.View;
 import android.view.ViewGroup;
 
-import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
-import androidx.preference.SwitchPreference;
-
 import com.android.internal.accessibility.AccessibilityShortcutController;
 import com.android.settings.R;
 import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.widget.SettingsMainSwitchPreference;
 import com.android.settingslib.search.SearchIndexable;
 
 import java.util.ArrayList;
@@ -44,6 +41,7 @@
 /** Settings for reducing brightness. */
 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
 public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePreferenceFragment {
+
     private static final String REDUCE_BRIGHT_COLORS_ACTIVATED_KEY =
             Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED;
     private static final String KEY_INTENSITY = "rbc_intensity";
@@ -73,7 +71,7 @@
         mSettingsContentObserver = new SettingsContentObserver(mHandler, enableServiceFeatureKeys) {
             @Override
             public void onChange(boolean selfChange, Uri uri) {
-                    updateSwitchBarToggleSwitch();
+                updateSwitchBarToggleSwitch();
             }
         };
 
@@ -83,11 +81,10 @@
     @Override
     public void onViewCreated(View view, Bundle savedInstanceState) {
         super.onViewCreated(view, savedInstanceState);
-        updatePreferenceOrder();
     }
 
     /** Customizes the order by preference key. */
-    private List<String> getPreferenceOrderList() {
+    protected List<String> getPreferenceOrderList() {
         final List<String> lists = new ArrayList<>();
         lists.add(KEY_USE_SERVICE_PREFERENCE);
         lists.add(KEY_INTENSITY);
@@ -97,20 +94,6 @@
         return lists;
     }
 
-    private void updatePreferenceOrder() {
-        final List<String> lists = getPreferenceOrderList();
-        final PreferenceScreen preferenceScreen = getPreferenceScreen();
-        preferenceScreen.setOrderingAsAdded(false);
-
-        final int size = lists.size();
-        for (int i = 0; i < size; i++) {
-            final Preference preference = preferenceScreen.findPreference(lists.get(i));
-            if (preference != null) {
-                preference.setOrder(i);
-            }
-        }
-    }
-
     @Override
     public void onResume() {
         super.onResume();
@@ -151,41 +134,31 @@
     @Override
     protected void onRemoveSwitchPreferenceToggleSwitch() {
         super.onRemoveSwitchPreferenceToggleSwitch();
-        mToggleServiceDividerSwitchPreference.setOnPreferenceClickListener(
+        mToggleServiceSwitchPreference.setOnPreferenceClickListener(
                 /* onPreferenceClickListener= */ null);
     }
 
     @Override
-    protected void updateToggleServiceTitle(SwitchPreference switchPreference) {
+    protected void updateToggleServiceTitle(SettingsMainSwitchPreference switchPreference) {
         switchPreference.setTitle(R.string.reduce_bright_colors_preference_title);
     }
 
     @Override
-    protected void onInstallSwitchPreferenceToggleSwitch() {
-        super.onInstallSwitchPreferenceToggleSwitch();
-        updateSwitchBarToggleSwitch();
-        mToggleServiceDividerSwitchPreference.setOnPreferenceClickListener((preference) -> {
-            boolean checked = ((SwitchPreference) preference).isChecked();
-            onPreferenceToggled(mPreferenceKey, checked);
-            return false;
-        });
-    }
-
-    @Override
     int getUserShortcutTypes() {
         return AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(),
                 mComponentName);
     }
 
-    private void updateSwitchBarToggleSwitch() {
+    @Override
+    protected void updateSwitchBarToggleSwitch() {
         final boolean checked = Settings.Secure.getInt(getContentResolver(),
                 REDUCE_BRIGHT_COLORS_ACTIVATED_KEY, OFF) == ON;
         mRbcIntensityPreferenceController.updateState(getPreferenceScreen()
                 .findPreference(KEY_INTENSITY));
         mRbcPersistencePreferenceController.updateState(getPreferenceScreen()
                 .findPreference(KEY_PERSIST));
-        if (mToggleServiceDividerSwitchPreference.isChecked() != checked) {
-            mToggleServiceDividerSwitchPreference.setChecked(checked);
+        if (mToggleServiceSwitchPreference.isChecked() != checked) {
+            mToggleServiceSwitchPreference.setChecked(checked);
         }
     }
 
diff --git a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
index 8e14e5a..ff46722 100644
--- a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
@@ -304,8 +304,7 @@
 
     @Override
     protected void onInstallSwitchPreferenceToggleSwitch() {
-        super.onInstallSwitchPreferenceToggleSwitch();
-        mToggleServiceDividerSwitchPreference.setVisible(false);
+        mToggleServiceSwitchPreference.setVisible(false);
     }
 
     @Override
diff --git a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentForSetupWizard.java b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentForSetupWizard.java
index bea528a..86ead5c 100644
--- a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentForSetupWizard.java
+++ b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentForSetupWizard.java
@@ -33,12 +33,12 @@
         // Log the final choice in value if it's different from the previous value.
         Bundle args = getArguments();
         if ((args != null) && args.containsKey(AccessibilitySettings.EXTRA_CHECKED)) {
-            if (mToggleServiceDividerSwitchPreference.isChecked() != args.getBoolean(
+            if (mToggleServiceSwitchPreference.isChecked() != args.getBoolean(
                     AccessibilitySettings.EXTRA_CHECKED)) {
                 // TODO: Distinguish between magnification modes
                 mMetricsFeatureProvider.action(getContext(),
                         SettingsEnums.SUW_ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFICATION,
-                        mToggleServiceDividerSwitchPreference.isChecked());
+                        mToggleServiceSwitchPreference.isChecked());
             }
         }
         super.onStop();
diff --git a/src/com/android/settings/accessibility/ToggleScreenReaderPreferenceFragmentForSetupWizard.java b/src/com/android/settings/accessibility/ToggleScreenReaderPreferenceFragmentForSetupWizard.java
index 4d7b653..c0d54e8 100644
--- a/src/com/android/settings/accessibility/ToggleScreenReaderPreferenceFragmentForSetupWizard.java
+++ b/src/com/android/settings/accessibility/ToggleScreenReaderPreferenceFragmentForSetupWizard.java
@@ -28,7 +28,7 @@
     @Override
     public void onViewCreated(View view, Bundle savedInstanceState) {
         super.onViewCreated(view, savedInstanceState);
-        mToggleSwitchWasInitiallyChecked = mToggleServiceDividerSwitchPreference.isChecked();
+        mToggleSwitchWasInitiallyChecked = mToggleServiceSwitchPreference.isChecked();
     }
 
     @Override
@@ -39,10 +39,10 @@
     @Override
     public void onStop() {
         // Log the final choice in value if it's different from the previous value.
-        if (mToggleServiceDividerSwitchPreference.isChecked() != mToggleSwitchWasInitiallyChecked) {
+        if (mToggleServiceSwitchPreference.isChecked() != mToggleSwitchWasInitiallyChecked) {
             mMetricsFeatureProvider.action(getContext(),
                     SettingsEnums.SUW_ACCESSIBILITY_TOGGLE_SCREEN_READER,
-                    mToggleServiceDividerSwitchPreference.isChecked());
+                    mToggleServiceSwitchPreference.isChecked());
         }
         super.onStop();
     }
diff --git a/src/com/android/settings/accessibility/ToggleSelectToSpeakPreferenceFragmentForSetupWizard.java b/src/com/android/settings/accessibility/ToggleSelectToSpeakPreferenceFragmentForSetupWizard.java
index 87b8469..4334cd0 100644
--- a/src/com/android/settings/accessibility/ToggleSelectToSpeakPreferenceFragmentForSetupWizard.java
+++ b/src/com/android/settings/accessibility/ToggleSelectToSpeakPreferenceFragmentForSetupWizard.java
@@ -28,7 +28,7 @@
     @Override
     public void onViewCreated(View view, Bundle savedInstanceState) {
         super.onViewCreated(view, savedInstanceState);
-        mToggleSwitchWasInitiallyChecked = mToggleServiceDividerSwitchPreference.isChecked();
+        mToggleSwitchWasInitiallyChecked = mToggleServiceSwitchPreference.isChecked();
     }
 
     @Override
@@ -39,10 +39,10 @@
     @Override
     public void onStop() {
         // Log the final choice in value if it's different from the previous value.
-        if (mToggleServiceDividerSwitchPreference.isChecked() != mToggleSwitchWasInitiallyChecked) {
+        if (mToggleServiceSwitchPreference.isChecked() != mToggleSwitchWasInitiallyChecked) {
             mMetricsFeatureProvider.action(getContext(),
                     SettingsEnums.SUW_ACCESSIBILITY_TOGGLE_SELECT_TO_SPEAK,
-                    mToggleServiceDividerSwitchPreference.isChecked());
+                    mToggleServiceSwitchPreference.isChecked());
         }
 
         super.onStop();
diff --git a/src/com/android/settings/accessibility/VolumeShortcutToggleScreenReaderPreferenceFragmentForSetupWizard.java b/src/com/android/settings/accessibility/VolumeShortcutToggleScreenReaderPreferenceFragmentForSetupWizard.java
index 6e4a233..4337177 100644
--- a/src/com/android/settings/accessibility/VolumeShortcutToggleScreenReaderPreferenceFragmentForSetupWizard.java
+++ b/src/com/android/settings/accessibility/VolumeShortcutToggleScreenReaderPreferenceFragmentForSetupWizard.java
@@ -29,7 +29,7 @@
     @Override
     public void onViewCreated(View view, Bundle savedInstanceState) {
         super.onViewCreated(view, savedInstanceState);
-        mToggleSwitchWasInitiallyChecked = mToggleServiceDividerSwitchPreference.isChecked();
+        mToggleSwitchWasInitiallyChecked = mToggleServiceSwitchPreference.isChecked();
     }
 
     @Override
@@ -40,10 +40,10 @@
     @Override
     public void onStop() {
         // Log the final choice in value if it's different from the previous value.
-        if (mToggleServiceDividerSwitchPreference.isChecked() != mToggleSwitchWasInitiallyChecked) {
+        if (mToggleServiceSwitchPreference.isChecked() != mToggleSwitchWasInitiallyChecked) {
             mMetricsFeatureProvider.action(getContext(),
                     SettingsEnums.SUW_ACCESSIBILITY_TOGGLE_SCREEN_READER,
-                    mToggleServiceDividerSwitchPreference.isChecked());
+                    mToggleServiceSwitchPreference.isChecked());
         }
 
         super.onStop();
diff --git a/src/com/android/settings/accessibility/VolumeShortcutToggleSelectToSpeakPreferenceFragmentForSetupWizard.java b/src/com/android/settings/accessibility/VolumeShortcutToggleSelectToSpeakPreferenceFragmentForSetupWizard.java
index 3dd648c..acdfdc9 100644
--- a/src/com/android/settings/accessibility/VolumeShortcutToggleSelectToSpeakPreferenceFragmentForSetupWizard.java
+++ b/src/com/android/settings/accessibility/VolumeShortcutToggleSelectToSpeakPreferenceFragmentForSetupWizard.java
@@ -29,7 +29,7 @@
     @Override
     public void onViewCreated(View view, Bundle savedInstanceState) {
         super.onViewCreated(view, savedInstanceState);
-        mToggleSwitchWasInitiallyChecked = mToggleServiceDividerSwitchPreference.isChecked();
+        mToggleSwitchWasInitiallyChecked = mToggleServiceSwitchPreference.isChecked();
     }
 
     @Override
@@ -40,10 +40,10 @@
     @Override
     public void onStop() {
         // Log the final choice in value if it's different from the previous value.
-        if (mToggleServiceDividerSwitchPreference.isChecked() != mToggleSwitchWasInitiallyChecked) {
+        if (mToggleServiceSwitchPreference.isChecked() != mToggleSwitchWasInitiallyChecked) {
             mMetricsFeatureProvider.action(getContext(),
                     SettingsEnums.SUW_ACCESSIBILITY_TOGGLE_SELECT_TO_SPEAK,
-                    mToggleServiceDividerSwitchPreference.isChecked());
+                    mToggleServiceSwitchPreference.isChecked());
         }
 
         super.onStop();
diff --git a/src/com/android/settings/applications/AppStateAlarmsAndRemindersBridge.java b/src/com/android/settings/applications/AppStateAlarmsAndRemindersBridge.java
new file mode 100644
index 0000000..ccfc87e
--- /dev/null
+++ b/src/com/android/settings/applications/AppStateAlarmsAndRemindersBridge.java
@@ -0,0 +1,88 @@
+/*
+ * 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.applications;
+
+import android.Manifest;
+import android.app.AppOpsManager;
+import android.content.Context;
+
+import com.android.settingslib.applications.ApplicationsState;
+import com.android.settingslib.applications.ApplicationsState.AppEntry;
+import com.android.settingslib.applications.ApplicationsState.AppFilter;
+
+import java.util.List;
+
+/**
+ * Connects app op info to the ApplicationsState. Extends {@link AppStateAppOpsBridge} to tailor
+ * to the semantics of {@link Manifest.permission#SCHEDULE_EXACT_ALARM}.
+ * Also provides app filters that can use the info.
+ */
+public class AppStateAlarmsAndRemindersBridge extends AppStateAppOpsBridge {
+
+    private AppOpsManager mAppOpsManager;
+
+    public AppStateAlarmsAndRemindersBridge(Context context, ApplicationsState appState,
+            Callback callback) {
+        super(context, appState, callback,
+                AppOpsManager.strOpToOp(AppOpsManager.OPSTR_SCHEDULE_EXACT_ALARM),
+                new String[]{Manifest.permission.SCHEDULE_EXACT_ALARM});
+
+        mAppOpsManager = context.getSystemService(AppOpsManager.class);
+    }
+
+    /**
+     * Returns information regarding {@link Manifest.permission#SCHEDULE_EXACT_ALARM} for the given
+     * package and uid.
+     */
+    public PermissionState createPermissionState(String packageName, int uid) {
+        final PermissionState permState = getPermissionInfo(packageName, uid);
+        permState.appOpMode = mAppOpsManager.unsafeCheckOpRawNoThrow(
+                AppOpsManager.OPSTR_SCHEDULE_EXACT_ALARM, uid, packageName);
+        return permState;
+    }
+
+    @Override
+    protected void updateExtraInfo(AppEntry app, String pkg, int uid) {
+        app.extraInfo = createPermissionState(pkg, uid);
+    }
+
+    @Override
+    protected void loadAllExtraInfo() {
+        final List<AppEntry> allApps = mAppSession.getAllApps();
+        for (int i = 0; i < allApps.size(); i++) {
+            final AppEntry currentEntry = allApps.get(i);
+            updateExtraInfo(currentEntry, currentEntry.info.packageName, currentEntry.info.uid);
+        }
+    }
+
+    public static final AppFilter FILTER_CLOCK_APPS = new AppFilter() {
+
+        @Override
+        public void init() {
+        }
+
+        @Override
+        public boolean filterApp(AppEntry info) {
+            if (info.extraInfo instanceof PermissionState) {
+                final PermissionState permissionState = (PermissionState) info.extraInfo;
+                return permissionState.permissionDeclared;
+            }
+            return false;
+        }
+    };
+
+}
diff --git a/src/com/android/settings/applications/AppStateAppOpsBridge.java b/src/com/android/settings/applications/AppStateAppOpsBridge.java
index b4f6e48..2ccdc78 100755
--- a/src/com/android/settings/applications/AppStateAppOpsBridge.java
+++ b/src/com/android/settings/applications/AppStateAppOpsBridge.java
@@ -277,7 +277,7 @@
             if (pe == null) {
                 Log.w(TAG, "AppOp permission exists for package " + packageOp.getPackageName()
                         + " of user " + userId + " but package doesn't exist or did not request "
-                        + mPermissions + " access");
+                        + Arrays.toString(mPermissions) + " access");
                 continue;
             }
 
diff --git a/src/com/android/settings/applications/appinfo/AlarmsAndRemindersDetails.java b/src/com/android/settings/applications/appinfo/AlarmsAndRemindersDetails.java
new file mode 100644
index 0000000..95835cb
--- /dev/null
+++ b/src/com/android/settings/applications/appinfo/AlarmsAndRemindersDetails.java
@@ -0,0 +1,137 @@
+/*
+ * 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.applications.appinfo;
+
+import static android.app.Activity.RESULT_CANCELED;
+import static android.app.Activity.RESULT_OK;
+
+import android.app.AppOpsManager;
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+import android.os.Bundle;
+
+import androidx.appcompat.app.AlertDialog;
+import androidx.preference.Preference;
+import androidx.preference.Preference.OnPreferenceChangeListener;
+
+import com.android.settings.R;
+import com.android.settings.Settings;
+import com.android.settings.applications.AppInfoWithHeader;
+import com.android.settings.applications.AppStateAlarmsAndRemindersBridge;
+import com.android.settings.applications.AppStateAppOpsBridge;
+import com.android.settingslib.RestrictedSwitchPreference;
+import com.android.settingslib.applications.ApplicationsState.AppEntry;
+
+/**
+ * App specific activity to show details about
+ * {@link android.Manifest.permission#SCHEDULE_EXACT_ALARM}.
+ */
+public class AlarmsAndRemindersDetails extends AppInfoWithHeader
+        implements OnPreferenceChangeListener {
+
+    private static final String KEY_SWITCH = "alarms_and_reminders_switch";
+
+    private AppStateAlarmsAndRemindersBridge mAppBridge;
+    private AppOpsManager mAppOpsManager;
+    private RestrictedSwitchPreference mSwitchPref;
+    private AppStateAppOpsBridge.PermissionState mPermissionState;
+
+    /**
+     * Returns the string that states whether the app has access to
+     * {@link android.Manifest.permission#SCHEDULE_EXACT_ALARM}.
+     */
+    public static int getSummary(Context context, AppEntry entry) {
+        final AppStateAppOpsBridge.PermissionState state;
+        if (entry.extraInfo instanceof AppStateAppOpsBridge.PermissionState) {
+            state = (AppStateAppOpsBridge.PermissionState) entry.extraInfo;
+        } else {
+            state = new AppStateAlarmsAndRemindersBridge(context, /*appState=*/null,
+                    /*callback=*/null).createPermissionState(entry.info.packageName,
+                    entry.info.uid);
+        }
+
+        return state.isPermissible() ? R.string.app_permission_summary_allowed
+                : R.string.app_permission_summary_not_allowed;
+    }
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        final Context context = getActivity();
+        mAppBridge = new AppStateAlarmsAndRemindersBridge(context, mState, /*callback=*/null);
+        mAppOpsManager = context.getSystemService(AppOpsManager.class);
+
+        addPreferencesFromResource(R.xml.alarms_and_reminders);
+        mSwitchPref = findPreference(KEY_SWITCH);
+        mSwitchPref.setOnPreferenceChangeListener(this);
+    }
+
+    @Override
+    public boolean onPreferenceChange(Preference preference, Object newValue) {
+        final boolean checked = (Boolean) newValue;
+        if (preference == mSwitchPref) {
+            if (mPermissionState != null && checked != mPermissionState.isPermissible()) {
+                if (Settings.AlarmsAndRemindersAppActivity.class.getName().equals(
+                        getIntent().getComponent().getClassName())) {
+                    setResult(checked ? RESULT_OK : RESULT_CANCELED);
+                }
+                setCanScheduleAlarms(checked);
+                logPermissionChange(checked, mPackageName);
+                refreshUi();
+            }
+            return true;
+        }
+        return false;
+    }
+
+    private void setCanScheduleAlarms(boolean newState) {
+        mAppOpsManager.setUidMode(AppOpsManager.OPSTR_SCHEDULE_EXACT_ALARM,
+                mPackageInfo.applicationInfo.uid,
+                newState ? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_ERRORED);
+    }
+
+    private void logPermissionChange(boolean newState, String packageName) {
+        mMetricsFeatureProvider.action(
+                mMetricsFeatureProvider.getAttribution(getActivity()),
+                SettingsEnums.ACTION_ALARMS_AND_REMINDERS_TOGGLE,
+                getMetricsCategory(),
+                packageName,
+                newState ? 1 : 0);
+    }
+
+    @Override
+    protected boolean refreshUi() {
+        if (mPackageInfo == null || mPackageInfo.applicationInfo == null) {
+            return false;
+        }
+        mPermissionState = mAppBridge.createPermissionState(mPackageName,
+                mPackageInfo.applicationInfo.uid);
+        mSwitchPref.setEnabled(mPermissionState.permissionDeclared);
+        mSwitchPref.setChecked(mPermissionState.isPermissible());
+        return true;
+    }
+
+    @Override
+    protected AlertDialog createDialog(int id, int errorCode) {
+        return null;
+    }
+
+    @Override
+    public int getMetricsCategory() {
+        return SettingsEnums.ALARMS_AND_REMINDERS;
+    }
+}
diff --git a/src/com/android/settings/applications/manageapplications/AppFilterRegistry.java b/src/com/android/settings/applications/manageapplications/AppFilterRegistry.java
index b370ad2..f4de226 100644
--- a/src/com/android/settings/applications/manageapplications/AppFilterRegistry.java
+++ b/src/com/android/settings/applications/manageapplications/AppFilterRegistry.java
@@ -19,6 +19,7 @@
 import androidx.annotation.IntDef;
 
 import com.android.settings.R;
+import com.android.settings.applications.AppStateAlarmsAndRemindersBridge;
 import com.android.settings.applications.AppStateInstallAppsBridge;
 import com.android.settings.applications.AppStateManageExternalStorageBridge;
 import com.android.settings.applications.AppStateNotificationBridge;
@@ -50,6 +51,7 @@
             FILTER_APPS_WRITE_SETTINGS,
             FILTER_APPS_INSTALL_SOURCES,
             FILTER_APPS_BLOCKED,
+            FILTER_ALARMS_AND_REMINDERS,
     })
     @interface FilterType {
     }
@@ -73,6 +75,7 @@
     public static final int FILTER_APP_CAN_CHANGE_WIFI_STATE = 15;
     public static final int FILTER_APPS_BLOCKED = 16;
     public static final int FILTER_MANAGE_EXTERNAL_STORAGE = 17;
+    public static final int FILTER_ALARMS_AND_REMINDERS = 18;
     // Next id: 18. If you add an entry here, length of mFilters should be updated
 
     private static AppFilterRegistry sRegistry;
@@ -80,7 +83,7 @@
     private final AppFilterItem[] mFilters;
 
     private AppFilterRegistry() {
-        mFilters = new AppFilterItem[18];
+        mFilters = new AppFilterItem[19];
 
         // High power allowlist, on
         mFilters[FILTER_APPS_POWER_ALLOWLIST] = new AppFilterItem(
@@ -185,6 +188,12 @@
                 AppStateManageExternalStorageBridge.FILTER_MANAGE_EXTERNAL_STORAGE,
                 FILTER_MANAGE_EXTERNAL_STORAGE,
                 R.string.filter_manage_external_storage);
+
+        // Apps that can schedule alarms and reminders
+        mFilters[FILTER_ALARMS_AND_REMINDERS] = new AppFilterItem(
+                AppStateAlarmsAndRemindersBridge.FILTER_CLOCK_APPS,
+                FILTER_ALARMS_AND_REMINDERS,
+                R.string.alarms_and_reminders_title);
     }
 
     public static AppFilterRegistry getInstance() {
@@ -213,6 +222,8 @@
                 return FILTER_APPS_RECENT;
             case ManageApplications.LIST_MANAGE_EXTERNAL_STORAGE:
                 return FILTER_MANAGE_EXTERNAL_STORAGE;
+            case ManageApplications.LIST_TYPE_ALARMS_AND_REMINDERS:
+                return FILTER_ALARMS_AND_REMINDERS;
             default:
                 return FILTER_APPS_ALL;
         }
diff --git a/src/com/android/settings/applications/manageapplications/ManageApplications.java b/src/com/android/settings/applications/manageapplications/ManageApplications.java
index 707e6f4..2dadbbc 100644
--- a/src/com/android/settings/applications/manageapplications/ManageApplications.java
+++ b/src/com/android/settings/applications/manageapplications/ManageApplications.java
@@ -91,6 +91,7 @@
 import com.android.settings.SettingsActivity;
 import com.android.settings.Utils;
 import com.android.settings.applications.AppInfoBase;
+import com.android.settings.applications.AppStateAlarmsAndRemindersBridge;
 import com.android.settings.applications.AppStateAppOpsBridge.PermissionState;
 import com.android.settings.applications.AppStateBaseBridge;
 import com.android.settings.applications.AppStateInstallAppsBridge;
@@ -104,6 +105,7 @@
 import com.android.settings.applications.AppStateWriteSettingsBridge;
 import com.android.settings.applications.AppStorageSettings;
 import com.android.settings.applications.UsageAccessDetails;
+import com.android.settings.applications.appinfo.AlarmsAndRemindersDetails;
 import com.android.settings.applications.appinfo.AppInfoDashboardFragment;
 import com.android.settings.applications.appinfo.DrawOverlayDetails;
 import com.android.settings.applications.appinfo.ExternalSourcesDetails;
@@ -230,6 +232,7 @@
     public static final int LIST_TYPE_PHOTOGRAPHY = 11;
     public static final int LIST_TYPE_WIFI_ACCESS = 13;
     public static final int LIST_MANAGE_EXTERNAL_STORAGE = 14;
+    public static final int LIST_TYPE_ALARMS_AND_REMINDERS = 15;
 
     // List types that should show instant apps.
     public static final Set<Integer> LIST_TYPES_WITH_INSTANT = new ArraySet<>(Arrays.asList(
@@ -321,6 +324,9 @@
         } else if (className.equals(Settings.ManageExternalStorageActivity.class.getName())) {
             mListType = LIST_MANAGE_EXTERNAL_STORAGE;
             screenTitle = R.string.manage_external_storage_title;
+        } else if (className.equals(Settings.AlarmsAndRemindersActivity.class.getName())) {
+            mListType = LIST_TYPE_ALARMS_AND_REMINDERS;
+            screenTitle = R.string.alarms_and_reminders_title;
         } else if (className.equals(Settings.NotificationAppListActivity.class.getName())) {
             mListType = LIST_TYPE_NOTIFICATION;
             mUsageStatsManager = IUsageStatsManager.Stub.asInterface(
@@ -545,6 +551,8 @@
                 return SettingsEnums.CONFIGURE_WIFI;
             case LIST_MANAGE_EXTERNAL_STORAGE:
                 return SettingsEnums.MANAGE_EXTERNAL_STORAGE;
+            case LIST_TYPE_ALARMS_AND_REMINDERS:
+                return SettingsEnums.ALARMS_AND_REMINDERS;
             default:
                 return SettingsEnums.PAGE_UNKNOWN;
         }
@@ -666,6 +674,10 @@
                 startAppInfoFragment(ManageExternalStorageDetails.class,
                         R.string.manage_external_storage_title);
                 break;
+            case LIST_TYPE_ALARMS_AND_REMINDERS:
+                startAppInfoFragment(AlarmsAndRemindersDetails.class,
+                        R.string.alarms_and_reminders_label);
+                break;
             // TODO: Figure out if there is a way where we can spin up the profile's settings
             // process ahead of time, to avoid a long load of data when user clicks on a managed
             // app. Maybe when they load the list of apps that contains managed profile apps.
@@ -744,6 +756,8 @@
                 return R.string.help_uri_apps_wifi_access;
             case LIST_MANAGE_EXTERNAL_STORAGE:
                 return R.string.help_uri_manage_external_storage;
+            case LIST_TYPE_ALARMS_AND_REMINDERS:
+                return R.string.help_uri_alarms_and_reminders;
             default:
             case LIST_TYPE_MAIN:
                 return R.string.help_uri_apps;
@@ -1066,6 +1080,8 @@
                 mExtraInfoBridge = new AppStateChangeWifiStateBridge(mContext, mState, this);
             } else if (mManageApplications.mListType == LIST_MANAGE_EXTERNAL_STORAGE) {
                 mExtraInfoBridge = new AppStateManageExternalStorageBridge(mContext, mState, this);
+            } else if (mManageApplications.mListType == LIST_TYPE_ALARMS_AND_REMINDERS) {
+                mExtraInfoBridge = new AppStateAlarmsAndRemindersBridge(mContext, mState, this);
             } else {
                 mExtraInfoBridge = null;
             }
@@ -1527,6 +1543,9 @@
                 case LIST_MANAGE_EXTERNAL_STORAGE:
                     holder.setSummary(ManageExternalStorageDetails.getSummary(mContext, entry));
                     break;
+                case LIST_TYPE_ALARMS_AND_REMINDERS:
+                    holder.setSummary(AlarmsAndRemindersDetails.getSummary(mContext, entry));
+                    break;
                 default:
                     holder.updateSizeText(entry, mManageApplications.mInvalidSizeStr, mWhichSize);
                     break;
diff --git a/src/com/android/settings/applications/specialaccess/HighPowerAppsController.java b/src/com/android/settings/applications/specialaccess/HighPowerAppsController.java
deleted file mode 100644
index b893b88..0000000
--- a/src/com/android/settings/applications/specialaccess/HighPowerAppsController.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2017 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.applications.specialaccess;
-
-import android.content.Context;
-
-import com.android.settings.R;
-import com.android.settings.core.BasePreferenceController;
-
-public class HighPowerAppsController extends BasePreferenceController {
-
-    public HighPowerAppsController(Context context, String key) {
-        super(context, key);
-    }
-
-    @AvailabilityStatus
-    public int getAvailabilityStatus() {
-        return mContext.getResources().getBoolean(R.bool.config_show_high_power_apps)
-                ? AVAILABLE
-                : UNSUPPORTED_ON_DEVICE;
-    }
-}
\ No newline at end of file
diff --git a/src/com/android/settings/applications/specialaccess/notificationaccess/OWNERS b/src/com/android/settings/applications/specialaccess/notificationaccess/OWNERS
new file mode 100644
index 0000000..4338198
--- /dev/null
+++ b/src/com/android/settings/applications/specialaccess/notificationaccess/OWNERS
@@ -0,0 +1,4 @@
+# Default reviewers for this and subdirectories.
+beverlyt@google.com
+dsandler@android.com
+juliacr@google.com
\ No newline at end of file
diff --git a/src/com/android/settings/bluetooth/BluetoothSwitchPreferenceController.java b/src/com/android/settings/bluetooth/BluetoothSwitchPreferenceController.java
index 5b74ce7..27f10da 100644
--- a/src/com/android/settings/bluetooth/BluetoothSwitchPreferenceController.java
+++ b/src/com/android/settings/bluetooth/BluetoothSwitchPreferenceController.java
@@ -23,7 +23,7 @@
 
 import com.android.settings.R;
 import com.android.settings.core.SubSettingLauncher;
-import com.android.settings.location.ScanningSettings;
+import com.android.settings.location.LocationServices;
 import com.android.settings.overlay.FeatureFactory;
 import com.android.settings.utils.AnnotationSpan;
 import com.android.settings.widget.SwitchWidgetController;
@@ -100,7 +100,7 @@
     public void onClick(View v) {
         // send users to scanning settings if they click on the link in the summary text
         new SubSettingLauncher(mContext)
-                .setDestination(ScanningSettings.class.getName())
+                .setDestination(LocationServices.class.getName())
                 .setSourceMetricsCategory(SettingsEnums.BLUETOOTH_FRAGMENT)
                 .launch();
     }
diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java
index 245389e..bc2582e 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -39,6 +39,7 @@
 import com.android.settings.applications.ProcessStatsSummary;
 import com.android.settings.applications.ProcessStatsUi;
 import com.android.settings.applications.UsageAccessDetails;
+import com.android.settings.applications.appinfo.AlarmsAndRemindersDetails;
 import com.android.settings.applications.appinfo.AppInfoDashboardFragment;
 import com.android.settings.applications.appinfo.DrawOverlayDetails;
 import com.android.settings.applications.appinfo.ExternalSourcesDetails;
@@ -110,8 +111,8 @@
 import com.android.settings.inputmethod.UserDictionarySettings;
 import com.android.settings.language.LanguageAndInputSettings;
 import com.android.settings.localepicker.LocaleListEditor;
+import com.android.settings.location.LocationServices;
 import com.android.settings.location.LocationSettings;
-import com.android.settings.location.ScanningSettings;
 import com.android.settings.network.MobileNetworkListFragment;
 import com.android.settings.network.NetworkDashboardFragment;
 import com.android.settings.network.NetworkProviderSettings;
@@ -200,7 +201,7 @@
             NotificationStation.class.getName(),
             LocationSettings.class.getName(),
             PrivacyDashboardFragment.class.getName(),
-            ScanningSettings.class.getName(),
+            LocationServices.class.getName(),
             SecuritySettings.class.getName(),
             UsageAccessDetails.class.getName(),
             PrivacySettings.class.getName(),
@@ -313,7 +314,8 @@
             InteractAcrossProfilesSettings.class.getName(),
             InteractAcrossProfilesDetails.class.getName(),
             MediaControlsSettings.class.getName(),
-            NetworkProviderSettings.class.getName()
+            NetworkProviderSettings.class.getName(),
+            AlarmsAndRemindersDetails.class.getName(),
     };
 
     public static final String[] SETTINGS_FOR_RESTRICTED = {
diff --git a/src/com/android/settings/development/ForcePeakRefreshRatePreferenceController.java b/src/com/android/settings/development/ForcePeakRefreshRatePreferenceController.java
index 78352d3..d5d4025 100644
--- a/src/com/android/settings/development/ForcePeakRefreshRatePreferenceController.java
+++ b/src/com/android/settings/development/ForcePeakRefreshRatePreferenceController.java
@@ -122,7 +122,7 @@
     private float findPeakRefreshRate(Display.Mode[] modes) {
         float peakRefreshRate = DEFAULT_REFRESH_RATE;
         for (Display.Mode mode : modes) {
-            if (Math.round(mode.getRefreshRate()) > DEFAULT_REFRESH_RATE) {
+            if (Math.round(mode.getRefreshRate()) > peakRefreshRate) {
                 peakRefreshRate = mode.getRefreshRate();
             }
         }
diff --git a/src/com/android/settings/development/bluetooth/BaseBluetoothDialogPreference.java b/src/com/android/settings/development/bluetooth/BaseBluetoothDialogPreference.java
index 08a450b..39e2276 100644
--- a/src/com/android/settings/development/bluetooth/BaseBluetoothDialogPreference.java
+++ b/src/com/android/settings/development/bluetooth/BaseBluetoothDialogPreference.java
@@ -97,10 +97,14 @@
             radioButton.setText(mRadioButtonStrings.get(i));
             radioButton.setEnabled(selectableIndex.contains(i));
         }
-        // View will be invisible when all options are enabled.
+        // Initial help information text view
+        final TextView helpTextView = view.findViewById(R.id.bluetooth_audio_codec_help_info);
         if (selectableIndex.size() == mRadioButtonIds.size()) {
-            final TextView helpTextView = view.findViewById(R.id.bluetooth_audio_codec_help_info);
+            // View will be invisible when all options are enabled.
             helpTextView.setVisibility(View.GONE);
+        } else {
+            helpTextView.setText(R.string.bluetooth_select_a2dp_codec_type_help_info);
+            helpTextView.setVisibility(View.VISIBLE);
         }
     }
 
diff --git a/src/com/android/settings/development/transcode/TranscodeNotificationPreferenceController.java b/src/com/android/settings/development/transcode/TranscodeNotificationPreferenceController.java
new file mode 100644
index 0000000..e51f8ad
--- /dev/null
+++ b/src/com/android/settings/development/transcode/TranscodeNotificationPreferenceController.java
@@ -0,0 +1,53 @@
+/*
+ * 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.development.transcode;
+
+import android.content.Context;
+import android.os.SystemProperties;
+
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.settings.core.TogglePreferenceController;
+
+/**
+ * The controller (in the Media transcoding settings) indicating the user's preference to show
+ * or hide the transcoding notifications.
+ */
+public class TranscodeNotificationPreferenceController extends TogglePreferenceController {
+    @VisibleForTesting
+    static final String TRANSCODE_NOTIFICATION_SYS_PROP_KEY =
+            "persist.sys.fuse.transcode_notification";
+
+    public TranscodeNotificationPreferenceController(Context context, String preferenceKey) {
+        super(context, preferenceKey);
+    }
+
+    @Override
+    public boolean isChecked() {
+        return SystemProperties.getBoolean(TRANSCODE_NOTIFICATION_SYS_PROP_KEY, true);
+    }
+
+    @Override
+    public boolean setChecked(boolean isChecked) {
+        SystemProperties.set(TRANSCODE_NOTIFICATION_SYS_PROP_KEY, String.valueOf(isChecked));
+        return true;
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        return AVAILABLE;
+    }
+}
diff --git a/src/com/android/settings/display/PeakRefreshRatePreferenceController.java b/src/com/android/settings/display/PeakRefreshRatePreferenceController.java
index 10cab1c..36e085a 100644
--- a/src/com/android/settings/display/PeakRefreshRatePreferenceController.java
+++ b/src/com/android/settings/display/PeakRefreshRatePreferenceController.java
@@ -129,10 +129,11 @@
         mDeviceConfigDisplaySettings.stopListening();
     }
 
-    private float findPeakRefreshRate(Display.Mode[] modes) {
+    @VisibleForTesting
+    float findPeakRefreshRate(Display.Mode[] modes) {
         float peakRefreshRate = DEFAULT_REFRESH_RATE;
         for (Display.Mode mode : modes) {
-            if (Math.round(mode.getRefreshRate()) > DEFAULT_REFRESH_RATE) {
+            if (Math.round(mode.getRefreshRate()) > peakRefreshRate) {
                 peakRefreshRate = mode.getRefreshRate();
             }
         }
diff --git a/src/com/android/settings/fuelgauge/OWNERS b/src/com/android/settings/fuelgauge/OWNERS
index ab3da89..d68dc98 100644
--- a/src/com/android/settings/fuelgauge/OWNERS
+++ b/src/com/android/settings/fuelgauge/OWNERS
@@ -2,3 +2,6 @@
 tifn@google.com
 wesleycwwang@google.com
 ykhung@google.com
+
+# BatteryStats
+per-file FakeUid.java = file:platform/frameworks/base:/BATTERY_STATS_OWNERS
diff --git a/src/com/android/settings/location/LocationPersonalSettings.java b/src/com/android/settings/location/LocationPersonalSettings.java
index 92796a4..38b7c4a 100644
--- a/src/com/android/settings/location/LocationPersonalSettings.java
+++ b/src/com/android/settings/location/LocationPersonalSettings.java
@@ -50,12 +50,13 @@
         super.onAttach(context);
 
         use(AppLocationPermissionPreferenceController.class).init(this);
-        use(LocationServicePreferenceController.class).init(this);
+        // STOPSHIP(b/180533061): resolve the personal/work location services issue before we can
+        // ship.
         use(LocationFooterPreferenceController.class).init(this);
 
         final int profileType = getArguments().getInt(ProfileSelectFragment.EXTRA_PROFILE);
-        final RecentLocationRequestPreferenceController controller = use(
-                RecentLocationRequestPreferenceController.class);
+        final RecentLocationAccessPreferenceController controller = use(
+                RecentLocationAccessPreferenceController.class);
         controller.init(this);
         controller.setProfileType(profileType);
     }
diff --git a/src/com/android/settings/location/ScanningSettings.java b/src/com/android/settings/location/LocationServices.java
similarity index 79%
rename from src/com/android/settings/location/ScanningSettings.java
rename to src/com/android/settings/location/LocationServices.java
index 90f4e2a..8f05584 100644
--- a/src/com/android/settings/location/ScanningSettings.java
+++ b/src/com/android/settings/location/LocationServices.java
@@ -29,20 +29,21 @@
 import java.util.List;
 
 /**
- * A page that configures the background scanning settings for Wi-Fi and Bluetooth.
+ * A page that configures the Location Services settings including Wi-Fi scanning, Bluetooth
+ * scanning, and injected location services.
  */
 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
-public class ScanningSettings extends DashboardFragment {
-    private static final String TAG = "ScanningSettings";
+public class LocationServices extends DashboardFragment {
+    private static final String TAG = "LocationServicesSettings";
 
     @Override
     public int getMetricsCategory() {
-        return SettingsEnums.LOCATION_SCANNING;
+        return SettingsEnums.LOCATION_SERVICES;
     }
 
     @Override
     protected int getPreferenceScreenResId() {
-        return R.xml.location_scanning;
+        return R.xml.location_services;
     }
 
     @Override
@@ -55,6 +56,13 @@
         return buildPreferenceControllers(context);
     }
 
+    @Override
+    public void onAttach(Context context) {
+        super.onAttach(context);
+
+        use(LocationServicePreferenceController.class).init(this);
+    }
+
     private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
         final List<AbstractPreferenceController> controllers = new ArrayList<>();
         controllers.add(new WifiScanningPreferenceController(context));
@@ -66,7 +74,7 @@
      * For Search.
      */
     public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
-            new BaseSearchIndexProvider(R.xml.location_scanning) {
+            new BaseSearchIndexProvider(R.xml.location_services) {
 
                 @Override
                 public List<AbstractPreferenceController> createPreferenceControllers(Context
diff --git a/src/com/android/settings/location/LocationSettings.java b/src/com/android/settings/location/LocationSettings.java
index b4f0f1f..9a61b31 100644
--- a/src/com/android/settings/location/LocationSettings.java
+++ b/src/com/android/settings/location/LocationSettings.java
@@ -82,8 +82,7 @@
         super.onAttach(context);
 
         use(AppLocationPermissionPreferenceController.class).init(this);
-        use(RecentLocationRequestPreferenceController.class).init(this);
-        use(LocationServicePreferenceController.class).init(this);
+        use(RecentLocationAccessPreferenceController.class).init(this);
         use(LocationFooterPreferenceController.class).init(this);
         use(LocationForWorkPreferenceController.class).init(this);
         use(LocationServiceForWorkPreferenceController.class).init(this);
diff --git a/src/com/android/settings/location/LocationWorkProfileSettings.java b/src/com/android/settings/location/LocationWorkProfileSettings.java
index 2bf5f98..601ec23 100644
--- a/src/com/android/settings/location/LocationWorkProfileSettings.java
+++ b/src/com/android/settings/location/LocationWorkProfileSettings.java
@@ -55,8 +55,8 @@
         use(LocationForWorkPreferenceController.class).init(this);
 
         final int profileType = getArguments().getInt(ProfileSelectFragment.EXTRA_PROFILE);
-        final RecentLocationRequestPreferenceController controller = use(
-                RecentLocationRequestPreferenceController.class);
+        final RecentLocationAccessPreferenceController controller = use(
+                RecentLocationAccessPreferenceController.class);
         controller.init(this);
         controller.setProfileType(profileType);
     }
diff --git a/src/com/android/settings/location/RecentLocationAccessPreferenceController.java b/src/com/android/settings/location/RecentLocationAccessPreferenceController.java
index c835a51..245118d 100644
--- a/src/com/android/settings/location/RecentLocationAccessPreferenceController.java
+++ b/src/com/android/settings/location/RecentLocationAccessPreferenceController.java
@@ -13,114 +13,141 @@
  */
 package com.android.settings.location;
 
-import static java.util.concurrent.TimeUnit.DAYS;
+import static android.Manifest.permission_group.LOCATION;
 
-import android.Manifest;
 import android.content.Context;
 import android.content.Intent;
-import android.icu.text.RelativeDateTimeFormatter;
-import android.provider.DeviceConfig;
-import android.view.View;
+import android.os.UserHandle;
+import android.os.UserManager;
 
 import androidx.annotation.VisibleForTesting;
 import androidx.preference.Preference;
+import androidx.preference.PreferenceCategory;
 import androidx.preference.PreferenceScreen;
 
 import com.android.settings.R;
-import com.android.settings.Utils;
-import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
 import com.android.settingslib.location.RecentLocationAccesses;
-import com.android.settingslib.utils.StringUtil;
-import com.android.settingslib.widget.AppEntitiesHeaderController;
-import com.android.settingslib.widget.AppEntityInfo;
-import com.android.settingslib.widget.LayoutPreference;
+import com.android.settingslib.widget.AppPreference;
 
+import java.util.ArrayList;
 import java.util.List;
 
-public class RecentLocationAccessPreferenceController extends AbstractPreferenceController
-        implements PreferenceControllerMixin {
-    /** Key for the recent location apps dashboard */
-    private static final String KEY_APPS_DASHBOARD = "apps_dashboard";
-    private final RecentLocationAccesses mRecentLocationAccesses;
-    private AppEntitiesHeaderController mController;
-    private static final int MAXIMUM_APP_COUNT = 3;
+/**
+ * Preference controller that handles the display of apps that access locations.
+ */
+public class RecentLocationAccessPreferenceController extends LocationBasePreferenceController {
+    @VisibleForTesting
+    RecentLocationAccesses mRecentLocationApps;
+    private PreferenceCategory mCategoryRecentLocationRequests;
+    private int mType = ProfileSelectFragment.ProfileType.ALL;
 
-    public RecentLocationAccessPreferenceController(Context context) {
-        this(context, new RecentLocationAccesses(context));
+    private static class PackageEntryClickedListener implements
+            Preference.OnPreferenceClickListener {
+        private final Context mContext;
+        private final String mPackage;
+        private final UserHandle mUserHandle;
+
+        PackageEntryClickedListener(Context context, String packageName,
+                UserHandle userHandle) {
+            mContext = context;
+            mPackage = packageName;
+            mUserHandle = userHandle;
+        }
+
+        @Override
+        public boolean onPreferenceClick(Preference preference) {
+            final Intent intent = new Intent(Intent.ACTION_MANAGE_APP_PERMISSION);
+            intent.putExtra(Intent.EXTRA_PERMISSION_GROUP_NAME, LOCATION);
+            intent.putExtra(Intent.EXTRA_PACKAGE_NAME, mPackage);
+            intent.putExtra(Intent.EXTRA_USER, mUserHandle);
+            mContext.startActivity(intent);
+            return true;
+        }
+    }
+
+    public RecentLocationAccessPreferenceController(Context context, String key) {
+        this(context, key, new RecentLocationAccesses(context));
     }
 
     @VisibleForTesting
-    RecentLocationAccessPreferenceController(Context context,
-            RecentLocationAccesses recentAccesses) {
-        super(context);
-        mRecentLocationAccesses = recentAccesses;
-    }
-
-    @Override
-    public String getPreferenceKey() {
-        return KEY_APPS_DASHBOARD;
-    }
-
-    @Override
-    public boolean isAvailable() {
-        return Boolean.parseBoolean(
-                DeviceConfig.getProperty(DeviceConfig.NAMESPACE_PRIVACY,
-                        Utils.PROPERTY_PERMISSIONS_HUB_ENABLED));
+    public RecentLocationAccessPreferenceController(Context context, String key,
+            RecentLocationAccesses recentLocationApps) {
+        super(context, key);
+        mRecentLocationApps = recentLocationApps;
     }
 
     @Override
     public void displayPreference(PreferenceScreen screen) {
         super.displayPreference(screen);
-        final LayoutPreference preference = screen.findPreference(KEY_APPS_DASHBOARD);
-        final View view = preference.findViewById(R.id.app_entities_header);
-        mController = AppEntitiesHeaderController.newInstance(mContext, view)
-                .setHeaderTitleRes(R.string.location_category_recent_location_access)
-                .setHeaderDetailsRes(R.string.location_recent_location_access_view_details)
-                .setHeaderEmptyRes(R.string.location_no_recent_accesses)
-                .setHeaderDetailsClickListener((View v) -> {
-                    final Intent intent = new Intent(Intent.ACTION_REVIEW_PERMISSION_USAGE);
-                    intent.putExtra(Intent.EXTRA_PERMISSION_NAME,
-                            Manifest.permission.ACCESS_FINE_LOCATION);
-                    intent.putExtra(Intent.EXTRA_DURATION_MILLIS, DAYS.toMillis(1));
-                    mContext.startActivity(intent);
-                });
+        mCategoryRecentLocationRequests = screen.findPreference(getPreferenceKey());
+        final Context prefContext = mCategoryRecentLocationRequests.getContext();
+        final List<RecentLocationAccesses.Access> recentLocationAccesses = new ArrayList<>();
+        final UserManager userManager = UserManager.get(mContext);
+        for (RecentLocationAccesses.Access access : mRecentLocationApps.getAppListSorted()) {
+            if (isRequestMatchesProfileType(userManager, access, mType)) {
+                recentLocationAccesses.add(access);
+            }
+        }
+
+        if (recentLocationAccesses.size() > 0) {
+            // Add preferences to container in original order (already sorted by recency).
+            for (RecentLocationAccesses.Access access : recentLocationAccesses) {
+                mCategoryRecentLocationRequests.addPreference(
+                        createAppPreference(prefContext, access, mFragment));
+            }
+        } else {
+            // If there's no item to display, add a "No recent apps" item.
+            final Preference banner = new AppPreference(prefContext);
+            banner.setTitle(R.string.location_no_recent_accesses);
+            banner.setSelectable(false);
+            mCategoryRecentLocationRequests.addPreference(banner);
+        }
     }
 
     @Override
-    public void updateState(Preference preference) {
-        updateRecentApps();
+    public void onLocationModeChanged(int mode, boolean restricted) {
+        mCategoryRecentLocationRequests.setEnabled(mLocationEnabler.isEnabled(mode));
     }
 
-    private void updateRecentApps() {
-        final List<RecentLocationAccesses.Access> recentLocationAccesses =
-                mRecentLocationAccesses.getAppListSorted();
-        if (recentLocationAccesses.size() > 0) {
-            // Display the top 3 preferences to container in original order.
-            int i = 0;
-            for (; i < Math.min(recentLocationAccesses.size(), MAXIMUM_APP_COUNT); i++) {
-                final RecentLocationAccesses.Access access = recentLocationAccesses.get(i);
-                final AppEntityInfo appEntityInfo = new AppEntityInfo.Builder()
-                        .setIcon(access.icon)
-                        .setTitle(access.label)
-                        .setSummary(StringUtil.formatRelativeTime(mContext,
-                                System.currentTimeMillis() - access.accessFinishTime, false,
-                                RelativeDateTimeFormatter.Style.SHORT))
-                        .setOnClickListener((v) -> {
-                            final Intent intent = new Intent(Intent.ACTION_MANAGE_APP_PERMISSION);
-                            intent.putExtra(Intent.EXTRA_PERMISSION_NAME,
-                                    Manifest.permission.ACCESS_FINE_LOCATION);
-                            intent.putExtra(Intent.EXTRA_PACKAGE_NAME, access.packageName);
-                            intent.putExtra(Intent.EXTRA_USER, access.userHandle);
-                            mContext.startActivity(intent);
-                        })
-                        .build();
-                mController.setAppEntity(i, appEntityInfo);
-            }
-            for (; i < MAXIMUM_APP_COUNT; i++) {
-                mController.removeAppEntity(i);
-            }
+    /**
+     * Initialize {@link ProfileSelectFragment.ProfileType} of the controller
+     *
+     * @param type {@link ProfileSelectFragment.ProfileType} of the controller.
+     */
+    public void setProfileType(@ProfileSelectFragment.ProfileType int type) {
+        mType = type;
+    }
+
+    /**
+     * Create a {@link AppPreference}
+     */
+    public static AppPreference createAppPreference(Context prefContext,
+            RecentLocationAccesses.Access access, DashboardFragment fragment) {
+        final AppPreference pref = new AppPreference(prefContext);
+        pref.setIcon(access.icon);
+        pref.setTitle(access.label);
+        pref.setOnPreferenceClickListener(new PackageEntryClickedListener(
+                fragment.getContext(), access.packageName, access.userHandle));
+        return pref;
+    }
+
+    /**
+     * Return if the {@link RecentLocationAccesses.Access} matches current UI
+     * {@ProfileSelectFragment.ProfileType}
+     */
+    public static boolean isRequestMatchesProfileType(UserManager userManager,
+            RecentLocationAccesses.Access access, @ProfileSelectFragment.ProfileType int type) {
+
+        final boolean isWorkProfile = userManager.isManagedProfile(
+                access.userHandle.getIdentifier());
+        if (isWorkProfile && (type & ProfileSelectFragment.ProfileType.WORK) != 0) {
+            return true;
         }
-        mController.apply();
+        if (!isWorkProfile && (type & ProfileSelectFragment.ProfileType.PERSONAL) != 0) {
+            return true;
+        }
+        return false;
     }
 }
diff --git a/src/com/android/settings/network/AdaptiveConnectivityTogglePreferenceController.java b/src/com/android/settings/network/AdaptiveConnectivityTogglePreferenceController.java
index e072b5c..e1e56a8 100644
--- a/src/com/android/settings/network/AdaptiveConnectivityTogglePreferenceController.java
+++ b/src/com/android/settings/network/AdaptiveConnectivityTogglePreferenceController.java
@@ -17,6 +17,7 @@
 package com.android.settings.network;
 
 import android.content.Context;
+import android.net.wifi.WifiManager;
 import android.provider.Settings;
 
 import androidx.preference.PreferenceScreen;
@@ -28,8 +29,11 @@
  */
 public class AdaptiveConnectivityTogglePreferenceController extends TogglePreferenceController {
 
+    private final WifiManager mWifiManager;
+
     public AdaptiveConnectivityTogglePreferenceController(Context context, String preferenceKey) {
         super(context, preferenceKey);
+        mWifiManager = context.getSystemService(WifiManager.class);
     }
 
     @Override
@@ -53,6 +57,7 @@
         Settings.Secure.putInt(mContext.getContentResolver(),
                 Settings.Secure.ADAPTIVE_CONNECTIVITY_ENABLED,
                 isChecked ? 1 : 0);
+        mWifiManager.setWifiScoringEnabled(isChecked);
         return true;
     }
 }
diff --git a/src/com/android/settings/network/BluetoothTetherPreferenceController.java b/src/com/android/settings/network/BluetoothTetherPreferenceController.java
index ab507da..96d39e3 100644
--- a/src/com/android/settings/network/BluetoothTetherPreferenceController.java
+++ b/src/com/android/settings/network/BluetoothTetherPreferenceController.java
@@ -70,7 +70,7 @@
 
     @Override
     public boolean shouldShow() {
-        final String[] bluetoothRegexs = mCm.getTetherableBluetoothRegexs();
+        final String[] bluetoothRegexs = mTm.getTetherableBluetoothRegexs();
         return bluetoothRegexs != null && bluetoothRegexs.length != 0;
     }
 
diff --git a/src/com/android/settings/network/EthernetTetherPreferenceController.java b/src/com/android/settings/network/EthernetTetherPreferenceController.java
index 19c410d..06cd6a7 100644
--- a/src/com/android/settings/network/EthernetTetherPreferenceController.java
+++ b/src/com/android/settings/network/EthernetTetherPreferenceController.java
@@ -65,7 +65,7 @@
 
     @Override
     public boolean shouldEnable() {
-        String[] available = mCm.getTetherableIfaces();
+        String[] available = mTm.getTetherableIfaces();
         for (String s : available) {
             if (s.matches(mEthernetRegex)) {
                 return true;
diff --git a/src/com/android/settings/network/OWNERS b/src/com/android/settings/network/OWNERS
index 4f17e3f..8b16bc9 100644
--- a/src/com/android/settings/network/OWNERS
+++ b/src/com/android/settings/network/OWNERS
@@ -6,6 +6,7 @@
 leechou@google.com
 songferngwang@google.com
 tomhsu@google.com
+wengsu@google.com
 zoeychen@google.com
 
 # Emergency approvers in case the above are not available
diff --git a/src/com/android/settings/network/TetherBasePreferenceController.java b/src/com/android/settings/network/TetherBasePreferenceController.java
index 1919770..822aa72 100644
--- a/src/com/android/settings/network/TetherBasePreferenceController.java
+++ b/src/com/android/settings/network/TetherBasePreferenceController.java
@@ -17,7 +17,7 @@
 package com.android.settings.network;
 
 import android.content.Context;
-import android.net.ConnectivityManager;
+import android.net.TetheringManager;
 
 import androidx.lifecycle.Lifecycle;
 import androidx.lifecycle.LifecycleObserver;
@@ -33,7 +33,7 @@
         TetherEnabler.OnTetherStateUpdateListener {
 
     private static final String TAG = "TetherBasePreferenceController";
-    final ConnectivityManager mCm;
+    final TetheringManager mTm;
     private final DataSaverBackend mDataSaverBackend;
 
     private TetherEnabler mTetherEnabler;
@@ -43,7 +43,7 @@
 
     TetherBasePreferenceController(Context context, String preferenceKey) {
         super(context, preferenceKey);
-        mCm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+        mTm = context.getSystemService(TetheringManager.class);
         mDataSaverBackend = new DataSaverBackend(context);
         mDataSaverEnabled = mDataSaverBackend.isDataSaverEnabled();
     }
diff --git a/src/com/android/settings/network/TetherEnabler.java b/src/com/android/settings/network/TetherEnabler.java
index 6ab4cb2..ef031f6 100644
--- a/src/com/android/settings/network/TetherEnabler.java
+++ b/src/com/android/settings/network/TetherEnabler.java
@@ -147,7 +147,7 @@
         mSwitchWidgetController.setListener(this);
         mSwitchWidgetController.startListening();
         final IntentFilter filter = new IntentFilter(
-                ConnectivityManager.ACTION_TETHER_STATE_CHANGED);
+                TetheringManager.ACTION_TETHER_STATE_CHANGED);
         filter.addAction(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
         filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
         mContext.registerReceiver(mTetherChangeReceiver, filter);
@@ -222,7 +222,7 @@
     int getTetheringState(@Nullable String[] tethered) {
         int tetherState = TETHERING_OFF;
         if (tethered == null) {
-            tethered = mConnectivityManager.getTetheredIfaces();
+            tethered = mTetheringManager.getTetheredIfaces();
         }
 
         if (mWifiManager.isWifiApEnabled()) {
@@ -239,7 +239,7 @@
             }
         }
 
-        String[] usbRegexs = mConnectivityManager.getTetherableUsbRegexs();
+        String[] usbRegexs = mTetheringManager.getTetherableUsbRegexs();
         for (String s : tethered) {
             for (String regex : usbRegexs) {
                 if (s.matches(regex)) {
diff --git a/src/com/android/settings/network/TetherPreferenceController.java b/src/com/android/settings/network/TetherPreferenceController.java
index 2409544..8df0ac1 100644
--- a/src/com/android/settings/network/TetherPreferenceController.java
+++ b/src/com/android/settings/network/TetherPreferenceController.java
@@ -28,6 +28,7 @@
 import android.content.IntentFilter;
 import android.database.ContentObserver;
 import android.net.ConnectivityManager;
+import android.net.TetheringManager;
 import android.net.Uri;
 import android.os.Bundle;
 import android.os.Handler;
@@ -62,6 +63,7 @@
     private final AtomicReference<BluetoothPan> mBluetoothPan;
     private final ConnectivityManager mConnectivityManager;
     private final BluetoothAdapter mBluetoothAdapter;
+    private final TetheringManager mTetheringManager;
     @VisibleForTesting
     final BluetoothProfile.ServiceListener mBtProfileServiceListener =
             new android.bluetooth.BluetoothProfile.ServiceListener() {
@@ -86,6 +88,7 @@
         mBluetoothPan = new AtomicReference<>();
         mConnectivityManager = null;
         mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+        mTetheringManager = null;
     }
 
     public TetherPreferenceController(Context context, Lifecycle lifecycle) {
@@ -95,6 +98,7 @@
         mConnectivityManager =
                 (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
         mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+        mTetheringManager = context.getSystemService(TetheringManager.class);
         if (lifecycle != null) {
             lifecycle.addObserver(this);
         }
@@ -144,7 +148,7 @@
             mTetherReceiver = new TetherBroadcastReceiver();
         }
         mContext.registerReceiver(
-                mTetherReceiver, new IntentFilter(ConnectivityManager.ACTION_TETHER_STATE_CHANGED));
+                mTetherReceiver, new IntentFilter(TetheringManager.ACTION_TETHER_STATE_CHANGED));
         mContext.getContentResolver()
                 .registerContentObserver(mAirplaneModeObserver.uri, false, mAirplaneModeObserver);
     }
@@ -178,9 +182,9 @@
             // Preference is not ready yet.
             return;
         }
-        String[] allTethered = mConnectivityManager.getTetheredIfaces();
-        String[] wifiTetherRegex = mConnectivityManager.getTetherableWifiRegexs();
-        String[] bluetoothRegex = mConnectivityManager.getTetherableBluetoothRegexs();
+        String[] allTethered = mTetheringManager.getTetheredIfaces();
+        String[] wifiTetherRegex = mTetheringManager.getTetherableWifiRegexs();
+        String[] bluetoothRegex = mTetheringManager.getTetherableBluetoothRegexs();
 
         boolean hotSpotOn = false;
         boolean tetherOn = false;
@@ -211,7 +215,7 @@
                 && bluetoothRegex != null && bluetoothRegex.length > 0
                 && mBluetoothAdapter != null
                 && mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON) {
-            // Check bluetooth state. It's not included in mConnectivityManager.getTetheredIfaces.
+            // Check bluetooth state. It's not included in mTetheringManager.getTetheredIfaces.
             final BluetoothPan pan = mBluetoothPan.get();
             tetherOn = pan != null && pan.isTetheringOn();
         }
diff --git a/src/com/android/settings/network/UsbTetherPreferenceController.java b/src/com/android/settings/network/UsbTetherPreferenceController.java
index 7cf1ddf..7a5cc21 100644
--- a/src/com/android/settings/network/UsbTetherPreferenceController.java
+++ b/src/com/android/settings/network/UsbTetherPreferenceController.java
@@ -68,7 +68,7 @@
 
     @Override
     public boolean shouldShow() {
-        String[] usbRegexs = mCm.getTetherableUsbRegexs();
+        String[] usbRegexs = mTm.getTetherableUsbRegexs();
         return  usbRegexs != null && usbRegexs.length != 0 && !Utils.isMonkeyRunning();
     }
 
diff --git a/src/com/android/settings/network/WifiTetherDisablePreferenceController.java b/src/com/android/settings/network/WifiTetherDisablePreferenceController.java
index 38e831b..783f78f 100644
--- a/src/com/android/settings/network/WifiTetherDisablePreferenceController.java
+++ b/src/com/android/settings/network/WifiTetherDisablePreferenceController.java
@@ -68,7 +68,7 @@
 
     @Override
     public boolean shouldShow() {
-        final String[] wifiRegexs = mCm.getTetherableWifiRegexs();
+        final String[] wifiRegexs = mTm.getTetherableWifiRegexs();
         return wifiRegexs != null && wifiRegexs.length != 0 && !Utils.isMonkeyRunning()
                 && getTetheringStateOfOtherInterfaces() != TetherEnabler.TETHERING_OFF;
     }
diff --git a/src/com/android/settings/notification/history/NotificationHistoryActivity.java b/src/com/android/settings/notification/history/NotificationHistoryActivity.java
index d5745ac..4958f1b 100644
--- a/src/com/android/settings/notification/history/NotificationHistoryActivity.java
+++ b/src/com/android/settings/notification/history/NotificationHistoryActivity.java
@@ -21,7 +21,6 @@
 import static androidx.core.view.accessibility.AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUSED;
 
 import android.app.ActionBar;
-import android.app.Activity;
 import android.app.ActivityManager;
 import android.app.INotificationManager;
 import android.content.ComponentName;
@@ -55,6 +54,7 @@
 import com.android.internal.logging.UiEventLoggerImpl;
 import com.android.settings.R;
 import com.android.settings.notification.NotificationBackend;
+import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity;
 import com.android.settingslib.utils.ThreadUtils;
 import com.android.settingslib.widget.MainSwitchBar;
 import com.android.settingslib.widget.OnMainSwitchChangeListener;
@@ -65,7 +65,7 @@
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 
-public class NotificationHistoryActivity extends Activity {
+public class NotificationHistoryActivity extends CollapsingToolbarBaseActivity {
 
     private static String TAG = "NotifHistory";
 
diff --git a/src/com/android/settings/security/UriAuthenticationPolicyAdapter.java b/src/com/android/settings/security/UriAuthenticationPolicyAdapter.java
index 8aeb074..0a6c398 100644
--- a/src/com/android/settings/security/UriAuthenticationPolicyAdapter.java
+++ b/src/com/android/settings/security/UriAuthenticationPolicyAdapter.java
@@ -74,7 +74,7 @@
     public void onBindViewHolder(UriAuthenticationPolicyAdapter.UriViewHolder holder,
             int position) {
         Uri uri = mUris.get(position);
-        holder.mUriNameView.setText(uri.toString());
+        holder.mUriNameView.setText(Uri.decode(uri.toString()));
     }
 
     @Override
diff --git a/src/com/android/settings/widget/HighlightablePreferenceGroupAdapter.java b/src/com/android/settings/widget/HighlightablePreferenceGroupAdapter.java
index e89e793..b3ae609 100644
--- a/src/com/android/settings/widget/HighlightablePreferenceGroupAdapter.java
+++ b/src/com/android/settings/widget/HighlightablePreferenceGroupAdapter.java
@@ -39,10 +39,14 @@
 import com.android.settings.R;
 import com.android.settings.SettingsPreferenceFragment;
 
+import com.google.android.material.appbar.AppBarLayout;
+
 public class HighlightablePreferenceGroupAdapter extends PreferenceGroupAdapter {
 
     private static final String TAG = "HighlightableAdapter";
     @VisibleForTesting
+    static final long DELAY_COLLAPSE_DURATION_MILLIS = 300L;
+    @VisibleForTesting
     static final long DELAY_HIGHLIGHT_DURATION_MILLIS = 600L;
     private static final long HIGHLIGHT_DURATION = 15000L;
     private static final long HIGHLIGHT_FADE_OUT_DURATION = 500L;
@@ -115,7 +119,7 @@
         View v = holder.itemView;
         if (position == mHighlightPosition
                 && (mHighlightKey != null
-                        && TextUtils.equals(mHighlightKey, getItem(position).getKey()))) {
+                && TextUtils.equals(mHighlightKey, getItem(position).getKey()))) {
             // This position should be highlighted. If it's highlighted before - skip animation.
             addHighlightBackground(v, !mFadeInAnimated);
         } else if (Boolean.TRUE.equals(v.getTag(R.id.preference_highlighted))) {
@@ -124,15 +128,26 @@
         }
     }
 
-    public void requestHighlight(View root, RecyclerView recyclerView) {
+    /**
+     * A function can highlight a specific setting in recycler view.
+     * note: Before highlighting a setting, screen collapses tool bar with an animation.
+     */
+    public void requestHighlight(View root, RecyclerView recyclerView, AppBarLayout appBarLayout) {
         if (mHighlightRequested || recyclerView == null || TextUtils.isEmpty(mHighlightKey)) {
             return;
         }
+        final int position = getPreferenceAdapterPosition(mHighlightKey);
+        if (position < 0) {
+            return;
+        }
+
+        if (appBarLayout != null) {
+            root.postDelayed(() -> {
+                appBarLayout.setExpanded(false, true);
+            }, DELAY_COLLAPSE_DURATION_MILLIS);
+        }
+
         root.postDelayed(() -> {
-            final int position = getPreferenceAdapterPosition(mHighlightKey);
-            if (position < 0) {
-                return;
-            }
             mHighlightRequested = true;
             recyclerView.smoothScrollToPosition(position);
             mHighlightPosition = position;
diff --git a/src/com/android/settings/widget/SettingsMainSwitchPreference.java b/src/com/android/settings/widget/SettingsMainSwitchPreference.java
index 2a7aa73..76f9b41 100644
--- a/src/com/android/settings/widget/SettingsMainSwitchPreference.java
+++ b/src/com/android/settings/widget/SettingsMainSwitchPreference.java
@@ -44,7 +44,8 @@
     private final List<OnMainSwitchChangeListener> mSwitchChangeListeners = new ArrayList<>();
 
     private SettingsMainSwitchBar mMainSwitchBar;
-    private String mTitle;
+    private CharSequence mTitle;
+    private boolean mIsVisible;
 
     private RestrictedLockUtils.EnforcedAdmin mEnforcedAdmin;
 
@@ -77,16 +78,22 @@
         holder.setDividerAllowedBelow(false);
 
         mMainSwitchBar = (SettingsMainSwitchBar) holder.findViewById(R.id.main_switch_bar);
+
         mMainSwitchBar.show();
         updateStatus(isChecked());
         registerListenerToSwitchBar();
+
+        if (!mIsVisible) {
+            mMainSwitchBar.hide();
+        }
     }
 
     private void init(Context context, AttributeSet attrs) {
         setLayoutResource(R.layout.preference_widget_main_switch);
+        mIsVisible = true;
 
         if (attrs != null) {
-            TypedArray a = context.obtainStyledAttributes(attrs,
+            final TypedArray a = context.obtainStyledAttributes(attrs,
                     androidx.preference.R.styleable.Preference, 0/*defStyleAttr*/,
                     0/*defStyleRes*/);
             final CharSequence title = TypedArrayUtils.getText(a,
@@ -99,6 +106,14 @@
         }
     }
 
+    @Override
+    public void setChecked(boolean checked) {
+        super.setChecked(checked);
+        if (mMainSwitchBar != null) {
+            mMainSwitchBar.setChecked(checked);
+        }
+    }
+
     /**
      * Return the SettingsMainSwitchBar
      */
@@ -106,11 +121,9 @@
         return mMainSwitchBar;
     }
 
-    /**
-     * Set the preference title text
-     */
-    public void setTitle(String text) {
-        mTitle = text;
+    @Override
+    public void setTitle(CharSequence title) {
+        mTitle = title;
         if (mMainSwitchBar != null) {
             mMainSwitchBar.setTitle(mTitle);
         }
@@ -133,6 +146,7 @@
      * Show the MainSwitchBar
      */
     public void show() {
+        mIsVisible = true;
         if (mMainSwitchBar != null) {
             mMainSwitchBar.show();
         }
@@ -142,6 +156,7 @@
      * Hide the MainSwitchBar
      */
     public void hide() {
+        mIsVisible = false;
         if (mMainSwitchBar != null) {
             mMainSwitchBar.hide();
         }
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index 34067e9..5545de6 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -63,7 +63,7 @@
 import com.android.settings.core.SubSettingLauncher;
 import com.android.settings.datausage.DataUsagePreference;
 import com.android.settings.datausage.DataUsageUtils;
-import com.android.settings.location.ScanningSettings;
+import com.android.settings.location.LocationServices;
 import com.android.settings.overlay.FeatureFactory;
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settings.widget.MainSwitchBarController;
@@ -921,8 +921,8 @@
                 : getText(R.string.wifi_scan_notify_text_scanning_off);
         final LinkifyUtils.OnClickListener clickListener =
                 () -> new SubSettingLauncher(getContext())
-                        .setDestination(ScanningSettings.class.getName())
-                        .setTitleRes(R.string.location_scanning_screen_title)
+                        .setDestination(LocationServices.class.getName())
+                        .setTitleRes(R.string.location_services_screen_title)
                         .setSourceMetricsCategory(getMetricsCategory())
                         .launch();
         mStatusMessagePreference.setText(title, description, clickListener);
diff --git a/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java b/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java
index 735fecc..024c1c3 100644
--- a/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java
+++ b/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java
@@ -55,14 +55,15 @@
 import com.android.settings.Utils;
 import com.android.settings.core.SubSettingLauncher;
 import com.android.settings.network.ims.WifiCallingQueryImsState;
-import com.android.settings.widget.SwitchBar;
+import com.android.settings.widget.SettingsMainSwitchBar;
+import com.android.settingslib.widget.OnMainSwitchChangeListener;
 
 /**
  * This is the inner class of {@link WifiCallingSettings} fragment.
  * The preference screen lets you enable/disable Wi-Fi Calling and change Wi-Fi Calling mode.
  */
 public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
-        implements SwitchBar.OnSwitchChangeListener,
+        implements OnMainSwitchChangeListener,
         Preference.OnPreferenceChangeListener {
     private static final String TAG = "WifiCallingForSub";
 
@@ -85,8 +86,7 @@
     public static final int LAUCH_APP_UPDATE = 1;
 
     //UI objects
-    private SwitchBar mSwitchBar;
-    private Switch mSwitch;
+    private SettingsMainSwitchBar mSwitchBar;
     private ListWithEntrySummaryPreference mButtonWfcMode;
     private ListWithEntrySummaryPreference mButtonWfcRoamingMode;
     private Preference mUpdateAddress;
@@ -190,7 +190,6 @@
 
         mSwitchBar = getView().findViewById(R.id.switch_bar);
         mSwitchBar.show();
-        mSwitch = mSwitchBar.getSwitch();
     }
 
     @Override
@@ -296,7 +295,7 @@
         mButtonWfcMode = findPreference(BUTTON_WFC_MODE);
         mButtonWfcMode.setOnPreferenceChangeListener(this);
 
-        mButtonWfcRoamingMode =  findPreference(BUTTON_WFC_ROAMING_MODE);
+        mButtonWfcRoamingMode = findPreference(BUTTON_WFC_ROAMING_MODE);
         mButtonWfcRoamingMode.setOnPreferenceChangeListener(this);
 
         mUpdateAddress = findPreference(PREFERENCE_EMERGENCY_ADDRESS);
@@ -403,7 +402,7 @@
         final WifiCallingQueryImsState queryIms = queryImsState(mSubId);
         final boolean wfcEnabled = queryIms.isEnabledByUser()
                 && queryIms.isAllowUserControl();
-        mSwitch.setChecked(wfcEnabled);
+        mSwitchBar.setChecked(wfcEnabled);
         final int wfcMode = mImsMmTelManager.getVoWiFiModeSetting();
         final int wfcRoamingMode = mImsMmTelManager.getVoWiFiRoamingModeSetting();
         mButtonWfcMode.setValue(Integer.toString(wfcMode));
diff --git a/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java b/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java
index 0989939..2d9d444 100644
--- a/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java
+++ b/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java
@@ -63,7 +63,7 @@
 import androidx.preference.PreferenceFragmentCompat;
 import androidx.preference.PreferenceScreen;
 
-import com.android.net.module.util.NetUtils;
+import com.android.net.module.util.Inet4AddressUtils;
 import com.android.settings.R;
 import com.android.settings.Utils;
 import com.android.settings.core.FeatureFlags;
@@ -99,7 +99,6 @@
 import java.net.Inet4Address;
 import java.net.Inet6Address;
 import java.net.InetAddress;
-import java.net.UnknownHostException;
 import java.time.Duration;
 import java.time.Instant;
 import java.time.ZonedDateTime;
@@ -873,10 +872,8 @@
 
     private static String ipv4PrefixLengthToSubnetMask(int prefixLength) {
         try {
-            InetAddress all = InetAddress.getByAddress(
-                    new byte[]{(byte) 255, (byte) 255, (byte) 255, (byte) 255});
-            return NetUtils.getNetworkPart(all, prefixLength).getHostAddress();
-        } catch (UnknownHostException e) {
+            return Inet4AddressUtils.getPrefixMaskAsInet4Address(prefixLength).getHostAddress();
+        } catch (IllegalArgumentException e) {
             return null;
         }
     }
diff --git a/src/com/android/settings/wifi/tether/WifiTetherBasePreferenceController.java b/src/com/android/settings/wifi/tether/WifiTetherBasePreferenceController.java
index 7ba0216..46da097 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherBasePreferenceController.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherBasePreferenceController.java
@@ -17,7 +17,7 @@
 package com.android.settings.wifi.tether;
 
 import android.content.Context;
-import android.net.ConnectivityManager;
+import android.net.TetheringManager;
 import android.net.wifi.WifiManager;
 
 import androidx.preference.Preference;
@@ -36,7 +36,7 @@
 
     protected final WifiManager mWifiManager;
     protected final String[] mWifiRegexs;
-    protected final ConnectivityManager mCm;
+    protected final TetheringManager mTm;
     protected final OnTetherConfigUpdateListener mListener;
 
     protected Preference mPreference;
@@ -46,8 +46,8 @@
         super(context);
         mListener = listener;
         mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
-        mCm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
-        mWifiRegexs = mCm.getTetherableWifiRegexs();
+        mTm = (TetheringManager) context.getSystemService(Context.TETHERING_SERVICE);
+        mWifiRegexs = mTm.getTetherableWifiRegexs();
     }
 
     @Override
diff --git a/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java b/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java
index 5049002..70b6a45 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java
@@ -18,7 +18,7 @@
 
 import android.annotation.NonNull;
 import android.content.Context;
-import android.net.ConnectivityManager;
+import android.net.TetheringManager;
 import android.net.wifi.SoftApConfiguration;
 import android.net.wifi.WifiClient;
 import android.net.wifi.WifiManager;
@@ -44,7 +44,7 @@
 
     private static final String WIFI_TETHER_SETTINGS = "wifi_tether";
 
-    private final ConnectivityManager mConnectivityManager;
+    private final TetheringManager mTetheringManager;
     private final String[] mWifiRegexs;
     private final WifiManager mWifiManager;
     private final Lifecycle mLifecycle;
@@ -62,10 +62,9 @@
     WifiTetherPreferenceController(Context context, Lifecycle lifecycle,
             boolean initSoftApManager) {
         super(context);
-        mConnectivityManager =
-                (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+        mTetheringManager = context.getSystemService(TetheringManager.class);
         mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
-        mWifiRegexs = mConnectivityManager.getTetherableWifiRegexs();
+        mWifiRegexs = mTetheringManager.getTetherableWifiRegexs();
         mLifecycle = lifecycle;
         if (lifecycle != null) {
             lifecycle.addObserver(this);
diff --git a/src/com/android/settings/wifi/tether/WifiTetherSettings.java b/src/com/android/settings/wifi/tether/WifiTetherSettings.java
index 0529b7a..939f077 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherSettings.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherSettings.java
@@ -16,7 +16,7 @@
 
 package com.android.settings.wifi.tether;
 
-import static android.net.ConnectivityManager.ACTION_TETHER_STATE_CHANGED;
+import static android.net.TetheringManager.ACTION_TETHER_STATE_CHANGED;
 import static android.net.wifi.WifiManager.WIFI_AP_STATE_CHANGED_ACTION;
 
 import android.app.settings.SettingsEnums;
diff --git a/tests/robotests/Android.bp b/tests/robotests/Android.bp
index a0e9820..337bad7 100644
--- a/tests/robotests/Android.bp
+++ b/tests/robotests/Android.bp
@@ -97,3 +97,15 @@
         "SettingsLib-search",
     ],
 }
+
+java_library {
+    name: "Settings-robo-testutils",
+    srcs: ["src/com/android/settings/testutils/**/*.java"],
+
+    libs: [
+        "Settings-core",
+        "Robolectric_all-target",
+        "mockito-robolectric-prebuilt",
+        "truth-prebuilt",
+    ],
+}
diff --git a/tests/robotests/src/com/android/settings/AllInOneTetherSettingsTest.java b/tests/robotests/src/com/android/settings/AllInOneTetherSettingsTest.java
index c9a8c44..cd33663 100644
--- a/tests/robotests/src/com/android/settings/AllInOneTetherSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/AllInOneTetherSettingsTest.java
@@ -33,6 +33,7 @@
 
 import android.content.Context;
 import android.net.ConnectivityManager;
+import android.net.TetheringManager;
 import android.net.wifi.SoftApConfiguration;
 import android.os.UserHandle;
 import android.os.UserManager;
@@ -74,6 +75,8 @@
     @Mock
     private ConnectivityManager mConnectivityManager;
     @Mock
+    private TetheringManager mTetheringManager;
+    @Mock
     private UserManager mUserManager;
     @Mock
     private WifiTetherSecurityPreferenceController mSecurityPreferenceController;
@@ -89,10 +92,12 @@
         MockitoAnnotations.initMocks(this);
         doReturn(mConnectivityManager)
                 .when(mContext).getSystemService(Context.CONNECTIVITY_SERVICE);
-        doReturn(WIFI_REGEXS).when(mConnectivityManager).getTetherableWifiRegexs();
-        doReturn(USB_REGEXS).when(mConnectivityManager).getTetherableUsbRegexs();
-        doReturn(BT_REGEXS).when(mConnectivityManager).getTetherableBluetoothRegexs();
-        doReturn(ETHERNET_REGEXS).when(mConnectivityManager).getTetherableIfaces();
+        doReturn(mTetheringManager)
+                .when(mContext).getSystemService(Context.TETHERING_SERVICE);
+        doReturn(WIFI_REGEXS).when(mTetheringManager).getTetherableWifiRegexs();
+        doReturn(USB_REGEXS).when(mTetheringManager).getTetherableUsbRegexs();
+        doReturn(BT_REGEXS).when(mTetheringManager).getTetherableBluetoothRegexs();
+        doReturn(ETHERNET_REGEXS).when(mTetheringManager).getTetherableIfaces();
         doReturn(mUserManager).when(mContext).getSystemService(Context.USER_SERVICE);
         // Assume the feature is enabled for most test cases.
         FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, true);
diff --git a/tests/robotests/src/com/android/settings/TetherSettingsTest.java b/tests/robotests/src/com/android/settings/TetherSettingsTest.java
index f217e21..0948cfa 100644
--- a/tests/robotests/src/com/android/settings/TetherSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/TetherSettingsTest.java
@@ -34,6 +34,7 @@
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.net.ConnectivityManager;
+import android.net.TetheringManager;
 import android.net.wifi.WifiManager;
 import android.os.UserHandle;
 import android.os.UserManager;
@@ -66,6 +67,8 @@
     private ConnectivityManager mConnectivityManager;
     @Mock
     private UserManager mUserManager;
+    @Mock
+    private TetheringManager mTetheringManager;
 
     @Before
     public void setUp() {
@@ -76,11 +79,13 @@
                 .when(mContext).getSystemService(Context.CONNECTIVITY_SERVICE);
         doReturn(mUserManager)
                 .when(mContext).getSystemService(Context.USER_SERVICE);
+        doReturn(mTetheringManager)
+                .when(mContext).getSystemService(Context.TETHERING_SERVICE);
 
         setupIsTetherAvailable(true);
 
-        when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
-        when(mConnectivityManager.getTetherableBluetoothRegexs()).thenReturn(new String[0]);
+        when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
+        when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[0]);
     }
 
     @Test
@@ -110,7 +115,7 @@
 
     @Test
     public void testTetherNonIndexableKeys_usbNotAvailable_usbKeyReturned() {
-        when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
+        when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
 
         final List<String> niks =
             TetherSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
@@ -123,7 +128,7 @@
         FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, false);
         // We can ignore the condition of Utils.isMonkeyRunning()
         // In normal case, monkey and robotest should not execute at the same time
-        when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(new String[]{"fakeRegex"});
+        when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[]{"fakeRegex"});
 
         final List<String> niks =
             TetherSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
@@ -133,7 +138,7 @@
 
     @Test
     public void testTetherNonIndexableKeys_bluetoothNotAvailable_bluetoothKeyReturned() {
-        when(mConnectivityManager.getTetherableBluetoothRegexs()).thenReturn(new String[0]);
+        when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[0]);
 
         final List<String> niks =
             TetherSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
@@ -144,7 +149,7 @@
     @Test
     public void testTetherNonIndexableKeys_bluetoothAvailable_bluetoothKeyNotReturned() {
         FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, false);
-        when(mConnectivityManager.getTetherableBluetoothRegexs())
+        when(mTetheringManager.getTetherableBluetoothRegexs())
                 .thenReturn(new String[]{"fakeRegex"});
 
         final List<String> niks =
@@ -235,11 +240,11 @@
     }
 
     private void updateOnlyBluetoothState(TetherSettings tetherSettings) {
-        doReturn(mConnectivityManager).when(tetherSettings)
-            .getSystemService(Context.CONNECTIVITY_SERVICE);
-        when(mConnectivityManager.getTetherableIfaces()).thenReturn(new String[0]);
-        when(mConnectivityManager.getTetheredIfaces()).thenReturn(new String[0]);
-        when(mConnectivityManager.getTetheringErroredIfaces()).thenReturn(new String[0]);
+        doReturn(mTetheringManager).when(tetherSettings)
+            .getSystemService(Context.TETHERING_SERVICE);
+        when(mTetheringManager.getTetherableIfaces()).thenReturn(new String[0]);
+        when(mTetheringManager.getTetheredIfaces()).thenReturn(new String[0]);
+        when(mTetheringManager.getTetheringErroredIfaces()).thenReturn(new String[0]);
         doNothing().when(tetherSettings).updateUsbState(any(String[].class), any(String[].class),
                 any(String[].class));
         doNothing().when(tetherSettings).updateEthernetState(any(String[].class),
diff --git a/tests/robotests/src/com/android/settings/applications/AppStateAppOpsBridgeTest.java b/tests/robotests/src/com/android/settings/applications/AppStateAppOpsBridgeTest.java
index 3f4175e..8f41884 100644
--- a/tests/robotests/src/com/android/settings/applications/AppStateAppOpsBridgeTest.java
+++ b/tests/robotests/src/com/android/settings/applications/AppStateAppOpsBridgeTest.java
@@ -25,10 +25,13 @@
 import android.content.Context;
 import android.content.pm.IPackageManager;
 import android.os.RemoteException;
+import android.os.UserHandle;
 import android.os.UserManager;
 
 import com.android.settingslib.applications.ApplicationsState.AppEntry;
 
+import com.google.common.truth.Truth;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -60,6 +63,58 @@
         // should not crash
     }
 
+    @Test
+    public void permissionState_modeDefault_IsPermissible() {
+        AppStateAppOpsBridge.PermissionState permissionState =
+                new AppStateAppOpsBridge.PermissionState("pkg1", UserHandle.of(123));
+        permissionState.appOpMode = AppOpsManager.MODE_DEFAULT;
+
+        permissionState.staticPermissionGranted = true;
+        Truth.assertThat(permissionState.isPermissible()).isTrue();
+
+        permissionState.staticPermissionGranted = false;
+        Truth.assertThat(permissionState.isPermissible()).isFalse();
+    }
+
+    @Test
+    public void permissionState_modeErrored_IsPermissible() {
+        AppStateAppOpsBridge.PermissionState permissionState =
+                new AppStateAppOpsBridge.PermissionState("pkg1", UserHandle.of(123));
+        permissionState.appOpMode = AppOpsManager.MODE_ERRORED;
+
+        permissionState.staticPermissionGranted = true;
+        Truth.assertThat(permissionState.isPermissible()).isFalse();
+
+        permissionState.staticPermissionGranted = false;
+        Truth.assertThat(permissionState.isPermissible()).isFalse();
+    }
+
+    @Test
+    public void permissionState_modeAllowed_IsPermissible() {
+        AppStateAppOpsBridge.PermissionState permissionState =
+                new AppStateAppOpsBridge.PermissionState("pkg1", UserHandle.of(123));
+        permissionState.appOpMode = AppOpsManager.MODE_ALLOWED;
+
+        permissionState.staticPermissionGranted = true;
+        Truth.assertThat(permissionState.isPermissible()).isTrue();
+
+        permissionState.staticPermissionGranted = false;
+        Truth.assertThat(permissionState.isPermissible()).isTrue();
+    }
+
+    @Test
+    public void permissionState_modeIgnored_IsPermissible() {
+        AppStateAppOpsBridge.PermissionState permissionState =
+                new AppStateAppOpsBridge.PermissionState("pkg1", UserHandle.of(123));
+        permissionState.appOpMode = AppOpsManager.MODE_IGNORED;
+
+        permissionState.staticPermissionGranted = true;
+        Truth.assertThat(permissionState.isPermissible()).isFalse();
+
+        permissionState.staticPermissionGranted = false;
+        Truth.assertThat(permissionState.isPermissible()).isFalse();
+    }
+
     private class TestAppStateAppOpsBridge extends AppStateAppOpsBridge {
         private TestAppStateAppOpsBridge() {
             super(mContext, null, null, AppOpsManager.OP_SYSTEM_ALERT_WINDOW,
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/AlarmsAndRemindersDetailsTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/AlarmsAndRemindersDetailsTest.java
new file mode 100644
index 0000000..c3bcead
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/AlarmsAndRemindersDetailsTest.java
@@ -0,0 +1,125 @@
+/*
+ * 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.applications.appinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageInfo;
+
+import com.android.settings.applications.AppStateAlarmsAndRemindersBridge;
+import com.android.settings.applications.AppStateAppOpsBridge;
+import com.android.settingslib.RestrictedSwitchPreference;
+
+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.util.ReflectionHelpers;
+
+@RunWith(RobolectricTestRunner.class)
+public class AlarmsAndRemindersDetailsTest {
+
+    @Mock
+    private RestrictedSwitchPreference mSwitchPref;
+    @Mock
+    private PackageInfo mPackageInfo;
+    @Mock
+    private AppStateAlarmsAndRemindersBridge mAppStateBridge;
+    @Mock
+    private AppStateAppOpsBridge.PermissionState mPermissionState;
+
+    private AlarmsAndRemindersDetails mFragment = new AlarmsAndRemindersDetails();
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+
+        ReflectionHelpers.setField(mFragment, "mSwitchPref", mSwitchPref);
+        ReflectionHelpers.setField(mFragment, "mAppBridge", mAppStateBridge);
+    }
+
+    @Test
+    public void refreshUi_noPackageInfo_shouldReturnFalseAndNoCrash() {
+        mFragment.refreshUi();
+
+        assertThat(mFragment.refreshUi()).isFalse();
+        // should not crash
+    }
+
+    @Test
+    public void refreshUi_noApplicationInfo_shouldReturnFalseAndNoCrash() {
+        ReflectionHelpers.setField(mFragment, "mPackageInfo", mPackageInfo);
+
+        mFragment.refreshUi();
+
+        assertThat(mFragment.refreshUi()).isFalse();
+        // should not crash
+    }
+
+    @Test
+    public void refreshUi_hasApplicationInfo_shouldReturnTrue() {
+        ReflectionHelpers.setField(mFragment, "mPackageInfo", mPackageInfo);
+        mPackageInfo.applicationInfo = new ApplicationInfo();
+        when(mAppStateBridge.createPermissionState(nullable(String.class), anyInt()))
+                .thenReturn(mPermissionState);
+
+        mFragment.refreshUi();
+
+        assertThat(mFragment.refreshUi()).isTrue();
+    }
+
+    @Test
+    public void refreshUi_switchPreferenceEnabled() {
+        ReflectionHelpers.setField(mFragment, "mPackageInfo", mPackageInfo);
+        mPackageInfo.applicationInfo = new ApplicationInfo();
+        when(mAppStateBridge.createPermissionState(nullable(String.class), anyInt()))
+                .thenReturn(mPermissionState);
+        mPermissionState.permissionDeclared = false;
+
+        mFragment.refreshUi();
+        verify(mSwitchPref).setEnabled(false);
+
+        mPermissionState.permissionDeclared = true;
+
+        mFragment.refreshUi();
+        verify(mSwitchPref).setEnabled(true);
+    }
+
+    @Test
+    public void refreshUi_switchPreferenceChecked() {
+        ReflectionHelpers.setField(mFragment, "mPackageInfo", mPackageInfo);
+        mPackageInfo.applicationInfo = new ApplicationInfo();
+        when(mAppStateBridge.createPermissionState(nullable(String.class), anyInt()))
+                .thenReturn(mPermissionState);
+
+        when(mPermissionState.isPermissible()).thenReturn(true);
+        mFragment.refreshUi();
+        verify(mSwitchPref).setChecked(true);
+
+        when(mPermissionState.isPermissible()).thenReturn(false);
+        mFragment.refreshUi();
+        verify(mSwitchPref).setChecked(false);
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/applications/specialaccess/HighPowerAppsControllerTest.java b/tests/robotests/src/com/android/settings/applications/specialaccess/HighPowerAppsControllerTest.java
deleted file mode 100644
index 0ed68cb..0000000
--- a/tests/robotests/src/com/android/settings/applications/specialaccess/HighPowerAppsControllerTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2017 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.applications.specialaccess;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.spy;
-
-import android.content.Context;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
-import org.robolectric.annotation.Config;
-
-@RunWith(RobolectricTestRunner.class)
-public class HighPowerAppsControllerTest {
-
-    private Context mContext;
-    private HighPowerAppsController mController;
-
-    @Before
-    public void setUp() {
-        MockitoAnnotations.initMocks(this);
-        mContext = spy(RuntimeEnvironment.application.getApplicationContext());
-        mController = new HighPowerAppsController(mContext, "key");
-    }
-
-    @Test
-    public void testHighPowerApps_byDefault_shouldBeShown() {
-        assertThat(mController.isAvailable()).isTrue();
-    }
-
-    @Test
-    @Config(qualifiers = "mcc999")
-    public void testHighPowerApps_ifDisabled_shouldNotBeShown() {
-        assertThat(mController.isAvailable()).isFalse();
-    }
-}
diff --git a/tests/robotests/src/com/android/settings/display/PeakRefreshRatePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/PeakRefreshRatePreferenceControllerTest.java
index cae7d89..aaeeea4 100644
--- a/tests/robotests/src/com/android/settings/display/PeakRefreshRatePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/PeakRefreshRatePreferenceControllerTest.java
@@ -24,6 +24,7 @@
 
 import android.content.Context;
 import android.provider.Settings;
+import android.view.Display;
 
 import androidx.preference.SwitchPreference;
 
@@ -102,6 +103,21 @@
         assertThat(mController.isChecked()).isFalse();
     }
 
+    @Test
+    public void findPeakRefreshRate_moreThanOneHigherThanDefault() {
+        Display.Mode lower = new Display.Mode(0, 0, 0, DEFAULT_REFRESH_RATE - 1);
+        Display.Mode def = new Display.Mode(0, 0, 0, DEFAULT_REFRESH_RATE);
+        Display.Mode higher = new Display.Mode(0, 0, 0, DEFAULT_REFRESH_RATE + 1);
+        Display.Mode higher1 = new Display.Mode(0, 0, 0, DEFAULT_REFRESH_RATE + 2);
+
+        assertThat(mController.findPeakRefreshRate(
+                new Display.Mode[] {lower, def, higher, higher1}))
+                .isEqualTo(DEFAULT_REFRESH_RATE + 2);
+        assertThat(mController.findPeakRefreshRate(
+                new Display.Mode[] {lower, def, higher1, higher}))
+                .isEqualTo(DEFAULT_REFRESH_RATE + 2);
+    }
+
     private void enableSmoothDisplayPreference() {
         mController.mPeakRefreshRate = 88f;
 
diff --git a/tests/robotests/src/com/android/settings/enterprise/GlobalHttpProxyPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/GlobalHttpProxyPreferenceControllerTest.java
index 11676a2..71eaffc 100644
--- a/tests/robotests/src/com/android/settings/enterprise/GlobalHttpProxyPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/GlobalHttpProxyPreferenceControllerTest.java
@@ -24,12 +24,9 @@
 import android.net.ConnectivityManager;
 import android.net.ProxyInfo;
 
-import androidx.preference.Preference;
-
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.mockito.Answers;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.RobolectricTestRunner;
@@ -39,7 +36,7 @@
 
     private static final String KEY_GLOBAL_HTTP_PROXY = "global_http_proxy";
 
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+    @Mock
     private Context mContext;
     @Mock
     private ConnectivityManager mCm;
@@ -49,6 +46,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
+        when(mContext.getSystemService(ConnectivityManager.class)).thenReturn(mCm);
         mController = new GlobalHttpProxyPreferenceController(mContext);
     }
 
@@ -62,12 +60,6 @@
     }
 
     @Test
-    public void testHandlePreferenceTreeClick() {
-        assertThat(mController.handlePreferenceTreeClick(new Preference(mContext, null, 0, 0)))
-                .isFalse();
-    }
-
-    @Test
     public void testGetPreferenceKey() {
         assertThat(mController.getPreferenceKey()).isEqualTo(KEY_GLOBAL_HTTP_PROXY);
     }
diff --git a/tests/robotests/src/com/android/settings/location/ScanningSettingsTest.java b/tests/robotests/src/com/android/settings/location/LocationServicesTest.java
similarity index 90%
rename from tests/robotests/src/com/android/settings/location/ScanningSettingsTest.java
rename to tests/robotests/src/com/android/settings/location/LocationServicesTest.java
index 649726a..f115845 100644
--- a/tests/robotests/src/com/android/settings/location/ScanningSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/location/LocationServicesTest.java
@@ -32,7 +32,7 @@
 import java.util.List;
 
 @RunWith(RobolectricTestRunner.class)
-public class ScanningSettingsTest {
+public class LocationServicesTest {
 
     private Context mContext;
 
@@ -43,10 +43,10 @@
 
     @Test
     public void searchProvider_shouldIndexDefaultXml() {
-        final List<SearchIndexableResource> sir = ScanningSettings.SEARCH_INDEX_DATA_PROVIDER
+        final List<SearchIndexableResource> sir = LocationServices.SEARCH_INDEX_DATA_PROVIDER
                 .getXmlResourcesToIndex(mContext, true /* enabled */);
 
         assertThat(sir).hasSize(1);
-        assertThat(sir.get(0).xmlResId).isEqualTo(R.xml.location_scanning);
+        assertThat(sir.get(0).xmlResId).isEqualTo(R.xml.location_services);
     }
 }
diff --git a/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java
index 71a80de..5feee60 100644
--- a/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java
@@ -24,19 +24,17 @@
 
 import android.content.Context;
 import android.graphics.drawable.Drawable;
-import android.provider.DeviceConfig;
 import android.view.LayoutInflater;
 import android.view.View;
-import android.widget.ImageView;
 import android.widget.TextView;
 
+import androidx.preference.PreferenceCategory;
 import androidx.preference.PreferenceScreen;
 
 import com.android.settings.R;
-import com.android.settings.Utils;
+import com.android.settings.dashboard.DashboardFragment;
 import com.android.settings.testutils.shadow.ShadowDeviceConfig;
 import com.android.settingslib.location.RecentLocationAccesses;
-import com.android.settingslib.widget.LayoutPreference;
 
 import org.junit.After;
 import org.junit.Before;
@@ -55,11 +53,14 @@
 @RunWith(RobolectricTestRunner.class)
 @Config(shadows = {ShadowDeviceConfig.class})
 public class RecentLocationAccessPreferenceControllerTest {
+    private static final String PREFERENCE_KEY = "test_preference_key";
     @Mock
-    private LayoutPreference mLayoutPreference;
+    private PreferenceCategory mLayoutPreference;
     @Mock
     private PreferenceScreen mScreen;
     @Mock
+    private DashboardFragment mDashboardFragment;
+    @Mock
     private RecentLocationAccesses mRecentLocationApps;
 
     private Context mContext;
@@ -71,15 +72,16 @@
         MockitoAnnotations.initMocks(this);
         mContext = spy(RuntimeEnvironment.application);
         mController = spy(
-                new RecentLocationAccessPreferenceController(mContext, mRecentLocationApps));
+                new RecentLocationAccessPreferenceController(mContext, PREFERENCE_KEY,
+                        mRecentLocationApps));
+        mController.init(mDashboardFragment);
         final String key = mController.getPreferenceKey();
         mAppEntitiesHeaderView = LayoutInflater.from(mContext).inflate(
                 R.layout.app_entities_header, null /* root */);
         when(mScreen.findPreference(key)).thenReturn(mLayoutPreference);
         when(mLayoutPreference.getKey()).thenReturn(key);
         when(mLayoutPreference.getContext()).thenReturn(mContext);
-        when(mLayoutPreference.findViewById(R.id.app_entities_header)).thenReturn(
-                mAppEntitiesHeaderView);
+        when(mDashboardFragment.getContext()).thenReturn(mContext);
     }
 
     @After
@@ -88,16 +90,7 @@
     }
 
     @Test
-    public void isAvailable_permissionHubNotSet_shouldReturnFalse() {
-        // We have not yet set the property to show the Permissions Hub.
-        assertThat(mController.isAvailable()).isEqualTo(false);
-    }
-
-    @Test
-    public void isAvailable_permissionHubEnabled_shouldReturnTrue() {
-        DeviceConfig.setProperty(DeviceConfig.NAMESPACE_PRIVACY,
-                Utils.PROPERTY_PERMISSIONS_HUB_ENABLED, "true", true);
-
+    public void isAvailable_shouldReturnTrue() {
         assertThat(mController.isAvailable()).isEqualTo(true);
     }
 
@@ -118,39 +111,6 @@
         assertThat(details.hasOnClickListeners()).isTrue();
     }
 
-    @Test
-    public void updateState_whenAppListMoreThanThree_shouldDisplayTopThreeApps() {
-        final List<RecentLocationAccesses.Access> accesses = createMockAccesses(6);
-        doReturn(accesses).when(mRecentLocationApps).getAppListSorted();
-        mController.displayPreference(mScreen);
-        mController.updateState(mLayoutPreference);
-
-        // The widget can display the top 3 apps from the list when there're more than 3.
-        final View app1View = mAppEntitiesHeaderView.findViewById(R.id.app1_view);
-        final ImageView appIconView1 = app1View.findViewById(R.id.app_icon);
-        final TextView appTitle1 = app1View.findViewById(R.id.app_title);
-
-        assertThat(app1View.getVisibility()).isEqualTo(View.VISIBLE);
-        assertThat(appIconView1.getDrawable()).isNotNull();
-        assertThat(appTitle1.getText()).isEqualTo("appTitle0");
-
-        final View app2View = mAppEntitiesHeaderView.findViewById(R.id.app2_view);
-        final ImageView appIconView2 = app2View.findViewById(R.id.app_icon);
-        final TextView appTitle2 = app2View.findViewById(R.id.app_title);
-
-        assertThat(app2View.getVisibility()).isEqualTo(View.VISIBLE);
-        assertThat(appIconView2.getDrawable()).isNotNull();
-        assertThat(appTitle2.getText()).isEqualTo("appTitle1");
-
-        final View app3View = mAppEntitiesHeaderView.findViewById(R.id.app3_view);
-        final ImageView appIconView3 = app3View.findViewById(R.id.app_icon);
-        final TextView appTitle3 = app3View.findViewById(R.id.app_title);
-
-        assertThat(app3View.getVisibility()).isEqualTo(View.VISIBLE);
-        assertThat(appIconView3.getDrawable()).isNotNull();
-        assertThat(appTitle3.getText()).isEqualTo("appTitle2");
-    }
-
     private List<RecentLocationAccesses.Access> createMockAccesses(int count) {
         final List<RecentLocationAccesses.Access> accesses = new ArrayList<>();
         for (int i = 0; i < count; i++) {
diff --git a/tests/robotests/src/com/android/settings/network/AdaptiveConnectivityTogglePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/AdaptiveConnectivityTogglePreferenceControllerTest.java
index dfb9a8f..c95797f 100644
--- a/tests/robotests/src/com/android/settings/network/AdaptiveConnectivityTogglePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/AdaptiveConnectivityTogglePreferenceControllerTest.java
@@ -19,8 +19,13 @@
 import static com.google.common.truth.Truth.assertThat;
 
 import static org.mockito.Answers.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 import android.content.Context;
+import android.net.wifi.WifiManager;
 import android.provider.Settings;
 
 import org.junit.Before;
@@ -29,6 +34,7 @@
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
 
 @RunWith(RobolectricTestRunner.class)
 public class AdaptiveConnectivityTogglePreferenceControllerTest {
@@ -37,12 +43,16 @@
 
     @Mock(answer = RETURNS_DEEP_STUBS)
     private Context mContext;
+    @Mock
+    WifiManager mWifiManager;
 
     private AdaptiveConnectivityTogglePreferenceController mController;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
+        mContext = spy(RuntimeEnvironment.application);
+        when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
         mController = new AdaptiveConnectivityTogglePreferenceController(mContext, PREF_KEY);
     }
 
@@ -61,6 +71,7 @@
         assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
                 Settings.Secure.ADAPTIVE_CONNECTIVITY_ENABLED, 1))
                 .isEqualTo(1);
+        verify(mWifiManager, atLeastOnce()).setWifiScoringEnabled(true);
     }
 
     @Test
@@ -73,5 +84,6 @@
         assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
                 Settings.Secure.ADAPTIVE_CONNECTIVITY_ENABLED, 1))
                 .isEqualTo(0);
+        verify(mWifiManager).setWifiScoringEnabled(false);
     }
 }
diff --git a/tests/robotests/src/com/android/settings/network/BluetoothTetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/BluetoothTetherPreferenceControllerTest.java
index 3b1f008..d3a3129 100644
--- a/tests/robotests/src/com/android/settings/network/BluetoothTetherPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/BluetoothTetherPreferenceControllerTest.java
@@ -26,7 +26,6 @@
 
 import android.bluetooth.BluetoothAdapter;
 import android.content.Context;
-import android.net.ConnectivityManager;
 import android.net.TetheringManager;
 
 import androidx.preference.SwitchPreference;
@@ -44,7 +43,7 @@
 public class BluetoothTetherPreferenceControllerTest {
 
     @Mock
-    private ConnectivityManager mConnectivityManager;
+    private TetheringManager mTetheringManager;
     @Mock
     private TetherEnabler mTetherEnabler;
 
@@ -58,9 +57,8 @@
 
         mContext = spy(ApplicationProvider.getApplicationContext());
         mSwitchPreference = spy(SwitchPreference.class);
-        when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
-                mConnectivityManager);
-        when(mConnectivityManager.getTetherableBluetoothRegexs()).thenReturn(new String[] {""});
+        when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
+        when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[] {""});
         mController = new BluetoothTetherPreferenceController(mContext, "BLUETOOTH");
         mController.setTetherEnabler(mTetherEnabler);
         ReflectionHelpers.setField(mController, "mPreference", mSwitchPreference);
@@ -98,7 +96,7 @@
 
     @Test
     public void shouldShow_noBluetoothTetherable() {
-        when(mConnectivityManager.getTetherableBluetoothRegexs()).thenReturn(new String[0]);
+        when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[0]);
         assertThat(mController.isAvailable()).isFalse();
     }
 
diff --git a/tests/robotests/src/com/android/settings/network/EthernetTetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/EthernetTetherPreferenceControllerTest.java
index d2e53b8..b269b05 100644
--- a/tests/robotests/src/com/android/settings/network/EthernetTetherPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/EthernetTetherPreferenceControllerTest.java
@@ -25,7 +25,6 @@
 import static org.mockito.Mockito.when;
 
 import android.content.Context;
-import android.net.ConnectivityManager;
 import android.net.EthernetManager;
 import android.net.TetheringManager;
 
@@ -49,7 +48,7 @@
     public MockitoRule mocks = MockitoJUnit.rule();
 
     @Mock
-    private ConnectivityManager mConnectivityManager;
+    private TetheringManager mTetheringManager;
     @Mock
     private EthernetManager mEthernetManager;
     @Mock
@@ -64,9 +63,8 @@
     public void setUp() {
         mContext = spy(ApplicationProvider.getApplicationContext());
         mPreference = spy(SwitchPreference.class);
-        when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
-                .thenReturn(mConnectivityManager);
-        when(mConnectivityManager.getTetherableIfaces()).thenReturn(new String[]{ETHERNET_REGEX});
+        when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
+        when(mTetheringManager.getTetherableIfaces()).thenReturn(new String[]{ETHERNET_REGEX});
         when(mContext.getSystemService(Context.ETHERNET_SERVICE)).thenReturn(mEthernetManager);
         mController = new EthernetTetherPreferenceController(mContext, "ethernet");
         mController.setTetherEnabler(mTetherEnabler);
@@ -105,7 +103,7 @@
 
     @Test
     public void shouldEnable_noTetherable() {
-        when(mConnectivityManager.getTetherableIfaces()).thenReturn(new String[0]);
+        when(mTetheringManager.getTetherableIfaces()).thenReturn(new String[0]);
         assertThat(mController.shouldEnable()).isFalse();
     }
 
diff --git a/tests/robotests/src/com/android/settings/network/TetherEnablerTest.java b/tests/robotests/src/com/android/settings/network/TetherEnablerTest.java
index 87806be..bb4b0c4 100644
--- a/tests/robotests/src/com/android/settings/network/TetherEnablerTest.java
+++ b/tests/robotests/src/com/android/settings/network/TetherEnablerTest.java
@@ -101,9 +101,9 @@
         when(context.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
         when(context.getSystemService(Context.NETWORK_POLICY_SERVICE)).thenReturn(
                 mNetworkPolicyManager);
-        when(mConnectivityManager.getTetherableIfaces()).thenReturn(new String[0]);
-        when(mConnectivityManager.getTetheredIfaces()).thenReturn(new String[0]);
-        when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
+        when(mTetheringManager.getTetherableIfaces()).thenReturn(new String[0]);
+        when(mTetheringManager.getTetheredIfaces()).thenReturn(new String[0]);
+        when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
         panReference.set(mBluetoothPan);
         mEnabler = spy(new TetherEnabler(context, mSwitchWidgetController, panReference));
         ReflectionHelpers.setField(mEnabler, "mBluetoothAdapter", mBluetoothAdapter);
@@ -111,8 +111,8 @@
 
     @Test
     public void lifecycle_onStart_setCheckedCorrectly() {
-        when(mConnectivityManager.getTetheredIfaces()).thenReturn(USB_TETHERED);
-        when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(USB_TETHERED);
+        when(mTetheringManager.getTetheredIfaces()).thenReturn(USB_TETHERED);
+        when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(USB_TETHERED);
 
         mEnabler.onStart();
         assertThat(mSwitchBar.isChecked()).isTrue();
@@ -150,7 +150,7 @@
         mEnabler.onStart();
         mEnabler.startTethering(TetheringManager.TETHERING_WIFI);
 
-        when(mConnectivityManager.getTetheredIfaces()).thenReturn(new String[0]);
+        when(mTetheringManager.getTetheredIfaces()).thenReturn(new String[0]);
         mEnabler.mOnStartTetheringCallback.onTetheringFailed();
 
         assertThat(mSwitchBar.isChecked()).isFalse();
@@ -255,8 +255,8 @@
 
     @Test
     public void updateState_shouldEnableSwitchBarTethering() {
-        when(mConnectivityManager.getTetheredIfaces()).thenReturn(USB_TETHERED);
-        when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(USB_TETHERED);
+        when(mTetheringManager.getTetheredIfaces()).thenReturn(USB_TETHERED);
+        when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(USB_TETHERED);
 
         mSwitchWidgetController.setListener(mEnabler);
         mSwitchWidgetController.startListening();
diff --git a/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java
index 3958589..4824eb2 100644
--- a/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java
@@ -33,6 +33,7 @@
 import android.content.IntentFilter;
 import android.database.ContentObserver;
 import android.net.ConnectivityManager;
+import android.net.TetheringManager;
 import android.provider.Settings;
 
 import androidx.preference.Preference;
@@ -56,7 +57,7 @@
     @Mock
     private Context mContext;
     @Mock
-    private ConnectivityManager mConnectivityManager;
+    private TetheringManager mTetheringManager;
     @Mock
     private BluetoothAdapter mBluetoothAdapter;
     @Mock
@@ -69,7 +70,7 @@
         MockitoAnnotations.initMocks(this);
         mController = spy(TetherPreferenceController.class);
         ReflectionHelpers.setField(mController, "mContext", mContext);
-        ReflectionHelpers.setField(mController, "mConnectivityManager", mConnectivityManager);
+        ReflectionHelpers.setField(mController, "mTetheringManager", mTetheringManager);
         ReflectionHelpers.setField(mController, "mBluetoothAdapter", mBluetoothAdapter);
         ReflectionHelpers.setField(mController, "mPreference", mPreference);
     }
@@ -106,16 +107,16 @@
     }
 
     @Test
-    public void updateSummary_noPreference_noInteractionWithConnectivityManager() {
+    public void updateSummary_noPreference_noInteractionWithTetheringManager() {
         ReflectionHelpers.setField(mController, "mPreference", null);
         mController.updateSummary();
-        verifyNoMoreInteractions(mConnectivityManager);
+        verifyNoMoreInteractions(mTetheringManager);
     }
 
     @Test
     public void updateSummary_wifiTethered_shouldShowHotspotMessage() {
-        when(mConnectivityManager.getTetheredIfaces()).thenReturn(new String[]{"123"});
-        when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"123"});
+        when(mTetheringManager.getTetheredIfaces()).thenReturn(new String[]{"123"});
+        when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"123"});
 
         mController.updateSummary();
         verify(mPreference).setSummary(R.string.tether_settings_summary_hotspot_on_tether_off);
@@ -123,8 +124,8 @@
 
     @Test
     public void updateSummary_btThetherOn_shouldShowTetherMessage() {
-        when(mConnectivityManager.getTetheredIfaces()).thenReturn(new String[]{"123"});
-        when(mConnectivityManager.getTetherableBluetoothRegexs()).thenReturn(new String[]{"123"});
+        when(mTetheringManager.getTetheredIfaces()).thenReturn(new String[]{"123"});
+        when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[]{"123"});
 
         mController.updateSummary();
         verify(mPreference).setSummary(R.string.tether_settings_summary_hotspot_off_tether_on);
@@ -132,8 +133,8 @@
 
     @Test
     public void updateSummary_tetherOff_shouldShowTetherOffMessage() {
-        when(mConnectivityManager.getTetherableBluetoothRegexs()).thenReturn(new String[]{"123"});
-        when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"456"});
+        when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[]{"123"});
+        when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"456"});
 
         mController.updateSummary();
         verify(mPreference).setSummary(R.string.switch_off_text);
@@ -141,9 +142,9 @@
 
     @Test
     public void updateSummary_wifiBtTetherOn_shouldShowHotspotAndTetherMessage() {
-        when(mConnectivityManager.getTetheredIfaces()).thenReturn(new String[]{"123", "456"});
-        when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"456"});
-        when(mConnectivityManager.getTetherableBluetoothRegexs()).thenReturn(new String[]{"23"});
+        when(mTetheringManager.getTetheredIfaces()).thenReturn(new String[]{"123", "456"});
+        when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"456"});
+        when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[]{"23"});
 
         mController.updateSummary();
         verify(mPreference).setSummary(R.string.tether_settings_summary_hotspot_on_tether_on);
diff --git a/tests/robotests/src/com/android/settings/network/UsbTetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/UsbTetherPreferenceControllerTest.java
index 066084e..e02da90 100644
--- a/tests/robotests/src/com/android/settings/network/UsbTetherPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/UsbTetherPreferenceControllerTest.java
@@ -25,7 +25,6 @@
 import static org.mockito.Mockito.when;
 
 import android.content.Context;
-import android.net.ConnectivityManager;
 import android.net.TetheringManager;
 
 import androidx.preference.SwitchPreference;
@@ -43,7 +42,7 @@
 public class UsbTetherPreferenceControllerTest {
 
     @Mock
-    private ConnectivityManager mConnectivityManager;
+    private TetheringManager mTetheringManager;
     @Mock
     private TetherEnabler mTetherEnabler;
 
@@ -56,9 +55,8 @@
         MockitoAnnotations.initMocks(this);
 
         mContext = spy(ApplicationProvider.getApplicationContext());
-        when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
-                mConnectivityManager);
-        when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(new String[]{""});
+        when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
+        when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[]{""});
         mController = new UsbTetherPreferenceController(mContext, "USB");
         mController.setTetherEnabler(mTetherEnabler);
         mSwitchPreference = spy(SwitchPreference.class);
@@ -94,7 +92,7 @@
 
     @Test
     public void shouldShow_noTetherableUsb() {
-        when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
+        when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
         assertThat(mController.shouldShow()).isFalse();
     }
 
diff --git a/tests/robotests/src/com/android/settings/network/WifiTetherDisablePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/WifiTetherDisablePreferenceControllerTest.java
index 1d2042c..a82a71f 100644
--- a/tests/robotests/src/com/android/settings/network/WifiTetherDisablePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/WifiTetherDisablePreferenceControllerTest.java
@@ -28,7 +28,7 @@
 import static org.mockito.Mockito.when;
 
 import android.content.Context;
-import android.net.ConnectivityManager;
+import android.net.TetheringManager;
 
 import androidx.preference.PreferenceScreen;
 import androidx.preference.SwitchPreference;
@@ -77,7 +77,7 @@
     }
 
     @Mock
-    private ConnectivityManager mConnectivityManager;
+    private TetheringManager mTetheringManager;
     @Mock
     private PreferenceScreen mPreferenceScreen;
     @Mock
@@ -100,9 +100,8 @@
 
         mContext = spy(ApplicationProvider.getApplicationContext());
         mPreference = spy(SwitchPreference.class);
-        when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
-                mConnectivityManager);
-        when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{""});
+        when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
+        when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{""});
         mController = new WifiTetherDisablePreferenceController(mContext, WIFI_TETHER_DISABLE_KEY);
         mController.setTetherEnabler(mTetherEnabler);
         ReflectionHelpers.setField(mController, "mScreen", mPreferenceScreen);
@@ -112,7 +111,7 @@
 
     @Test
     public void shouldShow_noTetherableWifi() {
-        when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[0]);
+        when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[0]);
         assertThat(mController.shouldShow()).isFalse();
     }
 
diff --git a/tests/robotests/src/com/android/settings/widget/HighlightablePreferenceGroupAdapterTest.java b/tests/robotests/src/com/android/settings/widget/HighlightablePreferenceGroupAdapterTest.java
index 23b7edc..f5e2a50 100644
--- a/tests/robotests/src/com/android/settings/widget/HighlightablePreferenceGroupAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/widget/HighlightablePreferenceGroupAdapterTest.java
@@ -20,6 +20,7 @@
 
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
@@ -43,6 +44,8 @@
 import com.android.settings.SettingsActivity;
 import com.android.settings.SettingsPreferenceFragment;
 
+import com.google.android.material.appbar.AppBarLayout;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -85,9 +88,12 @@
 
     @Test
     public void requestHighlight_hasKey_notHighlightedBefore_shouldRequest() {
-        mAdapter.requestHighlight(mRoot, mock(RecyclerView.class));
+        when(mAdapter.getPreferenceAdapterPosition(anyString())).thenReturn(1);
+        mAdapter.requestHighlight(mRoot, mock(RecyclerView.class), mock(AppBarLayout.class));
 
         verify(mRoot).postDelayed(any(),
+                eq(HighlightablePreferenceGroupAdapter.DELAY_COLLAPSE_DURATION_MILLIS));
+        verify(mRoot).postDelayed(any(),
                 eq(HighlightablePreferenceGroupAdapter.DELAY_HIGHLIGHT_DURATION_MILLIS));
     }
 
@@ -95,21 +101,21 @@
     public void requestHighlight_noKey_highlightedBefore_noRecyclerView_shouldNotRequest() {
         ReflectionHelpers.setField(mAdapter, "mHighlightKey", null);
         ReflectionHelpers.setField(mAdapter, "mHighlightRequested", false);
-        mAdapter.requestHighlight(mRoot, mock(RecyclerView.class));
+        mAdapter.requestHighlight(mRoot, mock(RecyclerView.class),  mock(AppBarLayout.class));
 
         ReflectionHelpers.setField(mAdapter, "mHighlightKey", TEST_KEY);
         ReflectionHelpers.setField(mAdapter, "mHighlightRequested", true);
-        mAdapter.requestHighlight(mRoot, mock(RecyclerView.class));
+        mAdapter.requestHighlight(mRoot, mock(RecyclerView.class), mock(AppBarLayout.class));
 
         ReflectionHelpers.setField(mAdapter, "mHighlightKey", TEST_KEY);
         ReflectionHelpers.setField(mAdapter, "mHighlightRequested", false);
-        mAdapter.requestHighlight(mRoot, null /* recyclerView */);
+        mAdapter.requestHighlight(mRoot, null /* recyclerView */,  mock(AppBarLayout.class));
 
         verifyZeroInteractions(mRoot);
     }
 
     @Test
-    public void adjustInitialExpandedChildCount_invalidInput_shouldNotadjust() {
+    public void adjustInitialExpandedChildCount_invalidInput_shouldNotAdjust() {
         HighlightablePreferenceGroupAdapter.adjustInitialExpandedChildCount(null /* host */);
         HighlightablePreferenceGroupAdapter.adjustInitialExpandedChildCount(mFragment);
         final Bundle args = new Bundle();
diff --git a/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsForSubTest.java b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsForSubTest.java
index 2e93faa..8ab3ad2 100644
--- a/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsForSubTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsForSubTest.java
@@ -27,7 +27,6 @@
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.spy;
@@ -55,8 +54,7 @@
 import com.android.settings.network.ims.MockWifiCallingQueryImsState;
 import com.android.settings.network.ims.WifiCallingQueryImsState;
 import com.android.settings.testutils.shadow.ShadowFragment;
-import com.android.settings.widget.SwitchBar;
-import com.android.settings.widget.ToggleSwitch;
+import com.android.settings.widget.SettingsMainSwitchBar;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -85,19 +83,28 @@
     private final PersistableBundle mBundle = new PersistableBundle();
 
     private MockWifiCallingQueryImsState mQueryImsState;
+    private SettingsMainSwitchBar mSwitchBar;
 
-    @Mock private static CarrierConfigManager sCarrierConfigManager;
-    @Mock private CarrierConfigManager mMockConfigManager;
-    @Mock private ImsMmTelManager mImsMmTelManager;
-    @Mock private TelephonyManager mTelephonyManager;
-    @Mock private PreferenceScreen mPreferenceScreen;
-    @Mock private SettingsActivity mActivity;
-    @Mock private SwitchBar mSwitchBar;
-    @Mock private ToggleSwitch mToggleSwitch;
-    @Mock private View mView;
-    @Mock private ListWithEntrySummaryPreference mButtonWfcMode;
-    @Mock private ListWithEntrySummaryPreference mButtonWfcRoamingMode;
-    @Mock private Preference mUpdateAddress;
+    @Mock
+    private static CarrierConfigManager sCarrierConfigManager;
+    @Mock
+    private CarrierConfigManager mMockConfigManager;
+    @Mock
+    private ImsMmTelManager mImsMmTelManager;
+    @Mock
+    private TelephonyManager mTelephonyManager;
+    @Mock
+    private PreferenceScreen mPreferenceScreen;
+    @Mock
+    private SettingsActivity mActivity;
+    @Mock
+    private View mView;
+    @Mock
+    private ListWithEntrySummaryPreference mButtonWfcMode;
+    @Mock
+    private ListWithEntrySummaryPreference mButtonWfcRoamingMode;
+    @Mock
+    private Preference mUpdateAddress;
 
     @Before
     public void setUp() throws Exception {
@@ -125,7 +132,7 @@
         mEmptyView = new TextView(mContext);
         doReturn(mEmptyView).when(mView).findViewById(android.R.id.empty);
 
-        ReflectionHelpers.setField(mSwitchBar, "mSwitch", mToggleSwitch);
+        mSwitchBar = new SettingsMainSwitchBar(mContext);
         doReturn(mSwitchBar).when(mView).findViewById(R.id.switch_bar);
 
         mQueryImsState = new MockWifiCallingQueryImsState(mContext, SUB_ID);
@@ -364,6 +371,7 @@
         }
 
         @Override
-        void showAlert(Intent intent) {}
+        void showAlert(Intent intent) {
+        }
     }
 }
diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceControllerTest.java
index e639b67..d777a59 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceControllerTest.java
@@ -25,7 +25,7 @@
 import static org.mockito.Mockito.when;
 
 import android.content.Context;
-import android.net.ConnectivityManager;
+import android.net.TetheringManager;
 import android.net.wifi.SoftApConfiguration;
 import android.net.wifi.WifiManager;
 
@@ -57,7 +57,7 @@
 
     private Context mContext;
     @Mock
-    private ConnectivityManager mConnectivityManager;
+    private TetheringManager mTetheringManager;
     @Mock
     private WifiManager mWifiManager;
     @Mock
@@ -74,9 +74,8 @@
         mContext = spy(RuntimeEnvironment.application);
         mPreference = new ListPreference(RuntimeEnvironment.application);
         when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
-        when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
-                .thenReturn(mConnectivityManager);
-        when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
+        when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
+        when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
         when(mContext.getResources()).thenReturn(RuntimeEnvironment.application.getResources());
         when(mScreen.findPreference(anyString())).thenReturn(mPreference);
         when(mWifiManager.getSoftApConfiguration()).thenReturn(
diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherFooterPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherFooterPreferenceControllerTest.java
index b0ed862..25ad730 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherFooterPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherFooterPreferenceControllerTest.java
@@ -22,7 +22,7 @@
 import static org.mockito.Mockito.when;
 
 import android.content.Context;
-import android.net.ConnectivityManager;
+import android.net.TetheringManager;
 import android.net.wifi.WifiManager;
 
 import androidx.preference.PreferenceScreen;
@@ -43,7 +43,7 @@
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private Context mContext;
     @Mock
-    private ConnectivityManager mConnectivityManager;
+    private TetheringManager mTetheringManager;
     @Mock
     private WifiManager mWifiManager;
     @Mock
@@ -58,9 +58,8 @@
         MockitoAnnotations.initMocks(this);
 
         when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
-        when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
-                .thenReturn(mConnectivityManager);
-        when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
+        when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
+        when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
         mController = new WifiTetherFooterPreferenceController(mContext);
         when(mScreen.findPreference(anyString())).thenReturn(mPreference);
     }
diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPasswordPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPasswordPreferenceControllerTest.java
index 7835f7e..8f8477f 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPasswordPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPasswordPreferenceControllerTest.java
@@ -26,7 +26,7 @@
 
 import android.app.settings.SettingsEnums;
 import android.content.Context;
-import android.net.ConnectivityManager;
+import android.net.TetheringManager;
 import android.net.wifi.SoftApConfiguration;
 import android.net.wifi.WifiManager;
 
@@ -53,7 +53,7 @@
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private Context mContext;
     @Mock
-    private ConnectivityManager mConnectivityManager;
+    private TetheringManager mTetheringManager;
     @Mock
     private WifiManager mWifiManager;
     @Mock
@@ -77,9 +77,8 @@
 
         when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
         when(mWifiManager.getSoftApConfiguration()).thenReturn(mConfig);
-        when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
-                .thenReturn(mConnectivityManager);
-        when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
+        when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
+        when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
         when(mContext.getResources()).thenReturn(RuntimeEnvironment.application.getResources());
         when(mScreen.findPreference(anyString())).thenReturn(mPreference);
 
diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java
index 920582f..23bb0db 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java
@@ -23,7 +23,7 @@
 import static org.mockito.Mockito.when;
 
 import android.content.Context;
-import android.net.ConnectivityManager;
+import android.net.TetheringManager;
 import android.net.wifi.SoftApConfiguration;
 import android.net.wifi.WifiManager;
 
@@ -56,7 +56,7 @@
 
     private Context mContext;
     @Mock
-    private ConnectivityManager mConnectivityManager;
+    private TetheringManager mTetheringManager;
     @Mock
     private WifiManager mWifiManager;
     @Mock
@@ -77,14 +77,13 @@
         mLifecycle = new Lifecycle(mLifecycleOwner);
         FakeFeatureFactory.setupForTest();
         mPreference = new PrimarySwitchPreference(RuntimeEnvironment.application);
-        when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
-                .thenReturn(mConnectivityManager);
+        when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
         when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
         when(mScreen.findPreference(anyString())).thenReturn(mPreference);
         mSoftApConfiguration = new SoftApConfiguration.Builder().setSsid(SSID).build();
         when(mWifiManager.getSoftApConfiguration()).thenReturn(mSoftApConfiguration);
 
-        when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
+        when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
         mController = new WifiTetherPreferenceController(mContext, mLifecycle,
                 false /* initSoftApManager */);
         mController.displayPreference(mScreen);
@@ -92,7 +91,7 @@
 
     @Test
     public void isAvailable_noTetherRegex_shouldReturnFalse() {
-        when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{});
+        when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{});
         mController = new WifiTetherPreferenceController(mContext, mLifecycle,
                 false /* initSoftApManager */);
 
diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSSIDPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSSIDPreferenceControllerTest.java
index a6a9dda..147cd64 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSSIDPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSSIDPreferenceControllerTest.java
@@ -26,7 +26,7 @@
 
 import android.app.settings.SettingsEnums;
 import android.content.Context;
-import android.net.ConnectivityManager;
+import android.net.TetheringManager;
 import android.net.wifi.SoftApConfiguration;
 import android.net.wifi.WifiManager;
 
@@ -49,7 +49,7 @@
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private Context mContext;
     @Mock
-    private ConnectivityManager mConnectivityManager;
+    private TetheringManager mTetheringManager;
     @Mock
     private WifiManager mWifiManager;
     @Mock
@@ -68,9 +68,8 @@
         mPreference = new WifiTetherSsidPreference(RuntimeEnvironment.application);
 
         when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
-        when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
-                .thenReturn(mConnectivityManager);
-        when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
+        when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
+        when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
         when(mContext.getResources()).thenReturn(RuntimeEnvironment.application.getResources());
         when(mScreen.findPreference(anyString())).thenReturn(mPreference);
         mController = new WifiTetherSSIDPreferenceController(mContext, mListener,
diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
index b41616b..a241296 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
@@ -30,6 +30,7 @@
 import android.content.Context;
 import android.content.res.Resources;
 import android.net.ConnectivityManager;
+import android.net.TetheringManager;
 import android.os.Bundle;
 import android.os.UserHandle;
 import android.os.UserManager;
@@ -70,6 +71,8 @@
     private ConnectivityManager mConnectivityManager;
     @Mock
     private UserManager mUserManager;
+    @Mock
+    private TetheringManager mTetheringManager;
 
     @Before
     public void setUp() {
@@ -78,7 +81,8 @@
         MockitoAnnotations.initMocks(this);
         doReturn(mConnectivityManager)
                 .when(mContext).getSystemService(Context.CONNECTIVITY_SERVICE);
-        doReturn(WIFI_REGEXS).when(mConnectivityManager).getTetherableWifiRegexs();
+        doReturn(mTetheringManager).when(mContext).getSystemService(Context.TETHERING_SERVICE);
+        doReturn(WIFI_REGEXS).when(mTetheringManager).getTetherableWifiRegexs();
         doReturn(mUserManager).when(mContext).getSystemService(Context.USER_SERVICE);
 
         mWifiTetherSettings = new WifiTetherSettings();
diff --git a/tests/unit/src/com/android/settings/applications/manageapplications/AppFilterRegistryTest.java b/tests/unit/src/com/android/settings/applications/manageapplications/AppFilterRegistryTest.java
index ba7a0d2..9c50d61 100644
--- a/tests/unit/src/com/android/settings/applications/manageapplications/AppFilterRegistryTest.java
+++ b/tests/unit/src/com/android/settings/applications/manageapplications/AppFilterRegistryTest.java
@@ -16,6 +16,7 @@
 
 package com.android.settings.applications.manageapplications;
 
+import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_ALARMS_AND_REMINDERS;
 import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_ALL;
 import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_INSTALL_SOURCES;
 import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_POWER_ALLOWLIST;
@@ -23,6 +24,7 @@
 import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_USAGE_ACCESS;
 import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_WITH_OVERLAY;
 import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_WRITE_SETTINGS;
+import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_ALARMS_AND_REMINDERS;
 import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_GAMES;
 import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_HIGH_POWER;
 import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_MAIN;
@@ -59,6 +61,9 @@
         assertThat(registry.getDefaultFilterType(LIST_TYPE_MANAGE_SOURCES))
                 .isEqualTo(FILTER_APPS_INSTALL_SOURCES);
 
+        assertThat(registry.getDefaultFilterType(LIST_TYPE_ALARMS_AND_REMINDERS))
+                .isEqualTo(FILTER_ALARMS_AND_REMINDERS);
+
         assertThat(registry.getDefaultFilterType(LIST_TYPE_MAIN)).isEqualTo(FILTER_APPS_ALL);
         assertThat(registry.getDefaultFilterType(LIST_TYPE_NOTIFICATION))
                 .isEqualTo(FILTER_APPS_RECENT);
diff --git a/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/OWNERS b/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/OWNERS
new file mode 100644
index 0000000..4338198
--- /dev/null
+++ b/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/OWNERS
@@ -0,0 +1,4 @@
+# Default reviewers for this and subdirectories.
+beverlyt@google.com
+dsandler@android.com
+juliacr@google.com
\ No newline at end of file
diff --git a/tests/unit/src/com/android/settings/development/transcode/TranscodeNotificationPreferenceControllerTest.java b/tests/unit/src/com/android/settings/development/transcode/TranscodeNotificationPreferenceControllerTest.java
new file mode 100644
index 0000000..0903c72
--- /dev/null
+++ b/tests/unit/src/com/android/settings/development/transcode/TranscodeNotificationPreferenceControllerTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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.development.transcode;
+
+import static com.android.settings.development.transcode.TranscodeNotificationPreferenceController.TRANSCODE_NOTIFICATION_SYS_PROP_KEY;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+import android.os.SystemProperties;
+
+import androidx.test.core.app.ApplicationProvider;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import com.android.settings.core.BasePreferenceController;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+public class TranscodeNotificationPreferenceControllerTest {
+    private TranscodeNotificationPreferenceController mUnderTest;
+
+    @Before
+    public void setUp() {
+        Context context = ApplicationProvider.getApplicationContext();
+        mUnderTest = new TranscodeNotificationPreferenceController(context, "notification_key");
+    }
+
+    @Test
+    public void isChecked_whenSysPropSet_shouldReturnTrue() {
+        SystemProperties.set(TRANSCODE_NOTIFICATION_SYS_PROP_KEY, "true");
+        assertThat(mUnderTest.isChecked()).isTrue();
+    }
+
+    @Test
+    public void isChecked_whenSysPropUnset_shouldReturnFalse() {
+        SystemProperties.set(TRANSCODE_NOTIFICATION_SYS_PROP_KEY, "false");
+        assertThat(mUnderTest.isChecked()).isFalse();
+    }
+
+    @Test
+    public void setChecked_withTrue_shouldSetSysProp() {
+        mUnderTest.setChecked(true);
+        assertThat(
+                SystemProperties.getBoolean(TRANSCODE_NOTIFICATION_SYS_PROP_KEY, false)).isTrue();
+    }
+
+    @Test
+    public void setChecked_withFalse_shouldUnsetSysProp() {
+        mUnderTest.setChecked(false);
+        assertThat(
+                SystemProperties.getBoolean(TRANSCODE_NOTIFICATION_SYS_PROP_KEY, true)).isFalse();
+    }
+
+    @Test
+    public void getAvailabilityStatus_shouldReturn_isAvailable() {
+        assertThat(mUnderTest.getAvailabilityStatus()).isEqualTo(
+                BasePreferenceController.AVAILABLE);
+    }
+}
diff --git a/tests/unit/src/com/android/settings/wifi/OWNERS b/tests/unit/src/com/android/settings/wifi/OWNERS
new file mode 100644
index 0000000..358c910
--- /dev/null
+++ b/tests/unit/src/com/android/settings/wifi/OWNERS
@@ -0,0 +1 @@
+include /src/com/android/settings/wifi/OWNERS