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
This commit is contained in:
Chaohui Wang
2024-03-15 13:32:23 +08:00
parent bfb4086689
commit 67579d564b
10 changed files with 46 additions and 56 deletions

View File

@@ -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
}
}

View File

@@ -23,4 +23,9 @@ interface HardwareInfoFeatureProvider {
* Returns the manufactured year
*/
val manufacturedYear: String?
}
/**
* The country of origin label.
*/
val countryIfOriginLabel: String
}

View File

@@ -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
}

View File

@@ -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

View File

@@ -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_<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 @@ 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 =

View File

@@ -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

View File

@@ -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) }

View File

@@ -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;

View File

@@ -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"
}
}

View File

@@ -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;