Merge "Replace the SwitchBar with MainSwitch." 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..e5a9db4 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>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index d36467d..c2fd5e0 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -4007,8 +4007,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 +4015,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>
 
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..7331058 100644
--- a/res/xml/location_settings.xml
+++ b/res/xml/location_settings.xml
@@ -50,9 +50,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 +65,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..2226a2c 100644
--- a/res/xml/location_settings_personal.xml
+++ b/res/xml/location_settings_personal.xml
@@ -46,15 +46,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/special_access.xml b/res/xml/special_access.xml
index 150c1e6..de833f0 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"
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/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..46bea30 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -110,8 +110,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 +200,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(),
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/location/LocationPersonalSettings.java b/src/com/android/settings/location/LocationPersonalSettings.java
index 92796a4..31ca0ae 100644
--- a/src/com/android/settings/location/LocationPersonalSettings.java
+++ b/src/com/android/settings/location/LocationPersonalSettings.java
@@ -50,7 +50,8 @@
         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);
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..8d862d4 100644
--- a/src/com/android/settings/location/LocationSettings.java
+++ b/src/com/android/settings/location/LocationSettings.java
@@ -83,7 +83,6 @@
 
         use(AppLocationPermissionPreferenceController.class).init(this);
         use(RecentLocationRequestPreferenceController.class).init(this);
-        use(LocationServicePreferenceController.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/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/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/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/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/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/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/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/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/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/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