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:
@@ -23,6 +23,7 @@ import android.widget.ImageView
|
|||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import com.android.settings.deviceinfo.regulatory.RegulatoryInfo.getRegulatoryInfo
|
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"
|
* [Activity] that displays regulatory information for the "Regulatory information"
|
||||||
@@ -53,8 +54,8 @@ class RegulatoryInfoDisplayActivity : Activity() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val regulatoryText = resources.getText(R.string.regulatory_info_text)
|
val regulatoryText = getRegulatoryText()
|
||||||
if (regulatoryText.isNotEmpty()) {
|
if (!regulatoryText.isNullOrEmpty()) {
|
||||||
builder.setMessage(regulatoryText)
|
builder.setMessage(regulatoryText)
|
||||||
val dialog = builder.show()
|
val dialog = builder.show()
|
||||||
// we have to show the dialog first, or the setGravity() call will throw a NPE
|
// we have to show the dialog first, or the setGravity() call will throw a NPE
|
||||||
@@ -64,4 +65,10 @@ class RegulatoryInfoDisplayActivity : Activity() {
|
|||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getRegulatoryText(): CharSequence? {
|
||||||
|
val regulatoryInfoText = resources.getText(R.string.regulatory_info_text)
|
||||||
|
if (regulatoryInfoText.isNotBlank()) return regulatoryInfoText
|
||||||
|
return featureFactory.hardwareInfoFeatureProvider?.countryIfOriginLabel
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -23,4 +23,9 @@ interface HardwareInfoFeatureProvider {
|
|||||||
* Returns the manufactured year
|
* Returns the manufactured year
|
||||||
*/
|
*/
|
||||||
val manufacturedYear: String?
|
val manufacturedYear: String?
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The country of origin label.
|
||||||
|
*/
|
||||||
|
val countryIfOriginLabel: String
|
||||||
}
|
}
|
@@ -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
|
|
||||||
}
|
|
@@ -22,7 +22,8 @@ import com.android.settings.overlay.FeatureFactory.Companion.featureFactory
|
|||||||
/** Preference controller for Manufactured Year. */
|
/** Preference controller for Manufactured Year. */
|
||||||
class ManufacturedYearPreferenceController(context: Context, preferenceKey: String) :
|
class ManufacturedYearPreferenceController(context: Context, preferenceKey: String) :
|
||||||
BasePreferenceController(context, preferenceKey) {
|
BasePreferenceController(context, preferenceKey) {
|
||||||
private val year: String? = featureFactory.hardwareInfoFeatureProvider.manufacturedYear
|
|
||||||
|
private val year: String? = featureFactory.hardwareInfoFeatureProvider?.manufacturedYear
|
||||||
|
|
||||||
override fun getAvailabilityStatus(): Int =
|
override fun getAvailabilityStatus(): Int =
|
||||||
if (!year.isNullOrEmpty()) AVAILABLE else UNSUPPORTED_ON_DEVICE
|
if (!year.isNullOrEmpty()) AVAILABLE else UNSUPPORTED_ON_DEVICE
|
||||||
|
@@ -23,8 +23,7 @@ import android.os.SystemProperties
|
|||||||
import androidx.annotation.DrawableRes
|
import androidx.annotation.DrawableRes
|
||||||
import androidx.annotation.VisibleForTesting
|
import androidx.annotation.VisibleForTesting
|
||||||
import com.android.settings.R
|
import com.android.settings.R
|
||||||
|
import com.android.settings.overlay.FeatureFactory.Companion.featureFactory
|
||||||
|
|
||||||
|
|
||||||
/** To load Regulatory Info from device. */
|
/** To load Regulatory Info from device. */
|
||||||
object RegulatoryInfo {
|
object RegulatoryInfo {
|
||||||
@@ -38,10 +37,10 @@ object RegulatoryInfo {
|
|||||||
|
|
||||||
/** Gets the regulatory drawable. */
|
/** Gets the regulatory drawable. */
|
||||||
fun Context.getRegulatoryInfo(): Drawable? {
|
fun Context.getRegulatoryInfo(): Drawable? {
|
||||||
val sku = getSku()
|
val sku = getSku().lowercase()
|
||||||
if (sku.isNotBlank()) {
|
if (sku.isNotBlank()) {
|
||||||
// When hardware coo property exists, use regulatory_info_<sku>_<coo> resource if valid.
|
// When hardware coo property exists, use regulatory_info_<sku>_<coo> resource if valid.
|
||||||
val coo = getCoo()
|
val coo = getCoo().lowercase()
|
||||||
if (coo.isNotBlank()) {
|
if (coo.isNotBlank()) {
|
||||||
getRegulatoryInfo("${REGULATORY_INFO_RESOURCE}_${sku}_$coo")?.let { return it }
|
getRegulatoryInfo("${REGULATORY_INFO_RESOURCE}_${sku}_$coo")?.let { return it }
|
||||||
}
|
}
|
||||||
@@ -51,9 +50,9 @@ object RegulatoryInfo {
|
|||||||
return getRegulatoryInfo(REGULATORY_INFO_RESOURCE)
|
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? {
|
private fun Context.getRegulatoryInfo(fileName: String): Drawable? {
|
||||||
val overlayPackageName =
|
val overlayPackageName =
|
||||||
|
@@ -68,7 +68,7 @@ abstract class FeatureFactory {
|
|||||||
/**
|
/**
|
||||||
* Retrieves implementation for Hardware Info feature.
|
* Retrieves implementation for Hardware Info feature.
|
||||||
*/
|
*/
|
||||||
abstract val hardwareInfoFeatureProvider: HardwareInfoFeatureProvider
|
open val hardwareInfoFeatureProvider: HardwareInfoFeatureProvider? = null
|
||||||
|
|
||||||
/** Implementation for [SupportFeatureProvider]. */
|
/** Implementation for [SupportFeatureProvider]. */
|
||||||
open val supportFeatureProvider: SupportFeatureProvider? = null
|
open val supportFeatureProvider: SupportFeatureProvider? = null
|
||||||
|
@@ -45,8 +45,6 @@ import com.android.settings.core.instrumentation.SettingsMetricsFeatureProvider
|
|||||||
import com.android.settings.dashboard.DashboardFeatureProviderImpl
|
import com.android.settings.dashboard.DashboardFeatureProviderImpl
|
||||||
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider
|
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider
|
||||||
import com.android.settings.dashboard.suggestions.SuggestionFeatureProviderImpl
|
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.DisplayFeatureProvider
|
||||||
import com.android.settings.display.DisplayFeatureProviderImpl
|
import com.android.settings.display.DisplayFeatureProviderImpl
|
||||||
import com.android.settings.enterprise.EnterprisePrivacyFeatureProviderImpl
|
import com.android.settings.enterprise.EnterprisePrivacyFeatureProviderImpl
|
||||||
@@ -81,9 +79,6 @@ open class FeatureFactoryImpl : FeatureFactory() {
|
|||||||
ContextualCardFeatureProviderImpl(appContext)
|
ContextualCardFeatureProviderImpl(appContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val hardwareInfoFeatureProvider: HardwareInfoFeatureProvider =
|
|
||||||
HardwareInfoFeatureProviderImpl
|
|
||||||
|
|
||||||
override val metricsFeatureProvider by lazy { SettingsMetricsFeatureProvider() }
|
override val metricsFeatureProvider by lazy { SettingsMetricsFeatureProvider() }
|
||||||
|
|
||||||
override val powerUsageFeatureProvider by lazy { PowerUsageFeatureProviderImpl(appContext) }
|
override val powerUsageFeatureProvider by lazy { PowerUsageFeatureProviderImpl(appContext) }
|
||||||
|
@@ -32,8 +32,6 @@ import com.android.settings.connecteddevice.fastpair.FastPairFeatureProvider;
|
|||||||
import com.android.settings.connecteddevice.stylus.StylusFeatureProvider;
|
import com.android.settings.connecteddevice.stylus.StylusFeatureProvider;
|
||||||
import com.android.settings.dashboard.DashboardFeatureProvider;
|
import com.android.settings.dashboard.DashboardFeatureProvider;
|
||||||
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
|
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.display.DisplayFeatureProvider;
|
||||||
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
|
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
|
||||||
import com.android.settings.fuelgauge.BatterySettingsFeatureProvider;
|
import com.android.settings.fuelgauge.BatterySettingsFeatureProvider;
|
||||||
@@ -298,11 +296,6 @@ public class FakeFeatureFactory extends FeatureFactory {
|
|||||||
return mAccessibilityMetricsFeatureProvider;
|
return mAccessibilityMetricsFeatureProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public HardwareInfoFeatureProvider getHardwareInfoFeatureProvider() {
|
|
||||||
return HardwareInfoFeatureProviderImpl.INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AdvancedVpnFeatureProvider getAdvancedVpnFeatureProvider() {
|
public AdvancedVpnFeatureProvider getAdvancedVpnFeatureProvider() {
|
||||||
return mAdvancedVpnFeatureProvider;
|
return mAdvancedVpnFeatureProvider;
|
||||||
|
@@ -35,14 +35,12 @@ import org.junit.Before
|
|||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.mockito.MockitoSession
|
import org.mockito.MockitoSession
|
||||||
import org.mockito.Spy
|
|
||||||
import org.mockito.quality.Strictness
|
import org.mockito.quality.Strictness
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4::class)
|
@RunWith(AndroidJUnit4::class)
|
||||||
class RegulatoryInfoTest {
|
class RegulatoryInfoTest {
|
||||||
private lateinit var mockSession: MockitoSession
|
private lateinit var mockSession: MockitoSession
|
||||||
|
|
||||||
@Spy
|
|
||||||
private val context: Context = ApplicationProvider.getApplicationContext()
|
private val context: Context = ApplicationProvider.getApplicationContext()
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@@ -98,8 +96,31 @@ class RegulatoryInfoTest {
|
|||||||
assertDrawableSameAs(regulatoryInfo, R.drawable.regulatory_info_sku)
|
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) {
|
private fun assertDrawableSameAs(drawable: Drawable?, @DrawableRes resId: Int) {
|
||||||
val expected = context.getDrawable(resId)!!.toBitmap()
|
val expected = context.getDrawable(resId)!!.toBitmap()
|
||||||
assertThat(drawable!!.toBitmap().sameAs(expected)).isTrue()
|
assertThat(drawable!!.toBitmap().sameAs(expected)).isTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
const val SKU = "ABC"
|
||||||
|
const val COO = "CN"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -32,8 +32,6 @@ import com.android.settings.connecteddevice.fastpair.FastPairFeatureProvider;
|
|||||||
import com.android.settings.connecteddevice.stylus.StylusFeatureProvider;
|
import com.android.settings.connecteddevice.stylus.StylusFeatureProvider;
|
||||||
import com.android.settings.dashboard.DashboardFeatureProvider;
|
import com.android.settings.dashboard.DashboardFeatureProvider;
|
||||||
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
|
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.display.DisplayFeatureProvider;
|
||||||
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
|
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
|
||||||
import com.android.settings.fuelgauge.BatterySettingsFeatureProvider;
|
import com.android.settings.fuelgauge.BatterySettingsFeatureProvider;
|
||||||
@@ -299,11 +297,6 @@ public class FakeFeatureFactory extends FeatureFactory {
|
|||||||
return mAccessibilityMetricsFeatureProvider;
|
return mAccessibilityMetricsFeatureProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public HardwareInfoFeatureProvider getHardwareInfoFeatureProvider() {
|
|
||||||
return HardwareInfoFeatureProviderImpl.INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AdvancedVpnFeatureProvider getAdvancedVpnFeatureProvider() {
|
public AdvancedVpnFeatureProvider getAdvancedVpnFeatureProvider() {
|
||||||
return mAdvancedVpnFeatureProvider;
|
return mAdvancedVpnFeatureProvider;
|
||||||
|
Reference in New Issue
Block a user