Merge "Introduce PointerLocationPreferenceController"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 51da73d..8f6cc9c 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2634,8 +2634,6 @@
     <string name="kernel_version">Kernel version</string>
     <!-- About phone screen,  setting option name  [CHAR LIMIT=40] -->
     <string name="build_number">Build number</string>
-    <!-- About phone screen,  setting option name  [CHAR LIMIT=40] -->
-    <string name="selinux_status">SELinux status</string>
 
     <!-- About phone screen, show when a value of some status item is unavailable. -->
     <string name="device_info_not_available">Not available</string>
@@ -3436,9 +3434,9 @@
     <!-- Message on first screen of choose password flow [CHAR LIMIT=NONE] -->
     <string name="lockpassword_choose_your_password_message">For security, set a password</string>
     <!-- Header on first screen of choose password/PIN as backup for fingerprint flow. If this string cannot be translated in under 40 characters, please translate "Set fingerprint backup" [CHAR LIMIT=40] -->
-    <string name="lockpassword_choose_your_password_header_for_fingerprint">To use fingerprint, set password</string>
+    <string name="lockpassword_choose_your_password_header_for_fingerprint">To use fingerprint, set a password</string>
     <!-- Header on first screen of choose pattern as backup for fingerprint flow. If this string cannot be translated in under 40 characters, please translate "Set fingerprint backup" [CHAR LIMIT=40] -->
-    <string name="lockpassword_choose_your_pattern_header_for_fingerprint">To use fingerprint, set pattern</string>
+    <string name="lockpassword_choose_your_pattern_header_for_fingerprint">To use fingerprint, set a pattern</string>
     <!-- Message on first screen of choose PIN flow [CHAR LIMIT=NONE] -->
     <string name="lockpassword_choose_your_pin_message">For security, set a PIN</string>
     <!-- Header on first screen of choose password/PIN as backup for fingerprint flow. If this string cannot be translated in under 40 characters, please translate "Set fingerprint backup" [CHAR LIMIT=40] -->
@@ -5974,11 +5972,6 @@
     from their cell phone carrier. The use of the string is similar to the string
     "system_update_settings_list_item_title" in this project. [CHAR LIMIT=25] -->
     <string name="additional_system_update_settings_list_item_title">Additional system updates</string>
-    <!-- These statuses are displayed when a device was built with SE Android supoprt.
-    These are displayed by the settings app in the about section. -->
-    <string name="selinux_status_disabled">Disabled</string>
-    <string name="selinux_status_permissive">Permissive</string>
-    <string name="selinux_status_enforcing">Enforcing</string>
 
     <!-- Notification of installed CA Certs --> <skip/>
 
diff --git a/res/xml/device_info_settings.xml b/res/xml/device_info_settings.xml
index b094175..1771799 100644
--- a/res/xml/device_info_settings.xml
+++ b/res/xml/device_info_settings.xml
@@ -103,10 +103,4 @@
                 android:title="@string/build_number"
                 android:summary="@string/summary_placeholder"/>
 
-        <!-- SELinux status information -->
-        <Preference
-                android:key="selinux_status"
-                android:title="@string/selinux_status"
-                android:summary="@string/selinux_status_enforcing"/>
-
 </PreferenceScreen>
diff --git a/src/com/android/settings/DeviceInfoSettings.java b/src/com/android/settings/DeviceInfoSettings.java
index 7ca52e2..abf68f2 100644
--- a/src/com/android/settings/DeviceInfoSettings.java
+++ b/src/com/android/settings/DeviceInfoSettings.java
@@ -35,7 +35,6 @@
 import com.android.settings.deviceinfo.KernelVersionPreferenceController;
 import com.android.settings.deviceinfo.ManualPreferenceController;
 import com.android.settings.deviceinfo.RegulatoryInfoPreferenceController;
-import com.android.settings.deviceinfo.SELinuxStatusPreferenceController;
 import com.android.settings.deviceinfo.SafetyInfoPreferenceController;
 import com.android.settings.deviceinfo.SecurityPatchPreferenceController;
 import com.android.settings.search.BaseSearchIndexProvider;
@@ -129,7 +128,6 @@
         controllers.add(new DeviceModelPreferenceController(context, fragment));
         controllers.add(new SecurityPatchPreferenceController(context));
         controllers.add(new FccEquipmentIdPreferenceController(context));
-        controllers.add(new SELinuxStatusPreferenceController(context));
         controllers.add(new SafetyInfoPreferenceController(context));
         return controllers;
     }
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index 89724cc..3b2ea1a 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -103,6 +103,7 @@
 import android.view.animation.Animation;
 import android.view.animation.Animation.AnimationListener;
 import android.view.animation.AnimationUtils;
+import android.widget.EditText;
 import android.widget.ListView;
 import android.widget.TabWidget;
 
@@ -1362,4 +1363,7 @@
                 && volume.isMountedReadable();
     }
 
+    public static void setEditTextCursorPosition(EditText editText) {
+        editText.setSelection(editText.getText().length());
+    }
 }
diff --git a/src/com/android/settings/bluetooth/BluetoothNameDialogFragment.java b/src/com/android/settings/bluetooth/BluetoothNameDialogFragment.java
index 25413fa..576e656 100644
--- a/src/com/android/settings/bluetooth/BluetoothNameDialogFragment.java
+++ b/src/com/android/settings/bluetooth/BluetoothNameDialogFragment.java
@@ -116,6 +116,7 @@
             mDeviceNameView.setSelection(deviceName.length());
         }
         mDeviceNameView.addTextChangedListener(this);
+        com.android.settings.Utils.setEditTextCursorPosition(mDeviceNameView);
         mDeviceNameView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
             @Override
             public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
diff --git a/src/com/android/settings/bluetooth/DeviceProfilesSettings.java b/src/com/android/settings/bluetooth/DeviceProfilesSettings.java
index a76ed46..eae2f29 100755
--- a/src/com/android/settings/bluetooth/DeviceProfilesSettings.java
+++ b/src/com/android/settings/bluetooth/DeviceProfilesSettings.java
@@ -323,6 +323,7 @@
         final EditText deviceNameField = (EditText) mRootView.findViewById(R.id.name);
         if (deviceNameField != null) {
             deviceNameField.setText(mCachedDevice.getName());
+            com.android.settings.Utils.setEditTextCursorPosition(deviceNameField);
         }
 
         refreshProfiles();
diff --git a/src/com/android/settings/development/AdbDialogHost.java b/src/com/android/settings/development/AdbDialogHost.java
new file mode 100644
index 0000000..3288ab3
--- /dev/null
+++ b/src/com/android/settings/development/AdbDialogHost.java
@@ -0,0 +1,33 @@
+/*
+ * 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.development;
+
+/**
+ * Interface for EnableAdbWarningDialog callbacks.
+ */
+public interface AdbDialogHost {
+    /**
+     * Called when the user presses enable on the warning dialog.
+     */
+    void onEnableAdbDialogConfirmed();
+
+    /**
+     * Called when the user dismisses or cancels the warning dialog.
+     */
+    void onEnableAdbDialogDismissed();
+}
diff --git a/src/com/android/settings/development/AdbOnChangeListener.java b/src/com/android/settings/development/AdbOnChangeListener.java
new file mode 100644
index 0000000..8069270
--- /dev/null
+++ b/src/com/android/settings/development/AdbOnChangeListener.java
@@ -0,0 +1,28 @@
+/*
+ * 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.development;
+
+/**
+ * Interface for callbacks in Adb setting changes.
+ */
+public interface AdbOnChangeListener {
+
+    /**
+     * Called when the global Adb setting changes
+     */
+    void onAdbSettingChanged();
+}
diff --git a/src/com/android/settings/development/AdbPreferenceController.java b/src/com/android/settings/development/AdbPreferenceController.java
new file mode 100644
index 0000000..ed13b73
--- /dev/null
+++ b/src/com/android/settings/development/AdbPreferenceController.java
@@ -0,0 +1,116 @@
+/*
+ * 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.development;
+
+
+import android.content.Context;
+import android.content.Intent;
+import android.os.UserManager;
+import android.provider.Settings;
+import android.support.annotation.VisibleForTesting;
+import android.support.v14.preference.SwitchPreference;
+import android.support.v4.content.LocalBroadcastManager;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+public class AdbPreferenceController extends DeveloperOptionsPreferenceController implements
+        Preference.OnPreferenceChangeListener {
+
+    public static final String ADB_STATE_CHANGED =
+            "com.android.settings.development.AdbPreferenceController.ADB_STATE_CHANGED";
+    public static final int ADB_SETTING_ON = 1;
+    public static final int ADB_SETTING_OFF = 0;
+
+    private static final String KEY_ENABLE_ADB = "enable_adb";
+
+    private final DevelopmentSettingsDashboardFragment mFragment;
+    private SwitchPreference mPreference;
+
+    public AdbPreferenceController(Context context, DevelopmentSettingsDashboardFragment fragment) {
+        super(context);
+        mFragment = fragment;
+    }
+
+    @Override
+    public boolean isAvailable() {
+        return mContext.getSystemService(UserManager.class).isAdminUser();
+    }
+
+    @Override
+    public String getPreferenceKey() {
+        return KEY_ENABLE_ADB;
+    }
+
+    @Override
+    public void displayPreference(PreferenceScreen screen) {
+        super.displayPreference(screen);
+
+        mPreference = (SwitchPreference) screen.findPreference(getPreferenceKey());
+    }
+
+    @Override
+    public boolean onPreferenceChange(Preference preference, Object newValue) {
+        final boolean isAdbEnabled = (Boolean) newValue;
+        if (isAdbEnabled) {
+            EnableAdbWarningDialog.show(mFragment);
+        } else {
+            writeAdbSetting(isAdbEnabled);
+            notifyStateChanged();
+        }
+        return true;
+    }
+
+    @Override
+    public void updateState(Preference preference) {
+        final int adbMode = Settings.Global.getInt(mContext.getContentResolver(),
+                Settings.Global.ADB_ENABLED, 0 /* default */);
+        mPreference.setChecked(adbMode != ADB_SETTING_OFF);
+    }
+
+    @Override
+    protected void onDeveloperOptionsSwitchEnabled() {
+        mPreference.setEnabled(true);
+    }
+
+    @Override
+    protected void onDeveloperOptionsSwitchDisabled() {
+        writeAdbSetting(false);
+        notifyStateChanged();
+        mPreference.setEnabled(false);
+        mPreference.setChecked(false);
+    }
+
+    public void onAdbDialogConfirmed() {
+        writeAdbSetting(true);
+        notifyStateChanged();
+    }
+
+    public void onAdbDialogDismissed() {
+        updateState(mPreference);
+    }
+
+    private void writeAdbSetting(boolean enabled) {
+        Settings.Global.putInt(mContext.getContentResolver(),
+                Settings.Global.ADB_ENABLED, enabled ? ADB_SETTING_ON : ADB_SETTING_OFF);
+    }
+
+    @VisibleForTesting
+    void notifyStateChanged() {
+        LocalBroadcastManager.getInstance(mContext)
+                .sendBroadcast(new Intent(ADB_STATE_CHANGED));
+    }
+}
diff --git a/src/com/android/settings/development/BluetoothAbsoluteVolumePreferenceController.java b/src/com/android/settings/development/BluetoothAbsoluteVolumePreferenceController.java
new file mode 100644
index 0000000..a1ee149
--- /dev/null
+++ b/src/com/android/settings/development/BluetoothAbsoluteVolumePreferenceController.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.development;
+
+import android.content.Context;
+import android.os.SystemProperties;
+import android.support.annotation.VisibleForTesting;
+import android.support.v14.preference.SwitchPreference;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+public class BluetoothAbsoluteVolumePreferenceController extends
+        DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener {
+
+    private static final String BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_KEY =
+            "bluetooth_disable_absolute_volume";
+    @VisibleForTesting
+    static final String BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_PROPERTY =
+            "persist.bluetooth.disableabsvol";
+
+    private SwitchPreference mPreference;
+
+    public BluetoothAbsoluteVolumePreferenceController(Context context) {
+        super(context);
+    }
+
+    @Override
+    public boolean isAvailable() {
+        return true;
+    }
+
+    @Override
+    public String getPreferenceKey() {
+        return BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_KEY;
+    }
+
+    @Override
+    public void displayPreference(PreferenceScreen screen) {
+        super.displayPreference(screen);
+
+        mPreference = (SwitchPreference) screen.findPreference(getPreferenceKey());
+    }
+
+    @Override
+    public boolean onPreferenceChange(Preference preference, Object newValue) {
+        final boolean isEnabled = (Boolean) newValue;
+        SystemProperties.set(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_PROPERTY,
+                isEnabled ? "true" : "false");
+        return true;
+    }
+
+    @Override
+    public void updateState(Preference preference) {
+        final boolean isEnabled = SystemProperties.getBoolean(
+                BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_PROPERTY, false /* default */);
+        mPreference.setChecked(isEnabled);
+    }
+
+    @Override
+    protected void onDeveloperOptionsSwitchEnabled() {
+        mPreference.setEnabled(true);
+    }
+
+    @Override
+    protected void onDeveloperOptionsSwitchDisabled() {
+        SystemProperties.set(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_PROPERTY, "false");
+        mPreference.setChecked(false);
+        mPreference.setEnabled(false);
+    }
+}
diff --git a/src/com/android/settings/development/CameraHalHdrPlusPreferenceControllerV2.java b/src/com/android/settings/development/CameraHalHdrPlusPreferenceControllerV2.java
index deb6389..2005623 100644
--- a/src/com/android/settings/development/CameraHalHdrPlusPreferenceControllerV2.java
+++ b/src/com/android/settings/development/CameraHalHdrPlusPreferenceControllerV2.java
@@ -40,12 +40,6 @@
     static final String ENABLED = "1";
     @VisibleForTesting
     static final String DISABLED = "0";
-    @VisibleForTesting
-    static final String USERDEBUG_BUILD = "userdebug";
-    @VisibleForTesting
-    static final String ENG_BUILD = "eng";
-    @VisibleForTesting
-    static final String USER_BUILD = "user";
 
     private SwitchPreference mPreference;
 
@@ -57,9 +51,7 @@
     public boolean isAvailable() {
         final String buildType = SystemProperties.get(BUILD_TYPE);
 
-        return mContext.getResources().getBoolean(R.bool.config_show_camera_hal_hdrplus) &&
-                (TextUtils.equals(USERDEBUG_BUILD, buildType) ||
-                        TextUtils.equals(ENG_BUILD, buildType));
+        return mContext.getResources().getBoolean(R.bool.config_show_camera_hal_hdrplus);
     }
 
     @Override
diff --git a/src/com/android/settings/development/CameraHalHdrplusPreferenceController.java b/src/com/android/settings/development/CameraHalHdrplusPreferenceController.java
index afd1da1..39b6db2 100644
--- a/src/com/android/settings/development/CameraHalHdrplusPreferenceController.java
+++ b/src/com/android/settings/development/CameraHalHdrplusPreferenceController.java
@@ -67,9 +67,7 @@
 
     @Override
     public boolean isAvailable() {
-        return mContext.getResources().getBoolean(R.bool.config_show_camera_hal_hdrplus) &&
-               (SystemProperties.get(BUILD_TYPE).equals("userdebug") ||
-                SystemProperties.get(BUILD_TYPE).equals("eng"));
+        return mContext.getResources().getBoolean(R.bool.config_show_camera_hal_hdrplus);
     }
 
     @Override
diff --git a/src/com/android/settings/development/ConnectivityMonitorPreferenceController.java b/src/com/android/settings/development/ConnectivityMonitorPreferenceController.java
index fa7102a..e481809 100644
--- a/src/com/android/settings/development/ConnectivityMonitorPreferenceController.java
+++ b/src/com/android/settings/development/ConnectivityMonitorPreferenceController.java
@@ -28,6 +28,10 @@
 import com.android.settings.R;
 import com.android.settingslib.core.AbstractPreferenceController;
 
+/**
+ * deprecated in favor of {@link ConnectivityMonitorPreferenceControllerV2}
+ */
+@Deprecated
 public class ConnectivityMonitorPreferenceController extends AbstractPreferenceController implements
         PreferenceControllerMixin {
 
diff --git a/src/com/android/settings/development/ConnectivityMonitorPreferenceControllerV2.java b/src/com/android/settings/development/ConnectivityMonitorPreferenceControllerV2.java
new file mode 100644
index 0000000..1fe2a0f
--- /dev/null
+++ b/src/com/android/settings/development/ConnectivityMonitorPreferenceControllerV2.java
@@ -0,0 +1,113 @@
+/*
+ * 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.development;
+
+import android.content.Context;
+import android.os.SystemProperties;
+import android.support.v14.preference.SwitchPreference;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import android.text.TextUtils;
+import android.widget.Toast;
+
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.settings.R;
+
+public class ConnectivityMonitorPreferenceControllerV2 extends
+        DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener {
+
+    private static final String KEY_CONNECTIVITY_MONITOR_SWITCH = "connectivity_monitor_switch";
+    @VisibleForTesting
+    static final String BUILD_TYPE = "ro.build.type";
+    @VisibleForTesting
+    static final String PROPERTY_CONNECTIVITY_MONITOR = "persist.radio.enable_tel_mon";
+
+    @VisibleForTesting
+    static final String ENABLED_STATUS = "enabled";
+    @VisibleForTesting
+    static final String DISABLED_STATUS = "disabled";
+    @VisibleForTesting
+    static final String USER_ENABLED_STATUS = "user_enabled";
+    @VisibleForTesting
+    static final String USER_DISABLED_STATUS = "user_disabled";
+
+    @VisibleForTesting
+    static final String USERDEBUG_BUILD = "userdebug";
+    @VisibleForTesting
+    static final String ENG_BUILD = "eng";
+
+    private SwitchPreference mPreference;
+
+    public ConnectivityMonitorPreferenceControllerV2(Context context) {
+        super(context);
+    }
+
+    @Override
+    public void displayPreference(PreferenceScreen screen) {
+        super.displayPreference(screen);
+
+        mPreference = (SwitchPreference) screen.findPreference(KEY_CONNECTIVITY_MONITOR_SWITCH);
+    }
+
+    @Override
+    public String getPreferenceKey() {
+        return KEY_CONNECTIVITY_MONITOR_SWITCH;
+    }
+
+    @Override
+    public boolean isAvailable() {
+        final String buildType = SystemProperties.get(BUILD_TYPE);
+        return mContext.getResources().getBoolean(R.bool.config_show_connectivity_monitor)
+                && (TextUtils.equals(buildType, USERDEBUG_BUILD)
+                || TextUtils.equals(buildType, ENG_BUILD));
+    }
+
+    @Override
+    public boolean onPreferenceChange(Preference preference, Object newValue) {
+        final boolean isEnabled = (Boolean) newValue;
+        SystemProperties.set(PROPERTY_CONNECTIVITY_MONITOR,
+                isEnabled ? USER_ENABLED_STATUS : USER_DISABLED_STATUS);
+        Toast.makeText(mContext, R.string.connectivity_monitor_toast,
+                Toast.LENGTH_LONG).show();
+        return true;
+    }
+
+    @Override
+    public void updateState(Preference preference) {
+        final boolean enabled = isConnectivityMonitorEnabled();
+        mPreference.setChecked(enabled);
+    }
+
+    @Override
+    protected void onDeveloperOptionsSwitchEnabled() {
+        mPreference.setEnabled(true);
+    }
+
+    @Override
+    protected void onDeveloperOptionsSwitchDisabled() {
+        SystemProperties.set(PROPERTY_CONNECTIVITY_MONITOR, USER_DISABLED_STATUS);
+        mPreference.setChecked(false);
+        mPreference.setEnabled(false);
+    }
+
+    private boolean isConnectivityMonitorEnabled() {
+        final String cmStatus = SystemProperties.get(PROPERTY_CONNECTIVITY_MONITOR,
+                DISABLED_STATUS);
+        return TextUtils.equals(ENABLED_STATUS, cmStatus) || TextUtils.equals(USER_ENABLED_STATUS,
+                cmStatus);
+    }
+}
diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
index 1474117..df6afc4 100644
--- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
+++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
@@ -17,13 +17,19 @@
 package com.android.settings.development;
 
 import android.app.Activity;
+import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
+import android.content.IntentFilter;
 import android.os.Bundle;
 import android.os.UserManager;
 import android.provider.SearchIndexableResource;
 import android.support.annotation.VisibleForTesting;
+import android.support.v4.content.LocalBroadcastManager;
 import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
 import android.widget.Switch;
 
 import com.android.internal.logging.nano.MetricsProto;
@@ -43,7 +49,7 @@
 import java.util.List;
 
 public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFragment
-        implements SwitchBar.OnSwitchChangeListener, OemUnlockDialogHost {
+        implements SwitchBar.OnSwitchChangeListener, OemUnlockDialogHost, AdbDialogHost {
 
     private static final String TAG = "DevSettingsDashboard";
 
@@ -52,6 +58,17 @@
     private DevelopmentSwitchBarController mSwitchBarController;
     private List<AbstractPreferenceController> mPreferenceControllers = new ArrayList<>();
 
+    private final BroadcastReceiver mEnableAdbReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            for (AbstractPreferenceController controller : mPreferenceControllers) {
+                if (controller instanceof AdbOnChangeListener) {
+                    ((AdbOnChangeListener) controller).onAdbSettingChanged();
+                }
+            }
+        }
+    };
+
     public DevelopmentSettingsDashboardFragment() {
         super(UserManager.DISALLOW_DEBUGGING_FEATURES);
     }
@@ -80,6 +97,19 @@
     }
 
     @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        registerReceivers();
+        return super.onCreateView(inflater, container, savedInstanceState);
+    }
+
+    @Override
+    public void onDestroyView() {
+        super.onDestroyView();
+        unregisterReceivers();
+    }
+
+    @Override
     public int getMetricsCategory() {
         return MetricsProto.MetricsEvent.DEVELOPMENT;
     }
@@ -121,6 +151,21 @@
     }
 
     @Override
+    public void onEnableAdbDialogConfirmed() {
+        final AdbPreferenceController controller = getDevelopmentOptionsController(
+                AdbPreferenceController.class);
+        controller.onAdbDialogConfirmed();
+
+    }
+
+    @Override
+    public void onEnableAdbDialogDismissed() {
+        final AdbPreferenceController controller = getDevelopmentOptionsController(
+                AdbPreferenceController.class);
+        controller.onAdbDialogDismissed();
+    }
+
+    @Override
     public void onActivityResult(int requestCode, int resultCode, Intent data) {
         boolean handledResult = false;
         for (AbstractPreferenceController controller : mPreferenceControllers) {
@@ -160,6 +205,16 @@
         return mPreferenceControllers;
     }
 
+    private void registerReceivers() {
+        LocalBroadcastManager.getInstance(getContext())
+                .registerReceiver(mEnableAdbReceiver, new IntentFilter(
+                        AdbPreferenceController.ADB_STATE_CHANGED));
+    }
+
+    private void unregisterReceivers() {
+        LocalBroadcastManager.getInstance(getContext()).unregisterReceiver(mEnableAdbReceiver);
+    }
+
     void onEnableDevelopmentOptionsConfirmed() {
         DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(getContext(), true);
         for (AbstractPreferenceController controller : mPreferenceControllers) {
@@ -191,7 +246,7 @@
         controllers.add(new DisableAutomaticUpdatesPreferenceController(context));
         // system ui demo mode
         // quick settings developer tiles
-        // usb debugging
+        controllers.add(new AdbPreferenceController(context, fragment));
         // revoke usb debugging authorizations
         controllers.add(new LocalTerminalPreferenceController(context));
         // bug report shortcut
@@ -202,7 +257,7 @@
         // verify apps over usb
         // logger buffer sizes
         // store logger data persistently on device
-        // telephony monitor
+        controllers.add(new ConnectivityMonitorPreferenceControllerV2(context));
         controllers.add(new CameraLaserSensorPreferenceControllerV2(context));
         controllers.add(new CameraHalHdrPlusPreferenceControllerV2(context));
         // feature flags
@@ -214,7 +269,7 @@
         controllers.add(new TetheringHardwareAccelPreferenceController(context));
         // select usb configuration
         controllers.add(new BluetoothDeviceNoNamePreferenceController(context));
-        // disable absolute volume
+        controllers.add(new BluetoothAbsoluteVolumePreferenceController(context));
         // enable in-band ringing
         // bluetooth avrcp version
         // bluetooth audio codec
diff --git a/src/com/android/settings/development/EnableAdbPreferenceController.java b/src/com/android/settings/development/EnableAdbPreferenceController.java
index bd6267b..a866353 100644
--- a/src/com/android/settings/development/EnableAdbPreferenceController.java
+++ b/src/com/android/settings/development/EnableAdbPreferenceController.java
@@ -27,6 +27,10 @@
 import com.android.settings.core.PreferenceControllerMixin;
 import com.android.settingslib.development.AbstractEnableAdbPreferenceController;
 
+/**
+ * @deprecated in favor of {@link AdbPreferenceController}
+ */
+@Deprecated
 public class EnableAdbPreferenceController extends AbstractEnableAdbPreferenceController
         implements PreferenceControllerMixin {
 
diff --git a/src/com/android/settings/development/EnableAdbWarningDialog.java b/src/com/android/settings/development/EnableAdbWarningDialog.java
new file mode 100644
index 0000000..9829f70
--- /dev/null
+++ b/src/com/android/settings/development/EnableAdbWarningDialog.java
@@ -0,0 +1,81 @@
+/*
+ * 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.development;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.Fragment;
+import android.app.FragmentManager;
+import android.content.DialogInterface;
+import android.os.Bundle;
+
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.R;
+import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
+
+public class EnableAdbWarningDialog extends InstrumentedDialogFragment implements
+        DialogInterface.OnClickListener, DialogInterface.OnDismissListener {
+
+    public static final String TAG = "EnableAdbDialog";
+
+    public static void show(Fragment host) {
+        final FragmentManager manager = host.getActivity().getFragmentManager();
+        if (manager.findFragmentByTag(TAG) == null) {
+            final EnableAdbWarningDialog dialog = new EnableAdbWarningDialog();
+            dialog.setTargetFragment(host, 0 /* requestCode */);
+            dialog.show(manager, TAG);
+        }
+    }
+
+    @Override
+    public int getMetricsCategory() {
+        return MetricsProto.MetricsEvent.DIALOG_ENABLE_ADB;
+    }
+
+    @Override
+    public Dialog onCreateDialog(Bundle savedInstanceState) {
+        return new AlertDialog.Builder(getActivity())
+                .setTitle(R.string.adb_warning_title)
+                .setMessage(R.string.adb_warning_message)
+                .setPositiveButton(android.R.string.yes, this /* onClickListener */)
+                .setNegativeButton(android.R.string.no, this /* onClickListener */)
+                .create();
+    }
+
+    @Override
+    public void onClick(DialogInterface dialog, int which) {
+        final AdbDialogHost host = (AdbDialogHost) getTargetFragment();
+        if (host == null) {
+            return;
+        }
+        if (which == DialogInterface.BUTTON_POSITIVE) {
+            host.onEnableAdbDialogConfirmed();
+        } else {
+            host.onEnableAdbDialogDismissed();
+        }
+    }
+
+    @Override
+    public void onDismiss(DialogInterface dialog) {
+        super.onDismiss(dialog);
+        final AdbDialogHost host = (AdbDialogHost) getTargetFragment();
+        if (host == null) {
+            return;
+        }
+        host.onEnableAdbDialogDismissed();
+    }
+}
diff --git a/src/com/android/settings/deviceinfo/SELinuxStatusPreferenceController.java b/src/com/android/settings/deviceinfo/SELinuxStatusPreferenceController.java
deleted file mode 100644
index 058992f..0000000
--- a/src/com/android/settings/deviceinfo/SELinuxStatusPreferenceController.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.settings.deviceinfo;
-
-import android.content.Context;
-import android.os.SELinux;
-import android.os.SystemProperties;
-import android.support.v7.preference.Preference;
-import android.support.v7.preference.PreferenceScreen;
-import android.text.TextUtils;
-
-import com.android.settings.R;
-import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settingslib.core.AbstractPreferenceController;
-
-public class SELinuxStatusPreferenceController extends AbstractPreferenceController implements
-        PreferenceControllerMixin {
-
-    private static final String PROPERTY_SELINUX_STATUS = "ro.build.selinux";
-    private static final String KEY_SELINUX_STATUS = "selinux_status";
-
-    public SELinuxStatusPreferenceController(Context context) {
-        super(context);
-    }
-
-    @Override
-    public boolean isAvailable() {
-        return !TextUtils.isEmpty(SystemProperties.get(PROPERTY_SELINUX_STATUS));
-    }
-
-    @Override
-    public String getPreferenceKey() {
-        return KEY_SELINUX_STATUS;
-    }
-
-    @Override
-    public void displayPreference(PreferenceScreen screen) {
-        super.displayPreference(screen);
-        final Preference pref = screen.findPreference(KEY_SELINUX_STATUS);
-        if (pref == null) {
-            return;
-        }
-        if (!SELinux.isSELinuxEnabled()) {
-            String status = mContext.getResources().getString(R.string.selinux_status_disabled);
-            pref.setSummary(status);
-        } else if (!SELinux.isSELinuxEnforced()) {
-            String status = mContext.getResources().getString(R.string.selinux_status_permissive);
-            pref.setSummary(status);
-        }
-    }
-}
-
diff --git a/src/com/android/settings/display/BrightnessLevelPreferenceController.java b/src/com/android/settings/display/BrightnessLevelPreferenceController.java
index f9c9d53..ee573eb 100644
--- a/src/com/android/settings/display/BrightnessLevelPreferenceController.java
+++ b/src/com/android/settings/display/BrightnessLevelPreferenceController.java
@@ -35,13 +35,13 @@
 import com.android.settingslib.core.AbstractPreferenceController;
 import com.android.settingslib.core.lifecycle.Lifecycle;
 import com.android.settingslib.core.lifecycle.LifecycleObserver;
-import com.android.settingslib.core.lifecycle.events.OnPause;
-import com.android.settingslib.core.lifecycle.events.OnResume;
+import com.android.settingslib.core.lifecycle.events.OnStart;
+import com.android.settingslib.core.lifecycle.events.OnStop;
 
 import java.text.NumberFormat;
 
 public class BrightnessLevelPreferenceController extends AbstractPreferenceController implements
-        PreferenceControllerMixin, LifecycleObserver, OnResume, OnPause {
+        PreferenceControllerMixin, LifecycleObserver, OnStart, OnStop {
 
     private static final String TAG = "BrightnessPrefCtrl";
     private static final String KEY_BRIGHTNESS = "brightness";
@@ -114,7 +114,7 @@
     }
 
     @Override
-    public void onResume() {
+    public void onStart() {
         mContentResolver.registerContentObserver(BRIGHTNESS_MODE_URI, false, mBrightnessObserver);
         mContentResolver.registerContentObserver(BRIGHTNESS_URI, false, mBrightnessObserver);
         mContentResolver.registerContentObserver(BRIGHTNESS_FOR_VR_URI, false, mBrightnessObserver);
@@ -122,7 +122,7 @@
     }
 
     @Override
-    public void onPause() {
+    public void onStop() {
         mContentResolver.unregisterContentObserver(mBrightnessObserver);
     }
 
diff --git a/src/com/android/settings/display/DensityPreference.java b/src/com/android/settings/display/DensityPreference.java
index a62e6b5..581a3ee 100644
--- a/src/com/android/settings/display/DensityPreference.java
+++ b/src/com/android/settings/display/DensityPreference.java
@@ -27,6 +27,7 @@
 
 import com.android.settings.R;
 import com.android.settingslib.CustomEditTextPreference;
+import com.android.settings.Utils;
 import com.android.settingslib.display.DisplayDensityUtils;
 
 import java.text.NumberFormat;
@@ -63,6 +64,7 @@
         if (editText != null) {
             editText.setInputType(InputType.TYPE_CLASS_NUMBER);
             editText.setText(getCurrentSwDp() + "");
+            Utils.setEditTextCursorPosition(editText);
         }
     }
 
diff --git a/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java b/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
index d29364d..adadb78 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
@@ -338,7 +338,8 @@
         return usageType == UsageType.CELL
                 || usageType == UsageType.BLUETOOTH
                 || usageType == UsageType.WIFI
-                || usageType == UsageType.APP;
+                || usageType == UsageType.APP
+                || usageType == UsageType.SYSTEM;
     }
 
     @VisibleForTesting
diff --git a/src/com/android/settings/search/DatabaseIndexingManager.java b/src/com/android/settings/search/DatabaseIndexingManager.java
index d540d2f..5d6fe3b 100644
--- a/src/com/android/settings/search/DatabaseIndexingManager.java
+++ b/src/com/android/settings/search/DatabaseIndexingManager.java
@@ -28,7 +28,8 @@
 import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.DATA_KEYWORDS;
 import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.DATA_KEY_REF;
 import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.DATA_SUMMARY_ON;
-import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.DATA_SUMMARY_ON_NORMALIZED;
+import static com.android.settings.search.IndexDatabaseHelper.IndexColumns
+        .DATA_SUMMARY_ON_NORMALIZED;
 import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.DATA_TITLE;
 import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.DATA_TITLE_NORMALIZED;
 import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.ENABLED;
@@ -234,9 +235,9 @@
     @VisibleForTesting
     List<IndexData> getIndexData(String locale, PreIndexData data) {
         if (mConverter == null) {
-            mConverter = new IndexDataConverter(mContext);
+            mConverter = new IndexDataConverter(mContext, locale);
         }
-        return mConverter.convertPreIndexDataToIndexData(data, locale);
+        return mConverter.convertPreIndexDataToIndexData(data);
     }
 
     /**
@@ -248,6 +249,10 @@
         ContentValues values;
 
         for (IndexData dataRow : indexData) {
+            if (TextUtils.isEmpty(dataRow.normalizedTitle)) {
+                continue;
+            }
+
             values = new ContentValues();
             values.put(IndexDatabaseHelper.IndexColumns.DOCID, dataRow.getDocId());
             values.put(LOCALE, dataRow.locale);
diff --git a/src/com/android/settings/search/DatabaseResultLoader.java b/src/com/android/settings/search/DatabaseResultLoader.java
index 3d280b2..c1663ab 100644
--- a/src/com/android/settings/search/DatabaseResultLoader.java
+++ b/src/com/android/settings/search/DatabaseResultLoader.java
@@ -93,7 +93,6 @@
      * If the query matches the prefix of the other words in the title, the best rank it can be is 3
      * If the query only matches the summary, the best rank it can be is 7
      * If the query only matches keywords or entries, the best rank it can be is 9
-     *
      */
     public static final int[] BASE_RANKS = {1, 3, 7, 9};
 
@@ -141,7 +140,7 @@
      * Creates and executes the query which matches prefixes of the first word of the given columns.
      *
      * @param matchColumns The columns to match on
-     * @param baseRank The highest rank achievable by these results
+     * @param baseRank     The highest rank achievable by these results
      * @return A set of the matching results.
      */
     private Set<SearchResult> firstWordQuery(String[] matchColumns, int baseRank) {
@@ -157,7 +156,7 @@
      * given columns.
      *
      * @param matchColumns The columns to match on
-     * @param baseRank The highest rank achievable by these results
+     * @param baseRank     The highest rank achievable by these results
      * @return A set of the matching results.
      */
     private Set<SearchResult> secondaryWordQuery(String[] matchColumns, int baseRank) {
@@ -172,7 +171,7 @@
      * Creates and executes the query which matches prefixes of the any word of the given columns.
      *
      * @param matchColumns The columns to match on
-     * @param baseRank The highest rank achievable by these results
+     * @param baseRank     The highest rank achievable by these results
      * @return A set of the matching results.
      */
     private Set<SearchResult> anyWordQuery(String[] matchColumns, int baseRank) {
@@ -186,8 +185,8 @@
      * Generic method used by all of the query methods above to execute a query.
      *
      * @param whereClause Where clause for the SQL query which uses bindings.
-     * @param selection List of the transformed query to match each bind in the whereClause
-     * @param baseRank The highest rank achievable by these results.
+     * @param selection   List of the transformed query to match each bind in the whereClause
+     * @param baseRank    The highest rank achievable by these results.
      * @return A set of the matching results.
      */
     private Set<SearchResult> query(String whereClause, String[] selection, int baseRank) {
@@ -249,7 +248,7 @@
     private String[] buildSingleWordSelection(String query, int size) {
         String[] selection = new String[size];
 
-        for(int i = 0; i < size; i ++) {
+        for (int i = 0; i < size; i++) {
             selection[i] = query;
         }
         return selection;
@@ -267,7 +266,7 @@
         final String query = mQueryText + "%";
         final String subStringQuery = "% " + mQueryText + "%";
 
-        for(int i = 0; i < (size - 1); i += 2) {
+        for (int i = 0; i < (size - 1); i += 2) {
             selection[i] = query;
             selection[i + 1] = subStringQuery;
         }
diff --git a/src/com/android/settings/search/indexing/IndexData.java b/src/com/android/settings/search/indexing/IndexData.java
index c05c95d..0e1fa2d 100644
--- a/src/com/android/settings/search/indexing/IndexData.java
+++ b/src/com/android/settings/search/indexing/IndexData.java
@@ -21,6 +21,7 @@
 import android.content.Context;
 import android.content.Intent;
 import android.text.TextUtils;
+
 import com.android.settings.SettingsActivity;
 import com.android.settings.search.DatabaseIndexingUtils;
 import com.android.settings.search.ResultPayload;
diff --git a/src/com/android/settings/search/indexing/IndexDataConverter.java b/src/com/android/settings/search/indexing/IndexDataConverter.java
index 90430a8..487132b 100644
--- a/src/com/android/settings/search/indexing/IndexDataConverter.java
+++ b/src/com/android/settings/search/indexing/IndexDataConverter.java
@@ -17,29 +17,31 @@
 
 package com.android.settings.search.indexing;
 
+import android.annotation.Nullable;
 import android.content.Context;
 import android.content.res.XmlResourceParser;
 import android.provider.SearchIndexableData;
 import android.provider.SearchIndexableResource;
 import android.support.annotation.DrawableRes;
-import android.support.annotation.VisibleForTesting;
 import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.util.Log;
 import android.util.Xml;
+
 import com.android.settings.core.PreferenceControllerMixin;
 
 import com.android.settings.search.DatabaseIndexingUtils;
 import com.android.settings.search.Indexable;
 import com.android.settings.search.ResultPayload;
 import com.android.settings.search.SearchIndexableRaw;
-import com.android.settings.search.SearchIndexableResources;
 import com.android.settings.search.XmlParserUtils;
+
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -47,10 +49,6 @@
 
 /**
  * Helper class to convert {@link PreIndexData} to {@link IndexData}.
- *
- * TODO (b/33577327) This is just copied straight from DatabaseIndexingManager. But it's still ugly.
- * TODO              This is currently a long chain of method calls. It needs to be broken up.
- * TODO              but for the sake of easy code reviews, that will happen later.
  */
 public class IndexDataConverter {
 
@@ -64,70 +62,77 @@
 
     private String mLocale;
 
-    private List<IndexData> mIndexData;
-
-    public IndexDataConverter(Context context) {
+    public IndexDataConverter(Context context, String locale) {
         mContext = context;
-        mLocale = Locale.getDefault().toString();
-    }
-
-    public List<IndexData> convertPreIndexDataToIndexData(PreIndexData preIndexData,
-            String locale) {
         mLocale = locale;
-        mIndexData = new ArrayList<>();
-        List<SearchIndexableData> dataToUpdate = preIndexData.dataToUpdate;
-        Map<String, Set<String>> nonIndexableKeys = preIndexData.nonIndexableKeys;
-        parsePreIndexData(dataToUpdate, nonIndexableKeys);
-        return mIndexData;
     }
 
     /**
-     * Inserts {@link SearchIndexableData} into the database.
+     * Return the collection of {@param preIndexData} converted into {@link IndexData}.
      *
-     * @param dataToUpdate     is a {@link List} of the data to be inserted.
-     * @param nonIndexableKeys is a {@link Map} from Package Name to a {@link Set} of keys which
-     *                         identify search results which should not be surfaced.
+     * @param preIndexData a collection of {@link SearchIndexableResource},
+     *                     {@link SearchIndexableRaw} and non-indexable keys.
      */
-    private void parsePreIndexData(List<SearchIndexableData> dataToUpdate,
-            Map<String, Set<String>> nonIndexableKeys) {
-        final long current = System.currentTimeMillis();
+    public List<IndexData> convertPreIndexDataToIndexData(PreIndexData preIndexData) {
 
-        for (SearchIndexableData data : dataToUpdate) {
-            try {
-                addOneIndexData(data, nonIndexableKeys);
-            } catch (Exception e) {
-                Log.e(LOG_TAG, "Cannot index: " + (data != null ? data.className : data)
-                        + " for locale: " + mLocale, e);
+        final long current = System.currentTimeMillis();
+        final List<SearchIndexableData> indexableData = preIndexData.dataToUpdate;
+        final Map<String, Set<String>> nonIndexableKeys = preIndexData.nonIndexableKeys;
+        final List<IndexData> indexData = new ArrayList<>();
+
+        for (SearchIndexableData data : indexableData) {
+            if (data instanceof SearchIndexableRaw) {
+                final SearchIndexableRaw rawData = (SearchIndexableRaw) data;
+                final Set<String> rawNonIndexableKeys = nonIndexableKeys.get(
+                        rawData.intentTargetPackage);
+                final IndexData.Builder builder = convertRaw(rawData, rawNonIndexableKeys);
+
+                if (builder != null) {
+                    indexData.add(builder.build(mContext));
+                }
+            } else if (data instanceof SearchIndexableResource) {
+                final SearchIndexableResource sir = (SearchIndexableResource) data;
+                final Set<String> resourceNonIndexableKeys =
+                        getNonIndexableKeysForResource(nonIndexableKeys, sir.packageName);
+
+                if (sir.xmlResId == 0) {
+                    // Index from provider
+                    final Indexable.SearchIndexProvider provider = getSearchProvider(sir);
+                    if (provider == null) {
+                        continue;
+                    }
+                    indexData.addAll(convertIndexProvider(provider, sir, resourceNonIndexableKeys));
+
+                } else {
+                    final List<IndexData> resourceData = convertResource(sir,
+                            resourceNonIndexableKeys);
+                    indexData.addAll(resourceData);
+                }
+
             }
         }
 
-        final long now = System.currentTimeMillis();
-        Log.d(LOG_TAG, "Indexing locale '" + mLocale + "' took " +
-                (now - current) + " millis");
+        final long endConversion = System.currentTimeMillis();
+        Log.d(LOG_TAG, "Converting pre-index data to index data took: "
+                + (endConversion - current));
+
+        return indexData;
     }
 
-    private void addOneIndexData(SearchIndexableData data,
-            Map<String, Set<String>> nonIndexableKeys) {
-        if (data instanceof SearchIndexableResource) {
-            addOneResource((SearchIndexableResource) data, nonIndexableKeys);
-        } else if (data instanceof SearchIndexableRaw) {
-            addOneRaw((SearchIndexableRaw) data, nonIndexableKeys);
-        }
-    }
-
-    private void addOneRaw(SearchIndexableRaw raw, Map<String,
-            Set<String>> nonIndexableKeysFromResource) {
+    /**
+     * Return the conversion of {@link SearchIndexableRaw} to {@link IndexData}.
+     * The fields of {@link SearchIndexableRaw} are a subset of {@link IndexData},
+     * and there is some data sanitization in the conversion.
+     */
+    @Nullable
+    private IndexData.Builder convertRaw(SearchIndexableRaw raw, Set<String> nonIndexableKeys) {
         // Should be the same locale as the one we are processing
         if (!raw.locale.toString().equalsIgnoreCase(mLocale)) {
-            return;
+            return null;
         }
 
-        Set<String> packageKeys = nonIndexableKeysFromResource.get(raw.intentTargetPackage);
-        boolean enabled = raw.enabled;
-
-        if (packageKeys != null && packageKeys.contains(raw.key)) {
-            enabled = false;
-        }
+        // A row is enabled if it does not show up as an nonIndexableKey
+        boolean enabled = !(nonIndexableKeys != null && nonIndexableKeys.contains(raw.key));
 
         IndexData.Builder builder = new IndexData.Builder();
         builder.setTitle(raw.title)
@@ -145,58 +150,22 @@
                 .setKey(raw.key)
                 .setUserId(raw.userId);
 
-        addRowToData(builder.build(mContext));
+        return builder;
     }
 
-    private void addOneResource(SearchIndexableResource sir,
-        Map<String, Set<String>> nonIndexableKeysFromResource) {
-
-        if (sir == null) {
-            Log.e(LOG_TAG, "Cannot index a null resource!");
-            return;
-        }
-
-        final List<String> nonIndexableKeys = new ArrayList<>();
-
-        if (sir.xmlResId > SearchIndexableResources.NO_DATA_RES_ID) {
-            Set<String> resNonIndexableKeys = nonIndexableKeysFromResource.get(sir.packageName);
-            if (resNonIndexableKeys != null && resNonIndexableKeys.size() > 0) {
-                nonIndexableKeys.addAll(resNonIndexableKeys);
-            }
-
-            addIndexDataFromResource(sir, nonIndexableKeys);
-        } else {
-            if (TextUtils.isEmpty(sir.className)) {
-                Log.w(LOG_TAG, "Cannot index an empty Search Provider name!");
-                return;
-            }
-
-            final Class<?> clazz = DatabaseIndexingUtils.getIndexableClass(sir.className);
-            if (clazz == null) {
-                Log.d(LOG_TAG, "SearchIndexableResource '" + sir.className +
-                        "' should implement the " + Indexable.class.getName() + " interface!");
-                return;
-            }
-
-            // Will be non null only for a Local provider implementing a
-            // SEARCH_INDEX_DATA_PROVIDER field
-            final Indexable.SearchIndexProvider provider =
-                    DatabaseIndexingUtils.getSearchIndexProvider(clazz);
-            if (provider != null) {
-                List<String> providerNonIndexableKeys = provider.getNonIndexableKeys(sir.context);
-                if (providerNonIndexableKeys != null) {
-                    nonIndexableKeys.addAll(providerNonIndexableKeys);
-                }
-
-                addIndexDataFromProvider(provider, sir, nonIndexableKeys);
-            }
-        }
-    }
-
-    private void addIndexDataFromResource(SearchIndexableResource sir,
-            List<String> nonIndexableKeys) {
+    /**
+     * Return the conversion of the {@link SearchIndexableResource} to {@link IndexData}.
+     * Each of the elements in the xml layout attribute of {@param sir} is a candidate to be
+     * converted (including the header element).
+     *
+     * TODO (b/33577327) simplify this method.
+     */
+    private List<IndexData> convertResource(SearchIndexableResource sir,
+            Set<String> nonIndexableKeys) {
         final Context context = sir.context;
         XmlResourceParser parser = null;
+
+        List<IndexData> resourceIndexData = new ArrayList<>();
         try {
             parser = context.getResources().getXml(sir.xmlResId);
 
@@ -226,8 +195,7 @@
             String keywords;
             String headerKeywords;
             String childFragment;
-            @DrawableRes
-            int iconResId;
+            @DrawableRes int iconResId;
             ResultPayload payload;
             boolean enabled;
             final String fragmentName = sir.className;
@@ -242,9 +210,6 @@
                         .getPreferenceControllerUriMap(fragmentName, context);
             }
 
-            // Insert rows for the main PreferenceScreen node. Rewrite the data for removing
-            // hyphens.
-
             headerTitle = XmlParserUtils.getDataTitle(context, attrs);
             headerSummary = XmlParserUtils.getDataSummary(context, attrs);
             headerKeywords = XmlParserUtils.getDataKeywords(context, attrs);
@@ -319,8 +284,7 @@
                             .setChildClassName(childFragment)
                             .setPayload(payload);
 
-                    // Insert rows for the child nodes of PreferenceScreen
-                    addRowToData(builder.build(mContext));
+                    resourceIndexData.add(builder.build(mContext));
                 } else {
                     // TODO (b/33577327) We removed summary off here. We should check if we can
                     // merge this 'else' section with the one above. Put a break point to
@@ -334,13 +298,13 @@
 
                     builder.setSummaryOn(summaryOn);
 
-                    addRowToData(builder.build(mContext));
+                    resourceIndexData.add(builder.build(mContext));
                 }
             }
 
             // The xml header's title does not match the title of one of the child settings.
             if (isHeaderUnique) {
-                addRowToData(headerBuilder.build(mContext));
+                resourceIndexData.add(headerBuilder.build(mContext));
             }
         } catch (XmlPullParserException e) {
             throw new RuntimeException("Error parsing PreferenceScreen", e);
@@ -349,62 +313,44 @@
         } finally {
             if (parser != null) parser.close();
         }
+        return resourceIndexData;
     }
 
-    private void addIndexDataFromProvider(Indexable.SearchIndexProvider provider,
-            SearchIndexableResource sir, List<String> nonIndexableKeys) {
+    private List<IndexData> convertIndexProvider(Indexable.SearchIndexProvider provider,
+            SearchIndexableResource sir, Set<String> nonIndexableKeys) {
+        final List<IndexData> indexData = new ArrayList<>();
 
         final String className = sir.className;
         final String intentAction = sir.intentAction;
         final String intentTargetPackage = sir.intentTargetPackage;
 
-        if (provider == null) {
-            Log.w(LOG_TAG, "Cannot find provider: " + className);
-            return;
-        }
+        // TODO (b/65376542) Move provider conversion to PreIndexTime
+        // TODO (b/37741509) Providers don't use general non-indexable keys
+        nonIndexableKeys.addAll(provider.getNonIndexableKeys(mContext));
 
         final List<SearchIndexableRaw> rawList = provider.getRawDataToIndex(mContext,
                 true /* enabled */);
 
         if (rawList != null) {
+            for (SearchIndexableRaw raw : rawList) {
+                // The classname and intent information comes from the PreIndexData
+                // This will be more clear when provider conversion is done at PreIndex time.
+                raw.className = className;
+                raw.intentAction = intentAction;
+                raw.intentTargetPackage = intentTargetPackage;
 
-            final int rawSize = rawList.size();
-            for (int i = 0; i < rawSize; i++) {
-                SearchIndexableRaw raw = rawList.get(i);
-
-                // Should be the same locale as the one we are processing
-                if (!raw.locale.toString().equalsIgnoreCase(mLocale)) {
-                    continue;
+                IndexData.Builder builder = convertRaw(raw, nonIndexableKeys);
+                if (builder != null) {
+                    indexData.add(builder.build(mContext));
                 }
-                boolean enabled = !nonIndexableKeys.contains(raw.key);
-
-                IndexData.Builder builder = new IndexData.Builder();
-                builder.setTitle(raw.title)
-                        .setSummaryOn(raw.summaryOn)
-                        .setLocale(mLocale)
-                        .setEntries(raw.entries)
-                        .setKeywords(raw.keywords)
-                        .setClassName(className)
-                        .setScreenTitle(raw.screenTitle)
-                        .setIconResId(raw.iconResId)
-                        .setIntentAction(raw.intentAction)
-                        .setIntentTargetPackage(raw.intentTargetPackage)
-                        .setIntentTargetClass(raw.intentTargetClass)
-                        .setEnabled(enabled)
-                        .setKey(raw.key)
-                        .setUserId(raw.userId);
-
-                addRowToData(builder.build(mContext));
             }
         }
 
         final List<SearchIndexableResource> resList =
                 provider.getXmlResourcesToIndex(mContext, true);
-        if (resList != null) {
-            final int resSize = resList.size();
-            for (int i = 0; i < resSize; i++) {
-                SearchIndexableResource item = resList.get(i);
 
+        if (resList != null) {
+            for (SearchIndexableResource item : resList) {
                 // Should be the same locale as the one we are processing
                 if (!item.locale.toString().equalsIgnoreCase(mLocale)) {
                     continue;
@@ -420,16 +366,39 @@
                         ? intentTargetPackage
                         : item.intentTargetPackage;
 
-                addIndexDataFromResource(item, nonIndexableKeys);
+                indexData.addAll(convertResource(item, nonIndexableKeys));
             }
         }
+
+        return indexData;
     }
 
-    private void addRowToData(IndexData row) {
-        if (TextUtils.isEmpty(row.updatedTitle)) {
-            return;
+    private Set<String> getNonIndexableKeysForResource(Map<String, Set<String>> nonIndexableKeys,
+            String packageName) {
+        return nonIndexableKeys.containsKey(packageName)
+                ? nonIndexableKeys.get(packageName)
+                : new HashSet<>();
+    }
+
+    /**
+     * @return Return the {@link Indexable.SearchIndexProvider} corresponding to the
+     * class specified by the Class name specified by {@param sir}.
+     */
+    private Indexable.SearchIndexProvider getSearchProvider(SearchIndexableResource sir) {
+        if (TextUtils.isEmpty(sir.className)) {
+            Log.w(LOG_TAG, "Cannot index an empty Search Provider name!");
+            return null;
         }
 
-        mIndexData.add(row);
+        final Class<?> clazz = DatabaseIndexingUtils.getIndexableClass(sir.className);
+        if (clazz == null) {
+            Log.d(LOG_TAG, "SearchIndexableResource '" + sir.className +
+                    "' should implement the " + Indexable.class.getName() + " interface!");
+            return null;
+        }
+
+        // Will be non null only for a Local provider implementing a
+        // SEARCH_INDEX_DATA_PROVIDER field
+        return DatabaseIndexingUtils.getSearchIndexProvider(clazz);
     }
 }
diff --git a/src/com/android/settings/search/indexing/PreIndexDataCollector.java b/src/com/android/settings/search/indexing/PreIndexDataCollector.java
index 7186df8..a4e1131 100644
--- a/src/com/android/settings/search/indexing/PreIndexDataCollector.java
+++ b/src/com/android/settings/search/indexing/PreIndexDataCollector.java
@@ -31,6 +31,7 @@
 import android.text.TextUtils;
 import android.util.ArraySet;
 import android.util.Log;
+
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.settings.search.SearchIndexableRaw;
 import com.android.settings.search.SettingsSearchIndexablesProvider;
@@ -186,7 +187,7 @@
 
     @VisibleForTesting
     List<String> getNonIndexablesKeysFromRemoteProvider(String packageName,
-        String authority) {
+            String authority) {
         try {
             final Context packageContext = mContext.createPackageContext(packageName, 0);
 
diff --git a/src/com/android/settings/sim/SimPreferenceDialog.java b/src/com/android/settings/sim/SimPreferenceDialog.java
index d195724..2b6ebe3 100644
--- a/src/com/android/settings/sim/SimPreferenceDialog.java
+++ b/src/com/android/settings/sim/SimPreferenceDialog.java
@@ -40,6 +40,7 @@
 import android.widget.TextView;
 
 import com.android.settings.R;
+import com.android.settings.Utils;
 
 public class SimPreferenceDialog extends Activity {
 
@@ -98,13 +99,14 @@
 
         EditText nameText = (EditText)mDialogLayout.findViewById(R.id.sim_name);
         nameText.setText(savedInstanceState.getString(SIM_NAME));
+        Utils.setEditTextCursorPosition(nameText);
     }
 
     private void createEditDialog(Bundle bundle) {
         final Resources res = mContext.getResources();
         EditText nameText = (EditText)mDialogLayout.findViewById(R.id.sim_name);
         nameText.setText(mSubInfoRecord.getDisplayName());
-
+        Utils.setEditTextCursorPosition(nameText);
         final Spinner tintSpinner = (Spinner) mDialogLayout.findViewById(R.id.spinner);
         SelectColorAdapter adapter = new SelectColorAdapter(mContext,
                 R.layout.settings_color_picker_item, mColorStrings);
@@ -154,7 +156,7 @@
             @Override
             public void onClick(DialogInterface dialog, int whichButton) {
                 final EditText nameText = (EditText)mDialogLayout.findViewById(R.id.sim_name);
-
+                Utils.setEditTextCursorPosition(nameText);
                 String displayName = nameText.getText().toString();
                 int subId = mSubInfoRecord.getSubscriptionId();
                 mSubInfoRecord.setDisplayName(displayName);
diff --git a/tests/robotests/Android.mk b/tests/robotests/Android.mk
index ae0102f..97e5e04 100644
--- a/tests/robotests/Android.mk
+++ b/tests/robotests/Android.mk
@@ -9,12 +9,12 @@
 # Include the testing libraries (JUnit4 + Robolectric libs).
 LOCAL_STATIC_JAVA_LIBRARIES := \
     mockito-robolectric-prebuilt \
+    platform-robolectric-android-all-stubs \
     truth-prebuilt
 
 LOCAL_JAVA_LIBRARIES := \
     junit \
-    platform-robolectric-prebuilt \
-    sdk_vcurrent \
+    platform-robolectric-3.4.2-prebuilt \
     telephony-common
 
 LOCAL_INSTRUMENTATION_FOR := Settings
@@ -40,4 +40,6 @@
 
 LOCAL_INSTRUMENT_SOURCE_DIRS := $(dir $(LOCAL_PATH))../src
 
-include prebuilts/misc/common/robolectric/run_robotests.mk
\ No newline at end of file
+LOCAL_ROBOTEST_TIMEOUT := 36000
+
+include prebuilts/misc/common/robolectric/3.4.2/run_robotests.mk
diff --git a/tests/robotests/res/values-mcc999/config.xml b/tests/robotests/res/values-mcc999/config.xml
index 1588d5d..33a1d95 100644
--- a/tests/robotests/res/values-mcc999/config.xml
+++ b/tests/robotests/res/values-mcc999/config.xml
@@ -18,4 +18,5 @@
     <bool name="config_show_camera_hal_hdrplus">false</bool>
     <bool name="config_enableColorTemperature">false</bool>
     <bool name="config_show_camera_laser_sensor">false</bool>
+    <bool name="config_show_connectivity_monitor">false</bool>
 </resources>
\ No newline at end of file
diff --git a/tests/robotests/res/values/config.xml b/tests/robotests/res/values/config.xml
index 4f32bf7..0afbe29 100644
--- a/tests/robotests/res/values/config.xml
+++ b/tests/robotests/res/values/config.xml
@@ -20,4 +20,5 @@
     <bool name="config_enableColorTemperature">true</bool>
     <bool name="config_show_camera_laser_sensor">true</bool>
     <bool name="config_show_camera_hal_hdrplus">true</bool>
+    <bool name="config_show_connectivity_monitor">true</bool>
 </resources>
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/SettingsActivityTest.java b/tests/robotests/src/com/android/settings/SettingsActivityTest.java
index 3fc46e8..fac136c 100644
--- a/tests/robotests/src/com/android/settings/SettingsActivityTest.java
+++ b/tests/robotests/src/com/android/settings/SettingsActivityTest.java
@@ -26,7 +26,6 @@
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-import android.app.Activity;
 import android.app.ActivityManager;
 import android.app.FragmentManager;
 import android.app.FragmentTransaction;
@@ -35,10 +34,8 @@
 import android.content.Intent;
 import android.graphics.Bitmap;
 import android.os.Bundle;
-import android.view.Menu;
 
 import com.android.settings.search.SearchActivity;
-import com.android.settings.testutils.FakeFeatureFactory;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 
 import org.junit.Before;
@@ -50,7 +47,6 @@
 import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
 import org.robolectric.shadows.ShadowApplication;
-import org.robolectric.util.ReflectionHelpers;
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
diff --git a/tests/robotests/src/com/android/settings/SettingsLicenseActivityTest.java b/tests/robotests/src/com/android/settings/SettingsLicenseActivityTest.java
index dd17d9c..ecda97e 100644
--- a/tests/robotests/src/com/android/settings/SettingsLicenseActivityTest.java
+++ b/tests/robotests/src/com/android/settings/SettingsLicenseActivityTest.java
@@ -39,8 +39,8 @@
 import org.mockito.MockitoAnnotations;
 import org.robolectric.Robolectric;
 import org.robolectric.RuntimeEnvironment;
+import org.robolectric.android.controller.ActivityController;
 import org.robolectric.annotation.Config;
-import org.robolectric.util.ActivityController;
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
diff --git a/tests/robotests/src/com/android/settings/SetupChooseLockPatternTest.java b/tests/robotests/src/com/android/settings/SetupChooseLockPatternTest.java
index 69a1351..206ba95 100644
--- a/tests/robotests/src/com/android/settings/SetupChooseLockPatternTest.java
+++ b/tests/robotests/src/com/android/settings/SetupChooseLockPatternTest.java
@@ -37,9 +37,9 @@
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.robolectric.Robolectric;
-import org.robolectric.RuntimeEnvironment;
+import org.robolectric.Shadows;
 import org.robolectric.annotation.Config;
-import org.robolectric.res.builder.RobolectricPackageManager.ComponentState;
+import org.robolectric.shadows.ShadowPackageManager.ComponentState;
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(
@@ -57,7 +57,7 @@
 
     @Before
     public void setUp() {
-        RuntimeEnvironment.getRobolectricPackageManager().setComponentEnabledSetting(
+        Shadows.shadowOf(application.getPackageManager()).setComponentEnabledSetting(
                 new ComponentName(application, SetupRedactionInterstitial.class),
                 PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                 PackageManager.DONT_KILL_APP);
@@ -77,7 +77,7 @@
         findFragment(mActivity).onChosenLockSaveFinished(false, null);
 
         ComponentState redactionComponentState =
-                RuntimeEnvironment.getRobolectricPackageManager().getComponentState(
+                Shadows.shadowOf(application.getPackageManager()).getComponentState(
                         new ComponentName(application, SetupRedactionInterstitial.class));
         assertThat(redactionComponentState.newState).named("Redaction component state")
                 .isEqualTo(PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
diff --git a/tests/robotests/src/com/android/settings/UtilsTest.java b/tests/robotests/src/com/android/settings/UtilsTest.java
index 26b5b02..ca02c1d 100644
--- a/tests/robotests/src/com/android/settings/UtilsTest.java
+++ b/tests/robotests/src/com/android/settings/UtilsTest.java
@@ -25,6 +25,8 @@
 import android.text.SpannableStringBuilder;
 import android.text.format.DateUtils;
 import android.text.style.TtsSpan;
+import android.widget.EditText;
+import android.widget.TextView;
 
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.wrapper.DevicePolicyManagerWrapper;
@@ -325,4 +327,15 @@
         assertThat(Utils.isProfileOrDeviceOwner(mUserManager, mDevicePolicyManager,
                 PACKAGE_NAME)).isTrue();
     }
+
+    @Test
+    public void testSetEditTextCursorPosition_shouldGetExpectedEditTextLenght() {
+        final EditText editText = new EditText(mContext);
+        final CharSequence text = "test";
+        editText.setText(text, TextView.BufferType.EDITABLE);
+        final int length = editText.getText().length();
+        Utils.setEditTextCursorPosition(editText);
+
+        assertThat(editText.getSelectionEnd()).isEqualTo(length);
+    }
 }
diff --git a/tests/robotests/src/com/android/settings/accessibility/ShortcutServicePickerFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/ShortcutServicePickerFragmentTest.java
index 785bdbd..66621a0 100644
--- a/tests/robotests/src/com/android/settings/accessibility/ShortcutServicePickerFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/ShortcutServicePickerFragmentTest.java
@@ -16,14 +16,19 @@
 
 package com.android.settings.accessibility;
 
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
 import android.app.Activity;
 import android.content.Context;
 import android.os.UserManager;
 
-import android.test.mock.MockContentResolver;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settingslib.wrapper.PackageManagerWrapper;
 
 import org.junit.Before;
@@ -35,11 +40,6 @@
 import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
 
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
 public class ShortcutServicePickerFragmentTest {
@@ -58,7 +58,6 @@
     private PackageManagerWrapper mPackageManager;
 
     private ShortcutServicePickerFragment mFragment;
-    private MockContentResolver mContentResolver;
 
     @Before
     public void setUp() {
diff --git a/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java
index 15a3746..cfed83b 100644
--- a/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java
@@ -41,7 +41,6 @@
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.Robolectric;
-import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
 import org.robolectric.shadows.ShadowApplication;
 import org.robolectric.util.ReflectionHelpers;
diff --git a/tests/robotests/src/com/android/settings/accounts/AccountHeaderPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/AccountHeaderPreferenceControllerTest.java
index 34ac183..db1db10 100644
--- a/tests/robotests/src/com/android/settings/accounts/AccountHeaderPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AccountHeaderPreferenceControllerTest.java
@@ -18,6 +18,7 @@
 
 import static com.google.common.truth.Truth.assertThat;
 import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.when;
 
 import android.accounts.Account;
@@ -76,6 +77,7 @@
         FakeFeatureFactory.setupForTest(mContext);
         mHeaderPreference = new LayoutPreference(
                 RuntimeEnvironment.application, R.layout.settings_entity_header);
+        doReturn(mContext).when(mActivity).getApplicationContext();
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/accounts/UserAndAccountDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/accounts/UserAndAccountDashboardFragmentTest.java
index 8c13aab..8dba2f2 100644
--- a/tests/robotests/src/com/android/settings/accounts/UserAndAccountDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/UserAndAccountDashboardFragmentTest.java
@@ -17,7 +17,6 @@
 
 import android.app.Activity;
 import android.content.pm.UserInfo;
-import android.os.Bundle;
 import android.os.UserManager;
 import android.provider.SearchIndexableResource;
 
@@ -25,7 +24,6 @@
 import com.android.settings.TestConfig;
 import com.android.settings.dashboard.SummaryLoader;
 import com.android.settingslib.drawer.CategoryKey;
-import com.android.settingslib.drawer.Tile;
 
 import org.junit.Before;
 import org.junit.Test;
diff --git a/tests/robotests/src/com/android/settings/applications/AppStorageSizesControllerTest.java b/tests/robotests/src/com/android/settings/applications/AppStorageSizesControllerTest.java
index 8145b40..027bd33 100644
--- a/tests/robotests/src/com/android/settings/applications/AppStorageSizesControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/AppStorageSizesControllerTest.java
@@ -85,10 +85,10 @@
         mController.setResult(result);
         mController.updateUi(mContext);
 
-        assertThat(mAppPreference.getSummary()).isEqualTo("1.00B");
-        assertThat(mCachePreference.getSummary()).isEqualTo("10.00B");
-        assertThat(mDataPreference.getSummary()).isEqualTo("90.00B");
-        assertThat(mTotalPreference.getSummary()).isEqualTo("101B");
+        assertThat(mAppPreference.getSummary()).isEqualTo("1.00 B");
+        assertThat(mCachePreference.getSummary()).isEqualTo("10.00 B");
+        assertThat(mDataPreference.getSummary()).isEqualTo("90.00 B");
+        assertThat(mTotalPreference.getSummary()).isEqualTo("101 B");
     }
 
     @Test
@@ -103,10 +103,10 @@
         mController.setCacheCleared(true);
         mController.updateUi(mContext);
 
-        assertThat(mAppPreference.getSummary()).isEqualTo("1.00B");
-        assertThat(mCachePreference.getSummary()).isEqualTo("0.00B");
-        assertThat(mDataPreference.getSummary()).isEqualTo("90.00B");
-        assertThat(mTotalPreference.getSummary()).isEqualTo("91.00B");
+        assertThat(mAppPreference.getSummary()).isEqualTo("1.00 B");
+        assertThat(mCachePreference.getSummary()).isEqualTo("0.00 B");
+        assertThat(mDataPreference.getSummary()).isEqualTo("90.00 B");
+        assertThat(mTotalPreference.getSummary()).isEqualTo("91.00 B");
     }
 
     @Test
@@ -121,9 +121,9 @@
         mController.setDataCleared(true);
         mController.updateUi(mContext);
 
-        assertThat(mAppPreference.getSummary()).isEqualTo("1.00B");
-        assertThat(mCachePreference.getSummary()).isEqualTo("0.00B");
-        assertThat(mDataPreference.getSummary()).isEqualTo("0.00B");
-        assertThat(mTotalPreference.getSummary()).isEqualTo("1.00B");
+        assertThat(mAppPreference.getSummary()).isEqualTo("1.00 B");
+        assertThat(mCachePreference.getSummary()).isEqualTo("0.00 B");
+        assertThat(mDataPreference.getSummary()).isEqualTo("0.00 B");
+        assertThat(mTotalPreference.getSummary()).isEqualTo("1.00 B");
     }
 }
diff --git a/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java b/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
index 35f961b..93f364b 100644
--- a/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
@@ -192,7 +192,7 @@
         when(stats.getTotalBytes()).thenReturn(1L);
 
         assertThat(InstalledAppDetails.getStorageSummary(context, stats, true))
-                .isEqualTo("1.00B used in external storage");
+                .isEqualTo("1.00 B used in external storage");
     }
 
     @Test
@@ -202,7 +202,7 @@
         when(stats.getTotalBytes()).thenReturn(1L);
 
         assertThat(InstalledAppDetails.getStorageSummary(context, stats, false))
-                .isEqualTo("1.00B used in internal storage");
+                .isEqualTo("1.00 B used in internal storage");
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/applications/MusicViewHolderControllerTest.java b/tests/robotests/src/com/android/settings/applications/MusicViewHolderControllerTest.java
index 5df5bed..3d04c73 100644
--- a/tests/robotests/src/com/android/settings/applications/MusicViewHolderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/MusicViewHolderControllerTest.java
@@ -77,7 +77,7 @@
     public void storageShouldBeZeroBytesIfQueriedBeforeStorageQueryFinishes() {
         mController.setupView(mHolder);
 
-        assertThat(mHolder.summary.getText().toString()).isEqualTo("0.00B");
+        assertThat(mHolder.summary.getText().toString()).isEqualTo("0.00 B");
     }
 
     @Test
@@ -88,7 +88,7 @@
         mController.queryStats();
         mController.setupView(mHolder);
 
-        assertThat(mHolder.summary.getText().toString()).isEqualTo("1.00B");
+        assertThat(mHolder.summary.getText().toString()).isEqualTo("1.00 B");
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/applications/PhotosViewHolderControllerTest.java b/tests/robotests/src/com/android/settings/applications/PhotosViewHolderControllerTest.java
index 7eacba2..7bf338d 100644
--- a/tests/robotests/src/com/android/settings/applications/PhotosViewHolderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/PhotosViewHolderControllerTest.java
@@ -59,7 +59,7 @@
     public void storageShouldBeZeroBytesIfQueriedBeforeStorageQueryFinishes() {
         mController.setupView(mHolder);
 
-        assertThat(mHolder.summary.getText().toString()).isEqualTo("0.00B");
+        assertThat(mHolder.summary.getText().toString()).isEqualTo("0.00 B");
     }
 
     @Test
@@ -70,7 +70,7 @@
         mController.queryStats();
         mController.setupView(mHolder);
 
-        assertThat(mHolder.summary.getText().toString()).isEqualTo("11.00B");
+        assertThat(mHolder.summary.getText().toString()).isEqualTo("11.00 B");
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/applications/assist/DefaultAssistPickerTest.java b/tests/robotests/src/com/android/settings/applications/assist/DefaultAssistPickerTest.java
index 52916f5..65f0b46 100644
--- a/tests/robotests/src/com/android/settings/applications/assist/DefaultAssistPickerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/assist/DefaultAssistPickerTest.java
@@ -25,6 +25,7 @@
 import com.android.settings.TestConfig;
 
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.robolectric.RuntimeEnvironment;
@@ -42,8 +43,12 @@
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
 public class DefaultAssistPickerTest {
 
-    private static final ComponentName TEST_ASSIST =
-            new ComponentName("com.android.settings", "assist");
+    private static ComponentName sTestAssist;
+
+    @BeforeClass
+    public static void beforeClass() {
+        sTestAssist = new ComponentName("com.android.settings", "assist");
+    }
 
     private Context mContext;
     private DefaultAssistPicker mPicker;
@@ -59,22 +64,22 @@
     @Test
     public void setDefaultAppKey_shouldUpdateDefaultAssist() {
         final List<DefaultAssistPicker.Info> assistants = new ArrayList<>();
-        assistants.add(new DefaultAssistPicker.Info(TEST_ASSIST));
+        assistants.add(new DefaultAssistPicker.Info(sTestAssist));
         ReflectionHelpers.setField(mPicker, "mAvailableAssistants", assistants);
-        mPicker.setDefaultKey(TEST_ASSIST.flattenToString());
+        mPicker.setDefaultKey(sTestAssist.flattenToString());
 
         assertThat(Settings.Secure.getString(mContext.getContentResolver(),
                 Settings.Secure.ASSISTANT))
-                .isEqualTo(TEST_ASSIST.flattenToString());
+                .isEqualTo(sTestAssist.flattenToString());
         assertThat(mPicker.getDefaultKey())
-                .isEqualTo(TEST_ASSIST.flattenToString());
+                .isEqualTo(sTestAssist.flattenToString());
     }
 
     @Test
     public void setDefaultAppKey_noAvaialbleAssit_shouldClearDefaultAssist() {
         final List<DefaultAssistPicker.Info> assistants = new ArrayList<>();
         ReflectionHelpers.setField(mPicker, "mAvailableAssistants", assistants);
-        mPicker.setDefaultKey(TEST_ASSIST.flattenToString());
+        mPicker.setDefaultKey(sTestAssist.flattenToString());
 
         assertThat(Settings.Secure.getString(mContext.getContentResolver(),
                 Settings.Secure.ASSISTANT))
@@ -86,7 +91,7 @@
     @Test
     public void setDefaultAppKeyToNull_shouldClearDefaultAssist() {
         final List<DefaultAssistPicker.Info> assistants = new ArrayList<>();
-        assistants.add(new DefaultAssistPicker.Info(TEST_ASSIST));
+        assistants.add(new DefaultAssistPicker.Info(sTestAssist));
         ReflectionHelpers.setField(mPicker, "mAvailableAssistants", assistants);
         mPicker.setDefaultKey(null);
 
diff --git a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutofillPickerTest.java b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutofillPickerTest.java
index 9a3ec10..06d3b8b 100644
--- a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutofillPickerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutofillPickerTest.java
@@ -17,19 +17,19 @@
 package com.android.settings.applications.defaultapps;
 
 import static com.google.common.truth.Truth.assertThat;
+
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.when;
 
 import android.app.Activity;
-import android.content.ComponentName;
 import android.content.Context;
 import android.os.UserManager;
 
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settingslib.wrapper.PackageManagerWrapper;
 
 import org.junit.Before;
@@ -46,8 +46,7 @@
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
 public class DefaultAutofillPickerTest {
 
-    private static final String TEST_APP_KEY = new ComponentName("foo.bar",
-            "foo.bar.Baz").flattenToString();
+    private static final String TEST_APP_KEY = "foo.bar/foo.bar.Baz";
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private Activity mActivity;
diff --git a/tests/robotests/src/com/android/settings/applications/instantapps/InstantAppButtonsControllerTest.java b/tests/robotests/src/com/android/settings/applications/instantapps/InstantAppButtonsControllerTest.java
index f56fbbf..c7ca133 100644
--- a/tests/robotests/src/com/android/settings/applications/instantapps/InstantAppButtonsControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/instantapps/InstantAppButtonsControllerTest.java
@@ -51,6 +51,7 @@
 import com.android.settingslib.wrapper.PackageManagerWrapper;
 
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Answers;
@@ -66,11 +67,16 @@
 
     private static final String TEST_INSTALLER_PACKAGE_NAME = "com.installer";
     private static final String TEST_INSTALLER_ACTIVITY_NAME = "com.installer.InstallerActivity";
-    private static final ComponentName TEST_INSTALLER_COMPONENT =
-            new ComponentName(
-                    TEST_INSTALLER_PACKAGE_NAME,
-                    TEST_INSTALLER_ACTIVITY_NAME);
     private static final String TEST_AIA_PACKAGE_NAME = "test.aia.package";
+    private static ComponentName sTestInstallerComponent;
+
+    @BeforeClass
+    public static void beforeClass() {
+        sTestInstallerComponent =
+                new ComponentName(
+                        TEST_INSTALLER_PACKAGE_NAME,
+                        TEST_INSTALLER_ACTIVITY_NAME);
+    }
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     Context mockContext;
@@ -133,7 +139,7 @@
         receivedListener.onClick(mockInstallButton);
         assertThat(testFragment.getStartActivityIntent()).isNotNull();
         assertThat(testFragment.getStartActivityIntent().getComponent())
-                .isEqualTo(TEST_INSTALLER_COMPONENT);
+                .isEqualTo(sTestInstallerComponent);
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/backup/BackupSettingsActivityTest.java b/tests/robotests/src/com/android/settings/backup/BackupSettingsActivityTest.java
index 69c8a03..44c7e10 100644
--- a/tests/robotests/src/com/android/settings/backup/BackupSettingsActivityTest.java
+++ b/tests/robotests/src/com/android/settings/backup/BackupSettingsActivityTest.java
@@ -16,6 +16,8 @@
 
 package com.android.settings.backup;
 
+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.isA;
@@ -32,9 +34,9 @@
 import android.content.pm.PackageManager;
 import android.os.UserHandle;
 
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.search.SearchIndexableRaw;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 
 import org.junit.After;
 import org.junit.Before;
@@ -44,14 +46,13 @@
 import org.mockito.MockitoAnnotations;
 import org.robolectric.Robolectric;
 import org.robolectric.RuntimeEnvironment;
+import org.robolectric.Shadows;
+import org.robolectric.android.controller.ActivityController;
 import org.robolectric.annotation.Config;
 import org.robolectric.annotation.Implementation;
 import org.robolectric.annotation.Implements;
 import org.robolectric.annotation.Resetter;
-import org.robolectric.res.builder.RobolectricPackageManager;
-import org.robolectric.util.ActivityController;
-
-import static com.google.common.truth.Truth.assertThat;
+import org.robolectric.shadows.ShadowPackageManager;
 
 import java.util.List;
 
@@ -64,7 +65,7 @@
     private ActivityController<BackupSettingsActivity> mActivityController;
     private BackupSettingsActivity mActivity;
     private Application mApplication;
-    private RobolectricPackageManager mPackageManager;
+    private ShadowPackageManager mPackageManager;
     private static boolean mIsBackupProvidedByOEM;
 
     @Mock
@@ -84,7 +85,7 @@
         mApplication = RuntimeEnvironment.application;
         mActivityController = Robolectric.buildActivity(BackupSettingsActivity.class);
         mActivity = mActivityController.get();
-        mPackageManager = (RobolectricPackageManager) mApplication.getPackageManager();
+        mPackageManager = Shadows.shadowOf(mApplication.getPackageManager());
         doReturn(mComponent).when(mIntent).getComponent();
     }
 
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java
index 8fa8f06..b973edb 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java
@@ -38,6 +38,7 @@
 import com.android.settingslib.bluetooth.LocalBluetoothManager;
 
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.ArgumentCaptor;
@@ -62,8 +63,12 @@
 })
 public class BluetoothEnablerTest {
 
-    private static final EnforcedAdmin FAKE_ENFORCED_ADMIN =
-            new EnforcedAdmin(new ComponentName("test.package", "test.Class"), 10);
+    private static EnforcedAdmin sFakeEnforcedAdmin;
+
+    @BeforeClass
+    public static void beforeClass() {
+        sFakeEnforcedAdmin = new EnforcedAdmin(new ComponentName("test.package", "test.Class"), 10);
+    }
 
     @Mock
     private MetricsFeatureProvider mMetricsFeatureProvider;
@@ -130,7 +135,7 @@
     public void maybeEnforceRestrictions_disallowBluetoothRestrictionSet() {
         // GIVEN Bluetooth has been disallowed...
         when(mRestrictionUtils.checkIfRestrictionEnforced(
-                mContext, UserManager.DISALLOW_BLUETOOTH)).thenReturn(FAKE_ENFORCED_ADMIN);
+                mContext, UserManager.DISALLOW_BLUETOOTH)).thenReturn(sFakeEnforcedAdmin);
         when(mRestrictionUtils.checkIfRestrictionEnforced(
                 mContext, UserManager.DISALLOW_CONFIG_BLUETOOTH)).thenReturn(null);
 
@@ -139,7 +144,7 @@
         assertThat(mBluetoothEnabler.maybeEnforceRestrictions()).isTrue();
 
         // THEN the expected EnfoceAdmin is set.
-        verify(mMasterSwitchController).setDisabledByAdmin(FAKE_ENFORCED_ADMIN);
+        verify(mMasterSwitchController).setDisabledByAdmin(sFakeEnforcedAdmin);
 
         // THEN the switch is unchecked.
         verify(mMasterSwitchController).setChecked(false);
@@ -151,14 +156,14 @@
         when(mRestrictionUtils.checkIfRestrictionEnforced(
                 mContext, UserManager.DISALLOW_BLUETOOTH)).thenReturn(null);
         when(mRestrictionUtils.checkIfRestrictionEnforced(
-                mContext, UserManager.DISALLOW_CONFIG_BLUETOOTH)).thenReturn(FAKE_ENFORCED_ADMIN);
+                mContext, UserManager.DISALLOW_CONFIG_BLUETOOTH)).thenReturn(sFakeEnforcedAdmin);
 
         // WHEN the maybeEnforceRestrictions is called...
         // THEN true is returned to indicate there was a restriction to enforce.
         assertThat(mBluetoothEnabler.maybeEnforceRestrictions()).isTrue();
 
         // THEN the expected EnfoceAdmin is set.
-        verify(mMasterSwitchController).setDisabledByAdmin(FAKE_ENFORCED_ADMIN);
+        verify(mMasterSwitchController).setDisabledByAdmin(sFakeEnforcedAdmin);
 
         // THEN the switch is unchecked.
         verify(mMasterSwitchController).setChecked(false);
@@ -168,7 +173,7 @@
     public void maybeEnforceRestrictions_disallowBluetoothNotOverriden() {
         // GIVEN Bluetooth has been disallowed...
         when(mRestrictionUtils.checkIfRestrictionEnforced(
-                mContext, UserManager.DISALLOW_BLUETOOTH)).thenReturn(FAKE_ENFORCED_ADMIN);
+                mContext, UserManager.DISALLOW_BLUETOOTH)).thenReturn(sFakeEnforcedAdmin);
         when(mRestrictionUtils.checkIfRestrictionEnforced(
                 mContext, UserManager.DISALLOW_CONFIG_BLUETOOTH)).thenReturn(null);
 
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothFilesPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothFilesPreferenceControllerTest.java
index 7713aaf..cdaf876 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothFilesPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothFilesPreferenceControllerTest.java
@@ -22,7 +22,6 @@
 import android.content.Intent;
 import android.os.Bundle;
 import android.support.v7.preference.Preference;
-import android.text.TextUtils;
 
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
@@ -35,8 +34,6 @@
 import org.robolectric.annotation.Config;
 import org.robolectric.shadows.ShadowApplication;
 
-import java.util.List;
-
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
 public class BluetoothFilesPreferenceControllerTest {
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceControllerTest.java
index 9634661..c9d5746 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceControllerTest.java
@@ -21,7 +21,6 @@
 import android.support.v7.preference.Preference.OnPreferenceChangeListener;
 import android.support.v7.preference.PreferenceScreen;
 
-import com.android.settings.R;
 import com.android.settings.SettingsActivity;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
diff --git a/tests/robotests/src/com/android/settings/bluetooth/ForgetDeviceDialogFragmentTest.java b/tests/robotests/src/com/android/settings/bluetooth/ForgetDeviceDialogFragmentTest.java
index 21bc868..9343721 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/ForgetDeviceDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/ForgetDeviceDialogFragmentTest.java
@@ -33,7 +33,6 @@
 import com.android.settings.testutils.FakeFeatureFactory;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settingslib.bluetooth.CachedBluetoothDevice;
-import com.android.settingslib.bluetooth.LocalBluetoothManager;
 
 import org.junit.Before;
 import org.junit.Test;
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
index 2f4e6d8..a977872 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
@@ -23,6 +23,7 @@
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
+import static org.robolectric.RuntimeEnvironment.application;
 import static org.robolectric.Shadows.shadowOf;
 
 import android.app.Activity;
@@ -59,7 +60,6 @@
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.Robolectric;
-import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
 import org.robolectric.shadows.ShadowActivity;
 import org.robolectric.shadows.ShadowApplication;
@@ -138,7 +138,7 @@
 
     @Test
     public void bindPreference_noFragmentMetadata_shouldBindToProfileSelector() {
-        final Preference preference = new Preference(RuntimeEnvironment.application);
+        final Preference preference = new Preference(application);
         final Tile tile = new Tile();
         tile.metaData = new Bundle();
         tile.userHandle = new ArrayList<>();
@@ -159,7 +159,7 @@
 
     @Test
     public void bindPreference_noFragmentMetadataSingleUser_shouldBindToDirectLaunchIntent() {
-        final Preference preference = new Preference(RuntimeEnvironment.application);
+        final Preference preference = new Preference(application);
         final Tile tile = new Tile();
         tile.metaData = new Bundle();
         tile.userHandle = new ArrayList<>();
@@ -184,19 +184,19 @@
 
     @Test
     public void bindPreference_toInternalSettingActivity_shouldBindToDirectLaunchIntentAndNotLog() {
-        final Preference preference = new Preference(RuntimeEnvironment.application);
+        final Preference preference = new Preference(application);
         final Tile tile = new Tile();
         tile.metaData = new Bundle();
         tile.userHandle = new ArrayList<>();
         tile.userHandle.add(mock(UserHandle.class));
         tile.intent = new Intent();
         tile.intent.setComponent(
-                new ComponentName(RuntimeEnvironment.application.getPackageName(), "class"));
+                new ComponentName(application.getPackageName(), "class"));
 
         when(mActivity.getSystemService(Context.USER_SERVICE))
                 .thenReturn(mUserManager);
         when(mActivity.getApplicationContext().getPackageName())
-                .thenReturn(RuntimeEnvironment.application.getPackageName());
+                .thenReturn(application.getPackageName());
 
         mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.SETTINGS_GESTURES,
                 preference, tile, "123", Preference.DEFAULT_ORDER);
@@ -211,7 +211,7 @@
 
     @Test
     public void bindPreference_withNullKeyNullPriority_shouldGenerateKeyAndPriority() {
-        final Preference preference = new Preference(RuntimeEnvironment.application);
+        final Preference preference = new Preference(application);
         final Tile tile = new Tile();
         tile.intent = new Intent();
         tile.intent.setComponent(new ComponentName("pkg", "class"));
@@ -224,7 +224,7 @@
 
     @Test
     public void bindPreference_noSummary_shouldSetSummaryToPlaceholder() {
-        final Preference preference = new Preference(RuntimeEnvironment.application);
+        final Preference preference = new Preference(application);
         final Tile tile = new Tile();
         tile.intent = new Intent();
         tile.intent.setComponent(new ComponentName("pkg", "class"));
@@ -232,12 +232,12 @@
                 preference, tile, null /*key */, Preference.DEFAULT_ORDER);
 
         assertThat(preference.getSummary())
-                .isEqualTo(RuntimeEnvironment.application.getString(R.string.summary_placeholder));
+                .isEqualTo(application.getString(R.string.summary_placeholder));
     }
 
     @Test
     public void bindPreference_hasSummary_shouldSetSummary() {
-        final Preference preference = new Preference(RuntimeEnvironment.application);
+        final Preference preference = new Preference(application);
         final Tile tile = new Tile();
         tile.summary = "test";
         tile.intent = new Intent();
@@ -254,7 +254,7 @@
             ShadowThreadUtils.class
     })
     public void bindPreference_hasSummaryUri_shouldLoadSummaryFromContentProvider() {
-        final Preference preference = new Preference(RuntimeEnvironment.application);
+        final Preference preference = new Preference(application);
         final Tile tile = new Tile();
         tile.intent = new Intent();
         tile.intent.setComponent(new ComponentName("pkg", "class"));
@@ -270,7 +270,7 @@
 
     @Test
     public void bindPreference_withNullKeyTileKey_shouldUseTileKey() {
-        final Preference preference = new Preference(RuntimeEnvironment.application);
+        final Preference preference = new Preference(application);
         final Tile tile = new Tile();
         tile.key = "key";
         tile.intent = new Intent();
@@ -287,12 +287,12 @@
             ShadowThreadUtils.class
     })
     public void bindPreference_withIconUri_shouldLoadIconFromContentProvider() {
-        final Preference preference = new Preference(RuntimeEnvironment.application);
+        final Preference preference = new Preference(application);
         final Tile tile = new Tile();
         tile.key = "key";
         tile.intent = new Intent();
         tile.intent.setComponent(
-                new ComponentName(RuntimeEnvironment.application.getPackageName(), "class"));
+                new ComponentName(application.getPackageName(), "class"));
         tile.metaData = new Bundle();
         tile.metaData.putString(TileUtils.META_DATA_PREFERENCE_ICON_URI,
                 "content://com.android.settings/tile_icon");
@@ -304,7 +304,7 @@
     @Test
     public void bindPreference_withBaseOrder_shouldOffsetPriority() {
         final int baseOrder = 100;
-        final Preference preference = new Preference(RuntimeEnvironment.application);
+        final Preference preference = new Preference(application);
         final Tile tile = new Tile();
         tile.metaData = new Bundle();
         tile.priority = 10;
@@ -316,7 +316,7 @@
 
     @Test
     public void bindPreference_withOrderMetadata_shouldUseOrderInMetadata() {
-        final Preference preference = new Preference(RuntimeEnvironment.application);
+        final Preference preference = new Preference(application);
         final int testOrder = -30;
         final Tile tile = new Tile();
         tile.metaData = new Bundle();
@@ -330,7 +330,7 @@
 
     @Test
     public void bindPreference_invalidOrderMetadata_shouldIgnore() {
-        final Preference preference = new Preference(RuntimeEnvironment.application);
+        final Preference preference = new Preference(application);
         final Tile tile = new Tile();
         tile.metaData = new Bundle();
         tile.metaData.putString(mImpl.META_DATA_KEY_ORDER, "hello");
@@ -368,7 +368,7 @@
     @Test
     public void clickPreference_withUnresolvableIntent_shouldNotLaunchAnything() {
         ReflectionHelpers.setField(
-                mImpl, "mPackageManager", RuntimeEnvironment.getPackageManager());
+                mImpl, "mPackageManager", application.getPackageManager());
         Activity activity = Robolectric.buildActivity(Activity.class).get();
         final ShadowApplication application = ShadowApplication.getInstance();
         final Preference preference = new Preference(application.getApplicationContext());
diff --git a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionLogHelperTest.java b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionLogHelperTest.java
index 8eb4273..01d253f 100644
--- a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionLogHelperTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionLogHelperTest.java
@@ -21,9 +21,15 @@
 import android.util.Pair;
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.annotation.Config;
 
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
 public class SuggestionLogHelperTest {
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/datausage/DataPlanSummaryPreferenceTest.java b/tests/robotests/src/com/android/settings/datausage/DataPlanSummaryPreferenceTest.java
index a5dbf78..9ddce53 100644
--- a/tests/robotests/src/com/android/settings/datausage/DataPlanSummaryPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/DataPlanSummaryPreferenceTest.java
@@ -31,6 +31,7 @@
 import com.android.settings.widget.DonutView;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.robolectric.RuntimeEnvironment;
@@ -48,9 +49,16 @@
     private static final String TEST_PLAN_USAGE = "Test plan usage";
     private static final String TEST_PLAN_NAME = "Test plan name";
     private static final String TEST_PLAN_DESCRIPTION = "Test plan description";
-    private static final int PLAN_USAGE_TEXT_COLOR = Color.parseColor("#FF5C94F1");
-    private static final int METER_BACKGROUND_COLOR = Color.parseColor("#FFDBDCDC");
-    private static final int METER_CONSUMED_COLOR = Color.parseColor("#FF5C94F1");
+    private static int sPlanUsageTextColor;
+    private static int sMeterBackgroundColor;
+    private static int sMeterConsumedColor;
+
+    @BeforeClass
+    public static void beforeClass() {
+        sPlanUsageTextColor = Color.parseColor("#FF5C94F1");
+        sMeterBackgroundColor = Color.parseColor("#FFDBDCDC");
+        sMeterConsumedColor = Color.parseColor("#FF5C94F1");
+    }
 
     private DataPlanSummaryPreference mPreference;
     private PreferenceViewHolder mHolder;
@@ -87,18 +95,18 @@
     @Test
     public void shouldRender_withData() {
         mPreference.setTitle(TEST_PLAN_USAGE);
-        mPreference.setUsageTextColor(PLAN_USAGE_TEXT_COLOR);
+        mPreference.setUsageTextColor(sPlanUsageTextColor);
         mPreference.setName(TEST_PLAN_NAME);
         mPreference.setDescription(TEST_PLAN_DESCRIPTION);
         mPreference.setPercentageUsage(0.25D);
-        mPreference.setMeterBackgroundColor(METER_BACKGROUND_COLOR);
-        mPreference.setMeterConsumedColor(METER_CONSUMED_COLOR);
+        mPreference.setMeterBackgroundColor(sMeterBackgroundColor);
+        mPreference.setMeterConsumedColor(sMeterConsumedColor);
 
         mPreference.onBindViewHolder(mHolder);
 
         TextView planUsageTextView = (TextView) mHolder.findViewById(android.R.id.title);
         assertThat(planUsageTextView.getTextColors().getDefaultColor())
-                .isEqualTo(PLAN_USAGE_TEXT_COLOR);
+                .isEqualTo(sPlanUsageTextColor);
         assertThat(planUsageTextView.getText()).isEqualTo(TEST_PLAN_USAGE);
 
         TextView planNameTextView = (TextView) mHolder.findViewById(android.R.id.text1);
@@ -108,7 +116,7 @@
         assertThat(planDescriptionTextView.getText()).isEqualTo(TEST_PLAN_DESCRIPTION);
 
         DonutView donutView = (DonutView) mHolder.findViewById(R.id.donut);
-        assertThat(donutView.getMeterBackgroundColor()).isEqualTo(METER_BACKGROUND_COLOR);
-        assertThat(donutView.getMeterConsumedColor()).isEqualTo(METER_CONSUMED_COLOR);
+        assertThat(donutView.getMeterBackgroundColor()).isEqualTo(sMeterBackgroundColor);
+        assertThat(donutView.getMeterConsumedColor()).isEqualTo(sMeterConsumedColor);
     }
 }
diff --git a/tests/robotests/src/com/android/settings/datausage/DataPlanUsageSummaryTest.java b/tests/robotests/src/com/android/settings/datausage/DataPlanUsageSummaryTest.java
index 30c7736..72e0b10 100644
--- a/tests/robotests/src/com/android/settings/datausage/DataPlanUsageSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/DataPlanUsageSummaryTest.java
@@ -34,7 +34,6 @@
 import com.android.settings.TestConfig;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.testutils.XmlTestUtils;
-import com.android.settings.testutils.shadow.ShadowConnectivityManager;
 import com.android.settings.testutils.shadow.ShadowDataUsageUtils;
 import com.android.settingslib.NetworkPolicyEditor;
 import java.util.ArrayList;
diff --git a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
index 431796a..750f785 100644
--- a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
@@ -31,17 +31,14 @@
 import com.android.settings.R;
 import com.android.settings.TestConfig;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
-import com.android.settings.testutils.XmlTestUtils;
-import com.android.settings.testutils.shadow.ShadowConnectivityManager;
 import com.android.settingslib.NetworkPolicyEditor;
 import java.util.ArrayList;
-import java.util.List;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
-import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
 import org.robolectric.shadows.ShadowApplication;
 import org.robolectric.util.ReflectionHelpers;
diff --git a/tests/robotests/src/com/android/settings/datetime/AutoTimeFormatPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datetime/AutoTimeFormatPreferenceControllerTest.java
index 82d3dd9..06969bb 100644
--- a/tests/robotests/src/com/android/settings/datetime/AutoTimeFormatPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/datetime/AutoTimeFormatPreferenceControllerTest.java
@@ -30,16 +30,13 @@
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import java.util.List;
 import java.util.Locale;
-import org.junit.After;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.annotation.Config;
-import org.robolectric.annotation.Implementation;
-import org.robolectric.annotation.Implements;
-import org.robolectric.annotation.Resetter;
 import org.robolectric.shadows.ShadowApplication;
 
 @RunWith(SettingsRobolectricTestRunner.class)
diff --git a/tests/robotests/src/com/android/settings/datetime/TimeFormatPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datetime/TimeFormatPreferenceControllerTest.java
index 31b6841..cd13513 100644
--- a/tests/robotests/src/com/android/settings/datetime/TimeFormatPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/datetime/TimeFormatPreferenceControllerTest.java
@@ -39,7 +39,6 @@
 import static com.google.common.truth.Truth.assertThat;
 import static org.mockito.Answers.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
diff --git a/tests/robotests/src/com/android/settings/development/AdbPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/AdbPreferenceControllerTest.java
new file mode 100644
index 0000000..2404f67
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/development/AdbPreferenceControllerTest.java
@@ -0,0 +1,152 @@
+/*
+ * 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.development;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.os.UserManager;
+import android.provider.Settings;
+import android.support.v14.preference.SwitchPreference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class AdbPreferenceControllerTest {
+    @Mock
+    private Context mContext;
+    @Mock
+    private SwitchPreference mPreference;
+    @Mock
+    private PreferenceScreen mPreferenceScreen;
+    @Mock
+    private UserManager mUserManager;
+    @Mock
+    private DevelopmentSettingsDashboardFragment mFragment;
+
+    private ContentResolver mContentResolver;
+    private AdbPreferenceController mController;
+
+    @Before
+    public void setup() {
+        MockitoAnnotations.initMocks(this);
+        mContentResolver = RuntimeEnvironment.application.getContentResolver();
+        mController = new AdbPreferenceController(mContext, mFragment);
+        when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
+        when(mContext.getContentResolver()).thenReturn(mContentResolver);
+        when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
+                mPreference);
+        mController.displayPreference(mPreferenceScreen);
+    }
+
+    @Test
+    public void isAvailable_notAdmin_shouldBeFalse() {
+        when(mUserManager.isAdminUser()).thenReturn(false);
+
+        assertThat(mController.isAvailable()).isFalse();
+    }
+
+    @Test
+    public void isAvailable_isAdmin_shouldBeTrue() {
+        when(mUserManager.isAdminUser()).thenReturn(true);
+
+        assertThat(mController.isAvailable()).isTrue();
+    }
+
+    @Test
+    public void onPreferenceChanged_settingDisabled_shouldTurnOffAdb() {
+        when(mContext.getApplicationContext()).thenReturn(RuntimeEnvironment.application);
+        mController.onPreferenceChange(null, false);
+
+        final int mode = Settings.System.getInt(mContentResolver,
+                Settings.Global.ADB_ENABLED, -1);
+
+        assertThat(mode).isEqualTo(AdbPreferenceController.ADB_SETTING_OFF);
+    }
+
+    @Test
+    public void updateState_settingEnabled_preferenceShouldBeChecked() {
+        Settings.System.putInt(mContentResolver, Settings.Global.ADB_ENABLED,
+                AdbPreferenceController.ADB_SETTING_ON);
+        mController.updateState(mPreference);
+
+        verify(mPreference).setChecked(true);
+    }
+
+    @Test
+    public void updateState_settingDisabled_preferenceShouldNotBeChecked() {
+        Settings.System.putInt(mContentResolver, Settings.Global.ADB_ENABLED,
+                AdbPreferenceController.ADB_SETTING_OFF);
+        mController.updateState(mPreference);
+
+        verify(mPreference).setChecked(false);
+    }
+
+    @Test
+    public void onDeveloperOptionsDisabled_shouldDisablePreference() {
+        when(mContext.getApplicationContext()).thenReturn(RuntimeEnvironment.application);
+        when(mUserManager.isAdminUser()).thenReturn(true);
+        mController.onDeveloperOptionsDisabled();
+        final int mode = Settings.System.getInt(mContentResolver,
+                Settings.Global.ADB_ENABLED, -1);
+
+        assertThat(mode).isEqualTo(AdbPreferenceController.ADB_SETTING_OFF);
+        verify(mPreference).setEnabled(false);
+        verify(mPreference).setChecked(false);
+    }
+
+    @Test
+    public void onDeveloperOptionsEnabled_shouldEnablePreference() {
+        when(mUserManager.isAdminUser()).thenReturn(true);
+        mController.onDeveloperOptionsEnabled();
+
+        verify(mPreference).setEnabled(true);
+    }
+
+    @Test
+    public void onAdbDialogConfirmed_shouldEnableAdbSetting() {
+        mController.onAdbDialogConfirmed();
+        final int mode = Settings.System.getInt(mContentResolver,
+                Settings.Global.ADB_ENABLED, -1);
+
+        assertThat(mode).isEqualTo(AdbPreferenceController.ADB_SETTING_ON);
+    }
+
+    @Test
+    public void onAdbDialogDismissed_preferenceShouldNotBeChecked() {
+        Settings.System.putInt(mContentResolver, Settings.Global.ADB_ENABLED,
+                AdbPreferenceController.ADB_SETTING_OFF);
+        mController.onAdbDialogDismissed();
+
+        verify(mPreference).setChecked(false);
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/development/BluetoothAbsoluteVolumePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/BluetoothAbsoluteVolumePreferenceControllerTest.java
new file mode 100644
index 0000000..09e6e9c
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/development/BluetoothAbsoluteVolumePreferenceControllerTest.java
@@ -0,0 +1,124 @@
+/*
+ * 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.development;
+
+
+import static com.android.settings.development.BluetoothAbsoluteVolumePreferenceController
+        .BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_PROPERTY;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.support.v14.preference.SwitchPreference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH,
+        sdk = TestConfig.SDK_VERSION,
+        shadows = {SettingsShadowSystemProperties.class})
+public class BluetoothAbsoluteVolumePreferenceControllerTest {
+
+    @Mock
+    private SwitchPreference mPreference;
+    @Mock
+    private PreferenceScreen mPreferenceScreen;
+
+    private Context mContext;
+    private BluetoothAbsoluteVolumePreferenceController mController;
+
+    @Before
+    public void setup() {
+        MockitoAnnotations.initMocks(this);
+        mContext = RuntimeEnvironment.application;
+        mController = new BluetoothAbsoluteVolumePreferenceController(mContext);
+        when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
+                mPreference);
+        mController.displayPreference(mPreferenceScreen);
+    }
+
+    @Test
+    public void onPreferenceChanged_settingEnabled_shouldTurnOnBluetoothDisableAbsoluteVolume() {
+        mController.onPreferenceChange(mPreference, true /* new value */);
+
+        final boolean mode = SettingsShadowSystemProperties.getBoolean(
+                BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_PROPERTY, false /* default */);
+
+        assertThat(mode).isTrue();
+    }
+
+    @Test
+    public void onPreferenceChanged_settingDisabled_shouldTurnOffBluetoothDisableAbsoluteVolume() {
+        mController.onPreferenceChange(mPreference, false /* new value */);
+
+        final boolean mode = SettingsShadowSystemProperties.getBoolean(
+                BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_PROPERTY, false /* default */);
+
+        assertThat(mode).isFalse();
+    }
+
+    @Test
+    public void updateState_settingEnabled_preferenceShouldBeChecked() {
+        SettingsShadowSystemProperties.set(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_PROPERTY,
+                Boolean.toString(true));
+        mController.updateState(mPreference);
+
+        verify(mPreference).setChecked(true);
+    }
+
+    @Test
+    public void updateState_settingDisabled_preferenceShouldNotBeChecked() {
+        SettingsShadowSystemProperties.set(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_PROPERTY,
+                Boolean.toString(false));
+        mController.updateState(mPreference);
+
+        verify(mPreference).setChecked(false);
+    }
+
+    @Test
+    public void onDeveloperOptionsDisabled_shouldDisablePreference() {
+        mController.onDeveloperOptionsDisabled();
+
+        final boolean mode = SettingsShadowSystemProperties.getBoolean(
+                BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_PROPERTY, false /* default */);
+
+        assertThat(mode).isFalse();
+        verify(mPreference).setEnabled(false);
+        verify(mPreference).setChecked(false);
+    }
+
+    @Test
+    public void onDeveloperOptionsEnabled_shouldEnablePreference() {
+        mController.onDeveloperOptionsEnabled();
+
+        verify(mPreference).setEnabled(true);
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/development/CameraHalHdrPlusPreferenceControllerV2Test.java b/tests/robotests/src/com/android/settings/development/CameraHalHdrPlusPreferenceControllerV2Test.java
index d4e7e20..f28fd6e 100644
--- a/tests/robotests/src/com/android/settings/development/CameraHalHdrPlusPreferenceControllerV2Test.java
+++ b/tests/robotests/src/com/android/settings/development/CameraHalHdrPlusPreferenceControllerV2Test.java
@@ -16,11 +16,6 @@
 
 package com.android.settings.development;
 
-import static com.android.settings.development.CameraHalHdrPlusPreferenceControllerV2.ENG_BUILD;
-import static com.android.settings.development
-        .CameraHalHdrPlusPreferenceControllerV2.USERDEBUG_BUILD;
-import static com.android.settings.development.CameraHalHdrPlusPreferenceControllerV2.USER_BUILD;
-
 import static com.google.common.truth.Truth.assertThat;
 
 import static org.mockito.Mockito.verify;
@@ -57,6 +52,8 @@
     private Context mContext;
     private CameraHalHdrPlusPreferenceControllerV2 mController;
 
+    static final String USERDEBUG_BUILD = "userdebug";
+
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
@@ -82,30 +79,6 @@
     }
 
     @Test
-    public void isAvailable_withUserdebugBuild_shouldReturnTrue() {
-        SettingsShadowSystemProperties.set(
-                CameraHalHdrPlusPreferenceControllerV2.BUILD_TYPE, USERDEBUG_BUILD);
-
-        assertThat(mController.isAvailable()).isTrue();
-    }
-
-    @Test
-    public void isAvailable_withEngBuild_shouldReturnTrue() {
-        SettingsShadowSystemProperties.set(
-                CameraHalHdrPlusPreferenceControllerV2.BUILD_TYPE, ENG_BUILD);
-
-        assertThat(mController.isAvailable()).isTrue();
-    }
-
-    @Test
-    public void isAvailable_withUserBuild_shouldReturnFalse() {
-        SettingsShadowSystemProperties.set(
-                CameraHalHdrPlusPreferenceControllerV2.BUILD_TYPE, USER_BUILD);
-
-        assertThat(mController.isAvailable()).isFalse();
-    }
-
-    @Test
     public void updateState_cameraHalHdrPlusEnabled_shouldCheckedPreference() {
         SettingsShadowSystemProperties.set(
                 CameraHalHdrPlusPreferenceControllerV2.PROPERTY_CAMERA_HAL_HDRPLUS,
diff --git a/tests/robotests/src/com/android/settings/development/CameraHalHdrplusPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/CameraHalHdrplusPreferenceControllerTest.java
index 913c7dd..48833e4 100644
--- a/tests/robotests/src/com/android/settings/development/CameraHalHdrplusPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/CameraHalHdrplusPreferenceControllerTest.java
@@ -57,8 +57,6 @@
     private SwitchPreference mPreference;
 
     static final String USERDEBUG_BUILD = "userdebug";
-    static final String ENG_BUILD = "eng";
-    static final String USER_BUILD = "user";
 
     private CameraHalHdrplusPreferenceController mController;
 
@@ -83,39 +81,6 @@
     }
 
     @Test
-    public void isAvailable_withUserdebugBuild_shouldReturnTrue() {
-        when(mContext.getResources().getBoolean(R.bool.config_show_camera_hal_hdrplus))
-                .thenReturn(true);
-
-        SettingsShadowSystemProperties.set(
-                CameraHalHdrplusPreferenceController.BUILD_TYPE, USERDEBUG_BUILD);
-
-        assertThat(mController.isAvailable()).isTrue();
-    }
-
-    @Test
-    public void isAvailable_withEngBuild_shouldReturnTrue() {
-        when(mContext.getResources().getBoolean(R.bool.config_show_camera_hal_hdrplus))
-                .thenReturn(true);
-
-        SettingsShadowSystemProperties.set(
-                CameraHalHdrplusPreferenceController.BUILD_TYPE, ENG_BUILD);
-
-        assertThat(mController.isAvailable()).isTrue();
-    }
-
-    @Test
-    public void isAvailable_withUserBuild_shouldReturnFalse() {
-        when(mContext.getResources().getBoolean(R.bool.config_show_camera_hal_hdrplus))
-                .thenReturn(true);
-
-        SettingsShadowSystemProperties.set(
-                CameraHalHdrplusPreferenceController.BUILD_TYPE, USER_BUILD);
-
-        assertThat(mController.isAvailable()).isFalse();
-    }
-
-    @Test
     public void displayPreference_cameraHalHdrplusEnabled_shouldCheckedPreference() {
         when(mContext.getResources().getBoolean(R.bool.config_show_camera_hal_hdrplus))
                 .thenReturn(true);
diff --git a/tests/robotests/src/com/android/settings/development/CameraLaserSensorPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/CameraLaserSensorPreferenceControllerTest.java
index 25c09fe..4003d9f 100644
--- a/tests/robotests/src/com/android/settings/development/CameraLaserSensorPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/CameraLaserSensorPreferenceControllerTest.java
@@ -34,7 +34,6 @@
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.annotation.Config;
-import org.robolectric.RuntimeEnvironment;
 
 import static com.google.common.truth.Truth.assertThat;
 import static org.mockito.Mockito.verify;
diff --git a/tests/robotests/src/com/android/settings/development/ConnectivityMonitorPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/ConnectivityMonitorPreferenceControllerTest.java
index d968ff9..bb9a6ee 100644
--- a/tests/robotests/src/com/android/settings/development/ConnectivityMonitorPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/ConnectivityMonitorPreferenceControllerTest.java
@@ -38,6 +38,10 @@
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
+/**
+ * deprecated in favor of {@link ConnectivityMonitorPreferenceControllerV2}
+ */
+@Deprecated
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
 public class ConnectivityMonitorPreferenceControllerTest {
diff --git a/tests/robotests/src/com/android/settings/development/ConnectivityMonitorPreferenceControllerV2Test.java b/tests/robotests/src/com/android/settings/development/ConnectivityMonitorPreferenceControllerV2Test.java
new file mode 100644
index 0000000..5b4f594
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/development/ConnectivityMonitorPreferenceControllerV2Test.java
@@ -0,0 +1,220 @@
+/*
+ * 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.development;
+
+import static com.android.settings.development.ConnectivityMonitorPreferenceControllerV2.ENG_BUILD;
+import static com.android.settings.development
+        .ConnectivityMonitorPreferenceControllerV2.USERDEBUG_BUILD;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.os.SystemProperties;
+import android.support.v14.preference.SwitchPreference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows =
+        SettingsShadowSystemProperties.class)
+public class ConnectivityMonitorPreferenceControllerV2Test {
+
+    private static final String USER_BUILD = "user";
+
+    @Mock
+    private PreferenceScreen mScreen;
+    @Mock
+    private SwitchPreference mPreference;
+
+    private Context mContext;
+    private ConnectivityMonitorPreferenceControllerV2 mController;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        SettingsShadowSystemProperties.clear();
+        mContext = RuntimeEnvironment.application;
+        mController = new ConnectivityMonitorPreferenceControllerV2(mContext);
+        when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
+        mController.displayPreference(mScreen);
+    }
+
+    @Test
+    public void isAvailable_trueShowFlagWithUserdebugBuild_shouldReturnTrue() {
+        SettingsShadowSystemProperties.set(
+                ConnectivityMonitorPreferenceControllerV2.BUILD_TYPE, USERDEBUG_BUILD);
+
+        assertThat(mController.isAvailable()).isTrue();
+    }
+
+    @Test
+    public void isAvailable_trueShowFlagWithEngBuild_shouldReturnTrue() {
+        SettingsShadowSystemProperties.set(
+                ConnectivityMonitorPreferenceControllerV2.BUILD_TYPE, ENG_BUILD);
+
+        assertThat(mController.isAvailable()).isTrue();
+    }
+
+    @Test
+    public void isAvailable_trueShowFlagWithUserBuild_shouldReturnFalse() {
+        SettingsShadowSystemProperties.set(
+                ConnectivityMonitorPreferenceControllerV2.BUILD_TYPE, USER_BUILD);
+
+        assertThat(mController.isAvailable()).isFalse();
+    }
+
+    @Test
+    @Config(qualifiers = "mcc999")
+    public void isAvailable_falseShowFlagWithUserdebugBuild_shouldReturnFalse() {
+        SettingsShadowSystemProperties.set(
+                ConnectivityMonitorPreferenceControllerV2.BUILD_TYPE, USERDEBUG_BUILD);
+
+        assertThat(mController.isAvailable()).isFalse();
+    }
+
+    @Test
+    @Config(qualifiers = "mcc999")
+    public void isAvailable_falseShowFlagWithEngBuild_shouldReturnFalse() {
+        SettingsShadowSystemProperties.set(
+                ConnectivityMonitorPreferenceControllerV2.BUILD_TYPE, ENG_BUILD);
+
+        assertThat(mController.isAvailable()).isFalse();
+    }
+
+    @Test
+    @Config(qualifiers = "mcc999")
+    public void isAvailable_falseShowFlagWithUserBuild_shouldReturnFalse() {
+        SettingsShadowSystemProperties.set(
+                ConnectivityMonitorPreferenceControllerV2.BUILD_TYPE, USER_BUILD);
+
+        assertThat(mController.isAvailable()).isFalse();
+    }
+
+    @Test
+    public void updateState_connectivityMonitorEnabled_shouldCheckedPreference() {
+        SettingsShadowSystemProperties.set(
+                ConnectivityMonitorPreferenceControllerV2.PROPERTY_CONNECTIVITY_MONITOR,
+                ConnectivityMonitorPreferenceControllerV2.ENABLED_STATUS);
+        SettingsShadowSystemProperties.set(
+                ConnectivityMonitorPreferenceControllerV2.BUILD_TYPE, USERDEBUG_BUILD);
+
+        mController.updateState(mPreference);
+
+        verify(mPreference).setChecked(true);
+    }
+
+    @Test
+    public void updateState_connectivityMonitorUserEnabled_shouldCheckedPreference() {
+        SettingsShadowSystemProperties.set(
+                ConnectivityMonitorPreferenceControllerV2.PROPERTY_CONNECTIVITY_MONITOR,
+                ConnectivityMonitorPreferenceControllerV2.USER_ENABLED_STATUS);
+        SettingsShadowSystemProperties.set(
+                ConnectivityMonitorPreferenceControllerV2.BUILD_TYPE, USERDEBUG_BUILD);
+
+        mController.updateState(mPreference);
+
+        verify(mPreference).setChecked(true);
+    }
+
+    @Test
+    public void updateState_connectivityMonitorDisabled_shouldUncheckedPreference() {
+        SettingsShadowSystemProperties.set(
+                ConnectivityMonitorPreferenceControllerV2.PROPERTY_CONNECTIVITY_MONITOR,
+                ConnectivityMonitorPreferenceControllerV2.DISABLED_STATUS);
+        SettingsShadowSystemProperties.set(
+                ConnectivityMonitorPreferenceControllerV2.BUILD_TYPE, USERDEBUG_BUILD);
+
+        mController.updateState(mPreference);
+
+        verify(mPreference).setChecked(false);
+    }
+
+    @Test
+    public void updateState_connectivityMonitorUserDisabled_shouldUncheckedPreference() {
+        SettingsShadowSystemProperties.set(
+                ConnectivityMonitorPreferenceControllerV2.PROPERTY_CONNECTIVITY_MONITOR,
+                ConnectivityMonitorPreferenceControllerV2.USER_DISABLED_STATUS);
+        SettingsShadowSystemProperties.set(
+                ConnectivityMonitorPreferenceControllerV2.BUILD_TYPE, USERDEBUG_BUILD);
+
+        mController.updateState(mPreference);
+
+        verify(mPreference).setChecked(false);
+    }
+
+    @Test
+    public void onPreferenceChange_preferenceChecked_shouldEnableConnectivityMonitor() {
+        SystemProperties.set(
+                ConnectivityMonitorPreferenceControllerV2.PROPERTY_CONNECTIVITY_MONITOR,
+                ConnectivityMonitorPreferenceControllerV2.USER_ENABLED_STATUS);
+
+        mController.handlePreferenceTreeClick(mPreference);
+
+        assertThat(ConnectivityMonitorPreferenceControllerV2.USER_ENABLED_STATUS).isEqualTo(
+                SystemProperties.get(
+                        ConnectivityMonitorPreferenceControllerV2.PROPERTY_CONNECTIVITY_MONITOR,
+                        ConnectivityMonitorPreferenceControllerV2.DISABLED_STATUS));
+    }
+
+    @Test
+    public void onPreferenceChange_preferenceUnchecked_shouldDisableConnectivityMonitor() {
+        SystemProperties.set(
+                ConnectivityMonitorPreferenceControllerV2.PROPERTY_CONNECTIVITY_MONITOR,
+                ConnectivityMonitorPreferenceControllerV2.USER_DISABLED_STATUS);
+
+        mController.handlePreferenceTreeClick(mPreference);
+
+        assertThat(ConnectivityMonitorPreferenceControllerV2.USER_DISABLED_STATUS).isEqualTo(
+                SystemProperties.get(
+                        ConnectivityMonitorPreferenceControllerV2.PROPERTY_CONNECTIVITY_MONITOR,
+                        ConnectivityMonitorPreferenceControllerV2.DISABLED_STATUS));
+    }
+
+    @Test
+    public void onDeveloperOptionsSwitchEnabled_shouldEnablePreference() {
+        mController.onDeveloperOptionsSwitchEnabled();
+
+        verify(mPreference).setEnabled(true);
+    }
+
+    @Test
+    public void onDeveloperOptionsSwitchDisabled_shouldDisablePreference() {
+        mController.onDeveloperOptionsSwitchDisabled();
+
+        String mode = SystemProperties.get(
+                ConnectivityMonitorPreferenceControllerV2.PROPERTY_CONNECTIVITY_MONITOR,
+                null /* default */);
+
+        assertThat(mode).isEqualTo(ConnectivityMonitorPreferenceControllerV2.USER_DISABLED_STATUS);
+        verify(mPreference).setEnabled(false);
+        verify(mPreference).setChecked(false);
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/development/DevelopmentSettingsDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/development/DevelopmentSettingsDashboardFragmentTest.java
index 13f7374..7121a30 100644
--- a/tests/robotests/src/com/android/settings/development/DevelopmentSettingsDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/development/DevelopmentSettingsDashboardFragmentTest.java
@@ -113,7 +113,8 @@
 
     @Test
     @Config(shadows = {
-            ShadowPictureColorModePreferenceController.class
+            ShadowPictureColorModePreferenceController.class,
+            ShadowAdbPreferenceController.class
     })
     public void searchIndex_pageEnabled_shouldNotAddKeysToNonIndexable() {
         final Context appContext = RuntimeEnvironment.application;
@@ -186,6 +187,26 @@
         verify(controller).onOemUnlockDismissed();
     }
 
+    @Test
+    public void onAdbDialogConfirmed_shouldCallControllerDialogConfirmed() {
+        final AdbPreferenceController controller = mock(AdbPreferenceController.class);
+        doReturn(controller).when(mDashboard).getDevelopmentOptionsController(
+                AdbPreferenceController.class);
+        mDashboard.onEnableAdbDialogConfirmed();
+
+        verify(controller).onAdbDialogConfirmed();
+    }
+
+    @Test
+    public void onAdbDialogDismissed_shouldCallControllerOemDismissed() {
+        final AdbPreferenceController controller = mock(AdbPreferenceController.class);
+        doReturn(controller).when(mDashboard).getDevelopmentOptionsController(
+                AdbPreferenceController.class);
+        mDashboard.onEnableAdbDialogDismissed();
+
+        verify(controller).onAdbDialogDismissed();
+    }
+
     @Implements(EnableDevelopmentSettingWarningDialog.class)
     public static class ShadowEnableDevelopmentSettingWarningDialog {
 
@@ -204,7 +225,14 @@
 
     @Implements(PictureColorModePreferenceController.class)
     public static class ShadowPictureColorModePreferenceController {
+        @Implementation
+        public boolean isAvailable() {
+            return true;
+        }
+    }
 
+    @Implements(AdbPreferenceController.class)
+    public static class ShadowAdbPreferenceController {
         @Implementation
         public boolean isAvailable() {
             return true;
diff --git a/tests/robotests/src/com/android/settings/development/EnableAdbPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/EnableAdbPreferenceControllerTest.java
index 6dcfbf2..e7080eb 100644
--- a/tests/robotests/src/com/android/settings/development/EnableAdbPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/EnableAdbPreferenceControllerTest.java
@@ -31,6 +31,10 @@
 import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
 
+/**
+ * @deprecated in favor of {@link AdbPreferenceController}
+ */
+@Deprecated
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
 public class EnableAdbPreferenceControllerTest {
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 bd40240..8ebfb89 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceControllerTest.java
@@ -97,8 +97,8 @@
         mController.updateBytes(0, 32 * GIGABYTE);
         mController.updateState(mPreference);
 
-        assertThat(mPreference.getTitle().toString()).isEqualTo("0.00B");
-        assertThat(mPreference.getSummary().toString()).isEqualTo("Used of 32GB");
+        assertThat(mPreference.getTitle().toString()).isEqualTo("0.00 B");
+        assertThat(mPreference.getSummary().toString()).isEqualTo("Used of 32 GB");
     }
 
     @Test
@@ -106,8 +106,8 @@
         mController.updateBytes(KILOBYTE, KILOBYTE * 10);
         mController.updateState(mPreference);
 
-        assertThat(mPreference.getTitle().toString()).isEqualTo("1.00KB");
-        assertThat(mPreference.getSummary().toString()).isEqualTo("Used of 10KB");
+        assertThat(mPreference.getTitle().toString()).isEqualTo("1.00 KB");
+        assertThat(mPreference.getSummary().toString()).isEqualTo("Used of 10 KB");
     }
 
     @Test
@@ -123,8 +123,8 @@
         mController.updateSizes(svp, volume);
         mController.updateState(mPreference);
 
-        assertThat(mPreference.getTitle().toString()).isEqualTo("9.00KB");
-        assertThat(mPreference.getSummary().toString()).isEqualTo("Used of 10KB");
+        assertThat(mPreference.getTitle().toString()).isEqualTo("9.00 KB");
+        assertThat(mPreference.getSummary().toString()).isEqualTo("Used of 10 KB");
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerTest.java
index 66bdba1..95144bd 100644
--- a/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerTest.java
@@ -17,6 +17,7 @@
 package com.android.settings.display;
 
 import static com.google.common.truth.Truth.assertThat;
+
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.reset;
@@ -30,8 +31,8 @@
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceScreen;
 
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.wrapper.PowerManagerWrapper;
 
 import org.junit.Before;
@@ -41,7 +42,7 @@
 import org.mockito.MockitoAnnotations;
 import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
-import org.robolectric.internal.ShadowExtractor;
+import org.robolectric.shadow.api.Shadow;
 import org.robolectric.shadows.ShadowContentResolver;
 
 @RunWith(SettingsRobolectricTestRunner.class)
@@ -80,14 +81,13 @@
     }
 
     @Test
-    public void onResume_shouldRegisterObserver() {
+    public void onStart_shouldRegisterObserver() {
         Context context = RuntimeEnvironment.application;
         BrightnessLevelPreferenceController controller =
             new BrightnessLevelPreferenceController(context, null, mPowerManager);
-        ShadowContentResolver shadowContentResolver =
-            (ShadowContentResolver) ShadowExtractor.extract(context.getContentResolver());
+        ShadowContentResolver shadowContentResolver = Shadow.extract(context.getContentResolver());
 
-        controller.onResume();
+        controller.onStart();
 
         assertThat(shadowContentResolver.getContentObservers(
             System.getUriFor(System.SCREEN_BRIGHTNESS_MODE))).isNotEmpty();
@@ -100,16 +100,15 @@
     }
 
     @Test
-    public void onPause_shouldUnregisterObserver() {
+    public void onStop_shouldUnregisterObserver() {
         Context context = RuntimeEnvironment.application;
         BrightnessLevelPreferenceController controller =
             new BrightnessLevelPreferenceController(context, null, mPowerManager);
-        ShadowContentResolver shadowContentResolver =
-            (ShadowContentResolver) ShadowExtractor.extract(context.getContentResolver());
+        ShadowContentResolver shadowContentResolver = Shadow.extract(context.getContentResolver());
 
         controller.displayPreference(mScreen);
-        controller.onResume();
-        controller.onPause();
+        controller.onStart();
+        controller.onStop();
 
         assertThat(shadowContentResolver.getContentObservers(
             System.getUriFor(System.SCREEN_BRIGHTNESS_MODE))).isEmpty();
diff --git a/tests/robotests/src/com/android/settings/fingerprint/FingerprintEnrollFindSensorTest.java b/tests/robotests/src/com/android/settings/fingerprint/FingerprintEnrollFindSensorTest.java
index 6e58b13..d495b74 100644
--- a/tests/robotests/src/com/android/settings/fingerprint/FingerprintEnrollFindSensorTest.java
+++ b/tests/robotests/src/com/android/settings/fingerprint/FingerprintEnrollFindSensorTest.java
@@ -47,7 +47,6 @@
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.Robolectric;
-import org.robolectric.RuntimeEnvironment;
 import org.robolectric.Shadows;
 import org.robolectric.annotation.Config;
 import org.robolectric.shadows.ShadowActivity;
@@ -75,8 +74,6 @@
         MockitoAnnotations.initMocks(this);
         ShadowUtils.setFingerprintManager(mFingerprintManager);
 
-        RuntimeEnvironment.getAppResourceLoader().getResourceIndex();
-
         mActivity = Robolectric.buildActivity(
                 FingerprintEnrollFindSensor.class,
                 new Intent()
diff --git a/tests/robotests/src/com/android/settings/fingerprint/FingerprintSuggestionActivityTest.java b/tests/robotests/src/com/android/settings/fingerprint/FingerprintSuggestionActivityTest.java
index bf2dfae..0254bcb 100644
--- a/tests/robotests/src/com/android/settings/fingerprint/FingerprintSuggestionActivityTest.java
+++ b/tests/robotests/src/com/android/settings/fingerprint/FingerprintSuggestionActivityTest.java
@@ -42,10 +42,10 @@
 import org.mockito.MockitoAnnotations;
 import org.robolectric.Robolectric;
 import org.robolectric.Shadows;
+import org.robolectric.android.controller.ActivityController;
 import org.robolectric.annotation.Config;
 import org.robolectric.shadows.ShadowActivity;
 import org.robolectric.shadows.ShadowKeyguardManager;
-import org.robolectric.util.ActivityController;
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(
diff --git a/tests/robotests/src/com/android/settings/fingerprint/SetupFingerprintEnrollFindSensorTest.java b/tests/robotests/src/com/android/settings/fingerprint/SetupFingerprintEnrollFindSensorTest.java
index b2ef65b..c3899e9 100644
--- a/tests/robotests/src/com/android/settings/fingerprint/SetupFingerprintEnrollFindSensorTest.java
+++ b/tests/robotests/src/com/android/settings/fingerprint/SetupFingerprintEnrollFindSensorTest.java
@@ -40,7 +40,6 @@
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.Robolectric;
-import org.robolectric.RuntimeEnvironment;
 import org.robolectric.Shadows;
 import org.robolectric.annotation.Config;
 import org.robolectric.shadows.ShadowAlertDialog;
@@ -66,8 +65,6 @@
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         ShadowUtils.setFingerprintManager(mFingerprintManager);
-        RuntimeEnvironment.getAppResourceLoader().getResourceIndex();
-
     }
 
     private void createActivity(Intent intent) {
diff --git a/tests/robotests/src/com/android/settings/fingerprint/SetupFingerprintEnrollIntroductionTest.java b/tests/robotests/src/com/android/settings/fingerprint/SetupFingerprintEnrollIntroductionTest.java
index f5859ac..2d98bf4 100644
--- a/tests/robotests/src/com/android/settings/fingerprint/SetupFingerprintEnrollIntroductionTest.java
+++ b/tests/robotests/src/com/android/settings/fingerprint/SetupFingerprintEnrollIntroductionTest.java
@@ -48,15 +48,14 @@
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.Robolectric;
-import org.robolectric.RuntimeEnvironment;
 import org.robolectric.Shadows;
+import org.robolectric.android.controller.ActivityController;
 import org.robolectric.annotation.Config;
 import org.robolectric.annotation.Implementation;
 import org.robolectric.annotation.Implements;
 import org.robolectric.shadows.ShadowActivity;
 import org.robolectric.shadows.ShadowActivity.IntentForResult;
 import org.robolectric.shadows.ShadowKeyguardManager;
-import org.robolectric.util.ActivityController;
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(
@@ -80,7 +79,7 @@
     public void setUp() {
         MockitoAnnotations.initMocks(this);
 
-        RuntimeEnvironment.getRobolectricPackageManager()
+        Shadows.shadowOf(application.getPackageManager())
                 .setSystemFeature(PackageManager.FEATURE_FINGERPRINT, true);
         ShadowFingerprintManager.addToServiceMap();
 
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java
index 4353b54..e010cf3 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java
@@ -38,6 +38,7 @@
 
 import com.android.settings.R;
 import com.android.settings.TestConfig;
+import com.android.settings.testutils.shadow.SettingsShadowResources;
 import com.android.settings.wrapper.DevicePolicyManagerWrapper;
 
 import org.junit.Before;
@@ -54,7 +55,13 @@
 import org.robolectric.util.FragmentTestUtil;
 
 @RunWith(RobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(
+        manifest = TestConfig.MANIFEST_PATH,
+        sdk = TestConfig.SDK_VERSION,
+        shadows = {
+                SettingsShadowResources.class,
+                SettingsShadowResources.SettingsShadowTheme.class
+        })
 public class BackgroundActivityPreferenceControllerTest {
     private static final int UID_LOW_SDK = 1234;
     private static final int UID_HIGH_SDK = 3456;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryEntryTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryEntryTest.java
index a461f46..a57b6ca 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryEntryTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryEntryTest.java
@@ -147,7 +147,7 @@
     }
 
     @Test
-    public void extractPackageFromSipper_normalSipper_returnDefaultPakcage() {
+    public void extractPackageFromSipper_normalSipper_returnDefaultPackage() {
         BatteryEntry entry = createBatteryEntryForApp();
 
         assertThat(entry.extractPackagesFromSipper(entry.sipper)).isEqualTo(entry.sipper.mPackages);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoLoaderTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoLoaderTest.java
index 796e63c..b87089a 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoLoaderTest.java
@@ -26,7 +26,6 @@
 
 import android.content.Context;
 import android.content.Intent;
-import android.os.BatteryManager;
 import android.os.BatteryStats;
 import com.android.internal.os.BatteryStatsHelper;
 import com.android.settings.TestConfig;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
index 6bde839..8030463 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
@@ -37,7 +37,6 @@
 import android.support.v7.preference.PreferenceGroup;
 import android.support.v7.preference.PreferenceManager;
 
-import android.view.View;
 import com.android.internal.os.BatterySipper;
 import com.android.internal.os.BatterySipper.DrainType;
 import com.android.internal.os.BatteryStatsHelper;
@@ -133,7 +132,7 @@
         when(mShadowContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
                 mConnectivityManager);
 
-        mPowerUsageData = new PowerUsageData(UsageType.SYSTEM);
+        mPowerUsageData = new PowerUsageData(UsageType.USER);
         mMaxBatterySipper.totalPowerMah = TYPE_BLUETOOTH_USAGE;
         mMaxBatterySipper.drainType = DrainType.BLUETOOTH;
         mNormalBatterySipper.drainType = DrainType.SCREEN;
@@ -342,6 +341,13 @@
     }
 
     @Test
+    public void testShouldHideSummary_typeSystem_returnTrue() {
+        mPowerUsageData.usageType = UsageType.SYSTEM;
+
+        assertThat(mPowerUsageAdvanced.shouldHideSummary(mPowerUsageData)).isTrue();
+    }
+
+    @Test
     public void testShouldHideSummary_typeWifi_returnTrue() {
         mPowerUsageData.usageType = UsageType.WIFI;
 
@@ -364,7 +370,7 @@
 
     @Test
     public void testShouldHideSummary_typeNormal_returnFalse() {
-        mPowerUsageData.usageType = UsageType.SYSTEM;
+        mPowerUsageData.usageType = UsageType.IDLE;
 
         assertThat(mPowerUsageAdvanced.shouldHideSummary(mPowerUsageData)).isFalse();
     }
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
index 5971711..4385409 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
@@ -66,6 +66,7 @@
 import com.android.settingslib.core.AbstractPreferenceController;
 
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Answers;
@@ -107,10 +108,14 @@
     private static final double BATTERY_OVERCOUNTED_USAGE = 500;
     private static final double PRECISION = 0.001;
     private static final double POWER_USAGE_PERCENTAGE = 50;
-    private static final Intent ADDITIONAL_BATTERY_INFO_INTENT =
-            new Intent("com.example.app.ADDITIONAL_BATTERY_INFO");
     public static final String NEW_ML_EST_SUFFIX = "(New ML est)";
     public static final String OLD_EST_SUFFIX = "(Old est)";
+    private static Intent sAdditionalBatteryInfoIntent;
+
+    @BeforeClass
+    public static void beforeClass() {
+        sAdditionalBatteryInfoIntent =new Intent("com.example.app.ADDITIONAL_BATTERY_INFO");
+    }
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private Context mContext;
@@ -188,7 +193,7 @@
         when(mToggleAppsMenu.getItemId()).thenReturn(MENU_TOGGLE_APPS);
         when(mHighPowerMenu.getItemId()).thenReturn(MENU_HIGH_POWER_APPS);
         when(mFeatureFactory.powerUsageFeatureProvider.getAdditionalBatteryInfoIntent())
-                .thenReturn(ADDITIONAL_BATTERY_INFO_INTENT);
+                .thenReturn(sAdditionalBatteryInfoIntent);
         when(mBatteryHelper.getTotalPower()).thenReturn(TOTAL_POWER);
         when(mBatteryHelper.getStats().computeBatteryRealtime(anyLong(), anyInt())).thenReturn(
                 TIME_SINCE_LAST_FULL_CHARGE_US);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyDialogFragmentTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyDialogFragmentTest.java
index 1111804..8431fde 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalyDialogFragmentTest.java
@@ -19,7 +19,6 @@
 import static com.google.common.truth.Truth.assertThat;
 
 import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyInt;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.spy;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalySummaryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalySummaryPreferenceControllerTest.java
index 8297e81..3f48d0a 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalySummaryPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/AnomalySummaryPreferenceControllerTest.java
@@ -32,7 +32,6 @@
 import android.support.v7.preference.Preference;
 
 import com.android.settings.SettingsActivity;
-import com.android.settings.fuelgauge.BatteryUtils;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/BluetoothScanAnomalyDetectorTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/BluetoothScanAnomalyDetectorTest.java
index f8d02ff..edf026a 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/BluetoothScanAnomalyDetectorTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/BluetoothScanAnomalyDetectorTest.java
@@ -26,7 +26,6 @@
 import static org.mockito.Mockito.spy;
 
 import android.content.Context;
-import android.content.pm.ApplicationInfo;
 import android.os.BatteryStats;
 import android.text.format.DateUtils;
 
diff --git a/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsTest.java b/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsTest.java
index 7ea42b8..041b7e0 100644
--- a/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsTest.java
@@ -27,7 +27,6 @@
 import com.android.settings.TestConfig;
 import com.android.settings.testutils.FakeFeatureFactory;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
-import com.android.settingslib.core.AbstractPreferenceController;
 
 import org.junit.Before;
 import org.junit.Test;
diff --git a/tests/robotests/src/com/android/settings/gestures/PIckupGesturePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/PickupGesturePreferenceControllerTest.java
similarity index 98%
rename from tests/robotests/src/com/android/settings/gestures/PIckupGesturePreferenceControllerTest.java
rename to tests/robotests/src/com/android/settings/gestures/PickupGesturePreferenceControllerTest.java
index 833f016..a2a6923 100644
--- a/tests/robotests/src/com/android/settings/gestures/PIckupGesturePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/PickupGesturePreferenceControllerTest.java
@@ -43,7 +43,7 @@
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
-public class PIckupGesturePreferenceControllerTest {
+public class PickupGesturePreferenceControllerTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationPreferenceControllerTest.java
index d4fc014..063d7eb 100644
--- a/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationPreferenceControllerTest.java
@@ -16,33 +16,26 @@
 
 package com.android.settings.gestures;
 
-import android.content.ContentResolver;
 import android.content.Context;
 import android.content.pm.PackageManager;
-import android.content.res.Resources;
 import android.hardware.fingerprint.FingerprintManager;
 import android.provider.Settings;
 
-import com.android.settings.search.InlinePayload;
-import com.android.settings.search.InlineSwitchPayload;
-import com.android.settings.search.ResultPayload;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 
-import com.android.settings.testutils.shadow.ShadowSecureSettings;
 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 org.robolectric.shadows.ShadowApplication;
 
 import static android.provider.Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED;
 import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.ArgumentMatchers.anyInt;
+
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
diff --git a/tests/robotests/src/com/android/settings/inputmethod/UserDictionaryCursorLoaderTest.java b/tests/robotests/src/com/android/settings/inputmethod/UserDictionaryCursorLoaderTest.java
index a76aebc..7b149f3 100644
--- a/tests/robotests/src/com/android/settings/inputmethod/UserDictionaryCursorLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/inputmethod/UserDictionaryCursorLoaderTest.java
@@ -49,7 +49,7 @@
         MockitoAnnotations.initMocks(this);
         mContentProvider = new FakeProvider();
         mLoader = new UserDictionaryCursorLoader(RuntimeEnvironment.application, "" /* locale */);
-        ShadowContentResolver.registerProvider(UserDictionary.AUTHORITY, mContentProvider);
+        ShadowContentResolver.registerProviderInternal(UserDictionary.AUTHORITY, mContentProvider);
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/inputmethod/UserDictionaryListTest.java b/tests/robotests/src/com/android/settings/inputmethod/UserDictionaryListTest.java
index c6793cb..91fcaae 100644
--- a/tests/robotests/src/com/android/settings/inputmethod/UserDictionaryListTest.java
+++ b/tests/robotests/src/com/android/settings/inputmethod/UserDictionaryListTest.java
@@ -47,7 +47,7 @@
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         mContentProvider = new FakeProvider();
-        ShadowContentResolver.registerProvider(UserDictionary.AUTHORITY, mContentProvider);
+        ShadowContentResolver.registerProviderInternal(UserDictionary.AUTHORITY, mContentProvider);
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/location/LocationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/LocationPreferenceControllerTest.java
index c7e0e0a..87691a5 100644
--- a/tests/robotests/src/com/android/settings/location/LocationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/location/LocationPreferenceControllerTest.java
@@ -15,7 +15,6 @@
  */
 package com.android.settings.location;
 
-import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE;
 import static com.google.common.truth.Truth.assertThat;
 
 import static org.mockito.ArgumentMatchers.nullable;
@@ -35,10 +34,8 @@
 import android.support.v7.preference.PreferenceScreen;
 
 import com.android.settings.R;
-import com.android.settings.display.AutoBrightnessPreferenceController;
 import com.android.settings.search.InlineListPayload;
 import com.android.settings.search.InlinePayload;
-import com.android.settings.search.InlineSwitchPayload;
 import com.android.settings.search.ResultPayload;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
@@ -53,7 +50,6 @@
 import org.mockito.MockitoAnnotations;
 import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
-import org.robolectric.shadows.ShadowApplication;
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
diff --git a/tests/robotests/src/com/android/settings/notification/NotificationBackendTest.java b/tests/robotests/src/com/android/settings/notification/NotificationBackendTest.java
index 97c0d94..089e330 100644
--- a/tests/robotests/src/com/android/settings/notification/NotificationBackendTest.java
+++ b/tests/robotests/src/com/android/settings/notification/NotificationBackendTest.java
@@ -16,21 +16,13 @@
 
 package com.android.settings.notification;
 
-import android.app.NotificationManager;
-import android.app.NotificationManager.Policy;
-import android.content.Context;
-import android.support.v7.preference.Preference;
-
-import com.android.settings.R;
 import com.android.settings.notification.NotificationBackend.AppRow;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import org.robolectric.annotation.Config;
 
-import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.mockito.Mock;
 
 import static junit.framework.Assert.assertEquals;
 import static junit.framework.Assert.assertTrue;
diff --git a/tests/robotests/src/com/android/settings/notification/SuppressorHelperTest.java b/tests/robotests/src/com/android/settings/notification/SuppressorHelperTest.java
index 86f3d81..74c41f3 100644
--- a/tests/robotests/src/com/android/settings/notification/SuppressorHelperTest.java
+++ b/tests/robotests/src/com/android/settings/notification/SuppressorHelperTest.java
@@ -21,12 +21,19 @@
 import android.content.pm.ServiceInfo;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
 
 import static com.google.common.truth.Truth.assertThat;
 import static org.mockito.Mockito.when;
 
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
 public class SuppressorHelperTest {
     private static final String SUPPRESSOR_NAME = "wear";
 
diff --git a/tests/robotests/src/com/android/settings/search/CursorToSearchResultConverterTest.java b/tests/robotests/src/com/android/settings/search/CursorToSearchResultConverterTest.java
index 47d5287..cd62c15 100644
--- a/tests/robotests/src/com/android/settings/search/CursorToSearchResultConverterTest.java
+++ b/tests/robotests/src/com/android/settings/search/CursorToSearchResultConverterTest.java
@@ -37,6 +37,7 @@
 import com.android.settings.wifi.WifiSettings;
 
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Answers;
@@ -59,9 +60,14 @@
     private static final String TARGET_PACKAGE = "a.b.c";
     private static final String TARGET_CLASS = "a.b.c.class";
     private static final String KEY = "key";
-    private static final Intent INTENT = new Intent("com.android.settings");
     private static final int ICON = R.drawable.ic_search_24dp;
     private static final int BASE_RANK = 1;
+    private static Intent sIntent;
+
+    @BeforeClass
+    public static void beforeClass() {
+        sIntent = new Intent("com.android.settings");
+    }
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private SiteMapManager mSiteMapManager;
@@ -120,7 +126,7 @@
     @Test
     public void testParseCursor_MatchesIcon() {
         final MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
-        final byte[] payload = ResultPayloadUtils.marshall(new ResultPayload(INTENT));
+        final byte[] payload = ResultPayloadUtils.marshall(new ResultPayload(sIntent));
         final String BLANK = "";
         cursor.addRow(new Object[]{
                 KEY.hashCode(),      // Doc ID
@@ -171,7 +177,7 @@
     @Test
     public void testLongTitle_PenalizedInRank() {
         final MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
-        final byte[] payload = ResultPayloadUtils.marshall(new ResultPayload(INTENT));
+        final byte[] payload = ResultPayloadUtils.marshall(new ResultPayload(sIntent));
         final String BLANK = "";
         cursor.addRow(new Object[]{
                 KEY.hashCode(),      // Doc ID
@@ -203,7 +209,7 @@
         for (SearchResult result : results) {
             payload = result.payload;
             Intent intent = payload.getIntent();
-            assertThat(intent.getAction()).isEqualTo(INTENT.getAction());
+            assertThat(intent.getAction()).isEqualTo(sIntent.getAction());
         }
     }
 
@@ -375,7 +381,7 @@
     private MatrixCursor getDummyCursor(String[] keys, String className) {
         MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
         final String BLANK = "";
-        final byte[] payload = ResultPayloadUtils.marshall(new ResultPayload(INTENT));
+        final byte[] payload = ResultPayloadUtils.marshall(new ResultPayload(sIntent));
 
         for (int i = 0; i < keys.length; i++) {
             ArrayList<Object> item = new ArrayList<>(DatabaseResultLoader.SELECT_COLUMNS.length);
@@ -386,7 +392,7 @@
             item.add(className); // classname
             item.add(BLANK); // screen title
             item.add(null); // Icon
-            item.add(INTENT.getAction()); // Intent action
+            item.add(sIntent.getAction()); // Intent action
             item.add(TARGET_PACKAGE); // target package
             item.add(TARGET_CLASS); // target class
             item.add(keys[i]); // Key
diff --git a/tests/robotests/src/com/android/settings/search/InlinePayloadTest.java b/tests/robotests/src/com/android/settings/search/InlinePayloadTest.java
index 1747cca..8bb558f 100644
--- a/tests/robotests/src/com/android/settings/search/InlinePayloadTest.java
+++ b/tests/robotests/src/com/android/settings/search/InlinePayloadTest.java
@@ -3,7 +3,6 @@
 import android.content.Context;
 import android.content.ContentResolver;
 import android.content.Intent;
-import android.os.Parcel;
 import android.provider.Settings;
 import com.android.settings.TestConfig;
 import com.android.settings.search.ResultPayload.SettingsSource;
diff --git a/tests/robotests/src/com/android/settings/search/SearchFragmentTest.java b/tests/robotests/src/com/android/settings/search/SearchFragmentTest.java
index d78a818..4976c6a 100644
--- a/tests/robotests/src/com/android/settings/search/SearchFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/search/SearchFragmentTest.java
@@ -60,8 +60,8 @@
 import org.mockito.MockitoAnnotations;
 import org.robolectric.Robolectric;
 import org.robolectric.RuntimeEnvironment;
+import org.robolectric.android.controller.ActivityController;
 import org.robolectric.annotation.Config;
-import org.robolectric.util.ActivityController;
 import org.robolectric.util.ReflectionHelpers;
 
 import java.util.Set;
diff --git a/tests/robotests/src/com/android/settings/search/indexing/FakeSettingsFragment.java b/tests/robotests/src/com/android/settings/search/indexing/FakeSettingsFragment.java
index 72df771..e857ae4 100644
--- a/tests/robotests/src/com/android/settings/search/indexing/FakeSettingsFragment.java
+++ b/tests/robotests/src/com/android/settings/search/indexing/FakeSettingsFragment.java
@@ -19,12 +19,12 @@
 
 import android.content.Context;
 import android.provider.SearchIndexableResource;
+
 import com.android.internal.logging.nano.MetricsProto;
 import com.android.settings.dashboard.DashboardFragment;
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settings.search.SearchIndexableRaw;
 import com.android.settingslib.core.AbstractPreferenceController;
-import com.android.settingslib.core.lifecycle.Lifecycle;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -76,7 +76,8 @@
     public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
             new BaseSearchIndexProvider() {
                 @Override
-                public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) {
+                public List<SearchIndexableRaw> getRawDataToIndex(Context context,
+                        boolean enabled) {
                     final SearchIndexableRaw data = new SearchIndexableRaw(context);
                     data.title = TITLE;
                     data.summaryOn = SUMMARY_ON;
@@ -118,7 +119,7 @@
 
                 @Override
                 public List<AbstractPreferenceController>
-                        getPreferenceControllers(Context context) {
+                getPreferenceControllers(Context context) {
                     return null;
                 }
             };
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 b5bfea0..cac6f3a 100644
--- a/tests/robotests/src/com/android/settings/search/indexing/IndexDataConverterTest.java
+++ b/tests/robotests/src/com/android/settings/search/indexing/IndexDataConverterTest.java
@@ -20,6 +20,7 @@
 import android.content.Context;
 import android.provider.SearchIndexableResource;
 import android.text.TextUtils;
+
 import com.android.settings.TestConfig;
 import com.android.settings.R;
 import com.android.settings.search.ResultPayload;
@@ -27,6 +28,7 @@
 import com.android.settings.search.SearchIndexableRaw;
 import com.android.settings.testutils.DatabaseTestUtils;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -40,6 +42,7 @@
 import java.util.Set;
 
 import static com.google.common.truth.Truth.assertThat;
+
 import static org.mockito.Mockito.spy;
 
 @RunWith(SettingsRobolectricTestRunner.class)
@@ -97,7 +100,7 @@
     @Before
     public void setUp() {
         mContext = spy(RuntimeEnvironment.application);
-        mConverter = spy(new IndexDataConverter(mContext));
+        mConverter = spy(new IndexDataConverter(mContext, localeStr));
     }
 
     @After
@@ -110,8 +113,7 @@
         final SearchIndexableRaw raw = getFakeRaw();
         final PreIndexData preIndexData = new PreIndexData();
         preIndexData.dataToUpdate.add(raw);
-        List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData,
-                localeStr);
+        List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData);
 
         assertThat(indexData.size()).isEqualTo(1);
         final IndexData row = indexData.get(0);
@@ -148,8 +150,7 @@
         preIndexData.dataToUpdate.add(raw);
         preIndexData.nonIndexableKeys.put(raw.intentTargetPackage, keys);
 
-        List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData,
-                localeStr);
+        List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData);
 
         assertThat(indexData.size()).isEqualTo(1);
         assertThat(indexData.get(0).enabled).isFalse();
@@ -163,8 +164,7 @@
         final SearchIndexableRaw raw = getFakeRaw("ca-fr");
         PreIndexData preIndexData = new PreIndexData();
         preIndexData.dataToUpdate.add(raw);
-        List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData,
-                localeStr);
+        List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData);
 
         assertThat(indexData).isEmpty();
     }
@@ -175,8 +175,7 @@
     @Test
     public void testNullResource_NothingInserted() {
         PreIndexData preIndexData = new PreIndexData();
-        List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData,
-                localeStr);
+        List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData);
 
         assertThat(indexData).isEmpty();
     }
@@ -187,8 +186,7 @@
         final PreIndexData preIndexData = new PreIndexData();
         preIndexData.dataToUpdate.add(resource);
 
-        final List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData,
-                localeStr);
+        final List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData);
         int numEnabled = getEnabledResultCount(indexData);
 
         assertThat(numEnabled).isEqualTo(NUM_DISPLAY_ENTRIES);
@@ -205,8 +203,7 @@
         preIndexData.dataToUpdate.add(resource);
         preIndexData.nonIndexableKeys.put(packageName, keys);
 
-        List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData,
-                localeStr);
+        List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData);
 
         assertThat(indexData.size()).isEqualTo(NUM_DISPLAY_ENTRIES);
         assertThat(getEnabledResultCount(indexData)).isEqualTo(NUM_DISPLAY_ENTRIES - 2);
@@ -218,8 +215,7 @@
         final PreIndexData preIndexData = new PreIndexData();
         preIndexData.dataToUpdate.add(resource);
 
-        List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData,
-                localeStr);
+        List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData);
 
         final IndexData row = findIndexDataForTitle(indexData, PAGE_TITLE);
 
@@ -234,8 +230,7 @@
         final PreIndexData preIndexData = new PreIndexData();
         preIndexData.dataToUpdate.add(resource);
 
-        List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData,
-                localeStr);
+        List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData);
 
         String checkBoxSummaryOn = "summary_on";
         String checkBoxSummaryOff = "summary_off";
@@ -252,8 +247,7 @@
         final PreIndexData preIndexData = new PreIndexData();
         preIndexData.dataToUpdate.add(resource);
 
-        List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData,
-                localeStr);
+        List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData);
 
         String listSummary = "summary_4";
         String listKey = "pref_key_4";
@@ -268,8 +262,7 @@
         final PreIndexData preIndexData = new PreIndexData();
         preIndexData.dataToUpdate.add(resource);
 
-        List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData,
-                localeStr);
+        List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData);
 
         final IndexData row = findIndexDataForTitle(indexData, TITLE_THREE);
 
@@ -286,8 +279,7 @@
         final PreIndexData preIndexData = new PreIndexData();
         preIndexData.dataToUpdate.add(resource);
 
-        List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData,
-                localeStr);
+        List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData);
 
         assertThat(indexData.size()).isEqualTo(NUM_FAKE_FRAGMENT_ENTRIES);
         assertThat(findIndexDataForTitle(indexData, PAGE_TITLE)).isNotNull();
@@ -306,8 +298,7 @@
         final PreIndexData preIndexData = new PreIndexData();
         preIndexData.dataToUpdate.add(resource);
 
-        List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData,
-                localeStr);
+        List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData);
 
         final IndexData data = findIndexDataForTitle(indexData, FakeSettingsFragment.TITLE);
         assertFakeFragment(data);
@@ -322,8 +313,7 @@
         final PreIndexData preIndexData = new PreIndexData();
         preIndexData.dataToUpdate.add(resource);
 
-        List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData,
-                localeStr);
+        List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData);
 
         assertThat(getEnabledResultCount(indexData)).isEqualTo(NUM_ENABLED_FAKE_FRAGMENT_ENTRIES);
     }
@@ -334,8 +324,7 @@
         final PreIndexData preIndexData = new PreIndexData();
         preIndexData.dataToUpdate.add(resource);
 
-        List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData,
-                localeStr);
+        List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData);
 
         int numEnabled = getEnabledResultCount(indexData);
         final IndexData nonTitlePref = findIndexDataForKey(indexData, "pref_key_1");
diff --git a/tests/robotests/src/com/android/settings/security/ConfigureKeyGuardDialogTest.java b/tests/robotests/src/com/android/settings/security/ConfigureKeyGuardDialogTest.java
index 1809e88..38a6b42 100644
--- a/tests/robotests/src/com/android/settings/security/ConfigureKeyGuardDialogTest.java
+++ b/tests/robotests/src/com/android/settings/security/ConfigureKeyGuardDialogTest.java
@@ -26,8 +26,8 @@
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.robolectric.Robolectric;
+import org.robolectric.android.controller.FragmentController;
 import org.robolectric.annotation.Config;
-import org.robolectric.util.FragmentController;
 
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.spy;
@@ -47,7 +47,7 @@
                 Robolectric.buildFragment(ConfigureKeyGuardDialog.class);
         final ConfigureKeyGuardDialog fragment = spy(fragmentController.get());
         doNothing().when(fragment).startPasswordSetup();
-        fragmentController.attach().create().start().resume();
+        fragmentController.create().start().resume();
         fragment.onClick(null /* dialog */, DialogInterface.BUTTON_POSITIVE);
         fragment.onDismiss(null /* dialog */);
 
diff --git a/tests/robotests/src/com/android/settings/support/NewDeviceIntroSuggestionActivityTest.java b/tests/robotests/src/com/android/settings/support/NewDeviceIntroSuggestionActivityTest.java
index 75551e5..5ad8500 100644
--- a/tests/robotests/src/com/android/settings/support/NewDeviceIntroSuggestionActivityTest.java
+++ b/tests/robotests/src/com/android/settings/support/NewDeviceIntroSuggestionActivityTest.java
@@ -17,6 +17,20 @@
 package com.android.settings.support;
 
 
+import static com.android.settings.support.NewDeviceIntroSuggestionActivity
+        .PERMANENT_DISMISS_THRESHOLD;
+import static com.android.settings.support.NewDeviceIntroSuggestionActivity
+        .PREF_KEY_SUGGGESTION_COMPLETE;
+import static com.android.settings.support.NewDeviceIntroSuggestionActivity
+        .PREF_KEY_SUGGGESTION_FIRST_DISPLAY_TIME;
+import static com.android.settings.support.NewDeviceIntroSuggestionActivity.isSuggestionComplete;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.when;
+import static org.robolectric.RuntimeEnvironment.application;
+
 import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
@@ -33,20 +47,9 @@
 import org.mockito.Answers;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
-import org.robolectric.RuntimeEnvironment;
+import org.robolectric.Shadows;
 import org.robolectric.annotation.Config;
-import org.robolectric.res.builder.RobolectricPackageManager;
-
-import static com.android.settings.support.NewDeviceIntroSuggestionActivity
-        .PERMANENT_DISMISS_THRESHOLD;
-import static com.android.settings.support.NewDeviceIntroSuggestionActivity
-        .PREF_KEY_SUGGGESTION_COMPLETE;
-import static com.android.settings.support.NewDeviceIntroSuggestionActivity
-        .PREF_KEY_SUGGGESTION_FIRST_DISPLAY_TIME;
-import static com.android.settings.support.NewDeviceIntroSuggestionActivity.isSuggestionComplete;
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.when;
+import org.robolectric.shadows.ShadowPackageManager;
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@@ -57,14 +60,14 @@
 
     private FakeFeatureFactory mFeatureFactory;
     private Context mContext;
-    private RobolectricPackageManager mRobolectricPackageManager;
+    private ShadowPackageManager mShadowPackageManager;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         mFeatureFactory = FakeFeatureFactory.setupForTest(mMockContext);
-        mContext = RuntimeEnvironment.application;
-        mRobolectricPackageManager = RuntimeEnvironment.getRobolectricPackageManager();
+        mContext = application;
+        mShadowPackageManager = Shadows.shadowOf(application.getPackageManager());
 
         when(mFeatureFactory.suggestionsFeatureProvider.getSharedPrefs(any(Context.class)))
                 .thenReturn(getSharedPreferences());
@@ -115,7 +118,7 @@
                 .thenReturn("https://com.android.settings");
 
         final Intent intent = NewDeviceIntroSuggestionActivity.getLaunchIntent(mContext);
-        mRobolectricPackageManager.addResolveInfoForIntent(intent, new ResolveInfo());
+        mShadowPackageManager.addResolveInfoForIntent(intent, new ResolveInfo());
         assertThat(isSuggestionComplete(mContext)).isFalse();
     }
 
diff --git a/tests/robotests/src/com/android/settings/support/SupportDashboardActivityTest.java b/tests/robotests/src/com/android/settings/support/SupportDashboardActivityTest.java
index 2c59ba7..178e4ec 100644
--- a/tests/robotests/src/com/android/settings/support/SupportDashboardActivityTest.java
+++ b/tests/robotests/src/com/android/settings/support/SupportDashboardActivityTest.java
@@ -19,20 +19,22 @@
 
 import static com.google.common.truth.Truth.assertThat;
 
+import static org.robolectric.RuntimeEnvironment.application;
+
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
 
 import com.android.settings.R;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.search.SearchIndexableRaw;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.robolectric.RuntimeEnvironment;
+import org.robolectric.Shadows;
 import org.robolectric.annotation.Config;
 
 import java.util.List;
@@ -45,7 +47,7 @@
 
     @Before
     public void setUp() {
-        mContext = RuntimeEnvironment.application;
+        mContext = application;
     }
 
     @Test
@@ -67,10 +69,11 @@
 
     @Test
     public void shouldHandleIntentAction() {
-        RuntimeEnvironment.getRobolectricPackageManager().setQueryIntentImplicitly(true);
+        PackageManager packageManager = application.getPackageManager();
+        Shadows.shadowOf(packageManager).setQueryIntentImplicitly(true);
         // Intent action used by setup wizard to start support settings
         Intent intent = new Intent("com.android.settings.action.SUPPORT_SETTINGS");
-        ResolveInfo resolveInfo = RuntimeEnvironment.getPackageManager().resolveActivity(
+        ResolveInfo resolveInfo = packageManager.resolveActivity(
                 intent,
                 PackageManager.MATCH_DEFAULT_ONLY);
         assertThat(resolveInfo).isNotNull();
diff --git a/tests/robotests/src/com/android/settings/support/SupportDisclaimerDialogFragmentTest.java b/tests/robotests/src/com/android/settings/support/SupportDisclaimerDialogFragmentTest.java
index 8cc05e0..31c654c 100644
--- a/tests/robotests/src/com/android/settings/support/SupportDisclaimerDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/support/SupportDisclaimerDialogFragmentTest.java
@@ -37,7 +37,7 @@
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
-import static org.robolectric.internal.Shadow.directlyOn;
+import static org.robolectric.shadow.api.Shadow.directlyOn;
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
diff --git a/tests/robotests/src/com/android/settings/testutils/SettingsRobolectricTestRunner.java b/tests/robotests/src/com/android/settings/testutils/SettingsRobolectricTestRunner.java
index 91bfff2..2e8bac0 100644
--- a/tests/robotests/src/com/android/settings/testutils/SettingsRobolectricTestRunner.java
+++ b/tests/robotests/src/com/android/settings/testutils/SettingsRobolectricTestRunner.java
@@ -20,11 +20,11 @@
 
 import org.junit.runners.model.InitializationError;
 import org.robolectric.RobolectricTestRunner;
+import org.robolectric.android.controller.ActivityController;
 import org.robolectric.annotation.Config;
 import org.robolectric.manifest.AndroidManifest;
 import org.robolectric.res.Fs;
 import org.robolectric.res.ResourcePath;
-import org.robolectric.util.ActivityController;
 import org.robolectric.util.ReflectionHelpers;
 
 import java.util.List;
@@ -79,35 +79,35 @@
 
     public static void getIncludedResourcePaths(String packageName, List<ResourcePath> paths) {
         paths.add(new ResourcePath(
-                packageName,
+                null,
                 Fs.fileFromPath("./packages/apps/Settings/res"),
                 null));
         paths.add(new ResourcePath(
-                packageName,
+                null,
                 Fs.fileFromPath("./frameworks/base/packages/SettingsLib/res"),
                 null));
         paths.add(new ResourcePath(
-                packageName,
+                null,
                 Fs.fileFromPath("./frameworks/base/core/res/res"),
                 null));
         paths.add(new ResourcePath(
-                packageName,
+                null,
                 Fs.fileFromPath("./frameworks/opt/setupwizard/library/main/res"),
                 null));
         paths.add(new ResourcePath(
-                packageName,
+                null,
                 Fs.fileFromPath("./frameworks/opt/setupwizard/library/gingerbread/res"),
                 null));
         paths.add(new ResourcePath(
-                packageName,
+                null,
                 Fs.fileFromPath("./frameworks/opt/setupwizard/library/recyclerview/res"),
                 null));
         paths.add(new ResourcePath(
-                packageName,
+                null,
                 Fs.fileFromPath("./frameworks/support/v7/appcompat/res"),
                 null));
         paths.add(new ResourcePath(
-                packageName,
+                null,
                 Fs.fileFromPath("./frameworks/support/v7/cardview/res"),
                 null));
     }
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResources.java b/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResources.java
index c56438f..39fd028 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResources.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResources.java
@@ -4,7 +4,7 @@
 
 import static org.robolectric.RuntimeEnvironment.application;
 import static org.robolectric.Shadows.shadowOf;
-import static org.robolectric.internal.Shadow.directlyOn;
+import static org.robolectric.shadow.api.Shadow.directlyOn;
 
 import android.annotation.DimenRes;
 import android.content.res.ColorStateList;
@@ -25,13 +25,13 @@
 import com.android.settings.R;
 
 import org.robolectric.RuntimeEnvironment;
+import org.robolectric.android.XmlResourceParserImpl;
 import org.robolectric.annotation.Implementation;
 import org.robolectric.annotation.Implements;
 import org.robolectric.annotation.RealObject;
-import org.robolectric.internal.Shadow;
 import org.robolectric.res.StyleData;
 import org.robolectric.res.StyleResolver;
-import org.robolectric.res.builder.XmlResourceParserImpl;
+import org.robolectric.res.ThemeStyleSet;
 import org.robolectric.shadows.ShadowAssetManager;
 import org.robolectric.shadows.ShadowResources;
 import org.robolectric.util.ReflectionHelpers;
@@ -133,7 +133,7 @@
         if (override instanceof String) {
             return (String) override;
         }
-        return Shadow.directlyOn(
+        return directlyOn(
                 realResources, Resources.class, "getString", ClassParameter.from(int.class, id));
     }
 
@@ -143,7 +143,7 @@
         if (override instanceof Integer) {
             return (Integer) override;
         }
-        return Shadow.directlyOn(
+        return directlyOn(
                 realResources, Resources.class, "getInteger", ClassParameter.from(int.class, id));
     }
 
@@ -153,7 +153,7 @@
         if (override instanceof Boolean) {
             return (boolean) override;
         }
-        return Shadow.directlyOn(realResources, Resources.class, "getBoolean",
+        return directlyOn(realResources, Resources.class, "getBoolean",
                 ClassParameter.from(int.class, id));
     }
 
@@ -184,13 +184,16 @@
 
             // Track down all styles and remove all inheritance from private styles.
             ShadowAssetManager assetManager = shadowOf(RuntimeEnvironment.application.getAssets());
-            // The Object's below are actually ShadowAssetManager.OverlayedStyle. We can't use it
-            // here because it's package private.
-            Map<Long, List<Object>> appliedStylesList =
-                    ReflectionHelpers.getField(assetManager, "appliedStyles");
+            Map<Long, Object /* NativeTheme */> appliedStylesList =
+                    ReflectionHelpers.getField(assetManager, "nativeThemes");
             for (Long idx : appliedStylesList.keySet()) {
-                List<Object> appliedStyles = appliedStylesList.get(idx);
-                for (Object appliedStyle : appliedStyles) {
+                ThemeStyleSet appliedStyles = ReflectionHelpers.getField(
+                        appliedStylesList.get(idx), "themeStyleSet");
+                // The Object's below are actually ShadowAssetManager.OverlayedStyle. We can't use
+                // it here because it's private.
+                List<Object /* OverlayedStyle */> overlayedStyles =
+                        ReflectionHelpers.getField(appliedStyles, "styles");
+                for (Object appliedStyle : overlayedStyles) {
                     StyleResolver styleResolver = ReflectionHelpers.getField(appliedStyle, "style");
                     List<StyleData> styleDatas =
                             ReflectionHelpers.getField(styleResolver, "styles");
@@ -223,5 +226,9 @@
             return directlyOn(realTheme, Theme.class)
                     .resolveAttribute(resid, outValue, resolveRefs);
         }
+
+        private Resources getResources() {
+            return ReflectionHelpers.callInstanceMethod(ShadowTheme.class, this, "getResources");
+        }
     }
 }
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowFingerprintManager.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowFingerprintManager.java
index b84cf42..d79e7aa 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowFingerprintManager.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowFingerprintManager.java
@@ -25,7 +25,7 @@
 import org.robolectric.annotation.Implementation;
 import org.robolectric.annotation.Implements;
 import org.robolectric.annotation.Resetter;
-import org.robolectric.internal.ShadowExtractor;
+import org.robolectric.shadow.api.Shadow;
 import org.robolectric.shadows.ShadowContextImpl;
 import org.robolectric.util.ReflectionHelpers;
 
@@ -96,7 +96,7 @@
     }
 
     public static ShadowFingerprintManager get() {
-        return (ShadowFingerprintManager) ShadowExtractor.extract(
+        return (ShadowFingerprintManager) Shadow.extract(
                 RuntimeEnvironment.application.getSystemService(FingerprintManager.class));
     }
 }
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowPackageMonitor.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowPackageMonitor.java
index b93b035..5a5f076 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowPackageMonitor.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowPackageMonitor.java
@@ -28,8 +28,7 @@
 import org.robolectric.annotation.Implementation;
 import org.robolectric.annotation.Implements;
 import org.robolectric.annotation.RealObject;
-import org.robolectric.internal.Shadow;
-import org.robolectric.internal.ShadowExtractor;
+import org.robolectric.shadow.api.Shadow;
 import org.robolectric.shadows.ShadowApplication;
 import org.robolectric.shadows.ShadowMessageQueue;
 
@@ -56,8 +55,8 @@
     }
 
     private static void setupBackgroundThreadScheduler() {
-        ShadowMessageQueue shadowMessageQueue = ((ShadowMessageQueue) ShadowExtractor.extract(
-                BackgroundThread.getHandler().getLooper().getQueue()));
+        ShadowMessageQueue shadowMessageQueue = Shadow.extract(
+                BackgroundThread.getHandler().getLooper().getQueue());
         shadowMessageQueue.setScheduler(
                 ShadowApplication.getInstance().getBackgroundThreadScheduler());
     }
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUserManager.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUserManager.java
index 860ee11..4d4fd62 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUserManager.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUserManager.java
@@ -25,7 +25,7 @@
 import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Implementation;
 import org.robolectric.annotation.Implements;
-import org.robolectric.internal.ShadowExtractor;
+import org.robolectric.shadow.api.Shadow;
 
 import java.util.Collections;
 import java.util.List;
@@ -63,7 +63,7 @@
     }
 
     public static ShadowUserManager getShadow() {
-        return (ShadowUserManager) ShadowExtractor.extract(
+        return (ShadowUserManager) Shadow.extract(
                 RuntimeEnvironment.application.getSystemService(UserManager.class));
     }
 }
diff --git a/tests/robotests/src/com/android/settings/wallpaper/WallpaperSuggestionActivityTest.java b/tests/robotests/src/com/android/settings/wallpaper/WallpaperSuggestionActivityTest.java
index dd93938..d8c0861 100644
--- a/tests/robotests/src/com/android/settings/wallpaper/WallpaperSuggestionActivityTest.java
+++ b/tests/robotests/src/com/android/settings/wallpaper/WallpaperSuggestionActivityTest.java
@@ -30,9 +30,9 @@
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.Robolectric;
+import org.robolectric.android.controller.ActivityController;
 import org.robolectric.annotation.Config;
 import org.robolectric.shadows.ShadowActivity;
-import org.robolectric.util.ActivityController;
 
 import static com.google.common.truth.Truth.assertThat;
 import static org.mockito.Mockito.when;
diff --git a/tests/robotests/src/com/android/settings/webview/WebViewAppPickerTest.java b/tests/robotests/src/com/android/settings/webview/WebViewAppPickerTest.java
index 2a53ab6..73d001a 100644
--- a/tests/robotests/src/com/android/settings/webview/WebViewAppPickerTest.java
+++ b/tests/robotests/src/com/android/settings/webview/WebViewAppPickerTest.java
@@ -36,6 +36,7 @@
 import com.android.settingslib.wrapper.PackageManagerWrapper;
 
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Answers;
@@ -66,11 +67,17 @@
 public class WebViewAppPickerTest {
     private Context mContext = RuntimeEnvironment.application;
 
-    private final static UserInfo FIRST_USER = new UserInfo(0, "FIRST_USER", 0);
-    private final static UserInfo SECOND_USER = new UserInfo(0, "SECOND_USER", 0);
+    private static UserInfo sFirstUser;
+    private static UserInfo sSecondUser;
 
     private final static String DEFAULT_PACKAGE_NAME = "DEFAULT_PACKAGE_NAME";
 
+    @BeforeClass
+    public static void beforeClass() {
+        sFirstUser = new UserInfo(0, "FIRST_USER", 0);
+        sSecondUser = new UserInfo(0, "SECOND_USER", 0);
+    }
+
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private Activity mActivity;
     @Mock
@@ -261,14 +268,14 @@
         UserPackageWrapper packageForFirstUser = mock(UserPackageWrapper.class);
         when(packageForFirstUser.isEnabledPackage()).thenReturn(false);
         when(packageForFirstUser.isInstalledPackage()).thenReturn(true);
-        when(packageForFirstUser.getUserInfo()).thenReturn(FIRST_USER);
+        when(packageForFirstUser.getUserInfo()).thenReturn(sFirstUser);
 
         WebViewUpdateServiceWrapper wvusWrapper = mock(WebViewUpdateServiceWrapper.class);
         when(wvusWrapper.getPackageInfosAllUsers(any(), eq(DEFAULT_PACKAGE_NAME)))
                 .thenReturn(Arrays.asList(packageForFirstUser));
 
         final String EXPECTED_DISABLED_REASON = String.format(
-                "(disabled for user %s)", FIRST_USER.name);
+                "(disabled for user %s)", sFirstUser.name);
         assertThat(mPicker.getDisabledReason(wvusWrapper, mContext,
                 DEFAULT_PACKAGE_NAME)).isEqualTo(EXPECTED_DISABLED_REASON);
     }
@@ -278,14 +285,14 @@
         UserPackageWrapper packageForFirstUser = mock(UserPackageWrapper.class);
         when(packageForFirstUser.isEnabledPackage()).thenReturn(true);
         when(packageForFirstUser.isInstalledPackage()).thenReturn(false);
-        when(packageForFirstUser.getUserInfo()).thenReturn(FIRST_USER);
+        when(packageForFirstUser.getUserInfo()).thenReturn(sFirstUser);
 
         WebViewUpdateServiceWrapper wvusWrapper = mock(WebViewUpdateServiceWrapper.class);
         when(wvusWrapper.getPackageInfosAllUsers(any(), eq(DEFAULT_PACKAGE_NAME)))
                 .thenReturn(Arrays.asList(packageForFirstUser));
 
         final String EXPECTED_DISABLED_REASON = String.format(
-                "(uninstalled for user %s)", FIRST_USER.name);
+                "(uninstalled for user %s)", sFirstUser.name);
         assertThat(mPicker.getDisabledReason(wvusWrapper, mContext,
                 DEFAULT_PACKAGE_NAME)).isEqualTo(EXPECTED_DISABLED_REASON);
     }
@@ -295,19 +302,19 @@
         UserPackageWrapper packageForFirstUser = mock(UserPackageWrapper.class);
         when(packageForFirstUser.isEnabledPackage()).thenReturn(false);
         when(packageForFirstUser.isInstalledPackage()).thenReturn(true);
-        when(packageForFirstUser.getUserInfo()).thenReturn(FIRST_USER);
+        when(packageForFirstUser.getUserInfo()).thenReturn(sFirstUser);
 
         UserPackageWrapper packageForSecondUser = mock(UserPackageWrapper.class);
         when(packageForSecondUser.isEnabledPackage()).thenReturn(true);
         when(packageForSecondUser.isInstalledPackage()).thenReturn(false);
-        when(packageForSecondUser.getUserInfo()).thenReturn(SECOND_USER);
+        when(packageForSecondUser.getUserInfo()).thenReturn(sSecondUser);
 
         WebViewUpdateServiceWrapper wvusWrapper = mock(WebViewUpdateServiceWrapper.class);
         when(wvusWrapper.getPackageInfosAllUsers(any(), eq(DEFAULT_PACKAGE_NAME)))
                 .thenReturn(Arrays.asList(packageForFirstUser, packageForSecondUser));
 
         final String EXPECTED_DISABLED_REASON = String.format(
-                "(disabled for user %s)", FIRST_USER.name);
+                "(disabled for user %s)", sFirstUser.name);
         assertThat(mPicker.getDisabledReason(
                 wvusWrapper, mContext, DEFAULT_PACKAGE_NAME)).isEqualTo(EXPECTED_DISABLED_REASON);
     }
@@ -321,19 +328,19 @@
         UserPackageWrapper packageForFirstUser = mock(UserPackageWrapper.class);
         when(packageForFirstUser.isEnabledPackage()).thenReturn(false);
         when(packageForFirstUser.isInstalledPackage()).thenReturn(false);
-        when(packageForFirstUser.getUserInfo()).thenReturn(FIRST_USER);
+        when(packageForFirstUser.getUserInfo()).thenReturn(sFirstUser);
 
         UserPackageWrapper packageForSecondUser = mock(UserPackageWrapper.class);
         when(packageForSecondUser.isEnabledPackage()).thenReturn(true);
         when(packageForSecondUser.isInstalledPackage()).thenReturn(true);
-        when(packageForSecondUser.getUserInfo()).thenReturn(SECOND_USER);
+        when(packageForSecondUser.getUserInfo()).thenReturn(sSecondUser);
 
         WebViewUpdateServiceWrapper wvusWrapper = mock(WebViewUpdateServiceWrapper.class);
         when(wvusWrapper.getPackageInfosAllUsers(any(), eq(DEFAULT_PACKAGE_NAME)))
                 .thenReturn(Arrays.asList(packageForFirstUser, packageForSecondUser));
 
         final String EXPECTED_DISABLED_REASON = String.format(
-                "(uninstalled for user %s)", FIRST_USER.name);
+                "(uninstalled for user %s)", sFirstUser.name);
         assertThat(mPicker.getDisabledReason(wvusWrapper, mContext,
                 DEFAULT_PACKAGE_NAME)).isEqualTo(EXPECTED_DISABLED_REASON);
     }
diff --git a/tests/robotests/src/com/android/settings/wifi/UseOpenWifiPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/UseOpenWifiPreferenceControllerTest.java
index 297054d..16d883a 100644
--- a/tests/robotests/src/com/android/settings/wifi/UseOpenWifiPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/UseOpenWifiPreferenceControllerTest.java
@@ -44,6 +44,7 @@
 
 import com.google.common.collect.Lists;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.ArgumentCaptor;
@@ -59,12 +60,16 @@
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
 public class UseOpenWifiPreferenceControllerTest {
-    private static ComponentName ENABLE_ACTIVITY_COMPONENT =
-            new ComponentName("package", "activityClass");
-    private static NetworkScorerAppData APP_DATA =
-            new NetworkScorerAppData(0, null, null, ENABLE_ACTIVITY_COMPONENT, null);
-    private static NetworkScorerAppData APP_DATA_NO_ACTIVITY =
-            new NetworkScorerAppData(0, null, null, null, null);
+    private static ComponentName sEnableActivityComponent;
+    private static NetworkScorerAppData sAppData;
+    private static NetworkScorerAppData sAppDataNoActivity;
+
+    @BeforeClass
+    public static void beforeClass() {
+        sEnableActivityComponent = new ComponentName("package", "activityClass");
+        sAppData = new NetworkScorerAppData(0, null, null, sEnableActivityComponent, null);
+        sAppDataNoActivity = new NetworkScorerAppData(0, null, null, null, null);
+    }
 
     @Mock private Lifecycle mLifecycle;
     @Mock private Fragment mFragment;
@@ -92,7 +97,7 @@
      */
     private void setupScorers(@NonNull List<NetworkScorerAppData> scorers) {
         when(mNetworkScoreManagerWrapper.getActiveScorerPackage()).thenReturn(
-                ENABLE_ACTIVITY_COMPONENT.getPackageName());
+                sEnableActivityComponent.getPackageName());
         when(mNetworkScoreManagerWrapper.getAllValidScorers()).thenReturn(scorers);
         when(mNetworkScoreManagerWrapper.getActiveScorer()).thenReturn(scorers.get(0));
     }
@@ -106,7 +111,7 @@
 
     @Test
     public void testIsAvailable_returnsFalseWhenScorersNotSupported() {
-        setupScorers(Lists.newArrayList(APP_DATA_NO_ACTIVITY));
+        setupScorers(Lists.newArrayList(sAppDataNoActivity));
         createController();
 
         assertThat(mController.isAvailable()).isFalse();
@@ -114,7 +119,7 @@
 
     @Test
     public void testIsAvailable_returnsTrueIfActiveScorerSupported() {
-        setupScorers(Lists.newArrayList(APP_DATA, APP_DATA_NO_ACTIVITY));
+        setupScorers(Lists.newArrayList(sAppData, sAppDataNoActivity));
         createController();
 
         assertThat(mController.isAvailable()).isTrue();
@@ -122,8 +127,8 @@
 
     @Test
     public void testIsAvailable_returnsTrueIfNonActiveScorerSupported() {
-        setupScorers(Lists.newArrayList(APP_DATA_NO_ACTIVITY, APP_DATA));
-        when(mNetworkScoreManagerWrapper.getActiveScorer()).thenReturn(APP_DATA_NO_ACTIVITY);
+        setupScorers(Lists.newArrayList(sAppDataNoActivity, sAppData));
+        when(mNetworkScoreManagerWrapper.getActiveScorer()).thenReturn(sAppDataNoActivity);
         createController();
 
         assertThat(mController.isAvailable()).isTrue();
@@ -150,7 +155,7 @@
 
     @Test
     public void onPreferenceChange_matchingKeyAndAvailable_enableShouldStartEnableActivity() {
-        setupScorers(Lists.newArrayList(APP_DATA, APP_DATA_NO_ACTIVITY));
+        setupScorers(Lists.newArrayList(sAppData, sAppDataNoActivity));
         createController();
 
         final SwitchPreference pref = new SwitchPreference(mContext);
@@ -160,15 +165,15 @@
         verify(mFragment).startActivityForResult(mIntentCaptor.capture(),
                 eq(REQUEST_CODE_OPEN_WIFI_AUTOMATICALLY));
         Intent activityIntent = mIntentCaptor.getValue();
-        assertThat(activityIntent.getComponent()).isEqualTo(ENABLE_ACTIVITY_COMPONENT);
+        assertThat(activityIntent.getComponent()).isEqualTo(sEnableActivityComponent);
         assertThat(activityIntent.getAction()).isEqualTo(NetworkScoreManager.ACTION_CUSTOM_ENABLE);
     }
 
     @Test
     public void onPreferenceChange_matchingKeyAndAvailable_disableShouldUpdateSetting() {
-        setupScorers(Lists.newArrayList(APP_DATA, APP_DATA_NO_ACTIVITY));
+        setupScorers(Lists.newArrayList(sAppData, sAppDataNoActivity));
         Settings.Global.putString(mContext.getContentResolver(), USE_OPEN_WIFI_PACKAGE,
-                ENABLE_ACTIVITY_COMPONENT.getPackageName());
+                sEnableActivityComponent.getPackageName());
 
         createController();
 
@@ -182,7 +187,7 @@
 
     @Test
     public void onActivityResult_nonmatchingRequestCode_shouldDoNothing() {
-        setupScorers(Lists.newArrayList(APP_DATA, APP_DATA_NO_ACTIVITY));
+        setupScorers(Lists.newArrayList(sAppData, sAppDataNoActivity));
         createController();
 
         assertThat(mController.onActivityResult(234 /* requestCode */ , Activity.RESULT_OK))
@@ -193,7 +198,7 @@
 
     @Test
     public void onActivityResult_matchingRequestCode_nonOkResult_shouldDoNothing() {
-        setupScorers(Lists.newArrayList(APP_DATA, APP_DATA_NO_ACTIVITY));
+        setupScorers(Lists.newArrayList(sAppData, sAppDataNoActivity));
         createController();
 
         assertThat(mController
@@ -205,24 +210,24 @@
 
     @Test
     public void onActivityResult_matchingRequestCode_okResult_updatesSetting() {
-        setupScorers(Lists.newArrayList(APP_DATA, APP_DATA_NO_ACTIVITY));
+        setupScorers(Lists.newArrayList(sAppData, sAppDataNoActivity));
         createController();
 
         assertThat(mController
                 .onActivityResult(REQUEST_CODE_OPEN_WIFI_AUTOMATICALLY, Activity.RESULT_OK))
                 .isEqualTo(true);
         assertThat(Settings.Global.getString(mContext.getContentResolver(), USE_OPEN_WIFI_PACKAGE))
-                .isEqualTo(ENABLE_ACTIVITY_COMPONENT.getPackageName());
+                .isEqualTo(sEnableActivityComponent.getPackageName());
     }
 
     @Test
     public void updateState_noEnableActivity_preferenceDisabled_summaryChanged() {
-        setupScorers(Lists.newArrayList(APP_DATA_NO_ACTIVITY));
+        setupScorers(Lists.newArrayList(sAppDataNoActivity));
         createController();
 
         final SwitchPreference preference = mock(SwitchPreference.class);
         Settings.Global.putString(mContext.getContentResolver(), USE_OPEN_WIFI_PACKAGE,
-                ENABLE_ACTIVITY_COMPONENT.getPackageName());
+                sEnableActivityComponent.getPackageName());
 
         mController.updateState(preference);
 
@@ -238,7 +243,7 @@
 
         final SwitchPreference preference = mock(SwitchPreference.class);
         Settings.Global.putString(mContext.getContentResolver(), USE_OPEN_WIFI_PACKAGE,
-                ENABLE_ACTIVITY_COMPONENT.getPackageName());
+                sEnableActivityComponent.getPackageName());
 
         mController.updateState(preference);
 
@@ -249,12 +254,12 @@
 
     @Test
     public void updateState_enableActivityExists_preferenceEnabled() {
-        setupScorers(Lists.newArrayList(APP_DATA, APP_DATA_NO_ACTIVITY));
+        setupScorers(Lists.newArrayList(sAppData, sAppDataNoActivity));
         createController();
 
         final SwitchPreference preference = mock(SwitchPreference.class);
         Settings.Global.putString(mContext.getContentResolver(), USE_OPEN_WIFI_PACKAGE,
-                ENABLE_ACTIVITY_COMPONENT.getPackageName());
+                sEnableActivityComponent.getPackageName());
 
         mController.updateState(preference);
 
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java
index 0435b7e..29df539 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java
@@ -23,7 +23,6 @@
 import static com.google.common.truth.Truth.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
 
 import android.content.Context;
 import android.provider.Settings;
@@ -34,14 +33,12 @@
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.testutils.shadow.SettingsShadowResources;
-import com.android.settings.wrapper.NetworkScoreManagerWrapper;
 import com.android.settingslib.core.lifecycle.Lifecycle;
 
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;