Merge "Update to support long version codes."
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 05c5075..07908e5 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -178,6 +178,7 @@
         </activity>
 
         <activity android:name=".Settings$ConnectedDeviceDashboardActivity"
+            android:enabled="false"
             android:taskAffinity="com.android.settings"
             android:label="@string/connected_devices_dashboard_title"
             android:icon="@drawable/ic_devices_other"
diff --git a/proguard.flags b/proguard.flags
index 7a403a4..d644f47 100644
--- a/proguard.flags
+++ b/proguard.flags
@@ -39,21 +39,3 @@
     public static ** SEARCH_INDEX_DATA_PROVIDER;
     public static ** SUMMARY_PROVIDER_FACTORY;
 }
-
-# Keep classes, annotations and members used by Lifecycle
--keepattributes *Annotation*
-
--keepclassmembers enum android.arch.lifecycle.Lifecycle$Event {
-    <fields>;
-}
-
--keep class * implements android.arch.lifecycle.LifecycleObserver {
-}
-
--keep class * implements android.arch.lifecycle.GeneratedAdapter {
-    <init>(...);
-}
-
--keepclassmembers class ** {
-    @android.arch.lifecycle.OnLifecycleEvent *;
-}
diff --git a/res/layout/dialog_sim_status.xml b/res/layout/dialog_sim_status.xml
index 9377664..66b17d7 100644
--- a/res/layout/dialog_sim_status.xml
+++ b/res/layout/dialog_sim_status.xml
@@ -139,6 +139,7 @@
             style="@style/device_info_dialog_value"
             android:id="@+id/icc_id_value"
             android:layout_width="match_parent"
-            android:layout_height="wrap_content"/>
+            android:layout_height="wrap_content"
+            android:text="@string/device_info_not_available"/>
     </LinearLayout>
 </ScrollView>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 3fb50e5..40152f7 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -398,6 +398,12 @@
     <string name="connected_device_connected_title">Currently connected</string>
     <!-- Title for connected device group [CHAR LIMIT=none]-->
     <string name="connected_device_saved_title">Saved devices</string>
+    <!-- Title for preference to add a device [CHAR LIMIT=none]-->
+    <string name="connected_device_add_device_title">Add device</string>
+    <!-- Summary for preference to add a device [CHAR LIMIT=none]-->
+    <string name="connected_device_add_device_summary">Bluetooth will turn on to enable pairing</string>
+    <!-- Title for other connection preferences [CHAR LIMIT=none]-->
+    <string name="connected_device_connections_title">Connection preferences</string>
 
     <!-- Date & time settings screen title -->
     <string name="date_and_time">Date &amp; time</string>
diff --git a/res/xml/app_info_settings.xml b/res/xml/app_info_settings.xml
index 48a4b6a..e2fb2e4 100644
--- a/res/xml/app_info_settings.xml
+++ b/res/xml/app_info_settings.xml
@@ -39,21 +39,18 @@
 
     <Preference
         android:key="notification_settings"
-        android:title="@string/notifications_label"
-        android:selectable="true"/>
+        android:title="@string/notifications_label"/>
 
     <com.android.settings.widget.FixedLineSummaryPreference
         android:key="permission_settings"
         android:title="@string/permissions_label"
         android:summary="@string/summary_placeholder"
-        android:selectable="true"
         app:summaryLineCount="1" />
 
     <Preference
         android:key="storage_settings"
         android:title="@string/storage_settings"
-        android:summary="@string/summary_placeholder"
-        android:selectable="true"/>
+        android:summary="@string/summary_placeholder"/>
 
     <com.android.settings.applications.AppDomainsPreference
         android:key="instant_app_launch_supported_domain_urls"
@@ -63,14 +60,12 @@
     <Preference
         android:key="data_settings"
         android:title="@string/data_usage_summary_title"
-        android:summary="@string/summary_placeholder"
-        android:selectable="true"/>
+        android:summary="@string/summary_placeholder"/>
 
     <Preference
         android:key="battery"
         android:title="@string/power_usage_summary_title"
-        android:summary="@string/summary_placeholder"
-        android:selectable="true"/>
+        android:summary="@string/summary_placeholder"/>
 
     <Preference
         android:key="preferred_settings"
@@ -82,8 +77,33 @@
         android:key="memory"
         android:title="@string/memory_settings_title"
         android:summary="@string/summary_placeholder"
-        android:enabled="false"
-        android:selectable="true"/>
+        android:enabled="false"/>
+
+    <!-- Default apps shortcuts -->
+    <Preference
+        android:key="default_home"
+        android:title="@string/home_app"
+        android:summary="@string/summary_placeholder" />
+
+    <Preference
+        android:key="default_browser"
+        android:title="@string/default_browser_title"
+        android:summary="@string/summary_placeholder" />
+
+    <Preference
+        android:key="default_phone_app"
+        android:title="@string/default_phone_title"
+        android:summary="@string/default_phone_title" />
+
+    <Preference
+        android:key="default_emergency_app"
+        android:title="@string/default_emergency_app"
+        android:summary="@string/summary_placeholder" />
+
+    <Preference
+        android:key="default_sms_app"
+        android:title="@string/sms_application_title"
+        android:summary="@string/summary_placeholder" />
 
     <Preference
         android:key="app_version"
diff --git a/res/xml/connected_devices.xml b/res/xml/connected_devices.xml
index 497a485..227dee2 100644
--- a/res/xml/connected_devices.xml
+++ b/res/xml/connected_devices.xml
@@ -16,6 +16,7 @@
 
 <PreferenceScreen
     xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:settings="http://schemas.android.com/apk/res-auto"
     android:key="connected_devices_screen"
     android:title="@string/connected_devices_dashboard_title">
 
@@ -26,4 +27,18 @@
     <PreferenceCategory
         android:key="saved_device_list"
         android:title="@string/connected_device_saved_title"/>
+
+    <Preference
+        android:fragment="com.android.settings.bluetooth.BluetoothPairingDetail"
+        android:key="add_bt_devices"
+        android:title="@string/connected_device_add_device_title"
+        android:icon="@drawable/ic_menu_add"
+        android:summary="@string/connected_device_add_device_summary"
+        settings:allowDividerAbove="true"/>
+
+    <Preference
+        android:fragment="com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment"
+        android:key="connection_preferences"
+        android:title="@string/connected_device_connections_title"
+        settings:allowDividerAbove="true"/>
 </PreferenceScreen>
diff --git a/res/xml/connected_devices_advanced.xml b/res/xml/connected_devices_advanced.xml
new file mode 100644
index 0000000..946151f
--- /dev/null
+++ b/res/xml/connected_devices_advanced.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<PreferenceScreen
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:key="connected_devices_screen"
+    android:title="@string/connected_devices_dashboard_title">
+
+    <com.android.settings.widget.MasterSwitchPreference
+      android:key="toggle_bluetooth"
+      android:title="@string/bluetooth_settings_title"
+      android:icon="@drawable/ic_settings_bluetooth"
+      android:order="-7"/>
+
+    <SwitchPreference
+        android:key="toggle_nfc"
+        android:title="@string/nfc_quick_toggle_title"
+        android:icon="@drawable/ic_nfc"
+        android:summary="@string/nfc_quick_toggle_summary"
+        android:order="-5"/>
+
+    <com.android.settingslib.RestrictedPreference
+        android:fragment="com.android.settings.nfc.AndroidBeam"
+        android:key="android_beam_settings"
+        android:title="@string/android_beam_settings_title"
+        android:icon="@drawable/ic_android"
+        android:order="-4"/>
+
+    <Preference
+        android:key="sms_mirroring"
+        android:title="@string/sms_mirroring_pref"
+        android:icon="@drawable/ic_sms_mirroring_24dp"
+        android:summary="@string/summary_placeholder"
+        android:order="-3"/>
+
+    <Preference
+        android:key="usb_mode"
+        android:title="@string/usb_pref"
+        android:icon="@drawable/ic_usb"
+        android:order="-2">
+        <intent android:action="android.intent.action.MAIN"
+                android:targetPackage="com.android.settings"
+                android:targetClass="com.android.settings.deviceinfo.UsbModeChooserActivity"/>
+    </Preference>
+
+    <Preference
+        android:key="bt_received_files"
+        android:icon="@drawable/ic_folder_vd_theme_24"
+        android:title="@string/bluetooth_show_received_files" />
+
+    <PreferenceCategory
+        android:key="dashboard_tile_placeholder"
+        android:order="50"/>
+
+</PreferenceScreen>
diff --git a/src/com/android/settings/applications/AppInfoDashboardFragment.java b/src/com/android/settings/applications/AppInfoDashboardFragment.java
index ba8b901..a725781 100755
--- a/src/com/android/settings/applications/AppInfoDashboardFragment.java
+++ b/src/com/android/settings/applications/AppInfoDashboardFragment.java
@@ -50,7 +50,6 @@
 import android.support.v7.preference.Preference.OnPreferenceClickListener;
 import android.support.v7.preference.PreferenceCategory;
 import android.support.v7.preference.PreferenceScreen;
-import android.text.BidiFormatter;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.Menu;
@@ -74,6 +73,11 @@
 import com.android.settings.applications.appinfo.AppPermissionPreferenceController;
 import com.android.settings.applications.appinfo.AppStoragePreferenceController;
 import com.android.settings.applications.appinfo.AppVersionPreferenceController;
+import com.android.settings.applications.appinfo.DefaultBrowserShortcutPreferenceController;
+import com.android.settings.applications.appinfo.DefaultEmergencyShortcutPreferenceController;
+import com.android.settings.applications.appinfo.DefaultHomeShortcutPreferenceController;
+import com.android.settings.applications.appinfo.DefaultPhoneShortcutPreferenceController;
+import com.android.settings.applications.appinfo.DefaultSmsShortcutPreferenceController;
 import com.android.settings.applications.defaultapps.DefaultBrowserPreferenceController;
 import com.android.settings.applications.defaultapps.DefaultEmergencyPreferenceController;
 import com.android.settings.applications.defaultapps.DefaultHomePreferenceController;
@@ -394,6 +398,12 @@
         // state when app state changes.
         controllers.add(new AppBatteryPreferenceController(context, this, packageName, lifecycle));
         controllers.add(new AppMemoryPreferenceController(context, this, lifecycle));
+        controllers.add(new DefaultHomeShortcutPreferenceController(context, packageName));
+        controllers.add(new DefaultBrowserShortcutPreferenceController(context, packageName));
+        controllers.add(new DefaultPhoneShortcutPreferenceController(context, packageName));
+        controllers.add(new DefaultEmergencyShortcutPreferenceController(context, packageName));
+        controllers.add(new DefaultSmsShortcutPreferenceController(context, packageName));
+
         return controllers;
     }
 
@@ -863,31 +873,6 @@
         }
         final PreferenceScreen screen = getPreferenceScreen();
         final Context context = getContext();
-        if (DefaultHomePreferenceController.hasHomePreference(mPackageName, context)) {
-            screen.addPreference(new ShortcutPreference(getPrefContext(),
-                    DefaultAppSettings.class, "default_home", R.string.home_app,
-                    R.string.configure_apps));
-        }
-        if (DefaultBrowserPreferenceController.hasBrowserPreference(mPackageName, context)) {
-            screen.addPreference(new ShortcutPreference(getPrefContext(),
-                    DefaultAppSettings.class, "default_browser", R.string.default_browser_title,
-                    R.string.configure_apps));
-        }
-        if (DefaultPhonePreferenceController.hasPhonePreference(mPackageName, context)) {
-            screen.addPreference(new ShortcutPreference(getPrefContext(),
-                    DefaultAppSettings.class, "default_phone_app", R.string.default_phone_title,
-                    R.string.configure_apps));
-        }
-        if (DefaultEmergencyPreferenceController.hasEmergencyPreference(mPackageName, context)) {
-            screen.addPreference(new ShortcutPreference(getPrefContext(),
-                    DefaultAppSettings.class, "default_emergency_app",
-                    R.string.default_emergency_app, R.string.configure_apps));
-        }
-        if (DefaultSmsPreferenceController.hasSmsPreference(mPackageName, context)) {
-            screen.addPreference(new ShortcutPreference(getPrefContext(),
-                    DefaultAppSettings.class, "default_sms_app", R.string.sms_application_title,
-                    R.string.configure_apps));
-        }
 
         // Get the package info with the activities
         PackageInfo packageInfoWithActivities = null;
@@ -1037,36 +1022,7 @@
 
     private void updateDynamicPrefs() {
         final Context context = getContext();
-        Preference pref = findPreference("default_home");
-
-        if (pref != null) {
-            pref.setSummary(DefaultHomePreferenceController.isHomeDefault(mPackageName,
-                    new PackageManagerWrapper(context.getPackageManager()))
-                    ? R.string.yes : R.string.no);
-        }
-        pref = findPreference("default_browser");
-        if (pref != null) {
-            pref.setSummary(new DefaultBrowserPreferenceController(context)
-                    .isBrowserDefault(mPackageName, mUserId)
-                    ? R.string.yes : R.string.no);
-        }
-        pref = findPreference("default_phone_app");
-        if (pref != null) {
-            pref.setSummary(
-                    DefaultPhonePreferenceController.isPhoneDefault(mPackageName, context)
-                    ? R.string.yes : R.string.no);
-        }
-        pref = findPreference("default_emergency_app");
-        if (pref != null) {
-            pref.setSummary(DefaultEmergencyPreferenceController.isEmergencyDefault(mPackageName,
-                    getContext()) ? R.string.yes : R.string.no);
-        }
-        pref = findPreference("default_sms_app");
-        if (pref != null) {
-            pref.setSummary(DefaultSmsPreferenceController.isSmsDefault(mPackageName, context)
-                    ? R.string.yes : R.string.no);
-        }
-        pref = findPreference("system_alert_window");
+        Preference pref = findPreference("system_alert_window");
         if (pref != null) {
             pref.setSummary(DrawOverlayDetails.getSummary(getContext(), mAppEntry));
         }
diff --git a/src/com/android/settings/applications/ShortcutPreference.java b/src/com/android/settings/applications/ShortcutPreference.java
index 91b41b7..9505e89 100644
--- a/src/com/android/settings/applications/ShortcutPreference.java
+++ b/src/com/android/settings/applications/ShortcutPreference.java
@@ -21,7 +21,12 @@
 import com.android.internal.logging.nano.MetricsProto;
 import com.android.settings.SettingsActivity;
 import com.android.settings.Utils;
+import com.android.settings.applications.appinfo.DefaultAppShortcutPreferenceControllerBase;
 
+/**
+ * deprecated in favor of {@link DefaultAppShortcutPreferenceControllerBase}
+ */
+@Deprecated
 public class ShortcutPreference extends Preference {
 
     private final Class mTarget;
diff --git a/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBase.java b/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBase.java
new file mode 100644
index 0000000..3311daa
--- /dev/null
+++ b/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBase.java
@@ -0,0 +1,87 @@
+/*
+ * 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.appinfo;
+
+import android.app.slice.Slice;
+import android.content.Context;
+import android.os.Bundle;
+import android.os.UserManager;
+import android.support.v7.preference.Preference;
+import android.text.TextUtils;
+
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.R;
+import com.android.settings.SettingsActivity;
+import com.android.settings.Utils;
+import com.android.settings.applications.DefaultAppSettings;
+import com.android.settings.core.BasePreferenceController;
+
+/*
+ * Abstract base controller for the default app shortcut preferences that launches the default app
+ * settings with the corresponding default app highlighted.
+ */
+public abstract class DefaultAppShortcutPreferenceControllerBase extends BasePreferenceController {
+
+    protected final String mPackageName;
+
+    public DefaultAppShortcutPreferenceControllerBase(Context context, String preferenceKey,
+            String packageName) {
+        super(context, preferenceKey);
+        mPackageName = packageName;
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        if (UserManager.get(mContext).isManagedProfile()) {
+            return DISABLED_FOR_USER;
+        }
+        return hasAppCapability() ? AVAILABLE : DISABLED_UNSUPPORTED;
+    }
+
+    @Override
+    public Slice getSettingSlice() {
+        return null;
+    }
+
+    @Override
+    public void updateState(Preference preference) {
+        preference.setSummary(isDefaultApp() ? R.string.yes : R.string.no);
+    }
+
+    @Override
+    public boolean handlePreferenceTreeClick(Preference preference) {
+        if (TextUtils.equals(mPreferenceKey, preference.getKey())) {
+            Bundle bundle = new Bundle();
+            bundle.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, mPreferenceKey);
+            Utils.startWithFragment(mContext, DefaultAppSettings.class.getName(), bundle, null, 0,
+                    R.string.configure_apps, null, MetricsProto.MetricsEvent.VIEW_UNKNOWN);
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Check whether the app has the default app capability
+     * @return true if the app has the default app capability
+     */
+    protected abstract boolean hasAppCapability();
+
+    /**
+     * Check whether the app is the default app
+     * @return true if the app is the default app
+     */
+    protected abstract boolean isDefaultApp();
+
+}
diff --git a/src/com/android/settings/applications/appinfo/DefaultBrowserShortcutPreferenceController.java b/src/com/android/settings/applications/appinfo/DefaultBrowserShortcutPreferenceController.java
new file mode 100644
index 0000000..64af3c2
--- /dev/null
+++ b/src/com/android/settings/applications/appinfo/DefaultBrowserShortcutPreferenceController.java
@@ -0,0 +1,42 @@
+/*
+ * 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.appinfo;
+
+import android.content.Context;
+import android.os.UserHandle;
+
+import com.android.settings.applications.defaultapps.DefaultBrowserPreferenceController;
+
+public class DefaultBrowserShortcutPreferenceController
+        extends DefaultAppShortcutPreferenceControllerBase {
+
+    private static final String KEY = "default_browser";
+
+    public DefaultBrowserShortcutPreferenceController(Context context, String packageName) {
+        super(context, KEY, packageName);
+    }
+
+    @Override
+    protected boolean hasAppCapability() {
+        return DefaultBrowserPreferenceController.hasBrowserPreference(mPackageName, mContext);
+    }
+
+    @Override
+    protected boolean isDefaultApp() {
+        return new DefaultBrowserPreferenceController(mContext)
+                .isBrowserDefault(mPackageName, UserHandle.myUserId());
+    }
+
+}
diff --git a/src/com/android/settings/applications/appinfo/DefaultEmergencyShortcutPreferenceController.java b/src/com/android/settings/applications/appinfo/DefaultEmergencyShortcutPreferenceController.java
new file mode 100644
index 0000000..f0c1b8a
--- /dev/null
+++ b/src/com/android/settings/applications/appinfo/DefaultEmergencyShortcutPreferenceController.java
@@ -0,0 +1,40 @@
+/*
+ * 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.appinfo;
+
+import android.content.Context;
+
+import com.android.settings.applications.defaultapps.DefaultEmergencyPreferenceController;
+
+public class DefaultEmergencyShortcutPreferenceController
+        extends DefaultAppShortcutPreferenceControllerBase {
+
+    private static final String KEY = "default_emergency_app";
+
+    public DefaultEmergencyShortcutPreferenceController(Context context, String packageName) {
+        super(context, KEY, packageName);
+    }
+
+    @Override
+    protected boolean hasAppCapability() {
+        return DefaultEmergencyPreferenceController.hasEmergencyPreference(mPackageName, mContext);
+    }
+
+    @Override
+    protected boolean isDefaultApp() {
+        return DefaultEmergencyPreferenceController.isEmergencyDefault(mPackageName, mContext);
+    }
+
+}
diff --git a/src/com/android/settings/applications/appinfo/DefaultHomeShortcutPreferenceController.java b/src/com/android/settings/applications/appinfo/DefaultHomeShortcutPreferenceController.java
new file mode 100644
index 0000000..4ae9083
--- /dev/null
+++ b/src/com/android/settings/applications/appinfo/DefaultHomeShortcutPreferenceController.java
@@ -0,0 +1,42 @@
+/*
+ * 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.appinfo;
+
+import android.content.Context;
+
+import com.android.settings.applications.defaultapps.DefaultHomePreferenceController;
+import com.android.settingslib.wrapper.PackageManagerWrapper;
+
+public class DefaultHomeShortcutPreferenceController
+        extends DefaultAppShortcutPreferenceControllerBase {
+
+    private static final String KEY = "default_home";
+
+    public DefaultHomeShortcutPreferenceController(Context context, String packageName) {
+        super(context, KEY, packageName);
+    }
+
+    @Override
+    protected boolean hasAppCapability() {
+        return DefaultHomePreferenceController.hasHomePreference(mPackageName, mContext);
+    }
+
+    @Override
+    protected boolean isDefaultApp() {
+        return DefaultHomePreferenceController.isHomeDefault(mPackageName,
+                new PackageManagerWrapper(mContext.getPackageManager()));
+    }
+
+}
diff --git a/src/com/android/settings/applications/appinfo/DefaultPhoneShortcutPreferenceController.java b/src/com/android/settings/applications/appinfo/DefaultPhoneShortcutPreferenceController.java
new file mode 100644
index 0000000..c968d55
--- /dev/null
+++ b/src/com/android/settings/applications/appinfo/DefaultPhoneShortcutPreferenceController.java
@@ -0,0 +1,40 @@
+/*
+ * 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.appinfo;
+
+import android.content.Context;
+
+import com.android.settings.applications.defaultapps.DefaultPhonePreferenceController;
+
+public class DefaultPhoneShortcutPreferenceController
+        extends DefaultAppShortcutPreferenceControllerBase {
+
+    private static final String KEY = "default_phone_app";
+
+    public DefaultPhoneShortcutPreferenceController(Context context, String packageName) {
+        super(context, KEY, packageName);
+    }
+
+    @Override
+    protected boolean hasAppCapability() {
+        return DefaultPhonePreferenceController.hasPhonePreference(mPackageName, mContext);
+    }
+
+    @Override
+    protected boolean isDefaultApp() {
+        return DefaultPhonePreferenceController.isPhoneDefault(mPackageName, mContext);
+    }
+
+}
diff --git a/src/com/android/settings/applications/appinfo/DefaultSmsShortcutPreferenceController.java b/src/com/android/settings/applications/appinfo/DefaultSmsShortcutPreferenceController.java
new file mode 100644
index 0000000..cf8b446
--- /dev/null
+++ b/src/com/android/settings/applications/appinfo/DefaultSmsShortcutPreferenceController.java
@@ -0,0 +1,40 @@
+/*
+ * 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.appinfo;
+
+import android.content.Context;
+
+import com.android.settings.applications.defaultapps.DefaultSmsPreferenceController;
+
+public class DefaultSmsShortcutPreferenceController
+        extends DefaultAppShortcutPreferenceControllerBase {
+
+    private static final String KEY = "default_sms_app";
+
+    public DefaultSmsShortcutPreferenceController(Context context, String packageName) {
+        super(context, KEY, packageName);
+    }
+
+    @Override
+    protected boolean hasAppCapability() {
+        return DefaultSmsPreferenceController.hasSmsPreference(mPackageName, mContext);
+    }
+
+    @Override
+    protected boolean isDefaultApp() {
+        return DefaultSmsPreferenceController.isSmsDefault(mPackageName, mContext);
+    }
+
+}
diff --git a/src/com/android/settings/bluetooth/BluetoothEnabler.java b/src/com/android/settings/bluetooth/BluetoothEnabler.java
index f95145d..87fa43d 100644
--- a/src/com/android/settings/bluetooth/BluetoothEnabler.java
+++ b/src/com/android/settings/bluetooth/BluetoothEnabler.java
@@ -23,7 +23,6 @@
 import android.content.IntentFilter;
 import android.os.UserManager;
 import android.provider.Settings;
-import android.widget.Switch;
 import android.widget.Toast;
 
 import com.android.internal.annotations.VisibleForTesting;
@@ -41,8 +40,7 @@
  * preference reflects the current state.
  */
 public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchChangeListener {
-    private final Switch mSwitch;
-    private final SwitchWidgetController mSwitchWidget;
+    private final SwitchWidgetController mSwitchController;
     private final MetricsFeatureProvider mMetricsFeatureProvider;
     private Context mContext;
     private boolean mValidListener;
@@ -64,28 +62,27 @@
         }
     };
 
-    public BluetoothEnabler(Context context, SwitchWidgetController switchWidget,
+    public BluetoothEnabler(Context context, SwitchWidgetController switchController,
             MetricsFeatureProvider metricsFeatureProvider, LocalBluetoothManager manager,
             int metricsEvent) {
-        this(context, switchWidget, metricsFeatureProvider, manager, metricsEvent,
+        this(context, switchController, metricsFeatureProvider, manager, metricsEvent,
                 new RestrictionUtils());
     }
 
-    public BluetoothEnabler(Context context, SwitchWidgetController switchWidget,
+    public BluetoothEnabler(Context context, SwitchWidgetController switchController,
             MetricsFeatureProvider metricsFeatureProvider, LocalBluetoothManager manager,
             int metricsEvent, RestrictionUtils restrictionUtils) {
         mContext = context;
         mMetricsFeatureProvider = metricsFeatureProvider;
-        mSwitchWidget = switchWidget;
-        mSwitch = mSwitchWidget.getSwitch();
-        mSwitchWidget.setListener(this);
+        mSwitchController = switchController;
+        mSwitchController.setListener(this);
         mValidListener = false;
         mMetricsEvent = metricsEvent;
 
         if (manager == null) {
             // Bluetooth is not supported
             mLocalAdapter = null;
-            mSwitchWidget.setEnabled(false);
+            mSwitchController.setEnabled(false);
         } else {
             mLocalAdapter = manager.getBluetoothAdapter();
         }
@@ -94,11 +91,11 @@
     }
 
     public void setupSwitchController() {
-        mSwitchWidget.setupView();
+        mSwitchController.setupView();
     }
 
     public void teardownSwitchController() {
-        mSwitchWidget.teardownView();
+        mSwitchController.teardownView();
     }
 
     public void resume(Context context) {
@@ -109,7 +106,7 @@
         final boolean restricted = maybeEnforceRestrictions();
 
         if (mLocalAdapter == null) {
-            mSwitchWidget.setEnabled(false);
+            mSwitchController.setEnabled(false);
             return;
         }
 
@@ -118,7 +115,7 @@
             handleStateChanged(mLocalAdapter.getBluetoothState());
         }
 
-        mSwitchWidget.startListening();
+        mSwitchController.startListening();
         mContext.registerReceiver(mReceiver, mIntentFilter);
         mValidListener = true;
     }
@@ -128,7 +125,7 @@
             return;
         }
         if (mValidListener) {
-            mSwitchWidget.stopListening();
+            mSwitchController.stopListening();
             mContext.unregisterReceiver(mReceiver);
             mValidListener = false;
         }
@@ -137,37 +134,35 @@
     void handleStateChanged(int state) {
         switch (state) {
             case BluetoothAdapter.STATE_TURNING_ON:
-                mSwitchWidget.setEnabled(false);
+                mSwitchController.setEnabled(false);
                 break;
             case BluetoothAdapter.STATE_ON:
                 setChecked(true);
-                mSwitchWidget.setEnabled(true);
+                mSwitchController.setEnabled(true);
                 break;
             case BluetoothAdapter.STATE_TURNING_OFF:
-                mSwitchWidget.setEnabled(false);
+                mSwitchController.setEnabled(false);
                 break;
             case BluetoothAdapter.STATE_OFF:
                 setChecked(false);
-                mSwitchWidget.setEnabled(true);
+                mSwitchController.setEnabled(true);
                 break;
             default:
                 setChecked(false);
-                mSwitchWidget.setEnabled(true);
+                mSwitchController.setEnabled(true);
         }
     }
 
     private void setChecked(boolean isChecked) {
-        final boolean currentState =
-                (mSwitchWidget.getSwitch() != null) && mSwitchWidget.getSwitch().isChecked();
-        if (isChecked != currentState) {
+        if (isChecked != mSwitchController.isChecked()) {
             // set listener to null, so onCheckedChanged won't be called
             // if the checked status on Switch isn't changed by user click
             if (mValidListener) {
-                mSwitchWidget.stopListening();
+                mSwitchController.stopListening();
             }
-            mSwitchWidget.setChecked(isChecked);
+            mSwitchController.setChecked(isChecked);
             if (mValidListener) {
-                mSwitchWidget.startListening();
+                mSwitchController.startListening();
             }
         }
     }
@@ -183,7 +178,7 @@
                 !WirelessUtils.isRadioAllowed(mContext, Settings.Global.RADIO_BLUETOOTH)) {
             Toast.makeText(mContext, R.string.wifi_in_airplane_mode, Toast.LENGTH_SHORT).show();
             // Reset switch to off
-            mSwitch.setChecked(false);
+            mSwitchController.setChecked(false);
             return false;
         }
 
@@ -195,13 +190,13 @@
             // a) The switch should be OFF but it should still be togglable (enabled = True)
             // b) The switch bar should have OFF text.
             if (isChecked && !status) {
-                mSwitch.setChecked(false);
-                mSwitch.setEnabled(true);
-                mSwitchWidget.updateTitle(false);
+                mSwitchController.setChecked(false);
+                mSwitchController.setEnabled(true);
+                mSwitchController.updateTitle(false);
                 return false;
             }
         }
-        mSwitchWidget.setEnabled(false);
+        mSwitchController.setEnabled(false);
         return true;
     }
 
@@ -213,13 +208,10 @@
     @VisibleForTesting
     boolean maybeEnforceRestrictions() {
         EnforcedAdmin admin = getEnforcedAdmin(mRestrictionUtils, mContext);
-        mSwitchWidget.setDisabledByAdmin(admin);
+        mSwitchController.setDisabledByAdmin(admin);
         if (admin != null) {
-            mSwitchWidget.setChecked(false);
-            if (mSwitch != null) {
-                mSwitch.setEnabled(false);
-                mSwitch.setChecked(false);
-            }
+            mSwitchController.setChecked(false);
+            mSwitchController.setEnabled(false);
         }
         return admin != null;
     }
diff --git a/src/com/android/settings/bluetooth/BluetoothPairingDetail.java b/src/com/android/settings/bluetooth/BluetoothPairingDetail.java
index fcfa3e2..a9756a6 100644
--- a/src/com/android/settings/bluetooth/BluetoothPairingDetail.java
+++ b/src/com/android/settings/bluetooth/BluetoothPairingDetail.java
@@ -73,10 +73,20 @@
     public void onStart() {
         super.onStart();
 
-        updateContent(mLocalAdapter.getBluetoothState());
+        updateBluetooth();
         mAvailableDevicesCategory.setProgress(mLocalAdapter.isDiscovering());
     }
 
+    @VisibleForTesting
+    void updateBluetooth() {
+        if (mLocalAdapter.isEnabled()) {
+            updateContent(mLocalAdapter.getBluetoothState());
+        } else {
+            // Turn on bluetooth if it is disabled
+            mLocalAdapter.enable();
+        }
+    }
+
     @Override
     public void onStop() {
         super.onStop();
diff --git a/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceDashboardFragment.java b/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceDashboardFragment.java
new file mode 100644
index 0000000..ea93fef
--- /dev/null
+++ b/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceDashboardFragment.java
@@ -0,0 +1,134 @@
+/*
+ * 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.connecteddevice;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.provider.SearchIndexableResource;
+
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.R;
+import com.android.settings.SettingsActivity;
+import com.android.settings.bluetooth.BluetoothFilesPreferenceController;
+import com.android.settings.bluetooth.BluetoothMasterSwitchPreferenceController;
+import com.android.settings.bluetooth.Utils;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.deviceinfo.UsbBackend;
+import com.android.settings.nfc.NfcPreferenceController;
+import com.android.settings.overlay.FeatureFactory;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.drawer.CategoryKey;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * This fragment contains all the advanced connection preferences(i.e, Bluetooth, NFC, USB..)
+ */
+public class AdvancedConnectedDeviceDashboardFragment extends DashboardFragment {
+
+    private static final String TAG = "AdvancedConnectedDeviceFrag";
+    private UsbModePreferenceController mUsbPrefController;
+
+    @Override
+    public int getMetricsCategory() {
+        return MetricsProto.MetricsEvent.CONNECTION_DEVICE_ADVANCED;
+    }
+
+    @Override
+    protected String getLogTag() {
+        return TAG;
+    }
+
+    @Override
+    public int getHelpResource() {
+        return R.string.help_url_connected_devices;
+    }
+
+    @Override
+    protected int getPreferenceScreenResId() {
+        return R.xml.connected_devices_advanced;
+    }
+
+    @Override
+    public String getCategoryKey() {
+        //TODO(b/69926683): remove this method and change DashboardFragmentRegistry directly for P
+        return CategoryKey.CATEGORY_DEVICE;
+    }
+
+    @Override
+    protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
+        final List<AbstractPreferenceController> controllers = new ArrayList<>();
+        final Lifecycle lifecycle = getLifecycle();
+        final NfcPreferenceController nfcPreferenceController =
+                new NfcPreferenceController(context);
+        lifecycle.addObserver(nfcPreferenceController);
+        controllers.add(nfcPreferenceController);
+        mUsbPrefController = new UsbModePreferenceController(context, new UsbBackend(context));
+        lifecycle.addObserver(mUsbPrefController);
+        controllers.add(mUsbPrefController);
+        final BluetoothMasterSwitchPreferenceController bluetoothPreferenceController =
+                new BluetoothMasterSwitchPreferenceController(
+                        context, Utils.getLocalBtManager(context), this,
+                        (SettingsActivity) getActivity());
+        lifecycle.addObserver(bluetoothPreferenceController);
+        controllers.add(bluetoothPreferenceController);
+
+        SmsMirroringFeatureProvider smsMirroringFeatureProvider =
+                FeatureFactory.getFactory(context).getSmsMirroringFeatureProvider();
+        AbstractPreferenceController smsMirroringController =
+                smsMirroringFeatureProvider.getController(context);
+        controllers.add(smsMirroringController);
+        controllers.add(new BluetoothFilesPreferenceController(context));
+        return controllers;
+    }
+
+    /**
+     * For Search.
+     */
+    public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+            new BaseSearchIndexProvider() {
+                @Override
+                public List<SearchIndexableResource> getXmlResourcesToIndex(
+                        Context context, boolean enabled) {
+                    final SearchIndexableResource sir = new SearchIndexableResource(context);
+                    sir.xmlResId = R.xml.connected_devices_advanced;
+                    return Arrays.asList(sir);
+                }
+
+                @Override
+                public List<String> getNonIndexableKeys(Context context) {
+                    final List<String> keys = super.getNonIndexableKeys(context);
+                    PackageManager pm = context.getPackageManager();
+                    if (!pm.hasSystemFeature(PackageManager.FEATURE_NFC)) {
+                        keys.add(NfcPreferenceController.KEY_TOGGLE_NFC);
+                        keys.add(NfcPreferenceController.KEY_ANDROID_BEAM_SETTINGS);
+                    }
+                    keys.add(BluetoothMasterSwitchPreferenceController.KEY_TOGGLE_BLUETOOTH);
+
+                    SmsMirroringFeatureProvider smsMirroringFeatureProvider =
+                            FeatureFactory.getFactory(context).getSmsMirroringFeatureProvider();
+                    SmsMirroringPreferenceController smsMirroringController =
+                            smsMirroringFeatureProvider.getController(context);
+                    smsMirroringController.updateNonIndexableKeys(keys);
+
+                    return keys;
+                }
+            };
+}
diff --git a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
index e4a6a64..e9ae11e 100644
--- a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
+++ b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
@@ -64,8 +64,8 @@
 
         controllers.add(new ConnectedDeviceGroupController(this, lifecycle));
         controllers.add(new SavedDeviceGroupController(this, lifecycle));
-        return controllers;
 
+        return controllers;
     }
 
     @VisibleForTesting
diff --git a/src/com/android/settings/dashboard/DashboardAdapter.java b/src/com/android/settings/dashboard/DashboardAdapter.java
index 54a1eeb..3d473f0 100644
--- a/src/com/android/settings/dashboard/DashboardAdapter.java
+++ b/src/com/android/settings/dashboard/DashboardAdapter.java
@@ -161,7 +161,6 @@
     }
 
     public void setSuggestionsV2(List<Suggestion> data) {
-        // TODO: Tint icon
         final DashboardData prevData = mDashboardData;
         mDashboardData = new DashboardData.Builder(prevData)
                 .setSuggestionsV2(data)
diff --git a/src/com/android/settings/dashboard/DashboardSummary.java b/src/com/android/settings/dashboard/DashboardSummary.java
index 8f66b67..ff2a76a 100644
--- a/src/com/android/settings/dashboard/DashboardSummary.java
+++ b/src/com/android/settings/dashboard/DashboardSummary.java
@@ -81,6 +81,9 @@
     private boolean isOnCategoriesChangedCalled;
     private boolean mOnConditionsChangedCalled;
 
+    private DashboardCategory mStagingCategory;
+    private List<Suggestion> mStagingSuggestions;
+
     @Override
     public int getMetricsCategory() {
         return MetricsEvent.DASHBOARD_SUMMARY;
@@ -291,7 +294,13 @@
 
     @Override
     public void onSuggestionReady(List<Suggestion> suggestions) {
+        mStagingSuggestions = suggestions;
         mAdapter.setSuggestionsV2(suggestions);
+        if (mStagingCategory != null) {
+            Log.d(TAG, "Category has loaded, setting category from suggestionReady");
+            mHandler.removeCallbacksAndMessages(null);
+            mAdapter.setCategory(mStagingCategory);
+        }
     }
 
     /**
@@ -342,7 +351,19 @@
         final DashboardCategory category = mDashboardFeatureProvider.getTilesForCategory(
                 CategoryKey.CATEGORY_HOMEPAGE);
         mSummaryLoader.updateSummaryToCache(category);
-        ThreadUtils.postOnMainThread(() -> mAdapter.setCategory(category));
+        mStagingCategory = category;
+        if (mSuggestionControllerMixin.isSuggestionLoaded()) {
+            Log.d(TAG, "Suggestion has loaded, setting suggestion/category");
+            ThreadUtils.postOnMainThread(() -> {
+                if (mStagingSuggestions != null) {
+                    mAdapter.setSuggestionsV2(mStagingSuggestions);
+                }
+                mAdapter.setCategory(mStagingCategory);
+            });
+        } else {
+            Log.d(TAG, "Suggestion NOT loaded, delaying setCategory by " + MAX_WAIT_MILLIS + "ms");
+            mHandler.postDelayed(() -> mAdapter.setCategory(mStagingCategory), MAX_WAIT_MILLIS);
+        }
     }
 
     /**
diff --git a/src/com/android/settings/dashboard/suggestions/SuggestionControllerMixin.java b/src/com/android/settings/dashboard/suggestions/SuggestionControllerMixin.java
index 71bf107..81496ee 100644
--- a/src/com/android/settings/dashboard/suggestions/SuggestionControllerMixin.java
+++ b/src/com/android/settings/dashboard/suggestions/SuggestionControllerMixin.java
@@ -59,6 +59,8 @@
     private final SuggestionController mSuggestionController;
     private final SuggestionControllerHost mHost;
 
+    private boolean mSuggestionLoaded;
+
     public SuggestionControllerMixin(Context context, SuggestionControllerHost host,
             Lifecycle lifecycle) {
         mContext = context.getApplicationContext();
@@ -106,6 +108,7 @@
     @Override
     public Loader<List<Suggestion>> onCreateLoader(int id, Bundle args) {
         if (id == SuggestionLoader.LOADER_ID_SUGGESTIONS) {
+            mSuggestionLoaded = false;
             return new SuggestionLoader(mContext, mSuggestionController);
         }
         throw new IllegalArgumentException("This loader id is not supported " + id);
@@ -113,12 +116,17 @@
 
     @Override
     public void onLoadFinished(Loader<List<Suggestion>> loader, List<Suggestion> data) {
+        mSuggestionLoaded = true;
         mHost.onSuggestionReady(data);
     }
 
     @Override
     public void onLoaderReset(Loader<List<Suggestion>> loader) {
+        mSuggestionLoaded = false;
+    }
 
+    public boolean isSuggestionLoaded() {
+        return mSuggestionLoaded;
     }
 
     public void dismissSuggestion(Suggestion suggestion) {
diff --git a/src/com/android/settings/deviceinfo/SimStatus.java b/src/com/android/settings/deviceinfo/SimStatus.java
index 768beb8..dad4419 100644
--- a/src/com/android/settings/deviceinfo/SimStatus.java
+++ b/src/com/android/settings/deviceinfo/SimStatus.java
@@ -408,6 +408,12 @@
         if (!mShowLatestAreaInfo) {
             removePreferenceFromScreen(KEY_LATEST_AREA_INFO);
         }
+
+        boolean hideSignalStrength = carrierConfig.getBoolean(
+                CarrierConfigManager.KEY_HIDE_SIGNAL_STRENGTH_IN_SIM_STATUS_BOOL);
+        if (hideSignalStrength) {
+            removePreferenceFromScreen(KEY_SIGNAL_STRENGTH);
+        }
     }
 
     private void updatePhoneInfos() {
diff --git a/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogController.java b/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogController.java
index 33bb1d4..f9555e2 100644
--- a/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogController.java
+++ b/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogController.java
@@ -80,9 +80,6 @@
      * Sets IMEI/MEID information based on whether the device is CDMA or GSM.
      */
     public void populateImeiInfo() {
-        if (mSubscriptionInfo == null) {
-            return;
-        }
         if (mTelephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) {
             updateDialogForCdmaPhone();
         } else {
@@ -94,7 +91,8 @@
         final Resources res = mDialog.getContext().getResources();
         mDialog.setText(ID_MEID_NUMBER_VALUE, getMeid());
         mDialog.setText(ID_MIN_NUMBER_VALUE,
-                mTelephonyManager.getCdmaMin(mSubscriptionInfo.getSubscriptionId()));
+                mSubscriptionInfo != null ? mTelephonyManager.getCdmaMin(
+                        mSubscriptionInfo.getSubscriptionId()) : "");
 
         if (res.getBoolean(R.bool.config_msid_enable)) {
             mDialog.setText(ID_MIN_NUMBER_LABEL,
@@ -103,7 +101,7 @@
 
         mDialog.setText(ID_PRL_VERSION_VALUE, getCdmaPrlVersion());
 
-        if (isCdmaLteEnabled()) {
+        if (mSubscriptionInfo != null && isCdmaLteEnabled()) {
             // Show IMEI for LTE device
             mDialog.setText(ID_IMEI_VALUE,
                     getTextAsDigits(mTelephonyManager.getImei(mSlotId)));
diff --git a/src/com/android/settings/network/AirplaneModePreferenceController.java b/src/com/android/settings/network/AirplaneModePreferenceController.java
index 0620f14..d86f7f7 100644
--- a/src/com/android/settings/network/AirplaneModePreferenceController.java
+++ b/src/com/android/settings/network/AirplaneModePreferenceController.java
@@ -100,12 +100,16 @@
     }
 
     public void onResume() {
-        mAirplaneModeEnabler.resume();
+        if (mAirplaneModeEnabler != null) {
+            mAirplaneModeEnabler.resume();
+        }
     }
 
     @Override
     public void onPause() {
-        mAirplaneModeEnabler.pause();
+        if (mAirplaneModeEnabler != null) {
+            mAirplaneModeEnabler.pause();
+        }
     }
 
     public void onActivityResult(int requestCode, int resultCode, Intent data) {
diff --git a/src/com/android/settings/notification/AbstractZenModePreferenceController.java b/src/com/android/settings/notification/AbstractZenModePreferenceController.java
index ec275b2..de2e8fd 100644
--- a/src/com/android/settings/notification/AbstractZenModePreferenceController.java
+++ b/src/com/android/settings/notification/AbstractZenModePreferenceController.java
@@ -22,10 +22,12 @@
 import android.database.ContentObserver;
 import android.net.Uri;
 import android.os.Handler;
+import android.os.UserHandle;
 import android.provider.Settings;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceScreen;
 
+import com.android.internal.annotations.VisibleForTesting;
 import com.android.settings.core.PreferenceControllerMixin;
 import com.android.settingslib.core.AbstractPreferenceController;
 import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -37,7 +39,8 @@
         AbstractPreferenceController implements PreferenceControllerMixin, LifecycleObserver,
         OnResume, OnPause {
 
-    private SettingObserver mSettingObserver;
+    @VisibleForTesting
+    protected SettingObserver mSettingObserver;
     private final String KEY;
     final private NotificationManager mNotificationManager;
 
@@ -94,8 +97,8 @@
         }
 
         public void register(ContentResolver cr) {
-            cr.registerContentObserver(ZEN_MODE_URI, false, this);
-            cr.registerContentObserver(ZEN_MODE_CONFIG_ETAG_URI, false, this);
+            cr.registerContentObserver(ZEN_MODE_URI, false, this, UserHandle.USER_ALL);
+            cr.registerContentObserver(ZEN_MODE_CONFIG_ETAG_URI, false, this, UserHandle.USER_ALL);
         }
 
         public void unregister(ContentResolver cr) {
diff --git a/src/com/android/settings/search/IndexDatabaseHelper.java b/src/com/android/settings/search/IndexDatabaseHelper.java
index 19e3419..7073545 100644
--- a/src/com/android/settings/search/IndexDatabaseHelper.java
+++ b/src/com/android/settings/search/IndexDatabaseHelper.java
@@ -293,7 +293,8 @@
     }
 
     static void setBuildIndexed(Context context, String buildNo) {
-        context.getSharedPreferences(SHARED_PREFS_TAG, 0).edit().putBoolean(buildNo, true).commit();
+        // Use #apply() instead of #commit() since #commit() Robolectric loop indefinitely in sdk 26
+        context.getSharedPreferences(SHARED_PREFS_TAG, 0).edit().putBoolean(buildNo, true).apply();
     }
 
     private void dropTables(SQLiteDatabase db) {
diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java
index 1f88872..c4e178f 100644
--- a/src/com/android/settings/search/SearchIndexableResources.java
+++ b/src/com/android/settings/search/SearchIndexableResources.java
@@ -33,6 +33,7 @@
 import com.android.settings.backup.BackupSettingsActivity;
 import com.android.settings.backup.BackupSettingsFragment;
 import com.android.settings.bluetooth.BluetoothSettings;
+import com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment;
 import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
 import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragmentOld;
 import com.android.settings.datausage.DataUsageMeteredSettings;
@@ -155,6 +156,7 @@
         addIndex(StorageDashboardFragment.class);
         addIndex(ConnectedDeviceDashboardFragment.class);
         addIndex(ConnectedDeviceDashboardFragmentOld.class);
+        addIndex(AdvancedConnectedDeviceDashboardFragment.class);
         addIndex(EnterprisePrivacySettings.class);
         addIndex(PaymentSettings.class);
         addIndex(TextToSpeechSettings.class);
diff --git a/src/com/android/settings/search/SearchViewHolder.java b/src/com/android/settings/search/SearchViewHolder.java
index ed72940..7667a06 100644
--- a/src/com/android/settings/search/SearchViewHolder.java
+++ b/src/com/android/settings/search/SearchViewHolder.java
@@ -17,6 +17,7 @@
 package com.android.settings.search;
 
 import android.content.Context;
+import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
 import android.graphics.drawable.Drawable;
 import android.os.UserHandle;
@@ -26,6 +27,7 @@
 import android.view.View;
 import android.widget.ImageView;
 import android.widget.TextView;
+import android.support.annotation.VisibleForTesting;
 
 import com.android.settings.R;
 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
@@ -84,8 +86,7 @@
             AppSearchResult appResult = (AppSearchResult) result;
             PackageManager pm = fragment.getActivity().getPackageManager();
             UserHandle userHandle = appResult.getAppUserHandle();
-            Drawable badgedIcon =
-                    mIconDrawableFactory.getBadgedIcon(appResult.info, userHandle.getIdentifier());
+            Drawable badgedIcon = getBadgedIcon(appResult.info, userHandle.getIdentifier());
             iconView.setImageDrawable(badgedIcon);
             titleView.setContentDescription(
                     pm.getUserBadgedLabel(appResult.info.loadLabel(pm), userHandle));
@@ -112,4 +113,9 @@
         breadcrumbView.setText(breadcrumb);
         breadcrumbView.setVisibility(View.VISIBLE);
     }
+
+    @VisibleForTesting
+    Drawable getBadgedIcon(ApplicationInfo info, int userId) {
+        return mIconDrawableFactory.getBadgedIcon(info, userId);
+    }
 }
\ No newline at end of file
diff --git a/src/com/android/settings/webview/WebViewAppPreferenceController.java b/src/com/android/settings/webview/WebViewAppPreferenceController.java
deleted file mode 100644
index 18d874e..0000000
--- a/src/com/android/settings/webview/WebViewAppPreferenceController.java
+++ /dev/null
@@ -1,76 +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.webview;
-
-import android.content.Context;
-import android.content.pm.PackageInfo;
-import android.support.v7.preference.Preference;
-import android.support.v7.preference.PreferenceScreen;
-
-import com.android.settings.applications.defaultapps.DefaultAppInfo;
-import com.android.settings.applications.defaultapps.DefaultAppPreferenceController;
-
-/**
- * Deprecated in favor of {@link com.android.settings.development.WebViewAppPreferenceController}
- */
-@Deprecated
-public class WebViewAppPreferenceController extends DefaultAppPreferenceController {
-
-    private static final String WEBVIEW_APP_KEY = "select_webview_provider";
-
-    private final WebViewUpdateServiceWrapper mWebViewUpdateServiceWrapper;
-    private Preference mPreference;
-
-    public WebViewAppPreferenceController(Context context) {
-        this(context, new WebViewUpdateServiceWrapper());
-    }
-
-    public WebViewAppPreferenceController(Context context,
-            WebViewUpdateServiceWrapper webviewUpdateServiceWrapper) {
-        super(context);
-        mWebViewUpdateServiceWrapper = webviewUpdateServiceWrapper;
-    }
-
-    @Override
-    public DefaultAppInfo getDefaultAppInfo() {
-        PackageInfo currentPackage = mWebViewUpdateServiceWrapper.getCurrentWebViewPackage();
-        return new DefaultAppInfo(mContext, mPackageManager,
-                currentPackage == null ? null : currentPackage.applicationInfo);
-    }
-
-    @Override
-    public void displayPreference(PreferenceScreen screen) {
-        super.displayPreference(screen);
-        if (isAvailable()) {
-            mPreference = screen.findPreference(WEBVIEW_APP_KEY);
-        }
-    }
-
-    @Override
-    public String getPreferenceKey() {
-        return WEBVIEW_APP_KEY;
-    }
-
-    @Override
-    public boolean isAvailable() {
-        return true;
-    }
-
-    public void enablePreference(boolean enabled) {
-        if (isAvailable()) {
-            mPreference.setEnabled(enabled);
-        }
-    }
-}
diff --git a/src/com/android/settings/widget/MasterSwitchController.java b/src/com/android/settings/widget/MasterSwitchController.java
index f7253fd..a22640c 100644
--- a/src/com/android/settings/widget/MasterSwitchController.java
+++ b/src/com/android/settings/widget/MasterSwitchController.java
@@ -74,9 +74,4 @@
     public void setDisabledByAdmin(EnforcedAdmin admin) {
         mPreference.setDisabledByAdmin(admin);
     }
-
-    @Override
-    public Switch getSwitch() {
-        return mPreference.getSwitch();
-    }
 }
diff --git a/src/com/android/settings/widget/MasterSwitchPreference.java b/src/com/android/settings/widget/MasterSwitchPreference.java
index 29bc17b..d47de88 100644
--- a/src/com/android/settings/widget/MasterSwitchPreference.java
+++ b/src/com/android/settings/widget/MasterSwitchPreference.java
@@ -90,7 +90,7 @@
     }
 
     public boolean isChecked() {
-        return mSwitch != null && mSwitch.isEnabled() && mChecked;
+        return mSwitch != null && mChecked;
     }
 
     public void setChecked(boolean checked) {
diff --git a/src/com/android/settings/widget/SwitchBarController.java b/src/com/android/settings/widget/SwitchBarController.java
index 624db2a..cc4c8dc 100644
--- a/src/com/android/settings/widget/SwitchBarController.java
+++ b/src/com/android/settings/widget/SwitchBarController.java
@@ -82,10 +82,4 @@
     public void setDisabledByAdmin(EnforcedAdmin admin) {
         mSwitchBar.setDisabledByAdmin(admin);
     }
-
-    @Override
-    public Switch getSwitch() {
-        return mSwitchBar.getSwitch();
-    }
-
 }
diff --git a/src/com/android/settings/widget/SwitchWidgetController.java b/src/com/android/settings/widget/SwitchWidgetController.java
index 325a093..6c4f40a 100644
--- a/src/com/android/settings/widget/SwitchWidgetController.java
+++ b/src/com/android/settings/widget/SwitchWidgetController.java
@@ -16,7 +16,6 @@
 
 package com.android.settings.widget;
 
-import android.widget.Switch;
 import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
 
 /*
@@ -108,12 +107,4 @@
      * is {@code null}, then this preference will be enabled. Otherwise, it will be disabled.
      */
     public abstract void setDisabledByAdmin(EnforcedAdmin admin);
-
-    /**
-     * Get the underlying switch widget.
-     *
-     * @return the switch widget.
-     */
-    public abstract Switch getSwitch();
-
 }
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/DeviceAdminAddTest.java b/tests/robotests/src/com/android/settings/DeviceAdminAddTest.java
index 82b8e1b..ccd0485 100644
--- a/tests/robotests/src/com/android/settings/DeviceAdminAddTest.java
+++ b/tests/robotests/src/com/android/settings/DeviceAdminAddTest.java
@@ -16,6 +16,10 @@
 
 package com.android.settings;
 
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.verify;
+
 import android.content.Context;
 
 import com.android.internal.logging.nano.MetricsProto;
@@ -25,30 +29,22 @@
 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.Robolectric;
 import org.robolectric.annotation.Config;
 
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.verify;
-
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class DeviceAdminAddTest {
 
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private Context mContext;
     private FakeFeatureFactory mFeatureFactory;
     private DeviceAdminAdd mDeviceAdminAdd;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mDeviceAdminAdd = Robolectric.buildActivity(DeviceAdminAdd.class).get();
     }
 
diff --git a/tests/robotests/src/com/android/settings/accessibility/ShortcutServicePickerFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/ShortcutServicePickerFragmentTest.java
index 2e95c73..b2eb5b4 100644
--- a/tests/robotests/src/com/android/settings/accessibility/ShortcutServicePickerFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/ShortcutServicePickerFragmentTest.java
@@ -17,7 +17,6 @@
 package com.android.settings.accessibility;
 
 import static com.google.common.truth.Truth.assertThat;
-
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.when;
@@ -29,7 +28,6 @@
 import com.android.settings.TestConfig;
 import com.android.settings.testutils.FakeFeatureFactory;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
-import com.android.settingslib.wrapper.PackageManagerWrapper;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -54,15 +52,13 @@
     private Activity mActivity;
     @Mock
     private UserManager mUserManager;
-    @Mock
-    private PackageManagerWrapper mPackageManager;
 
     private ShortcutServicePickerFragment mFragment;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mActivity);
+        FakeFeatureFactory.setupForTest();
         when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
 
         mFragment = spy(new ShortcutServicePickerFragment());
diff --git a/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java
index 8924551..323a624 100644
--- a/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java
@@ -15,6 +15,15 @@
  */
 package com.android.settings.accounts;
 
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Answers.RETURNS_DEEP_STUBS;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+import static org.robolectric.Shadows.shadowOf;
+
 import android.accounts.Account;
 import android.accounts.AccountManager;
 import android.app.Activity;
@@ -30,7 +39,6 @@
 import com.android.internal.logging.nano.MetricsProto;
 import com.android.settings.TestConfig;
 import com.android.settings.dashboard.DashboardFeatureProviderImpl;
-import com.android.settings.testutils.FakeFeatureFactory;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settingslib.drawer.CategoryKey;
 import com.android.settingslib.drawer.Tile;
@@ -45,15 +53,6 @@
 import org.robolectric.shadows.ShadowApplication;
 import org.robolectric.util.ReflectionHelpers;
 
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Answers.RETURNS_DEEP_STUBS;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-import static org.robolectric.Shadows.shadowOf;
-
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class AccountDetailDashboardFragmentTest {
@@ -127,9 +126,6 @@
 
     @Test
     public void refreshDashboardTiles_HasAccountType_shouldAddAccountNameToIntent() {
-        FakeFeatureFactory.setupForTest(mContext);
-        final FakeFeatureFactory featureFactory =
-                (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
         final DashboardFeatureProviderImpl dashboardFeatureProvider =
                 new DashboardFeatureProviderImpl(mContext);
         final PackageManager packageManager = mock(PackageManager.class);
diff --git a/tests/robotests/src/com/android/settings/accounts/AccountHeaderPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/AccountHeaderPreferenceControllerTest.java
index 1b20e96..0c15339 100644
--- a/tests/robotests/src/com/android/settings/accounts/AccountHeaderPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AccountHeaderPreferenceControllerTest.java
@@ -80,7 +80,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
+        FakeFeatureFactory.setupForTest();
         mHeaderPreference = new LayoutPreference(
                 RuntimeEnvironment.application, R.layout.settings_entity_header);
         doReturn(mContext).when(mActivity).getApplicationContext();
diff --git a/tests/robotests/src/com/android/settings/applications/AppInfoDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/applications/AppInfoDashboardFragmentTest.java
index 3462467..3314a21 100644
--- a/tests/robotests/src/com/android/settings/applications/AppInfoDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/applications/AppInfoDashboardFragmentTest.java
@@ -73,8 +73,7 @@
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(
     manifest = TestConfig.MANIFEST_PATH,
-    sdk = TestConfig.SDK_VERSION_O,
-    shadows = AppInfoDashboardFragmentTest.ShadowUtils.class
+    sdk = TestConfig.SDK_VERSION_O
 )
 public final class AppInfoDashboardFragmentTest {
 
@@ -101,7 +100,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        mFeatureFactory = FakeFeatureFactory.setupForTest(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mShadowContext = RuntimeEnvironment.application;
         mAppDetail = spy(new AppInfoDashboardFragment());
         doReturn(mActivity).when(mAppDetail).getActivity();
@@ -369,6 +368,7 @@
     }
 
     @Test
+    @Config(shadows = ShadowUtils.class)
     public void handleDisableable_appIsEnabled_buttonShouldWork() {
         final ApplicationInfo info = new ApplicationInfo();
         info.packageName = "pkg";
@@ -411,6 +411,7 @@
     }
 
     @Test
+    @Config(shadows = ShadowUtils.class)
     public void handleDisableable_appIsEnabledAndInKeepEnabledWhitelist_buttonShouldNotWork() {
         final ApplicationInfo info = new ApplicationInfo();
         info.packageName = "pkg";
diff --git a/tests/robotests/src/com/android/settings/applications/AppInfoWithHeaderTest.java b/tests/robotests/src/com/android/settings/applications/AppInfoWithHeaderTest.java
index 75ae458..7c9e81c 100644
--- a/tests/robotests/src/com/android/settings/applications/AppInfoWithHeaderTest.java
+++ b/tests/robotests/src/com/android/settings/applications/AppInfoWithHeaderTest.java
@@ -17,7 +17,6 @@
 package com.android.settings.applications;
 
 import static com.google.common.truth.Truth.assertThat;
-
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
@@ -61,8 +60,6 @@
         shadows = ShadowEntityHeaderController.class)
 public class AppInfoWithHeaderTest {
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private Context mContext;
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private EntityHeaderController mHeaderController;
 
     private FakeFeatureFactory mFactory;
@@ -71,9 +68,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-
-        mFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFactory = FakeFeatureFactory.setupForTest();
         when(mFactory.metricsFeatureProvider.getMetricsCategory(any(Object.class)))
                 .thenReturn(MetricsProto.MetricsEvent.SETTINGS_APP_NOTIF_CATEGORY);
         mAppInfoWithHeader = new TestFragment();
diff --git a/tests/robotests/src/com/android/settings/applications/DrawOverlayDetailsTest.java b/tests/robotests/src/com/android/settings/applications/DrawOverlayDetailsTest.java
index 38c0128..bc7738c 100644
--- a/tests/robotests/src/com/android/settings/applications/DrawOverlayDetailsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/DrawOverlayDetailsTest.java
@@ -63,8 +63,8 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mActivity);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mActivity);
+
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java b/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
index b8a27b9..b6f75d4 100644
--- a/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
@@ -130,7 +130,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        mFeatureFactory = FakeFeatureFactory.setupForTest(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mShadowContext = RuntimeEnvironment.application;
         mAppDetail = spy(new InstalledAppDetails());
         mAppDetail.mBatteryUtils = mBatteryUtils;
diff --git a/tests/robotests/src/com/android/settings/applications/PictureInPictureDetailsTest.java b/tests/robotests/src/com/android/settings/applications/PictureInPictureDetailsTest.java
index b998b81e..0291392 100644
--- a/tests/robotests/src/com/android/settings/applications/PictureInPictureDetailsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/PictureInPictureDetailsTest.java
@@ -17,7 +17,6 @@
 package com.android.settings.applications;
 
 import static com.google.common.truth.Truth.assertThat;
-
 import static org.mockito.ArgumentMatchers.nullable;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.verify;
@@ -25,16 +24,14 @@
 import android.content.Context;
 
 import com.android.internal.logging.nano.MetricsProto;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.wrapper.ActivityInfoWrapper;
 
 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.annotation.Config;
 
@@ -42,17 +39,13 @@
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class PictureInPictureDetailsTest {
 
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private Context mContext;
-
     private FakeFeatureFactory mFeatureFactory;
     private PictureInPictureDetails mFragment;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mFragment = new PictureInPictureDetails();
     }
 
diff --git a/tests/robotests/src/com/android/settings/applications/PictureInPictureSettingsTest.java b/tests/robotests/src/com/android/settings/applications/PictureInPictureSettingsTest.java
index 85b398a..81df422 100644
--- a/tests/robotests/src/com/android/settings/applications/PictureInPictureSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/PictureInPictureSettingsTest.java
@@ -17,22 +17,16 @@
 package com.android.settings.applications;
 
 import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.ArgumentMatchers.nullable;
 import static org.mockito.Matchers.anyInt;
 import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-import android.content.Context;
 import android.content.pm.ActivityInfo;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageInfo;
 import android.content.pm.UserInfo;
 import android.util.Pair;
 
-import com.android.internal.logging.nano.MetricsProto;
 import com.android.settings.TestConfig;
 import com.android.settings.testutils.FakeFeatureFactory;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -42,7 +36,6 @@
 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.annotation.Config;
@@ -57,9 +50,6 @@
     private static final int PRIMARY_USER_ID = 0;
     private static final int PROFILE_USER_ID = 10;
 
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private Context mContext;
-
     private FakeFeatureFactory mFeatureFactory;
     private PictureInPictureSettings mFragment;
     @Mock
@@ -73,8 +63,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mFragment = new PictureInPictureSettings(mPackageManager, mUserManager);
         mPrimaryUserPackages = new ArrayList<>();
         mProfileUserPackages = new ArrayList<>();
diff --git a/tests/robotests/src/com/android/settings/applications/PremiumSmsAccessTest.java b/tests/robotests/src/com/android/settings/applications/PremiumSmsAccessTest.java
index dedb61d..32a11f4 100644
--- a/tests/robotests/src/com/android/settings/applications/PremiumSmsAccessTest.java
+++ b/tests/robotests/src/com/android/settings/applications/PremiumSmsAccessTest.java
@@ -41,17 +41,13 @@
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class PremiumSmsAccessTest {
 
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private Context mContext;
-
     private FakeFeatureFactory mFeatureFactory;
     private PremiumSmsAccess mFragment;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mFragment = new PremiumSmsAccess();
         mFragment.onAttach(ShadowApplication.getInstance().getApplicationContext());
     }
diff --git a/tests/robotests/src/com/android/settings/applications/UsageAccessDetailsTest.java b/tests/robotests/src/com/android/settings/applications/UsageAccessDetailsTest.java
index 64ef4ff..44b54a8 100644
--- a/tests/robotests/src/com/android/settings/applications/UsageAccessDetailsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/UsageAccessDetailsTest.java
@@ -34,8 +34,6 @@
 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.annotation.Config;
 import org.robolectric.shadows.ShadowApplication;
@@ -44,17 +42,13 @@
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class UsageAccessDetailsTest {
 
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private Context mContext;
-
     private FakeFeatureFactory mFeatureFactory;
     private UsageAccessDetails mFragment;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mFragment = new UsageAccessDetails();
         mFragment.onAttach(ShadowApplication.getInstance().getApplicationContext());
     }
diff --git a/tests/robotests/src/com/android/settings/applications/VrListenerSettingsTest.java b/tests/robotests/src/com/android/settings/applications/VrListenerSettingsTest.java
index 5f9ec95..ed14879 100644
--- a/tests/robotests/src/com/android/settings/applications/VrListenerSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/VrListenerSettingsTest.java
@@ -23,15 +23,13 @@
 import android.content.Context;
 
 import com.android.internal.logging.nano.MetricsProto;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 
 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.annotation.Config;
 
@@ -39,17 +37,13 @@
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class VrListenerSettingsTest {
 
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private Context mContext;
-
     private FakeFeatureFactory mFeatureFactory;
     private VrListenerSettings mFragment;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mFragment = new VrListenerSettings();
     }
 
diff --git a/tests/robotests/src/com/android/settings/applications/WriteSettingsDetailsTest.java b/tests/robotests/src/com/android/settings/applications/WriteSettingsDetailsTest.java
index 6cd07e3..746bcf5 100644
--- a/tests/robotests/src/com/android/settings/applications/WriteSettingsDetailsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/WriteSettingsDetailsTest.java
@@ -23,15 +23,13 @@
 import android.content.Context;
 
 import com.android.internal.logging.nano.MetricsProto;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 
 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.annotation.Config;
 
@@ -39,17 +37,14 @@
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class WriteSettingsDetailsTest {
 
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private Context mContext;
-
     private FakeFeatureFactory mFeatureFactory;
     private WriteSettingsDetails mFragment;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mFragment = new WriteSettingsDetails();
     }
 
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBaseTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBaseTest.java
new file mode 100644
index 0000000..1a06f3b
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBaseTest.java
@@ -0,0 +1,145 @@
+/*
+ * 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.appinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.argThat;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.os.UserManager;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.SettingsActivity;
+import com.android.settings.TestConfig;
+import com.android.settings.applications.AppInfoDashboardFragment;
+import com.android.settings.applications.DefaultAppSettings;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class DefaultAppShortcutPreferenceControllerBaseTest {
+
+    @Mock
+    private UserManager mUserManager;
+    @Mock
+    private AppInfoDashboardFragment mFragment;
+    @Mock
+    private PreferenceScreen mScreen;
+    @Mock
+    private Preference mPreference;
+
+    private Context mContext;
+    private TestPreferenceController mController;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mContext = spy(RuntimeEnvironment.application);
+        when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
+        mController = new TestPreferenceController(mContext, mFragment);
+        final String key = mController.getPreferenceKey();
+        when(mPreference.getKey()).thenReturn(key);
+    }
+
+    @Test
+    public void getAvailabilityStatus_managedProfile_shouldReturnDisabled() {
+        when(mUserManager.isManagedProfile()).thenReturn(true);
+
+        assertThat(mController.getAvailabilityStatus()).isEqualTo(mController.DISABLED_FOR_USER);
+    }
+
+    @Test
+    public void getAvailabilityStatus_hasAppCapability_shouldReturnAvailable() {
+        mController.capable = true;
+        when(mUserManager.isManagedProfile()).thenReturn(false);
+
+        assertThat(mController.getAvailabilityStatus()).isEqualTo(mController.AVAILABLE);
+    }
+
+    @Test
+    public void getAvailabilityStatus_noAppCapability_shouldReturnDisabled() {
+        mController.capable = false;
+        when(mUserManager.isManagedProfile()).thenReturn(false);
+
+        assertThat(mController.getAvailabilityStatus()).isEqualTo(mController.DISABLED_UNSUPPORTED);
+    }
+
+    @Test
+    public void updateState_isDefaultApp_shouldSetSummaryToYes() {
+        mController.isDefault = true;
+
+        mController.updateState(mPreference);
+
+        verify(mPreference).setSummary(R.string.yes);
+    }
+
+    @Test
+    public void updateState_notDefaultApp_shouldSetSummaryToNo() {
+        mController.isDefault = false;
+
+        mController.updateState(mPreference);
+
+        verify(mPreference).setSummary(R.string.no);
+    }
+
+    @Test
+    public void handlePreferenceTreeClick_shouldStartDefaultAppSettings() {
+        mController.handlePreferenceTreeClick(mPreference);
+
+        verify(mContext).startActivity(argThat(intent-> intent != null
+                && intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT).equals(
+                        DefaultAppSettings.class.getName())
+                && intent.getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS)
+                .getString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY).equals("TestKey")));
+    }
+
+    private class TestPreferenceController extends DefaultAppShortcutPreferenceControllerBase {
+
+        private boolean isDefault;
+        private boolean capable;
+
+        public TestPreferenceController(Context context, AppInfoDashboardFragment parent) {
+            super(context, "TestKey", "TestPackage");
+        }
+
+        @Override
+        protected boolean hasAppCapability() {
+            return capable;
+        }
+
+        @Override
+        protected boolean isDefaultApp() {
+            return isDefault;
+        }
+
+    }
+
+}
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/DefaultBrowserShortcutPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultBrowserShortcutPreferenceControllerTest.java
new file mode 100644
index 0000000..0a18722
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultBrowserShortcutPreferenceControllerTest.java
@@ -0,0 +1,96 @@
+/*
+ * 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.appinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.argThat;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class DefaultBrowserShortcutPreferenceControllerTest {
+
+    @Mock
+    private PackageManager mPackageManager;
+
+    private Context mContext;
+    private DefaultBrowserShortcutPreferenceController mController;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mContext = spy(RuntimeEnvironment.application);
+        when(mContext.getPackageManager()).thenReturn(mPackageManager);
+        mController = new DefaultBrowserShortcutPreferenceController(mContext, "Package1");
+    }
+
+    @Test
+    public void getPreferenceKey_shouldReturnDefaultBrowser() {
+        assertThat(mController.getPreferenceKey()).isEqualTo("default_browser");
+    }
+
+    @Test
+    public void hasAppCapability_hasBrowserCapability_shouldReturnTrue() {
+        List<ResolveInfo> resolveInfos = new ArrayList<>();
+        resolveInfos.add(new ResolveInfo());
+        when(mPackageManager.queryIntentActivities(argThat(intent-> intent != null
+                && intent.getCategories().contains(Intent.CATEGORY_BROWSABLE)), anyInt()))
+                .thenReturn(resolveInfos);
+
+        assertThat(mController.hasAppCapability()).isTrue();
+    }
+
+    @Test
+    public void hasAppCapability_noBrowserCapability_shouldReturnFalse() {
+        assertThat(mController.hasAppCapability()).isFalse();
+    }
+
+    @Test
+    public void isDefaultApp_isDefaultBrowser_shouldReturnTrue() {
+        when(mPackageManager.getDefaultBrowserPackageNameAsUser(anyInt())).thenReturn("Package1");
+
+        assertThat(mController.isDefaultApp()).isTrue();
+    }
+
+    @Test
+    public void isDefaultApp_notDefaultBrowser_shouldReturnFalse() {
+        assertThat(mController.isDefaultApp()).isFalse();
+    }
+
+}
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/DefaultEmergencyShortcutPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultEmergencyShortcutPreferenceControllerTest.java
new file mode 100644
index 0000000..414ef70
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultEmergencyShortcutPreferenceControllerTest.java
@@ -0,0 +1,99 @@
+/*
+ * 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.appinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.argThat;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.provider.Settings;
+import android.telephony.TelephonyManager;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class DefaultEmergencyShortcutPreferenceControllerTest {
+
+    @Mock
+    private PackageManager mPackageManager;
+
+    private Context mContext;
+    private DefaultEmergencyShortcutPreferenceController mController;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mContext = spy(RuntimeEnvironment.application);
+        when(mContext.getPackageManager()).thenReturn(mPackageManager);
+        mController = new DefaultEmergencyShortcutPreferenceController(mContext, "Package1");
+    }
+
+    @Test
+    public void getPreferenceKey_shouldReturnDefaultEmergency() {
+        assertThat(mController.getPreferenceKey()).isEqualTo("default_emergency_app");
+    }
+
+    @Test
+    public void hasAppCapability_hasEmergencyCapability_shouldReturnTrue() {
+        List<ResolveInfo> resolveInfos = new ArrayList<>();
+        resolveInfos.add(new ResolveInfo());
+        when(mPackageManager.queryIntentActivities(argThat(intent-> intent != null
+                && intent.getAction().equals(TelephonyManager.ACTION_EMERGENCY_ASSISTANCE)),
+                anyInt())).thenReturn(resolveInfos);
+
+        assertThat(mController.hasAppCapability()).isTrue();
+    }
+
+    @Test
+    public void hasAppCapability_noEmergencyCapability_shouldReturnFalse() {
+        assertThat(mController.hasAppCapability()).isFalse();
+    }
+
+    @Test
+    public void isDefaultApp_isDefaultEmergency_shouldReturnTrue() {
+        Settings.Secure.putString(mContext.getContentResolver(),
+                Settings.Secure.EMERGENCY_ASSISTANCE_APPLICATION, "Package1");
+
+        assertThat(mController.isDefaultApp()).isTrue();
+    }
+
+    @Test
+    public void isDefaultApp_notDefaultEmergency_shouldReturnFalse() {
+        assertThat(mController.isDefaultApp()).isFalse();
+    }
+
+}
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/DefaultHomeShortcutPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultHomeShortcutPreferenceControllerTest.java
new file mode 100644
index 0000000..a0a57f6
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultHomeShortcutPreferenceControllerTest.java
@@ -0,0 +1,99 @@
+/*
+ * 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.appinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.pm.PackageManager;
+
+import com.android.settings.TestConfig;
+import com.android.settings.applications.defaultapps.DefaultHomePreferenceController;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class DefaultHomeShortcutPreferenceControllerTest {
+
+    @Mock
+    private PackageManager mPackageManager;
+
+    private Context mContext;
+    private DefaultHomeShortcutPreferenceController mController;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mContext = spy(RuntimeEnvironment.application);
+        when(mContext.getPackageManager()).thenReturn(mPackageManager);
+        mController = new DefaultHomeShortcutPreferenceController(mContext, "Package1");
+    }
+
+    @Test
+    public void getPreferenceKey_shouldReturnDefaultHome() {
+        assertThat(mController.getPreferenceKey()).isEqualTo("default_home");
+    }
+
+    @Test
+    @Config(shadows = ShadowDefaultHomePreferenceController.class)
+    public void hasAppCapability_hasHomeCapability_shouldReturnTrue() {
+        assertThat(mController.hasAppCapability()).isTrue();
+    }
+
+    @Test
+    public void hasAppCapability_noHomeCapability_shouldReturnFalse() {
+        assertThat(mController.hasAppCapability()).isFalse();
+    }
+
+    @Test
+    public void isDefaultApp_isDefaultHome_shouldReturnTrue() {
+        when(mPackageManager.getHomeActivities(anyList()))
+                .thenReturn(new ComponentName("Package1", "cls1"));
+        assertThat(mController.isDefaultApp()).isTrue();
+    }
+
+    @Test
+    public void isDefaultApp_notDefaultHome_shouldReturnFalse() {
+        when(mPackageManager.getHomeActivities(anyList()))
+                .thenReturn(new ComponentName("pkg2", "cls1"));
+        assertThat(mController.isDefaultApp()).isFalse();
+    }
+
+    @Implements(DefaultHomePreferenceController.class)
+    public static class ShadowDefaultHomePreferenceController {
+        @Implementation
+        public static boolean hasHomePreference(String pkg, Context context) {
+            return true;
+        }
+    }
+
+}
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/DefaultPhoneShortcutPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultPhoneShortcutPreferenceControllerTest.java
new file mode 100644
index 0000000..d04b114
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultPhoneShortcutPreferenceControllerTest.java
@@ -0,0 +1,99 @@
+/*
+ * 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.appinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+
+import com.android.settings.TestConfig;
+import com.android.settings.applications.defaultapps.DefaultPhonePreferenceController;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class DefaultPhoneShortcutPreferenceControllerTest {
+
+    @Mock
+    private PackageManager mPackageManager;
+
+    private Context mContext;
+    private DefaultPhoneShortcutPreferenceController mController;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mContext = spy(RuntimeEnvironment.application);
+        when(mContext.getPackageManager()).thenReturn(mPackageManager);
+        mController = new DefaultPhoneShortcutPreferenceController(mContext, "Package1");
+    }
+
+    @Test
+    public void getPreferenceKey_shouldReturnDefaultPhone() {
+        assertThat(mController.getPreferenceKey()).isEqualTo("default_phone_app");
+    }
+
+    @Test
+    @Config(shadows = ShadowDefaultPhonePreferenceController.class)
+    public void hasAppCapability_hasPhoneCapability_shouldReturnTrue() {
+        assertThat(mController.hasAppCapability()).isTrue();
+    }
+
+    @Test
+    public void hasAppCapability_noPhoneCapability_shouldReturnFalse() {
+        assertThat(mController.hasAppCapability()).isFalse();
+    }
+
+    @Test
+    @Config(shadows = ShadowDefaultPhonePreferenceController.class)
+    public void isDefaultApp_isDefaultPhone_shouldReturnTrue() {
+        assertThat(mController.isDefaultApp()).isTrue();
+    }
+
+    @Test
+    public void isDefaultApp_notDefaultPhone_shouldReturnFalse() {
+        assertThat(mController.isDefaultApp()).isFalse();
+    }
+
+    @Implements(DefaultPhonePreferenceController.class)
+    public static class ShadowDefaultPhonePreferenceController {
+        @Implementation
+        public static boolean hasPhonePreference(String pkg, Context context) {
+            return true;
+        }
+
+        @Implementation
+        public static boolean isPhoneDefault(String pkg, Context context) {
+            return true;
+        }
+    }
+
+}
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/DefaultSmsShortcutPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultSmsShortcutPreferenceControllerTest.java
new file mode 100644
index 0000000..4abaa6a
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultSmsShortcutPreferenceControllerTest.java
@@ -0,0 +1,99 @@
+/*
+ * 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.appinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+
+import com.android.settings.TestConfig;
+import com.android.settings.applications.defaultapps.DefaultSmsPreferenceController;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class DefaultSmsShortcutPreferenceControllerTest {
+
+    @Mock
+    private PackageManager mPackageManager;
+
+    private Context mContext;
+    private DefaultSmsShortcutPreferenceController mController;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mContext = spy(RuntimeEnvironment.application);
+        when(mContext.getPackageManager()).thenReturn(mPackageManager);
+        mController = new DefaultSmsShortcutPreferenceController(mContext, "Package1");
+    }
+
+    @Test
+    public void getPreferenceKey_shouldReturnDefaultSms() {
+        assertThat(mController.getPreferenceKey()).isEqualTo("default_sms_app");
+    }
+
+    @Test
+    @Config(shadows = ShadowDefaultSmsPreferenceController.class)
+    public void hasAppCapability_hasSmsCapability_shouldReturnTrue() {
+        assertThat(mController.hasAppCapability()).isTrue();
+    }
+
+    @Test
+    public void hasAppCapability_noSmsCapability_shouldReturnFalse() {
+        assertThat(mController.hasAppCapability()).isFalse();
+    }
+
+    @Test
+    @Config(shadows = ShadowDefaultSmsPreferenceController.class)
+    public void isDefaultApp_isDefaultSms_shouldReturnTrue() {
+        assertThat(mController.isDefaultApp()).isTrue();
+    }
+
+    @Test
+    public void isDefaultApp_notDefaultSms_shouldReturnFalse() {
+        assertThat(mController.isDefaultApp()).isFalse();
+    }
+
+    @Implements(DefaultSmsPreferenceController.class)
+    public static class ShadowDefaultSmsPreferenceController {
+        @Implementation
+        public static boolean hasSmsPreference(String pkg, Context context) {
+            return true;
+        }
+
+        @Implementation
+        public static boolean isSmsDefault(String pkg, Context context) {
+            return true;
+        }
+    }
+
+}
diff --git a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAppPickerFragmentTest.java b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAppPickerFragmentTest.java
index 804df51..1afc12a 100644
--- a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAppPickerFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAppPickerFragmentTest.java
@@ -67,7 +67,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        mFeatureFactory = FakeFeatureFactory.setupForTest(mActivity);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mFragment = spy(new TestFragment());
 
         when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
diff --git a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutofillPickerTest.java b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutofillPickerTest.java
index 61d7f34..448da81 100644
--- a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutofillPickerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutofillPickerTest.java
@@ -17,7 +17,6 @@
 package com.android.settings.applications.defaultapps;
 
 import static com.google.common.truth.Truth.assertThat;
-
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
@@ -59,7 +58,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mActivity);
+        FakeFeatureFactory.setupForTest();
         when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
         mPicker = spy(new DefaultAutofillPicker());
         mPicker.onAttach((Context) mActivity);
diff --git a/tests/robotests/src/com/android/settings/applications/instantapps/InstantAppButtonsControllerTest.java b/tests/robotests/src/com/android/settings/applications/instantapps/InstantAppButtonsControllerTest.java
index c7ca133..5c0badc 100644
--- a/tests/robotests/src/com/android/settings/applications/instantapps/InstantAppButtonsControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/instantapps/InstantAppButtonsControllerTest.java
@@ -18,13 +18,10 @@
 
 import static com.android.settings.applications.instantapps.InstantAppButtonsController
         .ShowDialogDelegate;
-
 import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Matchers.eq;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.isNull;
+import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
@@ -44,10 +41,10 @@
 import android.widget.Button;
 
 import com.android.settings.R;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settingslib.wrapper.PackageManagerWrapper;
 
 import org.junit.Before;
@@ -124,7 +121,7 @@
         controller.setPackageName(TEST_AIA_PACKAGE_NAME);
         ReflectionHelpers.setField(
                 controller, "mPackageManagerWrapper", mockPackageManagerWrapper);
-        FakeFeatureFactory.setupForTest(mockContext);
+        FakeFeatureFactory.setupForTest();
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java
index 2dc411c..b45a743 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java
@@ -17,20 +17,18 @@
 package com.android.settings.bluetooth;
 
 import static com.google.common.truth.Truth.assertThat;
-
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.inOrder;
-import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import android.graphics.drawable.Drawable;
 
 import com.android.settings.R;
-import com.android.settings.applications.LayoutPreference;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
+import com.android.settings.applications.LayoutPreference;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.testutils.shadow.SettingsShadowBluetoothDevice;
 import com.android.settings.testutils.shadow.SettingsShadowResources;
 import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
@@ -46,7 +44,7 @@
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
-        shadows={SettingsShadowBluetoothDevice.class, ShadowEntityHeaderController.class,
+        shadows = {SettingsShadowBluetoothDevice.class, ShadowEntityHeaderController.class,
                 SettingsShadowResources.class})
 public class BluetoothDetailsHeaderControllerTest extends BluetoothDetailsControllerTestBase {
     private BluetoothDetailsHeaderController mController;
@@ -58,7 +56,7 @@
     @Override
     public void setUp() {
         super.setUp();
-        FakeFeatureFactory.setupForTest(spy(mContext));
+        FakeFeatureFactory.setupForTest();
         ShadowEntityHeaderController.setUseMock(mHeaderController);
         mController = new BluetoothDetailsHeaderController(mContext, mFragment, mCachedDevice,
                 mLifecycle);
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragmentTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragmentTest.java
index cd07a90..5d18c85 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragmentTest.java
@@ -68,7 +68,7 @@
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         mContext = spy(RuntimeEnvironment.application);
-        FakeFeatureFactory.setupForTest(mContext);
+        FakeFeatureFactory.setupForTest();
 
         String deviceAddress = "55:66:77:88:99:AA";
         mFragment = spy(BluetoothDeviceDetailsFragment.newInstance(deviceAddress));
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePreferenceTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePreferenceTest.java
index 3dd97bb..dcf0296 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePreferenceTest.java
@@ -15,6 +15,14 @@
  */
 package com.android.settings.bluetooth;
 
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
 import android.bluetooth.BluetoothClass;
 import android.bluetooth.BluetoothDevice;
 import android.content.Context;
@@ -22,10 +30,10 @@
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settings.R;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.testutils.shadow.SettingsShadowResources;
 import com.android.settingslib.bluetooth.CachedBluetoothDevice;
 
@@ -38,16 +46,6 @@
 import org.robolectric.annotation.Config;
 import org.robolectric.util.ReflectionHelpers;
 
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
         shadows = SettingsShadowResources.class)
@@ -68,8 +66,7 @@
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         mContext = spy(RuntimeEnvironment.application.getApplicationContext());
-        FakeFeatureFactory.setupForTest(mContext);
-        mFakeFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
         mMetricsFeatureProvider = mFakeFeatureFactory.getMetricsFeatureProvider();
         mPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice,
                 SHOW_DEVICES_WITHOUT_NAMES);
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceControllerTest.java
index 534cace..27cf3ca 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceControllerTest.java
@@ -16,15 +16,21 @@
 
 package com.android.settings.bluetooth;
 
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
 import android.app.Fragment;
 import android.content.Context;
 import android.support.v7.preference.Preference.OnPreferenceChangeListener;
 import android.support.v7.preference.PreferenceScreen;
 
 import com.android.settings.SettingsActivity;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.widget.MasterSwitchPreference;
 import com.android.settingslib.bluetooth.BluetoothCallback;
 import com.android.settingslib.bluetooth.LocalBluetoothManager;
@@ -38,14 +44,6 @@
 import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
 
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class BluetoothMasterSwitchPreferenceControllerTest {
@@ -71,8 +69,7 @@
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         mContext = spy(RuntimeEnvironment.application.getApplicationContext());
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
 
         mController = new BluetoothMasterSwitchPreferenceController(
                 mContext, mBluetoothManager, mRestrictionUtils, mFragment, mActivity);
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingDetailTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingDetailTest.java
index 2b30ae4..f434186 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingDetailTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingDetailTest.java
@@ -31,7 +31,6 @@
 import android.bluetooth.BluetoothAdapter;
 import android.content.Context;
 import android.content.res.Resources;
-import android.os.UserManager;
 import android.support.v7.preference.PreferenceGroup;
 
 import com.android.settings.R;
@@ -56,8 +55,6 @@
 public class BluetoothPairingDetailTest {
 
     @Mock
-    private UserManager mUserManager;
-    @Mock
     private Resources mResource;
     @Mock
     private LocalBluetoothAdapter mLocalAdapter;
@@ -134,6 +131,25 @@
     }
 
     @Test
+    public void testUpdateBluetooth_bluetoothOff_turnOnBluetooth() {
+        doReturn(false).when(mLocalAdapter).isEnabled();
+
+        mFragment.updateBluetooth();
+
+        verify(mLocalAdapter).enable();
+    }
+
+    @Test
+    public void testUpdateBluetooth_bluetoothOn_updateState() {
+        doReturn(true).when(mLocalAdapter).isEnabled();
+        doNothing().when(mFragment).updateContent(anyInt());
+
+        mFragment.updateBluetooth();
+
+        verify(mFragment).updateContent(anyInt());
+    }
+
+    @Test
     public void testOnScanningStateChanged_restartScanAfterInitialScanning() {
         mFragment.mAvailableDevicesCategory = mAvailableDevicesCategory;
         mFragment.mFooterPreference = mFooterPreference;
@@ -181,6 +197,4 @@
         verify(mAvailableDevicesCategory, times(1)).removeAll();
     }
 
-
-
 }
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingDialogTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingDialogTest.java
index 25a24d4..e598ec1 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingDialogTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingDialogTest.java
@@ -290,7 +290,6 @@
         CheckBox sharingCheckbox = (CheckBox) frag.getmDialog()
                 .findViewById(R.id.phonebook_sharing_message_confirm_pin);
         assertThat(sharingCheckbox.getVisibility()).isEqualTo(View.VISIBLE);
-        assertThat(sharingCheckbox.getText().toString().contains(FAKE_DEVICE_NAME)).isTrue();
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothSettingsTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothSettingsTest.java
index b177729..dc318c2 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothSettingsTest.java
@@ -52,11 +52,10 @@
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class BluetoothSettingsTest {
+
     private static final String FOOTAGE_MAC_STRING = "Bluetooth mac: xxxx";
 
     @Mock
-    private UserManager mUserManager;
-    @Mock
     private Resources mResource;
     @Mock
     private LocalBluetoothAdapter mLocalAdapter;
@@ -78,8 +77,7 @@
         MockitoAnnotations.initMocks(this);
 
         mContext = spy(RuntimeEnvironment.application);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
 
         mFragment = spy(new BluetoothSettings());
 
diff --git a/tests/robotests/src/com/android/settings/bluetooth/ForgetDeviceDialogFragmentTest.java b/tests/robotests/src/com/android/settings/bluetooth/ForgetDeviceDialogFragmentTest.java
index 71e9933..6e1e1bc 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/ForgetDeviceDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/ForgetDeviceDialogFragmentTest.java
@@ -17,7 +17,6 @@
 package com.android.settings.bluetooth;
 
 import static com.google.common.truth.Truth.assertThat;
-
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.never;
@@ -27,7 +26,6 @@
 
 import android.app.Activity;
 import android.app.AlertDialog;
-import android.content.Context;
 
 import com.android.settings.TestConfig;
 import com.android.settings.testutils.FakeFeatureFactory;
@@ -41,7 +39,6 @@
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.Robolectric;
-import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
 import org.robolectric.shadows.ShadowDialog;
 
@@ -53,15 +50,13 @@
     private CachedBluetoothDevice mCachedDevice;
 
     private ForgetDeviceDialogFragment mFragment;
-    private Context mContext;
     private Activity mActivity;
     private AlertDialog mDialog;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        mContext = spy(RuntimeEnvironment.application);
-        FakeFeatureFactory.setupForTest(mContext);
+        FakeFeatureFactory.setupForTest();
         String deviceAddress = "55:66:77:88:99:AA";
         when(mCachedDevice.getAddress()).thenReturn(deviceAddress);
         mFragment = spy(ForgetDeviceDialogFragment.newInstance(deviceAddress));
diff --git a/tests/robotests/src/com/android/settings/bluetooth/RemoteDeviceNameDialogFragmentTest.java b/tests/robotests/src/com/android/settings/bluetooth/RemoteDeviceNameDialogFragmentTest.java
index 65fe46c..254de63 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/RemoteDeviceNameDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/RemoteDeviceNameDialogFragmentTest.java
@@ -17,7 +17,6 @@
 package com.android.settings.bluetooth;
 
 import static com.google.common.truth.Truth.assertThat;
-
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Mockito.doReturn;
@@ -27,7 +26,6 @@
 import static org.mockito.Mockito.when;
 
 import android.app.AlertDialog;
-import android.content.Context;
 import android.content.DialogInterface;
 import android.widget.Button;
 import android.widget.EditText;
@@ -44,7 +42,6 @@
 import org.mockito.Answers;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
-import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
 import org.robolectric.shadows.ShadowDialog;
 import org.robolectric.util.FragmentTestUtil;
@@ -57,13 +54,11 @@
     private CachedBluetoothDevice mCachedDevice;
 
     private RemoteDeviceNameDialogFragment mFragment;
-    private Context mContext;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        mContext = spy(RuntimeEnvironment.application);
-        FakeFeatureFactory.setupForTest(mContext);
+        FakeFeatureFactory.setupForTest();
 
         String deviceAddress = "55:66:77:88:99:AA";
         when(mCachedDevice.getAddress()).thenReturn(deviceAddress);
diff --git a/tests/robotests/src/com/android/settings/bluetooth/UtilsTest.java b/tests/robotests/src/com/android/settings/bluetooth/UtilsTest.java
index 43583ed..2008c81 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/UtilsTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/UtilsTest.java
@@ -15,13 +15,20 @@
  */
 package com.android.settings.bluetooth;
 
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
 import android.content.Context;
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.testutils.shadow.SettingsShadowResources;
 import com.android.settingslib.bluetooth.LocalBluetoothManager;
 
@@ -33,13 +40,6 @@
 import org.mockito.MockitoAnnotations;
 import org.robolectric.annotation.Config;
 
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
         shadows = SettingsShadowResources.class)
@@ -47,8 +47,6 @@
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private Context mContext;
-    @Mock
-    private LocalBluetoothManager mLocalBluetoothManager;
 
     private FakeFeatureFactory mFakeFeatureFactory;
     private MetricsFeatureProvider mMetricsFeatureProvider;
@@ -56,8 +54,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFakeFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
         mMetricsFeatureProvider = mFakeFeatureFactory.getMetricsFeatureProvider();
     }
 
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceDashboardFragmentTest.java
new file mode 100644
index 0000000..31d0ec5
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceDashboardFragmentTest.java
@@ -0,0 +1,162 @@
+/*
+ * 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.connecteddevice;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.provider.SearchIndexableResource;
+
+import com.android.settings.TestConfig;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.nfc.NfcPreferenceController;
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.XmlTestUtils;
+import com.android.settingslib.drawer.CategoryKey;
+
+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.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import java.util.List;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class AdvancedConnectedDeviceDashboardFragmentTest {
+
+    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+    private Context mContext;
+
+    @Mock
+    private PackageManager mManager;
+
+    private FakeFeatureFactory mFeatureFactory;
+    private SmsMirroringFeatureProvider mFeatureProvider;
+    private AdvancedConnectedDeviceDashboardFragment mFragment;
+    private TestSmsMirroringPreferenceController mSmsMirroringPreferenceController;
+
+    private static final class TestSmsMirroringPreferenceController
+            extends SmsMirroringPreferenceController implements PreferenceControllerMixin {
+
+        private boolean mIsAvailable;
+
+        public TestSmsMirroringPreferenceController(Context context) {
+            super(context);
+        }
+
+        @Override
+        public boolean isAvailable() {
+            return mIsAvailable;
+        }
+    }
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
+        mFeatureProvider = mFeatureFactory.smsMirroringFeatureProvider;
+
+        mFragment = new AdvancedConnectedDeviceDashboardFragment();
+        when(mContext.getPackageManager()).thenReturn(mManager);
+
+        mSmsMirroringPreferenceController = new TestSmsMirroringPreferenceController(mContext);
+        when(mFeatureProvider.getController(mContext)).thenReturn(
+                mSmsMirroringPreferenceController);
+    }
+
+    @Test
+    public void testCategory_isConnectedDevice() {
+        assertThat(mFragment.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_DEVICE);
+    }
+
+    @Test
+    public void testSearchIndexProvider_shouldIndexResource() {
+        final List<SearchIndexableResource> indexRes =
+                mFragment.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(mContext,
+                        true /* enabled */);
+
+        assertThat(indexRes).isNotNull();
+        assertThat(indexRes.get(0).xmlResId).isEqualTo(mFragment.getPreferenceScreenResId());
+    }
+
+    @Test
+    public void testSearchIndexProvider_NoNfc_KeyAdded() {
+        when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(false);
+        final List<String> keys = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
+                mContext);
+
+        assertThat(keys).isNotNull();
+        assertThat(keys).contains(NfcPreferenceController.KEY_TOGGLE_NFC);
+        assertThat(keys).contains(NfcPreferenceController.KEY_ANDROID_BEAM_SETTINGS);
+    }
+
+    @Test
+    public void testSearchIndexProvider_NFC_KeyNotAdded() {
+        when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(true);
+        final List<String> keys = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
+                mContext);
+
+        assertThat(keys).isNotNull();
+        assertThat(keys).doesNotContain(NfcPreferenceController.KEY_TOGGLE_NFC);
+        assertThat(keys).doesNotContain(NfcPreferenceController.KEY_ANDROID_BEAM_SETTINGS);
+    }
+
+    @Test
+    public void testSearchIndexProvider_NoSmsMirroring_KeyAdded() {
+        when(mFeatureProvider.shouldShowSmsMirroring(mContext)).thenReturn(false);
+        mSmsMirroringPreferenceController.mIsAvailable = false;
+
+        final List<String> keys = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
+                mContext);
+
+        assertThat(keys).isNotNull();
+        assertThat(keys).contains(mSmsMirroringPreferenceController.getPreferenceKey());
+    }
+
+    @Test
+    public void testSearchIndexProvider_SmsMirroring_KeyNotAdded() {
+        when(mFeatureProvider.shouldShowSmsMirroring(mContext)).thenReturn(true);
+        mSmsMirroringPreferenceController.mIsAvailable = true;
+
+        final List<String> keys = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
+                mContext);
+
+        assertThat(keys).isNotNull();
+        assertThat(keys).doesNotContain(mSmsMirroringPreferenceController.getPreferenceKey());
+    }
+
+    @Test
+    public void testNonIndexableKeys_existInXmlLayout() {
+        final Context context = RuntimeEnvironment.application;
+        when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(false);
+        final List<String> niks = ConnectedDeviceDashboardFragment.SEARCH_INDEX_DATA_PROVIDER
+                .getNonIndexableKeys(mContext);
+        final int xmlId = (new ConnectedDeviceDashboardFragment()).getPreferenceScreenResId();
+
+        final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId);
+
+        assertThat(keys).containsAllIn(niks);
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment2Test.java b/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment2Test.java
index 4bcb299..ada8944 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment2Test.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment2Test.java
@@ -15,6 +15,13 @@
  */
 package com.android.settings.connecteddevice;
 
+import static android.content.Context.NFC_SERVICE;
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
+
 import android.content.Context;
 import android.content.pm.PackageManager;
 import android.nfc.NfcAdapter;
@@ -22,12 +29,12 @@
 import android.provider.SearchIndexableResource;
 
 import com.android.settings.R;
-import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settings.nfc.NfcPreferenceController;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
+import com.android.settings.core.PreferenceControllerMixin;
 import com.android.settings.dashboard.SummaryLoader;
+import com.android.settings.nfc.NfcPreferenceController;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.testutils.XmlTestUtils;
 import com.android.settingslib.drawer.CategoryKey;
 
@@ -42,13 +49,6 @@
 
 import java.util.List;
 
-import static android.content.Context.NFC_SERVICE;
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
-
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class ConnectedDeviceDashboardFragment2Test {
@@ -82,8 +82,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mFeatureProvider = mFeatureFactory.smsMirroringFeatureProvider;
 
         mFragment = new ConnectedDeviceDashboardFragmentOld();
diff --git a/tests/robotests/src/com/android/settings/core/instrumentation/SharedPreferenceLoggerTest.java b/tests/robotests/src/com/android/settings/core/instrumentation/SharedPreferenceLoggerTest.java
index 3ad70ab..49556f2 100644
--- a/tests/robotests/src/com/android/settings/core/instrumentation/SharedPreferenceLoggerTest.java
+++ b/tests/robotests/src/com/android/settings/core/instrumentation/SharedPreferenceLoggerTest.java
@@ -63,8 +63,7 @@
     @Before
     public void init() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFactory = FakeFeatureFactory.setupForTest();
         mMetricsFeature = mFactory.metricsFeatureProvider;
 
         mSharedPrefLogger = new SharedPreferencesLogger(mContext, TEST_TAG);
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
index fdb1470..1c72863 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
@@ -92,8 +92,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFactory = FakeFeatureFactory.setupForTest();
         when(mFactory.dashboardFeatureProvider.shouldTintIcon()).thenReturn(true);
         when(mFactory.suggestionsFeatureProvider
                 .getSuggestionIdentifier(any(Context.class), any(Tile.class)))
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
index 3d36e6f..45038aa 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
@@ -98,8 +98,7 @@
         doReturn(mPackageManager).when(mContext).getPackageManager();
         when(mPackageManager.resolveActivity(any(Intent.class), anyInt())).thenReturn(
                 new ResolveInfo());
-        FakeFeatureFactory.setupForTest(mActivity);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mActivity);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mImpl = new DashboardFeatureProviderImpl(mContext);
     }
 
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java
index 14f3078..372d3c5 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java
@@ -16,9 +16,7 @@
 package com.android.settings.dashboard;
 
 import static com.google.common.truth.Truth.assertThat;
-
 import static org.mockito.ArgumentMatchers.nullable;
-import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
@@ -33,12 +31,11 @@
 import android.support.v7.preference.PreferenceManager;
 import android.support.v7.preference.PreferenceScreen;
 
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.core.PreferenceControllerMixin;
 import com.android.settings.core.instrumentation.VisibilityLoggerMixin;
-import com.android.settings.overlay.FeatureFactory;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settingslib.core.AbstractPreferenceController;
 import com.android.settingslib.drawer.DashboardCategory;
 import com.android.settingslib.drawer.Tile;
@@ -71,8 +68,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFakeFeatureFactory = (FakeFeatureFactory) FeatureFactory.getFactory(mContext);
+        mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
         mDashboardCategory = new DashboardCategory();
         mDashboardCategory.addTile(new Tile());
         mTestFragment = new TestFragment(ShadowApplication.getInstance().getApplicationContext());
diff --git a/tests/robotests/src/com/android/settings/dashboard/SummaryLoaderTest.java b/tests/robotests/src/com/android/settings/dashboard/SummaryLoaderTest.java
index 92ed7b4..f6a32dc 100644
--- a/tests/robotests/src/com/android/settings/dashboard/SummaryLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/SummaryLoaderTest.java
@@ -21,7 +21,6 @@
 import static org.mockito.Mockito.when;
 
 import android.app.Activity;
-import android.content.Context;
 import android.content.Intent;
 
 import com.android.settings.TestConfig;
@@ -34,8 +33,6 @@
 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.Robolectric;
 import org.robolectric.annotation.Config;
@@ -47,8 +44,6 @@
     private static final String SUMMARY_1 = "summary1";
     private static final String SUMMARY_2 = "summary2";
 
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private Context mContext;
     private SummaryLoader mSummaryLoader;
     private boolean mCallbackInvoked;
     private Tile mTile;
@@ -57,7 +52,7 @@
     @Before
     public void SetUp() {
         MockitoAnnotations.initMocks(this);
-        mFeatureFactory = FakeFeatureFactory.setupForTest(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
 
         mTile = new Tile();
         mTile.summary = SUMMARY_1;
diff --git a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionAdapterTest.java b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionAdapterTest.java
index b052527..b77f8a4 100644
--- a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionAdapterTest.java
@@ -82,7 +82,7 @@
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         mContext = RuntimeEnvironment.application;
-        mFeatureFactory = FakeFeatureFactory.setupForTest(mActivity);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
 
         final Tile suggestion1 = new Tile();
         final Tile suggestion2 = new Tile();
diff --git a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionControllerMixinTest.java b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionControllerMixinTest.java
index ad97e18..790f166 100644
--- a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionControllerMixinTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionControllerMixinTest.java
@@ -18,9 +18,7 @@
 
 import static android.arch.lifecycle.Lifecycle.Event.ON_START;
 import static android.arch.lifecycle.Lifecycle.Event.ON_STOP;
-
 import static com.google.common.truth.Truth.assertThat;
-
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -37,9 +35,9 @@
 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.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
@@ -49,19 +47,18 @@
         })
 public class SuggestionControllerMixinTest {
 
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private Context mContext;
     @Mock
     private SuggestionControllerMixin.SuggestionControllerHost mHost;
+    private Context mContext;
     private Lifecycle mLifecycle;
     private SuggestionControllerMixin mMixin;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
+        mContext = RuntimeEnvironment.application;
+        FakeFeatureFactory.setupForTest();
         mLifecycle = new Lifecycle(() -> mLifecycle);
-        when(mContext.getApplicationContext()).thenReturn(mContext);
     }
 
     @After
@@ -111,4 +108,17 @@
 
         verify(mHost).getLoaderManager();
     }
+
+    @Test
+    public void doneLoadingg_shouldSetSuggestionLoaded() {
+        mMixin = new SuggestionControllerMixin(mContext, mHost, mLifecycle);
+
+        mMixin.onLoadFinished(mock(SuggestionLoader.class), null);
+
+        assertThat(mMixin.isSuggestionLoaded()).isTrue();
+
+        mMixin.onLoaderReset(mock(SuggestionLoader.class));
+
+        assertThat(mMixin.isSuggestionLoaded()).isFalse();
+    }
 }
diff --git a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionDismissControllerTest.java b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionDismissControllerTest.java
index c94f200..7a4ff15 100644
--- a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionDismissControllerTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionDismissControllerTest.java
@@ -17,7 +17,6 @@
 package com.android.settings.dashboard.suggestions;
 
 import static com.google.common.truth.Truth.assertThat;
-
 import static org.mockito.ArgumentMatchers.nullable;
 import static org.mockito.Matchers.anyInt;
 import static org.mockito.Matchers.eq;
@@ -31,9 +30,9 @@
 import android.support.v7.widget.helper.ItemTouchHelper;
 
 import com.android.settings.R;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settingslib.drawer.Tile;
 import com.android.settingslib.suggestions.SuggestionParser;
 
@@ -66,8 +65,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFactory = FakeFeatureFactory.setupForTest();
 
         when(mRecyclerView.getResources().getDimension(anyInt())).thenReturn(50F);
 
diff --git a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java
index b74453c..fa53e06 100644
--- a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java
@@ -98,8 +98,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFactory = FakeFeatureFactory.setupForTest();
         when(mContext.getPackageManager()).thenReturn(mPackageManager);
         // Explicit casting to object due to MockitoCast bug
         when((Object) mContext.getSystemService(FingerprintManager.class))
diff --git a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionStateProviderTest.java b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionStateProviderTest.java
index 6ddba03..2ce3769 100644
--- a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionStateProviderTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionStateProviderTest.java
@@ -31,8 +31,6 @@
 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.Robolectric;
 import org.robolectric.annotation.Config;
@@ -41,16 +39,13 @@
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SuggestionStateProviderTest {
 
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private Context mContext;
-
     private SuggestionStateProvider mProvider;
     private FakeFeatureFactory mFeatureFactory;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        mFeatureFactory = FakeFeatureFactory.setupForTest(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
 
         mProvider = Robolectric.setupContentProvider(SuggestionStateProvider.class);
     }
diff --git a/tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java b/tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java
index 75fec68..509e7cc 100644
--- a/tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java
@@ -28,7 +28,6 @@
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-import android.content.Context;
 import android.content.pm.PackageManager;
 import android.os.Bundle;
 import android.support.v14.preference.SwitchPreference;
@@ -62,8 +61,6 @@
 public class AppDataUsageTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private Context mContext;
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private EntityHeaderController mHeaderController;
     @Mock
     private PackageManagerWrapper mPackageManagerWrapper;
@@ -73,7 +70,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
+        FakeFeatureFactory.setupForTest();
     }
 
     @After
diff --git a/tests/robotests/src/com/android/settings/datausage/UnrestrictedDataAccessTest.java b/tests/robotests/src/com/android/settings/datausage/UnrestrictedDataAccessTest.java
index 081337f..5ff273e 100644
--- a/tests/robotests/src/com/android/settings/datausage/UnrestrictedDataAccessTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/UnrestrictedDataAccessTest.java
@@ -16,7 +16,6 @@
 package com.android.settings.datausage;
 
 import static com.google.common.truth.Truth.assertThat;
-
 import static org.mockito.ArgumentMatchers.nullable;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.verify;
@@ -26,15 +25,14 @@
 import android.os.Process;
 
 import com.android.internal.logging.nano.MetricsProto;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settingslib.applications.ApplicationsState;
 
 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.annotation.Config;
@@ -43,9 +41,6 @@
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class UnrestrictedDataAccessTest {
 
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private Context mContext;
-
     @Mock
     private ApplicationsState.AppEntry mAppEntry;
     private UnrestrictedDataAccess mFragment;
@@ -54,8 +49,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mFragment = new UnrestrictedDataAccess();
     }
 
diff --git a/tests/robotests/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarControllerTest.java b/tests/robotests/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarControllerTest.java
index 3b98063..c9c3e24 100644
--- a/tests/robotests/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarControllerTest.java
@@ -17,11 +17,8 @@
 package com.android.settings.deletionhelper;
 
 import static com.google.common.truth.Truth.assertThat;
-
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
@@ -33,11 +30,10 @@
 import android.support.v7.preference.Preference;
 
 import com.android.internal.logging.nano.MetricsProto;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
-import com.android.settings.overlay.FeatureFactory;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
 import com.android.settings.widget.SwitchBar;
 
@@ -70,10 +66,7 @@
         mContext = spy(RuntimeEnvironment.application);
         mSwitchBar = new SwitchBar(mContext);
 
-        Context fakeContextForFakeProvider = mock(Context.class, RETURNS_DEEP_STUBS);
-        FakeFeatureFactory.setupForTest(fakeContextForFakeProvider);
-        FeatureFactory featureFactory = FakeFeatureFactory.getFactory(fakeContextForFakeProvider);
-        mMetricsFeatureProvider = featureFactory.getMetricsFeatureProvider();
+        mMetricsFeatureProvider = FakeFeatureFactory.setupForTest().getMetricsFeatureProvider();
         mPreference = new Preference(mContext);
 
         mController =
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/BuildNumberPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/BuildNumberPreferenceControllerTest.java
index 8312673..66d397e 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/BuildNumberPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/BuildNumberPreferenceControllerTest.java
@@ -17,7 +17,6 @@
 package com.android.settings.deviceinfo;
 
 import static com.google.common.truth.Truth.assertThat;
-
 import static org.mockito.Answers.RETURNS_DEEP_STUBS;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.eq;
@@ -83,7 +82,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        mFactory = FakeFeatureFactory.setupForTest(mContext);
+        mFactory = FakeFeatureFactory.setupForTest();
         mLifecycle = new Lifecycle(() -> mLifecycle);
         when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
         mController = new BuildNumberPreferenceController(
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogControllerTest.java
index 921c41f..fd7089e 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogControllerTest.java
@@ -112,6 +112,17 @@
     }
 
     @Test
+    public void populateImeiInfo_cdmaSimDisabled_shouldRemoveImeiInfoAndSetMinToEmpty() {
+        ReflectionHelpers.setField(mController, "mSubscriptionInfo", null);
+        when(mTelephonyManager.getPhoneType()).thenReturn(TelephonyManager.PHONE_TYPE_CDMA);
+
+        mController.populateImeiInfo();
+
+        verify(mDialog).setText(ID_MIN_NUMBER_VALUE, "");
+        verify(mDialog).removeViewFromScreen(ID_GSM_SETTINGS);
+    }
+
+    @Test
     public void populateImeinfo_gsm_shouldSetImeiAndRemoveCdmaSettings() {
         when(mTelephonyManager.getPhoneType()).thenReturn(TelephonyManager.PHONE_TYPE_GSM);
 
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java
index 7d47fc2..23d42da 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java
@@ -17,6 +17,7 @@
 package com.android.settings.deviceinfo.storage;
 
 import static com.google.common.truth.Truth.assertThat;
+
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.mock;
@@ -34,6 +35,7 @@
 import android.support.v7.preference.PreferenceScreen;
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.internal.os.RoSystemProperties;
 import com.android.settings.TestConfig;
 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
 import com.android.settings.deletionhelper.ActivationWarningFragment;
@@ -52,13 +54,14 @@
 import org.mockito.MockitoAnnotations;
 import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
 
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(
-    manifest = TestConfig.MANIFEST_PATH,
-    sdk = TestConfig.SDK_VERSION,
-    shadows = {SettingsShadowSystemProperties.class}
+        manifest = TestConfig.MANIFEST_PATH,
+        sdk = TestConfig.SDK_VERSION_O,
+        shadows = {SettingsShadowSystemProperties.class}
 )
 public class AutomaticStorageManagementSwitchPreferenceControllerTest {
 
@@ -79,13 +82,14 @@
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         mContext = RuntimeEnvironment.application.getApplicationContext();
-        FeatureFactory factory = FeatureFactory.getFactory(mContext);
+        final FeatureFactory factory = FeatureFactory.getFactory(mContext);
         mMetricsFeature = factory.getMetricsFeatureProvider();
 
         mController = new AutomaticStorageManagementSwitchPreferenceController(
                 mContext, mMetricsFeature, mFragmentManager);
         when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
     }
+
     @After
     public void tearDown() {
         SettingsShadowSystemProperties.clear();
@@ -98,15 +102,15 @@
 
     @Test
     public void isAvailable_shouldAlwaysReturnFalse_forLowRamDevice() {
-        SettingsShadowSystemProperties.set("ro.config.low_ram", "true");
+        ReflectionHelpers.setStaticField(RoSystemProperties.class, "CONFIG_LOW_RAM", true);
         assertThat(mController.isAvailable()).isFalse();
-        SettingsShadowSystemProperties.clear();
+        ReflectionHelpers.setStaticField(RoSystemProperties.class, "CONFIG_LOW_RAM", false);
     }
 
     @Test
     public void onResume_shouldReflectEnabledStatus() {
         mController.displayPreference(mScreen);
-        ContentResolver resolver = mContext.getContentResolver();
+        final ContentResolver resolver = mContext.getContentResolver();
         Settings.Secure.putInt(resolver, Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 1);
 
         mController.onResume();
@@ -127,10 +131,8 @@
     public void togglingShouldCauseMetricsEvent() {
         // FakeFeatureFactory uses mock contexts, so this test scaffolds itself rather than using
         // the instance variables.
-        FakeFeatureFactory.setupForTest(mMockContext);
-        FakeFeatureFactory factory =
-                (FakeFeatureFactory) FakeFeatureFactory.getFactory(mMockContext);
-        AutomaticStorageManagementSwitchPreferenceController controller =
+        final FakeFeatureFactory factory = FakeFeatureFactory.setupForTest();
+        final AutomaticStorageManagementSwitchPreferenceController controller =
                 new AutomaticStorageManagementSwitchPreferenceController(
                         mMockContext, factory.metricsFeatureProvider, mFragmentManager);
 
@@ -144,15 +146,15 @@
     public void togglingShouldUpdateSettingsSecure() {
         mController.onSwitchToggled(true);
 
-        ContentResolver resolver = mContext.getContentResolver();
+        final ContentResolver resolver = mContext.getContentResolver();
         assertThat(Settings.Secure.getInt(
                 resolver, Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 0)).isNotEqualTo(0);
     }
 
     @Test
     public void togglingOnShouldTriggerWarningFragment() {
-        FragmentTransaction transaction = mock(FragmentTransaction.class);
-        when (mFragmentManager.beginTransaction()).thenReturn(transaction);
+        final FragmentTransaction transaction = mock(FragmentTransaction.class);
+        when(mFragmentManager.beginTransaction()).thenReturn(transaction);
         SettingsShadowSystemProperties.set(
                 AutomaticStorageManagementSwitchPreferenceController
                         .STORAGE_MANAGER_ENABLED_BY_DEFAULT_PROPERTY, "false");
@@ -164,8 +166,8 @@
 
     @Test
     public void togglingOffShouldTriggerWarningFragment() {
-        FragmentTransaction transaction = mock(FragmentTransaction.class);
-        when (mFragmentManager.beginTransaction()).thenReturn(transaction);
+        final FragmentTransaction transaction = mock(FragmentTransaction.class);
+        when(mFragmentManager.beginTransaction()).thenReturn(transaction);
 
         mController.onSwitchToggled(false);
 
@@ -175,8 +177,8 @@
 
     @Test
     public void togglingOnShouldNotTriggerWarningFragmentIfEnabledByDefault() {
-        FragmentTransaction transaction = mock(FragmentTransaction.class);
-        when (mFragmentManager.beginTransaction()).thenReturn(transaction);
+        final FragmentTransaction transaction = mock(FragmentTransaction.class);
+        when(mFragmentManager.beginTransaction()).thenReturn(transaction);
         SettingsShadowSystemProperties.set(
                 AutomaticStorageManagementSwitchPreferenceController
                         .STORAGE_MANAGER_ENABLED_BY_DEFAULT_PROPERTY, "true");
@@ -188,7 +190,7 @@
 
     @Test
     public void togglingOnShouldTriggerWarningFragmentIfEnabledByDefaultAndDisabledByPolicy() {
-        FragmentTransaction transaction = mock(FragmentTransaction.class);
+        final FragmentTransaction transaction = mock(FragmentTransaction.class);
         when(mFragmentManager.beginTransaction()).thenReturn(transaction);
         SettingsShadowSystemProperties.set(
                 AutomaticStorageManagementSwitchPreferenceController
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/CachedStorageValuesHelperTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/CachedStorageValuesHelperTest.java
index 154a7a1..7b3556f 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/CachedStorageValuesHelperTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/CachedStorageValuesHelperTest.java
@@ -55,7 +55,7 @@
 import static com.google.common.truth.Truth.assertThat;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class CachedStorageValuesHelperTest {
     private Context mContext;
 
@@ -94,7 +94,7 @@
                 .putLong(TIMESTAMP_KEY, 10000L)
                 .apply();
 
-        PrivateStorageInfo info = mCachedValuesHelper.getCachedPrivateStorageInfo();
+        final PrivateStorageInfo info = mCachedValuesHelper.getCachedPrivateStorageInfo();
 
         assertThat(info.freeBytes).isEqualTo(1000L);
         assertThat(info.totalBytes).isEqualTo(6000L);
@@ -122,7 +122,7 @@
                 .putLong(TIMESTAMP_KEY, 10000L)
                 .apply();
 
-        SparseArray<StorageAsyncLoader.AppsStorageResult> result =
+        final SparseArray<StorageAsyncLoader.AppsStorageResult> result =
                 mCachedValuesHelper.getCachedAppsStorageResult();
 
         StorageAsyncLoader.AppsStorageResult primaryResult = result.get(0);
@@ -161,7 +161,7 @@
                 .putLong(TIMESTAMP_KEY, 10000L)
                 .apply();
 
-        PrivateStorageInfo info = mCachedValuesHelper.getCachedPrivateStorageInfo();
+        final PrivateStorageInfo info = mCachedValuesHelper.getCachedPrivateStorageInfo();
         assertThat(info).isNull();
     }
 
@@ -187,7 +187,7 @@
                 .putLong(TIMESTAMP_KEY, 10000L)
                 .apply();
 
-        SparseArray<StorageAsyncLoader.AppsStorageResult> result =
+        final SparseArray<StorageAsyncLoader.AppsStorageResult> result =
                 mCachedValuesHelper.getCachedAppsStorageResult();
         assertThat(result).isNull();
     }
@@ -214,7 +214,7 @@
                 .putLong(TIMESTAMP_KEY, 10000L)
                 .apply();
 
-        PrivateStorageInfo info = mCachedValuesHelper.getCachedPrivateStorageInfo();
+        final PrivateStorageInfo info = mCachedValuesHelper.getCachedPrivateStorageInfo();
         assertThat(info).isNull();
     }
 
@@ -240,20 +240,20 @@
                 .putLong(TIMESTAMP_KEY, 10000L)
                 .apply();
 
-        SparseArray<StorageAsyncLoader.AppsStorageResult> result =
+        final SparseArray<StorageAsyncLoader.AppsStorageResult> result =
                 mCachedValuesHelper.getCachedAppsStorageResult();
         assertThat(result).isNull();
     }
 
     @Test
     public void getCachedPrivateStorageInfo_nullIfEmpty() throws Exception {
-        PrivateStorageInfo info = mCachedValuesHelper.getCachedPrivateStorageInfo();
+        final PrivateStorageInfo info = mCachedValuesHelper.getCachedPrivateStorageInfo();
         assertThat(info).isNull();
     }
 
     @Test
     public void getCachedAppsStorageResult_nullIfEmpty() throws Exception {
-        SparseArray<StorageAsyncLoader.AppsStorageResult> result =
+        final SparseArray<StorageAsyncLoader.AppsStorageResult> result =
                 mCachedValuesHelper.getCachedAppsStorageResult();
         assertThat(result).isNull();
     }
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java
index f068397..804c6dc 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java
@@ -21,6 +21,7 @@
 import static com.google.common.truth.Truth.assertThat;
 
 import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
@@ -55,7 +56,7 @@
 import java.util.List;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SecondaryUserControllerTest {
     private static final String TEST_NAME = "Fred";
     private static final String TARGET_PREFERENCE_GROUP_KEY = "pref_secondary_users";
@@ -90,7 +91,7 @@
 
         final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
         verify(mGroup).addPreference(argumentCaptor.capture());
-        Preference preference = argumentCaptor.getValue();
+        final Preference preference = argumentCaptor.getValue();
         assertThat(preference.getTitle()).isEqualTo(TEST_NAME);
     }
 
@@ -103,17 +104,17 @@
 
         verify(mGroup).addPreference(argumentCaptor.capture());
 
-        Preference preference = argumentCaptor.getValue();
+        final Preference preference = argumentCaptor.getValue();
         assertThat(preference.getSummary()).isEqualTo("0.01 GB");
     }
 
     @Test
     public void noSecondaryUserAddedIfNoneExist() throws Exception {
-        ArrayList<UserInfo> userInfos = new ArrayList<>();
+        final ArrayList<UserInfo> userInfos = new ArrayList<>();
         userInfos.add(mPrimaryUser);
         when(mUserManager.getPrimaryUser()).thenReturn(mPrimaryUser);
         when(mUserManager.getUsers()).thenReturn(userInfos);
-        List<AbstractPreferenceController> controllers =
+        final List<AbstractPreferenceController> controllers =
                 SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager);
 
         assertThat(controllers).hasSize(1);
@@ -123,15 +124,15 @@
 
     @Test
     public void secondaryUserAddedIfHasDistinctId() throws Exception {
-        ArrayList<UserInfo> userInfos = new ArrayList<>();
-        UserInfo secondaryUser = new UserInfo();
+        final ArrayList<UserInfo> userInfos = new ArrayList<>();
+        final UserInfo secondaryUser = new UserInfo();
         secondaryUser.id = 10;
         secondaryUser.profileGroupId = 101010; // this just has to be something not 0
         userInfos.add(mPrimaryUser);
         userInfos.add(secondaryUser);
         when(mUserManager.getPrimaryUser()).thenReturn(mPrimaryUser);
         when(mUserManager.getUsers()).thenReturn(userInfos);
-        List<AbstractPreferenceController> controllers =
+        final List<AbstractPreferenceController> controllers =
                 SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager);
 
         assertThat(controllers).hasSize(1);
@@ -140,15 +141,15 @@
 
     @Test
     public void profilesOfPrimaryUserAreNotIgnored() throws Exception {
-        ArrayList<UserInfo> userInfos = new ArrayList<>();
-        UserInfo secondaryUser = new UserInfo();
+        final ArrayList<UserInfo> userInfos = new ArrayList<>();
+        final UserInfo secondaryUser = new UserInfo();
         secondaryUser.id = mPrimaryUser.id;
         userInfos.add(mPrimaryUser);
         userInfos.add(secondaryUser);
         when(mUserManager.getPrimaryUser()).thenReturn(mPrimaryUser);
         when(mUserManager.getUsers()).thenReturn(userInfos);
 
-        List<AbstractPreferenceController> controllers =
+        final List<AbstractPreferenceController> controllers =
                 SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager);
 
         assertThat(controllers).hasSize(2);
@@ -161,9 +162,9 @@
         mPrimaryUser.name = TEST_NAME;
         mPrimaryUser.id = 10;
         mController.displayPreference(mScreen);
-        StorageAsyncLoader.AppsStorageResult userResult =
+        final StorageAsyncLoader.AppsStorageResult userResult =
                 new StorageAsyncLoader.AppsStorageResult();
-        SparseArray<StorageAsyncLoader.AppsStorageResult> result = new SparseArray<>();
+        final SparseArray<StorageAsyncLoader.AppsStorageResult> result = new SparseArray<>();
         userResult.externalStats =
                 new StorageStatsSource.ExternalStorageStats(
                         MEGABYTE_IN_BYTES * 30,
@@ -175,23 +176,23 @@
         mController.handleResult(result);
         final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
         verify(mGroup).addPreference(argumentCaptor.capture());
-        Preference preference = argumentCaptor.getValue();
+        final Preference preference = argumentCaptor.getValue();
 
         assertThat(preference.getSummary()).isEqualTo("0.03 GB");
     }
 
     @Test
     public void dontAddPrimaryProfileAsASecondaryProfile() throws Exception {
-        ArrayList<UserInfo> userInfos = new ArrayList<>();
+        final ArrayList<UserInfo> userInfos = new ArrayList<>();
         // The primary UserInfo may be a different object with a different name... but represent the
         // same user!
-        UserInfo primaryUserRenamed = new UserInfo();
+        final UserInfo primaryUserRenamed = new UserInfo();
         primaryUserRenamed.name = "Owner";
         primaryUserRenamed.flags = UserInfo.FLAG_PRIMARY;
         userInfos.add(primaryUserRenamed);
         when(mUserManager.getPrimaryUser()).thenReturn(mPrimaryUser);
         when(mUserManager.getUsers()).thenReturn(userInfos);
-        List<AbstractPreferenceController> controllers =
+        final List<AbstractPreferenceController> controllers =
                 SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager);
 
         assertThat(controllers).hasSize(1);
@@ -201,34 +202,29 @@
 
     @Test
     public void iconCallbackChangesPreferenceIcon() throws Exception {
-        SparseArray<Drawable> icons = new SparseArray<>();
-        Bitmap userBitmap =
-                BitmapFactory.decodeResource(
-                        RuntimeEnvironment.application.getResources(), R.drawable.home);
-        UserIconDrawable drawable = new UserIconDrawable(100 /* size */).setIcon(userBitmap).bake();
-        icons.put(10, drawable);
+        final SparseArray<Drawable> icons = new SparseArray<>();
+        final UserIconDrawable drawable = mock(UserIconDrawable.class);
+        when(drawable.mutate()).thenReturn(drawable);
         mPrimaryUser.name = TEST_NAME;
         mPrimaryUser.id = 10;
+        icons.put(mPrimaryUser.id, drawable);
         mController.displayPreference(mScreen);
 
         mController.handleUserIcons(icons);
 
         final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
         verify(mGroup).addPreference(argumentCaptor.capture());
-        Preference preference = argumentCaptor.getValue();
+        final Preference preference = argumentCaptor.getValue();
         assertThat(preference.getIcon()).isEqualTo(drawable);
     }
 
     @Test
     public void setIcon_doesntNpeOnNullPreference() throws Exception {
-        SparseArray<Drawable> icons = new SparseArray<>();
-        Bitmap userBitmap =
-                BitmapFactory.decodeResource(
-                        RuntimeEnvironment.application.getResources(), R.drawable.home);
-        UserIconDrawable drawable = new UserIconDrawable(100 /* size */).setIcon(userBitmap).bake();
-        icons.put(10, drawable);
+        final SparseArray<Drawable> icons = new SparseArray<>();
+        final UserIconDrawable drawable = mock(UserIconDrawable.class);
         mPrimaryUser.name = TEST_NAME;
         mPrimaryUser.id = 10;
+        icons.put(mPrimaryUser.id, drawable);
 
         mController.handleUserIcons(icons);
 
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
index e6c161e..4828769 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
@@ -17,7 +17,8 @@
 
 
 import static com.android.settings.applications.manageapplications.ManageApplications.EXTRA_WORK_ID;
-import static com.android.settings.applications.manageapplications.ManageApplications.EXTRA_WORK_ONLY;
+import static com.android.settings.applications.manageapplications.ManageApplications
+        .EXTRA_WORK_ONLY;
 import static com.android.settings.utils.FileSizeFormatter.MEGABYTE_IN_BYTES;
 import static com.google.common.truth.Truth.assertThat;
 import static org.mockito.ArgumentMatchers.nullable;
@@ -28,7 +29,10 @@
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
+import android.app.Activity;
 import android.app.Fragment;
+import android.app.FragmentManager;
+import android.app.FragmentTransaction;
 import android.content.Context;
 import android.content.Intent;
 import android.graphics.drawable.Drawable;
@@ -67,14 +71,20 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class StorageItemPreferenceControllerTest {
     private Context mContext;
     private VolumeInfo mVolume;
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+    @Mock
     private Fragment mFragment;
     @Mock
     private StorageVolumeProvider mSvp;
+    @Mock
+    private Activity mActivity;
+    @Mock
+    private FragmentManager mFragmentManager;
+    @Mock
+    private FragmentTransaction mFragmentTransaction;
     private StorageItemPreferenceController mController;
     private StorageItemPreference mPreference;
     private FakeFeatureFactory mFakeFeatureFactory;
@@ -83,9 +93,11 @@
     @Before
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
+        when(mFragment.getActivity()).thenReturn(mActivity);
+        when(mFragment.getFragmentManager()).thenReturn(mFragmentManager);
+        when(mFragmentManager.beginTransaction()).thenReturn(mFragmentTransaction);
         mContext = spy(RuntimeEnvironment.application.getApplicationContext());
-        FakeFeatureFactory.setupForTest(mContext);
-        mFakeFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
         mMetricsFeatureProvider = mFakeFeatureFactory.getMetricsFeatureProvider();
         mVolume = spy(new VolumeInfo("id", 0, null, "id"));
         // Note: null is passed as the Lifecycle because we are handling it outside of the normal
@@ -94,7 +106,7 @@
         mPreference = new StorageItemPreference(mContext);
 
         // Inflate the preference and the widget.
-        LayoutInflater inflater = LayoutInflater.from(mContext);
+        final LayoutInflater inflater = LayoutInflater.from(mContext);
         final View view = inflater.inflate(
                 mPreference.getLayoutResource(), new LinearLayout(mContext), false);
     }
@@ -116,10 +128,10 @@
         mController.handlePreferenceTreeClick(mPreference);
 
         final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
-        verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
+        verify(mActivity).startActivityAsUser(argumentCaptor.capture(),
                 nullable(UserHandle.class));
 
-        Intent intent = argumentCaptor.getValue();
+        final Intent intent = argumentCaptor.getValue();
         assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
         assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
         assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
@@ -136,7 +148,7 @@
         final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
         verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
                 nullable(UserHandle.class));
-        Intent intent = argumentCaptor.getValue();
+        final Intent intent = argumentCaptor.getValue();
 
         assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
         assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
@@ -164,7 +176,7 @@
         verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
                 nullable(UserHandle.class));
 
-        Intent intent = argumentCaptor.getValue();
+        final Intent intent = argumentCaptor.getValue();
         assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
         assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
         assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT)).isEqualTo(
@@ -191,12 +203,12 @@
         assertThat(intent.getIntExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, 0))
                 .isEqualTo(R.string.apps_storage);
         assertThat(
-                        intent.getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS)
-                                .getBoolean(EXTRA_WORK_ONLY))
+                intent.getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS)
+                        .getBoolean(EXTRA_WORK_ONLY))
                 .isTrue();
         assertThat(
-                        intent.getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS)
-                                .getInt(EXTRA_WORK_ID))
+                intent.getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS)
+                        .getInt(EXTRA_WORK_ID))
                 .isEqualTo(0);
     }
 
@@ -273,14 +285,14 @@
 
     @Test
     public void testMeasurementCompletedUpdatesPreferences() {
-        StorageItemPreference audio = new StorageItemPreference(mContext);
-        StorageItemPreference image = new StorageItemPreference(mContext);
-        StorageItemPreference games = new StorageItemPreference(mContext);
-        StorageItemPreference movies = new StorageItemPreference(mContext);
-        StorageItemPreference apps = new StorageItemPreference(mContext);
-        StorageItemPreference system = new StorageItemPreference(mContext);
-        StorageItemPreference files = new StorageItemPreference(mContext);
-        PreferenceScreen screen = mock(PreferenceScreen.class);
+        final StorageItemPreference audio = new StorageItemPreference(mContext);
+        final StorageItemPreference image = new StorageItemPreference(mContext);
+        final StorageItemPreference games = new StorageItemPreference(mContext);
+        final StorageItemPreference movies = new StorageItemPreference(mContext);
+        final StorageItemPreference apps = new StorageItemPreference(mContext);
+        final StorageItemPreference system = new StorageItemPreference(mContext);
+        final StorageItemPreference files = new StorageItemPreference(mContext);
+        final PreferenceScreen screen = mock(PreferenceScreen.class);
         when(screen.findPreference(
                 eq(StorageItemPreferenceController.AUDIO_KEY))).thenReturn(audio);
         when(screen.findPreference(
@@ -298,7 +310,7 @@
         mController.displayPreference(screen);
 
         mController.setUsedSize(MEGABYTE_IN_BYTES * 970); // There should 870MB attributed.
-        StorageAsyncLoader.AppsStorageResult result = new StorageAsyncLoader.AppsStorageResult();
+        final StorageAsyncLoader.AppsStorageResult result = new StorageAsyncLoader.AppsStorageResult();
         result.gamesSize = MEGABYTE_IN_BYTES * 80;
         result.videoAppsSize = MEGABYTE_IN_BYTES * 160;
         result.musicAppsSize = MEGABYTE_IN_BYTES * 40;
@@ -310,7 +322,7 @@
                         MEGABYTE_IN_BYTES * 150, // video
                         MEGABYTE_IN_BYTES * 200, 0); // image
 
-        SparseArray<StorageAsyncLoader.AppsStorageResult> results = new SparseArray<>();
+        final SparseArray<StorageAsyncLoader.AppsStorageResult> results = new SparseArray<>();
         results.put(0, result);
         mController.onLoadFinished(results, 0);
 
@@ -324,21 +336,21 @@
 
     @Test
     public void settingUserIdAppliesNewIcons() {
-        StorageItemPreference audio = spy(new StorageItemPreference(mContext));
+        final StorageItemPreference audio = spy(new StorageItemPreference(mContext));
         audio.setIcon(R.drawable.ic_media_stream);
-        StorageItemPreference video = spy(new StorageItemPreference(mContext));
+        final StorageItemPreference video = spy(new StorageItemPreference(mContext));
         video.setIcon(R.drawable.ic_local_movies);
-        StorageItemPreference image = spy(new StorageItemPreference(mContext));
+        final StorageItemPreference image = spy(new StorageItemPreference(mContext));
         image.setIcon(R.drawable.ic_photo_library);
-        StorageItemPreference games = spy(new StorageItemPreference(mContext));
+        final StorageItemPreference games = spy(new StorageItemPreference(mContext));
         games.setIcon(R.drawable.ic_videogame_vd_theme_24);
-        StorageItemPreference apps = spy(new StorageItemPreference(mContext));
+        final StorageItemPreference apps = spy(new StorageItemPreference(mContext));
         apps.setIcon(R.drawable.ic_storage_apps);
-        StorageItemPreference system = spy(new StorageItemPreference(mContext));
+        final StorageItemPreference system = spy(new StorageItemPreference(mContext));
         system.setIcon(R.drawable.ic_system_update_vd_theme_24);
-        StorageItemPreference files = spy(new StorageItemPreference(mContext));
+        final StorageItemPreference files = spy(new StorageItemPreference(mContext));
         files.setIcon(R.drawable.ic_folder_vd_theme_24);
-        PreferenceScreen screen = mock(PreferenceScreen.class);
+        final PreferenceScreen screen = mock(PreferenceScreen.class);
         when(screen.findPreference(
                 eq(StorageItemPreferenceController.AUDIO_KEY))).thenReturn(audio);
         when(screen.findPreference(
@@ -368,13 +380,13 @@
 
     @Test
     public void displayPreference_dontHideFilePreferenceWhenEmulatedInternalStorageUsed() {
-        StorageItemPreference audio = new StorageItemPreference(mContext);
-        StorageItemPreference image = new StorageItemPreference(mContext);
-        StorageItemPreference games = new StorageItemPreference(mContext);
-        StorageItemPreference apps = new StorageItemPreference(mContext);
-        StorageItemPreference system = new StorageItemPreference(mContext);
-        StorageItemPreference files = new StorageItemPreference(mContext);
-        PreferenceScreen screen = mock(PreferenceScreen.class);
+        final StorageItemPreference audio = new StorageItemPreference(mContext);
+        final StorageItemPreference image = new StorageItemPreference(mContext);
+        final StorageItemPreference games = new StorageItemPreference(mContext);
+        final StorageItemPreference apps = new StorageItemPreference(mContext);
+        final StorageItemPreference system = new StorageItemPreference(mContext);
+        final StorageItemPreference files = new StorageItemPreference(mContext);
+        final PreferenceScreen screen = mock(PreferenceScreen.class);
         when(screen.findPreference(eq(StorageItemPreferenceController.AUDIO_KEY)))
                 .thenReturn(audio);
         when(screen.findPreference(eq(StorageItemPreferenceController.PHOTO_KEY)))
@@ -397,13 +409,13 @@
 
     @Test
     public void displayPreference_hideFilePreferenceWhenEmulatedStorageUnreadable() {
-        StorageItemPreference audio = new StorageItemPreference(mContext);
-        StorageItemPreference image = new StorageItemPreference(mContext);
-        StorageItemPreference games = new StorageItemPreference(mContext);
-        StorageItemPreference apps = new StorageItemPreference(mContext);
-        StorageItemPreference system = new StorageItemPreference(mContext);
-        StorageItemPreference files = new StorageItemPreference(mContext);
-        PreferenceScreen screen = mock(PreferenceScreen.class);
+        final StorageItemPreference audio = new StorageItemPreference(mContext);
+        final StorageItemPreference image = new StorageItemPreference(mContext);
+        final StorageItemPreference games = new StorageItemPreference(mContext);
+        final StorageItemPreference apps = new StorageItemPreference(mContext);
+        final StorageItemPreference system = new StorageItemPreference(mContext);
+        final StorageItemPreference files = new StorageItemPreference(mContext);
+        final PreferenceScreen screen = mock(PreferenceScreen.class);
         when(screen.findPreference(eq(StorageItemPreferenceController.AUDIO_KEY)))
                 .thenReturn(audio);
         when(screen.findPreference(eq(StorageItemPreferenceController.PHOTO_KEY)))
@@ -426,13 +438,13 @@
 
     @Test
     public void displayPreference_hideFilePreferenceWhenNoEmulatedInternalStorage() {
-        StorageItemPreference audio = new StorageItemPreference(mContext);
-        StorageItemPreference image = new StorageItemPreference(mContext);
-        StorageItemPreference games = new StorageItemPreference(mContext);
-        StorageItemPreference apps = new StorageItemPreference(mContext);
-        StorageItemPreference system = new StorageItemPreference(mContext);
-        StorageItemPreference files = new StorageItemPreference(mContext);
-        PreferenceScreen screen = mock(PreferenceScreen.class);
+        final StorageItemPreference audio = new StorageItemPreference(mContext);
+        final StorageItemPreference image = new StorageItemPreference(mContext);
+        final StorageItemPreference games = new StorageItemPreference(mContext);
+        final StorageItemPreference apps = new StorageItemPreference(mContext);
+        final StorageItemPreference system = new StorageItemPreference(mContext);
+        final StorageItemPreference files = new StorageItemPreference(mContext);
+        final PreferenceScreen screen = mock(PreferenceScreen.class);
         when(screen.findPreference(eq(StorageItemPreferenceController.AUDIO_KEY)))
                 .thenReturn(audio);
         when(screen.findPreference(eq(StorageItemPreferenceController.PHOTO_KEY)))
@@ -454,13 +466,13 @@
 
     @Test
     public void displayPreference_updateFilePreferenceToHideAfterSettingVolume() {
-        StorageItemPreference audio = new StorageItemPreference(mContext);
-        StorageItemPreference image = new StorageItemPreference(mContext);
-        StorageItemPreference games = new StorageItemPreference(mContext);
-        StorageItemPreference apps = new StorageItemPreference(mContext);
-        StorageItemPreference system = new StorageItemPreference(mContext);
-        StorageItemPreference files = new StorageItemPreference(mContext);
-        PreferenceScreen screen = mock(PreferenceScreen.class);
+        final StorageItemPreference audio = new StorageItemPreference(mContext);
+        final StorageItemPreference image = new StorageItemPreference(mContext);
+        final StorageItemPreference games = new StorageItemPreference(mContext);
+        final StorageItemPreference apps = new StorageItemPreference(mContext);
+        final StorageItemPreference system = new StorageItemPreference(mContext);
+        final StorageItemPreference files = new StorageItemPreference(mContext);
+        final PreferenceScreen screen = mock(PreferenceScreen.class);
         when(screen.findPreference(eq(StorageItemPreferenceController.AUDIO_KEY)))
                 .thenReturn(audio);
         when(screen.findPreference(eq(StorageItemPreferenceController.PHOTO_KEY)))
@@ -486,13 +498,13 @@
 
     @Test
     public void displayPreference_updateFilePreferenceToShowAfterSettingVolume() {
-        StorageItemPreference audio = new StorageItemPreference(mContext);
-        StorageItemPreference image = new StorageItemPreference(mContext);
-        StorageItemPreference games = new StorageItemPreference(mContext);
-        StorageItemPreference apps = new StorageItemPreference(mContext);
-        StorageItemPreference system = new StorageItemPreference(mContext);
-        StorageItemPreference files = new StorageItemPreference(mContext);
-        PreferenceScreen screen = mock(PreferenceScreen.class);
+        final StorageItemPreference audio = new StorageItemPreference(mContext);
+        final StorageItemPreference image = new StorageItemPreference(mContext);
+        final StorageItemPreference games = new StorageItemPreference(mContext);
+        final StorageItemPreference apps = new StorageItemPreference(mContext);
+        final StorageItemPreference system = new StorageItemPreference(mContext);
+        final StorageItemPreference files = new StorageItemPreference(mContext);
+        final PreferenceScreen screen = mock(PreferenceScreen.class);
         when(screen.findPreference(eq(StorageItemPreferenceController.AUDIO_KEY)))
                 .thenReturn(audio);
         when(screen.findPreference(eq(StorageItemPreferenceController.PHOTO_KEY)))
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceControllerTest.java
index 8ebfb89..b9a4963 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceControllerTest.java
@@ -16,8 +16,9 @@
 
 package com.android.settings.deviceinfo.storage;
 
+import static com.android.settings.TestUtils.GIGABYTE;
+import static com.android.settings.TestUtils.KILOBYTE;
 import static com.google.common.truth.Truth.assertThat;
-
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.spy;
@@ -28,6 +29,7 @@
 import android.content.Context;
 import android.os.storage.VolumeInfo;
 import android.support.v7.preference.PreferenceViewHolder;
+import android.text.format.Formatter;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.widget.Button;
@@ -35,10 +37,10 @@
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settings.R;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.testutils.shadow.SettingsShadowResources;
 import com.android.settingslib.deviceinfo.StorageVolumeProvider;
 
@@ -52,15 +54,12 @@
 
 import java.io.File;
 
-import static com.android.settings.TestUtils.KILOBYTE;
-import static com.android.settings.TestUtils.GIGABYTE;
-
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
         shadows = {
-        SettingsShadowResources.class,
-        SettingsShadowResources.SettingsShadowTheme.class
-})
+                SettingsShadowResources.class,
+                SettingsShadowResources.SettingsShadowTheme.class
+        })
 public class StorageSummaryDonutPreferenceControllerTest {
     private Context mContext;
     private StorageSummaryDonutPreferenceController mController;
@@ -74,8 +73,7 @@
         SettingsShadowResources.overrideResource(
                 com.android.internal.R.string.config_headlineFontFamily, "");
         mContext = spy(RuntimeEnvironment.application.getApplicationContext());
-        FakeFeatureFactory.setupForTest(mContext);
-        mFakeFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
         mMetricsFeatureProvider = mFakeFeatureFactory.getMetricsFeatureProvider();
         mController = new StorageSummaryDonutPreferenceController(mContext);
         mPreference = new StorageSummaryDonutPreference(mContext);
@@ -94,43 +92,62 @@
 
     @Test
     public void testEmpty() throws Exception {
+        final long totalSpace = 32 * GIGABYTE;
+        final long usedSpace = 0;
         mController.updateBytes(0, 32 * GIGABYTE);
         mController.updateState(mPreference);
 
-        assertThat(mPreference.getTitle().toString()).isEqualTo("0.00 B");
-        assertThat(mPreference.getSummary().toString()).isEqualTo("Used of 32 GB");
+        final Formatter.BytesResult usedSpaceResults = Formatter.formatBytes(
+                mContext.getResources(), usedSpace, 0 /* flags */);
+        assertThat(mPreference.getTitle().toString()).isEqualTo(
+                usedSpaceResults.value + " " + usedSpaceResults.units);
+        assertThat(mPreference.getSummary().toString()).isEqualTo(
+                "Used of " + Formatter.formatShortFileSize(mContext, totalSpace));
     }
 
     @Test
     public void testTotalStorage() throws Exception {
-        mController.updateBytes(KILOBYTE, KILOBYTE * 10);
+        final long totalSpace = KILOBYTE * 10;
+        final long usedSpace = KILOBYTE;
+        mController.updateBytes(KILOBYTE, totalSpace);
         mController.updateState(mPreference);
 
-        assertThat(mPreference.getTitle().toString()).isEqualTo("1.00 KB");
-        assertThat(mPreference.getSummary().toString()).isEqualTo("Used of 10 KB");
+        final Formatter.BytesResult usedSpaceResults = Formatter.formatBytes(
+                mContext.getResources(), usedSpace, 0 /* flags */);
+        assertThat(mPreference.getTitle().toString()).isEqualTo(
+                usedSpaceResults.value + " " + usedSpaceResults.units);
+        assertThat(mPreference.getSummary().toString()).isEqualTo(
+                "Used of " + Formatter.formatShortFileSize(mContext, totalSpace));
     }
 
     @Test
     public void testPopulateWithVolume() throws Exception {
-        VolumeInfo volume = Mockito.mock(VolumeInfo.class);
-        File file = Mockito.mock(File.class);
-        StorageVolumeProvider svp = Mockito.mock(StorageVolumeProvider.class);
+        final long totalSpace = KILOBYTE * 10;
+        final long freeSpace = KILOBYTE;
+        final long usedSpace = totalSpace - freeSpace;
+        final VolumeInfo volume = Mockito.mock(VolumeInfo.class);
+        final File file = Mockito.mock(File.class);
+        final StorageVolumeProvider svp = Mockito.mock(StorageVolumeProvider.class);
         when(volume.getPath()).thenReturn(file);
-        when(file.getTotalSpace()).thenReturn(KILOBYTE * 10);
-        when(file.getFreeSpace()).thenReturn(KILOBYTE);
-        when(svp.getPrimaryStorageSize()).thenReturn(KILOBYTE * 10);
+        when(file.getTotalSpace()).thenReturn(totalSpace);
+        when(file.getFreeSpace()).thenReturn(freeSpace);
+        when(svp.getPrimaryStorageSize()).thenReturn(totalSpace);
 
         mController.updateSizes(svp, volume);
         mController.updateState(mPreference);
 
-        assertThat(mPreference.getTitle().toString()).isEqualTo("9.00 KB");
-        assertThat(mPreference.getSummary().toString()).isEqualTo("Used of 10 KB");
+        final Formatter.BytesResult usedSpaceResults = Formatter.formatBytes(
+                mContext.getResources(), usedSpace, 0 /* flags */);
+        assertThat(mPreference.getTitle().toString()).isEqualTo(
+                usedSpaceResults.value + " " + usedSpaceResults.units);
+        assertThat(mPreference.getSummary().toString()).isEqualTo(
+                "Used of " + Formatter.formatShortFileSize(mContext, totalSpace));
     }
 
     @Test
     public void testFreeUpSpaceMetricIsTriggered() throws Exception {
         mPreference.onBindViewHolder(mHolder);
-        Button button = (Button) mHolder.findViewById(R.id.deletion_helper_button);
+        final Button button = (Button) mHolder.findViewById(R.id.deletion_helper_button);
 
         mPreference.onClick(button);
 
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/UserProfileControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/UserProfileControllerTest.java
index 8da5260..98e796e 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/UserProfileControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/UserProfileControllerTest.java
@@ -19,6 +19,7 @@
 import static com.google.common.truth.Truth.assertThat;
 import static com.android.settings.utils.FileSizeFormatter.MEGABYTE_IN_BYTES;
 
+import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -53,7 +54,7 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class UserProfileControllerTest {
     private static final String TEST_NAME = "Fred";
 
@@ -82,7 +83,7 @@
     public void controllerAddsPrimaryProfilePreference() throws Exception {
         final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
         verify(mScreen).addPreference(argumentCaptor.capture());
-        Preference preference = argumentCaptor.getValue();
+        final Preference preference = argumentCaptor.getValue();
 
         assertThat(preference.getTitle()).isEqualTo(TEST_NAME);
         assertThat(preference.getKey()).isEqualTo("pref_profile_10");
@@ -93,12 +94,12 @@
 
         final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
         verify(mScreen).addPreference(argumentCaptor.capture());
-        Preference preference = argumentCaptor.getValue();
+        final Preference preference = argumentCaptor.getValue();
         assertThat(mController.handlePreferenceTreeClick(preference)).isTrue();
         final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
         verify(mContext).startActivity(intentCaptor.capture());
 
-        Intent intent = intentCaptor.getValue();
+        final Intent intent = intentCaptor.getValue();
         assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
         assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT)).isEqualTo(
                 StorageProfileFragment.class.getName());
@@ -106,8 +107,8 @@
 
     @Test
     public void acceptingResultUpdatesPreferenceSize() throws Exception {
-        SparseArray<StorageAsyncLoader.AppsStorageResult> result = new SparseArray<>();
-        StorageAsyncLoader.AppsStorageResult userResult =
+        final SparseArray<StorageAsyncLoader.AppsStorageResult> result = new SparseArray<>();
+        final StorageAsyncLoader.AppsStorageResult userResult =
                 new StorageAsyncLoader.AppsStorageResult();
         userResult.externalStats =
                 new StorageStatsSource.ExternalStorageStats(
@@ -120,25 +121,23 @@
         mController.handleResult(result);
         final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
         verify(mScreen).addPreference(argumentCaptor.capture());
-        Preference preference = argumentCaptor.getValue();
+        final Preference preference = argumentCaptor.getValue();
 
         assertThat(preference.getSummary()).isEqualTo("0.10 GB");
     }
 
     @Test
     public void iconCallbackChangesPreferenceIcon() throws Exception {
-        SparseArray<Drawable> icons = new SparseArray<>();
-        Bitmap userBitmap =
-                BitmapFactory.decodeResource(
-                        RuntimeEnvironment.application.getResources(), R.drawable.home);
-        UserIconDrawable drawable = new UserIconDrawable(100 /* size */).setIcon(userBitmap).bake();
-        icons.put(10, drawable);
+        final SparseArray<Drawable> icons = new SparseArray<>();
+        final UserIconDrawable drawable = mock(UserIconDrawable.class);
+        when(drawable.mutate()).thenReturn(drawable);
+        icons.put(mPrimaryProfile.id, drawable);
 
         mController.handleUserIcons(icons);
 
         final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
         verify(mScreen).addPreference(argumentCaptor.capture());
-        Preference preference = argumentCaptor.getValue();
+        final Preference preference = argumentCaptor.getValue();
         assertThat(preference.getIcon()).isEqualTo(drawable);
     }
 }
diff --git a/tests/robotests/src/com/android/settings/display/AutoRotatePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/AutoRotatePreferenceControllerTest.java
index febbaf1..e193b94 100644
--- a/tests/robotests/src/com/android/settings/display/AutoRotatePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/AutoRotatePreferenceControllerTest.java
@@ -17,7 +17,6 @@
 package com.android.settings.display;
 
 import static com.google.common.truth.Truth.assertThat;
-
 import static org.mockito.Matchers.anyInt;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Mockito.when;
@@ -65,7 +64,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
+        FakeFeatureFactory.setupForTest();
         mContentResolver = RuntimeEnvironment.application.getContentResolver();
         mLifecycle = new Lifecycle(() -> mLifecycle);
         mPreference = new SwitchPreference(RuntimeEnvironment.application);
diff --git a/tests/robotests/src/com/android/settings/display/ThemePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/ThemePreferenceControllerTest.java
index 289b8c1..751fa40 100644
--- a/tests/robotests/src/com/android/settings/display/ThemePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/ThemePreferenceControllerTest.java
@@ -16,6 +16,15 @@
 
 package com.android.settings.display;
 
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
 import android.content.Context;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
@@ -23,10 +32,10 @@
 import android.support.v7.preference.ListPreference;
 
 import com.android.settings.R;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.display.ThemePreferenceController.OverlayManager;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -37,15 +46,6 @@
 import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
 
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class ThemePreferenceControllerTest {
@@ -64,7 +64,7 @@
     @Before
     public void setUp() throws NameNotFoundException {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
+        FakeFeatureFactory.setupForTest();
         when(mPackageManager.getApplicationInfo(any(), anyInt())).thenReturn(mApplicationInfo);
         when(mContext.getPackageManager()).thenReturn(mPackageManager);
         when(mContext.getString(R.string.default_theme))
diff --git a/tests/robotests/src/com/android/settings/dream/CurrentDreamPickerTest.java b/tests/robotests/src/com/android/settings/dream/CurrentDreamPickerTest.java
index e0a59b5..93403fe 100644
--- a/tests/robotests/src/com/android/settings/dream/CurrentDreamPickerTest.java
+++ b/tests/robotests/src/com/android/settings/dream/CurrentDreamPickerTest.java
@@ -16,17 +16,22 @@
 
 package com.android.settings.dream;
 
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
 import android.app.Activity;
 import android.content.ComponentName;
 import android.content.Context;
 import android.os.UserManager;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
 import com.android.settings.TestConfig;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settingslib.dream.DreamBackend;
 import com.android.settingslib.dream.DreamBackend.DreamInfo;
-import java.util.ArrayList;
-import java.util.Arrays;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -36,10 +41,8 @@
 import org.robolectric.annotation.Config;
 import org.robolectric.util.ReflectionHelpers;
 
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import java.util.ArrayList;
+import java.util.Arrays;
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
@@ -58,10 +61,10 @@
     public void setup() {
         MockitoAnnotations.initMocks(this);
         when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
-        FakeFeatureFactory.setupForTest(mActivity);
+        FakeFeatureFactory.setupForTest();
 
         mPicker = new CurrentDreamPicker();
-        mPicker.onAttach((Context)mActivity);
+        mPicker.onAttach((Context) mActivity);
 
         ReflectionHelpers.setField(mPicker, "mBackend", mBackend);
     }
diff --git a/tests/robotests/src/com/android/settings/dream/WhenToDreamPickerTest.java b/tests/robotests/src/com/android/settings/dream/WhenToDreamPickerTest.java
index 542e0b7..94d6853 100644
--- a/tests/robotests/src/com/android/settings/dream/WhenToDreamPickerTest.java
+++ b/tests/robotests/src/com/android/settings/dream/WhenToDreamPickerTest.java
@@ -16,13 +16,19 @@
 
 package com.android.settings.dream;
 
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
 import android.app.Activity;
 import android.content.Context;
 import android.os.UserManager;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
 import com.android.settings.TestConfig;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settingslib.dream.DreamBackend;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -32,10 +38,6 @@
 import org.robolectric.annotation.Config;
 import org.robolectric.util.ReflectionHelpers;
 
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class WhenToDreamPickerTest {
@@ -51,10 +53,10 @@
     public void setup() {
         MockitoAnnotations.initMocks(this);
         when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
-        FakeFeatureFactory.setupForTest(mActivity);
+        FakeFeatureFactory.setupForTest();
 
         mPicker = new WhenToDreamPicker();
-        mPicker.onAttach((Context)mActivity);
+        mPicker.onAttach((Context) mActivity);
 
         ReflectionHelpers.setField(mPicker, "mBackend", mBackend);
     }
diff --git a/tests/robotests/src/com/android/settings/enterprise/AdminActionPreferenceControllerTestBase.java b/tests/robotests/src/com/android/settings/enterprise/AdminActionPreferenceControllerTestBase.java
index e9b9d86..83b7198 100644
--- a/tests/robotests/src/com/android/settings/enterprise/AdminActionPreferenceControllerTestBase.java
+++ b/tests/robotests/src/com/android/settings/enterprise/AdminActionPreferenceControllerTestBase.java
@@ -16,6 +16,9 @@
 
 package com.android.settings.enterprise;
 
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.when;
+
 import android.content.Context;
 import android.provider.Settings;
 import android.support.v7.preference.Preference;
@@ -33,9 +36,6 @@
 import java.util.Date;
 import java.util.GregorianCalendar;
 
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.when;
-
 /**
  * Common base for testing subclasses of {@link AdminActionPreferenceControllerBase}.
  */
@@ -50,8 +50,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
     }
 
     public abstract void setDate(Date date);
diff --git a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerTestBase.java b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerTestBase.java
index 421fb0f..03dc9f1 100644
--- a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerTestBase.java
+++ b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerTestBase.java
@@ -58,8 +58,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mController = createController(true /* async */);
     }
 
@@ -69,9 +68,10 @@
                 ((ApplicationFeatureProvider.NumberOfAppsCallback)
                         invocation.getArguments()[2]).onNumberOfAppsResult(number);
                 return null;
-            }}).when(mFeatureFactory.applicationFeatureProvider)
-                    .calculateNumberOfAppsWithAdminGrantedPermissions(eq(mPermissions),
-                            eq(async), anyObject());
+            }
+        }).when(mFeatureFactory.applicationFeatureProvider)
+                .calculateNumberOfAppsWithAdminGrantedPermissions(eq(mPermissions),
+                        eq(async), anyObject());
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnCurrentUserPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnCurrentUserPreferenceControllerTest.java
index 17649bb..3c6b4c0 100644
--- a/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnCurrentUserPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnCurrentUserPreferenceControllerTest.java
@@ -55,8 +55,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mController = new AlwaysOnVpnCurrentUserPreferenceController(mContext);
         when(mContext.getString(R.string.enterprise_privacy_always_on_vpn_device))
                 .thenReturn(VPN_SET_DEVICE);
diff --git a/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnManagedProfilePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnManagedProfilePreferenceControllerTest.java
index d54505b..662b984 100644
--- a/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnManagedProfilePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnManagedProfilePreferenceControllerTest.java
@@ -52,8 +52,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mController = new AlwaysOnVpnManagedProfilePreferenceController(mContext);
     }
 
diff --git a/tests/robotests/src/com/android/settings/enterprise/CaCertsPreferenceControllerTestBase.java b/tests/robotests/src/com/android/settings/enterprise/CaCertsPreferenceControllerTestBase.java
index c2fb4da..fe7f4e1 100644
--- a/tests/robotests/src/com/android/settings/enterprise/CaCertsPreferenceControllerTestBase.java
+++ b/tests/robotests/src/com/android/settings/enterprise/CaCertsPreferenceControllerTestBase.java
@@ -44,8 +44,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mController = createController();
     }
 
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterpriseInstalledPackagesPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterpriseInstalledPackagesPreferenceControllerTest.java
index 7ecd0e3..19349a7 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterpriseInstalledPackagesPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterpriseInstalledPackagesPreferenceControllerTest.java
@@ -60,8 +60,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mController = new EnterpriseInstalledPackagesPreferenceController(mContext,
                 true /* async */);
     }
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyPreferenceControllerTest.java
index dd97cc0..8cbddb9 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyPreferenceControllerTest.java
@@ -56,8 +56,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mController = new EnterprisePrivacyPreferenceController(mContext);
     }
 
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java
index 1a37e63..845fd61 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java
@@ -55,8 +55,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
 
         mSettings = new EnterprisePrivacySettings();
     }
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsListPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsListPreferenceControllerTest.java
index cf66967..da26ba3 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsListPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsListPreferenceControllerTest.java
@@ -16,6 +16,16 @@
 
 package com.android.settings.enterprise;
 
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Answers.RETURNS_DEEP_STUBS;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
 import android.content.Context;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
@@ -28,13 +38,12 @@
 
 import com.android.settings.R;
 import com.android.settings.SettingsPreferenceFragment;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.applications.EnterpriseDefaultApps;
 import com.android.settings.applications.UserAppInfo;
-import com.android.settings.overlay.FeatureFactory;
 import com.android.settings.testutils.ApplicationTestUtils;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -48,16 +57,6 @@
 import java.util.Arrays;
 import java.util.Collections;
 
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Answers.RETURNS_DEEP_STUBS;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class EnterpriseSetDefaultAppsListPreferenceControllerTest {
@@ -86,8 +85,7 @@
         MockitoAnnotations.initMocks(this);
         ShadowApplication shadowContext = ShadowApplication.getInstance();
         mContext = spy(shadowContext.getApplicationContext());
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
         when(mPrefenceManager.getContext()).thenReturn(mContext);
         when(mFragment.getPreferenceManager()).thenReturn(mPrefenceManager);
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsPreferenceControllerTest.java
index 1223558..9d980cc 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsPreferenceControllerTest.java
@@ -67,8 +67,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mController = new EnterpriseSetDefaultAppsPreferenceController(mContext);
     }
 
diff --git a/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerTestBase.java b/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerTestBase.java
index fe4fb6b..4b85b78 100644
--- a/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerTestBase.java
+++ b/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerTestBase.java
@@ -51,8 +51,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
     }
 
     public abstract void setMaximumFailedPasswordsBeforeWipe(int maximum);
diff --git a/tests/robotests/src/com/android/settings/enterprise/GlobalHttpProxyPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/GlobalHttpProxyPreferenceControllerTest.java
index e31b40f..9bcda9a 100644
--- a/tests/robotests/src/com/android/settings/enterprise/GlobalHttpProxyPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/GlobalHttpProxyPreferenceControllerTest.java
@@ -52,8 +52,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mController = new GlobalHttpProxyPreferenceController(mContext);
     }
 
diff --git a/tests/robotests/src/com/android/settings/enterprise/ImePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/ImePreferenceControllerTest.java
index caa5121..a56d9d3 100644
--- a/tests/robotests/src/com/android/settings/enterprise/ImePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/ImePreferenceControllerTest.java
@@ -55,8 +55,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mController = new ImePreferenceController(mContext);
         when(mContext.getResources().getString(R.string.enterprise_privacy_input_method_name,
                 DEFAULT_IME_LABEL)).thenReturn(DEFAULT_IME_TEXT);
diff --git a/tests/robotests/src/com/android/settings/enterprise/ManageDeviceAdminPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/ManageDeviceAdminPreferenceControllerTest.java
index f46ecce..f656f10 100644
--- a/tests/robotests/src/com/android/settings/enterprise/ManageDeviceAdminPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/ManageDeviceAdminPreferenceControllerTest.java
@@ -16,13 +16,16 @@
 
 package com.android.settings.enterprise;
 
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.when;
+
 import android.content.Context;
 import android.support.v7.preference.Preference;
 
 import com.android.settings.R;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -32,9 +35,6 @@
 import org.mockito.MockitoAnnotations;
 import org.robolectric.annotation.Config;
 
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.when;
-
 /**
  * Tests for {@link ManageDeviceAdminPreferenceController}.
  */
@@ -51,8 +51,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mController = new ManageDeviceAdminPreferenceController(mContext);
     }
 
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
index 99b0945..338373b 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
@@ -17,7 +17,6 @@
 package com.android.settings.fuelgauge;
 
 import static com.google.common.truth.Truth.assertThat;
-
 import static org.mockito.ArgumentMatchers.nullable;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyInt;
@@ -45,14 +44,14 @@
 
 import com.android.internal.os.BatterySipper;
 import com.android.internal.os.BatteryStatsHelper;
+import com.android.settings.R;
 import com.android.settings.SettingsActivity;
-import com.android.settings.fuelgauge.anomaly.Anomaly;
-import com.android.settings.fuelgauge.anomaly.AnomalySummaryPreferenceController;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.applications.LayoutPreference;
-import com.android.settings.R;
+import com.android.settings.fuelgauge.anomaly.Anomaly;
+import com.android.settings.fuelgauge.anomaly.AnomalySummaryPreferenceController;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.testutils.shadow.ShadowActivityManager;
 import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
 import com.android.settings.widget.EntityHeaderController;
@@ -148,8 +147,7 @@
         MockitoAnnotations.initMocks(this);
 
         mContext = spy(RuntimeEnvironment.application);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
 
         mFragment = spy(new AdvancedPowerUsageDetail());
         doReturn(mContext).when(mFragment).getContext();
@@ -387,7 +385,7 @@
 
     @Test
     public void testStartBatteryDetailPage_batteryEntryNotExisted_extractUidFromPackageName() throws
-            PackageManager.NameNotFoundException{
+            PackageManager.NameNotFoundException {
         doReturn(UID).when(mPackageManager).getPackageUid(PACKAGE_NAME[0], 0 /* no flag */);
 
         AdvancedPowerUsageDetail.startBatteryDetailPage(mTestActivity, null, PACKAGE_NAME[0]);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/AppButtonsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/AppButtonsPreferenceControllerTest.java
index 5c28a06..acd9b97 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/AppButtonsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/AppButtonsPreferenceControllerTest.java
@@ -108,7 +108,7 @@
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
 
-        FakeFeatureFactory.setupForTest(mSettingsActivity);
+        FakeFeatureFactory.setupForTest();
         doReturn(mUserManager).when(mSettingsActivity).getSystemService(Context.USER_SERVICE);
         doReturn(mPackageManger).when(mSettingsActivity).getPackageManager();
         doReturn(mAm).when(mSettingsActivity).getSystemService(Context.ACTIVITY_SERVICE);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoLoaderTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoLoaderTest.java
index 5029897..ea0e6e5 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoLoaderTest.java
@@ -19,7 +19,6 @@
 import static com.google.common.truth.Truth.assertThat;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyLong;
-import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.when;
@@ -27,11 +26,13 @@
 import android.content.Context;
 import android.content.Intent;
 import android.os.BatteryStats;
+
 import com.android.internal.os.BatteryStatsHelper;
 import com.android.settings.TestConfig;
 import com.android.settings.testutils.BatteryTestUtils;
 import com.android.settings.testutils.FakeFeatureFactory;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -61,7 +62,7 @@
         MockitoAnnotations.initMocks(this);
         mContext = spy(RuntimeEnvironment.application);
         mProvider = FakeFeatureFactory
-                .setupForTest(mContext)
+                .setupForTest()
                 .getPowerUsageFeatureProvider(mContext);
 
         mDisChargingBatteryBroadcast = BatteryTestUtils.getDischargingIntent();
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
index dd6b709..4842b4e 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
@@ -87,7 +87,7 @@
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         mContext = spy(RuntimeEnvironment.application);
-        mFeatureFactory = FakeFeatureFactory.setupForTest(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
 
         mDisChargingBatteryBroadcast = BatteryTestUtils.getDischargingIntent();
 
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
index 56abf48..285ebc0 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
@@ -15,13 +15,32 @@
  */
 package com.android.settings.fuelgauge;
 
+import static android.os.BatteryStats.Uid.PROCESS_STATE_BACKGROUND;
+import static android.os.BatteryStats.Uid.PROCESS_STATE_FOREGROUND;
+import static android.os.BatteryStats.Uid.PROCESS_STATE_FOREGROUND_SERVICE;
+import static android.os.BatteryStats.Uid.PROCESS_STATE_TOP;
+import static android.os.BatteryStats.Uid.PROCESS_STATE_TOP_SLEEPING;
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
 import android.app.AppOpsManager;
 import android.content.Context;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
 import android.os.BatteryStats;
-import android.os.Bundle;
 import android.os.Build;
+import android.os.Bundle;
 import android.os.Process;
 import android.os.SystemClock;
 import android.os.UserManager;
@@ -30,10 +49,10 @@
 import com.android.internal.os.BatterySipper;
 import com.android.internal.os.BatteryStatsHelper;
 import com.android.settings.R;
-import com.android.settings.fuelgauge.anomaly.Anomaly;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
+import com.android.settings.fuelgauge.anomaly.Anomaly;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -47,27 +66,6 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import static android.os.BatteryStats.Uid.PROCESS_STATE_BACKGROUND;
-import static android.os.BatteryStats.Uid.PROCESS_STATE_FOREGROUND;
-import static android.os.BatteryStats.Uid.PROCESS_STATE_FOREGROUND_SERVICE;
-import static android.os.BatteryStats.Uid.PROCESS_STATE_TOP;
-import static android.os.BatteryStats.Uid.PROCESS_STATE_TOP_SLEEPING;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyLong;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.spy;
-
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class BatteryUtilsTest {
@@ -148,8 +146,7 @@
     public void setUp() {
         MockitoAnnotations.initMocks(this);
 
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mProvider = mFeatureFactory.powerUsageFeatureProvider;
 
         doReturn(TIME_STATE_TOP).when(mUid).getProcessStateTime(eq(PROCESS_STATE_TOP), anyLong(),
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/HighPowerDetailTest.java b/tests/robotests/src/com/android/settings/fuelgauge/HighPowerDetailTest.java
index fe3cd29..0b8832f 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/HighPowerDetailTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/HighPowerDetailTest.java
@@ -16,39 +16,35 @@
 
 package com.android.settings.fuelgauge;
 
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.verify;
+
 import android.content.Context;
 
 import com.android.internal.logging.nano.MetricsProto;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 
 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.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
 
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.verify;
-
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class HighPowerDetailTest {
 
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private Context mContext;
 
     private FakeFeatureFactory mFeatureFactory;
 
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mContext = RuntimeEnvironment.application;
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
index 5be2fe6..5ab7496 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
@@ -175,8 +175,7 @@
         MockitoAnnotations.initMocks(this);
 
         mRealContext = RuntimeEnvironment.application;
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         when(mContext.getSystemService(Context.POWER_SERVICE)).thenReturn(mPowerManager);
 
         mPreference = new PowerGaugePreference(mRealContext);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyDialogFragmentTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyDialogFragmentTest.java
index ccce08f..eea2256 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyDialogFragmentTest.java
@@ -99,7 +99,7 @@
                 .setPackageName(PACKAGE_NAME)
                 .setDisplayName(DISPLAY_NAME)
                 .build();
-        FakeFeatureFactory.setupForTest(mContext);
+        FakeFeatureFactory.setupForTest();
         ShadowRuntimePermissionPresenter.setRuntimePermissionPresenter(mRuntimePermissionPresenter);
     }
 
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyLoaderTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyLoaderTest.java
index dfb7d21..7193cca 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyLoaderTest.java
@@ -81,7 +81,7 @@
     public void setUp() throws PackageManager.NameNotFoundException {
         MockitoAnnotations.initMocks(this);
 
-        FakeFeatureFactory.setupForTest(mContext);
+        FakeFeatureFactory.setupForTest();
         doReturn(true).when(mAnomalyDetectionPolicy).isAnomalyDetectorEnabled(anyInt());
         doReturn(mUserManager).when(mContext).getSystemService(Context.USER_SERVICE);
         when(mContext.getPackageManager().getPackageUid(anyString(), anyInt())).thenReturn(UID);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/AnomalyActionTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/AnomalyActionTest.java
index 6f3e9b4..3f65a4c 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/AnomalyActionTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/AnomalyActionTest.java
@@ -57,8 +57,7 @@
     public void setUp() {
         MockitoAnnotations.initMocks(this);
 
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         doReturn(mAppOpsManagerr).when(mContext).getSystemService(Context.APP_OPS_SERVICE);
 
         mAnomaly = new Anomaly.Builder()
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/BackgroundCheckActionTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/BackgroundCheckActionTest.java
index e72039a..27f1b65 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/BackgroundCheckActionTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/BackgroundCheckActionTest.java
@@ -17,7 +17,6 @@
 package com.android.settings.fuelgauge.anomaly.action;
 
 import static com.google.common.truth.Truth.assertThat;
-
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.verify;
 
@@ -25,11 +24,11 @@
 import android.content.Context;
 import android.os.Build;
 
-import com.android.settings.fuelgauge.BatteryUtils;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
+import com.android.settings.fuelgauge.BatteryUtils;
 import com.android.settings.fuelgauge.anomaly.Anomaly;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -59,7 +58,7 @@
     public void setUp() {
         MockitoAnnotations.initMocks(this);
 
-        FakeFeatureFactory.setupForTest(mContext);
+        FakeFeatureFactory.setupForTest();
         doReturn(mAppOpsManager).when(mContext).getSystemService(Context.APP_OPS_SERVICE);
 
         mAnomaly = new Anomaly.Builder()
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/ForceStopActionTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/ForceStopActionTest.java
index fcb029c..351350a 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/ForceStopActionTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/ForceStopActionTest.java
@@ -17,7 +17,6 @@
 package com.android.settings.fuelgauge.anomaly.action;
 
 import static com.google.common.truth.Truth.assertThat;
-
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.verify;
 
@@ -26,10 +25,10 @@
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
 
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.fuelgauge.anomaly.Anomaly;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -59,7 +58,7 @@
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
 
-        FakeFeatureFactory.setupForTest(mContext);
+        FakeFeatureFactory.setupForTest();
         doReturn(mActivityManager).when(mContext).getSystemService(Context.ACTIVITY_SERVICE);
         doReturn(mPackageManager).when(mContext).getPackageManager();
         doReturn(mApplicationInfo).when(mPackageManager).getApplicationInfo(PACKAGE_NAME,
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/LocationCheckActionTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/LocationCheckActionTest.java
index d2b6fcb..7b76261 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/LocationCheckActionTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/LocationCheckActionTest.java
@@ -51,7 +51,7 @@
     @Before
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
+        FakeFeatureFactory.setupForTest();
         mLocationCheckAction = new LocationCheckAction(mContext, null);
         mAnomaly = new Anomaly.Builder()
                 .setType(Anomaly.AnomalyType.BLUETOOTH_SCAN)
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/StopAndBackgroundActionTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/StopAndBackgroundActionTest.java
index de7402b..544b54e 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/StopAndBackgroundActionTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/action/StopAndBackgroundActionTest.java
@@ -59,7 +59,7 @@
                 .setPackageName(PACKAGE_NAME)
                 .build();
 
-        FakeFeatureFactory.setupForTest(mContext);
+        FakeFeatureFactory.setupForTest();
         mStopAndBackgroundCheckAction = new StopAndBackgroundCheckAction(mContext, mForceStopAction,
                 mBackgroundCheckAction);
     }
diff --git a/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsPreferenceControllerTest.java
index 40c4af3..e2429c9 100644
--- a/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsPreferenceControllerTest.java
@@ -17,7 +17,6 @@
 package com.android.settings.gestures;
 
 import static com.google.common.truth.Truth.assertThat;
-
 import static org.mockito.Mockito.when;
 
 import android.content.ContentResolver;
@@ -44,9 +43,9 @@
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(
-    manifest = TestConfig.MANIFEST_PATH,
-    sdk = TestConfig.SDK_VERSION_O,
-    shadows = ShadowSecureSettings.class
+        manifest = TestConfig.MANIFEST_PATH,
+        sdk = TestConfig.SDK_VERSION_O,
+        shadows = ShadowSecureSettings.class
 )
 public class AssistGestureSettingsPreferenceControllerTest {
 
@@ -60,8 +59,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFactory = FakeFeatureFactory.setupForTest();
         mController = new AssistGestureSettingsPreferenceController(mContext, null, KEY_ASSIST,
                 false);
     }
diff --git a/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsTest.java b/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsTest.java
index b2bd27e..50cb611 100644
--- a/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsTest.java
@@ -31,8 +31,6 @@
 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.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
@@ -43,16 +41,14 @@
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class AssistGestureSettingsTest {
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private Context mContext;
+
     private FakeFeatureFactory mFakeFeatureFactory;
     private AssistGestureSettings mSettings;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFakeFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
         mSettings = new AssistGestureSettings();
     }
 
diff --git a/tests/robotests/src/com/android/settings/gestures/GesturesSettingsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/GesturesSettingsPreferenceControllerTest.java
index dcc06af..f0e1063 100644
--- a/tests/robotests/src/com/android/settings/gestures/GesturesSettingsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/GesturesSettingsPreferenceControllerTest.java
@@ -61,7 +61,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mActivity);
+        FakeFeatureFactory.setupForTest();
         mController = new GesturesSettingPreferenceController(mActivity);
     }
 
diff --git a/tests/robotests/src/com/android/settings/language/PhoneLanguagePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/language/PhoneLanguagePreferenceControllerTest.java
index 485efbe..137bba4 100644
--- a/tests/robotests/src/com/android/settings/language/PhoneLanguagePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/language/PhoneLanguagePreferenceControllerTest.java
@@ -52,21 +52,20 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mController = new PhoneLanguagePreferenceController(mContext);
     }
 
     @Test
     public void testIsAvailable_hasMultipleLocales_shouldReturnTrue() {
-        when(mContext.getAssets().getLocales()).thenReturn(new String[]{"en", "de"});
+        when(mContext.getAssets().getLocales()).thenReturn(new String[] {"en", "de"});
 
         assertThat(mController.isAvailable()).isTrue();
     }
 
     @Test
     public void testIsAvailable_hasSingleLocales_shouldReturnFalse() {
-        when(mContext.getAssets().getLocales()).thenReturn(new String[]{"en"});
+        when(mContext.getAssets().getLocales()).thenReturn(new String[] {"en"});
 
         assertThat(mController.isAvailable()).isFalse();
     }
diff --git a/tests/robotests/src/com/android/settings/language/UserDictionaryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/language/UserDictionaryPreferenceControllerTest.java
index 77d60cb..fd6a9c4 100644
--- a/tests/robotests/src/com/android/settings/language/UserDictionaryPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/language/UserDictionaryPreferenceControllerTest.java
@@ -50,7 +50,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
+        FakeFeatureFactory.setupForTest();
         mController = new TestController(mContext);
         mPreference = new Preference(ShadowApplication.getInstance().getApplicationContext());
     }
diff --git a/tests/robotests/src/com/android/settings/network/AirplaneModePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/AirplaneModePreferenceControllerTest.java
new file mode 100644
index 0000000..9dea6f5
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/network/AirplaneModePreferenceControllerTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.network;
+
+import static junit.framework.Assert.assertFalse;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.content.res.Resources;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+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.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class AirplaneModePreferenceControllerTest {
+
+    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+    private Context mContext;
+
+    @Mock
+    private Resources mResources;
+
+    @Mock
+    private PreferenceScreen mScreen;
+
+    @Mock
+    private PackageManager mPackageManager;
+
+    private AirplaneModePreferenceController mController;
+    private Lifecycle mLifecycle;
+    private FakeFeatureFactory mFactory;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mFactory = FakeFeatureFactory.setupForTest();
+        doReturn(mResources).when(mContext).getResources();
+        doReturn(mPackageManager).when(mContext).getPackageManager();
+        mController = spy(new AirplaneModePreferenceController(mContext, null));
+        mLifecycle = new Lifecycle(() -> mLifecycle);
+        mLifecycle.addObserver(mController);
+    }
+
+    @Test
+    public void airplaneModePreference_shouldNotBeAvailable_ifHasLeanbackFeature() {
+        when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)).thenReturn(true);
+        assertFalse(mController.isAvailable());
+
+        mController.displayPreference(mScreen);
+
+        // This should not crash
+        mController.onResume();
+        mController.onPause();
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/NotificationAccessSettingsTest.java b/tests/robotests/src/com/android/settings/notification/NotificationAccessSettingsTest.java
index 8e74e79..9709504 100644
--- a/tests/robotests/src/com/android/settings/notification/NotificationAccessSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/notification/NotificationAccessSettingsTest.java
@@ -23,15 +23,13 @@
 import android.content.Context;
 
 import com.android.internal.logging.nano.MetricsProto;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 
 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.annotation.Config;
 
@@ -39,17 +37,13 @@
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class NotificationAccessSettingsTest {
 
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private Context mContext;
-
     private FakeFeatureFactory mFeatureFactory;
     private NotificationAccessSettings mFragment;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mFragment = new NotificationAccessSettings();
     }
 
diff --git a/tests/robotests/src/com/android/settings/notification/ZenAccessSettingsTest.java b/tests/robotests/src/com/android/settings/notification/ZenAccessSettingsTest.java
index f65752f..5fe3154 100644
--- a/tests/robotests/src/com/android/settings/notification/ZenAccessSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ZenAccessSettingsTest.java
@@ -16,12 +16,16 @@
 
 package com.android.settings.notification;
 
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.verify;
+
 import android.content.Context;
 
 import com.android.internal.logging.nano.MetricsProto;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -31,10 +35,6 @@
 import org.mockito.MockitoAnnotations;
 import org.robolectric.annotation.Config;
 
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.verify;
-
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class ZenAccessSettingsTest {
@@ -47,8 +47,8 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeButtonPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeButtonPreferenceControllerTest.java
index a1b4dab..a6f7b2b 100644
--- a/tests/robotests/src/com/android/settings/notification/ZenModeButtonPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeButtonPreferenceControllerTest.java
@@ -130,4 +130,21 @@
         verify(mZenButtonOn).setVisibility(View.VISIBLE);
         verify(mZenButtonOff).setVisibility(View.GONE);
     }
+
+    @Test
+    public void updateState_otherUserChangedZen() {
+        final Preference mockPref = mock(Preference.class);
+        Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_OFF);
+        mController.updateState(mockPref);
+        verify(mZenButtonOn).setVisibility(View.VISIBLE);
+        verify(mZenButtonOff).setVisibility(View.GONE);
+
+        Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
+        final int GUEST_USER_ID = 10;
+        mController.mSettingObserver.onChange(false,
+                Settings.Global.getUriFor(Settings.Global.ZEN_MODE), GUEST_USER_ID);
+
+        verify(mZenButtonOn).setVisibility(View.GONE);
+        verify(mZenButtonOff).setVisibility(View.VISIBLE);
+    }
 }
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeCallsTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeCallsTest.java
index c495759..b7c122c 100644
--- a/tests/robotests/src/com/android/settings/notification/ZenModeCallsTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeCallsTest.java
@@ -59,7 +59,7 @@
         when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
         when(mActivity.getSystemService(Context.NOTIFICATION_SERVICE))
                 .thenReturn(mNotificationManager);
-        FakeFeatureFactory.setupForTest(mActivity);
+        FakeFeatureFactory.setupForTest();
 
         mCalls = new ZenModeCallsSettings();
         mCalls.onAttach((Context)mActivity);
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeMessagesTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeMessagesTest.java
index 03226f9..e924487 100644
--- a/tests/robotests/src/com/android/settings/notification/ZenModeMessagesTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeMessagesTest.java
@@ -59,7 +59,7 @@
         when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
         when(mActivity.getSystemService(Context.NOTIFICATION_SERVICE))
                 .thenReturn(mNotificationManager);
-        FakeFeatureFactory.setupForTest(mActivity);
+        FakeFeatureFactory.setupForTest();
 
         mMessages = new ZenModeMessagesSettings();
         mMessages.onAttach((Context)mActivity);
diff --git a/tests/robotests/src/com/android/settings/password/ChooseLockGenericControllerTest.java b/tests/robotests/src/com/android/settings/password/ChooseLockGenericControllerTest.java
index 28b0264..5b86374 100644
--- a/tests/robotests/src/com/android/settings/password/ChooseLockGenericControllerTest.java
+++ b/tests/robotests/src/com/android/settings/password/ChooseLockGenericControllerTest.java
@@ -47,7 +47,7 @@
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(
         manifest = TestConfig.MANIFEST_PATH,
-        sdk = TestConfig.SDK_VERSION,
+        sdk = TestConfig.SDK_VERSION_O,
         shadows = {
                 SettingsShadowResources.class
         })
diff --git a/tests/robotests/src/com/android/settings/password/ChooseLockPasswordTest.java b/tests/robotests/src/com/android/settings/password/ChooseLockPasswordTest.java
index b8f0679..12c6b99 100644
--- a/tests/robotests/src/com/android/settings/password/ChooseLockPasswordTest.java
+++ b/tests/robotests/src/com/android/settings/password/ChooseLockPasswordTest.java
@@ -31,6 +31,7 @@
 import com.android.settings.password.ChooseLockPassword.IntentBuilder;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.testutils.shadow.SettingsShadowResources;
+import com.android.settings.testutils.shadow.SettingsShadowResourcesImpl;
 import com.android.settings.testutils.shadow.ShadowEventLogWriter;
 import com.android.settings.testutils.shadow.ShadowUtils;
 import com.android.setupwizardlib.GlifLayout;
@@ -47,9 +48,10 @@
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(
         manifest = TestConfig.MANIFEST_PATH,
-        sdk = TestConfig.SDK_VERSION,
+        sdk = TestConfig.SDK_VERSION_O,
         shadows = {
                 SettingsShadowResources.class,
+                SettingsShadowResourcesImpl.class,
                 SettingsShadowResources.SettingsShadowTheme.class,
                 ShadowEventLogWriter.class,
                 ShadowUtils.class
diff --git a/tests/robotests/src/com/android/settings/password/ChooseLockPatternTest.java b/tests/robotests/src/com/android/settings/password/ChooseLockPatternTest.java
index c74448b..da3a157 100644
--- a/tests/robotests/src/com/android/settings/password/ChooseLockPatternTest.java
+++ b/tests/robotests/src/com/android/settings/password/ChooseLockPatternTest.java
@@ -29,6 +29,7 @@
 import com.android.settings.password.ChooseLockPattern.IntentBuilder;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.testutils.shadow.SettingsShadowResources;
+import com.android.settings.testutils.shadow.SettingsShadowResourcesImpl;
 import com.android.settings.testutils.shadow.ShadowEventLogWriter;
 import com.android.settings.testutils.shadow.ShadowUtils;
 import com.android.setupwizardlib.GlifLayout;
@@ -43,9 +44,10 @@
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(
         manifest = TestConfig.MANIFEST_PATH,
-        sdk = TestConfig.SDK_VERSION,
+        sdk = TestConfig.SDK_VERSION_O,
         shadows = {
                 SettingsShadowResources.class,
+                SettingsShadowResourcesImpl.class,
                 SettingsShadowResources.SettingsShadowTheme.class,
                 ShadowEventLogWriter.class,
                 ShadowUtils.class
diff --git a/tests/robotests/src/com/android/settings/password/ChooseLockSettingsHelperTest.java b/tests/robotests/src/com/android/settings/password/ChooseLockSettingsHelperTest.java
index 20a05e3..55e60e5 100644
--- a/tests/robotests/src/com/android/settings/password/ChooseLockSettingsHelperTest.java
+++ b/tests/robotests/src/com/android/settings/password/ChooseLockSettingsHelperTest.java
@@ -33,7 +33,7 @@
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(
         manifest = TestConfig.MANIFEST_PATH,
-        sdk = TestConfig.SDK_VERSION,
+        sdk = TestConfig.SDK_VERSION_O,
         shadows = {
                 ShadowUserManager.class,
                 ShadowUtils.class
diff --git a/tests/robotests/src/com/android/settings/password/ChooseLockTypeDialogFragmentTest.java b/tests/robotests/src/com/android/settings/password/ChooseLockTypeDialogFragmentTest.java
index 0a0734f..2d82e0e 100644
--- a/tests/robotests/src/com/android/settings/password/ChooseLockTypeDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/password/ChooseLockTypeDialogFragmentTest.java
@@ -49,7 +49,7 @@
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(
         manifest = TestConfig.MANIFEST_PATH,
-        sdk = TestConfig.SDK_VERSION,
+        sdk = TestConfig.SDK_VERSION_O,
         shadows = {
                 ShadowEventLogWriter.class,
                 ShadowUserManager.class,
diff --git a/tests/robotests/src/com/android/settings/password/ConfirmCredentialTest.java b/tests/robotests/src/com/android/settings/password/ConfirmCredentialTest.java
index d76968e..1568f19 100644
--- a/tests/robotests/src/com/android/settings/password/ConfirmCredentialTest.java
+++ b/tests/robotests/src/com/android/settings/password/ConfirmCredentialTest.java
@@ -35,7 +35,7 @@
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(
         manifest = TestConfig.MANIFEST_PATH,
-        sdk = TestConfig.SDK_VERSION,
+        sdk = TestConfig.SDK_VERSION_O,
         shadows = {
                 SettingsShadowResources.class,
                 SettingsShadowResources.SettingsShadowTheme.class,
diff --git a/tests/robotests/src/com/android/settings/password/ScreenLockTypeTest.java b/tests/robotests/src/com/android/settings/password/ScreenLockTypeTest.java
index 8beefa8..f8792a8 100644
--- a/tests/robotests/src/com/android/settings/password/ScreenLockTypeTest.java
+++ b/tests/robotests/src/com/android/settings/password/ScreenLockTypeTest.java
@@ -30,7 +30,7 @@
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(
         manifest = TestConfig.MANIFEST_PATH,
-        sdk = TestConfig.SDK_VERSION)
+        sdk = TestConfig.SDK_VERSION_O)
 public class ScreenLockTypeTest {
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/password/SetNewPasswordActivityTest.java b/tests/robotests/src/com/android/settings/password/SetNewPasswordActivityTest.java
index cb863a0..06086fc 100644
--- a/tests/robotests/src/com/android/settings/password/SetNewPasswordActivityTest.java
+++ b/tests/robotests/src/com/android/settings/password/SetNewPasswordActivityTest.java
@@ -38,7 +38,7 @@
 import org.robolectric.shadows.ShadowActivity;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SetNewPasswordActivityTest {
 
     private int mProvisioned;
diff --git a/tests/robotests/src/com/android/settings/password/SetNewPasswordControllerTest.java b/tests/robotests/src/com/android/settings/password/SetNewPasswordControllerTest.java
index 52678fb..a3f1787 100644
--- a/tests/robotests/src/com/android/settings/password/SetNewPasswordControllerTest.java
+++ b/tests/robotests/src/com/android/settings/password/SetNewPasswordControllerTest.java
@@ -57,7 +57,7 @@
  * Tests for {@link SetNewPasswordController}.
  */
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public final class SetNewPasswordControllerTest {
     private static final int CURRENT_USER_ID = 101;
     private static final long FINGERPRINT_CHALLENGE = -9876512313131L;
diff --git a/tests/robotests/src/com/android/settings/password/SetupChooseLockPasswordTest.java b/tests/robotests/src/com/android/settings/password/SetupChooseLockPasswordTest.java
index 1195a2c..97fffd5 100644
--- a/tests/robotests/src/com/android/settings/password/SetupChooseLockPasswordTest.java
+++ b/tests/robotests/src/com/android/settings/password/SetupChooseLockPasswordTest.java
@@ -34,6 +34,7 @@
 import com.android.settings.password.SetupChooseLockPassword.SetupChooseLockPasswordFragment;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.testutils.shadow.SettingsShadowResources;
+import com.android.settings.testutils.shadow.SettingsShadowResourcesImpl;
 import com.android.settings.testutils.shadow.ShadowEventLogWriter;
 import com.android.settings.testutils.shadow.ShadowUtils;
 
@@ -57,9 +58,10 @@
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(
         manifest = TestConfig.MANIFEST_PATH,
-        sdk = TestConfig.SDK_VERSION,
+        sdk = TestConfig.SDK_VERSION_O,
         shadows = {
                 SettingsShadowResources.class,
+                SettingsShadowResourcesImpl.class,
                 SettingsShadowResources.SettingsShadowTheme.class,
                 ShadowEventLogWriter.class,
                 ShadowUtils.class
diff --git a/tests/robotests/src/com/android/settings/password/SetupSkipDialogTest.java b/tests/robotests/src/com/android/settings/password/SetupSkipDialogTest.java
index 0e6f28a..6cd4244 100644
--- a/tests/robotests/src/com/android/settings/password/SetupSkipDialogTest.java
+++ b/tests/robotests/src/com/android/settings/password/SetupSkipDialogTest.java
@@ -40,7 +40,7 @@
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH,
-        sdk = TestConfig.SDK_VERSION,
+        sdk = TestConfig.SDK_VERSION_O,
         shadows = {
                 SettingsShadowResources.class,
                 SettingsShadowResources.SettingsShadowTheme.class,
diff --git a/tests/robotests/src/com/android/settings/search/AccessibilityServiceResultFutureTaskTest.java b/tests/robotests/src/com/android/settings/search/AccessibilityServiceResultFutureTaskTest.java
index 0e4abe1..456f820 100644
--- a/tests/robotests/src/com/android/settings/search/AccessibilityServiceResultFutureTaskTest.java
+++ b/tests/robotests/src/com/android/settings/search/AccessibilityServiceResultFutureTaskTest.java
@@ -28,6 +28,7 @@
 import android.content.pm.ServiceInfo;
 import android.graphics.Color;
 import android.graphics.drawable.ColorDrawable;
+import android.os.UserManager;
 import android.view.accessibility.AccessibilityManager;
 
 import com.android.settings.TestConfig;
@@ -46,7 +47,7 @@
 import java.util.List;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class AccessibilityServiceResultFutureTaskTest {
 
     private static final String QUERY = "test_query";
@@ -59,6 +60,8 @@
     private AccessibilityManager mAccessibilityManager;
     @Mock
     private SiteMapManager mSiteMapManager;
+    @Mock
+    private UserManager mUserManager;
 
     private AccessibilityServiceResultLoader.AccessibilityServiceResultCallable mCallable;
 
@@ -67,6 +70,7 @@
         MockitoAnnotations.initMocks(this);
         when(mContext.getSystemService(Context.ACCESSIBILITY_SERVICE))
                 .thenReturn(mAccessibilityManager);
+        when((Object)mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
         when(mContext.getPackageManager()).thenReturn(mPackageManager);
 
         mCallable = new AccessibilityServiceResultLoader.AccessibilityServiceResultCallable(
diff --git a/tests/robotests/src/com/android/settings/search/BaseSearchIndexProviderTest.java b/tests/robotests/src/com/android/settings/search/BaseSearchIndexProviderTest.java
index 6c6d7ab..4c19220 100644
--- a/tests/robotests/src/com/android/settings/search/BaseSearchIndexProviderTest.java
+++ b/tests/robotests/src/com/android/settings/search/BaseSearchIndexProviderTest.java
@@ -45,7 +45,7 @@
 import java.util.List;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class BaseSearchIndexProviderTest {
 
     private static final String TEST_PREF_KEY = "test_pref_key";
diff --git a/tests/robotests/src/com/android/settings/search/CursorToSearchResultConverterTest.java b/tests/robotests/src/com/android/settings/search/CursorToSearchResultConverterTest.java
index cd62c15..f862529 100644
--- a/tests/robotests/src/com/android/settings/search/CursorToSearchResultConverterTest.java
+++ b/tests/robotests/src/com/android/settings/search/CursorToSearchResultConverterTest.java
@@ -52,7 +52,7 @@
 import java.util.Set;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class CursorToSearchResultConverterTest {
 
     private static final List<String> TITLES = Arrays.asList("title1", "title2", "title3");
diff --git a/tests/robotests/src/com/android/settings/search/DatabaseIndexingManagerTest.java b/tests/robotests/src/com/android/settings/search/DatabaseIndexingManagerTest.java
index 20f58ad..b02543b 100644
--- a/tests/robotests/src/com/android/settings/search/DatabaseIndexingManagerTest.java
+++ b/tests/robotests/src/com/android/settings/search/DatabaseIndexingManagerTest.java
@@ -19,10 +19,10 @@
 
 import static com.google.common.truth.Truth.assertThat;
 import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyBoolean;
 import static org.mockito.Matchers.anyInt;
 import static org.mockito.Matchers.anyList;
 import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.anyBoolean;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
@@ -69,11 +69,11 @@
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(
-    manifest = TestConfig.MANIFEST_PATH,
-    sdk = TestConfig.SDK_VERSION,
-    shadows = {
-        ShadowRunnableAsyncTask.class,
-    }
+        manifest = TestConfig.MANIFEST_PATH,
+        sdk = TestConfig.SDK_VERSION_O,
+        shadows = {
+                ShadowRunnableAsyncTask.class,
+        }
 )
 public class DatabaseIndexingManagerTest {
     private final String localeStr = "en_US";
@@ -128,7 +128,7 @@
         doReturn(mPackageManager).when(mContext).getPackageManager();
         doReturn(FAKE_PROVIDER_LIST).when(mPackageManager)
                 .queryIntentContentProviders(any(Intent.class), anyInt());
-        FakeFeatureFactory.setupForTest(mContext);
+        FakeFeatureFactory.setupForTest();
     }
 
     @After
diff --git a/tests/robotests/src/com/android/settings/search/DatabaseIndexingUtilsTest.java b/tests/robotests/src/com/android/settings/search/DatabaseIndexingUtilsTest.java
index 94ce487..4b662b6 100644
--- a/tests/robotests/src/com/android/settings/search/DatabaseIndexingUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/search/DatabaseIndexingUtilsTest.java
@@ -35,7 +35,7 @@
 import java.util.Map;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class DatabaseIndexingUtilsTest {
 
     private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/search/InlineListPayloadTest.java b/tests/robotests/src/com/android/settings/search/InlineListPayloadTest.java
index fc15205..8194b12 100644
--- a/tests/robotests/src/com/android/settings/search/InlineListPayloadTest.java
+++ b/tests/robotests/src/com/android/settings/search/InlineListPayloadTest.java
@@ -14,7 +14,7 @@
 import static com.google.common.truth.Truth.assertThat;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class InlineListPayloadTest {
 
     private static final String DUMMY_SETTING = "inline_list_key";
diff --git a/tests/robotests/src/com/android/settings/search/InlinePayloadTest.java b/tests/robotests/src/com/android/settings/search/InlinePayloadTest.java
index 8bb558f..180e6a0 100644
--- a/tests/robotests/src/com/android/settings/search/InlinePayloadTest.java
+++ b/tests/robotests/src/com/android/settings/search/InlinePayloadTest.java
@@ -17,7 +17,7 @@
 import static com.google.common.truth.Truth.assertThat;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class InlinePayloadTest {
 
     private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/search/InlineSwitchPayloadTest.java b/tests/robotests/src/com/android/settings/search/InlineSwitchPayloadTest.java
index 64778a0..895bf9c 100644
--- a/tests/robotests/src/com/android/settings/search/InlineSwitchPayloadTest.java
+++ b/tests/robotests/src/com/android/settings/search/InlineSwitchPayloadTest.java
@@ -37,7 +37,7 @@
 import static com.google.common.truth.Truth.assertThat;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class InlineSwitchPayloadTest {
 
     private static final String DUMMY_SETTING = "inline_test";
diff --git a/tests/robotests/src/com/android/settings/search/InlineSwitchViewHolderTest.java b/tests/robotests/src/com/android/settings/search/InlineSwitchViewHolderTest.java
index 86aee6f..2ab24e2 100644
--- a/tests/robotests/src/com/android/settings/search/InlineSwitchViewHolderTest.java
+++ b/tests/robotests/src/com/android/settings/search/InlineSwitchViewHolderTest.java
@@ -33,7 +33,6 @@
 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.RuntimeEnvironment;
@@ -43,14 +42,12 @@
 import java.util.ArrayList;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class InlineSwitchViewHolderTest {
 
     private static final String TITLE = "title";
     private static final String SUMMARY = "summary";
 
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private Context mContext;
     @Mock
     private SearchFragment mFragment;
 
@@ -66,8 +63,7 @@
         MockitoAnnotations.initMocks(this);
         final Context context = RuntimeEnvironment.application;
         mIcon = context.getDrawable(R.drawable.ic_search_24dp);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
 
         mHolder = new InlineSwitchViewHolder(
                 LayoutInflater.from(context).inflate(R.layout.search_inline_switch_item, null),
diff --git a/tests/robotests/src/com/android/settings/search/InputDeviceResultFutureTaskTest.java b/tests/robotests/src/com/android/settings/search/InputDeviceResultFutureTaskTest.java
index e31b3d7..73fe52c 100644
--- a/tests/robotests/src/com/android/settings/search/InputDeviceResultFutureTaskTest.java
+++ b/tests/robotests/src/com/android/settings/search/InputDeviceResultFutureTaskTest.java
@@ -56,7 +56,7 @@
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH,
-        sdk = TestConfig.SDK_VERSION,
+        sdk = TestConfig.SDK_VERSION_O,
         shadows = {
                 ShadowInputDevice.class
         })
diff --git a/tests/robotests/src/com/android/settings/search/InstalledAppResultLoaderTest.java b/tests/robotests/src/com/android/settings/search/InstalledAppResultLoaderTest.java
index 0e84dc7..4dcd9b2 100644
--- a/tests/robotests/src/com/android/settings/search/InstalledAppResultLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/search/InstalledAppResultLoaderTest.java
@@ -19,9 +19,7 @@
 
 import static android.content.pm.ApplicationInfo.FLAG_SYSTEM;
 import static android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
-
 import static com.google.common.truth.Truth.assertThat;
-
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyInt;
 import static org.mockito.Matchers.anyList;
@@ -65,7 +63,7 @@
 import java.util.stream.Collectors;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class InstalledAppResultLoaderTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
@@ -83,7 +81,7 @@
     public void setUp() {
         MockitoAnnotations.initMocks(this);
 
-        final FakeFeatureFactory factory = FakeFeatureFactory.setupForTest(mContext);
+        final FakeFeatureFactory factory = FakeFeatureFactory.setupForTest();
         when(factory.searchFeatureProvider.getSiteMapManager())
                 .thenReturn(mSiteMapManager);
         final List<UserInfo> infos = new ArrayList<>();
@@ -127,7 +125,7 @@
                 mPackageManagerWrapper, query,
                 mSiteMapManager));
         when(mSiteMapManager.buildBreadCrumb(eq(mContext), anyString(), anyString()))
-                .thenReturn(Arrays.asList(new String[]{"123"}));
+                .thenReturn(Arrays.asList(new String[] {"123"}));
 
         assertThat(mCallable.call()).hasSize(3);
         verify(mSiteMapManager)
diff --git a/tests/robotests/src/com/android/settings/search/IntentSearchViewHolderTest.java b/tests/robotests/src/com/android/settings/search/IntentSearchViewHolderTest.java
index 4ec080c..f19da83 100644
--- a/tests/robotests/src/com/android/settings/search/IntentSearchViewHolderTest.java
+++ b/tests/robotests/src/com/android/settings/search/IntentSearchViewHolderTest.java
@@ -18,6 +18,7 @@
 package com.android.settings.search;
 
 import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.anyInt;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.doReturn;
@@ -32,6 +33,7 @@
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
+import android.graphics.drawable.ColorDrawable;
 import android.graphics.drawable.Drawable;
 import android.os.UserHandle;
 import android.view.LayoutInflater;
@@ -58,7 +60,7 @@
 import java.util.Objects;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class IntentSearchViewHolderTest {
 
     private static final String TITLE = "title";
@@ -75,20 +77,17 @@
     private FakeFeatureFactory mFeatureFactory;
     private IntentSearchViewHolder mHolder;
     private Drawable mIcon;
-    private Drawable mBadgedIcon;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
 
         final Context context = RuntimeEnvironment.application;
         final View view = LayoutInflater.from(context).inflate(R.layout.search_intent_item, null);
         mHolder = new IntentSearchViewHolder(view);
 
         mIcon = context.getDrawable(R.drawable.ic_search_24dp);
-        mBadgedIcon = context.getDrawable(R.drawable.ic_add);
         when(mFragment.getActivity().getPackageManager()).thenReturn(mPackageManager);
     }
 
@@ -189,6 +188,9 @@
 
     @Test
     public void testBindViewElements_appSearchResult() {
+        mHolder = spy(mHolder);
+        doReturn(new ColorDrawable(0)).when(mHolder).getBadgedIcon(any(ApplicationInfo.class),
+                anyInt());
         when(mPackageManager.getUserBadgedLabel(any(CharSequence.class),
                 eq(new UserHandle(USER_ID)))).thenReturn(BADGED_LABEL);
 
diff --git a/tests/robotests/src/com/android/settings/search/ResultPayloadTest.java b/tests/robotests/src/com/android/settings/search/ResultPayloadTest.java
index 0bb43c5..2d9d4aa 100644
--- a/tests/robotests/src/com/android/settings/search/ResultPayloadTest.java
+++ b/tests/robotests/src/com/android/settings/search/ResultPayloadTest.java
@@ -30,7 +30,7 @@
 import static com.google.common.truth.Truth.assertThat;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class ResultPayloadTest {
     private ResultPayload mPayload;
 
diff --git a/tests/robotests/src/com/android/settings/search/ResultPayloadUtilsTest.java b/tests/robotests/src/com/android/settings/search/ResultPayloadUtilsTest.java
index 50bdb84..a86089e 100644
--- a/tests/robotests/src/com/android/settings/search/ResultPayloadUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/search/ResultPayloadUtilsTest.java
@@ -30,7 +30,7 @@
 import static junit.framework.Assert.fail;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class ResultPayloadUtilsTest {
     private ResultPayload payload;
 
diff --git a/tests/robotests/src/com/android/settings/search/SavedQueryLoaderTest.java b/tests/robotests/src/com/android/settings/search/SavedQueryLoaderTest.java
index 780a8a5d..4142111 100644
--- a/tests/robotests/src/com/android/settings/search/SavedQueryLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/search/SavedQueryLoaderTest.java
@@ -38,7 +38,7 @@
 import static com.google.common.truth.Truth.assertThat;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SavedQueryLoaderTest {
 
     private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/search/SavedQueryPayloadTest.java b/tests/robotests/src/com/android/settings/search/SavedQueryPayloadTest.java
index 7421d1a..0845aa6 100644
--- a/tests/robotests/src/com/android/settings/search/SavedQueryPayloadTest.java
+++ b/tests/robotests/src/com/android/settings/search/SavedQueryPayloadTest.java
@@ -28,7 +28,7 @@
 import static com.google.common.truth.Truth.assertThat;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SavedQueryPayloadTest {
 
     private SavedQueryPayload mPayload;
diff --git a/tests/robotests/src/com/android/settings/search/SavedQueryRecorderAndRemoverTest.java b/tests/robotests/src/com/android/settings/search/SavedQueryRecorderAndRemoverTest.java
index af8cfe4..5e1de45 100644
--- a/tests/robotests/src/com/android/settings/search/SavedQueryRecorderAndRemoverTest.java
+++ b/tests/robotests/src/com/android/settings/search/SavedQueryRecorderAndRemoverTest.java
@@ -36,7 +36,7 @@
 import java.util.List;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SavedQueryRecorderAndRemoverTest {
 
     private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/search/SavedQueryViewHolderTest.java b/tests/robotests/src/com/android/settings/search/SavedQueryViewHolderTest.java
index bb8f6d1..0bb30e9 100644
--- a/tests/robotests/src/com/android/settings/search/SavedQueryViewHolderTest.java
+++ b/tests/robotests/src/com/android/settings/search/SavedQueryViewHolderTest.java
@@ -38,7 +38,7 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SavedQueryViewHolderTest {
 
     @Mock
diff --git a/tests/robotests/src/com/android/settings/search/SearchFragmentTest.java b/tests/robotests/src/com/android/settings/search/SearchFragmentTest.java
index a3f3334..014ca7c 100644
--- a/tests/robotests/src/com/android/settings/search/SearchFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/search/SearchFragmentTest.java
@@ -18,7 +18,6 @@
 package com.android.settings.search;
 
 import static com.google.common.truth.Truth.assertThat;
-
 import static org.mockito.ArgumentMatchers.nullable;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyInt;
@@ -28,14 +27,12 @@
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import android.app.LoaderManager;
 import android.content.Context;
 import android.content.Intent;
-import android.content.Loader;
 import android.os.Bundle;
 import android.util.Pair;
 import android.view.View;
@@ -54,7 +51,6 @@
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.mockito.Answers;
 import org.mockito.ArgumentMatcher;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
@@ -64,19 +60,14 @@
 import org.robolectric.annotation.Config;
 import org.robolectric.util.ReflectionHelpers;
 
-import java.util.List;
-
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH,
-        sdk = TestConfig.SDK_VERSION,
+        sdk = TestConfig.SDK_VERSION_O,
         shadows = {
                 SettingsShadowResources.class,
                 SettingsShadowResources.SettingsShadowTheme.class,
         })
 public class SearchFragmentTest {
-
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private Context mContext;
     @Mock
     private SearchResultLoader mSearchResultLoader;
     @Mock
@@ -92,7 +83,7 @@
     public void setUp() {
         MockitoAnnotations.initMocks(this);
 
-        mFeatureFactory = FakeFeatureFactory.setupForTest(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
     }
 
     @After
diff --git a/tests/robotests/src/com/android/settings/search/SearchIndexableResourcesTest.java b/tests/robotests/src/com/android/settings/search/SearchIndexableResourcesTest.java
index eedb324..90dba29 100644
--- a/tests/robotests/src/com/android/settings/search/SearchIndexableResourcesTest.java
+++ b/tests/robotests/src/com/android/settings/search/SearchIndexableResourcesTest.java
@@ -40,7 +40,7 @@
 import java.util.Set;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SearchIndexableResourcesTest {
 
     Set<Class> sProviderClassCopy;
diff --git a/tests/robotests/src/com/android/settings/search/SearchResultAggregatorTest.java b/tests/robotests/src/com/android/settings/search/SearchResultAggregatorTest.java
index 286d7cf9..babb6e4 100644
--- a/tests/robotests/src/com/android/settings/search/SearchResultAggregatorTest.java
+++ b/tests/robotests/src/com/android/settings/search/SearchResultAggregatorTest.java
@@ -1,7 +1,6 @@
 package com.android.settings.search;
 
 import static com.google.common.truth.Truth.assertThat;
-
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyLong;
 import static org.mockito.ArgumentMatchers.anyString;
@@ -31,7 +30,7 @@
 import java.util.concurrent.TimeUnit;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SearchResultAggregatorTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
@@ -63,8 +62,7 @@
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
         mAggregator = spy(SearchResultAggregator.getInstance());
-        FakeFeatureFactory.setupForTest(mContext);
-        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
 
         // Return mock loaders from feature provider
         when(mFeatureFactory.searchFeatureProvider.getStaticSearchResultTask(any(Context.class),
diff --git a/tests/robotests/src/com/android/settings/search/SearchResultBuilderTest.java b/tests/robotests/src/com/android/settings/search/SearchResultBuilderTest.java
index cd77b25..6d38aa8 100644
--- a/tests/robotests/src/com/android/settings/search/SearchResultBuilderTest.java
+++ b/tests/robotests/src/com/android/settings/search/SearchResultBuilderTest.java
@@ -37,7 +37,7 @@
 import java.util.ArrayList;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SearchResultBuilderTest {
 
     private static final String TITLE = "title";
diff --git a/tests/robotests/src/com/android/settings/search/SearchResultsAdapterTest.java b/tests/robotests/src/com/android/settings/search/SearchResultsAdapterTest.java
index 4baf8d2..1dad447 100644
--- a/tests/robotests/src/com/android/settings/search/SearchResultsAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/search/SearchResultsAdapterTest.java
@@ -46,7 +46,7 @@
 import java.util.Objects;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SearchResultsAdapterTest {
 
     @Mock
diff --git a/tests/robotests/src/com/android/settings/search/SettingsSearchIndexablesProviderTest.java b/tests/robotests/src/com/android/settings/search/SettingsSearchIndexablesProviderTest.java
index efeaed7..ac70a63 100644
--- a/tests/robotests/src/com/android/settings/search/SettingsSearchIndexablesProviderTest.java
+++ b/tests/robotests/src/com/android/settings/search/SettingsSearchIndexablesProviderTest.java
@@ -27,7 +27,7 @@
 import java.util.Set;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SettingsSearchIndexablesProviderTest {
 
     private final String BASE_AUTHORITY = "com.android.settings";
diff --git a/tests/robotests/src/com/android/settings/search/StaticSearchResultFutureTaskTest.java b/tests/robotests/src/com/android/settings/search/StaticSearchResultFutureTaskTest.java
index e285555..69795e7 100644
--- a/tests/robotests/src/com/android/settings/search/StaticSearchResultFutureTaskTest.java
+++ b/tests/robotests/src/com/android/settings/search/StaticSearchResultFutureTaskTest.java
@@ -17,6 +17,16 @@
 
 package com.android.settings.search;
 
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
 import android.content.ContentValues;
 import android.content.Context;
 import android.content.Intent;
@@ -35,7 +45,6 @@
 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.RuntimeEnvironment;
@@ -51,23 +60,10 @@
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyLong;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class StaticSearchResultFutureTaskTest {
 
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private Context mMockContext;
     @Mock
     private SiteMapManager mSiteMapManager;
     @Mock
@@ -86,7 +82,7 @@
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         mContext = RuntimeEnvironment.application;
-        mFeatureFactory = FakeFeatureFactory.setupForTest(mMockContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         when(mFeatureFactory.searchFeatureProvider.getExecutorService()).thenReturn(mService);
         when(mFeatureFactory.searchFeatureProvider.getSiteMapManager())
                 .thenReturn(mSiteMapManager);
diff --git a/tests/robotests/src/com/android/settings/search/XmlParserUtilTest.java b/tests/robotests/src/com/android/settings/search/XmlParserUtilTest.java
index 6050b32..4a9baa1 100644
--- a/tests/robotests/src/com/android/settings/search/XmlParserUtilTest.java
+++ b/tests/robotests/src/com/android/settings/search/XmlParserUtilTest.java
@@ -43,7 +43,7 @@
  * with another preference with a matchin replacement attribute.
  */
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class XmlParserUtilTest {
 
     private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/search/indexing/IndexDataConverterTest.java b/tests/robotests/src/com/android/settings/search/indexing/IndexDataConverterTest.java
index 0f2ab56..58003c4 100644
--- a/tests/robotests/src/com/android/settings/search/indexing/IndexDataConverterTest.java
+++ b/tests/robotests/src/com/android/settings/search/indexing/IndexDataConverterTest.java
@@ -46,7 +46,7 @@
 import static org.mockito.Mockito.spy;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, qualifiers = "mcc999")
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O, qualifiers = "mcc999")
 public class IndexDataConverterTest {
 
     private final String localeStr = "en_US";
diff --git a/tests/robotests/src/com/android/settings/search/indexing/IndexDataTest.java b/tests/robotests/src/com/android/settings/search/indexing/IndexDataTest.java
index 1a05a2b..9fe647a 100644
--- a/tests/robotests/src/com/android/settings/search/indexing/IndexDataTest.java
+++ b/tests/robotests/src/com/android/settings/search/indexing/IndexDataTest.java
@@ -36,7 +36,7 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class IndexDataTest {
     private IndexData.Builder mBuilder;
 
diff --git a/tests/robotests/src/com/android/settings/search/indexing/PreIndexDataCollectorTest.java b/tests/robotests/src/com/android/settings/search/indexing/PreIndexDataCollectorTest.java
index 2bb03cb..ef16a37 100644
--- a/tests/robotests/src/com/android/settings/search/indexing/PreIndexDataCollectorTest.java
+++ b/tests/robotests/src/com/android/settings/search/indexing/PreIndexDataCollectorTest.java
@@ -46,7 +46,7 @@
 import static org.mockito.Mockito.spy;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class PreIndexDataCollectorTest {
 
     private final String AUTHORITY_ONE = "authority";
diff --git a/tests/robotests/src/com/android/settings/security/ConfigureKeyGuardDialogTest.java b/tests/robotests/src/com/android/settings/security/ConfigureKeyGuardDialogTest.java
index ab7512f..df0cc2e 100644
--- a/tests/robotests/src/com/android/settings/security/ConfigureKeyGuardDialogTest.java
+++ b/tests/robotests/src/com/android/settings/security/ConfigureKeyGuardDialogTest.java
@@ -36,7 +36,7 @@
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(
     manifest = TestConfig.MANIFEST_PATH,
-    sdk = TestConfig.SDK_VERSION,
+    sdk = TestConfig.SDK_VERSION_O,
     shadows = ShadowEventLogWriter.class
 )
 public class ConfigureKeyGuardDialogTest {
diff --git a/tests/robotests/src/com/android/settings/security/EncryptionAndCredentialTest.java b/tests/robotests/src/com/android/settings/security/EncryptionAndCredentialTest.java
index 60e7dee..f5f0bb3 100644
--- a/tests/robotests/src/com/android/settings/security/EncryptionAndCredentialTest.java
+++ b/tests/robotests/src/com/android/settings/security/EncryptionAndCredentialTest.java
@@ -42,7 +42,7 @@
 import java.util.List;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class EncryptionAndCredentialTest {
 
     @Mock
diff --git a/tests/robotests/src/com/android/settings/security/LockscreenDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/security/LockscreenDashboardFragmentTest.java
index bb667f2..1a41c2d 100644
--- a/tests/robotests/src/com/android/settings/security/LockscreenDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/security/LockscreenDashboardFragmentTest.java
@@ -30,7 +30,7 @@
 import java.util.List;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class LockscreenDashboardFragmentTest {
 
     private LockscreenDashboardFragment mFragment;
diff --git a/tests/robotests/src/com/android/settings/security/OwnerInfoPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/OwnerInfoPreferenceControllerTest.java
index 71e2d8b..9bf8606 100644
--- a/tests/robotests/src/com/android/settings/security/OwnerInfoPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/security/OwnerInfoPreferenceControllerTest.java
@@ -16,13 +16,14 @@
 package com.android.settings.security;
 
 import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Answers.RETURNS_DEEP_STUBS;
+
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyInt;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
@@ -30,6 +31,7 @@
 import android.app.FragmentTransaction;
 import android.content.Context;
 import android.support.v14.preference.PreferenceFragment;
+import android.support.v7.preference.PreferenceManager;
 import android.support.v7.preference.PreferenceScreen;
 
 import com.android.internal.widget.LockPatternUtils;
@@ -49,14 +51,16 @@
 import org.robolectric.util.ReflectionHelpers;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class OwnerInfoPreferenceControllerTest {
 
-    @Mock(answer = RETURNS_DEEP_STUBS)
+    @Mock
     private PreferenceFragment mFragment;
     @Mock
     private PreferenceScreen mScreen;
     @Mock
+    private PreferenceManager mPreferenceManager;
+    @Mock
     private FragmentManager mFragmentManager;
     @Mock
     private FragmentTransaction mFragmentTransaction;
@@ -76,7 +80,8 @@
 
         when(mFragment.isAdded()).thenReturn(true);
         when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
-        when(mFragment.getPreferenceManager().getContext()).thenReturn(mContext);
+        when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
+        when(mPreference.getContext()).thenReturn(mContext);
         when(mFragment.getFragmentManager()).thenReturn(mFragmentManager);
         when(mFragmentManager.beginTransaction()).thenReturn(mFragmentTransaction);
 
@@ -187,7 +192,8 @@
 
         preference.performClick();
 
-        verify(mFragment).getFragmentManager();
+        // Called once in setTargetFragment, and a second time to display the fragment.
+        verify(mFragment, times(2)).getFragmentManager();
         verify(mFragment.getFragmentManager().beginTransaction())
                 .add(any(OwnerInfoSettings.class), anyString());
     }
diff --git a/tests/robotests/src/com/android/settings/security/SecurityFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/security/SecurityFeatureProviderImplTest.java
index 627ecf5..62ed3ab 100644
--- a/tests/robotests/src/com/android/settings/security/SecurityFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/security/SecurityFeatureProviderImplTest.java
@@ -53,7 +53,7 @@
 import org.robolectric.shadows.ShadowLooper;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SecurityFeatureProviderImplTest {
 
     private static final String MOCK_KEY = "key";
diff --git a/tests/robotests/src/com/android/settings/security/SecuritySettingsTest.java b/tests/robotests/src/com/android/settings/security/SecuritySettingsTest.java
index 827dd64..a1e264d 100644
--- a/tests/robotests/src/com/android/settings/security/SecuritySettingsTest.java
+++ b/tests/robotests/src/com/android/settings/security/SecuritySettingsTest.java
@@ -75,7 +75,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
+        FakeFeatureFactory.setupForTest();
         mSummaryProvider = new SecuritySettings.SummaryProvider(mContext, mSummaryLoader);
     }
 
diff --git a/tests/robotests/src/com/android/settings/suggestions/SettingsSuggestionsTest.java b/tests/robotests/src/com/android/settings/suggestions/SettingsSuggestionsTest.java
index 677bf41..4f0bee2 100644
--- a/tests/robotests/src/com/android/settings/suggestions/SettingsSuggestionsTest.java
+++ b/tests/robotests/src/com/android/settings/suggestions/SettingsSuggestionsTest.java
@@ -41,7 +41,7 @@
 import java.util.Map;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SettingsSuggestionsTest {
 
     private static final String CATEGORY_FIRST_IMPRESSION =
diff --git a/tests/robotests/src/com/android/settings/support/NewDeviceIntroSuggestionActivityTest.java b/tests/robotests/src/com/android/settings/support/NewDeviceIntroSuggestionActivityTest.java
index 5ad8500..92e1384 100644
--- a/tests/robotests/src/com/android/settings/support/NewDeviceIntroSuggestionActivityTest.java
+++ b/tests/robotests/src/com/android/settings/support/NewDeviceIntroSuggestionActivityTest.java
@@ -52,7 +52,7 @@
 import org.robolectric.shadows.ShadowPackageManager;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class NewDeviceIntroSuggestionActivityTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
@@ -65,7 +65,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        mFeatureFactory = FakeFeatureFactory.setupForTest(mMockContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mContext = application;
         mShadowPackageManager = Shadows.shadowOf(application.getPackageManager());
 
diff --git a/tests/robotests/src/com/android/settings/support/SupportConfigTest.java b/tests/robotests/src/com/android/settings/support/SupportConfigTest.java
index 28b0a9d..ae4fcff 100644
--- a/tests/robotests/src/com/android/settings/support/SupportConfigTest.java
+++ b/tests/robotests/src/com/android/settings/support/SupportConfigTest.java
@@ -28,7 +28,7 @@
 import static com.google.common.truth.Truth.assertThat;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SupportConfigTest {
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/support/SupportDashboardActivityTest.java b/tests/robotests/src/com/android/settings/support/SupportDashboardActivityTest.java
index 178e4ec..e7de81c 100644
--- a/tests/robotests/src/com/android/settings/support/SupportDashboardActivityTest.java
+++ b/tests/robotests/src/com/android/settings/support/SupportDashboardActivityTest.java
@@ -40,7 +40,7 @@
 import java.util.List;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SupportDashboardActivityTest {
 
     private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/support/SupportDisclaimerDialogFragmentTest.java b/tests/robotests/src/com/android/settings/support/SupportDisclaimerDialogFragmentTest.java
index 31c654c..8aacb52 100644
--- a/tests/robotests/src/com/android/settings/support/SupportDisclaimerDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/support/SupportDisclaimerDialogFragmentTest.java
@@ -1,5 +1,13 @@
 package com.android.settings.support;
 
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.robolectric.shadow.api.Shadow.directlyOn;
+
 import android.accounts.Account;
 import android.annotation.NonNull;
 import android.annotation.StringRes;
@@ -10,16 +18,18 @@
 import android.text.Spannable;
 import android.text.style.URLSpan;
 import android.widget.CheckBox;
+
 import com.android.internal.logging.nano.MetricsProto;
 import com.android.settings.R;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
 import com.android.settings.overlay.SupportFeatureProvider;
 import com.android.settings.overlay.SupportFeatureProvider.SupportType;
 import com.android.settings.support.SupportDisclaimerDialogFragmentTest.SupportDisclaimerShadowResources;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.testutils.shadow.SettingsShadowResources;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -31,16 +41,8 @@
 import org.robolectric.annotation.Implements;
 import org.robolectric.util.FragmentTestUtil;
 
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.robolectric.shadow.api.Shadow.directlyOn;
-
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
         shadows = {SupportDisclaimerShadowResources.class})
 public class SupportDisclaimerDialogFragmentTest {
 
@@ -57,8 +59,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mContext);
-        mFakeFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
         mMetricsFeatureProvider = mFakeFeatureFactory.getMetricsFeatureProvider();
         mSupportFeatureProvider = mFakeFeatureFactory.getSupportFeatureProvider(mContext);
         when(mSupportFeatureProvider.getDisclaimerStringResId())
diff --git a/tests/robotests/src/com/android/settings/survey/SurveyMixinTest.java b/tests/robotests/src/com/android/settings/survey/SurveyMixinTest.java
index 116b63c..f8c7247 100644
--- a/tests/robotests/src/com/android/settings/survey/SurveyMixinTest.java
+++ b/tests/robotests/src/com/android/settings/survey/SurveyMixinTest.java
@@ -14,13 +14,13 @@
 import android.content.Context;
 import android.content.IntentFilter;
 import android.support.v4.content.LocalBroadcastManager;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
 import com.android.settings.TestConfig;
 import com.android.settings.core.InstrumentedPreferenceFragment;
 import com.android.settings.overlay.SurveyFeatureProvider;
 import com.android.settings.testutils.FakeFeatureFactory;
-import java.util.ArrayList;
-import java.util.HashMap;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -31,8 +31,11 @@
 import org.robolectric.annotation.Config;
 import org.robolectric.util.ReflectionHelpers;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SurveyMixinTest {
 
     private static final String FAKE_KEY = "fake_key";
@@ -51,8 +54,7 @@
         // set up the fakefeature factory to mock out the survey provider
         MockitoAnnotations.initMocks(this);
         mContext = spy(RuntimeEnvironment.application.getApplicationContext());
-        FakeFeatureFactory.setupForTest(mContext);
-        mFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFactory = FakeFeatureFactory.setupForTest();
         mProvider = mFactory.getSurveyFeatureProvider(mContext);
         when(mProvider.getSurveyId(any(), eq(FAKE_KEY))).thenReturn(FAKE_SURVEY_ID);
     }
diff --git a/tests/robotests/src/com/android/settings/system/FactoryResetPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/system/FactoryResetPreferenceControllerTest.java
index b986e4f..7ae6cdb 100644
--- a/tests/robotests/src/com/android/settings/system/FactoryResetPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/system/FactoryResetPreferenceControllerTest.java
@@ -39,7 +39,7 @@
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(
     manifest = TestConfig.MANIFEST_PATH,
-    sdk = TestConfig.SDK_VERSION,
+    sdk = TestConfig.SDK_VERSION_O,
     shadows = {ShadowSecureSettings.class, ShadowUtils.class}
 )
 public class FactoryResetPreferenceControllerTest {
diff --git a/tests/robotests/src/com/android/settings/system/SystemDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/system/SystemDashboardFragmentTest.java
index cd25953..8a1951a 100644
--- a/tests/robotests/src/com/android/settings/system/SystemDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/system/SystemDashboardFragmentTest.java
@@ -41,7 +41,7 @@
 import java.util.List;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
         shadows = {
                 ShadowUserManager.class,
                 SettingsShadowResources.class,
diff --git a/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java b/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java
index dd5c76a..5430e9b 100644
--- a/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java
+++ b/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java
@@ -66,11 +66,9 @@
 
     /**
      * Call this in {@code @Before} method of the test class to use fake factory.
-     *
-     * @param context The context must be a deep mock.
      */
-    @Deprecated
-    public static FakeFeatureFactory setupForTest(Context context) {
+    public static FakeFeatureFactory setupForTest() {
+        final Context context = mock(Context.class, Answers.RETURNS_DEEP_STUBS);
         sFactory = null;
         when(context.getString(com.android.settings.R.string.config_featureFactory))
                 .thenReturn(FakeFeatureFactory.class.getName());
@@ -84,14 +82,6 @@
     }
 
     /**
-     * Call this in {@code @Before} method of the test class to use fake factory.
-     */
-    public static FakeFeatureFactory setupForTest() {
-        final Context context = mock(Context.class, Answers.RETURNS_DEEP_STUBS);
-        return setupForTest(context);
-    }
-
-    /**
      * Used by reflection. Do not call directly.
      */
     public FakeFeatureFactory() {
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowBidiFormatter.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowBidiFormatter.java
new file mode 100644
index 0000000..66d7338
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowBidiFormatter.java
@@ -0,0 +1,31 @@
+/*
+ * 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.testutils.shadow;
+
+import android.support.v4.text.BidiFormatter;
+import android.support.v4.text.TextDirectionHeuristicCompat;
+
+import org.robolectric.annotation.Implements;
+
+@Implements(BidiFormatter.class)
+public class ShadowBidiFormatter {
+
+    public CharSequence unicodeWrap(CharSequence str, TextDirectionHeuristicCompat heuristic,
+            boolean isolate) {
+        return str;
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/users/UserFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/users/UserFeatureProviderImplTest.java
index e1bc157..8c10c31 100644
--- a/tests/robotests/src/com/android/settings/users/UserFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/users/UserFeatureProviderImplTest.java
@@ -37,7 +37,7 @@
 import static org.mockito.Mockito.when;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class UserFeatureProviderImplTest {
     public static final int FIRST_USER_ID = 0;
     public static final int SECOND_USER_ID = 4;
diff --git a/tests/robotests/src/com/android/settings/users/UserPreferenceTest.java b/tests/robotests/src/com/android/settings/users/UserPreferenceTest.java
index 5b31a82..242604a 100644
--- a/tests/robotests/src/com/android/settings/users/UserPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/users/UserPreferenceTest.java
@@ -38,7 +38,7 @@
 import org.robolectric.util.ReflectionHelpers;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class UserPreferenceTest {
 
     @Mock
diff --git a/tests/robotests/src/com/android/settings/users/UserSettingsTest.java b/tests/robotests/src/com/android/settings/users/UserSettingsTest.java
index 56f3949..28b8c86 100644
--- a/tests/robotests/src/com/android/settings/users/UserSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/users/UserSettingsTest.java
@@ -40,7 +40,7 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class UserSettingsTest {
 
     @Mock private UserManager mUserManager;
diff --git a/tests/robotests/src/com/android/settings/utils/LocalClassLoaderContextThemeWrapperTest.java b/tests/robotests/src/com/android/settings/utils/LocalClassLoaderContextThemeWrapperTest.java
index 690c292..ac6dc02 100644
--- a/tests/robotests/src/com/android/settings/utils/LocalClassLoaderContextThemeWrapperTest.java
+++ b/tests/robotests/src/com/android/settings/utils/LocalClassLoaderContextThemeWrapperTest.java
@@ -32,7 +32,7 @@
 import static com.google.common.truth.Truth.assertThat;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class LocalClassLoaderContextThemeWrapperTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/vpn2/AppDialogFragmentTest.java b/tests/robotests/src/com/android/settings/vpn2/AppDialogFragmentTest.java
index 4b4f3fb..587a82a 100644
--- a/tests/robotests/src/com/android/settings/vpn2/AppDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/vpn2/AppDialogFragmentTest.java
@@ -33,7 +33,7 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class AppDialogFragmentTest {
 
     @Mock
diff --git a/tests/robotests/src/com/android/settings/vpn2/VpnUtilsTest.java b/tests/robotests/src/com/android/settings/vpn2/VpnUtilsTest.java
index 9442892..5a029c7 100644
--- a/tests/robotests/src/com/android/settings/vpn2/VpnUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/vpn2/VpnUtilsTest.java
@@ -32,7 +32,7 @@
  * Tests for {@link VpnUtils}.
  */
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public final class VpnUtilsTest {
     @Test
     public void testIsAlwaysOnVpnSet() {
diff --git a/tests/robotests/src/com/android/settings/webview/WebViewAppPickerTest.java b/tests/robotests/src/com/android/settings/webview/WebViewAppPickerTest.java
index 470b69c..d06980b 100644
--- a/tests/robotests/src/com/android/settings/webview/WebViewAppPickerTest.java
+++ b/tests/robotests/src/com/android/settings/webview/WebViewAppPickerTest.java
@@ -17,7 +17,9 @@
 package com.android.settings.webview;
 
 import static android.provider.Settings.ACTION_WEBVIEW_SETTINGS;
+
 import static com.google.common.truth.Truth.assertThat;
+
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyInt;
 import static org.mockito.Matchers.eq;
@@ -43,7 +45,6 @@
 import com.android.settings.TestConfig;
 import com.android.settings.applications.defaultapps.DefaultAppInfo;
 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
-import com.android.settings.testutils.FakeFeatureFactory;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.widget.RadioButtonPreference;
 import com.android.settings.wrapper.UserPackageWrapper;
@@ -62,16 +63,16 @@
 import java.util.Arrays;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class WebViewAppPickerTest {
-    private Context mContext = RuntimeEnvironment.application;
+    private Context mContext;
 
     private UserInfo mFirstUser;
     private UserInfo mSecondUser;
 
     private final static String DEFAULT_PACKAGE_NAME = "DEFAULT_PACKAGE_NAME";
 
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+    @Mock
     private Activity mActivity;
     @Mock
     private UserManager mUserManager;
@@ -90,8 +91,8 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mActivity);
-        when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
+        mContext = spy(RuntimeEnvironment.application);
+        doReturn(mUserManager).when(mContext).getSystemService(Context.USER_SERVICE);
         mFirstUser = new UserInfo(0, "FIRST_USER", 0);
         mSecondUser = new UserInfo(0, "SECOND_USER", 0);
         mPicker = new WebViewAppPicker();
@@ -168,7 +169,7 @@
     @Test
     public void testDisabledPackageShownAsDisabled() {
         String disabledReason = "disabled";
-        DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mActivity, mPackageManager,
+        DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mContext, mPackageManager,
                 createApplicationInfo(DEFAULT_PACKAGE_NAME), disabledReason);
 
         RadioButtonPreference mockPreference = mock(RadioButtonPreference.class);
@@ -183,7 +184,7 @@
     @Test
     public void testEnabledPackageShownAsEnabled() {
         String disabledReason = "";
-        DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mActivity, mPackageManager,
+        DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mContext, mPackageManager,
                 createApplicationInfo(DEFAULT_PACKAGE_NAME), disabledReason);
 
         RadioButtonPreference mockPreference = mock(RadioButtonPreference.class);
@@ -198,7 +199,7 @@
     @Test
     public void testDisabledPackageShowsDisabledReasonSummary() {
         String disabledReason = "disabled";
-        DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mActivity, mPackageManager,
+        DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mContext, mPackageManager,
                 createApplicationInfo(DEFAULT_PACKAGE_NAME), disabledReason);
 
         RadioButtonPreference mockPreference = mock(RadioButtonPreference.class);
@@ -214,7 +215,7 @@
     @Test
     public void testEnabledPackageShowsEmptySummary() {
         String disabledReason = null;
-        DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mActivity, mPackageManager,
+        DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mContext, mPackageManager,
                 createApplicationInfo(DEFAULT_PACKAGE_NAME), disabledReason);
 
         RadioButtonPreference mockPreference = mock(RadioButtonPreference.class);
@@ -228,14 +229,14 @@
     @Test
     public void testFinishIfNotAdmin() {
         doReturn(false).when(mUserManager).isAdminUser();
-        mPicker.onAttach((Context) mActivity);
+        mPicker.onAttach(mContext);
         verify(mActivity, times(1)).finish();
     }
 
     @Test
     public void testNotFinishedIfAdmin() {
         doReturn(true).when(mUserManager).isAdminUser();
-        mPicker.onAttach((Context) mActivity);
+        mPicker.onAttach(mContext);
         verify(mActivity, never()).finish();
     }
 
@@ -348,7 +349,7 @@
         PackageItemInfo mockPackageItemInfo = mock(PackageItemInfo.class);
         mockPackageItemInfo.packageName = DEFAULT_PACKAGE_NAME;
         when(mockPackageItemInfo.loadLabel(any())).thenReturn("myPackage");
-        DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mActivity, mPackageManager,
+        DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mContext, mPackageManager,
                 mockPackageItemInfo, "" /* disabledReason */);
 
         PackageInfo packageInfo = new PackageInfo();
diff --git a/tests/robotests/src/com/android/settings/webview/WebViewAppPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/webview/WebViewAppPreferenceControllerTest.java
deleted file mode 100644
index 9404e53..0000000
--- a/tests/robotests/src/com/android/settings/webview/WebViewAppPreferenceControllerTest.java
+++ /dev/null
@@ -1,62 +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.webview;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.mock;
-
-import android.content.Context;
-import android.support.v7.preference.Preference;
-
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
-import com.android.settings.TestConfig;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.annotation.Config;
-
-/**
- * Deprecated in favor of {@link com.android.settings.development.WebViewAppPreferenceController}
- */
-@Deprecated
-@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
-public class WebViewAppPreferenceControllerTest {
-    @Mock
-    private Context mContext;
-
-    private WebViewAppPreferenceController mController;
-
-    private static final String DEFAULT_PACKAGE_NAME = "DEFAULT_PACKAGE_NAME";
-
-    @Before
-    public void setUp() {
-        MockitoAnnotations.initMocks(this);
-        mController = new WebViewAppPreferenceController(mContext);
-    }
-
-    @Test
-    public void testIsAlwaysAvailable() {
-        assertThat(mController.isAvailable()).isTrue();
-    }
-
-    @Test
-    public void testNeverHandlesClick() {
-        assertThat(mController.handlePreferenceTreeClick(mock(Preference.class))).isFalse();
-    }
-}
diff --git a/tests/robotests/src/com/android/settings/wfd/WifiDisplaySettingsTest.java b/tests/robotests/src/com/android/settings/wfd/WifiDisplaySettingsTest.java
index 7d8ee52..a65bd3b 100644
--- a/tests/robotests/src/com/android/settings/wfd/WifiDisplaySettingsTest.java
+++ b/tests/robotests/src/com/android/settings/wfd/WifiDisplaySettingsTest.java
@@ -42,7 +42,7 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class WifiDisplaySettingsTest {
 
     @Mock
diff --git a/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java b/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java
index af30e4f..842f53c 100644
--- a/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java
@@ -16,6 +16,15 @@
 
 package com.android.settings.widget;
 
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
 import android.app.ActionBar;
 import android.app.Activity;
 import android.app.Fragment;
@@ -48,15 +57,6 @@
 import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
 
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class EntityHeaderControllerTest {
@@ -77,7 +77,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        mFeatureFactory = FakeFeatureFactory.setupForTest(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mShadowContext = RuntimeEnvironment.application;
         when(mActivity.getApplicationContext()).thenReturn(mShadowContext);
         when(mContext.getApplicationContext()).thenReturn(mContext);
diff --git a/tests/robotests/src/com/android/settings/widget/RadioButtonPickerFragmentTest.java b/tests/robotests/src/com/android/settings/widget/RadioButtonPickerFragmentTest.java
index 9fc5b2e..b4b86f6 100644
--- a/tests/robotests/src/com/android/settings/widget/RadioButtonPickerFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/widget/RadioButtonPickerFragmentTest.java
@@ -61,7 +61,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mActivity);
+        FakeFeatureFactory.setupForTest();
         mFragment = spy(new TestFragment());
 
         when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
diff --git a/tests/robotests/src/com/android/settings/wifi/CellularFallbackPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/CellularFallbackPreferenceControllerTest.java
index 415cd92..84d73c1 100644
--- a/tests/robotests/src/com/android/settings/wifi/CellularFallbackPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/CellularFallbackPreferenceControllerTest.java
@@ -34,7 +34,7 @@
 import static org.mockito.Mockito.when;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class CellularFallbackPreferenceControllerTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/wifi/ConfigureWifiSettingsTest.java b/tests/robotests/src/com/android/settings/wifi/ConfigureWifiSettingsTest.java
index 687287b..3cd5ee8 100644
--- a/tests/robotests/src/com/android/settings/wifi/ConfigureWifiSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/ConfigureWifiSettingsTest.java
@@ -23,7 +23,7 @@
 import java.util.List;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class ConfigureWifiSettingsTest {
 
     private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/wifi/ConnectedAccessPointPreferenceTest.java b/tests/robotests/src/com/android/settings/wifi/ConnectedAccessPointPreferenceTest.java
index 2eaa587..5a38c4e 100644
--- a/tests/robotests/src/com/android/settings/wifi/ConnectedAccessPointPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/ConnectedAccessPointPreferenceTest.java
@@ -37,7 +37,7 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class ConnectedAccessPointPreferenceTest {
     @Mock
     private AccessPoint mAccessPoint;
diff --git a/tests/robotests/src/com/android/settings/wifi/LinkablePreferenceTest.java b/tests/robotests/src/com/android/settings/wifi/LinkablePreferenceTest.java
index 9321827..f8d8428 100644
--- a/tests/robotests/src/com/android/settings/wifi/LinkablePreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/LinkablePreferenceTest.java
@@ -38,7 +38,7 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class LinkablePreferenceTest {
 
     private static final String TITLE = "Title";
diff --git a/tests/robotests/src/com/android/settings/wifi/NotifyOpenNetworkPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/NotifyOpenNetworkPreferenceControllerTest.java
index b83a3e3..f1299f4 100644
--- a/tests/robotests/src/com/android/settings/wifi/NotifyOpenNetworkPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/NotifyOpenNetworkPreferenceControllerTest.java
@@ -40,7 +40,7 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class NotifyOpenNetworkPreferenceControllerTest {
 
     private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/wifi/SavedAccessPointsWifiSettingsTest.java b/tests/robotests/src/com/android/settings/wifi/SavedAccessPointsWifiSettingsTest.java
index ec406cd..d157615 100644
--- a/tests/robotests/src/com/android/settings/wifi/SavedAccessPointsWifiSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/SavedAccessPointsWifiSettingsTest.java
@@ -37,7 +37,7 @@
 import static org.mockito.Mockito.*;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SavedAccessPointsWifiSettingsTest {
 
     @Mock private WifiManagerWrapper mockWifiManager;
diff --git a/tests/robotests/src/com/android/settings/wifi/UseOpenWifiPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/UseOpenWifiPreferenceControllerTest.java
index 16d883a..851c4c2 100644
--- a/tests/robotests/src/com/android/settings/wifi/UseOpenWifiPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/UseOpenWifiPreferenceControllerTest.java
@@ -58,7 +58,7 @@
 import java.util.List;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class UseOpenWifiPreferenceControllerTest {
     private static ComponentName sEnableActivityComponent;
     private static NetworkScorerAppData sAppData;
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java
index e9b6146..7cef9ce 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java
@@ -41,7 +41,7 @@
 import static org.mockito.Mockito.*;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
         shadows = ShadowConnectivityManager.class)
 public class WifiConfigControllerTest {
 
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiDialogTest.java b/tests/robotests/src/com/android/settings/wifi/WifiDialogTest.java
index 00941ad..1460c33 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiDialogTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiDialogTest.java
@@ -21,7 +21,7 @@
 
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
         shadows = ShadowEntityHeaderController.class)
 public class WifiDialogTest {
     @Mock private AccessPoint mockAccessPoint;
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiEnablerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiEnablerTest.java
index 63f89e6..b9dbae5 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiEnablerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiEnablerTest.java
@@ -38,7 +38,7 @@
 import static org.mockito.Mockito.when;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class WifiEnablerTest {
 
     @Mock
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiInfoPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiInfoPreferenceControllerTest.java
index cf3cca7..7582143 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiInfoPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiInfoPreferenceControllerTest.java
@@ -46,7 +46,7 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class WifiInfoPreferenceControllerTest {
 
     @Mock
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiMasterSwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiMasterSwitchPreferenceControllerTest.java
index 307cccb..425f17d 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiMasterSwitchPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiMasterSwitchPreferenceControllerTest.java
@@ -16,6 +16,12 @@
 
 package com.android.settings.wifi;
 
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.IntentFilter;
@@ -23,33 +29,24 @@
 import android.support.v7.preference.Preference.OnPreferenceChangeListener;
 import android.support.v7.preference.PreferenceScreen;
 
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.widget.MasterSwitchPreference;
 
 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.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
 
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class WifiMasterSwitchPreferenceControllerTest {
 
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    Context mMockContext;
     @Mock
     private WifiManager mWifiManager;
     @Mock
@@ -65,8 +62,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mMockContext);
-        mFakeFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mMockContext);
+        mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
         mMetricsFeatureProvider = mFakeFeatureFactory.getMetricsFeatureProvider();
         mContext = spy(RuntimeEnvironment.application.getApplicationContext());
         mController = new WifiMasterSwitchPreferenceController(mContext, mMetricsFeatureProvider);
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiSummaryUpdaterTest.java b/tests/robotests/src/com/android/settings/wifi/WifiSummaryUpdaterTest.java
index 4507e54..a9757bd 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiSummaryUpdaterTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiSummaryUpdaterTest.java
@@ -44,7 +44,7 @@
 import static org.mockito.Mockito.verify;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class WifiSummaryUpdaterTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiUtilsTest.java b/tests/robotests/src/com/android/settings/wifi/WifiUtilsTest.java
index 1ccdb1f..3cdcee4 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiUtilsTest.java
@@ -27,7 +27,7 @@
 import static com.google.common.truth.Truth.assertThat;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class WifiUtilsTest {
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java
index 29df539..07f2d30 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java
@@ -46,7 +46,7 @@
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(
         manifest = TestConfig.MANIFEST_PATH,
-        sdk = TestConfig.SDK_VERSION,
+        sdk = TestConfig.SDK_VERSION_O,
         shadows = { SettingsShadowResources.class })
 public class WifiWakeupPreferenceControllerTest {
 
diff --git a/tests/robotests/src/com/android/settings/wifi/WpsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WpsPreferenceControllerTest.java
index 7a734e5..21488e8 100644
--- a/tests/robotests/src/com/android/settings/wifi/WpsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WpsPreferenceControllerTest.java
@@ -48,7 +48,7 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class WpsPreferenceControllerTest {
 
     @Mock
diff --git a/tests/robotests/src/com/android/settings/wifi/WriteWifiConfigToNfcDialogTest.java b/tests/robotests/src/com/android/settings/wifi/WriteWifiConfigToNfcDialogTest.java
index 5e10e0f..4fc118a 100644
--- a/tests/robotests/src/com/android/settings/wifi/WriteWifiConfigToNfcDialogTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WriteWifiConfigToNfcDialogTest.java
@@ -42,7 +42,7 @@
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(
         manifest = TestConfig.MANIFEST_PATH,
-        sdk = TestConfig.SDK_VERSION,
+        sdk = TestConfig.SDK_VERSION_O,
         shadows = ShadowNfcAdapter.class
 )
 public class WriteWifiConfigToNfcDialogTest {
diff --git a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java
index 3a0341c..64d9f59 100644
--- a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java
@@ -66,6 +66,7 @@
 import com.android.settings.applications.LayoutPreference;
 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.ShadowBidiFormatter;
 import com.android.settings.testutils.shadow.ShadowDevicePolicyManagerWrapper;
 import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
 import com.android.settings.testutils.shadow.ShadowPackageManagerWrapper;
@@ -97,11 +98,12 @@
 import java.util.stream.Collectors;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
         shadows = {
                 ShadowDevicePolicyManagerWrapper.class,
                 ShadowEntityHeaderController.class,
                 ShadowPackageManagerWrapper.class,
+                ShadowBidiFormatter.class
         })
 public class WifiDetailPreferenceControllerTest {
 
diff --git a/tests/robotests/src/com/android/settings/wifi/p2p/P2pThisDevicePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/p2p/P2pThisDevicePreferenceControllerTest.java
index 62fd01f..02017f7 100644
--- a/tests/robotests/src/com/android/settings/wifi/p2p/P2pThisDevicePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/p2p/P2pThisDevicePreferenceControllerTest.java
@@ -37,7 +37,7 @@
 import static org.mockito.Mockito.when;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class P2pThisDevicePreferenceControllerTest {
 
     @Mock
diff --git a/tests/robotests/src/com/android/settings/wifi/p2p/WifiP2PPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/p2p/WifiP2PPreferenceControllerTest.java
index e809431..0b8d27a 100644
--- a/tests/robotests/src/com/android/settings/wifi/p2p/WifiP2PPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/p2p/WifiP2PPreferenceControllerTest.java
@@ -47,7 +47,7 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class WifiP2PPreferenceControllerTest {
 
     @Mock
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 44c70f6..48b5379 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java
@@ -18,9 +18,7 @@
 
 import static android.arch.lifecycle.Lifecycle.Event.ON_START;
 import static android.arch.lifecycle.Lifecycle.Event.ON_STOP;
-
 import static com.google.common.truth.Truth.assertThat;
-
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Matchers.eq;
@@ -50,7 +48,6 @@
 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.RuntimeEnvironment;
@@ -70,8 +67,6 @@
         })
 public class WifiTetherPreferenceControllerTest {
 
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private Context mFeatureFactoryContext;
     @Mock
     private Context mContext;
     @Mock
@@ -89,14 +84,14 @@
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         mLifecycle = new Lifecycle(() -> mLifecycle);
-        FakeFeatureFactory.setupForTest(mFeatureFactoryContext);
+        FakeFeatureFactory.setupForTest();
         mPreference = new MasterSwitchPreference(RuntimeEnvironment.application);
         when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
                 .thenReturn(mConnectivityManager);
         when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
         when(mScreen.findPreference(anyString())).thenReturn(mPreference);
 
-        when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
+        when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[] {"1", "2"});
         mController = new WifiTetherPreferenceController(mContext, mLifecycle);
     }
 
@@ -107,7 +102,7 @@
 
     @Test
     public void isAvailable_noTetherRegex_shouldReturnFalse() {
-        when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{});
+        when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[] {});
         mController = new WifiTetherPreferenceController(mContext, mLifecycle);
 
         assertThat(mController.isAvailable()).isFalse();
@@ -272,6 +267,7 @@
     /**
      * Helper to cause the controller to receive a WIFI_AP_STATE_CHANGED_ACTION with a specific
      * state.
+     *
      * @param state - the state, as specified by one of the WifiManager.WIFI_AP_STATE_* values
      */
     private void receiveApStateChangedBroadcast(int state) {
diff --git a/tests/unit/src/com/android/settings/connecteddevice/ConnectedDeviceActivityTest.java b/tests/unit/src/com/android/settings/connecteddevice/ConnectedDeviceActivityTest.java
new file mode 100644
index 0000000..4be8a39
--- /dev/null
+++ b/tests/unit/src/com/android/settings/connecteddevice/ConnectedDeviceActivityTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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.connecteddevice;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.app.Instrumentation;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+import android.text.TextUtils;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.List;
+
+@RunWith(AndroidJUnit4.class)
+@SmallTest
+public class ConnectedDeviceActivityTest {
+    private static final String INTENT_ACTION = "android.intent.action.MAIN";
+    private static final String CONNECTED_DEVICE_TITLE = "Connected devices";
+
+    private Instrumentation mInstrumentation;
+
+    @Before
+    public void setUp() throws Exception {
+        mInstrumentation = InstrumentationRegistry.getInstrumentation();
+    }
+
+    @Test
+    public void queryConnectedDeviceActivity_onlyOneResponse() {
+        final PackageManager packageManager = mInstrumentation.getContext().getPackageManager();
+        final Intent intent = new Intent(INTENT_ACTION);
+
+        int count = 0;
+        final List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(intent,
+                PackageManager.GET_META_DATA);
+        for (ResolveInfo info : resolveInfoList) {
+            if (TextUtils.equals(info.activityInfo.loadLabel(packageManager).toString(),
+                    CONNECTED_DEVICE_TITLE)) {
+                count++;
+            }
+        }
+
+        assertThat(count).isEqualTo(1);
+    }
+
+}