Merge "Hack to wait for both suggestion/category to load"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 05c5075..07908e5 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -178,6 +178,7 @@
         </activity>
 
         <activity android:name=".Settings$ConnectedDeviceDashboardActivity"
+            android:enabled="false"
             android:taskAffinity="com.android.settings"
             android:label="@string/connected_devices_dashboard_title"
             android:icon="@drawable/ic_devices_other"
diff --git a/proguard.flags b/proguard.flags
index 7a403a4..d644f47 100644
--- a/proguard.flags
+++ b/proguard.flags
@@ -39,21 +39,3 @@
     public static ** SEARCH_INDEX_DATA_PROVIDER;
     public static ** SUMMARY_PROVIDER_FACTORY;
 }
-
-# Keep classes, annotations and members used by Lifecycle
--keepattributes *Annotation*
-
--keepclassmembers enum android.arch.lifecycle.Lifecycle$Event {
-    <fields>;
-}
-
--keep class * implements android.arch.lifecycle.LifecycleObserver {
-}
-
--keep class * implements android.arch.lifecycle.GeneratedAdapter {
-    <init>(...);
-}
-
--keepclassmembers class ** {
-    @android.arch.lifecycle.OnLifecycleEvent *;
-}
diff --git a/res/xml/connected_devices.xml b/res/xml/connected_devices.xml
index 5417051..227dee2 100644
--- a/res/xml/connected_devices.xml
+++ b/res/xml/connected_devices.xml
@@ -37,6 +37,7 @@
         settings:allowDividerAbove="true"/>
 
     <Preference
+        android:fragment="com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment"
         android:key="connection_preferences"
         android:title="@string/connected_device_connections_title"
         settings:allowDividerAbove="true"/>
diff --git a/res/xml/connected_devices_advanced.xml b/res/xml/connected_devices_advanced.xml
new file mode 100644
index 0000000..946151f
--- /dev/null
+++ b/res/xml/connected_devices_advanced.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2017 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<PreferenceScreen
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:key="connected_devices_screen"
+    android:title="@string/connected_devices_dashboard_title">
+
+    <com.android.settings.widget.MasterSwitchPreference
+      android:key="toggle_bluetooth"
+      android:title="@string/bluetooth_settings_title"
+      android:icon="@drawable/ic_settings_bluetooth"
+      android:order="-7"/>
+
+    <SwitchPreference
+        android:key="toggle_nfc"
+        android:title="@string/nfc_quick_toggle_title"
+        android:icon="@drawable/ic_nfc"
+        android:summary="@string/nfc_quick_toggle_summary"
+        android:order="-5"/>
+
+    <com.android.settingslib.RestrictedPreference
+        android:fragment="com.android.settings.nfc.AndroidBeam"
+        android:key="android_beam_settings"
+        android:title="@string/android_beam_settings_title"
+        android:icon="@drawable/ic_android"
+        android:order="-4"/>
+
+    <Preference
+        android:key="sms_mirroring"
+        android:title="@string/sms_mirroring_pref"
+        android:icon="@drawable/ic_sms_mirroring_24dp"
+        android:summary="@string/summary_placeholder"
+        android:order="-3"/>
+
+    <Preference
+        android:key="usb_mode"
+        android:title="@string/usb_pref"
+        android:icon="@drawable/ic_usb"
+        android:order="-2">
+        <intent android:action="android.intent.action.MAIN"
+                android:targetPackage="com.android.settings"
+                android:targetClass="com.android.settings.deviceinfo.UsbModeChooserActivity"/>
+    </Preference>
+
+    <Preference
+        android:key="bt_received_files"
+        android:icon="@drawable/ic_folder_vd_theme_24"
+        android:title="@string/bluetooth_show_received_files" />
+
+    <PreferenceCategory
+        android:key="dashboard_tile_placeholder"
+        android:order="50"/>
+
+</PreferenceScreen>
diff --git a/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceDashboardFragment.java b/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceDashboardFragment.java
new file mode 100644
index 0000000..ea93fef
--- /dev/null
+++ b/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceDashboardFragment.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.connecteddevice;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.provider.SearchIndexableResource;
+
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.R;
+import com.android.settings.SettingsActivity;
+import com.android.settings.bluetooth.BluetoothFilesPreferenceController;
+import com.android.settings.bluetooth.BluetoothMasterSwitchPreferenceController;
+import com.android.settings.bluetooth.Utils;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.deviceinfo.UsbBackend;
+import com.android.settings.nfc.NfcPreferenceController;
+import com.android.settings.overlay.FeatureFactory;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.drawer.CategoryKey;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * This fragment contains all the advanced connection preferences(i.e, Bluetooth, NFC, USB..)
+ */
+public class AdvancedConnectedDeviceDashboardFragment extends DashboardFragment {
+
+    private static final String TAG = "AdvancedConnectedDeviceFrag";
+    private UsbModePreferenceController mUsbPrefController;
+
+    @Override
+    public int getMetricsCategory() {
+        return MetricsProto.MetricsEvent.CONNECTION_DEVICE_ADVANCED;
+    }
+
+    @Override
+    protected String getLogTag() {
+        return TAG;
+    }
+
+    @Override
+    public int getHelpResource() {
+        return R.string.help_url_connected_devices;
+    }
+
+    @Override
+    protected int getPreferenceScreenResId() {
+        return R.xml.connected_devices_advanced;
+    }
+
+    @Override
+    public String getCategoryKey() {
+        //TODO(b/69926683): remove this method and change DashboardFragmentRegistry directly for P
+        return CategoryKey.CATEGORY_DEVICE;
+    }
+
+    @Override
+    protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
+        final List<AbstractPreferenceController> controllers = new ArrayList<>();
+        final Lifecycle lifecycle = getLifecycle();
+        final NfcPreferenceController nfcPreferenceController =
+                new NfcPreferenceController(context);
+        lifecycle.addObserver(nfcPreferenceController);
+        controllers.add(nfcPreferenceController);
+        mUsbPrefController = new UsbModePreferenceController(context, new UsbBackend(context));
+        lifecycle.addObserver(mUsbPrefController);
+        controllers.add(mUsbPrefController);
+        final BluetoothMasterSwitchPreferenceController bluetoothPreferenceController =
+                new BluetoothMasterSwitchPreferenceController(
+                        context, Utils.getLocalBtManager(context), this,
+                        (SettingsActivity) getActivity());
+        lifecycle.addObserver(bluetoothPreferenceController);
+        controllers.add(bluetoothPreferenceController);
+
+        SmsMirroringFeatureProvider smsMirroringFeatureProvider =
+                FeatureFactory.getFactory(context).getSmsMirroringFeatureProvider();
+        AbstractPreferenceController smsMirroringController =
+                smsMirroringFeatureProvider.getController(context);
+        controllers.add(smsMirroringController);
+        controllers.add(new BluetoothFilesPreferenceController(context));
+        return controllers;
+    }
+
+    /**
+     * For Search.
+     */
+    public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+            new BaseSearchIndexProvider() {
+                @Override
+                public List<SearchIndexableResource> getXmlResourcesToIndex(
+                        Context context, boolean enabled) {
+                    final SearchIndexableResource sir = new SearchIndexableResource(context);
+                    sir.xmlResId = R.xml.connected_devices_advanced;
+                    return Arrays.asList(sir);
+                }
+
+                @Override
+                public List<String> getNonIndexableKeys(Context context) {
+                    final List<String> keys = super.getNonIndexableKeys(context);
+                    PackageManager pm = context.getPackageManager();
+                    if (!pm.hasSystemFeature(PackageManager.FEATURE_NFC)) {
+                        keys.add(NfcPreferenceController.KEY_TOGGLE_NFC);
+                        keys.add(NfcPreferenceController.KEY_ANDROID_BEAM_SETTINGS);
+                    }
+                    keys.add(BluetoothMasterSwitchPreferenceController.KEY_TOGGLE_BLUETOOTH);
+
+                    SmsMirroringFeatureProvider smsMirroringFeatureProvider =
+                            FeatureFactory.getFactory(context).getSmsMirroringFeatureProvider();
+                    SmsMirroringPreferenceController smsMirroringController =
+                            smsMirroringFeatureProvider.getController(context);
+                    smsMirroringController.updateNonIndexableKeys(keys);
+
+                    return keys;
+                }
+            };
+}
diff --git a/src/com/android/settings/deviceinfo/SimStatus.java b/src/com/android/settings/deviceinfo/SimStatus.java
index 768beb8..dad4419 100644
--- a/src/com/android/settings/deviceinfo/SimStatus.java
+++ b/src/com/android/settings/deviceinfo/SimStatus.java
@@ -408,6 +408,12 @@
         if (!mShowLatestAreaInfo) {
             removePreferenceFromScreen(KEY_LATEST_AREA_INFO);
         }
+
+        boolean hideSignalStrength = carrierConfig.getBoolean(
+                CarrierConfigManager.KEY_HIDE_SIGNAL_STRENGTH_IN_SIM_STATUS_BOOL);
+        if (hideSignalStrength) {
+            removePreferenceFromScreen(KEY_SIGNAL_STRENGTH);
+        }
     }
 
     private void updatePhoneInfos() {
diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java
index 1f88872..c4e178f 100644
--- a/src/com/android/settings/search/SearchIndexableResources.java
+++ b/src/com/android/settings/search/SearchIndexableResources.java
@@ -33,6 +33,7 @@
 import com.android.settings.backup.BackupSettingsActivity;
 import com.android.settings.backup.BackupSettingsFragment;
 import com.android.settings.bluetooth.BluetoothSettings;
+import com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment;
 import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
 import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragmentOld;
 import com.android.settings.datausage.DataUsageMeteredSettings;
@@ -155,6 +156,7 @@
         addIndex(StorageDashboardFragment.class);
         addIndex(ConnectedDeviceDashboardFragment.class);
         addIndex(ConnectedDeviceDashboardFragmentOld.class);
+        addIndex(AdvancedConnectedDeviceDashboardFragment.class);
         addIndex(EnterprisePrivacySettings.class);
         addIndex(PaymentSettings.class);
         addIndex(TextToSpeechSettings.class);
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceDashboardFragmentTest.java
new file mode 100644
index 0000000..bb35911
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceDashboardFragmentTest.java
@@ -0,0 +1,163 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+package com.android.settings.connecteddevice;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.provider.SearchIndexableResource;
+
+import com.android.settings.TestConfig;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.nfc.NfcPreferenceController;
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.XmlTestUtils;
+import com.android.settingslib.drawer.CategoryKey;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import java.util.List;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class AdvancedConnectedDeviceDashboardFragmentTest {
+
+    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+    Context mContext;
+
+    @Mock
+    private PackageManager mManager;
+
+    private FakeFeatureFactory mFeatureFactory;
+    private SmsMirroringFeatureProvider mFeatureProvider;
+    private AdvancedConnectedDeviceDashboardFragment mFragment;
+    private TestSmsMirroringPreferenceController mSmsMirroringPreferenceController;
+
+    private static final class TestSmsMirroringPreferenceController
+            extends SmsMirroringPreferenceController implements PreferenceControllerMixin {
+
+        private boolean mIsAvailable;
+
+        public TestSmsMirroringPreferenceController(Context context) {
+            super(context);
+        }
+
+        @Override
+        public boolean isAvailable() {
+            return mIsAvailable;
+        }
+    }
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        FakeFeatureFactory.setupForTest(mContext);
+        mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+        mFeatureProvider = mFeatureFactory.smsMirroringFeatureProvider;
+
+        mFragment = new AdvancedConnectedDeviceDashboardFragment();
+        when(mContext.getPackageManager()).thenReturn(mManager);
+
+        mSmsMirroringPreferenceController = new TestSmsMirroringPreferenceController(mContext);
+        when(mFeatureProvider.getController(mContext)).thenReturn(
+                mSmsMirroringPreferenceController);
+    }
+
+    @Test
+    public void testCategory_isConnectedDevice() {
+        assertThat(mFragment.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_DEVICE);
+    }
+
+    @Test
+    public void testSearchIndexProvider_shouldIndexResource() {
+        final List<SearchIndexableResource> indexRes =
+                mFragment.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(mContext,
+                        true /* enabled */);
+
+        assertThat(indexRes).isNotNull();
+        assertThat(indexRes.get(0).xmlResId).isEqualTo(mFragment.getPreferenceScreenResId());
+    }
+
+    @Test
+    public void testSearchIndexProvider_NoNfc_KeyAdded() {
+        when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(false);
+        final List<String> keys = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
+                mContext);
+
+        assertThat(keys).isNotNull();
+        assertThat(keys).contains(NfcPreferenceController.KEY_TOGGLE_NFC);
+        assertThat(keys).contains(NfcPreferenceController.KEY_ANDROID_BEAM_SETTINGS);
+    }
+
+    @Test
+    public void testSearchIndexProvider_NFC_KeyNotAdded() {
+        when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(true);
+        final List<String> keys = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
+                mContext);
+
+        assertThat(keys).isNotNull();
+        assertThat(keys).doesNotContain(NfcPreferenceController.KEY_TOGGLE_NFC);
+        assertThat(keys).doesNotContain(NfcPreferenceController.KEY_ANDROID_BEAM_SETTINGS);
+    }
+
+    @Test
+    public void testSearchIndexProvider_NoSmsMirroring_KeyAdded() {
+        when(mFeatureProvider.shouldShowSmsMirroring(mContext)).thenReturn(false);
+        mSmsMirroringPreferenceController.mIsAvailable = false;
+
+        final List<String> keys = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
+                mContext);
+
+        assertThat(keys).isNotNull();
+        assertThat(keys).contains(mSmsMirroringPreferenceController.getPreferenceKey());
+    }
+
+    @Test
+    public void testSearchIndexProvider_SmsMirroring_KeyNotAdded() {
+        when(mFeatureProvider.shouldShowSmsMirroring(mContext)).thenReturn(true);
+        mSmsMirroringPreferenceController.mIsAvailable = true;
+
+        final List<String> keys = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
+                mContext);
+
+        assertThat(keys).isNotNull();
+        assertThat(keys).doesNotContain(mSmsMirroringPreferenceController.getPreferenceKey());
+    }
+
+    @Test
+    public void testNonIndexableKeys_existInXmlLayout() {
+        final Context context = RuntimeEnvironment.application;
+        when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(false);
+        final List<String> niks = ConnectedDeviceDashboardFragment.SEARCH_INDEX_DATA_PROVIDER
+                .getNonIndexableKeys(mContext);
+        final int xmlId = (new ConnectedDeviceDashboardFragment()).getPreferenceScreenResId();
+
+        final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId);
+
+        assertThat(keys).containsAllIn(niks);
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java
index 7d47fc2..fe640d2 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java
@@ -17,6 +17,7 @@
 package com.android.settings.deviceinfo.storage;
 
 import static com.google.common.truth.Truth.assertThat;
+
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.mock;
@@ -34,6 +35,7 @@
 import android.support.v7.preference.PreferenceScreen;
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.internal.os.RoSystemProperties;
 import com.android.settings.TestConfig;
 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
 import com.android.settings.deletionhelper.ActivationWarningFragment;
@@ -52,13 +54,14 @@
 import org.mockito.MockitoAnnotations;
 import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
 
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(
-    manifest = TestConfig.MANIFEST_PATH,
-    sdk = TestConfig.SDK_VERSION,
-    shadows = {SettingsShadowSystemProperties.class}
+        manifest = TestConfig.MANIFEST_PATH,
+        sdk = TestConfig.SDK_VERSION_O,
+        shadows = {SettingsShadowSystemProperties.class}
 )
 public class AutomaticStorageManagementSwitchPreferenceControllerTest {
 
@@ -79,13 +82,14 @@
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         mContext = RuntimeEnvironment.application.getApplicationContext();
-        FeatureFactory factory = FeatureFactory.getFactory(mContext);
+        final FeatureFactory factory = FeatureFactory.getFactory(mContext);
         mMetricsFeature = factory.getMetricsFeatureProvider();
 
         mController = new AutomaticStorageManagementSwitchPreferenceController(
                 mContext, mMetricsFeature, mFragmentManager);
         when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
     }
+
     @After
     public void tearDown() {
         SettingsShadowSystemProperties.clear();
@@ -98,15 +102,15 @@
 
     @Test
     public void isAvailable_shouldAlwaysReturnFalse_forLowRamDevice() {
-        SettingsShadowSystemProperties.set("ro.config.low_ram", "true");
+        ReflectionHelpers.setStaticField(RoSystemProperties.class, "CONFIG_LOW_RAM", true);
         assertThat(mController.isAvailable()).isFalse();
-        SettingsShadowSystemProperties.clear();
+        ReflectionHelpers.setStaticField(RoSystemProperties.class, "CONFIG_LOW_RAM", false);
     }
 
     @Test
     public void onResume_shouldReflectEnabledStatus() {
         mController.displayPreference(mScreen);
-        ContentResolver resolver = mContext.getContentResolver();
+        final ContentResolver resolver = mContext.getContentResolver();
         Settings.Secure.putInt(resolver, Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 1);
 
         mController.onResume();
@@ -128,9 +132,9 @@
         // FakeFeatureFactory uses mock contexts, so this test scaffolds itself rather than using
         // the instance variables.
         FakeFeatureFactory.setupForTest(mMockContext);
-        FakeFeatureFactory factory =
+        final FakeFeatureFactory factory =
                 (FakeFeatureFactory) FakeFeatureFactory.getFactory(mMockContext);
-        AutomaticStorageManagementSwitchPreferenceController controller =
+        final AutomaticStorageManagementSwitchPreferenceController controller =
                 new AutomaticStorageManagementSwitchPreferenceController(
                         mMockContext, factory.metricsFeatureProvider, mFragmentManager);
 
@@ -144,15 +148,15 @@
     public void togglingShouldUpdateSettingsSecure() {
         mController.onSwitchToggled(true);
 
-        ContentResolver resolver = mContext.getContentResolver();
+        final ContentResolver resolver = mContext.getContentResolver();
         assertThat(Settings.Secure.getInt(
                 resolver, Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 0)).isNotEqualTo(0);
     }
 
     @Test
     public void togglingOnShouldTriggerWarningFragment() {
-        FragmentTransaction transaction = mock(FragmentTransaction.class);
-        when (mFragmentManager.beginTransaction()).thenReturn(transaction);
+        final FragmentTransaction transaction = mock(FragmentTransaction.class);
+        when(mFragmentManager.beginTransaction()).thenReturn(transaction);
         SettingsShadowSystemProperties.set(
                 AutomaticStorageManagementSwitchPreferenceController
                         .STORAGE_MANAGER_ENABLED_BY_DEFAULT_PROPERTY, "false");
@@ -164,8 +168,8 @@
 
     @Test
     public void togglingOffShouldTriggerWarningFragment() {
-        FragmentTransaction transaction = mock(FragmentTransaction.class);
-        when (mFragmentManager.beginTransaction()).thenReturn(transaction);
+        final FragmentTransaction transaction = mock(FragmentTransaction.class);
+        when(mFragmentManager.beginTransaction()).thenReturn(transaction);
 
         mController.onSwitchToggled(false);
 
@@ -175,8 +179,8 @@
 
     @Test
     public void togglingOnShouldNotTriggerWarningFragmentIfEnabledByDefault() {
-        FragmentTransaction transaction = mock(FragmentTransaction.class);
-        when (mFragmentManager.beginTransaction()).thenReturn(transaction);
+        final FragmentTransaction transaction = mock(FragmentTransaction.class);
+        when(mFragmentManager.beginTransaction()).thenReturn(transaction);
         SettingsShadowSystemProperties.set(
                 AutomaticStorageManagementSwitchPreferenceController
                         .STORAGE_MANAGER_ENABLED_BY_DEFAULT_PROPERTY, "true");
@@ -188,7 +192,7 @@
 
     @Test
     public void togglingOnShouldTriggerWarningFragmentIfEnabledByDefaultAndDisabledByPolicy() {
-        FragmentTransaction transaction = mock(FragmentTransaction.class);
+        final FragmentTransaction transaction = mock(FragmentTransaction.class);
         when(mFragmentManager.beginTransaction()).thenReturn(transaction);
         SettingsShadowSystemProperties.set(
                 AutomaticStorageManagementSwitchPreferenceController
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/CachedStorageValuesHelperTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/CachedStorageValuesHelperTest.java
index 154a7a1..7b3556f 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/CachedStorageValuesHelperTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/CachedStorageValuesHelperTest.java
@@ -55,7 +55,7 @@
 import static com.google.common.truth.Truth.assertThat;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class CachedStorageValuesHelperTest {
     private Context mContext;
 
@@ -94,7 +94,7 @@
                 .putLong(TIMESTAMP_KEY, 10000L)
                 .apply();
 
-        PrivateStorageInfo info = mCachedValuesHelper.getCachedPrivateStorageInfo();
+        final PrivateStorageInfo info = mCachedValuesHelper.getCachedPrivateStorageInfo();
 
         assertThat(info.freeBytes).isEqualTo(1000L);
         assertThat(info.totalBytes).isEqualTo(6000L);
@@ -122,7 +122,7 @@
                 .putLong(TIMESTAMP_KEY, 10000L)
                 .apply();
 
-        SparseArray<StorageAsyncLoader.AppsStorageResult> result =
+        final SparseArray<StorageAsyncLoader.AppsStorageResult> result =
                 mCachedValuesHelper.getCachedAppsStorageResult();
 
         StorageAsyncLoader.AppsStorageResult primaryResult = result.get(0);
@@ -161,7 +161,7 @@
                 .putLong(TIMESTAMP_KEY, 10000L)
                 .apply();
 
-        PrivateStorageInfo info = mCachedValuesHelper.getCachedPrivateStorageInfo();
+        final PrivateStorageInfo info = mCachedValuesHelper.getCachedPrivateStorageInfo();
         assertThat(info).isNull();
     }
 
@@ -187,7 +187,7 @@
                 .putLong(TIMESTAMP_KEY, 10000L)
                 .apply();
 
-        SparseArray<StorageAsyncLoader.AppsStorageResult> result =
+        final SparseArray<StorageAsyncLoader.AppsStorageResult> result =
                 mCachedValuesHelper.getCachedAppsStorageResult();
         assertThat(result).isNull();
     }
@@ -214,7 +214,7 @@
                 .putLong(TIMESTAMP_KEY, 10000L)
                 .apply();
 
-        PrivateStorageInfo info = mCachedValuesHelper.getCachedPrivateStorageInfo();
+        final PrivateStorageInfo info = mCachedValuesHelper.getCachedPrivateStorageInfo();
         assertThat(info).isNull();
     }
 
@@ -240,20 +240,20 @@
                 .putLong(TIMESTAMP_KEY, 10000L)
                 .apply();
 
-        SparseArray<StorageAsyncLoader.AppsStorageResult> result =
+        final SparseArray<StorageAsyncLoader.AppsStorageResult> result =
                 mCachedValuesHelper.getCachedAppsStorageResult();
         assertThat(result).isNull();
     }
 
     @Test
     public void getCachedPrivateStorageInfo_nullIfEmpty() throws Exception {
-        PrivateStorageInfo info = mCachedValuesHelper.getCachedPrivateStorageInfo();
+        final PrivateStorageInfo info = mCachedValuesHelper.getCachedPrivateStorageInfo();
         assertThat(info).isNull();
     }
 
     @Test
     public void getCachedAppsStorageResult_nullIfEmpty() throws Exception {
-        SparseArray<StorageAsyncLoader.AppsStorageResult> result =
+        final SparseArray<StorageAsyncLoader.AppsStorageResult> result =
                 mCachedValuesHelper.getCachedAppsStorageResult();
         assertThat(result).isNull();
     }
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java
index f068397..804c6dc 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java
@@ -21,6 +21,7 @@
 import static com.google.common.truth.Truth.assertThat;
 
 import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
@@ -55,7 +56,7 @@
 import java.util.List;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SecondaryUserControllerTest {
     private static final String TEST_NAME = "Fred";
     private static final String TARGET_PREFERENCE_GROUP_KEY = "pref_secondary_users";
@@ -90,7 +91,7 @@
 
         final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
         verify(mGroup).addPreference(argumentCaptor.capture());
-        Preference preference = argumentCaptor.getValue();
+        final Preference preference = argumentCaptor.getValue();
         assertThat(preference.getTitle()).isEqualTo(TEST_NAME);
     }
 
@@ -103,17 +104,17 @@
 
         verify(mGroup).addPreference(argumentCaptor.capture());
 
-        Preference preference = argumentCaptor.getValue();
+        final Preference preference = argumentCaptor.getValue();
         assertThat(preference.getSummary()).isEqualTo("0.01 GB");
     }
 
     @Test
     public void noSecondaryUserAddedIfNoneExist() throws Exception {
-        ArrayList<UserInfo> userInfos = new ArrayList<>();
+        final ArrayList<UserInfo> userInfos = new ArrayList<>();
         userInfos.add(mPrimaryUser);
         when(mUserManager.getPrimaryUser()).thenReturn(mPrimaryUser);
         when(mUserManager.getUsers()).thenReturn(userInfos);
-        List<AbstractPreferenceController> controllers =
+        final List<AbstractPreferenceController> controllers =
                 SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager);
 
         assertThat(controllers).hasSize(1);
@@ -123,15 +124,15 @@
 
     @Test
     public void secondaryUserAddedIfHasDistinctId() throws Exception {
-        ArrayList<UserInfo> userInfos = new ArrayList<>();
-        UserInfo secondaryUser = new UserInfo();
+        final ArrayList<UserInfo> userInfos = new ArrayList<>();
+        final UserInfo secondaryUser = new UserInfo();
         secondaryUser.id = 10;
         secondaryUser.profileGroupId = 101010; // this just has to be something not 0
         userInfos.add(mPrimaryUser);
         userInfos.add(secondaryUser);
         when(mUserManager.getPrimaryUser()).thenReturn(mPrimaryUser);
         when(mUserManager.getUsers()).thenReturn(userInfos);
-        List<AbstractPreferenceController> controllers =
+        final List<AbstractPreferenceController> controllers =
                 SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager);
 
         assertThat(controllers).hasSize(1);
@@ -140,15 +141,15 @@
 
     @Test
     public void profilesOfPrimaryUserAreNotIgnored() throws Exception {
-        ArrayList<UserInfo> userInfos = new ArrayList<>();
-        UserInfo secondaryUser = new UserInfo();
+        final ArrayList<UserInfo> userInfos = new ArrayList<>();
+        final UserInfo secondaryUser = new UserInfo();
         secondaryUser.id = mPrimaryUser.id;
         userInfos.add(mPrimaryUser);
         userInfos.add(secondaryUser);
         when(mUserManager.getPrimaryUser()).thenReturn(mPrimaryUser);
         when(mUserManager.getUsers()).thenReturn(userInfos);
 
-        List<AbstractPreferenceController> controllers =
+        final List<AbstractPreferenceController> controllers =
                 SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager);
 
         assertThat(controllers).hasSize(2);
@@ -161,9 +162,9 @@
         mPrimaryUser.name = TEST_NAME;
         mPrimaryUser.id = 10;
         mController.displayPreference(mScreen);
-        StorageAsyncLoader.AppsStorageResult userResult =
+        final StorageAsyncLoader.AppsStorageResult userResult =
                 new StorageAsyncLoader.AppsStorageResult();
-        SparseArray<StorageAsyncLoader.AppsStorageResult> result = new SparseArray<>();
+        final SparseArray<StorageAsyncLoader.AppsStorageResult> result = new SparseArray<>();
         userResult.externalStats =
                 new StorageStatsSource.ExternalStorageStats(
                         MEGABYTE_IN_BYTES * 30,
@@ -175,23 +176,23 @@
         mController.handleResult(result);
         final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
         verify(mGroup).addPreference(argumentCaptor.capture());
-        Preference preference = argumentCaptor.getValue();
+        final Preference preference = argumentCaptor.getValue();
 
         assertThat(preference.getSummary()).isEqualTo("0.03 GB");
     }
 
     @Test
     public void dontAddPrimaryProfileAsASecondaryProfile() throws Exception {
-        ArrayList<UserInfo> userInfos = new ArrayList<>();
+        final ArrayList<UserInfo> userInfos = new ArrayList<>();
         // The primary UserInfo may be a different object with a different name... but represent the
         // same user!
-        UserInfo primaryUserRenamed = new UserInfo();
+        final UserInfo primaryUserRenamed = new UserInfo();
         primaryUserRenamed.name = "Owner";
         primaryUserRenamed.flags = UserInfo.FLAG_PRIMARY;
         userInfos.add(primaryUserRenamed);
         when(mUserManager.getPrimaryUser()).thenReturn(mPrimaryUser);
         when(mUserManager.getUsers()).thenReturn(userInfos);
-        List<AbstractPreferenceController> controllers =
+        final List<AbstractPreferenceController> controllers =
                 SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager);
 
         assertThat(controllers).hasSize(1);
@@ -201,34 +202,29 @@
 
     @Test
     public void iconCallbackChangesPreferenceIcon() throws Exception {
-        SparseArray<Drawable> icons = new SparseArray<>();
-        Bitmap userBitmap =
-                BitmapFactory.decodeResource(
-                        RuntimeEnvironment.application.getResources(), R.drawable.home);
-        UserIconDrawable drawable = new UserIconDrawable(100 /* size */).setIcon(userBitmap).bake();
-        icons.put(10, drawable);
+        final SparseArray<Drawable> icons = new SparseArray<>();
+        final UserIconDrawable drawable = mock(UserIconDrawable.class);
+        when(drawable.mutate()).thenReturn(drawable);
         mPrimaryUser.name = TEST_NAME;
         mPrimaryUser.id = 10;
+        icons.put(mPrimaryUser.id, drawable);
         mController.displayPreference(mScreen);
 
         mController.handleUserIcons(icons);
 
         final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
         verify(mGroup).addPreference(argumentCaptor.capture());
-        Preference preference = argumentCaptor.getValue();
+        final Preference preference = argumentCaptor.getValue();
         assertThat(preference.getIcon()).isEqualTo(drawable);
     }
 
     @Test
     public void setIcon_doesntNpeOnNullPreference() throws Exception {
-        SparseArray<Drawable> icons = new SparseArray<>();
-        Bitmap userBitmap =
-                BitmapFactory.decodeResource(
-                        RuntimeEnvironment.application.getResources(), R.drawable.home);
-        UserIconDrawable drawable = new UserIconDrawable(100 /* size */).setIcon(userBitmap).bake();
-        icons.put(10, drawable);
+        final SparseArray<Drawable> icons = new SparseArray<>();
+        final UserIconDrawable drawable = mock(UserIconDrawable.class);
         mPrimaryUser.name = TEST_NAME;
         mPrimaryUser.id = 10;
+        icons.put(mPrimaryUser.id, drawable);
 
         mController.handleUserIcons(icons);
 
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
index e6c161e..a1a48ae 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
@@ -28,7 +28,10 @@
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
+import android.app.Activity;
 import android.app.Fragment;
+import android.app.FragmentManager;
+import android.app.FragmentTransaction;
 import android.content.Context;
 import android.content.Intent;
 import android.graphics.drawable.Drawable;
@@ -67,14 +70,20 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class StorageItemPreferenceControllerTest {
     private Context mContext;
     private VolumeInfo mVolume;
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+    @Mock
     private Fragment mFragment;
     @Mock
     private StorageVolumeProvider mSvp;
+    @Mock
+    private Activity mActivity;
+    @Mock
+    private FragmentManager mFragmentManager;
+    @Mock
+    private FragmentTransaction mFragmentTransaction;
     private StorageItemPreferenceController mController;
     private StorageItemPreference mPreference;
     private FakeFeatureFactory mFakeFeatureFactory;
@@ -83,6 +92,9 @@
     @Before
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
+        when(mFragment.getActivity()).thenReturn(mActivity);
+        when(mFragment.getFragmentManager()).thenReturn(mFragmentManager);
+        when(mFragmentManager.beginTransaction()).thenReturn(mFragmentTransaction);
         mContext = spy(RuntimeEnvironment.application.getApplicationContext());
         FakeFeatureFactory.setupForTest(mContext);
         mFakeFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
@@ -94,7 +106,7 @@
         mPreference = new StorageItemPreference(mContext);
 
         // Inflate the preference and the widget.
-        LayoutInflater inflater = LayoutInflater.from(mContext);
+        final LayoutInflater inflater = LayoutInflater.from(mContext);
         final View view = inflater.inflate(
                 mPreference.getLayoutResource(), new LinearLayout(mContext), false);
     }
@@ -116,10 +128,10 @@
         mController.handlePreferenceTreeClick(mPreference);
 
         final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
-        verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
+        verify(mActivity).startActivityAsUser(argumentCaptor.capture(),
                 nullable(UserHandle.class));
 
-        Intent intent = argumentCaptor.getValue();
+        final Intent intent = argumentCaptor.getValue();
         assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
         assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
         assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
@@ -136,7 +148,7 @@
         final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
         verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
                 nullable(UserHandle.class));
-        Intent intent = argumentCaptor.getValue();
+        final Intent intent = argumentCaptor.getValue();
 
         assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
         assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
@@ -164,7 +176,7 @@
         verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
                 nullable(UserHandle.class));
 
-        Intent intent = argumentCaptor.getValue();
+        final Intent intent = argumentCaptor.getValue();
         assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
         assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
         assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT)).isEqualTo(
@@ -273,14 +285,14 @@
 
     @Test
     public void testMeasurementCompletedUpdatesPreferences() {
-        StorageItemPreference audio = new StorageItemPreference(mContext);
-        StorageItemPreference image = new StorageItemPreference(mContext);
-        StorageItemPreference games = new StorageItemPreference(mContext);
-        StorageItemPreference movies = new StorageItemPreference(mContext);
-        StorageItemPreference apps = new StorageItemPreference(mContext);
-        StorageItemPreference system = new StorageItemPreference(mContext);
-        StorageItemPreference files = new StorageItemPreference(mContext);
-        PreferenceScreen screen = mock(PreferenceScreen.class);
+        final StorageItemPreference audio = new StorageItemPreference(mContext);
+        final StorageItemPreference image = new StorageItemPreference(mContext);
+        final StorageItemPreference games = new StorageItemPreference(mContext);
+        final StorageItemPreference movies = new StorageItemPreference(mContext);
+        final StorageItemPreference apps = new StorageItemPreference(mContext);
+        final StorageItemPreference system = new StorageItemPreference(mContext);
+        final StorageItemPreference files = new StorageItemPreference(mContext);
+        final PreferenceScreen screen = mock(PreferenceScreen.class);
         when(screen.findPreference(
                 eq(StorageItemPreferenceController.AUDIO_KEY))).thenReturn(audio);
         when(screen.findPreference(
@@ -298,7 +310,7 @@
         mController.displayPreference(screen);
 
         mController.setUsedSize(MEGABYTE_IN_BYTES * 970); // There should 870MB attributed.
-        StorageAsyncLoader.AppsStorageResult result = new StorageAsyncLoader.AppsStorageResult();
+        final StorageAsyncLoader.AppsStorageResult result = new StorageAsyncLoader.AppsStorageResult();
         result.gamesSize = MEGABYTE_IN_BYTES * 80;
         result.videoAppsSize = MEGABYTE_IN_BYTES * 160;
         result.musicAppsSize = MEGABYTE_IN_BYTES * 40;
@@ -310,7 +322,7 @@
                         MEGABYTE_IN_BYTES * 150, // video
                         MEGABYTE_IN_BYTES * 200, 0); // image
 
-        SparseArray<StorageAsyncLoader.AppsStorageResult> results = new SparseArray<>();
+        final SparseArray<StorageAsyncLoader.AppsStorageResult> results = new SparseArray<>();
         results.put(0, result);
         mController.onLoadFinished(results, 0);
 
@@ -324,21 +336,21 @@
 
     @Test
     public void settingUserIdAppliesNewIcons() {
-        StorageItemPreference audio = spy(new StorageItemPreference(mContext));
+        final StorageItemPreference audio = spy(new StorageItemPreference(mContext));
         audio.setIcon(R.drawable.ic_media_stream);
-        StorageItemPreference video = spy(new StorageItemPreference(mContext));
+        final StorageItemPreference video = spy(new StorageItemPreference(mContext));
         video.setIcon(R.drawable.ic_local_movies);
-        StorageItemPreference image = spy(new StorageItemPreference(mContext));
+        final StorageItemPreference image = spy(new StorageItemPreference(mContext));
         image.setIcon(R.drawable.ic_photo_library);
-        StorageItemPreference games = spy(new StorageItemPreference(mContext));
+        final StorageItemPreference games = spy(new StorageItemPreference(mContext));
         games.setIcon(R.drawable.ic_videogame_vd_theme_24);
-        StorageItemPreference apps = spy(new StorageItemPreference(mContext));
+        final StorageItemPreference apps = spy(new StorageItemPreference(mContext));
         apps.setIcon(R.drawable.ic_storage_apps);
-        StorageItemPreference system = spy(new StorageItemPreference(mContext));
+        final StorageItemPreference system = spy(new StorageItemPreference(mContext));
         system.setIcon(R.drawable.ic_system_update_vd_theme_24);
-        StorageItemPreference files = spy(new StorageItemPreference(mContext));
+        final StorageItemPreference files = spy(new StorageItemPreference(mContext));
         files.setIcon(R.drawable.ic_folder_vd_theme_24);
-        PreferenceScreen screen = mock(PreferenceScreen.class);
+        final PreferenceScreen screen = mock(PreferenceScreen.class);
         when(screen.findPreference(
                 eq(StorageItemPreferenceController.AUDIO_KEY))).thenReturn(audio);
         when(screen.findPreference(
@@ -368,13 +380,13 @@
 
     @Test
     public void displayPreference_dontHideFilePreferenceWhenEmulatedInternalStorageUsed() {
-        StorageItemPreference audio = new StorageItemPreference(mContext);
-        StorageItemPreference image = new StorageItemPreference(mContext);
-        StorageItemPreference games = new StorageItemPreference(mContext);
-        StorageItemPreference apps = new StorageItemPreference(mContext);
-        StorageItemPreference system = new StorageItemPreference(mContext);
-        StorageItemPreference files = new StorageItemPreference(mContext);
-        PreferenceScreen screen = mock(PreferenceScreen.class);
+        final StorageItemPreference audio = new StorageItemPreference(mContext);
+        final StorageItemPreference image = new StorageItemPreference(mContext);
+        final StorageItemPreference games = new StorageItemPreference(mContext);
+        final StorageItemPreference apps = new StorageItemPreference(mContext);
+        final StorageItemPreference system = new StorageItemPreference(mContext);
+        final StorageItemPreference files = new StorageItemPreference(mContext);
+        final PreferenceScreen screen = mock(PreferenceScreen.class);
         when(screen.findPreference(eq(StorageItemPreferenceController.AUDIO_KEY)))
                 .thenReturn(audio);
         when(screen.findPreference(eq(StorageItemPreferenceController.PHOTO_KEY)))
@@ -397,13 +409,13 @@
 
     @Test
     public void displayPreference_hideFilePreferenceWhenEmulatedStorageUnreadable() {
-        StorageItemPreference audio = new StorageItemPreference(mContext);
-        StorageItemPreference image = new StorageItemPreference(mContext);
-        StorageItemPreference games = new StorageItemPreference(mContext);
-        StorageItemPreference apps = new StorageItemPreference(mContext);
-        StorageItemPreference system = new StorageItemPreference(mContext);
-        StorageItemPreference files = new StorageItemPreference(mContext);
-        PreferenceScreen screen = mock(PreferenceScreen.class);
+        final StorageItemPreference audio = new StorageItemPreference(mContext);
+        final StorageItemPreference image = new StorageItemPreference(mContext);
+        final StorageItemPreference games = new StorageItemPreference(mContext);
+        final StorageItemPreference apps = new StorageItemPreference(mContext);
+        final StorageItemPreference system = new StorageItemPreference(mContext);
+        final StorageItemPreference files = new StorageItemPreference(mContext);
+        final PreferenceScreen screen = mock(PreferenceScreen.class);
         when(screen.findPreference(eq(StorageItemPreferenceController.AUDIO_KEY)))
                 .thenReturn(audio);
         when(screen.findPreference(eq(StorageItemPreferenceController.PHOTO_KEY)))
@@ -426,13 +438,13 @@
 
     @Test
     public void displayPreference_hideFilePreferenceWhenNoEmulatedInternalStorage() {
-        StorageItemPreference audio = new StorageItemPreference(mContext);
-        StorageItemPreference image = new StorageItemPreference(mContext);
-        StorageItemPreference games = new StorageItemPreference(mContext);
-        StorageItemPreference apps = new StorageItemPreference(mContext);
-        StorageItemPreference system = new StorageItemPreference(mContext);
-        StorageItemPreference files = new StorageItemPreference(mContext);
-        PreferenceScreen screen = mock(PreferenceScreen.class);
+        final StorageItemPreference audio = new StorageItemPreference(mContext);
+        final StorageItemPreference image = new StorageItemPreference(mContext);
+        final StorageItemPreference games = new StorageItemPreference(mContext);
+        final StorageItemPreference apps = new StorageItemPreference(mContext);
+        final StorageItemPreference system = new StorageItemPreference(mContext);
+        final StorageItemPreference files = new StorageItemPreference(mContext);
+        final PreferenceScreen screen = mock(PreferenceScreen.class);
         when(screen.findPreference(eq(StorageItemPreferenceController.AUDIO_KEY)))
                 .thenReturn(audio);
         when(screen.findPreference(eq(StorageItemPreferenceController.PHOTO_KEY)))
@@ -454,13 +466,13 @@
 
     @Test
     public void displayPreference_updateFilePreferenceToHideAfterSettingVolume() {
-        StorageItemPreference audio = new StorageItemPreference(mContext);
-        StorageItemPreference image = new StorageItemPreference(mContext);
-        StorageItemPreference games = new StorageItemPreference(mContext);
-        StorageItemPreference apps = new StorageItemPreference(mContext);
-        StorageItemPreference system = new StorageItemPreference(mContext);
-        StorageItemPreference files = new StorageItemPreference(mContext);
-        PreferenceScreen screen = mock(PreferenceScreen.class);
+        final StorageItemPreference audio = new StorageItemPreference(mContext);
+        final StorageItemPreference image = new StorageItemPreference(mContext);
+        final StorageItemPreference games = new StorageItemPreference(mContext);
+        final StorageItemPreference apps = new StorageItemPreference(mContext);
+        final StorageItemPreference system = new StorageItemPreference(mContext);
+        final StorageItemPreference files = new StorageItemPreference(mContext);
+        final PreferenceScreen screen = mock(PreferenceScreen.class);
         when(screen.findPreference(eq(StorageItemPreferenceController.AUDIO_KEY)))
                 .thenReturn(audio);
         when(screen.findPreference(eq(StorageItemPreferenceController.PHOTO_KEY)))
@@ -486,13 +498,13 @@
 
     @Test
     public void displayPreference_updateFilePreferenceToShowAfterSettingVolume() {
-        StorageItemPreference audio = new StorageItemPreference(mContext);
-        StorageItemPreference image = new StorageItemPreference(mContext);
-        StorageItemPreference games = new StorageItemPreference(mContext);
-        StorageItemPreference apps = new StorageItemPreference(mContext);
-        StorageItemPreference system = new StorageItemPreference(mContext);
-        StorageItemPreference files = new StorageItemPreference(mContext);
-        PreferenceScreen screen = mock(PreferenceScreen.class);
+        final StorageItemPreference audio = new StorageItemPreference(mContext);
+        final StorageItemPreference image = new StorageItemPreference(mContext);
+        final StorageItemPreference games = new StorageItemPreference(mContext);
+        final StorageItemPreference apps = new StorageItemPreference(mContext);
+        final StorageItemPreference system = new StorageItemPreference(mContext);
+        final StorageItemPreference files = new StorageItemPreference(mContext);
+        final PreferenceScreen screen = mock(PreferenceScreen.class);
         when(screen.findPreference(eq(StorageItemPreferenceController.AUDIO_KEY)))
                 .thenReturn(audio);
         when(screen.findPreference(eq(StorageItemPreferenceController.PHOTO_KEY)))
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceControllerTest.java
index 8ebfb89..1c1824d 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceControllerTest.java
@@ -28,6 +28,7 @@
 import android.content.Context;
 import android.os.storage.VolumeInfo;
 import android.support.v7.preference.PreferenceViewHolder;
+import android.text.format.Formatter;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.widget.Button;
@@ -56,11 +57,11 @@
 import static com.android.settings.TestUtils.GIGABYTE;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
         shadows = {
-        SettingsShadowResources.class,
-        SettingsShadowResources.SettingsShadowTheme.class
-})
+                SettingsShadowResources.class,
+                SettingsShadowResources.SettingsShadowTheme.class
+        })
 public class StorageSummaryDonutPreferenceControllerTest {
     private Context mContext;
     private StorageSummaryDonutPreferenceController mController;
@@ -94,43 +95,62 @@
 
     @Test
     public void testEmpty() throws Exception {
+        final long totalSpace = 32 * GIGABYTE;
+        final long usedSpace = 0;
         mController.updateBytes(0, 32 * GIGABYTE);
         mController.updateState(mPreference);
 
-        assertThat(mPreference.getTitle().toString()).isEqualTo("0.00 B");
-        assertThat(mPreference.getSummary().toString()).isEqualTo("Used of 32 GB");
+        final Formatter.BytesResult usedSpaceResults = Formatter.formatBytes(
+                mContext.getResources(), usedSpace, 0 /* flags */);
+        assertThat(mPreference.getTitle().toString()).isEqualTo(
+                usedSpaceResults.value + " " + usedSpaceResults.units);
+        assertThat(mPreference.getSummary().toString()).isEqualTo(
+                "Used of " + Formatter.formatShortFileSize(mContext, totalSpace));
     }
 
     @Test
     public void testTotalStorage() throws Exception {
-        mController.updateBytes(KILOBYTE, KILOBYTE * 10);
+        final long totalSpace = KILOBYTE * 10;
+        final long usedSpace = KILOBYTE;
+        mController.updateBytes(KILOBYTE, totalSpace);
         mController.updateState(mPreference);
 
-        assertThat(mPreference.getTitle().toString()).isEqualTo("1.00 KB");
-        assertThat(mPreference.getSummary().toString()).isEqualTo("Used of 10 KB");
+        final Formatter.BytesResult usedSpaceResults = Formatter.formatBytes(
+                mContext.getResources(), usedSpace, 0 /* flags */);
+        assertThat(mPreference.getTitle().toString()).isEqualTo(
+                usedSpaceResults.value + " " + usedSpaceResults.units);
+        assertThat(mPreference.getSummary().toString()).isEqualTo(
+                "Used of " + Formatter.formatShortFileSize(mContext, totalSpace));
     }
 
     @Test
     public void testPopulateWithVolume() throws Exception {
-        VolumeInfo volume = Mockito.mock(VolumeInfo.class);
-        File file = Mockito.mock(File.class);
-        StorageVolumeProvider svp = Mockito.mock(StorageVolumeProvider.class);
+        final long totalSpace = KILOBYTE * 10;
+        final long freeSpace = KILOBYTE;
+        final long usedSpace = totalSpace - freeSpace;
+        final VolumeInfo volume = Mockito.mock(VolumeInfo.class);
+        final File file = Mockito.mock(File.class);
+        final StorageVolumeProvider svp = Mockito.mock(StorageVolumeProvider.class);
         when(volume.getPath()).thenReturn(file);
-        when(file.getTotalSpace()).thenReturn(KILOBYTE * 10);
-        when(file.getFreeSpace()).thenReturn(KILOBYTE);
-        when(svp.getPrimaryStorageSize()).thenReturn(KILOBYTE * 10);
+        when(file.getTotalSpace()).thenReturn(totalSpace);
+        when(file.getFreeSpace()).thenReturn(freeSpace);
+        when(svp.getPrimaryStorageSize()).thenReturn(totalSpace);
 
         mController.updateSizes(svp, volume);
         mController.updateState(mPreference);
 
-        assertThat(mPreference.getTitle().toString()).isEqualTo("9.00 KB");
-        assertThat(mPreference.getSummary().toString()).isEqualTo("Used of 10 KB");
+        final Formatter.BytesResult usedSpaceResults = Formatter.formatBytes(
+                mContext.getResources(), usedSpace, 0 /* flags */);
+        assertThat(mPreference.getTitle().toString()).isEqualTo(
+                usedSpaceResults.value + " " + usedSpaceResults.units);
+        assertThat(mPreference.getSummary().toString()).isEqualTo(
+                "Used of " + Formatter.formatShortFileSize(mContext, totalSpace));
     }
 
     @Test
     public void testFreeUpSpaceMetricIsTriggered() throws Exception {
         mPreference.onBindViewHolder(mHolder);
-        Button button = (Button) mHolder.findViewById(R.id.deletion_helper_button);
+        final Button button = (Button) mHolder.findViewById(R.id.deletion_helper_button);
 
         mPreference.onClick(button);
 
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/UserProfileControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/UserProfileControllerTest.java
index 8da5260..98e796e 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/UserProfileControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/UserProfileControllerTest.java
@@ -19,6 +19,7 @@
 import static com.google.common.truth.Truth.assertThat;
 import static com.android.settings.utils.FileSizeFormatter.MEGABYTE_IN_BYTES;
 
+import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -53,7 +54,7 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class UserProfileControllerTest {
     private static final String TEST_NAME = "Fred";
 
@@ -82,7 +83,7 @@
     public void controllerAddsPrimaryProfilePreference() throws Exception {
         final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
         verify(mScreen).addPreference(argumentCaptor.capture());
-        Preference preference = argumentCaptor.getValue();
+        final Preference preference = argumentCaptor.getValue();
 
         assertThat(preference.getTitle()).isEqualTo(TEST_NAME);
         assertThat(preference.getKey()).isEqualTo("pref_profile_10");
@@ -93,12 +94,12 @@
 
         final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
         verify(mScreen).addPreference(argumentCaptor.capture());
-        Preference preference = argumentCaptor.getValue();
+        final Preference preference = argumentCaptor.getValue();
         assertThat(mController.handlePreferenceTreeClick(preference)).isTrue();
         final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
         verify(mContext).startActivity(intentCaptor.capture());
 
-        Intent intent = intentCaptor.getValue();
+        final Intent intent = intentCaptor.getValue();
         assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
         assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT)).isEqualTo(
                 StorageProfileFragment.class.getName());
@@ -106,8 +107,8 @@
 
     @Test
     public void acceptingResultUpdatesPreferenceSize() throws Exception {
-        SparseArray<StorageAsyncLoader.AppsStorageResult> result = new SparseArray<>();
-        StorageAsyncLoader.AppsStorageResult userResult =
+        final SparseArray<StorageAsyncLoader.AppsStorageResult> result = new SparseArray<>();
+        final StorageAsyncLoader.AppsStorageResult userResult =
                 new StorageAsyncLoader.AppsStorageResult();
         userResult.externalStats =
                 new StorageStatsSource.ExternalStorageStats(
@@ -120,25 +121,23 @@
         mController.handleResult(result);
         final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
         verify(mScreen).addPreference(argumentCaptor.capture());
-        Preference preference = argumentCaptor.getValue();
+        final Preference preference = argumentCaptor.getValue();
 
         assertThat(preference.getSummary()).isEqualTo("0.10 GB");
     }
 
     @Test
     public void iconCallbackChangesPreferenceIcon() throws Exception {
-        SparseArray<Drawable> icons = new SparseArray<>();
-        Bitmap userBitmap =
-                BitmapFactory.decodeResource(
-                        RuntimeEnvironment.application.getResources(), R.drawable.home);
-        UserIconDrawable drawable = new UserIconDrawable(100 /* size */).setIcon(userBitmap).bake();
-        icons.put(10, drawable);
+        final SparseArray<Drawable> icons = new SparseArray<>();
+        final UserIconDrawable drawable = mock(UserIconDrawable.class);
+        when(drawable.mutate()).thenReturn(drawable);
+        icons.put(mPrimaryProfile.id, drawable);
 
         mController.handleUserIcons(icons);
 
         final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
         verify(mScreen).addPreference(argumentCaptor.capture());
-        Preference preference = argumentCaptor.getValue();
+        final Preference preference = argumentCaptor.getValue();
         assertThat(preference.getIcon()).isEqualTo(drawable);
     }
 }
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowBidiFormatter.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowBidiFormatter.java
new file mode 100644
index 0000000..66d7338
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowBidiFormatter.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.testutils.shadow;
+
+import android.support.v4.text.BidiFormatter;
+import android.support.v4.text.TextDirectionHeuristicCompat;
+
+import org.robolectric.annotation.Implements;
+
+@Implements(BidiFormatter.class)
+public class ShadowBidiFormatter {
+
+    public CharSequence unicodeWrap(CharSequence str, TextDirectionHeuristicCompat heuristic,
+            boolean isolate) {
+        return str;
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/wifi/CellularFallbackPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/CellularFallbackPreferenceControllerTest.java
index 415cd92..84d73c1 100644
--- a/tests/robotests/src/com/android/settings/wifi/CellularFallbackPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/CellularFallbackPreferenceControllerTest.java
@@ -34,7 +34,7 @@
 import static org.mockito.Mockito.when;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class CellularFallbackPreferenceControllerTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/wifi/ConfigureWifiSettingsTest.java b/tests/robotests/src/com/android/settings/wifi/ConfigureWifiSettingsTest.java
index 687287b..3cd5ee8 100644
--- a/tests/robotests/src/com/android/settings/wifi/ConfigureWifiSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/ConfigureWifiSettingsTest.java
@@ -23,7 +23,7 @@
 import java.util.List;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class ConfigureWifiSettingsTest {
 
     private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/wifi/ConnectedAccessPointPreferenceTest.java b/tests/robotests/src/com/android/settings/wifi/ConnectedAccessPointPreferenceTest.java
index 2eaa587..5a38c4e 100644
--- a/tests/robotests/src/com/android/settings/wifi/ConnectedAccessPointPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/ConnectedAccessPointPreferenceTest.java
@@ -37,7 +37,7 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class ConnectedAccessPointPreferenceTest {
     @Mock
     private AccessPoint mAccessPoint;
diff --git a/tests/robotests/src/com/android/settings/wifi/LinkablePreferenceTest.java b/tests/robotests/src/com/android/settings/wifi/LinkablePreferenceTest.java
index 9321827..f8d8428 100644
--- a/tests/robotests/src/com/android/settings/wifi/LinkablePreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/LinkablePreferenceTest.java
@@ -38,7 +38,7 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class LinkablePreferenceTest {
 
     private static final String TITLE = "Title";
diff --git a/tests/robotests/src/com/android/settings/wifi/NotifyOpenNetworkPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/NotifyOpenNetworkPreferenceControllerTest.java
index b83a3e3..f1299f4 100644
--- a/tests/robotests/src/com/android/settings/wifi/NotifyOpenNetworkPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/NotifyOpenNetworkPreferenceControllerTest.java
@@ -40,7 +40,7 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class NotifyOpenNetworkPreferenceControllerTest {
 
     private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/wifi/SavedAccessPointsWifiSettingsTest.java b/tests/robotests/src/com/android/settings/wifi/SavedAccessPointsWifiSettingsTest.java
index ec406cd..d157615 100644
--- a/tests/robotests/src/com/android/settings/wifi/SavedAccessPointsWifiSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/SavedAccessPointsWifiSettingsTest.java
@@ -37,7 +37,7 @@
 import static org.mockito.Mockito.*;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class SavedAccessPointsWifiSettingsTest {
 
     @Mock private WifiManagerWrapper mockWifiManager;
diff --git a/tests/robotests/src/com/android/settings/wifi/UseOpenWifiPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/UseOpenWifiPreferenceControllerTest.java
index 16d883a..851c4c2 100644
--- a/tests/robotests/src/com/android/settings/wifi/UseOpenWifiPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/UseOpenWifiPreferenceControllerTest.java
@@ -58,7 +58,7 @@
 import java.util.List;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class UseOpenWifiPreferenceControllerTest {
     private static ComponentName sEnableActivityComponent;
     private static NetworkScorerAppData sAppData;
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java
index e9b6146..7cef9ce 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java
@@ -41,7 +41,7 @@
 import static org.mockito.Mockito.*;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
         shadows = ShadowConnectivityManager.class)
 public class WifiConfigControllerTest {
 
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiDialogTest.java b/tests/robotests/src/com/android/settings/wifi/WifiDialogTest.java
index 00941ad..1460c33 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiDialogTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiDialogTest.java
@@ -21,7 +21,7 @@
 
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
         shadows = ShadowEntityHeaderController.class)
 public class WifiDialogTest {
     @Mock private AccessPoint mockAccessPoint;
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiEnablerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiEnablerTest.java
index 63f89e6..b9dbae5 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiEnablerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiEnablerTest.java
@@ -38,7 +38,7 @@
 import static org.mockito.Mockito.when;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class WifiEnablerTest {
 
     @Mock
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiInfoPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiInfoPreferenceControllerTest.java
index cf3cca7..7582143 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiInfoPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiInfoPreferenceControllerTest.java
@@ -46,7 +46,7 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class WifiInfoPreferenceControllerTest {
 
     @Mock
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiMasterSwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiMasterSwitchPreferenceControllerTest.java
index 307cccb..8523cea 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiMasterSwitchPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiMasterSwitchPreferenceControllerTest.java
@@ -45,7 +45,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 WifiMasterSwitchPreferenceControllerTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiSummaryUpdaterTest.java b/tests/robotests/src/com/android/settings/wifi/WifiSummaryUpdaterTest.java
index 4507e54..a9757bd 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiSummaryUpdaterTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiSummaryUpdaterTest.java
@@ -44,7 +44,7 @@
 import static org.mockito.Mockito.verify;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class WifiSummaryUpdaterTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiUtilsTest.java b/tests/robotests/src/com/android/settings/wifi/WifiUtilsTest.java
index 1ccdb1f..3cdcee4 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiUtilsTest.java
@@ -27,7 +27,7 @@
 import static com.google.common.truth.Truth.assertThat;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class WifiUtilsTest {
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java
index 29df539..07f2d30 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java
@@ -46,7 +46,7 @@
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(
         manifest = TestConfig.MANIFEST_PATH,
-        sdk = TestConfig.SDK_VERSION,
+        sdk = TestConfig.SDK_VERSION_O,
         shadows = { SettingsShadowResources.class })
 public class WifiWakeupPreferenceControllerTest {
 
diff --git a/tests/robotests/src/com/android/settings/wifi/WpsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WpsPreferenceControllerTest.java
index 7a734e5..21488e8 100644
--- a/tests/robotests/src/com/android/settings/wifi/WpsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WpsPreferenceControllerTest.java
@@ -48,7 +48,7 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class WpsPreferenceControllerTest {
 
     @Mock
diff --git a/tests/robotests/src/com/android/settings/wifi/WriteWifiConfigToNfcDialogTest.java b/tests/robotests/src/com/android/settings/wifi/WriteWifiConfigToNfcDialogTest.java
index 5e10e0f..4fc118a 100644
--- a/tests/robotests/src/com/android/settings/wifi/WriteWifiConfigToNfcDialogTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WriteWifiConfigToNfcDialogTest.java
@@ -42,7 +42,7 @@
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(
         manifest = TestConfig.MANIFEST_PATH,
-        sdk = TestConfig.SDK_VERSION,
+        sdk = TestConfig.SDK_VERSION_O,
         shadows = ShadowNfcAdapter.class
 )
 public class WriteWifiConfigToNfcDialogTest {
diff --git a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java
index 3a0341c..64d9f59 100644
--- a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java
@@ -66,6 +66,7 @@
 import com.android.settings.applications.LayoutPreference;
 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.ShadowBidiFormatter;
 import com.android.settings.testutils.shadow.ShadowDevicePolicyManagerWrapper;
 import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
 import com.android.settings.testutils.shadow.ShadowPackageManagerWrapper;
@@ -97,11 +98,12 @@
 import java.util.stream.Collectors;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
         shadows = {
                 ShadowDevicePolicyManagerWrapper.class,
                 ShadowEntityHeaderController.class,
                 ShadowPackageManagerWrapper.class,
+                ShadowBidiFormatter.class
         })
 public class WifiDetailPreferenceControllerTest {
 
diff --git a/tests/robotests/src/com/android/settings/wifi/p2p/P2pThisDevicePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/p2p/P2pThisDevicePreferenceControllerTest.java
index 62fd01f..02017f7 100644
--- a/tests/robotests/src/com/android/settings/wifi/p2p/P2pThisDevicePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/p2p/P2pThisDevicePreferenceControllerTest.java
@@ -37,7 +37,7 @@
 import static org.mockito.Mockito.when;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class P2pThisDevicePreferenceControllerTest {
 
     @Mock
diff --git a/tests/robotests/src/com/android/settings/wifi/p2p/WifiP2PPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/p2p/WifiP2PPreferenceControllerTest.java
index e809431..0b8d27a 100644
--- a/tests/robotests/src/com/android/settings/wifi/p2p/WifiP2PPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/p2p/WifiP2PPreferenceControllerTest.java
@@ -47,7 +47,7 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
 public class WifiP2PPreferenceControllerTest {
 
     @Mock
diff --git a/tests/unit/src/com/android/settings/connecteddevice/ConnectedDeviceActivityTest.java b/tests/unit/src/com/android/settings/connecteddevice/ConnectedDeviceActivityTest.java
new file mode 100644
index 0000000..4be8a39
--- /dev/null
+++ b/tests/unit/src/com/android/settings/connecteddevice/ConnectedDeviceActivityTest.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.connecteddevice;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.app.Instrumentation;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+import android.text.TextUtils;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.List;
+
+@RunWith(AndroidJUnit4.class)
+@SmallTest
+public class ConnectedDeviceActivityTest {
+    private static final String INTENT_ACTION = "android.intent.action.MAIN";
+    private static final String CONNECTED_DEVICE_TITLE = "Connected devices";
+
+    private Instrumentation mInstrumentation;
+
+    @Before
+    public void setUp() throws Exception {
+        mInstrumentation = InstrumentationRegistry.getInstrumentation();
+    }
+
+    @Test
+    public void queryConnectedDeviceActivity_onlyOneResponse() {
+        final PackageManager packageManager = mInstrumentation.getContext().getPackageManager();
+        final Intent intent = new Intent(INTENT_ACTION);
+
+        int count = 0;
+        final List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(intent,
+                PackageManager.GET_META_DATA);
+        for (ResolveInfo info : resolveInfoList) {
+            if (TextUtils.equals(info.activityInfo.loadLabel(packageManager).toString(),
+                    CONNECTED_DEVICE_TITLE)) {
+                count++;
+            }
+        }
+
+        assertThat(count).isEqualTo(1);
+    }
+
+}