Merge "Import translations. DO NOT MERGE ANYWHERE" into 24D1-dev
diff --git a/src/com/android/settings/RegulatoryInfoDisplayActivity.kt b/src/com/android/settings/RegulatoryInfoDisplayActivity.kt
index fdf66c3..6b5ccc7 100644
--- a/src/com/android/settings/RegulatoryInfoDisplayActivity.kt
+++ b/src/com/android/settings/RegulatoryInfoDisplayActivity.kt
@@ -23,6 +23,7 @@
 import android.widget.TextView
 import androidx.appcompat.app.AlertDialog
 import com.android.settings.deviceinfo.regulatory.RegulatoryInfo.getRegulatoryInfo
+import com.android.settings.overlay.FeatureFactory.Companion.featureFactory
 
 /**
  * [Activity] that displays regulatory information for the "Regulatory information"
@@ -53,8 +54,8 @@
             return
         }
 
-        val regulatoryText = resources.getText(R.string.regulatory_info_text)
-        if (regulatoryText.isNotEmpty()) {
+        val regulatoryText = getRegulatoryText()
+        if (!regulatoryText.isNullOrEmpty()) {
             builder.setMessage(regulatoryText)
             val dialog = builder.show()
             // we have to show the dialog first, or the setGravity() call will throw a NPE
@@ -64,4 +65,10 @@
             finish()
         }
     }
+
+    private fun getRegulatoryText(): CharSequence? {
+        val regulatoryInfoText = resources.getText(R.string.regulatory_info_text)
+        if (regulatoryInfoText.isNotBlank()) return regulatoryInfoText
+        return featureFactory.hardwareInfoFeatureProvider?.countryIfOriginLabel
+    }
 }
diff --git a/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoFeatureProvider.kt b/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoFeatureProvider.kt
index 400ece9..e9866d7 100644
--- a/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoFeatureProvider.kt
+++ b/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoFeatureProvider.kt
@@ -23,4 +23,9 @@
      * Returns the manufactured year
      */
     val manufacturedYear: String?
-}
\ No newline at end of file
+
+    /**
+     * The country of origin label.
+     */
+    val countryIfOriginLabel: String
+}
diff --git a/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoFeatureProviderImpl.kt b/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoFeatureProviderImpl.kt
deleted file mode 100644
index 54a112b..0000000
--- a/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoFeatureProviderImpl.kt
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (C) 2023 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.deviceinfo.hardwareinfo
-
-/**
- * Feature provider for hardware info
- */
-object HardwareInfoFeatureProviderImpl : HardwareInfoFeatureProvider {
-    override val manufacturedYear: String?
-        get() = null
-}
\ No newline at end of file
diff --git a/src/com/android/settings/deviceinfo/hardwareinfo/ManufacturedYearPreferenceController.kt b/src/com/android/settings/deviceinfo/hardwareinfo/ManufacturedYearPreferenceController.kt
index 92d7733..9d1a826 100644
--- a/src/com/android/settings/deviceinfo/hardwareinfo/ManufacturedYearPreferenceController.kt
+++ b/src/com/android/settings/deviceinfo/hardwareinfo/ManufacturedYearPreferenceController.kt
@@ -22,7 +22,8 @@
 /** Preference controller for Manufactured Year. */
 class ManufacturedYearPreferenceController(context: Context, preferenceKey: String) :
     BasePreferenceController(context, preferenceKey) {
-    private val year: String? = featureFactory.hardwareInfoFeatureProvider.manufacturedYear
+
+    private val year: String? = featureFactory.hardwareInfoFeatureProvider?.manufacturedYear
 
     override fun getAvailabilityStatus(): Int =
         if (!year.isNullOrEmpty()) AVAILABLE else UNSUPPORTED_ON_DEVICE
diff --git a/src/com/android/settings/deviceinfo/regulatory/RegulatoryInfo.kt b/src/com/android/settings/deviceinfo/regulatory/RegulatoryInfo.kt
index e26e061..2982e47 100644
--- a/src/com/android/settings/deviceinfo/regulatory/RegulatoryInfo.kt
+++ b/src/com/android/settings/deviceinfo/regulatory/RegulatoryInfo.kt
@@ -23,8 +23,7 @@
 import androidx.annotation.DrawableRes
 import androidx.annotation.VisibleForTesting
 import com.android.settings.R
-
-
+import com.android.settings.overlay.FeatureFactory.Companion.featureFactory
 
 /** To load Regulatory Info from device. */
 object RegulatoryInfo {
@@ -38,10 +37,10 @@
 
     /** Gets the regulatory drawable. */
     fun Context.getRegulatoryInfo(): Drawable? {
-        val sku = getSku()
+        val sku = getSku().lowercase()
         if (sku.isNotBlank()) {
             // When hardware coo property exists, use regulatory_info_<sku>_<coo> resource if valid.
-            val coo = getCoo()
+            val coo = getCoo().lowercase()
             if (coo.isNotBlank()) {
                 getRegulatoryInfo("${REGULATORY_INFO_RESOURCE}_${sku}_$coo")?.let { return it }
             }
@@ -51,9 +50,9 @@
         return getRegulatoryInfo(REGULATORY_INFO_RESOURCE)
     }
 
-    private fun getCoo(): String = SystemProperties.get(KEY_COO).lowercase()
+    fun getCoo(): String = SystemProperties.get(KEY_COO)
 
-    private fun getSku(): String = SystemProperties.get(KEY_SKU).lowercase()
+    fun getSku(): String = SystemProperties.get(KEY_SKU)
 
     private fun Context.getRegulatoryInfo(fileName: String): Drawable? {
         val overlayPackageName =
diff --git a/src/com/android/settings/overlay/FeatureFactory.kt b/src/com/android/settings/overlay/FeatureFactory.kt
index 2c4a295..53ad8ba 100644
--- a/src/com/android/settings/overlay/FeatureFactory.kt
+++ b/src/com/android/settings/overlay/FeatureFactory.kt
@@ -68,7 +68,7 @@
     /**
      * Retrieves implementation for Hardware Info feature.
      */
-    abstract val hardwareInfoFeatureProvider: HardwareInfoFeatureProvider
+    open val hardwareInfoFeatureProvider: HardwareInfoFeatureProvider? = null
 
     /** Implementation for [SupportFeatureProvider]. */
     open val supportFeatureProvider: SupportFeatureProvider? = null
diff --git a/src/com/android/settings/overlay/FeatureFactoryImpl.kt b/src/com/android/settings/overlay/FeatureFactoryImpl.kt
index e1519b3..1770209 100644
--- a/src/com/android/settings/overlay/FeatureFactoryImpl.kt
+++ b/src/com/android/settings/overlay/FeatureFactoryImpl.kt
@@ -45,8 +45,6 @@
 import com.android.settings.dashboard.DashboardFeatureProviderImpl
 import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider
 import com.android.settings.dashboard.suggestions.SuggestionFeatureProviderImpl
-import com.android.settings.deviceinfo.hardwareinfo.HardwareInfoFeatureProvider
-import com.android.settings.deviceinfo.hardwareinfo.HardwareInfoFeatureProviderImpl
 import com.android.settings.display.DisplayFeatureProvider
 import com.android.settings.display.DisplayFeatureProviderImpl
 import com.android.settings.enterprise.EnterprisePrivacyFeatureProviderImpl
@@ -81,9 +79,6 @@
         ContextualCardFeatureProviderImpl(appContext)
     }
 
-    override val hardwareInfoFeatureProvider: HardwareInfoFeatureProvider =
-        HardwareInfoFeatureProviderImpl
-
     override val metricsFeatureProvider by lazy { SettingsMetricsFeatureProvider() }
 
     override val powerUsageFeatureProvider by lazy { PowerUsageFeatureProviderImpl(appContext) }
diff --git a/tests/robotests/testutils/com/android/settings/testutils/FakeFeatureFactory.java b/tests/robotests/testutils/com/android/settings/testutils/FakeFeatureFactory.java
index f49cc68..38683d0 100644
--- a/tests/robotests/testutils/com/android/settings/testutils/FakeFeatureFactory.java
+++ b/tests/robotests/testutils/com/android/settings/testutils/FakeFeatureFactory.java
@@ -32,8 +32,6 @@
 import com.android.settings.connecteddevice.stylus.StylusFeatureProvider;
 import com.android.settings.dashboard.DashboardFeatureProvider;
 import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
-import com.android.settings.deviceinfo.hardwareinfo.HardwareInfoFeatureProvider;
-import com.android.settings.deviceinfo.hardwareinfo.HardwareInfoFeatureProviderImpl;
 import com.android.settings.display.DisplayFeatureProvider;
 import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
 import com.android.settings.fuelgauge.BatterySettingsFeatureProvider;
@@ -299,11 +297,6 @@
     }
 
     @Override
-    public HardwareInfoFeatureProvider getHardwareInfoFeatureProvider() {
-        return HardwareInfoFeatureProviderImpl.INSTANCE;
-    }
-
-    @Override
     public AdvancedVpnFeatureProvider getAdvancedVpnFeatureProvider() {
         return mAdvancedVpnFeatureProvider;
     }
diff --git a/tests/spa_unit/src/com/android/settings/deviceinfo/regulatory/RegulatoryInfoTest.kt b/tests/spa_unit/src/com/android/settings/deviceinfo/regulatory/RegulatoryInfoTest.kt
index f1e18fc..7486e78 100644
--- a/tests/spa_unit/src/com/android/settings/deviceinfo/regulatory/RegulatoryInfoTest.kt
+++ b/tests/spa_unit/src/com/android/settings/deviceinfo/regulatory/RegulatoryInfoTest.kt
@@ -35,14 +35,12 @@
 import org.junit.Test
 import org.junit.runner.RunWith
 import org.mockito.MockitoSession
-import org.mockito.Spy
 import org.mockito.quality.Strictness
 
 @RunWith(AndroidJUnit4::class)
 class RegulatoryInfoTest {
     private lateinit var mockSession: MockitoSession
 
-    @Spy
     private val context: Context = ApplicationProvider.getApplicationContext()
 
     @Before
@@ -98,8 +96,31 @@
         assertDrawableSameAs(regulatoryInfo, R.drawable.regulatory_info_sku)
     }
 
+    @Test
+    fun getCoo() {
+        doReturn(COO).`when` { SystemProperties.get(KEY_COO) }
+
+        val coo = RegulatoryInfo.getCoo()
+
+        assertThat(coo).isEqualTo(COO)
+    }
+
+    @Test
+    fun getSku() {
+        doReturn(SKU).`when` { SystemProperties.get(KEY_SKU) }
+
+        val coo = RegulatoryInfo.getSku()
+
+        assertThat(coo).isEqualTo(SKU)
+    }
+
     private fun assertDrawableSameAs(drawable: Drawable?, @DrawableRes resId: Int) {
         val expected = context.getDrawable(resId)!!.toBitmap()
         assertThat(drawable!!.toBitmap().sameAs(expected)).isTrue()
     }
+
+    private companion object {
+        const val SKU = "ABC"
+        const val COO = "CN"
+    }
 }
diff --git a/tests/unit/src/com/android/settings/testutils/FakeFeatureFactory.java b/tests/unit/src/com/android/settings/testutils/FakeFeatureFactory.java
index 4f17a3a..29758de 100644
--- a/tests/unit/src/com/android/settings/testutils/FakeFeatureFactory.java
+++ b/tests/unit/src/com/android/settings/testutils/FakeFeatureFactory.java
@@ -32,8 +32,6 @@
 import com.android.settings.connecteddevice.stylus.StylusFeatureProvider;
 import com.android.settings.dashboard.DashboardFeatureProvider;
 import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
-import com.android.settings.deviceinfo.hardwareinfo.HardwareInfoFeatureProvider;
-import com.android.settings.deviceinfo.hardwareinfo.HardwareInfoFeatureProviderImpl;
 import com.android.settings.display.DisplayFeatureProvider;
 import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
 import com.android.settings.fuelgauge.BatterySettingsFeatureProvider;
@@ -300,11 +298,6 @@
     }
 
     @Override
-    public HardwareInfoFeatureProvider getHardwareInfoFeatureProvider() {
-        return HardwareInfoFeatureProviderImpl.INSTANCE;
-    }
-
-    @Override
     public AdvancedVpnFeatureProvider getAdvancedVpnFeatureProvider() {
         return mAdvancedVpnFeatureProvider;
     }