Merge "Add shadow and wrapper classes" into oc-dr1-dev
diff --git a/res/layout/master_clear.xml b/res/layout/master_clear.xml
index 4423e10..ec2aaea 100644
--- a/res/layout/master_clear.xml
+++ b/res/layout/master_clear.xml
@@ -45,6 +45,13 @@
                 android:visibility="gone"
                 android:textSize="18sp"
                 android:text="@string/master_clear_desc_also_erases_external" />
+            <TextView android:id="@+id/also_erases_esim"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:includeFontPadding="false"
+                android:visibility="gone"
+                android:textSize="18sp"
+                android:text="@string/master_clear_desc_also_erases_esim" />
             <TextView android:id="@+id/accounts_label"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
@@ -65,6 +72,12 @@
                 android:visibility="gone"
                 android:textSize="18sp"
                 android:text="@string/master_clear_other_users_present" />
+            <TextView android:id="@+id/no_cancel_mobile_plan"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:visibility="gone"
+                android:textSize="18sp"
+                android:text="@string/master_clear_desc_no_cancel_mobile_plan" />
             <TextView android:id="@+id/erase_external_option_text"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
@@ -102,38 +115,6 @@
                         android:text="@string/erase_external_storage_description" />
                 </LinearLayout>
             </LinearLayout>
-            <LinearLayout android:id="@+id/erase_esim_container"
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    android:orientation="horizontal"
-                    android:focusable="true"
-                    android:clickable="true">
-                <CheckBox android:id="@+id/erase_esim"
-                        android:layout_width="wrap_content"
-                        android:layout_height="wrap_content"
-                        android:layout_gravity="center_vertical"
-                        android:paddingEnd="8dp"
-                        android:focusable="false"
-                        android:clickable="false"
-                        android:duplicateParentState="true" />
-                <LinearLayout android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:layout_gravity="center_vertical"
-                        android:orientation="vertical">
-                    <TextView
-                        android:layout_width="wrap_content"
-                        android:layout_height="wrap_content"
-                        android:paddingTop="12dp"
-                        android:textSize="18sp"
-                        android:text="@string/erase_esim_storage" />
-                    <TextView
-                        android:layout_width="wrap_content"
-                        android:layout_height="wrap_content"
-                        android:paddingTop="4sp"
-                        android:textSize="14sp"
-                        android:text="@string/erase_esim_storage_description" />
-                </LinearLayout>
-            </LinearLayout>
         </LinearLayout>
     </ScrollView>
     <Button
diff --git a/res/values/strings.xml b/res/values/strings.xml
index f629611..aa87101 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -3131,13 +3131,17 @@
     <!-- SD card & phone storage settings screen, message on screen after user selects Factory data reset [CHAR LIMIT=NONE] -->
     <string name="master_clear_desc" product="tablet">"This will erase all data from your tablet\u2019s <b>internal storage</b>, including:\n\n<li>Your Google account</li>\n<li>System and app data and settings</li>\n<li>Downloaded apps</li>"</string>
     <!-- SD card & phone storage settings screen, message on screen after user selects Factory data reset [CHAR LIMIT=NONE] -->
-    <string name="master_clear_desc" product="default">"This will erase all data from your phone\u2019s <b>internal storage</b>, including:\n\n<li>Your Google account</li>\n<li>System and app data and settings</li>\n<li>Downloaded apps"</li></string>
+    <string name="master_clear_desc" product="default">"This will erase all data from your phone\u2019s <b>internal storage</b>, including:\n\n<li>Your Google account</li>\n<li>System and app data and settings</li>\n<li>Downloaded apps</li>"</string>
     <!-- SD card & phone storage settings screen, instructions and list of current accounts.  The list of accounts follows this text[CHAR LIMIT=NONE] -->
     <string name="master_clear_accounts" product="default">"\n\nYou are currently signed into the following accounts:\n"</string>
     <!-- SD card & phone storage settings screen, notification if other users are present on the device [CHAR LIMIT=NONE] -->
     <string name="master_clear_other_users_present" product="default">"\n\nThere are other users present on this device.\n"</string>
     <!-- SD card & phone storage settings screen, list of items in user data storage (USB storage or SD card) that will be erased during this operation [CHAR LIMIT=NONE] -->
     <string name="master_clear_desc_also_erases_external">"<li>Music</li>\n<li>Photos</li>\n<li>Other user data</li>"</string>
+    <!-- SD card & phone storage settings screen, list of items on an eSIM (embedded SIM) that will be erased during this operation [CHAR LIMIT=NONE] -->
+    <string name="master_clear_desc_also_erases_esim">"<li>Carriers on eSIM</li>"</string>
+    <!-- SD card & phone storage settings screen, notification if there are eSIM (embedded SIM) profiles present that the user's mobile service plan will not be canceled [CHAR LIMIT=NONE] -->
+    <string name="master_clear_desc_no_cancel_mobile_plan">"\n\nThis will not cancel your mobile service plan.</string>
     <!-- SD card & phone storage settings screen, instructions about whether to also erase the external storage (SD card) when erasing the internal storage [CHAR LIMIT=NONE] -->
     <string name="master_clear_desc_erase_external_storage" product="nosdcard">"\n\nTo clear music, pictures, and other user data, the <b>USB storage</b> needs to be erased."</string>
     <!-- SD card & phone storage settings screen, instructions about whether to also erase the external storage (SD card) when erasing the internal storage [CHAR LIMIT=NONE] -->
diff --git a/src/com/android/settings/MasterClear.java b/src/com/android/settings/MasterClear.java
index 1bdd6f4..96ce17e 100644
--- a/src/com/android/settings/MasterClear.java
+++ b/src/com/android/settings/MasterClear.java
@@ -81,8 +81,6 @@
     private Button mInitiateButton;
     private View mExternalStorageContainer;
     @VisibleForTesting CheckBox mExternalStorage;
-    private View mEsimStorageContainer;
-    @VisibleForTesting CheckBox mEsimStorage;
     private ScrollView mScrollView;
 
     private final OnGlobalLayoutListener mOnGlobalLayoutListener = new OnGlobalLayoutListener() {
@@ -126,7 +124,8 @@
     void showFinalConfirmation() {
         Bundle args = new Bundle();
         args.putBoolean(ERASE_EXTERNAL_EXTRA, mExternalStorage.isChecked());
-        args.putBoolean(ERASE_ESIMS_EXTRA, mEsimStorage.isChecked());
+        // TODO: Offer the user a choice to wipe eSIMs when it is technically feasible to do so.
+        args.putBoolean(ERASE_ESIMS_EXTRA, true);
         ((SettingsActivity) getActivity()).startPreferencePanel(
                 this, MasterClearConfirm.class.getName(),
                 args, R.string.master_clear_confirm_title, null, null, 0);
@@ -175,8 +174,6 @@
         mInitiateButton.setOnClickListener(mInitiateListener);
         mExternalStorageContainer = mContentView.findViewById(R.id.erase_external_container);
         mExternalStorage = (CheckBox) mContentView.findViewById(R.id.erase_external);
-        mEsimStorageContainer = mContentView.findViewById(R.id.erase_esim_container);
-        mEsimStorage = (CheckBox) mContentView.findViewById(R.id.erase_esim);
         mScrollView = (ScrollView) mContentView.findViewById(R.id.master_clear_scrollview);
 
         /*
@@ -211,15 +208,11 @@
         }
 
         if (showWipeEuicc()) {
-            mEsimStorageContainer.setOnClickListener(new View.OnClickListener() {
+            final View esimAlsoErased = mContentView.findViewById(R.id.also_erases_esim);
+            esimAlsoErased.setVisibility(View.VISIBLE);
 
-                @Override
-                public void onClick(View v) {
-                    mEsimStorage.toggle();
-                }
-            });
-        } else {
-            mEsimStorageContainer.setVisibility(View.GONE);
+            final View noCancelMobilePlan = mContentView.findViewById(R.id.no_cancel_mobile_plan);
+            noCancelMobilePlan.setVisibility(View.VISIBLE);
         }
 
         final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
@@ -245,9 +238,9 @@
     }
 
     /**
-     * Whether to show the checkbox to wipe the eUICC.
+     * Whether to show strings indicating that the eUICC will be wiped.
      *
-     * <p>We show the checkbox on any device which supports eUICC as long as the eUICC was ever
+     * <p>We show the strings on any device which supports eUICC as long as the eUICC was ever
      * provisioned (that is, at least one profile was ever downloaded onto it).
      */
     @VisibleForTesting
diff --git a/src/com/android/settings/datausage/DataUsageSummary.java b/src/com/android/settings/datausage/DataUsageSummary.java
index 5a84d13..417d74b 100644
--- a/src/com/android/settings/datausage/DataUsageSummary.java
+++ b/src/com/android/settings/datausage/DataUsageSummary.java
@@ -72,11 +72,21 @@
     public static final String TEST_RADIOS_PROP = "test.radios";
 
     public static final String KEY_RESTRICT_BACKGROUND = "restrict_background";
-    public static final String KEY_NETWORK_RESTRICTIONS = "network_restrictions";
 
     private static final String KEY_STATUS_HEADER = "status_header";
     private static final String KEY_LIMIT_SUMMARY = "limit_summary";
-    private static final String KEY_WIFI_USAGE_TITLE = "wifi_category";
+
+    // Mobile data keys
+    public static final String KEY_MOBILE_CATEGORY = "mobile_category";
+    public static final String KEY_MOBILE_DATA_USAGE_TOGGLE = "data_usage_enable";
+    public static final String KEY_MOBILE_DATA_USAGE = "cellular_data_usage";
+    public static final String KEY_MOBILE_BILLING_CYCLE = "billing_preference";
+
+    // Wifi keys
+    public static final String KEY_WIFI_USAGE_TITLE = "wifi_category";
+    public static final String KEY_WIFI_DATA_USAGE = "wifi_data_usage";
+    public static final String KEY_NETWORK_RESTRICTIONS = "network_restrictions";
+
 
     private DataUsageController mDataUsageController;
     private DataUsageInfoController mDataInfoController;
@@ -471,16 +481,14 @@
                 resource.xmlResId = R.xml.data_usage;
                 resources.add(resource);
 
-                if (hasMobileData(context)) {
-                    resource = new SearchIndexableResource(context);
-                    resource.xmlResId = R.xml.data_usage_cellular;
-                    resources.add(resource);
-                }
-                if (hasWifiRadio(context)) {
-                    resource = new SearchIndexableResource(context);
-                    resource.xmlResId = R.xml.data_usage_wifi;
-                    resources.add(resource);
-                }
+                resource = new SearchIndexableResource(context);
+                resource.xmlResId = R.xml.data_usage_cellular;
+                resources.add(resource);
+
+                resource = new SearchIndexableResource(context);
+                resource.xmlResId = R.xml.data_usage_wifi;
+                resources.add(resource);
+
                 return resources;
             }
 
@@ -488,12 +496,19 @@
             public List<String> getNonIndexableKeys(Context context) {
                 List<String> keys = super.getNonIndexableKeys(context);
 
-                if (hasMobileData(context)) {
-                    keys.add(KEY_RESTRICT_BACKGROUND);
+                if (!hasMobileData(context)) {
+                    keys.add(KEY_MOBILE_CATEGORY);
+                    keys.add(KEY_MOBILE_DATA_USAGE_TOGGLE);
+                    keys.add(KEY_MOBILE_DATA_USAGE);
+                    keys.add(KEY_MOBILE_BILLING_CYCLE);
                 }
-                if (hasWifiRadio(context)) {
+
+                if (!hasWifiRadio(context)) {
+                    keys.add(KEY_WIFI_DATA_USAGE);
                     keys.add(KEY_NETWORK_RESTRICTIONS);
                 }
+
+                // This title is named Wifi, and will confuse users.
                 keys.add(KEY_WIFI_USAGE_TITLE);
 
                 return keys;
diff --git a/tests/robotests/src/com/android/settings/MasterClearTest.java b/tests/robotests/src/com/android/settings/MasterClearTest.java
index edad391..b501654 100644
--- a/tests/robotests/src/com/android/settings/MasterClearTest.java
+++ b/tests/robotests/src/com/android/settings/MasterClearTest.java
@@ -123,32 +123,6 @@
     }
 
     @Test
-    public void testShowFinalConfirmation_EraseEsimChecked() {
-        ActivityForTest testActivity = new ActivityForTest();
-        when(mMasterClear.getActivity()).thenReturn(testActivity);
-
-        mMasterClear.mEsimStorage = (CheckBox) mContentView.findViewById(R.id.erase_esim);
-        mMasterClear.mExternalStorage = (CheckBox) mContentView.findViewById(R.id.erase_external);
-        mMasterClear.mEsimStorage.setChecked(true);
-        mMasterClear.showFinalConfirmation();
-        assertThat(testActivity.getArgs().getBoolean(MasterClear.ERASE_ESIMS_EXTRA, false))
-                .isTrue();
-    }
-
-    @Test
-    public void testShowFinalConfirmation_EraseEsimUnchecked() {
-        ActivityForTest testActivity = new ActivityForTest();
-        when(mMasterClear.getActivity()).thenReturn(testActivity);
-
-        mMasterClear.mEsimStorage = (CheckBox) mContentView.findViewById(R.id.erase_esim);
-        mMasterClear.mExternalStorage = (CheckBox) mContentView.findViewById(R.id.erase_external);
-        mMasterClear.mEsimStorage.setChecked(false);
-        mMasterClear.showFinalConfirmation();
-        assertThat(testActivity.getArgs().getBoolean(MasterClear.ERASE_ESIMS_EXTRA, true))
-                .isFalse();
-    }
-
-    @Test
     public void testHasReachedBottom_NotScrollDown_returnFalse() {
         initScrollView(100, 0, 200);
 
diff --git a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
index 77e0fe9..e4ad5b5 100644
--- a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
@@ -27,6 +27,7 @@
 import com.android.settings.TestConfig;
 import com.android.settings.testutils.XmlTestUtils;
 import com.android.settings.testutils.shadow.ShadowConnectivityManager;
+import com.android.settings.testutils.shadow.ShadowDataUsageSummary;
 import com.android.settingslib.NetworkPolicyEditor;
 
 import org.junit.Before;
@@ -149,27 +150,50 @@
     }
 
     @Test
+    @Config(shadows = ShadowDataUsageSummary.class)
     public void testNonIndexableKeys_existInXmlLayout() {
         final Context context = RuntimeEnvironment.application;
+        ShadowDataUsageSummary.IS_WIFI_SUPPORTED = true;
+        ShadowDataUsageSummary.IS_MOBILE_DATA_SUPPORTED = true;
         final List<String> niks = DataUsageSummary.SEARCH_INDEX_DATA_PROVIDER
                 .getNonIndexableKeys(context);
         final List<String> keys = new ArrayList<>();
 
         keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context, R.xml.data_usage_wifi));
         keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context, R.xml.data_usage));
+        keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context, R.xml.data_usage_cellular));
 
         assertThat(keys).containsAllIn(niks);
     }
 
     @Test
-    @Config(shadows = ShadowConnectivityManager.class)
-    public void testNonIndexableKeys_hasMobileData_restrictedAccessesAdded() {
-        ShadowConnectivityManager.setIsNetworkSupported(true);
+    @Config(shadows = ShadowDataUsageSummary.class)
+    public void testNonIndexableKeys_hasMobileData_hasWifi_allNonIndexableKeysAdded() {
+        ShadowDataUsageSummary.IS_WIFI_SUPPORTED = false;
+        ShadowDataUsageSummary.IS_MOBILE_DATA_SUPPORTED = false;
         List<String> keys = DataUsageSummary.SEARCH_INDEX_DATA_PROVIDER
                 .getNonIndexableKeys(mContext);
 
-        assertThat(keys).contains(DataUsageSummary.KEY_RESTRICT_BACKGROUND);
+        // Mobile data keys
+        assertThat(keys).contains(DataUsageSummary.KEY_MOBILE_CATEGORY);
+        assertThat(keys).contains(DataUsageSummary.KEY_MOBILE_DATA_USAGE_TOGGLE);
+        assertThat(keys).contains(DataUsageSummary.KEY_MOBILE_DATA_USAGE);
+        assertThat(keys).contains(DataUsageSummary.KEY_MOBILE_BILLING_CYCLE);
+
+        // Wifi keys
+        assertThat(keys).contains(DataUsageSummary.KEY_WIFI_DATA_USAGE);
         assertThat(keys).contains(DataUsageSummary.KEY_NETWORK_RESTRICTIONS);
-        ShadowConnectivityManager.setIsNetworkSupported(false);
+        assertThat(keys).contains(DataUsageSummary.KEY_WIFI_USAGE_TITLE);
+    }
+
+    @Test
+    @Config(shadows = ShadowDataUsageSummary.class)
+    public void testNonIndexableKeys_noMobile_noWifi_limitedNonIndexableKeys() {
+        ShadowDataUsageSummary.IS_WIFI_SUPPORTED = true;
+        ShadowDataUsageSummary.IS_MOBILE_DATA_SUPPORTED = true;
+        List<String> keys = DataUsageSummary.SEARCH_INDEX_DATA_PROVIDER
+                .getNonIndexableKeys(mContext);
+
+        assertThat(keys).containsExactly(DataUsageSummary.KEY_WIFI_USAGE_TITLE);
     }
 }
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowDataUsageSummary.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowDataUsageSummary.java
new file mode 100644
index 0000000..c5fc601
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowDataUsageSummary.java
@@ -0,0 +1,24 @@
+package com.android.settings.testutils.shadow;
+
+import android.content.Context;
+
+import com.android.settings.datausage.DataUsageSummary;
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+
+@Implements(DataUsageSummary.class)
+public class ShadowDataUsageSummary {
+
+    public static boolean IS_MOBILE_DATA_SUPPORTED = true;
+    public static boolean IS_WIFI_SUPPORTED = true;
+
+    @Implementation
+    public static boolean hasMobileData(Context context) {
+        return IS_MOBILE_DATA_SUPPORTED;
+    }
+
+    @Implementation
+    public static boolean hasWifiRadio(Context context) {
+        return IS_WIFI_SUPPORTED;
+    }
+}