Merge "Add controllers for default app shortcut preferences."
diff --git a/src/com/android/settings/network/AirplaneModePreferenceController.java b/src/com/android/settings/network/AirplaneModePreferenceController.java
index 0620f14..d86f7f7 100644
--- a/src/com/android/settings/network/AirplaneModePreferenceController.java
+++ b/src/com/android/settings/network/AirplaneModePreferenceController.java
@@ -100,12 +100,16 @@
     }
 
     public void onResume() {
-        mAirplaneModeEnabler.resume();
+        if (mAirplaneModeEnabler != null) {
+            mAirplaneModeEnabler.resume();
+        }
     }
 
     @Override
     public void onPause() {
-        mAirplaneModeEnabler.pause();
+        if (mAirplaneModeEnabler != null) {
+            mAirplaneModeEnabler.pause();
+        }
     }
 
     public void onActivityResult(int requestCode, int resultCode, Intent data) {
diff --git a/src/com/android/settings/search/IndexDatabaseHelper.java b/src/com/android/settings/search/IndexDatabaseHelper.java
index 19e3419..7073545 100644
--- a/src/com/android/settings/search/IndexDatabaseHelper.java
+++ b/src/com/android/settings/search/IndexDatabaseHelper.java
@@ -293,7 +293,8 @@
     }
 
     static void setBuildIndexed(Context context, String buildNo) {
-        context.getSharedPreferences(SHARED_PREFS_TAG, 0).edit().putBoolean(buildNo, true).commit();
+        // Use #apply() instead of #commit() since #commit() Robolectric loop indefinitely in sdk 26
+        context.getSharedPreferences(SHARED_PREFS_TAG, 0).edit().putBoolean(buildNo, true).apply();
     }
 
     private void dropTables(SQLiteDatabase db) {
diff --git a/src/com/android/settings/search/SearchViewHolder.java b/src/com/android/settings/search/SearchViewHolder.java
index ed72940..7667a06 100644
--- a/src/com/android/settings/search/SearchViewHolder.java
+++ b/src/com/android/settings/search/SearchViewHolder.java
@@ -17,6 +17,7 @@
 package com.android.settings.search;
 
 import android.content.Context;
+import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
 import android.graphics.drawable.Drawable;
 import android.os.UserHandle;
@@ -26,6 +27,7 @@
 import android.view.View;
 import android.widget.ImageView;
 import android.widget.TextView;
+import android.support.annotation.VisibleForTesting;
 
 import com.android.settings.R;
 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
@@ -84,8 +86,7 @@
             AppSearchResult appResult = (AppSearchResult) result;
             PackageManager pm = fragment.getActivity().getPackageManager();
             UserHandle userHandle = appResult.getAppUserHandle();
-            Drawable badgedIcon =
-                    mIconDrawableFactory.getBadgedIcon(appResult.info, userHandle.getIdentifier());
+            Drawable badgedIcon = getBadgedIcon(appResult.info, userHandle.getIdentifier());
             iconView.setImageDrawable(badgedIcon);
             titleView.setContentDescription(
                     pm.getUserBadgedLabel(appResult.info.loadLabel(pm), userHandle));
@@ -112,4 +113,9 @@
         breadcrumbView.setText(breadcrumb);
         breadcrumbView.setVisibility(View.VISIBLE);
     }
+
+    @VisibleForTesting
+    Drawable getBadgedIcon(ApplicationInfo info, int userId) {
+        return mIconDrawableFactory.getBadgedIcon(info, userId);
+    }
 }
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/network/AirplaneModePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/AirplaneModePreferenceControllerTest.java
new file mode 100644
index 0000000..48c26f3
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/network/AirplaneModePreferenceControllerTest.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network;
+
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.content.res.Resources;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class AirplaneModePreferenceControllerTest {
+
+    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+    private Context mContext;
+
+    @Mock
+    private Resources mResources;
+
+    @Mock
+    private PreferenceScreen mScreen;
+
+    @Mock
+    private PackageManager mPackageManager;
+
+    private AirplaneModePreferenceController mController;
+    private Lifecycle mLifecycle;
+    private FakeFeatureFactory mFactory;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mFactory = FakeFeatureFactory.setupForTest(mContext);
+        doReturn(mResources).when(mContext).getResources();
+        doReturn(mPackageManager).when(mContext).getPackageManager();
+        mController = spy(new AirplaneModePreferenceController(mContext, null));
+        mLifecycle = new Lifecycle(() -> mLifecycle);
+        mLifecycle.addObserver(mController);
+    }
+
+    @Test
+    public void airplaneModePreference_shouldNotBeAvailable_ifHasLeanbackFeature() {
+        when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)).thenReturn(true);
+        assertFalse(mController.isAvailable());
+
+        mController.displayPreference(mScreen);
+
+        // This should not crash
+        mController.onResume();
+        mController.onPause();
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/search/AccessibilityServiceResultFutureTaskTest.java b/tests/robotests/src/com/android/settings/search/AccessibilityServiceResultFutureTaskTest.java
index 0e4abe1..456f820 100644
--- a/tests/robotests/src/com/android/settings/search/AccessibilityServiceResultFutureTaskTest.java
+++ b/tests/robotests/src/com/android/settings/search/AccessibilityServiceResultFutureTaskTest.java
@@ -28,6 +28,7 @@
 import android.content.pm.ServiceInfo;
 import android.graphics.Color;
 import android.graphics.drawable.ColorDrawable;
+import android.os.UserManager;
 import android.view.accessibility.AccessibilityManager;
 
 import com.android.settings.TestConfig;
@@ -46,7 +47,7 @@
 import java.util.List;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class AccessibilityServiceResultFutureTaskTest {
 
     private static final String QUERY = "test_query";
@@ -59,6 +60,8 @@
     private AccessibilityManager mAccessibilityManager;
     @Mock
     private SiteMapManager mSiteMapManager;
+    @Mock
+    private UserManager mUserManager;
 
     private AccessibilityServiceResultLoader.AccessibilityServiceResultCallable mCallable;
 
@@ -67,6 +70,7 @@
         MockitoAnnotations.initMocks(this);
         when(mContext.getSystemService(Context.ACCESSIBILITY_SERVICE))
                 .thenReturn(mAccessibilityManager);
+        when((Object)mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
         when(mContext.getPackageManager()).thenReturn(mPackageManager);
 
         mCallable = new AccessibilityServiceResultLoader.AccessibilityServiceResultCallable(
diff --git a/tests/robotests/src/com/android/settings/search/BaseSearchIndexProviderTest.java b/tests/robotests/src/com/android/settings/search/BaseSearchIndexProviderTest.java
index 6c6d7ab..4c19220 100644
--- a/tests/robotests/src/com/android/settings/search/BaseSearchIndexProviderTest.java
+++ b/tests/robotests/src/com/android/settings/search/BaseSearchIndexProviderTest.java
@@ -45,7 +45,7 @@
 import java.util.List;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class BaseSearchIndexProviderTest {
 
     private static final String TEST_PREF_KEY = "test_pref_key";
diff --git a/tests/robotests/src/com/android/settings/search/CursorToSearchResultConverterTest.java b/tests/robotests/src/com/android/settings/search/CursorToSearchResultConverterTest.java
index cd62c15..f862529 100644
--- a/tests/robotests/src/com/android/settings/search/CursorToSearchResultConverterTest.java
+++ b/tests/robotests/src/com/android/settings/search/CursorToSearchResultConverterTest.java
@@ -52,7 +52,7 @@
 import java.util.Set;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class CursorToSearchResultConverterTest {
 
     private static final List<String> TITLES = Arrays.asList("title1", "title2", "title3");
diff --git a/tests/robotests/src/com/android/settings/search/DatabaseIndexingManagerTest.java b/tests/robotests/src/com/android/settings/search/DatabaseIndexingManagerTest.java
index 20f58ad..7b5f474 100644
--- a/tests/robotests/src/com/android/settings/search/DatabaseIndexingManagerTest.java
+++ b/tests/robotests/src/com/android/settings/search/DatabaseIndexingManagerTest.java
@@ -70,7 +70,7 @@
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(
     manifest = TestConfig.MANIFEST_PATH,
-    sdk = TestConfig.SDK_VERSION,
+    sdk = TestConfig.SDK_VERSION_O,
     shadows = {
         ShadowRunnableAsyncTask.class,
     }
diff --git a/tests/robotests/src/com/android/settings/search/DatabaseIndexingUtilsTest.java b/tests/robotests/src/com/android/settings/search/DatabaseIndexingUtilsTest.java
index 94ce487..4b662b6 100644
--- a/tests/robotests/src/com/android/settings/search/DatabaseIndexingUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/search/DatabaseIndexingUtilsTest.java
@@ -35,7 +35,7 @@
 import java.util.Map;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class DatabaseIndexingUtilsTest {
 
     private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/search/InlineListPayloadTest.java b/tests/robotests/src/com/android/settings/search/InlineListPayloadTest.java
index fc15205..8194b12 100644
--- a/tests/robotests/src/com/android/settings/search/InlineListPayloadTest.java
+++ b/tests/robotests/src/com/android/settings/search/InlineListPayloadTest.java
@@ -14,7 +14,7 @@
 import static com.google.common.truth.Truth.assertThat;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class InlineListPayloadTest {
 
     private static final String DUMMY_SETTING = "inline_list_key";
diff --git a/tests/robotests/src/com/android/settings/search/InlinePayloadTest.java b/tests/robotests/src/com/android/settings/search/InlinePayloadTest.java
index 8bb558f..180e6a0 100644
--- a/tests/robotests/src/com/android/settings/search/InlinePayloadTest.java
+++ b/tests/robotests/src/com/android/settings/search/InlinePayloadTest.java
@@ -17,7 +17,7 @@
 import static com.google.common.truth.Truth.assertThat;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class InlinePayloadTest {
 
     private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/search/InlineSwitchPayloadTest.java b/tests/robotests/src/com/android/settings/search/InlineSwitchPayloadTest.java
index 64778a0..895bf9c 100644
--- a/tests/robotests/src/com/android/settings/search/InlineSwitchPayloadTest.java
+++ b/tests/robotests/src/com/android/settings/search/InlineSwitchPayloadTest.java
@@ -37,7 +37,7 @@
 import static com.google.common.truth.Truth.assertThat;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class InlineSwitchPayloadTest {
 
     private static final String DUMMY_SETTING = "inline_test";
diff --git a/tests/robotests/src/com/android/settings/search/InlineSwitchViewHolderTest.java b/tests/robotests/src/com/android/settings/search/InlineSwitchViewHolderTest.java
index 86aee6f..a2319f3 100644
--- a/tests/robotests/src/com/android/settings/search/InlineSwitchViewHolderTest.java
+++ b/tests/robotests/src/com/android/settings/search/InlineSwitchViewHolderTest.java
@@ -43,7 +43,7 @@
 import java.util.ArrayList;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class InlineSwitchViewHolderTest {
 
     private static final String TITLE = "title";
diff --git a/tests/robotests/src/com/android/settings/search/InputDeviceResultFutureTaskTest.java b/tests/robotests/src/com/android/settings/search/InputDeviceResultFutureTaskTest.java
index e31b3d7..73fe52c 100644
--- a/tests/robotests/src/com/android/settings/search/InputDeviceResultFutureTaskTest.java
+++ b/tests/robotests/src/com/android/settings/search/InputDeviceResultFutureTaskTest.java
@@ -56,7 +56,7 @@
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH,
-        sdk = TestConfig.SDK_VERSION,
+        sdk = TestConfig.SDK_VERSION_O,
         shadows = {
                 ShadowInputDevice.class
         })
diff --git a/tests/robotests/src/com/android/settings/search/InstalledAppResultLoaderTest.java b/tests/robotests/src/com/android/settings/search/InstalledAppResultLoaderTest.java
index 0e84dc7..1ed483d 100644
--- a/tests/robotests/src/com/android/settings/search/InstalledAppResultLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/search/InstalledAppResultLoaderTest.java
@@ -65,7 +65,7 @@
 import java.util.stream.Collectors;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class InstalledAppResultLoaderTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/search/IntentSearchViewHolderTest.java b/tests/robotests/src/com/android/settings/search/IntentSearchViewHolderTest.java
index 4ec080c..14fe63a 100644
--- a/tests/robotests/src/com/android/settings/search/IntentSearchViewHolderTest.java
+++ b/tests/robotests/src/com/android/settings/search/IntentSearchViewHolderTest.java
@@ -18,6 +18,8 @@
 package com.android.settings.search;
 
 import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.anyInt;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.doReturn;
@@ -32,8 +34,10 @@
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
+import android.graphics.drawable.ColorDrawable;
 import android.graphics.drawable.Drawable;
 import android.os.UserHandle;
+import android.os.UserManager;
 import android.view.LayoutInflater;
 import android.view.View;
 
@@ -58,7 +62,7 @@
 import java.util.Objects;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class IntentSearchViewHolderTest {
 
     private static final String TITLE = "title";
@@ -72,6 +76,8 @@
     private SearchFragment mFragment;
     @Mock
     private PackageManager mPackageManager;
+    @Mock
+    private UserManager mUserManager;
     private FakeFeatureFactory mFeatureFactory;
     private IntentSearchViewHolder mHolder;
     private Drawable mIcon;
@@ -189,6 +195,9 @@
 
     @Test
     public void testBindViewElements_appSearchResult() {
+        mHolder = spy(mHolder);
+        doReturn(new ColorDrawable(0)).when(mHolder).getBadgedIcon(any(ApplicationInfo.class),
+                anyInt());
         when(mPackageManager.getUserBadgedLabel(any(CharSequence.class),
                 eq(new UserHandle(USER_ID)))).thenReturn(BADGED_LABEL);
 
diff --git a/tests/robotests/src/com/android/settings/search/ResultPayloadTest.java b/tests/robotests/src/com/android/settings/search/ResultPayloadTest.java
index 0bb43c5..2d9d4aa 100644
--- a/tests/robotests/src/com/android/settings/search/ResultPayloadTest.java
+++ b/tests/robotests/src/com/android/settings/search/ResultPayloadTest.java
@@ -30,7 +30,7 @@
 import static com.google.common.truth.Truth.assertThat;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class ResultPayloadTest {
     private ResultPayload mPayload;
 
diff --git a/tests/robotests/src/com/android/settings/search/ResultPayloadUtilsTest.java b/tests/robotests/src/com/android/settings/search/ResultPayloadUtilsTest.java
index 50bdb84..a86089e 100644
--- a/tests/robotests/src/com/android/settings/search/ResultPayloadUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/search/ResultPayloadUtilsTest.java
@@ -30,7 +30,7 @@
 import static junit.framework.Assert.fail;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class ResultPayloadUtilsTest {
     private ResultPayload payload;
 
diff --git a/tests/robotests/src/com/android/settings/search/SavedQueryLoaderTest.java b/tests/robotests/src/com/android/settings/search/SavedQueryLoaderTest.java
index 780a8a5d..4142111 100644
--- a/tests/robotests/src/com/android/settings/search/SavedQueryLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/search/SavedQueryLoaderTest.java
@@ -38,7 +38,7 @@
 import static com.google.common.truth.Truth.assertThat;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SavedQueryLoaderTest {
 
     private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/search/SavedQueryPayloadTest.java b/tests/robotests/src/com/android/settings/search/SavedQueryPayloadTest.java
index 7421d1a..0845aa6 100644
--- a/tests/robotests/src/com/android/settings/search/SavedQueryPayloadTest.java
+++ b/tests/robotests/src/com/android/settings/search/SavedQueryPayloadTest.java
@@ -28,7 +28,7 @@
 import static com.google.common.truth.Truth.assertThat;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SavedQueryPayloadTest {
 
     private SavedQueryPayload mPayload;
diff --git a/tests/robotests/src/com/android/settings/search/SavedQueryRecorderAndRemoverTest.java b/tests/robotests/src/com/android/settings/search/SavedQueryRecorderAndRemoverTest.java
index af8cfe4..5e1de45 100644
--- a/tests/robotests/src/com/android/settings/search/SavedQueryRecorderAndRemoverTest.java
+++ b/tests/robotests/src/com/android/settings/search/SavedQueryRecorderAndRemoverTest.java
@@ -36,7 +36,7 @@
 import java.util.List;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SavedQueryRecorderAndRemoverTest {
 
     private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/search/SavedQueryViewHolderTest.java b/tests/robotests/src/com/android/settings/search/SavedQueryViewHolderTest.java
index bb8f6d1..0bb30e9 100644
--- a/tests/robotests/src/com/android/settings/search/SavedQueryViewHolderTest.java
+++ b/tests/robotests/src/com/android/settings/search/SavedQueryViewHolderTest.java
@@ -38,7 +38,7 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SavedQueryViewHolderTest {
 
     @Mock
diff --git a/tests/robotests/src/com/android/settings/search/SearchFragmentTest.java b/tests/robotests/src/com/android/settings/search/SearchFragmentTest.java
index a3f3334..f1f633c 100644
--- a/tests/robotests/src/com/android/settings/search/SearchFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/search/SearchFragmentTest.java
@@ -68,7 +68,7 @@
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH,
-        sdk = TestConfig.SDK_VERSION,
+        sdk = TestConfig.SDK_VERSION_O,
         shadows = {
                 SettingsShadowResources.class,
                 SettingsShadowResources.SettingsShadowTheme.class,
diff --git a/tests/robotests/src/com/android/settings/search/SearchIndexableResourcesTest.java b/tests/robotests/src/com/android/settings/search/SearchIndexableResourcesTest.java
index eedb324..90dba29 100644
--- a/tests/robotests/src/com/android/settings/search/SearchIndexableResourcesTest.java
+++ b/tests/robotests/src/com/android/settings/search/SearchIndexableResourcesTest.java
@@ -40,7 +40,7 @@
 import java.util.Set;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SearchIndexableResourcesTest {
 
     Set<Class> sProviderClassCopy;
diff --git a/tests/robotests/src/com/android/settings/search/SearchResultAggregatorTest.java b/tests/robotests/src/com/android/settings/search/SearchResultAggregatorTest.java
index 286d7cf9..4dc0589 100644
--- a/tests/robotests/src/com/android/settings/search/SearchResultAggregatorTest.java
+++ b/tests/robotests/src/com/android/settings/search/SearchResultAggregatorTest.java
@@ -31,7 +31,7 @@
 import java.util.concurrent.TimeUnit;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SearchResultAggregatorTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/search/SearchResultBuilderTest.java b/tests/robotests/src/com/android/settings/search/SearchResultBuilderTest.java
index cd77b25..6d38aa8 100644
--- a/tests/robotests/src/com/android/settings/search/SearchResultBuilderTest.java
+++ b/tests/robotests/src/com/android/settings/search/SearchResultBuilderTest.java
@@ -37,7 +37,7 @@
 import java.util.ArrayList;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SearchResultBuilderTest {
 
     private static final String TITLE = "title";
diff --git a/tests/robotests/src/com/android/settings/search/SearchResultsAdapterTest.java b/tests/robotests/src/com/android/settings/search/SearchResultsAdapterTest.java
index 4baf8d2..1dad447 100644
--- a/tests/robotests/src/com/android/settings/search/SearchResultsAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/search/SearchResultsAdapterTest.java
@@ -46,7 +46,7 @@
 import java.util.Objects;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SearchResultsAdapterTest {
 
     @Mock
diff --git a/tests/robotests/src/com/android/settings/search/SettingsSearchIndexablesProviderTest.java b/tests/robotests/src/com/android/settings/search/SettingsSearchIndexablesProviderTest.java
index efeaed7..ac70a63 100644
--- a/tests/robotests/src/com/android/settings/search/SettingsSearchIndexablesProviderTest.java
+++ b/tests/robotests/src/com/android/settings/search/SettingsSearchIndexablesProviderTest.java
@@ -27,7 +27,7 @@
 import java.util.Set;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SettingsSearchIndexablesProviderTest {
 
     private final String BASE_AUTHORITY = "com.android.settings";
diff --git a/tests/robotests/src/com/android/settings/search/StaticSearchResultFutureTaskTest.java b/tests/robotests/src/com/android/settings/search/StaticSearchResultFutureTaskTest.java
index e285555..31026fc 100644
--- a/tests/robotests/src/com/android/settings/search/StaticSearchResultFutureTaskTest.java
+++ b/tests/robotests/src/com/android/settings/search/StaticSearchResultFutureTaskTest.java
@@ -63,7 +63,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 StaticSearchResultFutureTaskTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/search/XmlParserUtilTest.java b/tests/robotests/src/com/android/settings/search/XmlParserUtilTest.java
index 6050b32..4a9baa1 100644
--- a/tests/robotests/src/com/android/settings/search/XmlParserUtilTest.java
+++ b/tests/robotests/src/com/android/settings/search/XmlParserUtilTest.java
@@ -43,7 +43,7 @@
  * with another preference with a matchin replacement attribute.
  */
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class XmlParserUtilTest {
 
     private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/search/indexing/IndexDataConverterTest.java b/tests/robotests/src/com/android/settings/search/indexing/IndexDataConverterTest.java
index 0f2ab56..58003c4 100644
--- a/tests/robotests/src/com/android/settings/search/indexing/IndexDataConverterTest.java
+++ b/tests/robotests/src/com/android/settings/search/indexing/IndexDataConverterTest.java
@@ -46,7 +46,7 @@
 import static org.mockito.Mockito.spy;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, qualifiers = "mcc999")
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O, qualifiers = "mcc999")
 public class IndexDataConverterTest {
 
     private final String localeStr = "en_US";
diff --git a/tests/robotests/src/com/android/settings/search/indexing/IndexDataTest.java b/tests/robotests/src/com/android/settings/search/indexing/IndexDataTest.java
index 1a05a2b..9fe647a 100644
--- a/tests/robotests/src/com/android/settings/search/indexing/IndexDataTest.java
+++ b/tests/robotests/src/com/android/settings/search/indexing/IndexDataTest.java
@@ -36,7 +36,7 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class IndexDataTest {
     private IndexData.Builder mBuilder;
 
diff --git a/tests/robotests/src/com/android/settings/search/indexing/PreIndexDataCollectorTest.java b/tests/robotests/src/com/android/settings/search/indexing/PreIndexDataCollectorTest.java
index 2bb03cb..ef16a37 100644
--- a/tests/robotests/src/com/android/settings/search/indexing/PreIndexDataCollectorTest.java
+++ b/tests/robotests/src/com/android/settings/search/indexing/PreIndexDataCollectorTest.java
@@ -46,7 +46,7 @@
 import static org.mockito.Mockito.spy;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class PreIndexDataCollectorTest {
 
     private final String AUTHORITY_ONE = "authority";
diff --git a/tests/robotests/src/com/android/settings/suggestions/SettingsSuggestionsTest.java b/tests/robotests/src/com/android/settings/suggestions/SettingsSuggestionsTest.java
index 677bf41..4f0bee2 100644
--- a/tests/robotests/src/com/android/settings/suggestions/SettingsSuggestionsTest.java
+++ b/tests/robotests/src/com/android/settings/suggestions/SettingsSuggestionsTest.java
@@ -41,7 +41,7 @@
 import java.util.Map;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SettingsSuggestionsTest {
 
     private static final String CATEGORY_FIRST_IMPRESSION =
diff --git a/tests/robotests/src/com/android/settings/users/UserFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/users/UserFeatureProviderImplTest.java
index e1bc157..8c10c31 100644
--- a/tests/robotests/src/com/android/settings/users/UserFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/users/UserFeatureProviderImplTest.java
@@ -37,7 +37,7 @@
 import static org.mockito.Mockito.when;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class UserFeatureProviderImplTest {
     public static final int FIRST_USER_ID = 0;
     public static final int SECOND_USER_ID = 4;
diff --git a/tests/robotests/src/com/android/settings/users/UserPreferenceTest.java b/tests/robotests/src/com/android/settings/users/UserPreferenceTest.java
index 5b31a82..242604a 100644
--- a/tests/robotests/src/com/android/settings/users/UserPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/users/UserPreferenceTest.java
@@ -38,7 +38,7 @@
 import org.robolectric.util.ReflectionHelpers;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class UserPreferenceTest {
 
     @Mock
diff --git a/tests/robotests/src/com/android/settings/users/UserSettingsTest.java b/tests/robotests/src/com/android/settings/users/UserSettingsTest.java
index 56f3949..28b8c86 100644
--- a/tests/robotests/src/com/android/settings/users/UserSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/users/UserSettingsTest.java
@@ -40,7 +40,7 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class UserSettingsTest {
 
     @Mock private UserManager mUserManager;
diff --git a/tests/robotests/src/com/android/settings/utils/LocalClassLoaderContextThemeWrapperTest.java b/tests/robotests/src/com/android/settings/utils/LocalClassLoaderContextThemeWrapperTest.java
index 690c292..ac6dc02 100644
--- a/tests/robotests/src/com/android/settings/utils/LocalClassLoaderContextThemeWrapperTest.java
+++ b/tests/robotests/src/com/android/settings/utils/LocalClassLoaderContextThemeWrapperTest.java
@@ -32,7 +32,7 @@
 import static com.google.common.truth.Truth.assertThat;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class LocalClassLoaderContextThemeWrapperTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/vpn2/AppDialogFragmentTest.java b/tests/robotests/src/com/android/settings/vpn2/AppDialogFragmentTest.java
index 4b4f3fb..587a82a 100644
--- a/tests/robotests/src/com/android/settings/vpn2/AppDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/vpn2/AppDialogFragmentTest.java
@@ -33,7 +33,7 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class AppDialogFragmentTest {
 
     @Mock
diff --git a/tests/robotests/src/com/android/settings/vpn2/VpnUtilsTest.java b/tests/robotests/src/com/android/settings/vpn2/VpnUtilsTest.java
index 9442892..5a029c7 100644
--- a/tests/robotests/src/com/android/settings/vpn2/VpnUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/vpn2/VpnUtilsTest.java
@@ -32,7 +32,7 @@
  * Tests for {@link VpnUtils}.
  */
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public final class VpnUtilsTest {
     @Test
     public void testIsAlwaysOnVpnSet() {
diff --git a/tests/robotests/src/com/android/settings/webview/WebViewAppPickerTest.java b/tests/robotests/src/com/android/settings/webview/WebViewAppPickerTest.java
index 470b69c..d06980b 100644
--- a/tests/robotests/src/com/android/settings/webview/WebViewAppPickerTest.java
+++ b/tests/robotests/src/com/android/settings/webview/WebViewAppPickerTest.java
@@ -17,7 +17,9 @@
 package com.android.settings.webview;
 
 import static android.provider.Settings.ACTION_WEBVIEW_SETTINGS;
+
 import static com.google.common.truth.Truth.assertThat;
+
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyInt;
 import static org.mockito.Matchers.eq;
@@ -43,7 +45,6 @@
 import com.android.settings.TestConfig;
 import com.android.settings.applications.defaultapps.DefaultAppInfo;
 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
-import com.android.settings.testutils.FakeFeatureFactory;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.widget.RadioButtonPreference;
 import com.android.settings.wrapper.UserPackageWrapper;
@@ -62,16 +63,16 @@
 import java.util.Arrays;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class WebViewAppPickerTest {
-    private Context mContext = RuntimeEnvironment.application;
+    private Context mContext;
 
     private UserInfo mFirstUser;
     private UserInfo mSecondUser;
 
     private final static String DEFAULT_PACKAGE_NAME = "DEFAULT_PACKAGE_NAME";
 
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+    @Mock
     private Activity mActivity;
     @Mock
     private UserManager mUserManager;
@@ -90,8 +91,8 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        FakeFeatureFactory.setupForTest(mActivity);
-        when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
+        mContext = spy(RuntimeEnvironment.application);
+        doReturn(mUserManager).when(mContext).getSystemService(Context.USER_SERVICE);
         mFirstUser = new UserInfo(0, "FIRST_USER", 0);
         mSecondUser = new UserInfo(0, "SECOND_USER", 0);
         mPicker = new WebViewAppPicker();
@@ -168,7 +169,7 @@
     @Test
     public void testDisabledPackageShownAsDisabled() {
         String disabledReason = "disabled";
-        DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mActivity, mPackageManager,
+        DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mContext, mPackageManager,
                 createApplicationInfo(DEFAULT_PACKAGE_NAME), disabledReason);
 
         RadioButtonPreference mockPreference = mock(RadioButtonPreference.class);
@@ -183,7 +184,7 @@
     @Test
     public void testEnabledPackageShownAsEnabled() {
         String disabledReason = "";
-        DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mActivity, mPackageManager,
+        DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mContext, mPackageManager,
                 createApplicationInfo(DEFAULT_PACKAGE_NAME), disabledReason);
 
         RadioButtonPreference mockPreference = mock(RadioButtonPreference.class);
@@ -198,7 +199,7 @@
     @Test
     public void testDisabledPackageShowsDisabledReasonSummary() {
         String disabledReason = "disabled";
-        DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mActivity, mPackageManager,
+        DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mContext, mPackageManager,
                 createApplicationInfo(DEFAULT_PACKAGE_NAME), disabledReason);
 
         RadioButtonPreference mockPreference = mock(RadioButtonPreference.class);
@@ -214,7 +215,7 @@
     @Test
     public void testEnabledPackageShowsEmptySummary() {
         String disabledReason = null;
-        DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mActivity, mPackageManager,
+        DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mContext, mPackageManager,
                 createApplicationInfo(DEFAULT_PACKAGE_NAME), disabledReason);
 
         RadioButtonPreference mockPreference = mock(RadioButtonPreference.class);
@@ -228,14 +229,14 @@
     @Test
     public void testFinishIfNotAdmin() {
         doReturn(false).when(mUserManager).isAdminUser();
-        mPicker.onAttach((Context) mActivity);
+        mPicker.onAttach(mContext);
         verify(mActivity, times(1)).finish();
     }
 
     @Test
     public void testNotFinishedIfAdmin() {
         doReturn(true).when(mUserManager).isAdminUser();
-        mPicker.onAttach((Context) mActivity);
+        mPicker.onAttach(mContext);
         verify(mActivity, never()).finish();
     }
 
@@ -348,7 +349,7 @@
         PackageItemInfo mockPackageItemInfo = mock(PackageItemInfo.class);
         mockPackageItemInfo.packageName = DEFAULT_PACKAGE_NAME;
         when(mockPackageItemInfo.loadLabel(any())).thenReturn("myPackage");
-        DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mActivity, mPackageManager,
+        DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mContext, mPackageManager,
                 mockPackageItemInfo, "" /* disabledReason */);
 
         PackageInfo packageInfo = new PackageInfo();
diff --git a/tests/robotests/src/com/android/settings/wfd/WifiDisplaySettingsTest.java b/tests/robotests/src/com/android/settings/wfd/WifiDisplaySettingsTest.java
index 7d8ee52..a65bd3b 100644
--- a/tests/robotests/src/com/android/settings/wfd/WifiDisplaySettingsTest.java
+++ b/tests/robotests/src/com/android/settings/wfd/WifiDisplaySettingsTest.java
@@ -42,7 +42,7 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class WifiDisplaySettingsTest {
 
     @Mock