Merge "Create a string for private DNS "On"" am: a64f8d9521
am: 903e8dac6c

Change-Id: Id364ce04a54afe3abe8e9b240a6a6ed9864d5681
diff --git a/src/com/android/settings/MasterClear.java b/src/com/android/settings/MasterClear.java
index 14a6aed..0df3984 100644
--- a/src/com/android/settings/MasterClear.java
+++ b/src/com/android/settings/MasterClear.java
@@ -182,8 +182,7 @@
     void showFinalConfirmation() {
         final Bundle args = new Bundle();
         args.putBoolean(ERASE_EXTERNAL_EXTRA, mExternalStorage.isChecked());
-        args.putBoolean(ERASE_ESIMS_EXTRA,
-            mEsimStorageContainer.getVisibility() == View.VISIBLE && mEsimStorage.isChecked());
+        args.putBoolean(ERASE_ESIMS_EXTRA, mEsimStorage.isChecked());
         new SubSettingLauncher(getContext())
                 .setDestination(MasterClearConfirm.class.getName())
                 .setArguments(args)
diff --git a/src/com/android/settings/RegulatoryInfoDisplayActivity.java b/src/com/android/settings/RegulatoryInfoDisplayActivity.java
index 8bc1cef..4c7515d 100644
--- a/src/com/android/settings/RegulatoryInfoDisplayActivity.java
+++ b/src/com/android/settings/RegulatoryInfoDisplayActivity.java
@@ -119,7 +119,8 @@
         }
     }
 
-    private int getResourceId() {
+    @VisibleForTesting
+    int getResourceId() {
         // Use regulatory_info by default.
         int resId = getResources().getIdentifier(
                 REGULATORY_INFO_RESOURCE, "drawable", getPackageName());
@@ -134,6 +135,18 @@
                 resId = id;
             }
         }
+
+        // When hardware coo property exists, use regulatory_info_<sku>_<coo> resource if valid.
+        final String coo = getCoo();
+        if (!TextUtils.isEmpty(coo) && !TextUtils.isEmpty(sku)) {
+            final String regulatory_info_coo_res =
+                    REGULATORY_INFO_RESOURCE + "_" + sku.toLowerCase() + "_" + coo.toLowerCase();
+            final int id = getResources().getIdentifier(
+                    regulatory_info_coo_res, "drawable", getPackageName());
+            if (id != 0) {
+                resId = id;
+            }
+        }
         return resId;
     }
 
@@ -142,13 +155,15 @@
         finish();   // close the activity
     }
 
-    @VisibleForTesting
-    public static String getSku() {
+    private String getCoo() {
+        return SystemProperties.get("ro.boot.hardware.coo", "");
+    }
+
+    private String getSku() {
         return SystemProperties.get("ro.boot.hardware.sku", "");
     }
 
-    @VisibleForTesting
-    public static String getRegulatoryInfoImageFileName() {
+    private String getRegulatoryInfoImageFileName() {
         final String sku = getSku();
         if (TextUtils.isEmpty(sku)) {
             return DEFAULT_REGULATORY_INFO_FILEPATH;
diff --git a/src/com/android/settings/deviceinfo/TopLevelStoragePreferenceController.java b/src/com/android/settings/deviceinfo/TopLevelStoragePreferenceController.java
index c6fc23b..fdc5feb 100644
--- a/src/com/android/settings/deviceinfo/TopLevelStoragePreferenceController.java
+++ b/src/com/android/settings/deviceinfo/TopLevelStoragePreferenceController.java
@@ -20,10 +20,13 @@
 import android.os.storage.StorageManager;
 import android.text.format.Formatter;
 
+import androidx.preference.Preference;
+
 import com.android.settings.R;
 import com.android.settings.core.BasePreferenceController;
 import com.android.settingslib.deviceinfo.PrivateStorageInfo;
 import com.android.settingslib.deviceinfo.StorageManagerVolumeProvider;
+import com.android.settingslib.utils.ThreadUtils;
 
 import java.text.NumberFormat;
 
@@ -44,14 +47,22 @@
     }
 
     @Override
-    public CharSequence getSummary() {
-        // TODO: Register listener.
-        final NumberFormat percentageFormat = NumberFormat.getPercentInstance();
-        final PrivateStorageInfo info = PrivateStorageInfo.getPrivateStorageInfo(
-                mStorageManagerVolumeProvider);
-        double privateUsedBytes = info.totalBytes - info.freeBytes;
-        return mContext.getString(R.string.storage_summary,
-                percentageFormat.format(privateUsedBytes / info.totalBytes),
-                Formatter.formatFileSize(mContext, info.freeBytes));
+    protected void refreshSummary(Preference preference) {
+        if (preference == null) {
+            return;
+        }
+
+        ThreadUtils.postOnBackgroundThread(() -> {
+            final NumberFormat percentageFormat = NumberFormat.getPercentInstance();
+            final PrivateStorageInfo info = PrivateStorageInfo.getPrivateStorageInfo(
+                    mStorageManagerVolumeProvider);
+            final double privateUsedBytes = info.totalBytes - info.freeBytes;
+
+            ThreadUtils.postOnMainThread(() -> {
+                preference.setSummary(mContext.getString(R.string.storage_summary,
+                        percentageFormat.format(privateUsedBytes / info.totalBytes),
+                        Formatter.formatFileSize(mContext, info.freeBytes)));
+            });
+        });
     }
 }
diff --git a/tests/robotests/res/drawable/regulatory_info.png b/tests/robotests/res/drawable/regulatory_info.png
new file mode 100644
index 0000000..65de26c
--- /dev/null
+++ b/tests/robotests/res/drawable/regulatory_info.png
Binary files differ
diff --git a/tests/robotests/res/drawable/regulatory_info_sku.png b/tests/robotests/res/drawable/regulatory_info_sku.png
new file mode 100644
index 0000000..65de26c
--- /dev/null
+++ b/tests/robotests/res/drawable/regulatory_info_sku.png
Binary files differ
diff --git a/tests/robotests/res/drawable/regulatory_info_sku1_coo.png b/tests/robotests/res/drawable/regulatory_info_sku1_coo.png
new file mode 100644
index 0000000..65de26c
--- /dev/null
+++ b/tests/robotests/res/drawable/regulatory_info_sku1_coo.png
Binary files differ
diff --git a/tests/robotests/src/com/android/settings/MasterClearTest.java b/tests/robotests/src/com/android/settings/MasterClearTest.java
index 813e4aa..73adf93 100644
--- a/tests/robotests/src/com/android/settings/MasterClearTest.java
+++ b/tests/robotests/src/com/android/settings/MasterClearTest.java
@@ -163,7 +163,7 @@
         verify(context).startActivity(intent.capture());
         assertThat(intent.getValue().getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS)
             .getBoolean(MasterClear.ERASE_ESIMS_EXTRA, false))
-            .isFalse();
+            .isTrue();
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/RegulatoryInfoDisplayActivityTest.java b/tests/robotests/src/com/android/settings/RegulatoryInfoDisplayActivityTest.java
new file mode 100644
index 0000000..d05d5d7
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/RegulatoryInfoDisplayActivityTest.java
@@ -0,0 +1,83 @@
+/*
+ * 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;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.os.SystemProperties;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.Robolectric;
+import org.robolectric.RobolectricTestRunner;
+
+
+@RunWith(RobolectricTestRunner.class)
+public class RegulatoryInfoDisplayActivityTest {
+
+    private static final String SKU_PROP_KEY = "ro.boot.hardware.sku";
+    private static final String COO_PROP_KEY = "ro.boot.hardware.coo";
+
+    private RegulatoryInfoDisplayActivity mRegulatoryInfoDisplayActivity;
+
+    @Before
+    public void setUp() {
+        mRegulatoryInfoDisplayActivity = Robolectric.buildActivity(
+                RegulatoryInfoDisplayActivity.class).create().get();
+    }
+
+    @Test
+    public void getResourceId_noSkuProperty_shouldReturnDefaultLabel() {
+        SystemProperties.set(SKU_PROP_KEY, "");
+
+        final int expectedResId = getResourceId("regulatory_info");
+        assertThat(mRegulatoryInfoDisplayActivity.getResourceId()).isEqualTo(expectedResId);
+    }
+
+    @Test
+    public void getResourceId_noCooProperty_shouldReturnSkuLabel() {
+        SystemProperties.set(SKU_PROP_KEY, "sku");
+        SystemProperties.set(COO_PROP_KEY, "");
+
+        final int expectedResId = getResourceId("regulatory_info_sku");
+        assertThat(mRegulatoryInfoDisplayActivity.getResourceId()).isEqualTo(expectedResId);
+    }
+
+    @Test
+    public void getResourceId_hasSkuAndCooProperties_shouldReturnCooLabel() {
+        SystemProperties.set(SKU_PROP_KEY, "sku1");
+        SystemProperties.set(COO_PROP_KEY, "coo");
+
+        final int expectedResId = getResourceId("regulatory_info_sku1_coo");
+        assertThat(mRegulatoryInfoDisplayActivity.getResourceId()).isEqualTo(expectedResId);
+    }
+
+    @Test
+    public void getResourceId_noCorrespondingCooLabel_shouldReturnSkuLabel() {
+        SystemProperties.set(SKU_PROP_KEY, "sku");
+        SystemProperties.set(COO_PROP_KEY, "unknown");
+
+        final int expectedResId = getResourceId("regulatory_info_sku");
+        assertThat(mRegulatoryInfoDisplayActivity.getResourceId()).isEqualTo(expectedResId);
+    }
+
+    private int getResourceId(String resourceName) {
+        return mRegulatoryInfoDisplayActivity.getResources().getIdentifier(resourceName, "drawable",
+                mRegulatoryInfoDisplayActivity.getPackageName());
+    }
+}