From 67579d564be7af1a9d8213515927049fff595dd5 Mon Sep 17 00:00:00 2001 From: Chaohui Wang Date: Fri, 15 Mar 2024 13:32:23 +0800 Subject: [PATCH] New countryIfOriginLabel And display this label as fallback when Regulatory Image is missing. Bug: 329378943 Test: manual - on SIMs Test: unit test Change-Id: I0b8851da20face9ca444b3e6456a4a662b944b65 Merged-In: I0b8851da20face9ca444b3e6456a4a662b944b65 --- .../settings/RegulatoryInfoDisplayActivity.kt | 11 ++++++-- .../HardwareInfoFeatureProvider.kt | 7 +++++- .../HardwareInfoFeatureProviderImpl.kt | 24 ------------------ .../ManufacturedYearPreferenceController.kt | 3 ++- .../deviceinfo/regulatory/RegulatoryInfo.kt | 11 ++++---- .../settings/overlay/FeatureFactory.kt | 2 +- .../settings/overlay/FeatureFactoryImpl.kt | 5 ---- .../testutils/FakeFeatureFactory.java | 7 ------ .../regulatory/RegulatoryInfoTest.kt | 25 +++++++++++++++++-- .../testutils/FakeFeatureFactory.java | 7 ------ 10 files changed, 46 insertions(+), 56 deletions(-) delete mode 100644 src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoFeatureProviderImpl.kt diff --git a/src/com/android/settings/RegulatoryInfoDisplayActivity.kt b/src/com/android/settings/RegulatoryInfoDisplayActivity.kt index fdf66c36b2b..6b5ccc79047 100644 --- a/src/com/android/settings/RegulatoryInfoDisplayActivity.kt +++ b/src/com/android/settings/RegulatoryInfoDisplayActivity.kt @@ -23,6 +23,7 @@ import android.widget.ImageView 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 @@ class RegulatoryInfoDisplayActivity : Activity() { 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 @@ class RegulatoryInfoDisplayActivity : Activity() { 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 400ece9a217..e9866d73263 100644 --- a/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoFeatureProvider.kt +++ b/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoFeatureProvider.kt @@ -23,4 +23,9 @@ interface HardwareInfoFeatureProvider { * 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 54a112bec35..00000000000 --- 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 92d773363c6..9d1a8269f4a 100644 --- a/src/com/android/settings/deviceinfo/hardwareinfo/ManufacturedYearPreferenceController.kt +++ b/src/com/android/settings/deviceinfo/hardwareinfo/ManufacturedYearPreferenceController.kt @@ -22,7 +22,8 @@ import com.android.settings.overlay.FeatureFactory.Companion.featureFactory /** 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 e26e0610502..2982e4735a1 100644 --- a/src/com/android/settings/deviceinfo/regulatory/RegulatoryInfo.kt +++ b/src/com/android/settings/deviceinfo/regulatory/RegulatoryInfo.kt @@ -23,8 +23,7 @@ import android.os.SystemProperties 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 @@ object RegulatoryInfo { /** 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__ 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 @@ object RegulatoryInfo { 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 2c4a2957422..53ad8ba642e 100644 --- a/src/com/android/settings/overlay/FeatureFactory.kt +++ b/src/com/android/settings/overlay/FeatureFactory.kt @@ -68,7 +68,7 @@ abstract class FeatureFactory { /** * 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 e1519b3af1f..1770209cc86 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.core.instrumentation.SettingsMetricsFeatureProvider 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 @@ open class FeatureFactoryImpl : FeatureFactory() { 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 f49cc6873eb..38683d01ea6 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.fastpair.FastPairFeatureProvider; 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; @@ -298,11 +296,6 @@ public class FakeFeatureFactory extends FeatureFactory { return mAccessibilityMetricsFeatureProvider; } - @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 f1e18fc8023..7486e789479 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.Before 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 @@ class RegulatoryInfoTest { 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 4f17a3acfff..29758de5555 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.fastpair.FastPairFeatureProvider; 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 @@ public class FakeFeatureFactory extends FeatureFactory { return mAccessibilityMetricsFeatureProvider; } - @Override - public HardwareInfoFeatureProvider getHardwareInfoFeatureProvider() { - return HardwareInfoFeatureProviderImpl.INSTANCE; - } - @Override public AdvancedVpnFeatureProvider getAdvancedVpnFeatureProvider() { return mAdvancedVpnFeatureProvider;