Merge "Fix unit test for PreferenceController"
diff --git a/res/drawable-hdpi/empty_search_results.png b/res/drawable-hdpi/empty_search_results.png
deleted file mode 100644
index 6202a33..0000000
--- a/res/drawable-hdpi/empty_search_results.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-mdpi/empty_search_results.png b/res/drawable-mdpi/empty_search_results.png
deleted file mode 100644
index e418d7c..0000000
--- a/res/drawable-mdpi/empty_search_results.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xhdpi/empty_search_results.png b/res/drawable-xhdpi/empty_search_results.png
deleted file mode 100644
index a92f000..0000000
--- a/res/drawable-xhdpi/empty_search_results.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xxhdpi/empty_search_results.png b/res/drawable-xxhdpi/empty_search_results.png
deleted file mode 100644
index 4c549bc..0000000
--- a/res/drawable-xxhdpi/empty_search_results.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xxxhdpi/empty_search_results.png b/res/drawable-xxxhdpi/empty_search_results.png
deleted file mode 100644
index 1aed6ad..0000000
--- a/res/drawable-xxxhdpi/empty_search_results.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable/empty_search_results.xml b/res/drawable/empty_search_results.xml
new file mode 100644
index 0000000..9162107
--- /dev/null
+++ b/res/drawable/empty_search_results.xml
@@ -0,0 +1,30 @@
+<?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.
+  -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="96dp"
+    android:height="96dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24"
+    android:tint="?android:attr/colorControlNormal">
+
+    <path
+        android:fillColor="#000000"
+        android:pathData="M15.5,14h-0.79l-0.28-0.27c1.2-1.4,1.82-3.31,1.48-5.34c-0.47-2.78-2.79-5-5.59-5.34c-4.23-0.52-7.79,3.04-7.27,7.27
+c0.34,2.8,2.56,5.12,5.34,5.59c2.03,0.34,3.94-0.28,5.34-1.48L14,14.71v0.79l5.2,5.19c0.41,0.41,1.07,0.41,1.48,0l0.01-0.01
+c0.41-0.41,0.41-1.07,0-1.48L15.5,14z M9.5,14C7.01,14,5,11.99,5,9.5S7.01,5,9.5,5S14,7.01,14,9.5S11.99,14,9.5,14z" />
+</vector>
\ No newline at end of file
diff --git a/res/layout/search_panel.xml b/res/layout/search_panel.xml
index 42fbefb..10c2a00 100644
--- a/res/layout/search_panel.xml
+++ b/res/layout/search_panel.xml
@@ -85,8 +85,8 @@
                 android:layout_height="?android:attr/actionBarSize"/>
 
             <ImageView
-                android:layout_height="160dp"
-                android:layout_width="160dp"
+                android:layout_height="wrap_content"
+                android:layout_width="wrap_content"
                 android:layout_gravity="center_horizontal"
                 android:src="@drawable/empty_search_results"/>
 
diff --git a/res/layout/settings_main_dashboard.xml b/res/layout/settings_main_dashboard.xml
index 7c34803..269bc3c 100644
--- a/res/layout/settings_main_dashboard.xml
+++ b/res/layout/settings_main_dashboard.xml
@@ -32,7 +32,7 @@
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_margin="@dimen/search_bar_margin"
-            app:cardCornerRadius="@dimen/search_bar_half_height"
+            app:cardCornerRadius="@dimen/search_bar_corner_radius"
             app:cardBackgroundColor="?android:attr/colorBackground"
             app:cardElevation="2dp">
             <Toolbar
diff --git a/res/layout/support_escalation_options.xml b/res/layout/support_escalation_options.xml
index 17e03ff..ae208f1 100644
--- a/res/layout/support_escalation_options.xml
+++ b/res/layout/support_escalation_options.xml
@@ -65,7 +65,7 @@
             android:orientation="vertical">
             <Button
                 android:id="@android:id/text1"
-                style="@style/SupportPrimaryButton"
+                style="@style/ActionPrimaryButton"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_margin="8dp"/>
@@ -86,7 +86,7 @@
             android:orientation="vertical">
             <Button
                 android:id="@android:id/text2"
-                style="@style/SupportPrimaryButton"
+                style="@style/ActionPrimaryButton"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_margin="8dp"/>
diff --git a/res/layout/support_offline_escalation_options.xml b/res/layout/support_offline_escalation_options.xml
index 18d8f98..09863d3 100644
--- a/res/layout/support_offline_escalation_options.xml
+++ b/res/layout/support_offline_escalation_options.xml
@@ -56,7 +56,7 @@
     </LinearLayout>
     <Button
         android:id="@android:id/text1"
-        style="@style/SupportPrimaryButton"
+        style="@style/ActionPrimaryButton"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_margin="8dp"
diff --git a/res/layout/support_sign_in_button.xml b/res/layout/support_sign_in_button.xml
index 45de571..5bea068 100644
--- a/res/layout/support_sign_in_button.xml
+++ b/res/layout/support_sign_in_button.xml
@@ -38,7 +38,7 @@
         android:textColor="?android:attr/textColorSecondary"/>
     <Button
         android:id="@android:id/text1"
-        style="@style/SupportPrimaryButton"
+        style="@style/ActionPrimaryButton"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_margin="8dp"/>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 2f00297..ef4d269 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -121,7 +121,7 @@
     <dimen name="search_bar_negative_margin">-8dp</dimen>
 
     <dimen name="search_bar_height">48dp</dimen>
-    <dimen name="search_bar_half_height">24dp</dimen>
+    <dimen name="search_bar_corner_radius">2dp</dimen>
     <dimen name="search_bar_text_size">16dp</dimen>
 
     <!-- Dimensions for Wifi Assistant Card -->
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 7c43e99..c68eb72 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -338,8 +338,6 @@
 
     <style name="TextAppearance.SupportSummary" parent="TextAppearance.CategoryTitle"/>
 
-    <style name="SupportPrimaryButton" parent="android:Widget.DeviceDefault.Button.Colored"/>
-
     <style name="SupportSecondaryButton"
            parent="android:Widget.DeviceDefault.Button.Borderless.Colored">
         <item name="android:textSize">12sp</item>
diff --git a/res/xml/connected_devices.xml b/res/xml/connected_devices.xml
index d24dd51..497a485 100644
--- a/res/xml/connected_devices.xml
+++ b/res/xml/connected_devices.xml
@@ -22,4 +22,8 @@
     <PreferenceCategory
         android:key="connected_device_list"
         android:title="@string/connected_device_connected_title"/>
+
+    <PreferenceCategory
+        android:key="saved_device_list"
+        android:title="@string/connected_device_saved_title"/>
 </PreferenceScreen>
diff --git a/res/xml/wifi_display_settings.xml b/res/xml/wifi_display_settings.xml
index 2be31d2..7ad214e 100644
--- a/res/xml/wifi_display_settings.xml
+++ b/res/xml/wifi_display_settings.xml
@@ -14,7 +14,9 @@
      limitations under the License.
 -->
 
-<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+<PreferenceScreen
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:key="wifi_display_settings_screen"
     android:title="@string/wifi_display_settings_title">
 
 </PreferenceScreen>
diff --git a/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java
index e053bc9..127730b 100644
--- a/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java
+++ b/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java
@@ -149,9 +149,22 @@
     }
 
     /**
+     * Return {@code true} if {@code cachedBluetoothDevice} matches this
+     * {@link BluetoothDeviceUpdater} and should stay in the list, otherwise return {@code false}
+     */
+    public abstract boolean isFilterMatched(CachedBluetoothDevice cachedBluetoothDevice);
+
+    /**
      * Update whether to show {@cde cachedBluetoothDevice} in the list.
      */
-    abstract public void update(CachedBluetoothDevice cachedBluetoothDevice);
+    protected void update(CachedBluetoothDevice cachedBluetoothDevice) {
+        if (isFilterMatched(cachedBluetoothDevice)) {
+            // Add the preference if it is new one
+            addPreference(cachedBluetoothDevice);
+        } else {
+            removePreference(cachedBluetoothDevice);
+        }
+    }
 
     /**
      * Add the {@link Preference} that represents the {@code cachedDevice}
diff --git a/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java
index 239e405..deab29f 100644
--- a/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java
+++ b/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java
@@ -51,16 +51,8 @@
     }
 
     @Override
-    public void update(CachedBluetoothDevice cachedDevice) {
+    public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) {
         final BluetoothDevice device = cachedDevice.getDevice();
-        final boolean filterMatch =
-                device.getBondState() == BluetoothDevice.BOND_BONDED && device.isConnected();
-
-        if (filterMatch) {
-            // Add the preference if it is new one
-            addPreference(cachedDevice);
-        } else {
-            removePreference(cachedDevice);
-        }
+        return device.getBondState() == BluetoothDevice.BOND_BONDED && device.isConnected();
     }
 }
diff --git a/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdater.java
new file mode 100644
index 0000000..da7679a
--- /dev/null
+++ b/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdater.java
@@ -0,0 +1,58 @@
+/*
+ * 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.bluetooth;
+
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.support.annotation.VisibleForTesting;
+
+import com.android.settings.connecteddevice.DevicePreferenceCallback;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+import com.android.settingslib.bluetooth.LocalBluetoothManager;
+
+/**
+ * Maintain and update saved bluetooth devices(bonded but not connected)
+ */
+public class SavedBluetoothDeviceUpdater extends BluetoothDeviceUpdater {
+
+    public SavedBluetoothDeviceUpdater(DashboardFragment fragment,
+            DevicePreferenceCallback devicePreferenceCallback) {
+        super(fragment, devicePreferenceCallback);
+    }
+
+    @VisibleForTesting
+    SavedBluetoothDeviceUpdater(DashboardFragment fragment,
+            DevicePreferenceCallback devicePreferenceCallback,
+            LocalBluetoothManager localBluetoothManager) {
+        super(fragment, devicePreferenceCallback, localBluetoothManager);
+    }
+
+    @Override
+    public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) {
+        if (state == BluetoothAdapter.STATE_CONNECTED) {
+            removePreference(cachedDevice);
+        } else if (state == BluetoothAdapter.STATE_DISCONNECTED) {
+            addPreference(cachedDevice);
+        }
+    }
+
+    @Override
+    public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) {
+        final BluetoothDevice device = cachedDevice.getDevice();
+        return device.getBondState() == BluetoothDevice.BOND_BONDED && !device.isConnected();
+    }
+}
diff --git a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
index 14acd89..8b0e568 100644
--- a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
+++ b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
@@ -62,9 +62,8 @@
         final List<AbstractPreferenceController> controllers = new ArrayList<>();
         final Lifecycle lifecycle = getLifecycle();
 
-        final ConnectedDeviceGroupController connectedDeviceGroupController =
-                new ConnectedDeviceGroupController(this, lifecycle);
-        controllers.add(connectedDeviceGroupController);
+        controllers.add(new ConnectedDeviceGroupController(this, lifecycle));
+        controllers.add(new SavedDeviceGroupController(this, lifecycle));
         return controllers;
 
     }
diff --git a/src/com/android/settings/connecteddevice/SavedDeviceGroupController.java b/src/com/android/settings/connecteddevice/SavedDeviceGroupController.java
new file mode 100644
index 0000000..7445047
--- /dev/null
+++ b/src/com/android/settings/connecteddevice/SavedDeviceGroupController.java
@@ -0,0 +1,109 @@
+/*
+ * 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.support.annotation.VisibleForTesting;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceGroup;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.bluetooth.BluetoothDeviceUpdater;
+import com.android.settings.bluetooth.SavedBluetoothDeviceUpdater;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnStart;
+import com.android.settingslib.core.lifecycle.events.OnStop;
+
+/**
+ * Controller to maintain the {@link PreferenceGroup} for all
+ * saved devices. It uses {@link DevicePreferenceCallback} to add/remove {@link Preference}
+ */
+public class SavedDeviceGroupController extends AbstractPreferenceController
+        implements PreferenceControllerMixin, LifecycleObserver, OnStart, OnStop,
+        DevicePreferenceCallback {
+
+    private static final String KEY = "saved_device_list";
+
+    @VisibleForTesting
+    PreferenceGroup mPreferenceGroup;
+    private BluetoothDeviceUpdater mBluetoothDeviceUpdater;
+
+    public SavedDeviceGroupController(DashboardFragment fragment, Lifecycle lifecycle) {
+        super(fragment.getContext());
+        init(lifecycle, new SavedBluetoothDeviceUpdater(fragment, SavedDeviceGroupController.this));
+    }
+
+    @VisibleForTesting
+    SavedDeviceGroupController(DashboardFragment fragment, Lifecycle lifecycle,
+            BluetoothDeviceUpdater bluetoothDeviceUpdater) {
+        super(fragment.getContext());
+        init(lifecycle, bluetoothDeviceUpdater);
+    }
+
+    @Override
+    public void onStart() {
+        mBluetoothDeviceUpdater.registerCallback();
+    }
+
+    @Override
+    public void onStop() {
+        mBluetoothDeviceUpdater.unregisterCallback();
+    }
+
+    @Override
+    public void displayPreference(PreferenceScreen screen) {
+        mPreferenceGroup = (PreferenceGroup) screen.findPreference(KEY);
+        mPreferenceGroup.setVisible(false);
+        mBluetoothDeviceUpdater.setPrefContext(screen.getContext());
+        mBluetoothDeviceUpdater.forceUpdate();
+    }
+
+    @Override
+    public boolean isAvailable() {
+        return true;
+    }
+
+    @Override
+    public String getPreferenceKey() {
+        return KEY;
+    }
+
+    @Override
+    public void onDeviceAdded(Preference preference) {
+        if (mPreferenceGroup.getPreferenceCount() == 0) {
+            mPreferenceGroup.setVisible(true);
+        }
+        mPreferenceGroup.addPreference(preference);
+    }
+
+    @Override
+    public void onDeviceRemoved(Preference preference) {
+        mPreferenceGroup.removePreference(preference);
+        if (mPreferenceGroup.getPreferenceCount() == 0) {
+            mPreferenceGroup.setVisible(false);
+        }
+    }
+
+    private void init(Lifecycle lifecycle, BluetoothDeviceUpdater bluetoothDeviceUpdater) {
+        if (lifecycle != null) {
+            lifecycle.addObserver(this);
+        }
+        mBluetoothDeviceUpdater = bluetoothDeviceUpdater;
+    }
+}
diff --git a/src/com/android/settings/dashboard/DashboardAdapter.java b/src/com/android/settings/dashboard/DashboardAdapter.java
index fd2adac..54a1eeb 100644
--- a/src/com/android/settings/dashboard/DashboardAdapter.java
+++ b/src/com/android/settings/dashboard/DashboardAdapter.java
@@ -477,7 +477,7 @@
         final int tintColor = a.getColor(0, mContext.getColor(R.color.fallback_tintColor));
         a.recycle();
         if (category != null) {
-            for (Tile tile : category.tiles) {
+            for (Tile tile : category.getTiles()) {
                 if (tile.isIconTintable) {
                     // If this drawable is tintable, tint it to match the color.
                     tile.icon.setTint(tintColor);
diff --git a/src/com/android/settings/dashboard/DashboardData.java b/src/com/android/settings/dashboard/DashboardData.java
index a14b8c2..6407960 100644
--- a/src/com/android/settings/dashboard/DashboardData.java
+++ b/src/com/android/settings/dashboard/DashboardData.java
@@ -268,8 +268,9 @@
                         && hiddenSuggestion == 0);
 
         if (mCategory != null) {
-            for (int j = 0; j < mCategory.tiles.size(); j++) {
-                final Tile tile = mCategory.tiles.get(j);
+            final List<Tile> tiles = mCategory.getTiles();
+            for (int j = 0; j < tiles.size(); j++) {
+                final Tile tile = tiles.get(j);
                 addToItemList(tile, R.layout.dashboard_tile, Objects.hash(tile.title),
                         true /* add */);
             }
diff --git a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
index bee822a..9ef38b8 100644
--- a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
+++ b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
@@ -91,7 +91,7 @@
             Log.d(TAG, "NO dashboard tiles for " + TAG);
             return null;
         }
-        final List<Tile> tiles = category.tiles;
+        final List<Tile> tiles = category.getTiles();
         if (tiles == null || tiles.isEmpty()) {
             Log.d(TAG, "tile list is empty, skipping category " + category.title);
             return null;
diff --git a/src/com/android/settings/dashboard/DashboardFragment.java b/src/com/android/settings/dashboard/DashboardFragment.java
index 3551d23..3e1e881 100644
--- a/src/com/android/settings/dashboard/DashboardFragment.java
+++ b/src/com/android/settings/dashboard/DashboardFragment.java
@@ -307,7 +307,7 @@
             Log.d(TAG, "NO dashboard tiles for " + TAG);
             return;
         }
-        List<Tile> tiles = category.tiles;
+        final List<Tile> tiles = category.getTiles();
         if (tiles == null) {
             Log.d(TAG, "tile list is empty, skipping category " + category.title);
             return;
diff --git a/src/com/android/settings/dashboard/SiteMapManager.java b/src/com/android/settings/dashboard/SiteMapManager.java
index 50d7a18..b54e061 100644
--- a/src/com/android/settings/dashboard/SiteMapManager.java
+++ b/src/com/android/settings/dashboard/SiteMapManager.java
@@ -154,7 +154,7 @@
                 continue;
             }
             // Build parent-child mPairs for all children listed under this key.
-            for (Tile tile : category.tiles) {
+            for (Tile tile : category.getTiles()) {
                 final String childTitle = tile.title.toString();
                 String childClass = null;
                 if (tile.metaData != null) {
diff --git a/src/com/android/settings/dashboard/SummaryLoader.java b/src/com/android/settings/dashboard/SummaryLoader.java
index fe55be8..5af276c 100644
--- a/src/com/android/settings/dashboard/SummaryLoader.java
+++ b/src/com/android/settings/dashboard/SummaryLoader.java
@@ -216,7 +216,7 @@
         if (category == null) {
             return;
         }
-        for (Tile tile : category.tiles) {
+        for (Tile tile : category.getTiles()) {
             final String key = mDashboardFeatureProvider.getDashboardKeyForTile(tile);
             if (mSummaryTextMap.containsKey(key)) {
                 tile.summary = mSummaryTextMap.get(key);
@@ -250,12 +250,13 @@
     }
 
     private Tile getTileFromCategory(DashboardCategory category, ComponentName component) {
-        if (category == null || category.tiles == null) {
+        if (category == null || category.getTilesCount() == 0) {
             return null;
         }
-        final int tileCount = category.tiles.size();
+        final List<Tile> tiles = category.getTiles();
+        final int tileCount = tiles.size();
         for (int j = 0; j < tileCount; j++) {
-            final Tile tile = category.tiles.get(j);
+            final Tile tile = tiles.get(j);
             if (component.equals(tile.intent.getComponent())) {
                 return tile;
             }
@@ -291,10 +292,10 @@
                 case MSG_GET_CATEGORY_TILES_AND_SET_LISTENING:
                     final DashboardCategory category =
                             mDashboardFeatureProvider.getTilesForCategory(mCategoryKey);
-                    if (category == null || category.tiles == null) {
+                    if (category == null || category.getTilesCount() == 0) {
                         return;
                     }
-                    final List<Tile> tiles = category.tiles;
+                    final List<Tile> tiles = category.getTiles();
                     for (Tile tile : tiles) {
                         makeProviderW(tile);
                     }
diff --git a/src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceController.java b/src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceController.java
index 2fb538e..9132daa 100644
--- a/src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceController.java
+++ b/src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceController.java
@@ -21,6 +21,7 @@
 import android.provider.Settings;
 import android.support.v14.preference.SwitchPreference;
 import android.support.v7.preference.Preference;
+import android.support.annotation.VisibleForTesting;
 
 import com.android.internal.hardware.AmbientDisplayConfiguration;
 import com.android.settings.R;
@@ -81,7 +82,7 @@
 
     @Override
     public boolean isAvailable() {
-        return isAvailable(mConfig);
+        return alwaysOnAvailableForUser(mConfig);
     }
 
     public static boolean isAvailable(AmbientDisplayConfiguration config) {
@@ -102,4 +103,9 @@
                 ResultPayload.SettingsSource.SECURE, ON /* onValue */, intent, isAvailable(),
                 ON /* defaultValue */);
     }
+
+    @VisibleForTesting
+    boolean alwaysOnAvailableForUser(AmbientDisplayConfiguration config) {
+        return isAvailable(config);
+    }
 }
diff --git a/src/com/android/settings/notification/ZenModeAutomationSettings.java b/src/com/android/settings/notification/ZenModeAutomationSettings.java
index d096e8c..582fb03 100644
--- a/src/com/android/settings/notification/ZenModeAutomationSettings.java
+++ b/src/com/android/settings/notification/ZenModeAutomationSettings.java
@@ -18,6 +18,7 @@
 
 import android.app.Fragment;
 import android.content.Context;
+import android.provider.SearchIndexableResource;
 import android.service.notification.ConditionProviderService;
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
@@ -78,17 +79,30 @@
      */
     public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
             new BaseSearchIndexProvider() {
-        @Override
-        public List<String> getNonIndexableKeys(Context context) {
-            final List<String> keys = super.getNonIndexableKeys(context);
-            keys.add(KEY_ADD_RULE);
-            keys.add(KEY_AUTOMATIC_RULES);
-            return keys;
-        }
 
-        @Override
-        public List<AbstractPreferenceController> getPreferenceControllers(Context context) {
-            return buildPreferenceControllers(context, null, null);
-        }
-    };
+                @Override
+                public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
+                        boolean enabled) {
+                    final ArrayList<SearchIndexableResource> result = new ArrayList<>();
+
+                    final SearchIndexableResource sir = new SearchIndexableResource(context);
+                    sir.xmlResId = R.xml.zen_mode_automation_settings;
+                    result.add(sir);
+                    return result;
+                }
+
+                @Override
+                public List<String> getNonIndexableKeys(Context context) {
+                    final List<String> keys = super.getNonIndexableKeys(context);
+                    keys.add(KEY_ADD_RULE);
+                    keys.add(KEY_AUTOMATIC_RULES);
+                    return keys;
+                }
+
+                @Override
+                public List<AbstractPreferenceController> getPreferenceControllers(
+                        Context context) {
+                    return buildPreferenceControllers(context, null, null);
+                }
+            };
 }
diff --git a/src/com/android/settings/notification/ZenModeBehaviorSettings.java b/src/com/android/settings/notification/ZenModeBehaviorSettings.java
index dfe6786..b58ef86 100644
--- a/src/com/android/settings/notification/ZenModeBehaviorSettings.java
+++ b/src/com/android/settings/notification/ZenModeBehaviorSettings.java
@@ -17,6 +17,7 @@
 package com.android.settings.notification;
 
 import android.content.Context;
+import android.provider.SearchIndexableResource;
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settings.R;
@@ -65,6 +66,18 @@
      */
     public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
             new BaseSearchIndexProvider() {
+
+                @Override
+                public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
+                        boolean enabled) {
+                    final ArrayList<SearchIndexableResource> result = new ArrayList<>();
+
+                    final SearchIndexableResource sir = new SearchIndexableResource(context);
+                    sir.xmlResId = R.xml.zen_mode_behavior_settings;
+                    result.add(sir);
+                    return result;
+                }
+
                 @Override
                 public List<String> getNonIndexableKeys(Context context) {
                     final List<String> keys = super.getNonIndexableKeys(context);
diff --git a/src/com/android/settings/notification/ZenModeRuleSettingsBase.java b/src/com/android/settings/notification/ZenModeRuleSettingsBase.java
index 9eccfdc..069d38b 100644
--- a/src/com/android/settings/notification/ZenModeRuleSettingsBase.java
+++ b/src/com/android/settings/notification/ZenModeRuleSettingsBase.java
@@ -26,7 +26,6 @@
 import android.content.Intent;
 import android.net.Uri;
 import android.os.Bundle;
-import android.provider.SearchIndexableResource;
 import android.service.notification.ConditionProviderService;
 import android.support.v7.preference.DropDownPreference;
 import android.support.v7.preference.Preference;
@@ -44,15 +43,9 @@
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settings.R;
 import com.android.settings.SettingsActivity;
-import com.android.settings.search.BaseSearchIndexProvider;
-import com.android.settings.search.Indexable;
 import com.android.settings.widget.SwitchBar;
 import com.android.settingslib.core.AbstractPreferenceController;
 
-import java.util.Arrays;
-import java.util.List;
-
-import java.util.Arrays;
 import java.util.List;
 
 public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase
@@ -62,8 +55,6 @@
 
     private static final String KEY_RULE_NAME = "rule_name";
     private static final String KEY_ZEN_MODE = "zen_mode";
-    private static final String KEY_EVENT_RULE_SETTINGS = "zen_mode_event_rule_settings";
-    private static final String KEY_SCHEDULE_RULE_SETTINGS = "zen_mode_schedule_rule_settings";
 
     protected Context mContext;
     protected boolean mDisableListeners;
@@ -306,26 +297,4 @@
         }
         mDisableListeners = false;
     }
-
-    /**
-     * For Search.
-     */
-    public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
-            new BaseSearchIndexProvider() {
-                @Override
-                public List<SearchIndexableResource> getXmlResourcesToIndex(
-                        Context context, boolean enabled) {
-                    final SearchIndexableResource sir = new SearchIndexableResource(context);
-                    // not indexable
-                    return Arrays.asList(sir);
-                }
-
-                @Override
-                public List<String> getNonIndexableKeys(Context context) {
-                    final List<String> keys = super.getNonIndexableKeys(context);
-                    keys.add(KEY_SCHEDULE_RULE_SETTINGS);
-                    keys.add(KEY_EVENT_RULE_SETTINGS);
-                    return keys;
-                }
-            };
 }
diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java
index 7512c13..82ab020 100644
--- a/src/com/android/settings/search/SearchIndexableResources.java
+++ b/src/com/android/settings/search/SearchIndexableResources.java
@@ -39,7 +39,6 @@
 import com.android.settings.datausage.DataUsageSummary;
 import com.android.settings.deletionhelper.AutomaticStorageManagerSettings;
 import com.android.settings.development.DevelopmentSettingsDashboardFragment;
-import com.android.settings.deviceinfo.Status;
 import com.android.settings.deviceinfo.StorageDashboardFragment;
 import com.android.settings.deviceinfo.StorageSettings;
 import com.android.settings.display.AmbientDisplaySettings;
@@ -69,8 +68,6 @@
 import com.android.settings.notification.SoundSettings;
 import com.android.settings.notification.ZenModeAutomationSettings;
 import com.android.settings.notification.ZenModeBehaviorSettings;
-import com.android.settings.notification.ZenModeEventRuleSettings;
-import com.android.settings.notification.ZenModeScheduleRuleSettings;
 import com.android.settings.notification.ZenModeSettings;
 import com.android.settings.print.PrintSettingsFragment;
 import com.android.settings.security.EncryptionAndCredential;
@@ -86,6 +83,7 @@
 import com.android.settings.tts.TtsEnginePreferenceFragment;
 import com.android.settings.users.UserSettings;
 import com.android.settings.wallpaper.WallpaperTypeSettings;
+import com.android.settings.wfd.WifiDisplaySettings;
 import com.android.settings.wifi.ConfigureWifiSettings;
 import com.android.settings.wifi.WifiSettings;
 
@@ -169,10 +167,9 @@
         addIndex(PowerUsageSummary.class);
         addIndex(BatterySaverSettings.class);
         addIndex(LockscreenDashboardFragment.class);
+        addIndex(WifiDisplaySettings.class);
         addIndex(ZenModeBehaviorSettings.class);
         addIndex(ZenModeAutomationSettings.class);
-        addIndex(ZenModeEventRuleSettings.class);
-        addIndex(ZenModeScheduleRuleSettings.class);
     }
 
     private SearchIndexableResources() {
diff --git a/src/com/android/settings/search/SettingsSearchIndexablesProvider.java b/src/com/android/settings/search/SettingsSearchIndexablesProvider.java
index 9e35082..0c98b9c 100644
--- a/src/com/android/settings/search/SettingsSearchIndexablesProvider.java
+++ b/src/com/android/settings/search/SettingsSearchIndexablesProvider.java
@@ -156,7 +156,7 @@
                 continue;
             }
             // Build parent-child class pairs for all children listed under this key.
-            for (Tile tile : category.tiles) {
+            for (Tile tile : category.getTiles()) {
                 String childClass = null;
                 if (tile.metaData != null) {
                     childClass = tile.metaData.getString(
diff --git a/src/com/android/settings/users/UserSettings.java b/src/com/android/settings/users/UserSettings.java
index 9f510d2..834166b 100644
--- a/src/com/android/settings/users/UserSettings.java
+++ b/src/com/android/settings/users/UserSettings.java
@@ -923,7 +923,7 @@
                 for (int userId : values[0]) {
                     Bitmap bitmap = mUserManager.getUserIcon(userId);
                     if (bitmap == null) {
-                        bitmap = getDefaultUserIconAsBitmap(userId);
+                        bitmap = getDefaultUserIconAsBitmap(getContext().getResources(), userId);
                     }
                     mUserIcons.append(userId, bitmap);
                 }
@@ -934,7 +934,8 @@
 
     private Drawable getEncircledDefaultIcon() {
         if (mDefaultIconDrawable == null) {
-            mDefaultIconDrawable = encircle(getDefaultUserIconAsBitmap(UserHandle.USER_NULL));
+            mDefaultIconDrawable = encircle(
+                    getDefaultUserIconAsBitmap(getContext().getResources(), UserHandle.USER_NULL));
         }
         return mDefaultIconDrawable;
     }
@@ -1038,14 +1039,16 @@
      * Returns a default user icon (as a {@link Bitmap}) for the given user.
      *
      * Note that for guest users, you should pass in {@code UserHandle.USER_NULL}.
+     * @param resources resources object to fetch the user icon.
      * @param userId the user id or {@code UserHandle.USER_NULL} for a non-user specific icon
      */
-    private static Bitmap getDefaultUserIconAsBitmap(int userId) {
+    private static Bitmap getDefaultUserIconAsBitmap(Resources resources, int userId) {
         Bitmap bitmap = null;
         // Try finding the corresponding bitmap in the dark bitmap cache
         bitmap = sDarkDefaultUserBitmapCache.get(userId);
         if (bitmap == null) {
-            bitmap = UserIcons.convertToBitmap(UserIcons.getDefaultUserIcon(userId, false));
+            bitmap = UserIcons.convertToBitmap(
+                    UserIcons.getDefaultUserIcon(resources, userId, false));
             // Save it to cache
             sDarkDefaultUserBitmapCache.put(userId, bitmap);
         }
@@ -1064,7 +1067,7 @@
             return false;
         }
         UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
-        Bitmap bitmap = getDefaultUserIconAsBitmap(userId);
+        Bitmap bitmap = getDefaultUserIconAsBitmap(context.getResources(), userId);
         um.setUserIcon(userId, bitmap);
 
         return true;
diff --git a/src/com/android/settings/wfd/WifiDisplaySettings.java b/src/com/android/settings/wfd/WifiDisplaySettings.java
index 3fe438f..5707e3e 100755
--- a/src/com/android/settings/wfd/WifiDisplaySettings.java
+++ b/src/com/android/settings/wfd/WifiDisplaySettings.java
@@ -36,7 +36,7 @@
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Looper;
-import android.os.ServiceManager;
+import android.provider.SearchIndexableResource;
 import android.provider.Settings;
 import android.support.v14.preference.SwitchPreference;
 import android.support.v7.preference.ListPreference;
@@ -63,6 +63,11 @@
 import com.android.settings.R;
 import com.android.settings.SettingsPreferenceFragment;
 import com.android.settings.dashboard.SummaryLoader;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.search.Indexable;
+
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * The Settings screen for WifiDisplay configuration and connection management.
@@ -72,7 +77,7 @@
  * on the system.  In that case, the enable option will not be shown but other
  * remote display routes will continue to be made available.
  */
-public final class WifiDisplaySettings extends SettingsPreferenceFragment {
+public final class WifiDisplaySettings extends SettingsPreferenceFragment implements Indexable {
     private static final String TAG = "WifiDisplaySettings";
     private static final boolean DEBUG = false;
 
@@ -823,4 +828,18 @@
 
     public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
             = (activity, summaryLoader) -> new SummaryProvider(activity, summaryLoader);
+
+    public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+            new BaseSearchIndexProvider() {
+                @Override
+                public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
+                        boolean enabled) {
+                    final ArrayList<SearchIndexableResource> result = new ArrayList<>();
+
+                    final SearchIndexableResource sir = new SearchIndexableResource(context);
+                    sir.xmlResId = R.xml.wifi_display_settings;
+                    result.add(sir);
+                    return result;
+                }
+            };
 }
diff --git a/tests/robotests/assets/grandfather_not_implementing_index_provider b/tests/robotests/assets/grandfather_not_implementing_index_provider
index 6704fc3..ab1a2af 100644
--- a/tests/robotests/assets/grandfather_not_implementing_index_provider
+++ b/tests/robotests/assets/grandfather_not_implementing_index_provider
@@ -19,4 +19,6 @@
 com.android.settings.enterprise.ApplicationListFragment$EnterpriseInstalledPackages
 com.android.settings.enterprise.EnterpriseSetDefaultAppsListFragment
 com.android.settings.wifi.tether.WifiTetherSettings
-com.android.settings.wifi.SavedAccessPointsWifiSettings
\ No newline at end of file
+com.android.settings.wifi.SavedAccessPointsWifiSettings
+com.android.settings.notification.ZenModeEventRuleSettings
+com.android.settings.notification.ZenModeScheduleRuleSettings
diff --git a/tests/robotests/assets/grandfather_not_implementing_indexable b/tests/robotests/assets/grandfather_not_implementing_indexable
index 500a582..681e8f6 100644
--- a/tests/robotests/assets/grandfather_not_implementing_indexable
+++ b/tests/robotests/assets/grandfather_not_implementing_indexable
@@ -50,7 +50,6 @@
 com.android.settings.applications.AppInfoDashboardFragment
 com.android.settings.accessibility.ToggleAccessibilityServicePreferenceFragment
 com.android.settings.print.PrintServiceSettingsFragment
-com.android.settings.wfd.WifiDisplaySettings
 com.android.settings.deviceinfo.PrivateVolumeSettings
 com.android.settings.users.AppRestrictionsFragment
 com.android.settings.deviceinfo.PrivateVolumeUnmount
diff --git a/tests/robotests/res/values/themes.xml b/tests/robotests/res/values/themes.xml
index b91df65..74bdd9b 100644
--- a/tests/robotests/res/values/themes.xml
+++ b/tests/robotests/res/values/themes.xml
@@ -1,3 +1,7 @@
 <resources>
-    <style name="Theme.Settings" parent="@android:style/Theme.DeviceDefault.Settings"/>
+    <style name="Theme.Settings" parent="@android:style/Theme.DeviceDefault.Settings" />
+
+    <!-- Override the main app's style for ActionPrimaryButton to get around lack of new style
+         support in robolectric  -->
+    <style name="ActionPrimaryButton" parent="android:Widget.DeviceDefault.Button" />
 </resources>
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java
index 525f70e..d5abd93 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java
@@ -73,8 +73,8 @@
         mBluetoothDeviceUpdater = new BluetoothDeviceUpdater(mDashboardFragment,
                 mDevicePreferenceCallback, null) {
             @Override
-            public void update(CachedBluetoothDevice cachedBluetoothDevice) {
-                // do nothing
+            public boolean isFilterMatched(CachedBluetoothDevice cachedBluetoothDevice) {
+                return true;
             }
         };
         mBluetoothDeviceUpdater.setPrefContext(mContext);
diff --git a/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java b/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java
new file mode 100644
index 0000000..d0f367e
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java
@@ -0,0 +1,108 @@
+/*
+ * 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.bluetooth;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.content.Context;
+
+import com.android.settings.TestConfig;
+import com.android.settings.connecteddevice.DevicePreferenceCallback;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+
+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 SavedBluetoothDeviceUpdaterTest {
+    @Mock
+    private DashboardFragment mDashboardFragment;
+    @Mock
+    private DevicePreferenceCallback mDevicePreferenceCallback;
+    @Mock
+    private CachedBluetoothDevice mCachedBluetoothDevice;
+    @Mock
+    private BluetoothDevice mBluetoothDevice;
+
+    private Context mContext;
+    private BluetoothDeviceUpdater mBluetoothDeviceUpdater;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+
+        mContext = RuntimeEnvironment.application;
+        doReturn(mContext).when(mDashboardFragment).getContext();
+        doReturn(mBluetoothDevice).when(mCachedBluetoothDevice).getDevice();
+
+        mBluetoothDeviceUpdater = spy(new SavedBluetoothDeviceUpdater(mDashboardFragment,
+                mDevicePreferenceCallback, null));
+        mBluetoothDeviceUpdater.setPrefContext(mContext);
+        doNothing().when(mBluetoothDeviceUpdater).addPreference(any());
+        doNothing().when(mBluetoothDeviceUpdater).removePreference(any());
+    }
+
+    @Test
+    public void testUpdate_filterMatch_addPreference() {
+        doReturn(BluetoothDevice.BOND_BONDED).when(mBluetoothDevice).getBondState();
+        doReturn(false).when(mBluetoothDevice).isConnected();
+
+        mBluetoothDeviceUpdater.update(mCachedBluetoothDevice);
+
+        verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
+    }
+
+    @Test
+    public void testUpdate_filterNotMatch_removePreference() {
+        doReturn(BluetoothDevice.BOND_NONE).when(mBluetoothDevice).getBondState();
+        doReturn(true).when(mBluetoothDevice).isConnected();
+
+        mBluetoothDeviceUpdater.update(mCachedBluetoothDevice);
+
+        verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
+    }
+
+    @Test
+    public void testOnConnectionStateChanged_deviceConnected_removePreference() {
+        mBluetoothDeviceUpdater.onConnectionStateChanged(mCachedBluetoothDevice,
+                BluetoothAdapter.STATE_CONNECTED);
+
+        verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
+    }
+
+    @Test
+    public void testOnConnectionStateChanged_deviceDisconnected_addPreference() {
+        mBluetoothDeviceUpdater.onConnectionStateChanged(mCachedBluetoothDevice,
+                BluetoothAdapter.STATE_DISCONNECTED);
+
+        verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
+    }
+
+}
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
index c9469a8..fdb1470 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
@@ -222,14 +222,12 @@
         doReturn(mockTypedArray).when(mContext).obtainStyledAttributes(any(int[].class));
         doReturn(0x89000000).when(mockTypedArray).getColor(anyInt(), anyInt());
 
-        final DashboardCategory category = mock(DashboardCategory.class);
-        final List<Tile> tiles = new ArrayList<>();
+        final DashboardCategory category = new DashboardCategory();
         final Icon mockIcon = mock(Icon.class);
         final Tile tile = new Tile();
         tile.isIconTintable = true;
         tile.icon = mockIcon;
-        tiles.add(tile);
-        category.tiles = tiles;
+        category.addTile(tile);
 
         mDashboardAdapter.setCategory(category);
 
@@ -250,10 +248,8 @@
     public void testBindConditionAndSuggestion_shouldSetSuggestionAdapterAndNoCrash() {
         mDashboardAdapter = new DashboardAdapter(mContext, null, null, null, null, null);
         final List<Tile> suggestions = makeSuggestions("pkg1");
-        final DashboardCategory category = mock(DashboardCategory.class);
-        final List<Tile> tiles = new ArrayList<>();
-        tiles.add(mock(Tile.class));
-        category.tiles = tiles;
+        final DashboardCategory category = new DashboardCategory();
+        category.addTile(mock(Tile.class));
 
         mDashboardAdapter.setCategoriesAndSuggestions(category, suggestions);
 
@@ -277,10 +273,8 @@
     public void testBindConditionAndSuggestion_v2_shouldSetSuggestionAdapterAndNoCrash() {
         mDashboardAdapter = new DashboardAdapter(mContext, null, null, null, null, null);
         final List<Suggestion> suggestions = makeSuggestionsV2("pkg1");
-        final DashboardCategory category = mock(DashboardCategory.class);
-        final List<Tile> tiles = new ArrayList<>();
-        tiles.add(mock(Tile.class));
-        category.tiles = tiles;
+        final DashboardCategory category = new DashboardCategory();
+        category.addTile(mock(Tile.class));
 
         mDashboardAdapter.setSuggestionsV2(suggestions);
 
@@ -310,10 +304,8 @@
                 null /* SuggestionDismissController.Callback */);
 
         final List<Tile> suggestions = new ArrayList<>();
-        final DashboardCategory category = mock(DashboardCategory.class);
-        final List<Tile> tiles = new ArrayList<>();
-        tiles.add(mock(Tile.class));
-        category.tiles = tiles;
+        final DashboardCategory category = new DashboardCategory();
+        category.addTile(mock(Tile.class));
         mDashboardAdapter.setCategoriesAndSuggestions(category, suggestions);
 
         final RecyclerView data = mock(RecyclerView.class);
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardDataTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardDataTest.java
index a3483fb..33f379e 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardDataTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardDataTest.java
@@ -57,13 +57,12 @@
     private DashboardData mDashboardDataWithOneConditions;
     private DashboardData mDashboardDataWithTwoConditions;
     private DashboardData mDashboardDataWithNoItems;
+    private DashboardCategory mDashboardCategory;
     @Mock
     private Tile mTestCategoryTile;
     @Mock
     private Tile mTestSuggestion;
     @Mock
-    private DashboardCategory mDashboardCategory;
-    @Mock
     private Condition mTestCondition;
     @Mock
     private Condition mSecondCondition; // condition used to test insert in DiffUtil
@@ -72,6 +71,8 @@
     public void SetUp() {
         MockitoAnnotations.initMocks(this);
 
+        mDashboardCategory = new DashboardCategory();
+
         // Build suggestions
         final List<Tile> suggestions = new ArrayList<>();
         mTestSuggestion.title = TEST_SUGGESTION_TITLE;
@@ -91,8 +92,8 @@
         // Build category
         mTestCategoryTile.title = TEST_CATEGORY_TILE_TITLE;
         mDashboardCategory.title = "test";
-        mDashboardCategory.tiles = new ArrayList<>();
-        mDashboardCategory.tiles.add(mTestCategoryTile);
+
+        mDashboardCategory.addTile(mTestCategoryTile);
 
         // Build DashboardData
         mDashboardDataWithOneConditions = new DashboardData.Builder()
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
index 559e989..3d36e6f 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
@@ -431,7 +431,7 @@
         mImpl = new DashboardFeatureProviderImpl(mActivity);
         ReflectionHelpers.setField(mImpl, "mCategoryManager", mCategoryManager);
         final DashboardCategory category = new DashboardCategory();
-        category.tiles.add(new Tile());
+        category.addTile(new Tile());
         when(mCategoryManager
                 .getTilesByCategory(any(Context.class), eq(CategoryKey.CATEGORY_HOMEPAGE)))
                 .thenReturn(category);
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java
index 2ee1837..14f3078 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java
@@ -64,9 +64,8 @@
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private Context mContext;
     @Mock
-    private DashboardCategory mDashboardCategory;
-    @Mock
     private FakeFeatureFactory mFakeFeatureFactory;
+    private DashboardCategory mDashboardCategory;
     private TestFragment mTestFragment;
 
     @Before
@@ -74,8 +73,8 @@
         MockitoAnnotations.initMocks(this);
         FakeFeatureFactory.setupForTest(mContext);
         mFakeFeatureFactory = (FakeFeatureFactory) FeatureFactory.getFactory(mContext);
-        mDashboardCategory.tiles = new ArrayList<>();
-        mDashboardCategory.tiles.add(new Tile());
+        mDashboardCategory = new DashboardCategory();
+        mDashboardCategory.addTile(new Tile());
         mTestFragment = new TestFragment(ShadowApplication.getInstance().getApplicationContext());
         when(mFakeFeatureFactory.dashboardFeatureProvider
                 .getTilesForCategory(nullable(String.class)))
@@ -117,7 +116,7 @@
 
     @Test
     public void displayTilesAsPreference_withEmptyCategory_shouldNotAddTiles() {
-        mDashboardCategory.tiles = null;
+        mDashboardCategory.removeTile(0);
         mTestFragment.onCreatePreferences(new Bundle(), "rootKey");
 
         verify(mTestFragment.mScreen, never()).addPreference(nullable(Preference.class));
diff --git a/tests/robotests/src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceControllerTest.java
index dfe81db..d1d479a 100644
--- a/tests/robotests/src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceControllerTest.java
@@ -17,7 +17,11 @@
 package com.android.settings.display;
 
 import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
@@ -41,22 +45,27 @@
 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,
         shadows = {ShadowSecureSettings.class})
 public class AmbientDisplayAlwaysOnPreferenceControllerTest {
 
-    @Mock Context mContext;
-    @Mock AmbientDisplayConfiguration mConfig;
-    @Mock SwitchPreference mSwitchPreference;
+    @Mock
+    private Context mContext;
+    @Mock
+    private AmbientDisplayConfiguration mConfig;
+    @Mock
+    private SwitchPreference mSwitchPreference;
 
-    AmbientDisplayAlwaysOnPreferenceController mController;
-    boolean mCallbackInvoked;
+    private AmbientDisplayAlwaysOnPreferenceController mController;
+    private boolean mCallbackInvoked;
 
     @Before
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
         mController = new AmbientDisplayAlwaysOnPreferenceController(mContext, mConfig,
-                () -> { mCallbackInvoked = true; });
+                () -> {
+                    mCallbackInvoked = true;
+                });
     }
 
     @Test
@@ -91,7 +100,7 @@
         mController.onPreferenceChange(mSwitchPreference, true);
 
         assertThat(Settings.Secure.getInt(null, Settings.Secure.DOZE_ALWAYS_ON, -1))
-            .isEqualTo(1);
+                .isEqualTo(1);
     }
 
     @Test
@@ -99,39 +108,45 @@
         mController.onPreferenceChange(mSwitchPreference, false);
 
         assertThat(Settings.Secure.getInt(null, Settings.Secure.DOZE_ALWAYS_ON, -1))
-            .isEqualTo(0);
+                .isEqualTo(0);
     }
 
     @Test
     public void isAvailable_available() throws Exception {
-        when(mConfig.alwaysOnAvailableForUser(anyInt()))
-                .thenReturn(true);
+        mController = spy(mController);
+        doReturn(true).when(mController).alwaysOnAvailableForUser(any());
 
         assertThat(mController.isAvailable()).isTrue();
     }
 
     @Test
     public void isAvailable_unavailable() throws Exception {
-        when(mConfig.alwaysOnAvailableForUser(anyInt()))
-                .thenReturn(false);
+        mController = spy(mController);
+        doReturn(false).when(mController).alwaysOnAvailableForUser(any());
+
 
         assertThat(mController.isAvailable()).isFalse();
     }
 
     @Test
     public void testPreferenceController_ProperResultPayloadType() {
+        mController = spy(mController);
+        doReturn(false).when(mController).alwaysOnAvailableForUser(any());
         assertThat(mController.getResultPayload()).isInstanceOf(InlineSwitchPayload.class);
     }
 
     @Test
     @Config(shadows = ShadowSecureSettings.class)
     public void testSetValue_updatesCorrectly() {
-        int newValue = 1;
-        ContentResolver resolver = mContext.getContentResolver();
-        Settings.Secure.putInt(resolver, Settings.Secure.DOZE_ALWAYS_ON, 0);
+        mController = spy(mController);
+        doReturn(false).when(mController).alwaysOnAvailableForUser(any());
+        final int newValue = 1;
+        final ContentResolver resolver = mContext.getContentResolver();
+        Settings.Secure.putInt(resolver, Settings.Secure.DOZE_ALWAYS_ON, 0 /* value */);
 
         ((InlinePayload) mController.getResultPayload()).setValue(mContext, newValue);
-        int updatedValue = Settings.Secure.getInt(resolver, Settings.Secure.DOZE_ALWAYS_ON, 1);
+        final int updatedValue = Settings.Secure.getInt(resolver,
+                Settings.Secure.DOZE_ALWAYS_ON, 1 /* default */);
 
         assertThat(updatedValue).isEqualTo(newValue);
     }
@@ -139,11 +154,13 @@
     @Test
     @Config(shadows = ShadowSecureSettings.class)
     public void testGetValue_correctValueReturned() {
-        int currentValue = 1;
-        ContentResolver resolver = mContext.getContentResolver();
+        mController = spy(mController);
+        doReturn(false).when(mController).alwaysOnAvailableForUser(any());
+        final int currentValue = 1;
+        final ContentResolver resolver = mContext.getContentResolver();
         Settings.Secure.putInt(resolver, Settings.Secure.DOZE_ALWAYS_ON, currentValue);
 
-        int newValue = ((InlinePayload) mController.getResultPayload()).getValue(mContext);
+        final int newValue = ((InlinePayload) mController.getResultPayload()).getValue(mContext);
 
         assertThat(newValue).isEqualTo(currentValue);
     }
diff --git a/tests/robotests/src/com/android/settings/display/AmbientDisplayNotificationsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/AmbientDisplayNotificationsPreferenceControllerTest.java
index e1ce694..d442c82 100644
--- a/tests/robotests/src/com/android/settings/display/AmbientDisplayNotificationsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/AmbientDisplayNotificationsPreferenceControllerTest.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,
         shadows = {ShadowSecureSettings.class})
 public class AmbientDisplayNotificationsPreferenceControllerTest {
 
diff --git a/tests/robotests/src/com/android/settings/display/AmbientDisplayPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/AmbientDisplayPreferenceControllerTest.java
index 2933517..123dd85 100644
--- a/tests/robotests/src/com/android/settings/display/AmbientDisplayPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/AmbientDisplayPreferenceControllerTest.java
@@ -39,7 +39,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,
         shadows = {ShadowSecureSettings.class})
 public class AmbientDisplayPreferenceControllerTest {
 
diff --git a/tests/robotests/src/com/android/settings/display/AppGridViewTest.java b/tests/robotests/src/com/android/settings/display/AppGridViewTest.java
index d0a92c9..a2cc76d 100644
--- a/tests/robotests/src/com/android/settings/display/AppGridViewTest.java
+++ b/tests/robotests/src/com/android/settings/display/AppGridViewTest.java
@@ -18,9 +18,16 @@
 
 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;
+
 import android.content.Context;
 import android.content.pm.ActivityInfo;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
+import android.graphics.drawable.Drawable;
 import android.util.IconDrawableFactory;
 
 import com.android.settings.TestConfig;
@@ -35,13 +42,19 @@
 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 AppGridViewTest {
 
     @Mock
     private ResolveInfo mInfo;
     @Mock
     private ActivityInfo mActivityInfo;
+    @Mock
+    private ApplicationInfo mApplicationInfo;
+    @Mock
+    private Drawable mIcon;
+    @Mock
+    private PackageManager mPackageManager;
     private Context mContext;
     private IconDrawableFactory mIconFactory;
 
@@ -49,13 +62,16 @@
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         mInfo.activityInfo = mActivityInfo;
-        mContext = RuntimeEnvironment.application;
+        mInfo.activityInfo.applicationInfo = mApplicationInfo;
+        mContext = spy(RuntimeEnvironment.application);
+        doReturn(mPackageManager).when(mContext).getPackageManager();
         mIconFactory = IconDrawableFactory.newInstance(mContext);
     }
 
     @Test
     public void appEntry_shouldLoadIcon() {
-
+        when(mPackageManager.loadUnbadgedItemIcon(mActivityInfo, mApplicationInfo)).thenReturn(
+                mIcon);
         final AppGridView.ActivityEntry activityEntry = new AppGridView.ActivityEntry(
                 mInfo, "label", mIconFactory);
 
diff --git a/tests/robotests/src/com/android/settings/display/AutoRotatePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/AutoRotatePreferenceControllerTest.java
index 091ae1a..febbaf1 100644
--- a/tests/robotests/src/com/android/settings/display/AutoRotatePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/AutoRotatePreferenceControllerTest.java
@@ -48,7 +48,7 @@
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(
     manifest = TestConfig.MANIFEST_PATH,
-    sdk = TestConfig.SDK_VERSION,
+    sdk = TestConfig.SDK_VERSION_O,
     shadows = ShadowSystemSettings.class
 )
 public class AutoRotatePreferenceControllerTest {
diff --git a/tests/robotests/src/com/android/settings/display/BatteryPercentagePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/BatteryPercentagePreferenceControllerTest.java
index 73c5374..655cf51 100644
--- a/tests/robotests/src/com/android/settings/display/BatteryPercentagePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/BatteryPercentagePreferenceControllerTest.java
@@ -31,7 +31,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 BatteryPercentagePreferenceControllerTest {
     @Mock private Context mContext;
     private BatteryPercentagePreferenceController mController;
diff --git a/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerTest.java
index 95144bd..f8999b5 100644
--- a/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerTest.java
@@ -46,7 +46,7 @@
 import org.robolectric.shadows.ShadowContentResolver;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class BrightnessLevelPreferenceControllerTest {
     @Mock
     private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/display/ColorModePreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/display/ColorModePreferenceFragmentTest.java
index dc3d27a..dc9dc5b 100644
--- a/tests/robotests/src/com/android/settings/display/ColorModePreferenceFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/display/ColorModePreferenceFragmentTest.java
@@ -46,7 +46,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 ColorModePreferenceFragmentTest {
 
     private ColorModePreferenceFragment mFragment;
diff --git a/tests/robotests/src/com/android/settings/display/ShowOperatorNamePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/ShowOperatorNamePreferenceControllerTest.java
index 23b43d6..4d701ca 100644
--- a/tests/robotests/src/com/android/settings/display/ShowOperatorNamePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/ShowOperatorNamePreferenceControllerTest.java
@@ -36,7 +36,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 ShowOperatorNamePreferenceControllerTest {
 
     private static final String KEY_SHOW_OPERATOR_NAME = "show_operator_name";
diff --git a/tests/robotests/src/com/android/settings/display/ThemePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/ThemePreferenceControllerTest.java
index 3d99f65..289b8c1 100644
--- a/tests/robotests/src/com/android/settings/display/ThemePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/ThemePreferenceControllerTest.java
@@ -47,7 +47,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 ThemePreferenceControllerTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/display/TimeoutPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/TimeoutPreferenceControllerTest.java
index 480e41f..48997c3 100644
--- a/tests/robotests/src/com/android/settings/display/TimeoutPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/TimeoutPreferenceControllerTest.java
@@ -33,7 +33,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 TimeoutPreferenceControllerTest {
     private static final int TIMEOUT = 30;
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/display/VrDisplayPreferencePickerTest.java b/tests/robotests/src/com/android/settings/display/VrDisplayPreferencePickerTest.java
index 191a8fb..f874007 100644
--- a/tests/robotests/src/com/android/settings/display/VrDisplayPreferencePickerTest.java
+++ b/tests/robotests/src/com/android/settings/display/VrDisplayPreferencePickerTest.java
@@ -39,7 +39,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 VrDisplayPreferencePickerTest {
 
     private VrDisplayPreferencePicker mPicker;
diff --git a/tests/robotests/src/com/android/settings/display/WallpaperPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/WallpaperPreferenceControllerTest.java
index 1419ad5..17d12c0 100644
--- a/tests/robotests/src/com/android/settings/display/WallpaperPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/WallpaperPreferenceControllerTest.java
@@ -43,7 +43,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 WallpaperPreferenceControllerTest {
 
     private static final String WALLPAPER_PACKAGE = "TestPkg";
diff --git a/tests/robotests/src/com/android/settings/dream/CurrentDreamPickerTest.java b/tests/robotests/src/com/android/settings/dream/CurrentDreamPickerTest.java
index bd25d92..e0a59b5 100644
--- a/tests/robotests/src/com/android/settings/dream/CurrentDreamPickerTest.java
+++ b/tests/robotests/src/com/android/settings/dream/CurrentDreamPickerTest.java
@@ -42,7 +42,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 CurrentDreamPickerTest {
     private static String COMPONENT_KEY = "mocked_component_name_string";
 
diff --git a/tests/robotests/src/com/android/settings/dream/CurrentDreamPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/dream/CurrentDreamPreferenceControllerTest.java
index e3493a1..b0ef640 100644
--- a/tests/robotests/src/com/android/settings/dream/CurrentDreamPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/dream/CurrentDreamPreferenceControllerTest.java
@@ -41,7 +41,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 CurrentDreamPreferenceControllerTest {
     private static String TAG = "CurrentDreamPreferenceControllerTest";
 
diff --git a/tests/robotests/src/com/android/settings/dream/DreamSettingsTest.java b/tests/robotests/src/com/android/settings/dream/DreamSettingsTest.java
index 73526e5..ba3aab5 100644
--- a/tests/robotests/src/com/android/settings/dream/DreamSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/dream/DreamSettingsTest.java
@@ -33,7 +33,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 DreamSettingsTest {
     private static final List<String> KEYS = Arrays.asList(
             DreamSettings.WHILE_CHARGING_ONLY,
diff --git a/tests/robotests/src/com/android/settings/dream/StartNowPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/dream/StartNowPreferenceControllerTest.java
index 444591a..7e310c3 100644
--- a/tests/robotests/src/com/android/settings/dream/StartNowPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/dream/StartNowPreferenceControllerTest.java
@@ -40,7 +40,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 StartNowPreferenceControllerTest {
     private StartNowPreferenceController mController;
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/dream/WhenToDreamPickerTest.java b/tests/robotests/src/com/android/settings/dream/WhenToDreamPickerTest.java
index bafc2d4..542e0b7 100644
--- a/tests/robotests/src/com/android/settings/dream/WhenToDreamPickerTest.java
+++ b/tests/robotests/src/com/android/settings/dream/WhenToDreamPickerTest.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 WhenToDreamPickerTest {
     private WhenToDreamPicker mPicker;
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/dream/WhenToDreamPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/dream/WhenToDreamPreferenceControllerTest.java
index 2acf82b..4763f29 100644
--- a/tests/robotests/src/com/android/settings/dream/WhenToDreamPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/dream/WhenToDreamPreferenceControllerTest.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 WhenToDreamPreferenceControllerTest {
     private WhenToDreamPreferenceController mController;
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/enterprise/AdminActionPreferenceControllerBaseTest.java b/tests/robotests/src/com/android/settings/enterprise/AdminActionPreferenceControllerBaseTest.java
index 111e503..24a96b1 100644
--- a/tests/robotests/src/com/android/settings/enterprise/AdminActionPreferenceControllerBaseTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/AdminActionPreferenceControllerBaseTest.java
@@ -31,7 +31,7 @@
  * Tests for {@link AdminActionPreferenceControllerBase}.
  */
 @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 AdminActionPreferenceControllerBaseTest extends
         AdminActionPreferenceControllerTestBase {
 
diff --git a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedCameraPermissionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedCameraPermissionPreferenceControllerTest.java
index 1154aa7..b003ad8 100644
--- a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedCameraPermissionPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedCameraPermissionPreferenceControllerTest.java
@@ -28,7 +28,7 @@
  * Tests for {@link AdminGrantedCameraPermissionPreferenceController}.
  */
 @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 AdminGrantedCameraPermissionPreferenceControllerTest extends
         AdminGrantedPermissionsPreferenceControllerTestBase {
 
diff --git a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedLocationPermissionsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedLocationPermissionsPreferenceControllerTest.java
index 1c30da1..2fb3e21 100644
--- a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedLocationPermissionsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedLocationPermissionsPreferenceControllerTest.java
@@ -28,7 +28,7 @@
  * Tests for {@link AdminGrantedLocationPermissionsPreferenceController}.
  */
 @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 AdminGrantedLocationPermissionsPreferenceControllerTest extends
         AdminGrantedPermissionsPreferenceControllerTestBase {
 
diff --git a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedMicrophonePermissionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedMicrophonePermissionPreferenceControllerTest.java
index 624022b..9ee8100 100644
--- a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedMicrophonePermissionPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedMicrophonePermissionPreferenceControllerTest.java
@@ -28,7 +28,7 @@
  * Tests for {@link AdminGrantedMicrophonePermissionPreferenceController}.
  */
 @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 AdminGrantedMicrophonePermissionPreferenceControllerTest extends
         AdminGrantedPermissionsPreferenceControllerTestBase {
 
diff --git a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerBaseTest.java b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerBaseTest.java
index a5d1d1a..918c5fb 100644
--- a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerBaseTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerBaseTest.java
@@ -26,7 +26,7 @@
  * Tests for {@link AdminGrantedPermissionsPreferenceControllerBase}.
  */
 @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 AdminGrantedPermissionsPreferenceControllerBaseTest extends
         AdminGrantedPermissionsPreferenceControllerTestBase {
 
diff --git a/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnCurrentUserPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnCurrentUserPreferenceControllerTest.java
index 365b9be..17649bb 100644
--- a/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnCurrentUserPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnCurrentUserPreferenceControllerTest.java
@@ -39,7 +39,7 @@
  * Tests for {@link AlwaysOnVpnCurrentUserPreferenceController}.
  */
 @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 AlwaysOnVpnCurrentUserPreferenceControllerTest {
 
     private static final String VPN_SET_DEVICE = "VPN set";
diff --git a/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnManagedProfilePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnManagedProfilePreferenceControllerTest.java
index 5f921cd..d54505b 100644
--- a/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnManagedProfilePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnManagedProfilePreferenceControllerTest.java
@@ -38,7 +38,7 @@
  * Tests for {@link AlwaysOnVpnManagedProfilePreferenceController}.
  */
 @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 AlwaysOnVpnManagedProfilePreferenceControllerTest {
 
     private static final String KEY_ALWAYS_ON_VPN_MANAGED_PROFILE = "always_on_vpn_managed_profile";
diff --git a/tests/robotests/src/com/android/settings/enterprise/ApplicationListFragmentTest.java b/tests/robotests/src/com/android/settings/enterprise/ApplicationListFragmentTest.java
index 80d4aaf..fce2719 100644
--- a/tests/robotests/src/com/android/settings/enterprise/ApplicationListFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/ApplicationListFragmentTest.java
@@ -46,7 +46,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 ApplicationListFragmentTest {
     private static final int USER_ID = 0;
     private static final int USER_APP_UID = 0;
diff --git a/tests/robotests/src/com/android/settings/enterprise/ApplicationListPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/ApplicationListPreferenceControllerTest.java
index 81223a5..963b2ce 100644
--- a/tests/robotests/src/com/android/settings/enterprise/ApplicationListPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/ApplicationListPreferenceControllerTest.java
@@ -17,11 +17,15 @@
 package com.android.settings.enterprise;
 
 import static com.android.settings.testutils.ApplicationTestUtils.buildInfo;
+
 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.doReturn;
+import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -29,6 +33,7 @@
 import android.content.Context;
 import android.content.pm.PackageManager;
 import android.content.pm.UserInfo;
+import android.os.UserManager;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceScreen;
 
@@ -54,7 +59,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 ApplicationListPreferenceControllerTest {
 
     private static final int MAIN_USER_ID = 0;
@@ -74,6 +79,8 @@
     private PackageManager mPackageManager;
     @Mock(answer = RETURNS_DEEP_STUBS)
     private SettingsPreferenceFragment mFragment;
+    @Mock
+    private UserManager mUserManager;
 
     private Context mContext;
     private ApplicationListPreferenceController mController;
@@ -82,7 +89,8 @@
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         final ShadowApplication shadowContext = ShadowApplication.getInstance();
-        mContext = shadowContext.getApplicationContext();
+        mContext = spy(shadowContext.getApplicationContext());
+        doReturn(mUserManager).when(mContext).getSystemService(UserManager.class);
         when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
         when(mFragment.getPreferenceManager().getContext()).thenReturn(mContext);
         when(mPackageManager.getText(eq(APP_1), anyInt(), any())).thenReturn(APP_1);
diff --git a/tests/robotests/src/com/android/settings/enterprise/BugReportsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/BugReportsPreferenceControllerTest.java
index 0b97353..cc1de27 100644
--- a/tests/robotests/src/com/android/settings/enterprise/BugReportsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/BugReportsPreferenceControllerTest.java
@@ -32,7 +32,7 @@
  * Tests for {@link BugReportsPreferenceController}.
  */
 @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 BugReportsPreferenceControllerTest extends
         AdminActionPreferenceControllerTestBase {
 
diff --git a/tests/robotests/src/com/android/settings/enterprise/CaCertsCurrentUserPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/CaCertsCurrentUserPreferenceControllerTest.java
index 5ee1145..c933d18 100644
--- a/tests/robotests/src/com/android/settings/enterprise/CaCertsCurrentUserPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/CaCertsCurrentUserPreferenceControllerTest.java
@@ -35,7 +35,7 @@
  * Tests for {@link CaCertsCurrentUserPreferenceController}.
  */
 @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 CaCertsCurrentUserPreferenceControllerTest extends
         CaCertsPreferenceControllerTestBase {
 
diff --git a/tests/robotests/src/com/android/settings/enterprise/CaCertsManagedProfilePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/CaCertsManagedProfilePreferenceControllerTest.java
index 2aa5306..d246488 100644
--- a/tests/robotests/src/com/android/settings/enterprise/CaCertsManagedProfilePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/CaCertsManagedProfilePreferenceControllerTest.java
@@ -28,7 +28,7 @@
  * Tests for {@link CaCertsManagedProfilePreferenceController}.
  */
 @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 CaCertsManagedProfilePreferenceControllerTest extends
         CaCertsPreferenceControllerTestBase {
 
diff --git a/tests/robotests/src/com/android/settings/enterprise/CaCertsPreferenceControllerBaseTest.java b/tests/robotests/src/com/android/settings/enterprise/CaCertsPreferenceControllerBaseTest.java
index ec76b2b..7a6bc88 100644
--- a/tests/robotests/src/com/android/settings/enterprise/CaCertsPreferenceControllerBaseTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/CaCertsPreferenceControllerBaseTest.java
@@ -28,7 +28,7 @@
  * Tests for {@link CaCertsPreferenceControllerBase}.
  */
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class CaCertsPreferenceControllerBaseTest extends CaCertsPreferenceControllerTestBase {
     private static final String PREF_KEY = "pref";
 
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterpriseInstalledPackagesPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterpriseInstalledPackagesPreferenceControllerTest.java
index b4f7827..7ecd0e3 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterpriseInstalledPackagesPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterpriseInstalledPackagesPreferenceControllerTest.java
@@ -45,7 +45,7 @@
  * Tests for {@link EnterpriseInstalledPackagesPreferenceController}.
  */
 @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 EnterpriseInstalledPackagesPreferenceControllerTest {
 
     private static final String KEY_NUMBER_ENTERPRISE_INSTALLED_PACKAGES
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
index 1ea2567..516ccb5 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
@@ -57,7 +57,7 @@
  * Tests for {@link EnterprisePrivacyFeatureProviderImpl}.
  */
 @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 EnterprisePrivacyFeatureProviderImplTest {
 
     private final ComponentName OWNER = new ComponentName("dummy", "component");
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyPreferenceControllerTest.java
index 18f16f4..dd97cc0 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyPreferenceControllerTest.java
@@ -39,7 +39,7 @@
  * Tests for {@link EnterprisePrivacyPreferenceController}.
  */
 @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 EnterprisePrivacyPreferenceControllerTest {
 
     private static final String MANAGED_GENERIC = "managed by organization";
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java
index a2b539d..1a37e63 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java
@@ -44,7 +44,7 @@
  * Tests for {@link EnterprisePrivacySettings}.
  */
 @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 EnterprisePrivacySettingsTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsListFragmentTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsListFragmentTest.java
index 567c06f..c47a0ac 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsListFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsListFragmentTest.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 EnterpriseSetDefaultAppsListFragmentTest {
     @Mock(answer = RETURNS_DEEP_STUBS)
     private PreferenceScreen mScreen;
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsListPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsListPreferenceControllerTest.java
index c38f56a..cf66967 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsListPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsListPreferenceControllerTest.java
@@ -59,7 +59,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 EnterpriseSetDefaultAppsListPreferenceControllerTest {
     private static final int USER_ID = 0;
     private static final int APP_UID = 0;
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsPreferenceControllerTest.java
index 9eb6d66..1223558 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsPreferenceControllerTest.java
@@ -52,7 +52,7 @@
  * Tests for {@link EnterpriseSetDefaultAppsPreferenceController}.
  */
 @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 EnterpriseSetDefaultAppsPreferenceControllerTest {
 
     private static final String KEY_DEFAULT_APPS = "number_enterprise_set_default_apps";
diff --git a/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipeCurrentUserPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipeCurrentUserPreferenceControllerTest.java
index 8453d62..77d6ea0 100644
--- a/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipeCurrentUserPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipeCurrentUserPreferenceControllerTest.java
@@ -28,7 +28,7 @@
  * Tests for {@link FailedPasswordWipeCurrentUserPreferenceController}.
  */
 @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 FailedPasswordWipeCurrentUserPreferenceControllerTest extends
         FailedPasswordWipePreferenceControllerTestBase {
 
diff --git a/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipeManagedProfilePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipeManagedProfilePreferenceControllerTest.java
index a001a9c..c88c22b 100644
--- a/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipeManagedProfilePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipeManagedProfilePreferenceControllerTest.java
@@ -28,7 +28,7 @@
  * Tests for {@link FailedPasswordWipeManagedProfilePreferenceController}.
  */
 @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 FailedPasswordWipeManagedProfilePreferenceControllerTest extends
         FailedPasswordWipePreferenceControllerTestBase {
 
diff --git a/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerBaseTest.java b/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerBaseTest.java
index f80667c..ecc490f 100644
--- a/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerBaseTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerBaseTest.java
@@ -26,7 +26,7 @@
  * Tests for {@link FailedPasswordWipePreferenceControllerBase}.
  */
 @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 FailedPasswordWipePreferenceControllerBaseTest extends
         FailedPasswordWipePreferenceControllerTestBase {
 
diff --git a/tests/robotests/src/com/android/settings/enterprise/GlobalHttpProxyPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/GlobalHttpProxyPreferenceControllerTest.java
index b9c24bf..e31b40f 100644
--- a/tests/robotests/src/com/android/settings/enterprise/GlobalHttpProxyPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/GlobalHttpProxyPreferenceControllerTest.java
@@ -38,7 +38,7 @@
  * Tests for {@link GlobalHttpProxyPreferenceController}.
  */
 @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 GlobalHttpProxyPreferenceControllerTest {
 
     private static final String KEY_GLOBAL_HTTP_PROXY = "global_http_proxy";
diff --git a/tests/robotests/src/com/android/settings/enterprise/ImePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/ImePreferenceControllerTest.java
index 1e05383..caa5121 100644
--- a/tests/robotests/src/com/android/settings/enterprise/ImePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/ImePreferenceControllerTest.java
@@ -39,7 +39,7 @@
  * Tests for {@link ImePreferenceController}.
  */
 @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 ImePreferenceControllerTest {
 
     private static final String DEFAULT_IME_LABEL = "Test IME";
diff --git a/tests/robotests/src/com/android/settings/enterprise/ManageDeviceAdminPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/ManageDeviceAdminPreferenceControllerTest.java
index 2df05c2..f46ecce 100644
--- a/tests/robotests/src/com/android/settings/enterprise/ManageDeviceAdminPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/ManageDeviceAdminPreferenceControllerTest.java
@@ -39,7 +39,7 @@
  * Tests for {@link ManageDeviceAdminPreferenceController}.
  */
 @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 ManageDeviceAdminPreferenceControllerTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/enterprise/NetworkLogsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/NetworkLogsPreferenceControllerTest.java
index 43b793d..e8f7398 100644
--- a/tests/robotests/src/com/android/settings/enterprise/NetworkLogsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/NetworkLogsPreferenceControllerTest.java
@@ -32,7 +32,7 @@
  * Tests for {@link NetworkLogsPreferenceController}.
  */
 @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 NetworkLogsPreferenceControllerTest extends
         AdminActionPreferenceControllerTestBase {
 
diff --git a/tests/robotests/src/com/android/settings/enterprise/SecurityLogsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/SecurityLogsPreferenceControllerTest.java
index 11e219a..7a597dc 100644
--- a/tests/robotests/src/com/android/settings/enterprise/SecurityLogsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/SecurityLogsPreferenceControllerTest.java
@@ -32,7 +32,7 @@
  * Tests for {@link SecurityLogsPreferenceController}.
  */
 @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 SecurityLogsPreferenceControllerTest extends
         AdminActionPreferenceControllerTestBase {
 
diff --git a/tests/robotests/src/com/android/settings/fingerprint/DeleteFingerprintDialogTest.java b/tests/robotests/src/com/android/settings/fingerprint/DeleteFingerprintDialogTest.java
index c3c1b42..125977f 100644
--- a/tests/robotests/src/com/android/settings/fingerprint/DeleteFingerprintDialogTest.java
+++ b/tests/robotests/src/com/android/settings/fingerprint/DeleteFingerprintDialogTest.java
@@ -17,6 +17,10 @@
 package com.android.settings.fingerprint;
 
 
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
 import android.app.Dialog;
 import android.hardware.fingerprint.Fingerprint;
 
@@ -26,6 +30,7 @@
         .DeleteFingerprintDialog;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.testutils.shadow.ShadowEventLogWriter;
+import com.android.settings.testutils.shadow.ShadowFragment;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -35,27 +40,25 @@
 import org.robolectric.annotation.Config;
 import org.robolectric.util.FragmentTestUtil;
 
-import static org.mockito.Mockito.never;
-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,
         shadows = {
-                ShadowEventLogWriter.class
+                ShadowEventLogWriter.class,
+                ShadowFragment.class
         })
 public class DeleteFingerprintDialogTest {
 
     @Mock
-    private FingerprintSettingsFragment mTarget;
-    @Mock
     private Fingerprint mFingerprint;
-    private DeleteFingerprintDialog mFragment;
+    @Mock
+    private FingerprintSettingsFragment mTarget;
 
+    private DeleteFingerprintDialog mFragment;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        mFragment = DeleteFingerprintDialog.newInstance(mFingerprint, mTarget);
+        mFragment = spy(DeleteFingerprintDialog.newInstance(mFingerprint, mTarget));
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/fingerprint/FingerprintEnrollEnrollingTest.java b/tests/robotests/src/com/android/settings/fingerprint/FingerprintEnrollEnrollingTest.java
index ace535e..190d65d 100644
--- a/tests/robotests/src/com/android/settings/fingerprint/FingerprintEnrollEnrollingTest.java
+++ b/tests/robotests/src/com/android/settings/fingerprint/FingerprintEnrollEnrollingTest.java
@@ -57,7 +57,7 @@
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(
         manifest = TestConfig.MANIFEST_PATH,
-        sdk = Config.NEWEST_SDK,
+        sdk = TestConfig.SDK_VERSION_O,
         shadows = {
                 ShadowUtils.class,
                 ShadowVibrator.class
diff --git a/tests/robotests/src/com/android/settings/fingerprint/FingerprintEnrollFindSensorTest.java b/tests/robotests/src/com/android/settings/fingerprint/FingerprintEnrollFindSensorTest.java
index d495b74..d479e1e 100644
--- a/tests/robotests/src/com/android/settings/fingerprint/FingerprintEnrollFindSensorTest.java
+++ b/tests/robotests/src/com/android/settings/fingerprint/FingerprintEnrollFindSensorTest.java
@@ -55,7 +55,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/fingerprint/FingerprintEnrollSuggestionActivityTest.java b/tests/robotests/src/com/android/settings/fingerprint/FingerprintEnrollSuggestionActivityTest.java
index e299fd5..2856325 100644
--- a/tests/robotests/src/com/android/settings/fingerprint/FingerprintEnrollSuggestionActivityTest.java
+++ b/tests/robotests/src/com/android/settings/fingerprint/FingerprintEnrollSuggestionActivityTest.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 FingerprintEnrollSuggestionActivityTest {
 
     @Mock
diff --git a/tests/robotests/src/com/android/settings/fingerprint/FingerprintLocationAnimationVideoViewTest.java b/tests/robotests/src/com/android/settings/fingerprint/FingerprintLocationAnimationVideoViewTest.java
index 7b7e440..f80b324 100644
--- a/tests/robotests/src/com/android/settings/fingerprint/FingerprintLocationAnimationVideoViewTest.java
+++ b/tests/robotests/src/com/android/settings/fingerprint/FingerprintLocationAnimationVideoViewTest.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 FingerprintLocationAnimationVideoViewTest {
 
     private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/fingerprint/FingerprintPreferenceTest.java b/tests/robotests/src/com/android/settings/fingerprint/FingerprintPreferenceTest.java
index 29c6f10..23e0e73 100644
--- a/tests/robotests/src/com/android/settings/fingerprint/FingerprintPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/fingerprint/FingerprintPreferenceTest.java
@@ -39,7 +39,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 FingerprintPreferenceTest {
 
     @Mock
diff --git a/tests/robotests/src/com/android/settings/fingerprint/FingerprintSuggestionActivityTest.java b/tests/robotests/src/com/android/settings/fingerprint/FingerprintSuggestionActivityTest.java
index 0254bcb..0e4446f 100644
--- a/tests/robotests/src/com/android/settings/fingerprint/FingerprintSuggestionActivityTest.java
+++ b/tests/robotests/src/com/android/settings/fingerprint/FingerprintSuggestionActivityTest.java
@@ -50,7 +50,7 @@
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(
         manifest = TestConfig.MANIFEST_PATH,
-        sdk = TestConfig.SDK_VERSION,
+        sdk = TestConfig.SDK_VERSION_O,
         shadows = {
                 ShadowEventLogWriter.class,
                 ShadowLockPatternUtils.class,
diff --git a/tests/robotests/src/com/android/settings/fingerprint/SetupFingerprintEnrollFindSensorTest.java b/tests/robotests/src/com/android/settings/fingerprint/SetupFingerprintEnrollFindSensorTest.java
index c3899e9..f9d1994 100644
--- a/tests/robotests/src/com/android/settings/fingerprint/SetupFingerprintEnrollFindSensorTest.java
+++ b/tests/robotests/src/com/android/settings/fingerprint/SetupFingerprintEnrollFindSensorTest.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,
                 SettingsShadowResources.SettingsShadowTheme.class,
diff --git a/tests/robotests/src/com/android/settings/fingerprint/SetupFingerprintEnrollIntroductionTest.java b/tests/robotests/src/com/android/settings/fingerprint/SetupFingerprintEnrollIntroductionTest.java
index 2d98bf4..bf5c187 100644
--- a/tests/robotests/src/com/android/settings/fingerprint/SetupFingerprintEnrollIntroductionTest.java
+++ b/tests/robotests/src/com/android/settings/fingerprint/SetupFingerprintEnrollIntroductionTest.java
@@ -60,7 +60,7 @@
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(
         manifest = TestConfig.MANIFEST_PATH,
-        sdk = TestConfig.SDK_VERSION,
+        sdk = TestConfig.SDK_VERSION_O,
         shadows = {
                 ShadowEventLogWriter.class,
                 ShadowFingerprintManager.class,
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
index c9fcf26..99b0945 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
@@ -78,7 +78,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 = {ShadowEntityHeaderController.class, ShadowActivityManager.class})
 public class AdvancedPowerUsageDetailTest {
     private static final String APP_LABEL = "app label";
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/AppButtonsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/AppButtonsPreferenceControllerTest.java
index ad5f5b0..5c28a06 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/AppButtonsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/AppButtonsPreferenceControllerTest.java
@@ -66,7 +66,7 @@
 import org.robolectric.util.ReflectionHelpers;
 
 @RunWith(RobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class AppButtonsPreferenceControllerTest {
     private static final String PACKAGE_NAME = "com.android.settings";
     private static final String RESOURCE_STRING = "string";
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java
index e010cf3..cb5914f 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java
@@ -39,6 +39,7 @@
 import com.android.settings.R;
 import com.android.settings.TestConfig;
 import com.android.settings.testutils.shadow.SettingsShadowResources;
+import com.android.settings.testutils.shadow.ShadowFragment;
 import com.android.settings.wrapper.DevicePolicyManagerWrapper;
 
 import org.junit.Before;
@@ -57,10 +58,11 @@
 @RunWith(RobolectricTestRunner.class)
 @Config(
         manifest = TestConfig.MANIFEST_PATH,
-        sdk = TestConfig.SDK_VERSION,
+        sdk = TestConfig.SDK_VERSION_O,
         shadows = {
                 SettingsShadowResources.class,
-                SettingsShadowResources.SettingsShadowTheme.class
+                SettingsShadowResources.SettingsShadowTheme.class,
+                ShadowFragment.class
         })
 public class BackgroundActivityPreferenceControllerTest {
     private static final int UID_LOW_SDK = 1234;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java
index a163a43..30b3448 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java
@@ -41,7 +41,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 BatteryBroadcastReceiverTest {
     private static final String BATTERY_INIT_LEVEL = "100%";
     private static final String BATTERY_INIT_STATUS = "Not charging";
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryEntryTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryEntryTest.java
index a57b6ca..04040ac 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryEntryTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryEntryTest.java
@@ -43,7 +43,7 @@
 import static org.mockito.Mockito.when;
 
 @RunWith(RobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class BatteryEntryTest {
 
     private static final int APP_UID = 123;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceControllerTest.java
index 719cc33..e433b3c 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceControllerTest.java
@@ -43,6 +43,7 @@
 import com.android.settings.applications.LayoutPreference;
 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.ShadowEntityHeaderController;
 import com.android.settings.widget.EntityHeaderController;
 import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -58,9 +59,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,
                 ShadowEntityHeaderController.class
         })
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryPreferenceTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryPreferenceTest.java
index 0d03512..60d06cd 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryPreferenceTest.java
@@ -44,7 +44,8 @@
 
 
 @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
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoLoaderTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoLoaderTest.java
index b87089a..5029897 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoLoaderTest.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 BatteryInfoLoaderTest {
     private static final long TEST_TIME_REMAINING = 1000L;
 
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
index d82a89b..dd6b709 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
@@ -58,7 +58,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 BatteryInfoTest {
 
     private static final String STATUS_FULL = "Full";
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryMeterViewTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryMeterViewTest.java
index 3a1fad0..fba6a24 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryMeterViewTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryMeterViewTest.java
@@ -39,7 +39,7 @@
 @RunWith(SettingsRobolectricTestRunner.class)
 // TODO: Consider making the shadow class set global using a robolectric.properties file.
 @Config(manifest = TestConfig.MANIFEST_PATH,
-        sdk = TestConfig.SDK_VERSION,
+        sdk = TestConfig.SDK_VERSION_O,
         shadows = {
                 SettingsShadowResources.class,
                 SettingsShadowTheme.class,
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryOptimizationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryOptimizationPreferenceControllerTest.java
index 77e3198..8b8541a 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryOptimizationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryOptimizationPreferenceControllerTest.java
@@ -45,7 +45,7 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(RobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class BatteryOptimizationPreferenceControllerTest {
     private static final String PKG_IN_WHITELIST = "com.pkg.in.whitelist";
     private static final String PKG_NOT_IN_WHITELIST = "com.pkg.not.in.whitelist";
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatterySaverControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatterySaverControllerTest.java
index c75a6a6..eeca72f 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatterySaverControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatterySaverControllerTest.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 BatterySaverControllerTest {
     @Mock
     private MasterSwitchPreference mBatterySaverPref;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatterySaverReceiverTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatterySaverReceiverTest.java
index 259bcd2..944f755 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatterySaverReceiverTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatterySaverReceiverTest.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 BatterySaverReceiverTest {
     @Mock
     private BatterySaverReceiver.BatterySaverListener mBatterySaverListener;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatterySaverSettingsTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatterySaverSettingsTest.java
index 0e32f6b..a7bcf53 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatterySaverSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatterySaverSettingsTest.java
@@ -35,7 +35,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 BatterySaverSettingsTest {
     private Context mContext;
     private BatterySaverSettings mBatterySaverSettings;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryStatsHelperLoaderTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryStatsHelperLoaderTest.java
index 5f8d7cf..5ba98f2 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryStatsHelperLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryStatsHelperLoaderTest.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 BatteryStatsHelperLoaderTest {
     @Mock
     private BatteryUtils mBatteryUtils;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
index c08b01d..56abf48 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
@@ -69,7 +69,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 BatteryUtilsTest {
     // unit that used to converted ms to us
     private static final long UNIT = 1000;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/ButtonActionDialogFragmentTest.java b/tests/robotests/src/com/android/settings/fuelgauge/ButtonActionDialogFragmentTest.java
index dec445d..468c160 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/ButtonActionDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/ButtonActionDialogFragmentTest.java
@@ -45,7 +45,7 @@
 import org.robolectric.util.FragmentTestUtil;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows = {
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O, shadows = {
         ShadowEventLogWriter.class
 })
 public class ButtonActionDialogFragmentTest {
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/HighPowerDetailTest.java b/tests/robotests/src/com/android/settings/fuelgauge/HighPowerDetailTest.java
index d87020e..fe3cd29 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/HighPowerDetailTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/HighPowerDetailTest.java
@@ -36,7 +36,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 HighPowerDetailTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerGaugePreferenceTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerGaugePreferenceTest.java
index 32f6a96..e2f5fad 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerGaugePreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerGaugePreferenceTest.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 PowerGaugePreferenceTest {
     private static final String SUBTITLE = "Summary";
     private static final String CONTENT_DESCRIPTION = "Content description";
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
index 2b5e704..2056262 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
@@ -63,7 +63,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 PowerUsageAdvancedTest {
     private static final int FAKE_UID_1 = 50;
     private static final int FAKE_UID_2 = 100;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAnomalyDetailsTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAnomalyDetailsTest.java
index c992d0a..c6040c0 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAnomalyDetailsTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAnomalyDetailsTest.java
@@ -59,7 +59,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 PowerUsageAnomalyDetailsTest {
     private static final String NAME_APP_1 = "app1";
     private static final String NAME_APP_2 = "app2";
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageBaseTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageBaseTest.java
index 9e0d4de..df829aa 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageBaseTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageBaseTest.java
@@ -47,7 +47,7 @@
  * Unit tests for {@link PowerUsageBase}.
  */
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
         shadows = ShadowDashboardFragment.class)
 public class PowerUsageBaseTest {
     @Mock
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
index afda69f..6961b60 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
@@ -33,7 +33,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 PowerUsageFeatureProviderImplTest {
     private static final int UID_OTHER = Process.FIRST_APPLICATION_UID + 2;
     private static final int UID_CALENDAR = Process.FIRST_APPLICATION_UID + 3;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
index 4385409..5be2fe6 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
@@ -86,7 +86,7 @@
 // TODO: Improve this test class so that it starts up the real activity and fragment.
 @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/fuelgauge/anomaly/AnomalyDetectionPolicyTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyDetectionPolicyTest.java
index 46db6b3..4ecd1dd 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyDetectionPolicyTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyDetectionPolicyTest.java
@@ -39,7 +39,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 AnomalyDetectionPolicyTest {
     private static final String ANOMALY_DETECTION_CONSTANTS_VALUE =
             "anomaly_detection_enabled=true"
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 6b3791a..ccce08f 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyDialogFragmentTest.java
@@ -49,7 +49,7 @@
 import org.robolectric.util.FragmentTestUtil;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
         shadows = ShadowRuntimePermissionPresenter.class)
 public class AnomalyDialogFragmentTest {
     private static final String PACKAGE_NAME = "com.android.app";
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 48749d5..dfb7d21 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyLoaderTest.java
@@ -49,7 +49,8 @@
 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 AnomalyLoaderTest {
     private static final String PACKAGE_NAME = "com.android.settings";
     private static final CharSequence DISPLAY_NAME = "Settings";
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyPreferenceTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyPreferenceTest.java
index c0157ae..7061b8a 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyPreferenceTest.java
@@ -31,7 +31,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 AnomalyPreferenceTest {
     @Anomaly.AnomalyType
     private static final int ANOMALY_TYPE = Anomaly.AnomalyType.WAKE_LOCK;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalySummaryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalySummaryPreferenceControllerTest.java
index 3f48d0a..1114e6a 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalySummaryPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalySummaryPreferenceControllerTest.java
@@ -30,6 +30,7 @@
 import android.content.Context;
 import android.support.v14.preference.PreferenceFragment;
 import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
 
 import com.android.settings.SettingsActivity;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -48,7 +49,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 AnomalySummaryPreferenceControllerTest {
     @Anomaly.AnomalyType
     private static final int ANOMALY_TYPE = Anomaly.AnomalyType.WAKE_LOCK;
@@ -56,7 +57,7 @@
     private static final String DISPLAY_NAME = "appName";
     private static final int UID = 111;
 
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+    @Mock
     private PreferenceFragment mFragment;
     @Mock
     private FragmentManager mFragmentManager;
@@ -64,6 +65,9 @@
     private FragmentTransaction mFragmentTransaction;
     @Mock
     private SettingsActivity mSettingsActivity;
+    @Mock
+    private PreferenceScreen mPreferenceScreen;
+
     private AnomalySummaryPreferenceController mAnomalySummaryPreferenceController;
     private Preference mPreference;
     private Context mContext;
@@ -76,11 +80,12 @@
         mContext = RuntimeEnvironment.application;
         mPreference = new Preference(mContext);
         mPreference.setKey(AnomalySummaryPreferenceController.ANOMALY_KEY);
-        when(mFragment.getPreferenceScreen().findPreference(any())).thenReturn(mPreference);
+        when(mFragment.getPreferenceScreen()).thenReturn(mPreferenceScreen);
         when(mFragment.getFragmentManager()).thenReturn(mFragmentManager);
         when(mFragmentManager.beginTransaction()).thenReturn(mFragmentTransaction);
         when(mFragment.getContext()).thenReturn(mContext);
         when(mSettingsActivity.getApplicationContext()).thenReturn(mContext);
+        when(mPreferenceScreen.findPreference(any())).thenReturn(mPreference);
 
         mAnomalyList = new ArrayList<>();
 
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyTest.java
index 13a5b31..dae1141 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyTest.java
@@ -29,7 +29,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 AnomalyTest {
     private static int TYPE = Anomaly.AnomalyType.WAKE_LOCK;
     private static int UID = 111;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyUtilsTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyUtilsTest.java
index 38391c9..d37d01e 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyUtilsTest.java
@@ -45,7 +45,7 @@
 import java.util.List;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows = {
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O, shadows = {
         ShadowKeyValueListParserWrapperImpl.class})
 public class AnomalyUtilsTest {
     private static final String PACKAGE_NAME_WAKEUP = "com.android.app1";
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 8db1a8c..6f3e9b4 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
@@ -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 AnomalyActionTest {
     private static final String PACKAGE_NAME = "com.android.app";
     private static final int UID = 111;
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 7e5fc4a..e72039a 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
@@ -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 BackgroundCheckActionTest {
     private static final String PACKAGE_NAME = "com.android.app";
     private static final int UID = 111;
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 89b1a16..fcb029c 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
@@ -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 ForceStopActionTest {
     private static final String PACKAGE_NAME = "com.android.app";
 
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 234dd12..d2b6fcb 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
@@ -37,7 +37,7 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows =
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O, shadows =
         ShadowPermissionChecker.class)
 public class LocationCheckActionTest {
     private static final String PACKAGE_NAME = "com.android.app";
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 c06bddd..de7402b 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
@@ -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 StopAndBackgroundActionTest {
     private static final String PACKAGE_NAME = "com.android.app";
     private static final int UID = 111;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/BluetoothScanAnomalyDetectorTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/BluetoothScanAnomalyDetectorTest.java
index edf026a..b148ce9 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/BluetoothScanAnomalyDetectorTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/BluetoothScanAnomalyDetectorTest.java
@@ -52,7 +52,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 BluetoothScanAnomalyDetectorTest {
     private static final String TARGET_PACKAGE_NAME = "com.android.app";
     private static final int ANOMALY_UID = 111;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/WakeLockAnomalyDetectorTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/WakeLockAnomalyDetectorTest.java
index d7682ea..0991d89 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/WakeLockAnomalyDetectorTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/WakeLockAnomalyDetectorTest.java
@@ -55,7 +55,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 WakeLockAnomalyDetectorTest {
     private static final String TARGET_PACKAGE_NAME = "com.android.app";
     private static final long ANOMALY_WAKELOCK_TIME_MS = 2 * DateUtils.HOUR_IN_MILLIS;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/WakeupAlarmAnomalyDetectorTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/WakeupAlarmAnomalyDetectorTest.java
index 13a5ab8..f014f8d 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/WakeupAlarmAnomalyDetectorTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/WakeupAlarmAnomalyDetectorTest.java
@@ -56,7 +56,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 WakeupAlarmAnomalyDetectorTest {
     private static final String TARGET_PACKAGE_NAME = "com.android.target";
     private static final String ANOMALY_PACKAGE_NAME = "com.android.anomaly";
diff --git a/tests/robotests/src/com/android/settings/search/SearchIndexProviderCodeInspector.java b/tests/robotests/src/com/android/settings/search/SearchIndexProviderCodeInspector.java
index 3c51a90..a8372d9 100644
--- a/tests/robotests/src/com/android/settings/search/SearchIndexProviderCodeInspector.java
+++ b/tests/robotests/src/com/android/settings/search/SearchIndexProviderCodeInspector.java
@@ -16,6 +16,9 @@
 
 package com.android.settings.search;
 
+import static com.google.common.truth.Truth.assertWithMessage;
+
+import android.provider.SearchIndexableResource;
 import android.util.ArraySet;
 import android.util.Log;
 
@@ -23,13 +26,13 @@
 import com.android.settings.core.codeinspection.CodeInspector;
 import com.android.settings.dashboard.DashboardFragmentSearchIndexProviderInspector;
 
+import org.robolectric.RuntimeEnvironment;
+
 import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
 
-import static com.google.common.truth.Truth.assertWithMessage;
-
 /**
  * {@link CodeInspector} to ensure fragments implement search components correctly.
  */
@@ -49,6 +52,9 @@
             "Class containing " + DatabaseIndexingManager.FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER
                     + " must be added to " + SearchIndexableResources.class.getName()
                     + " but these are not: \n";
+    private static final String NOT_PROVIDING_VALID_RESOURCE_ERROR =
+            "SearchIndexableProvider must either provide no resource to index, or valid ones. "
+            + "But the followings contain resource with xml id = 0\n";
 
     private final List<String> notImplementingIndexableGrandfatherList;
     private final List<String> notImplementingIndexProviderGrandfatherList;
@@ -77,6 +83,7 @@
         final Set<String> notImplementingIndexProvider = new ArraySet<>();
         final Set<String> notInSearchProviderRegistry = new ArraySet<>();
         final Set<String> notSharingPreferenceControllers = new ArraySet<>();
+        final Set<String> notProvidingValidResource = new ArraySet<>();
 
         for (Class clazz : mClasses) {
             if (!isConcreteSettingsClass(clazz)) {
@@ -119,6 +126,10 @@
                     notInSearchProviderRegistry.add(className);
                 }
             }
+            // Search provider must either don't provider resource xml, or provide valid ones.
+            if (!hasValidResourceFromProvider(clazz)) {
+                notProvidingValidResource.add(className);
+            }
         }
 
         // Build error messages
@@ -131,6 +142,8 @@
                 notSharingPreferenceControllers);
         final String notInProviderRegistryError =
                 buildErrorMessage(NOT_IN_INDEXABLE_PROVIDER_REGISTRY, notInSearchProviderRegistry);
+        final String notProvidingValidResourceError = buildErrorMessage(
+                NOT_PROVIDING_VALID_RESOURCE_ERROR, notProvidingValidResource);
         assertWithMessage(indexableError)
                 .that(notImplementingIndexable)
                 .isEmpty();
@@ -143,6 +156,9 @@
         assertWithMessage(notInProviderRegistryError)
                 .that(notInSearchProviderRegistry)
                 .isEmpty();
+        assertWithMessage(notProvidingValidResourceError)
+                .that(notProvidingValidResource)
+                .isEmpty();
         assertNoObsoleteInGrandfatherList("grandfather_not_implementing_indexable",
                 notImplementingIndexableGrandfatherList);
         assertNoObsoleteInGrandfatherList("grandfather_not_implementing_index_provider",
@@ -168,6 +184,28 @@
         }
     }
 
+    private boolean hasValidResourceFromProvider(Class clazz) {
+        try {
+            final Indexable.SearchIndexProvider provider =
+                    DatabaseIndexingUtils.getSearchIndexProvider(clazz);
+            final List<SearchIndexableResource> resources = provider.getXmlResourcesToIndex(
+                    RuntimeEnvironment.application, true /* enabled */);
+            if (resources == null) {
+                // No resource, that's fine.
+                return true;
+            }
+            for (SearchIndexableResource res : resources) {
+                if (res.xmlResId == 0) {
+                    // Invalid resource
+                    return false;
+                }
+            }
+        } catch (Exception e) {
+            // Ignore.
+        }
+        return true;
+    }
+
     private String buildErrorMessage(String errorSummary, Set<String> errorClasses) {
         final StringBuilder error = new StringBuilder(errorSummary);
         for (String c : errorClasses) {
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowFragment.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowFragment.java
new file mode 100644
index 0000000..4596559
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowFragment.java
@@ -0,0 +1,47 @@
+/*
+ * 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.app.Fragment;
+import android.app.FragmentManager;
+
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+
+/**
+ * Override the {@link #setTargetFragment(Fragment, int)} to skip an illegal state exception
+ * in SDK 26. SDK 26 requires that the target fragment be in the same {@link FragmentManager} as
+ * the current {@link Fragment}. This is infeasible with our current framework.
+ */
+@Implements(
+        value = Fragment.class,
+        minSdk = 26
+)
+public class ShadowFragment {
+
+    private Fragment mTargetFragment;
+
+    @Implementation
+    public void setTargetFragment(Fragment fragment, int requestCode) {
+        mTargetFragment = fragment;
+    }
+
+    @Implementation
+    final public Fragment getTargetFragment() {
+        return mTargetFragment;
+    }
+}