Merge "Update char limit for DND conditional"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 6f0fd09..c052c62 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1859,6 +1859,11 @@
     <!-- This string asks the user whether or not to allow an app to disable WiFi. [CHAR LIMIT=NONE] -->
     <string name="wifi_ask_disable"><xliff:g id="requester" example="FancyApp">%s</xliff:g> wants to turn off Wi-Fi</string>
 
+    <!-- Debugging developer settings: Enable ART verifier for Debuggable Apps [CHAR LIMIT=40] -->
+    <string name="art_verifier_for_debuggable_title">Verify bytecode of debuggable apps</string>
+    <!-- Debugging developer settings: Enable ART verifier for Debuggable Apps [CHAR LIMIT=NONE] -->
+    <string name="art_verifier_for_debuggable_summary">Allow ART to verify bytecode for debuggable apps</string>
+
     <!-- NFC settings -->
     <!-- Used in the 1st-level settings screen to turn on NFC -->
     <string name="nfc_quick_toggle_title">NFC</string>
diff --git a/res/xml/development_settings.xml b/res/xml/development_settings.xml
index d9b592c..032f622 100644
--- a/res/xml/development_settings.xml
+++ b/res/xml/development_settings.xml
@@ -175,6 +175,11 @@
             android:title="@string/verify_apps_over_usb_title"
             android:summary="@string/verify_apps_over_usb_summary" />
 
+        <SwitchPreference
+            android:key="art_verifier_for_debuggable"
+            android:title="@string/art_verifier_for_debuggable_title"
+            android:summary="@string/art_verifier_for_debuggable_summary" />
+
         <ListPreference
             android:key="select_logd_size"
             android:title="@string/select_logd_size_title"
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index 65cfdf6..37643b3 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -89,6 +89,7 @@
 import android.widget.TabWidget;
 
 import androidx.annotation.StringRes;
+import androidx.core.graphics.drawable.IconCompat;
 import androidx.fragment.app.Fragment;
 import androidx.preference.Preference;
 import androidx.preference.PreferenceGroup;
@@ -950,24 +951,30 @@
             bitmap = Bitmap.createScaledBitmap(((BitmapDrawable) original).getBitmap(), width,
                     height, false);
         } else {
-            bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
-            final Canvas canvas = new Canvas(bitmap);
-            original.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
-            original.draw(canvas);
+            bitmap = createBitmap(original, width, height);
         }
         return new BitmapDrawable(null, bitmap);
     }
 
     /**
-     * Converts the {@link Drawable} to a {@link Bitmap}.
+     * Create an Icon pointing to a drawable.
      */
-    public static Bitmap drawableToBitmap(Drawable drawable) {
+    public static IconCompat createIconWithDrawable(Drawable drawable) {
+        Bitmap bitmap;
         if (drawable instanceof BitmapDrawable) {
-            return ((BitmapDrawable)drawable).getBitmap();
+            bitmap = ((BitmapDrawable)drawable).getBitmap();
+        } else {
+            final int width = drawable.getIntrinsicWidth();
+            final int height = drawable.getIntrinsicHeight();
+            bitmap = createBitmap(drawable,
+                    width > 0 ? width : 1,
+                    height > 0 ? height : 1);
         }
+        return IconCompat.createWithBitmap(bitmap);
+    }
 
-        final Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
-                drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
+    private static Bitmap createBitmap(Drawable drawable, int width, int height) {
+        final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
         final Canvas canvas = new Canvas(bitmap);
         drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
         drawable.draw(canvas);
diff --git a/src/com/android/settings/development/ArtVerifierPreferenceController.java b/src/com/android/settings/development/ArtVerifierPreferenceController.java
new file mode 100644
index 0000000..4b2f030
--- /dev/null
+++ b/src/com/android/settings/development/ArtVerifierPreferenceController.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2019 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.provider.Settings;
+
+import androidx.annotation.VisibleForTesting;
+import androidx.preference.Preference;
+import androidx.preference.SwitchPreference;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.development.DeveloperOptionsPreferenceController;
+
+public class ArtVerifierPreferenceController extends DeveloperOptionsPreferenceController
+        implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
+
+    private static final String ART_VERIFIER_FOR_DEBUGGABLE = "art_verifier_for_debuggable";
+
+    @VisibleForTesting
+    static final int SETTING_VALUE_ON = 1;
+    @VisibleForTesting
+    static final int SETTING_VALUE_OFF = 0;
+
+    public ArtVerifierPreferenceController(Context context) {
+        super(context);
+    }
+
+    @Override
+    public String getPreferenceKey() {
+        return ART_VERIFIER_FOR_DEBUGGABLE;
+    }
+
+    @Override
+    public boolean onPreferenceChange(Preference preference, Object newValue) {
+        final boolean isEnabled = (Boolean) newValue;
+        Settings.Global.putInt(mContext.getContentResolver(),
+                Settings.Global.ART_VERIFIER_VERIFY_DEBUGGABLE,
+                isEnabled ? SETTING_VALUE_ON : SETTING_VALUE_OFF);
+        return true;
+    }
+
+    @Override
+    public void updateState(Preference preference) {
+        final int verifyDebuggable = Settings.Global.getInt(
+                mContext.getContentResolver(),
+                Settings.Global.ART_VERIFIER_VERIFY_DEBUGGABLE, SETTING_VALUE_ON);
+        ((SwitchPreference) mPreference).setChecked(verifyDebuggable != SETTING_VALUE_OFF);
+    }
+
+    @Override
+    protected void onDeveloperOptionsSwitchDisabled() {
+        super.onDeveloperOptionsSwitchDisabled();
+        Settings.Global.putInt(mContext.getContentResolver(),
+                Settings.Global.ART_VERIFIER_VERIFY_DEBUGGABLE, SETTING_VALUE_ON);
+        ((SwitchPreference) mPreference).setChecked(true);
+    }
+}
diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
index 78520c6..adc23a8 100644
--- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
+++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
@@ -424,6 +424,7 @@
         controllers.add(new WaitForDebuggerPreferenceController(context));
         controllers.add(new EnableGpuDebugLayersPreferenceController(context));
         controllers.add(new VerifyAppsOverUsbPreferenceController(context));
+        controllers.add(new ArtVerifierPreferenceController(context));
         controllers.add(new LogdSizePreferenceController(context));
         controllers.add(new LogPersistPreferenceController(context, fragment, lifecycle));
         controllers.add(new CameraLaserSensorPreferenceController(context));
diff --git a/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSlice.java b/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSlice.java
index 0156ac6..95412a8 100644
--- a/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSlice.java
+++ b/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSlice.java
@@ -214,7 +214,7 @@
                 .getBtClassDrawableWithDescription(mContext, device);
 
         if (pair.first != null) {
-            return IconCompat.createWithBitmap(Utils.drawableToBitmap(pair.first));
+            return Utils.createIconWithDrawable(pair.first);
         } else {
             return IconCompat.createWithResource(mContext,
                 com.android.internal.R.drawable.ic_settings_bluetooth);
diff --git a/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSlice.java b/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSlice.java
index 692dc0a..c2c2ece 100644
--- a/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSlice.java
+++ b/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSlice.java
@@ -30,9 +30,6 @@
 import android.content.Intent;
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
 import android.net.Uri;
 import android.os.Bundle;
@@ -243,7 +240,7 @@
             return null;
         }
 
-        return IconCompat.createWithBitmap(Utils.drawableToBitmap(drawable));
+        return Utils.createIconWithDrawable(drawable);
     }
 
     @VisibleForTesting
diff --git a/src/com/android/settings/media/MediaOutputSlice.java b/src/com/android/settings/media/MediaOutputSlice.java
index 5c5eb88..d52b441 100644
--- a/src/com/android/settings/media/MediaOutputSlice.java
+++ b/src/com/android/settings/media/MediaOutputSlice.java
@@ -23,8 +23,6 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.PackageManager;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
 import android.graphics.drawable.Drawable;
 import android.net.Uri;
 import android.os.UserHandle;
@@ -87,7 +85,7 @@
 
         final Drawable drawable =
                 Utils.getBadgedIcon(mIconDrawableFactory, pm, mPackageName, UserHandle.myUserId());
-        final IconCompat icon = IconCompat.createWithBitmap(getBitmapFromDrawable(drawable));
+        final IconCompat icon = Utils.createIconWithDrawable(drawable);
 
         @ColorInt final int color = Utils.getColorAccentDefaultColor(mContext);
         final SliceAction primarySliceAction = SliceAction.createDeeplink(getPrimaryAction(), icon,
@@ -134,17 +132,6 @@
         return PendingIntent.getActivity(mContext, 0  /* requestCode */, intent, 0  /* flags */);
     }
 
-    private Bitmap getBitmapFromDrawable(Drawable drawable) {
-        final Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
-                drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
-        final Canvas canvas = new Canvas(bitmap);
-
-        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
-        drawable.draw(canvas);
-
-        return bitmap;
-    }
-
     private ListBuilder.RowBuilder getMediaDeviceRow(MediaDevice device) {
         final String title = device.getName();
         final PendingIntent broadcastAction =
diff --git a/src/com/android/settings/network/telephony/MobileDataPreferenceController.java b/src/com/android/settings/network/telephony/MobileDataPreferenceController.java
index f678e08..de54879 100644
--- a/src/com/android/settings/network/telephony/MobileDataPreferenceController.java
+++ b/src/com/android/settings/network/telephony/MobileDataPreferenceController.java
@@ -22,21 +22,21 @@
 import android.os.Handler;
 import android.os.Looper;
 import android.provider.Settings;
+import android.telephony.SubscriptionInfo;
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
 import android.text.TextUtils;
 
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnStart;
+import com.android.settingslib.core.lifecycle.events.OnStop;
+
 import androidx.annotation.VisibleForTesting;
 import androidx.fragment.app.FragmentManager;
 import androidx.preference.Preference;
 import androidx.preference.PreferenceScreen;
 import androidx.preference.SwitchPreference;
 
-import com.android.settings.core.TogglePreferenceController;
-import com.android.settingslib.core.lifecycle.LifecycleObserver;
-import com.android.settingslib.core.lifecycle.events.OnStart;
-import com.android.settingslib.core.lifecycle.events.OnStop;
-
 /**
  * Preference controller for "Mobile data"
  */
@@ -115,8 +115,18 @@
 
     @Override
     public boolean isChecked() {
-        return mTelephonyManager.isDataEnabled()
-                && mSubId == SubscriptionManager.getDefaultDataSubscriptionId();
+        return mTelephonyManager.isDataEnabled();
+    }
+
+    @Override
+    public void updateState(Preference preference) {
+        super.updateState(preference);
+        preference.setEnabled(!isOpportunistic());
+    }
+
+    private boolean isOpportunistic() {
+        SubscriptionInfo info = mSubscriptionManager.getActiveSubscriptionInfo(mSubId);
+        return info != null && info.isOpportunistic();
     }
 
     public static Uri getObservableUri(int subId) {
diff --git a/src/com/android/settings/wifi/slice/ContextualWifiSlice.java b/src/com/android/settings/wifi/slice/ContextualWifiSlice.java
index 7a6d1fa..5761ae5 100644
--- a/src/com/android/settings/wifi/slice/ContextualWifiSlice.java
+++ b/src/com/android/settings/wifi/slice/ContextualWifiSlice.java
@@ -90,7 +90,7 @@
         }
 
         d.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN));
-        return IconCompat.createWithBitmap(Utils.drawableToBitmap(d));
+        return Utils.createIconWithDrawable(d);
     }
 
     @Override
diff --git a/tests/robotests/src/com/android/settings/UtilsTest.java b/tests/robotests/src/com/android/settings/UtilsTest.java
index c10e0d6..37186ca 100644
--- a/tests/robotests/src/com/android/settings/UtilsTest.java
+++ b/tests/robotests/src/com/android/settings/UtilsTest.java
@@ -34,6 +34,11 @@
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
 import android.content.pm.UserInfo;
+import android.graphics.Bitmap;
+import android.graphics.Color;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.ColorDrawable;
+import android.graphics.drawable.VectorDrawable;
 import android.net.ConnectivityManager;
 import android.net.LinkAddress;
 import android.net.LinkProperties;
@@ -48,6 +53,8 @@
 import android.widget.EditText;
 import android.widget.TextView;
 
+import androidx.core.graphics.drawable.IconCompat;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -96,7 +103,7 @@
     }
 
     @Test
-    public void testGetWifiIpAddresses_succeeds() throws Exception {
+    public void getWifiIpAddresses_succeeds() throws Exception {
         when(wifiManager.getCurrentNetwork()).thenReturn(network);
         LinkAddress address = new LinkAddress(InetAddress.getByName("127.0.0.1"), 0);
         LinkProperties lp = new LinkProperties();
@@ -107,7 +114,7 @@
     }
 
     @Test
-    public void testGetWifiIpAddresses_nullLinkProperties() {
+    public void getWifiIpAddresses_nullLinkProperties() {
         when(wifiManager.getCurrentNetwork()).thenReturn(network);
         // Explicitly set the return value to null for readability sake.
         when(connectivityManager.getLinkProperties(network)).thenReturn(null);
@@ -116,7 +123,7 @@
     }
 
     @Test
-    public void testGetWifiIpAddresses_nullNetwork() {
+    public void getWifiIpAddresses_nullNetwork() {
         // Explicitly set the return value to null for readability sake.
         when(wifiManager.getCurrentNetwork()).thenReturn(null);
 
@@ -124,7 +131,7 @@
     }
 
     @Test
-    public void testInitializeVolumeDoesntBreakOnNullVolume() {
+    public void initializeVolumeDoesntBreakOnNullVolume() {
         VolumeInfo info = new VolumeInfo("id", 0, new DiskInfo("id", 0), "");
         StorageManager storageManager = mock(StorageManager.class, RETURNS_DEEP_STUBS);
         when(storageManager.findVolumeById(anyString())).thenReturn(info);
@@ -133,13 +140,13 @@
     }
 
     @Test
-    public void testGetInstallationStatus_notInstalled_shouldReturnUninstalled() {
+    public void getInstallationStatus_notInstalled_shouldReturnUninstalled() {
         assertThat(Utils.getInstallationStatus(new ApplicationInfo()))
                 .isEqualTo(R.string.not_installed);
     }
 
     @Test
-    public void testGetInstallationStatus_enabled_shouldReturnInstalled() {
+    public void getInstallationStatus_enabled_shouldReturnInstalled() {
         final ApplicationInfo info = new ApplicationInfo();
         info.flags = ApplicationInfo.FLAG_INSTALLED;
         info.enabled = true;
@@ -148,7 +155,7 @@
     }
 
     @Test
-    public void testGetInstallationStatus_disabled_shouldReturnDisabled() {
+    public void getInstallationStatus_disabled_shouldReturnDisabled() {
         final ApplicationInfo info = new ApplicationInfo();
         info.flags = ApplicationInfo.FLAG_INSTALLED;
         info.enabled = false;
@@ -157,7 +164,7 @@
     }
 
     @Test
-    public void testIsProfileOrDeviceOwner_deviceOwnerApp_returnTrue() {
+    public void isProfileOrDeviceOwner_deviceOwnerApp_returnTrue() {
         when(mDevicePolicyManager.isDeviceOwnerAppOnAnyUser(PACKAGE_NAME)).thenReturn(true);
 
         assertThat(Utils.isProfileOrDeviceOwner(mUserManager, mDevicePolicyManager, PACKAGE_NAME))
@@ -165,7 +172,7 @@
     }
 
     @Test
-    public void testIsProfileOrDeviceOwner_profileOwnerApp_returnTrue() {
+    public void isProfileOrDeviceOwner_profileOwnerApp_returnTrue() {
         final List<UserInfo> userInfos = new ArrayList<>();
         userInfos.add(new UserInfo());
 
@@ -178,7 +185,7 @@
     }
 
     @Test
-    public void testSetEditTextCursorPosition_shouldGetExpectedEditTextLenght() {
+    public void setEditTextCursorPosition_shouldGetExpectedEditTextLenght() {
         final EditText editText = new EditText(mContext);
         final CharSequence text = "test";
         editText.setText(text, TextView.BufferType.EDITABLE);
@@ -189,7 +196,36 @@
     }
 
     @Test
-    public void testGetBadgedIcon_usePackageNameAndUserId()
+    public void createIconWithDrawable_BitmapDrawable() {
+        final Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
+        final BitmapDrawable drawable = new BitmapDrawable(mContext.getResources(), bitmap);
+
+        final IconCompat icon = Utils.createIconWithDrawable(drawable);
+
+        assertThat(icon.getBitmap()).isNotNull();
+    }
+
+    @Test
+    public void createIconWithDrawable_ColorDrawable() {
+        final ColorDrawable drawable = new ColorDrawable(Color.BLACK);
+
+        final IconCompat icon = Utils.createIconWithDrawable(drawable);
+
+        assertThat(icon.getBitmap()).isNotNull();
+    }
+
+    @Test
+    public void createIconWithDrawable_VectorDrawable() {
+        final VectorDrawable drawable = VectorDrawable.create(mContext.getResources(),
+                R.drawable.ic_settings_accent);
+
+        final IconCompat icon = Utils.createIconWithDrawable(drawable);
+
+        assertThat(icon.getBitmap()).isNotNull();
+    }
+
+    @Test
+    public void getBadgedIcon_usePackageNameAndUserId()
         throws PackageManager.NameNotFoundException {
         doReturn(mApplicationInfo).when(mPackageManager).getApplicationInfoAsUser(
                 PACKAGE_NAME, PackageManager.GET_META_DATA, USER_ID);
diff --git a/tests/robotests/src/com/android/settings/development/ArtVerifierPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/ArtVerifierPreferenceControllerTest.java
new file mode 100644
index 0000000..e5dade4
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/development/ArtVerifierPreferenceControllerTest.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2019 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.Context;
+import android.provider.Settings;
+
+import androidx.preference.PreferenceScreen;
+import androidx.preference.SwitchPreference;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class ArtVerifierPreferenceControllerTest {
+
+    @Mock
+    private SwitchPreference mPreference;
+    @Mock
+    private PreferenceScreen mPreferenceScreen;
+
+    private Context mContext;
+    private ArtVerifierPreferenceController mController;
+
+    @Before
+    public void setup() {
+        MockitoAnnotations.initMocks(this);
+        mContext = RuntimeEnvironment.application;
+        mController = new ArtVerifierPreferenceController(mContext);
+        when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
+            .thenReturn(mPreference);
+        mController.displayPreference(mPreferenceScreen);
+    }
+
+    @Test
+    public void onPreferenceChanged_settingEnabled_turnOnArtVerifier() {
+        mController.onPreferenceChange(mPreference, true /* new value */);
+
+        final int mode = Settings.Global.getInt(mContext.getContentResolver(),
+                Settings.Global.ART_VERIFIER_VERIFY_DEBUGGABLE, -1 /* default */);
+
+        assertThat(mode).isEqualTo(ArtVerifierPreferenceController.SETTING_VALUE_ON);
+    }
+
+    @Test
+    public void onPreferenceChanged_settingDisabled_turnOffArtVerifier() {
+        mController.onPreferenceChange(mPreference, false /* new value */);
+
+        final int mode = Settings.Global.getInt(mContext.getContentResolver(),
+                Settings.Global.ART_VERIFIER_VERIFY_DEBUGGABLE, -1 /* default */);
+
+        assertThat(mode).isEqualTo(ArtVerifierPreferenceController.SETTING_VALUE_OFF);
+    }
+
+    @Test
+    public void updateState_settingEnabled_preferenceShouldBeChecked() {
+        Settings.Global.putInt(mContext.getContentResolver(),
+                Settings.Global.ART_VERIFIER_VERIFY_DEBUGGABLE,
+                ArtVerifierPreferenceController.SETTING_VALUE_ON);
+        mController.updateState(mPreference);
+
+        verify(mPreference).setChecked(true);
+    }
+
+    @Test
+    public void updateState_settingDisabled_preferenceShouldBeChecked() {
+        Settings.Global.putInt(mContext.getContentResolver(),
+                Settings.Global.ART_VERIFIER_VERIFY_DEBUGGABLE,
+                ArtVerifierPreferenceController.SETTING_VALUE_OFF);
+        mController.updateState(mPreference);
+
+        verify(mPreference).setChecked(false);
+    }
+
+    @Test
+    public void onDeveloperOptionsSwitchDisabled_shouldDisablePreference() {
+        mController.onDeveloperOptionsSwitchDisabled();
+        final int mode = Settings.Global.getInt(mContext.getContentResolver(),
+                Settings.Global.ART_VERIFIER_VERIFY_DEBUGGABLE, -1 /* default */);
+
+        assertThat(mode).isEqualTo(ArtVerifierPreferenceController.SETTING_VALUE_ON);
+        verify(mPreference).setEnabled(false);
+        verify(mPreference).setChecked(true);
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/network/telephony/MobileDataPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/MobileDataPreferenceControllerTest.java
index 4c242c1..1b7b4b4 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/MobileDataPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/MobileDataPreferenceControllerTest.java
@@ -149,4 +149,23 @@
 
         verify(mTelephonyManager).setDataEnabled(true);
     }
+
+    @Test
+    public void isChecked_returnUserDataEnabled() {
+        mController.init(mFragmentManager, SUB_ID);
+        assertThat(mController.isChecked()).isFalse();
+
+        doReturn(true).when(mTelephonyManager).isDataEnabled();
+        assertThat(mController.isChecked()).isTrue();
+    }
+
+    @Test
+    public void updateState_opportunistic_disabled() {
+        doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(SUB_ID);
+        mController.init(mFragmentManager, SUB_ID);
+        doReturn(true).when(mSubscriptionInfo).isOpportunistic();
+        mController.updateState(mPreference);
+
+        assertThat(mPreference.isEnabled()).isFalse();
+    }
 }
diff --git a/tests/robotests/src/com/android/settings/wifi/qrcode/QrCameraTest.java b/tests/robotests/src/com/android/settings/wifi/qrcode/QrCameraTest.java
index a57fefc..bd2ce1e 100644
--- a/tests/robotests/src/com/android/settings/wifi/qrcode/QrCameraTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/qrcode/QrCameraTest.java
@@ -22,14 +22,11 @@
 
 import android.content.Context;
 import android.graphics.Bitmap;
-import android.graphics.Color;
 import android.graphics.Matrix;
 import android.graphics.Rect;
 import android.graphics.SurfaceTexture;
 import android.util.Size;
 
-import com.android.settings.R;
-
 import com.google.zxing.BinaryBitmap;
 import com.google.zxing.LuminanceSource;
 import com.google.zxing.RGBLuminanceSource;