Merge "Fix typo in fingerprint string"
diff --git a/res/layout-sw320dp/settings_entity_header.xml b/res/layout-sw320dp/settings_entity_header.xml
index 5cedd8d..951961c 100644
--- a/res/layout-sw320dp/settings_entity_header.xml
+++ b/res/layout-sw320dp/settings_entity_header.xml
@@ -38,7 +38,7 @@
             android:id="@+id/entity_header_icon"
             android:layout_width="48dp"
             android:layout_height="48dp"
-            android:scaleType="fitXY"
+            android:scaleType="fitCenter"
             android:layout_gravity="center_horizontal"
             android:antialias="true" />
 
diff --git a/src/com/android/settings/bluetooth/BluetoothDetailsHeaderController.java b/src/com/android/settings/bluetooth/BluetoothDetailsHeaderController.java
index 5ec7c85..1470214 100644
--- a/src/com/android/settings/bluetooth/BluetoothDetailsHeaderController.java
+++ b/src/com/android/settings/bluetooth/BluetoothDetailsHeaderController.java
@@ -16,8 +16,8 @@
 
 package com.android.settings.bluetooth;
 
-
 import android.content.Context;
+import android.graphics.drawable.Drawable;
 import android.support.v14.preference.PreferenceFragment;
 import android.support.v7.preference.PreferenceScreen;
 import android.util.Pair;
@@ -51,11 +51,11 @@
     }
 
     protected void setHeaderProperties() {
-        Pair<Integer, String> pair = Utils.getBtClassDrawableWithDescription
-                (mContext.getResources(), mCachedDevice);
+        final Pair<Drawable, String> pair = Utils.getBtClassDrawableWithDescription
+                (mContext, mCachedDevice);
         String summaryText = mCachedDevice.getConnectionSummary();
         mHeaderController.setLabel(mCachedDevice.getName());
-        mHeaderController.setIcon(mContext.getDrawable(pair.first));
+        mHeaderController.setIcon(pair.first);
         mHeaderController.setIconContentDescription(pair.second);
         mHeaderController.setSummary(summaryText);
     }
diff --git a/src/com/android/settings/bluetooth/BluetoothDevicePreference.java b/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
index a216400..7b81018 100644
--- a/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
+++ b/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
@@ -21,6 +21,7 @@
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.res.Resources;
+import android.graphics.drawable.Drawable;
 import android.os.UserManager;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceViewHolder;
@@ -120,9 +121,9 @@
         // Null check is done at the framework
         setSummary(mCachedDevice.getConnectionSummary());
 
-        Pair<Integer, String> pair = Utils.getBtClassDrawableWithDescription(mResources,
+        final Pair<Drawable, String> pair = Utils.getBtClassDrawableWithDescription(getContext(),
                 mCachedDevice);
-        if (pair.first != 0) {
+        if (pair.first != null) {
             setIcon(pair.first);
             contentDescription = pair.second;
         }
diff --git a/src/com/android/settings/bluetooth/Utils.java b/src/com/android/settings/bluetooth/Utils.java
index 26edd84..e80237eb 100755
--- a/src/com/android/settings/bluetooth/Utils.java
+++ b/src/com/android/settings/bluetooth/Utils.java
@@ -23,6 +23,9 @@
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.res.Resources;
+import android.graphics.drawable.Drawable;
+import android.support.annotation.DrawableRes;
+import android.support.annotation.IdRes;
 import android.support.annotation.VisibleForTesting;
 import android.util.Pair;
 import android.widget.Toast;
@@ -36,6 +39,7 @@
 import com.android.settingslib.bluetooth.LocalBluetoothManager.BluetoothManagerCallback;
 import com.android.settingslib.bluetooth.LocalBluetoothProfile;
 import com.android.settingslib.bluetooth.Utils.ErrorListener;
+import com.android.settingslib.graph.BluetoothDeviceLayerDrawable;
 
 import java.util.List;
 
@@ -150,27 +154,31 @@
         }
     };
 
-    static Pair<Integer, String> getBtClassDrawableWithDescription(Resources r,
+    static Pair<Drawable, String> getBtClassDrawableWithDescription(Context context,
             CachedBluetoothDevice cachedDevice) {
         BluetoothClass btClass = cachedDevice.getBtClass();
+        final int level = cachedDevice.getBatteryLevel();
         if (btClass != null) {
             switch (btClass.getMajorDeviceClass()) {
                 case BluetoothClass.Device.Major.COMPUTER:
-                    return new Pair<Integer, String>(R.drawable.ic_bt_laptop,
-                           r.getString(R.string.bluetooth_talkback_computer));
+                    return new Pair<>(getBluetoothDrawable(context, R.drawable.ic_bt_laptop, level),
+                            context.getString(R.string.bluetooth_talkback_computer));
 
                 case BluetoothClass.Device.Major.PHONE:
-                    return new Pair<Integer, String>(R.drawable.ic_bt_cellphone,
-                            r.getString(R.string.bluetooth_talkback_phone));
+                    return new Pair<>(
+                            getBluetoothDrawable(context, R.drawable.ic_bt_cellphone, level),
+                            context.getString(R.string.bluetooth_talkback_phone));
 
                 case BluetoothClass.Device.Major.PERIPHERAL:
-                    return new Pair<Integer, String>(HidProfile.getHidClassDrawable(btClass),
-                            r.getString(
-                                    R.string.bluetooth_talkback_input_peripheral));
+                    return new Pair<>(
+                            getBluetoothDrawable(context, HidProfile.getHidClassDrawable(btClass),
+                                    level),
+                            context.getString(R.string.bluetooth_talkback_input_peripheral));
 
                 case BluetoothClass.Device.Major.IMAGING:
-                    return new Pair<Integer, String>(R.drawable.ic_settings_print,
-                            r.getString(R.string.bluetooth_talkback_imaging));
+                    return new Pair<>(
+                            getBluetoothDrawable(context, R.drawable.ic_settings_print, level),
+                            context.getString(R.string.bluetooth_talkback_imaging));
 
                 default:
                     // unrecognized device class; continue
@@ -181,20 +189,34 @@
         for (LocalBluetoothProfile profile : profiles) {
             int resId = profile.getDrawableResource(btClass);
             if (resId != 0) {
-                return new Pair<Integer, String>(resId, null);
+                return new Pair<>(getBluetoothDrawable(context, resId, level), null);
             }
         }
         if (btClass != null) {
             if (btClass.doesClassMatch(BluetoothClass.PROFILE_HEADSET)) {
-                return new Pair<Integer, String>(R.drawable.ic_bt_headset_hfp,
-                        r.getString(R.string.bluetooth_talkback_headset));
+                return new Pair<>(
+                        getBluetoothDrawable(context, R.drawable.ic_bt_headset_hfp, level),
+                        context.getString(R.string.bluetooth_talkback_headset));
             }
             if (btClass.doesClassMatch(BluetoothClass.PROFILE_A2DP)) {
-                return new Pair<Integer, String>(R.drawable.ic_bt_headphones_a2dp,
-                        r.getString(R.string.bluetooth_talkback_headphone));
+                return new Pair<>(
+                        getBluetoothDrawable(context, R.drawable.ic_bt_headphones_a2dp, level),
+                        context.getString(R.string.bluetooth_talkback_headphone));
             }
         }
-        return new Pair<Integer, String>(R.drawable.ic_settings_bluetooth,
-                r.getString(R.string.bluetooth_talkback_bluetooth));
+        return new Pair<>(getBluetoothDrawable(context, R.drawable.ic_settings_bluetooth, level),
+                context.getString(R.string.bluetooth_talkback_bluetooth));
+    }
+
+    @VisibleForTesting
+    static Drawable getBluetoothDrawable(Context context, @DrawableRes int resId,
+            int batteryLevel) {
+        if (batteryLevel != BluetoothDevice.BATTERY_LEVEL_UNKNOWN) {
+            return BluetoothDeviceLayerDrawable.createLayerDrawable(context, resId, batteryLevel);
+        } else if (resId != 0) {
+            return context.getDrawable(resId);
+        } else {
+            return null;
+        }
     }
 }
diff --git a/tests/robotests/src/com/android/settings/DeviceInfoSettingsTest.java b/tests/robotests/src/com/android/settings/DeviceInfoSettingsTest.java
index 51034dd..c5a1833 100644
--- a/tests/robotests/src/com/android/settings/DeviceInfoSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/DeviceInfoSettingsTest.java
@@ -45,7 +45,11 @@
 import java.util.List;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(
+    manifest = TestConfig.MANIFEST_PATH,
+    sdk = TestConfig.SDK_VERSION,
+    shadows = ShadowUtils.class
+)
 public class DeviceInfoSettingsTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
@@ -83,7 +87,6 @@
     }
 
     @Test
-    @Config(shadows = ShadowUtils.class)
     public void testNonIndexableKeys_existInXmlLayout() {
         final Context context = RuntimeEnvironment.application;
         final List<String> niks = DeviceInfoSettings.SEARCH_INDEX_DATA_PROVIDER
diff --git a/tests/robotests/src/com/android/settings/MasterClearTest.java b/tests/robotests/src/com/android/settings/MasterClearTest.java
index 21b8e47..838b1e8 100644
--- a/tests/robotests/src/com/android/settings/MasterClearTest.java
+++ b/tests/robotests/src/com/android/settings/MasterClearTest.java
@@ -33,7 +33,6 @@
 import android.provider.Settings;
 import android.view.LayoutInflater;
 import android.view.View;
-import android.widget.CheckBox;
 import android.widget.LinearLayout;
 import android.widget.ScrollView;
 
@@ -46,12 +45,15 @@
 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;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(
+    manifest = TestConfig.MANIFEST_PATH,
+    sdk = TestConfig.SDK_VERSION,
+    shadows = {ShadowUtils.class}
+)
 public class MasterClearTest {
 
     @Mock
@@ -144,7 +146,6 @@
     }
 
     @Test
-    @Config(shadows = { ShadowUtils.class })
     public void testInitiateMasterClear_inDemoMode_sendsIntent() {
         ShadowUtils.setIsDemoUser(true);
 
diff --git a/tests/robotests/src/com/android/settings/SecuritySettingsTest.java b/tests/robotests/src/com/android/settings/SecuritySettingsTest.java
index 9600936..fc3478d 100644
--- a/tests/robotests/src/com/android/settings/SecuritySettingsTest.java
+++ b/tests/robotests/src/com/android/settings/SecuritySettingsTest.java
@@ -56,7 +56,11 @@
 import java.util.List;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(
+    manifest = TestConfig.MANIFEST_PATH,
+    sdk = TestConfig.SDK_VERSION,
+    shadows = {ShadowLockPatternUtils.class}
+)
 public class SecuritySettingsTest {
 
 
@@ -165,9 +169,6 @@
     }
 
     @Test
-    @Config (shadows = {
-            ShadowLockPatternUtils.class,
-    })
     public void testNonIndexableKeys_existInXmlLayout() {
         final Context context = spy(RuntimeEnvironment.application);
         UserManager manager = mock(UserManager.class);
diff --git a/tests/robotests/src/com/android/settings/accounts/AccountHeaderPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/AccountHeaderPreferenceControllerTest.java
index 4dce0c6..34ac183 100644
--- a/tests/robotests/src/com/android/settings/accounts/AccountHeaderPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AccountHeaderPreferenceControllerTest.java
@@ -50,7 +50,11 @@
 
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(
+    manifest = TestConfig.MANIFEST_PATH,
+    sdk = TestConfig.SDK_VERSION,
+    shadows = AccountHeaderPreferenceControllerTest.ShadowAuthenticatorHelper.class
+)
 public class AccountHeaderPreferenceControllerTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
@@ -83,7 +87,6 @@
     }
 
     @Test
-    @Config(shadows = ShadowAuthenticatorHelper.class)
     public void onResume_shouldDisplayAccountInEntityHeader() {
         final Lifecycle lifecycle = new Lifecycle();
         final Account account = new Account("name1@abc.com", "com.abc");
diff --git a/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java
index f4f093a..139bee7 100644
--- a/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java
@@ -111,7 +111,6 @@
     }
 
     @Test
-    @Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
     public void onResume_linkedUser_shouldAddOneAccountCategory() {
         final UserInfo info = new UserInfo(1, "user 1", 0);
         when(mUserManager.isManagedProfile()).thenReturn(false);
@@ -124,7 +123,6 @@
     }
 
     @Test
-    @Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
     public void onResume_oneProfile_shouldAddOneAccountCategory() {
         final List<UserInfo> infos = new ArrayList<>();
         infos.add(new UserInfo(1, "user 1", 0));
@@ -138,7 +136,6 @@
     }
 
     @Test
-    @Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
     public void onResume_twoProfiles_shouldAddTwoAccountCategory() {
         final List<UserInfo> infos = new ArrayList<>();
         infos.add(new UserInfo(1, "user 1", 0));
@@ -153,7 +150,6 @@
     }
 
     @Test
-    @Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
     public void onResume_noProfileChange_shouldNotAddOrRemoveAccountCategory() {
         final List<UserInfo> infos = new ArrayList<>();
         infos.add(new UserInfo(1, "user 1", 0));
@@ -171,7 +167,6 @@
     }
 
     @Test
-    @Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
     public void onResume_oneNewProfile_shouldAddOneAccountCategory() {
         final List<UserInfo> infos = new ArrayList<>();
         infos.add(new UserInfo(1, "user 1", 0));
@@ -189,7 +184,6 @@
     }
 
     @Test
-    @Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
     public void onResume_oneProfileRemoved_shouldRemoveOneAccountCategory() {
         final List<UserInfo> infos = new ArrayList<>();
         infos.add(new UserInfo(1, "user 1", 0));
@@ -207,7 +201,6 @@
     }
 
     @Test
-    @Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
     public void onResume_oneProfile_shouldSetAccountTitleWithUserName() {
         final List<UserInfo> infos = new ArrayList<>();
         infos.add(new UserInfo(1, "user 1", UserInfo.FLAG_MANAGED_PROFILE));
@@ -226,7 +219,6 @@
     }
 
     @Test
-    @Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
     public void onResume_noPreferenceScreen_shouldNotCrash() {
         final List<UserInfo> infos = new ArrayList<>();
         infos.add(new UserInfo(1, "user 1", 0));
@@ -244,7 +236,6 @@
     }
 
     @Test
-    @Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
     public void onResume_noPreferenceManager_shouldNotCrash() {
         when(mFragment.getPreferenceManager()).thenReturn(null);
         final List<UserInfo> infos = new ArrayList<>();
@@ -337,7 +328,6 @@
     }
 
     @Test
-    @Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
     public void onResume_twoAccountsOfSameType_shouldAddThreePreferences() {
         final List<UserInfo> infos = new ArrayList<>();
         infos.add(new UserInfo(1, "user 1", 0));
@@ -417,7 +407,6 @@
     }
 
     @Test
-    @Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
     public void onResume_noAccountChange_shouldNotAddAccountPreference() {
         final List<UserInfo> infos = new ArrayList<>();
         infos.add(new UserInfo(1, "user 1", 0));
@@ -498,7 +487,6 @@
     }
 
     @Test
-    @Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
     public void onResume_oneNewAccountType_shouldAddOneAccountPreference() {
         final List<UserInfo> infos = new ArrayList<>();
         infos.add(new UserInfo(1, "user 1", 0));
@@ -534,7 +522,6 @@
     }
 
     @Test
-    @Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
     public void onResume_oneAccountRemoved_shouldRemoveOneAccountPreference() {
         final List<UserInfo> infos = new ArrayList<>();
         infos.add(new UserInfo(1, "user 1", 0));
diff --git a/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java b/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
index 3226a3e..dc0730e 100644
--- a/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
@@ -83,7 +83,11 @@
 
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(
+    manifest = TestConfig.MANIFEST_PATH,
+    sdk = TestConfig.SDK_VERSION,
+    shadows = InstalledAppDetailsTest.ShadowUtils.class
+)
 public final class InstalledAppDetailsTest {
 
     private static final String PACKAGE_NAME = "test_package_name";
@@ -487,7 +491,6 @@
     }
 
     @Test
-    @Config(shadows = ShadowUtils.class)
     public void handleDisableable_appIsEnabled_buttonShouldWork() {
         final ApplicationInfo info = new ApplicationInfo();
         info.packageName = "pkg";
@@ -530,7 +533,6 @@
     }
 
     @Test
-    @Config(shadows = ShadowUtils.class)
     public void handleDisableable_appIsEnabledAndInKeepEnabledWhitelist_buttonShouldNotWork() {
         final ApplicationInfo info = new ApplicationInfo();
         info.packageName = "pkg";
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java
index 27c1a83..98a3580 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java
@@ -32,6 +32,7 @@
 import com.android.settings.TestConfig;
 import com.android.settings.testutils.FakeFeatureFactory;
 import com.android.settings.testutils.shadow.SettingsShadowBluetoothDevice;
+import com.android.settings.testutils.shadow.SettingsShadowResources;
 import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
 import com.android.settings.widget.EntityHeaderController;
 
@@ -45,7 +46,8 @@
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
-        shadows={SettingsShadowBluetoothDevice.class, ShadowEntityHeaderController.class})
+        shadows={SettingsShadowBluetoothDevice.class, ShadowEntityHeaderController.class,
+                SettingsShadowResources.class})
 public class BluetoothDetailsHeaderControllerTest extends BluetoothDetailsControllerTestBase {
     private BluetoothDetailsHeaderController mController;
     private LayoutPreference mPreference;
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePreferenceTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePreferenceTest.java
index d60571c..b16e5bc 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePreferenceTest.java
@@ -26,6 +26,7 @@
 import com.android.settings.TestConfig;
 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.shadow.SettingsShadowResources;
 import com.android.settingslib.bluetooth.CachedBluetoothDevice;
 
 import org.junit.Before;
@@ -44,7 +45,8 @@
 import static org.mockito.Mockito.when;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+        shadows = SettingsShadowResources.class)
 public class BluetoothDevicePreferenceTest {
 
     private Context mContext;
@@ -140,8 +142,11 @@
 
     @Test
     public void imagingDeviceIcon_isICSettingsPrint() {
+        when(mCachedBluetoothDevice.getBatteryLevel()).thenReturn(
+                BluetoothDevice.BATTERY_LEVEL_UNKNOWN);
         when(mCachedBluetoothDevice.getBtClass()).thenReturn(
                 new BluetoothClass(BluetoothClass.Device.Major.IMAGING));
+
         mPreference.onDeviceAttributesChanged();
         assertThat(mPreference.getIcon()).isEqualTo(
                 mContext.getDrawable(R.drawable.ic_settings_print));
diff --git a/tests/robotests/src/com/android/settings/bluetooth/UtilsTest.java b/tests/robotests/src/com/android/settings/bluetooth/UtilsTest.java
index 4667dac..7654921 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/UtilsTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/UtilsTest.java
@@ -15,14 +15,21 @@
  */
 package com.android.settings.bluetooth;
 
+import static com.google.common.truth.Truth.assertThat;
+
+import android.bluetooth.BluetoothDevice;
 import android.content.Context;
+import android.graphics.drawable.Drawable;
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.settings.R;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.shadow.SettingsShadowResources;
 import com.android.settingslib.bluetooth.LocalBluetoothManager;
+import com.android.settingslib.graph.BluetoothDeviceLayerDrawable;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -30,6 +37,7 @@
 import org.mockito.Answers;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
 
 import static org.mockito.Matchers.anyInt;
@@ -40,7 +48,8 @@
 import static org.mockito.Mockito.when;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+        shadows = SettingsShadowResources.class)
 public class UtilsTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
@@ -60,11 +69,27 @@
     }
 
     @Test
-    public void showConnectingError_shouldLogBluetoothConnectError() {
+    public void testShowConnectingError_shouldLogBluetoothConnectError() {
         when(mContext.getString(anyInt(), anyString())).thenReturn("testMessage");
         Utils.showConnectingError(mContext, "testName", mock(LocalBluetoothManager.class));
 
         verify(mMetricsFeatureProvider).visible(eq(mContext), anyInt(),
-            eq(MetricsEvent.ACTION_SETTINGS_BLUETOOTH_CONNECT_ERROR));
+                eq(MetricsEvent.ACTION_SETTINGS_BLUETOOTH_CONNECT_ERROR));
+    }
+
+    @Test
+    public void testGetBluetoothDrawable_noBatteryLevel_returnSimpleDrawable() {
+        final Drawable drawable = Utils.getBluetoothDrawable(RuntimeEnvironment.application,
+                R.drawable.ic_bt_laptop, BluetoothDevice.BATTERY_LEVEL_UNKNOWN);
+
+        assertThat(drawable).isNotInstanceOf(BluetoothDeviceLayerDrawable.class);
+    }
+
+    @Test
+    public void testGetBluetoothDrawable_hasBatteryLevel_returnLayerDrawable() {
+        final Drawable drawable = Utils.getBluetoothDrawable(RuntimeEnvironment.application,
+                R.drawable.ic_bt_laptop, 10 /* batteryLevel */);
+
+        assertThat(drawable).isInstanceOf(BluetoothDeviceLayerDrawable.class);
     }
 }
diff --git a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java
index 59b918a..45d04a4 100644
--- a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java
@@ -69,9 +69,11 @@
 import java.util.List;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH,
-        sdk = TestConfig.SDK_VERSION,
-        shadows = ShadowSecureSettings.class)
+@Config(
+    manifest = TestConfig.MANIFEST_PATH,
+    sdk = TestConfig.SDK_VERSION,
+    shadows = {ShadowSecureSettings.class, SettingsShadowResources.class}
+)
 public class SuggestionFeatureProviderImplTest {
 
     private static final String DOUBLE_TWIST_SENSOR_NAME = "double_twist_sensor_name";
@@ -115,7 +117,6 @@
     }
 
     @Test
-    @Config(shadows = SettingsShadowResources.class)
     public void isSuggestionCompleted_doubleTapPower_trueWhenNotAvailable() {
         SettingsShadowResources.overrideResource(
                 com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled, false);
@@ -126,7 +127,6 @@
     }
 
     @Test
-    @Config(shadows = SettingsShadowResources.class)
     public void isSuggestionCompleted_doubleTapPower_falseWhenNotVisited() {
         SettingsShadowResources.overrideResource(
                 com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled, true);
@@ -138,7 +138,6 @@
     }
 
     @Test
-    @Config(shadows = SettingsShadowResources.class)
     public void isSuggestionCompleted_doubleTapPower_trueWhenVisited() {
         SettingsShadowResources.overrideResource(
                 com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled, true);
@@ -151,7 +150,6 @@
     }
 
     @Test
-    @Config(shadows = SettingsShadowResources.class)
     public void isSuggestionCompleted_doubleTwist_trueWhenNotAvailable() {
         SettingsShadowResources.overrideResource(
                 R.string.gesture_double_twist_sensor_name, "nonexistant name");
@@ -164,7 +162,6 @@
     }
 
     @Test
-    @Config(shadows = SettingsShadowResources.class)
     public void isSuggestionCompleted_ambientDisplay_falseWhenNotVisited() {
         SettingsShadowResources.overrideResource(
                 com.android.internal.R.string.config_dozeComponent, "foo");
@@ -178,7 +175,6 @@
     }
 
     @Test
-    @Config(shadows = SettingsShadowResources.class)
     public void isSuggestionCompleted_ambientDisplay_trueWhenVisited() {
         SettingsShadowResources.overrideResource(
                 com.android.internal.R.string.config_dozeComponent, "foo");
@@ -193,7 +189,6 @@
     }
 
     @Test
-    @Config(shadows = SettingsShadowResources.class)
     public void isSuggestionCompleted_ambientDisplayPickup_falseWhenNotVisited() {
         SettingsShadowResources.overrideResource(
                 com.android.internal.R.string.config_dozeComponent, "foo");
@@ -207,7 +202,6 @@
     }
 
     @Test
-    @Config(shadows = SettingsShadowResources.class)
     public void isSuggestionCompleted_ambientDisplayPickup_trueWhenVisited() {
         SettingsShadowResources.overrideResource(
                 com.android.internal.R.string.config_dozeComponent, "foo");
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java
index 6b0bed1..b737d1f 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java
@@ -52,7 +52,11 @@
 
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(
+    manifest = TestConfig.MANIFEST_PATH,
+    sdk = TestConfig.SDK_VERSION,
+    shadows = {SettingsShadowSystemProperties.class}
+)
 public class AutomaticStorageManagementSwitchPreferenceControllerTest {
 
     @Mock
@@ -86,7 +90,6 @@
     }
 
     @Test
-    @Config(shadows = {SettingsShadowSystemProperties.class})
     public void isAvailable_shouldAlwaysReturnFalse_forLowRamDevice() {
         SettingsShadowSystemProperties.set("ro.config.low_ram", "true");
         assertThat(mController.isAvailable()).isFalse();
@@ -160,7 +163,6 @@
     }
 
 
-    @Config(shadows = {SettingsShadowSystemProperties.class})
     @Test
     public void togglingOnShouldNotTriggerWarningFragmentIfEnabledByDefault() {
         FragmentTransaction transaction = mock(FragmentTransaction.class);
@@ -174,7 +176,6 @@
         verify(transaction, never()).add(any(), eq(ActivationWarningFragment.TAG));
     }
 
-    @Config(shadows = {SettingsShadowSystemProperties.class})
     @Test
     public void togglingOnShouldTriggerWarningFragmentIfEnabledByDefaultAndDisabledByPolicy() {
         FragmentTransaction transaction = mock(FragmentTransaction.class);
diff --git a/tests/robotests/src/com/android/settings/display/AutoRotatePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/AutoRotatePreferenceControllerTest.java
index 6d9cbab..06fd297 100644
--- a/tests/robotests/src/com/android/settings/display/AutoRotatePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/AutoRotatePreferenceControllerTest.java
@@ -45,7 +45,11 @@
 import static org.mockito.Mockito.when;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(
+    manifest = TestConfig.MANIFEST_PATH,
+    sdk = TestConfig.SDK_VERSION,
+    shadows = ShadowSystemSettings.class
+)
 public class AutoRotatePreferenceControllerTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
@@ -88,7 +92,6 @@
     }
 
     @Test
-    @Config(shadows = ShadowSystemSettings.class)
     public void updatePreference_settingsIsOff_shouldTurnOffToggle() {
         Settings.System.putIntForUser(mContentResolver,
                 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT);
@@ -99,7 +102,6 @@
     }
 
     @Test
-    @Config(shadows = ShadowSystemSettings.class)
     public void updatePreference_settingsIsOn_shouldTurnOnToggle() {
         Settings.System.putIntForUser(mContentResolver,
                 Settings.System.ACCELEROMETER_ROTATION, 1, UserHandle.USER_CURRENT);
diff --git a/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsPreferenceControllerTest.java
index 6767346..7633ce9 100644
--- a/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsPreferenceControllerTest.java
@@ -43,7 +43,11 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(
+    manifest = TestConfig.MANIFEST_PATH,
+    sdk = TestConfig.SDK_VERSION,
+    shadows = ShadowSecureSettings.class
+)
 public class AssistGestureSettingsPreferenceControllerTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
@@ -86,7 +90,6 @@
     }
 
     @Test
-    @Config(shadows = ShadowSecureSettings.class)
     public void testSetValue_updatesCorrectly() {
         int newValue = 1;
         ContentResolver resolver = mContext.getContentResolver();
@@ -99,7 +102,6 @@
     }
 
     @Test
-    @Config(shadows = ShadowSecureSettings.class)
     public void testGetValue_correctValueReturned() {
         int currentValue = 1;
         ContentResolver resolver = mContext.getContentResolver();
diff --git a/tests/robotests/src/com/android/settings/network/MobileNetworkPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/MobileNetworkPreferenceControllerTest.java
index 66e357b..2c11e0c 100644
--- a/tests/robotests/src/com/android/settings/network/MobileNetworkPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/MobileNetworkPreferenceControllerTest.java
@@ -47,7 +47,11 @@
 import static org.mockito.Mockito.when;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(
+    manifest = TestConfig.MANIFEST_PATH,
+    sdk = TestConfig.SDK_VERSION,
+    shadows = ShadowRestrictedLockUtilsWrapper.class
+)
 public class MobileNetworkPreferenceControllerTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
@@ -88,7 +92,6 @@
     }
 
     @Test
-    @Config(shadows = ShadowRestrictedLockUtilsWrapper.class)
     public void wifiOnly_prefIsNotAvailable() {
         when(mUserManager.isAdminUser()).thenReturn(true);
         when(mUserManager.hasUserRestriction(anyString(), any(UserHandle.class)))
diff --git a/tests/robotests/src/com/android/settings/search/DatabaseIndexingManagerTest.java b/tests/robotests/src/com/android/settings/search/DatabaseIndexingManagerTest.java
index 3641368..70ed568 100644
--- a/tests/robotests/src/com/android/settings/search/DatabaseIndexingManagerTest.java
+++ b/tests/robotests/src/com/android/settings/search/DatabaseIndexingManagerTest.java
@@ -79,8 +79,15 @@
 import java.util.Set;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
-        shadows = {ShadowRunnableAsyncTask.class})
+@Config(
+    manifest = TestConfig.MANIFEST_PATH,
+    sdk = TestConfig.SDK_VERSION,
+    shadows = {
+        ShadowRunnableAsyncTask.class,
+        ShadowDatabaseIndexingUtils.class,
+        ShadowContentResolver.class
+    }
+)
 public class DatabaseIndexingManagerTest {
     private final String localeStr = "en_US";
 
@@ -747,7 +754,6 @@
     // Test new public indexing flow
 
     @Test
-    @Config(shadows = {ShadowDatabaseIndexingUtils.class})
     public void testPerformIndexing_fullIndex_getsDataFromProviders() {
         DummyProvider provider = new DummyProvider();
         provider.onCreate();
@@ -767,7 +773,6 @@
     }
 
     @Test
-    @Config(shadows = {ShadowDatabaseIndexingUtils.class,})
     public void testPerformIndexing_incrementalIndex_noDataAdded() {
         final List<ResolveInfo> providerInfo = getDummyResolveInfo();
         skipFullIndex(providerInfo);
@@ -792,7 +797,6 @@
     }
 
     @Test
-    @Config(shadows = {ShadowDatabaseIndexingUtils.class,})
     public void testPerformIndexing_localeChanged_databaseDropped() {
         DummyProvider provider = new DummyProvider();
         provider.onCreate();
@@ -830,7 +834,6 @@
     }
 
     @Test
-    @Config(shadows = {ShadowDatabaseIndexingUtils.class,})
     public void testPerformIndexing_onOta_FullIndex() {
         DummyProvider provider = new DummyProvider();
         provider.onCreate();
@@ -851,7 +854,6 @@
     }
 
     @Test
-    @Config(shadows = {ShadowDatabaseIndexingUtils.class,})
     public void testPerformIndexing_onPackageChange_shouldFullIndex() {
         final List<ResolveInfo> providers = getDummyResolveInfo();
         final String buildNumber = Build.FINGERPRINT;
@@ -873,7 +875,6 @@
     }
 
     @Test
-    @Config(shadows = {ShadowDatabaseIndexingUtils.class,})
     public void testPerformIndexing_onOta_buildNumberIsCached() {
         DummyProvider provider = new DummyProvider();
         provider.onCreate();
@@ -1017,7 +1018,6 @@
     }
 
     @Test
-    @Config(shadows = {ShadowContentResolver.class})
     public void testEmptyNonIndexableKeys_emptyDataKeyResources_addedToDatabase() {
         insertSpecialCase(TITLE_ONE, true /* enabled */, null /* dataReferenceKey */);
 
diff --git a/tests/robotests/src/com/android/settings/security/ConfigureKeyGuardDialogTest.java b/tests/robotests/src/com/android/settings/security/ConfigureKeyGuardDialogTest.java
index 1a37dec..1809e88 100644
--- a/tests/robotests/src/com/android/settings/security/ConfigureKeyGuardDialogTest.java
+++ b/tests/robotests/src/com/android/settings/security/ConfigureKeyGuardDialogTest.java
@@ -34,11 +34,14 @@
 import static org.mockito.Mockito.verify;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(
+    manifest = TestConfig.MANIFEST_PATH,
+    sdk = TestConfig.SDK_VERSION,
+    shadows = ShadowEventLogWriter.class
+)
 public class ConfigureKeyGuardDialogTest {
 
     @Test
-    @Config(shadows = ShadowEventLogWriter.class)
     public void displayDialog_clickPositiveButton_launchSetNewPassword() {
         final FragmentController<ConfigureKeyGuardDialog> fragmentController =
                 Robolectric.buildFragment(ConfigureKeyGuardDialog.class);
diff --git a/tests/robotests/src/com/android/settings/system/FactoryResetPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/system/FactoryResetPreferenceControllerTest.java
index 7310ae0..b986e4f 100644
--- a/tests/robotests/src/com/android/settings/system/FactoryResetPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/system/FactoryResetPreferenceControllerTest.java
@@ -37,7 +37,11 @@
 import org.robolectric.annotation.Config;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(
+    manifest = TestConfig.MANIFEST_PATH,
+    sdk = TestConfig.SDK_VERSION,
+    shadows = {ShadowSecureSettings.class, ShadowUtils.class}
+)
 public class FactoryResetPreferenceControllerTest {
 
     private static final String FACTORY_RESET_KEY = "factory_reset";
@@ -72,7 +76,6 @@
     }
 
     @Test
-    @Config(shadows = { ShadowSecureSettings.class, ShadowUtils.class })
     public void isAvailable_nonSystemUser() {
         when(mUserManager.isAdminUser()).thenReturn(false);
         ShadowUtils.setIsDemoUser(false);
@@ -81,7 +84,6 @@
     }
 
     @Test
-    @Config(shadows = { ShadowSecureSettings.class, ShadowUtils.class })
     public void isAvailable_demoUser() {
         when(mUserManager.isAdminUser()).thenReturn(false);
         ShadowUtils.setIsDemoUser(true);
diff --git a/tests/robotests/src/com/android/settings/widget/RtlCompatibleViewPagerTest.java b/tests/robotests/src/com/android/settings/widget/RtlCompatibleViewPagerTest.java
index ea27d05..78afc43 100644
--- a/tests/robotests/src/com/android/settings/widget/RtlCompatibleViewPagerTest.java
+++ b/tests/robotests/src/com/android/settings/widget/RtlCompatibleViewPagerTest.java
@@ -34,7 +34,11 @@
 import static com.google.common.truth.Truth.assertThat;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(
+    manifest = TestConfig.MANIFEST_PATH,
+    sdk = TestConfig.SDK_VERSION,
+    shadows = {ShadowTextUtils.class}
+)
 public class RtlCompatibleViewPagerTest {
 
     private Locale mLocaleEn;
@@ -51,7 +55,6 @@
     }
 
     @Test
-    @Config(shadows = {ShadowTextUtils.class})
     public void testGetCurrentItem_shouldMaintainIndexDuringLocaleChange() {
         testRtlCompatibleInner(0);
         testRtlCompatibleInner(1);