Merge "Remove the duplicate test case that is added by auto-merge."
diff --git a/res/layout/preference_widget_seekbar_settings.xml b/res/layout/preference_widget_seekbar_settings.xml
index 87fea99..c25c598 100644
--- a/res/layout/preference_widget_seekbar_settings.xml
+++ b/res/layout/preference_widget_seekbar_settings.xml
@@ -19,36 +19,36 @@
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    android:minHeight="?android:attr/listPreferredItemHeight"
+    android:layout_marginTop="6dp"
+    android:layout_marginBottom="6dp"
     android:gravity="center_vertical"
+    android:minHeight="?android:attr/listPreferredItemHeight"
     android:paddingStart="?android:attr/listPreferredItemPaddingStart"
-    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
-    android:paddingBottom="6dp"
-    android:paddingTop="6dp">
+    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
 
     <TextView
         android:id="@android:id/title"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_marginStart="60dp"
-        android:layout_marginEnd="8dp"
+        android:ellipsize="marquee"
+        android:fadingEdge="horizontal"
+        android:paddingStart="56dp"
+        android:paddingEnd="8dp"
         android:singleLine="true"
         android:textAppearance="@android:style/TextAppearance.Material.Subhead"
-        android:textColor="?android:attr/textColorPrimary"
-        android:ellipsize="marquee"
-        android:fadingEdge="horizontal" />
+        android:textColor="?android:attr/textColorPrimary" />
 
     <TextView
         android:id="@android:id/summary"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_marginStart="60dp"
-        android:layout_marginEnd="8dp"
-        android:layout_below="@android:id/title"
         android:layout_alignStart="@android:id/title"
+        android:layout_below="@android:id/title"
+        android:maxLines="4"
+        android:paddingStart="56dp"
+        android:paddingEnd="8dp"
         android:textAppearance="?android:attr/textAppearanceListItemSecondary"
-        android:textColor="?android:attr/textColorSecondary"
-        android:maxLines="4" />
+        android:textColor="?android:attr/textColorSecondary" />
 
     <com.android.settings.widget.DefaultIndicatorSeekBar
         android:id="@*android:id/seekbar"
@@ -57,7 +57,7 @@
         android:layout_height="48dp"
         android:layout_alignParentEnd="true"
         android:layout_below="@android:id/summary"
-        android:layout_marginEnd="8dp"
-        android:layout_marginStart="44dp" />
+        android:paddingStart="56dp"
+        android:paddingEnd="8dp" />
 
 </RelativeLayout>
diff --git a/src/com/android/settings/MasterClear.java b/src/com/android/settings/MasterClear.java
index 77c6091..dc4c995 100644
--- a/src/com/android/settings/MasterClear.java
+++ b/src/com/android/settings/MasterClear.java
@@ -23,6 +23,7 @@
 import android.accounts.AuthenticatorDescription;
 import android.app.Activity;
 import android.app.FragmentManager;
+import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.PackageManager;
@@ -34,6 +35,7 @@
 import android.os.SystemProperties;
 import android.os.UserHandle;
 import android.os.UserManager;
+import android.provider.Settings;
 import android.support.annotation.VisibleForTesting;
 import android.telephony.euicc.EuiccManager;
 import android.util.Log;
@@ -208,9 +210,7 @@
             });
         }
 
-        EuiccManager euiccManager =
-                        (EuiccManager) getActivity().getSystemService(Context.EUICC_SERVICE);
-        if (euiccManager.isEnabled()) {
+        if (showWipeEuicc()) {
             mEsimStorageContainer.setOnClickListener(new View.OnClickListener() {
 
                 @Override
@@ -244,6 +244,30 @@
         mScrollView.getViewTreeObserver().addOnGlobalLayoutListener(mOnGlobalLayoutListener);
     }
 
+    /**
+     * Whether to show the checkbox to wipe the eUICC.
+     *
+     * <p>We show the checkbox on any device which supports eUICC as long as either the eUICC was
+     * ever provisioned (that is, at least one profile was ever downloaded onto it), or if the user
+     * has enabled development mode.
+     */
+    @VisibleForTesting
+    boolean showWipeEuicc() {
+        Context context = getContext();
+        if (!isEuiccEnabled(context)) {
+            return false;
+        }
+        ContentResolver cr = context.getContentResolver();
+        return Settings.Global.getInt(cr, Settings.Global.EUICC_PROVISIONED, 0) != 0
+                || Settings.Global.getInt(cr, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
+    }
+
+    @VisibleForTesting
+    protected boolean isEuiccEnabled(Context context) {
+        EuiccManager euiccManager = (EuiccManager) context.getSystemService(Context.EUICC_SERVICE);
+        return euiccManager.isEnabled();
+    }
+
     @VisibleForTesting
     boolean hasReachedBottom(final ScrollView scrollView) {
         if (scrollView.getChildCount() < 1) {
diff --git a/tests/robotests/src/com/android/settings/MasterClearTest.java b/tests/robotests/src/com/android/settings/MasterClearTest.java
index 98b33d3..9af2b5f 100644
--- a/tests/robotests/src/com/android/settings/MasterClearTest.java
+++ b/tests/robotests/src/com/android/settings/MasterClearTest.java
@@ -17,13 +17,18 @@
 package com.android.settings;
 
 import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.when;
 import static org.robolectric.Shadows.shadowOf;
 
 import android.app.Activity;
 import android.app.Fragment;
+import android.content.ContentResolver;
 import android.os.Bundle;
+import android.provider.Settings;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.widget.CheckBox;
@@ -83,6 +88,60 @@
     }
 
     @Test
+    public void testShowWipeEuicc_euiccDisabled() {
+        prepareEuiccState(
+                false /* isEuiccEnabled */, true /* isEuiccProvisioned */,
+                true /* isDevelopmentSettingsEnabled */);
+        assertThat(mMasterClear.showWipeEuicc()).isFalse();
+    }
+
+    @Test
+    public void testShowWipeEuicc_euiccEnabled_unprovisioned() {
+        prepareEuiccState(
+                true /* isEuiccEnabled */, false /* isEuiccProvisioned */,
+                false /* isDevelopmentSettingsEnabled */);
+        assertThat(mMasterClear.showWipeEuicc()).isFalse();
+    }
+
+    @Test
+    public void testShowWipeEuicc_euiccEnabled_provisioned() {
+        prepareEuiccState(
+                true /* isEuiccEnabled */, true /* isEuiccProvisioned */,
+                false /* isDevelopmentSettingsEnabled */);
+        assertThat(mMasterClear.showWipeEuicc()).isTrue();
+    }
+
+    @Test
+    public void testShowWipeEuicc_euiccEnabled_developmentSettingsEnabled() {
+        prepareEuiccState(
+                true /* isEuiccEnabled */, false /* isEuiccProvisioned */,
+                true /* isDevelopmentSettingsEnabled */);
+        assertThat(mMasterClear.showWipeEuicc()).isTrue();
+    }
+
+    @Test
+    public void testShowWipeEuicc_euiccEnabled_provisioned_developmentSettingsEnabled() {
+        prepareEuiccState(
+                true /* isEuiccEnabled */, true /* isEuiccProvisioned */,
+                true /* isDevelopmentSettingsEnabled */);
+        assertThat(mMasterClear.showWipeEuicc()).isTrue();
+    }
+
+    private void prepareEuiccState(
+            boolean isEuiccEnabled,
+            boolean isEuiccProvisioned,
+            boolean isDevelopmentSettingsEnabled) {
+        doReturn(mActivity).when(mMasterClear).getContext();
+        doReturn(isEuiccEnabled).when(mMasterClear).isEuiccEnabled(any());
+        ContentResolver cr = mActivity.getContentResolver();
+        Settings.Global.putInt(
+                cr, android.provider.Settings.Global.EUICC_PROVISIONED, isEuiccProvisioned ? 1 : 0);
+        Settings.Global.putInt(
+                cr, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED,
+                isDevelopmentSettingsEnabled ? 1 : 0);
+    }
+
+    @Test
     public void testShowFinalConfirmation_EraseEsimChecked() {
         ActivityForTest testActivity = new ActivityForTest();
         when(mMasterClear.getActivity()).thenReturn(testActivity);