Merge "[Regulatory Labels] Load labels from overlays" into udc-d1-dev

This commit is contained in:
Chaohui Wang
2023-07-11 07:50:49 +00:00
committed by Android (Google) Code Review
13 changed files with 312 additions and 254 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 159 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 159 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 159 B

View File

@@ -1,83 +0,0 @@
/*
* 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());
}
}

View File

@@ -0,0 +1,20 @@
<!--
~ 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.
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ff0000"/>
<size android:width="24dp" android:height="24dp" />
</shape>

View File

@@ -0,0 +1,21 @@
<!--
~ 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.
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#00ff00"/>
<size android:width="24dp" android:height="24dp" />
</shape>

View File

@@ -0,0 +1,20 @@
<!--
~ 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.
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#0000ff"/>
<size android:width="24dp" android:height="24dp" />
</shape>

View File

@@ -0,0 +1,105 @@
/*
* 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.regulatory
import android.content.Context
import android.graphics.drawable.Drawable
import android.os.SystemProperties
import androidx.annotation.DrawableRes
import androidx.core.graphics.drawable.toBitmap
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.android.dx.mockito.inline.extended.ExtendedMockito
import com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn
import com.android.settings.deviceinfo.regulatory.RegulatoryInfo.KEY_COO
import com.android.settings.deviceinfo.regulatory.RegulatoryInfo.KEY_SKU
import com.android.settings.deviceinfo.regulatory.RegulatoryInfo.getRegulatoryInfo
import com.android.settings.tests.spa_unit.R
import com.google.common.truth.Truth.assertThat
import org.junit.After
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
fun setUp() {
mockSession = ExtendedMockito.mockitoSession()
.initMocks(this)
.mockStatic(SystemProperties::class.java)
.strictness(Strictness.LENIENT)
.startMocking()
}
@After
fun tearDown() {
mockSession.finishMocking()
}
@Test
fun getRegulatoryInfo_noSkuProperty_shouldReturnDefaultLabel() {
doReturn("").`when` { SystemProperties.get(KEY_SKU) }
val regulatoryInfo = context.getRegulatoryInfo()
assertDrawableSameAs(regulatoryInfo, R.drawable.regulatory_info)
}
@Test
fun getResourceId_noCooProperty_shouldReturnSkuLabel() {
doReturn("sku").`when` { SystemProperties.get(KEY_SKU) }
doReturn("").`when` { SystemProperties.get(KEY_COO) }
val regulatoryInfo = context.getRegulatoryInfo()
assertDrawableSameAs(regulatoryInfo, R.drawable.regulatory_info_sku)
}
@Test
fun getResourceId_hasSkuAndCooProperties_shouldReturnCooLabel() {
doReturn("sku1").`when` { SystemProperties.get(KEY_SKU) }
doReturn("coo").`when` { SystemProperties.get(KEY_COO) }
val regulatoryInfo = context.getRegulatoryInfo()
assertDrawableSameAs(regulatoryInfo, R.drawable.regulatory_info_sku1_coo)
}
@Test
fun getResourceId_noCorrespondingCooLabel_shouldReturnSkuLabel() {
doReturn("sku").`when` { SystemProperties.get(KEY_SKU) }
doReturn("unknown").`when` { SystemProperties.get(KEY_COO) }
val regulatoryInfo = context.getRegulatoryInfo()
assertDrawableSameAs(regulatoryInfo, R.drawable.regulatory_info_sku)
}
private fun assertDrawableSameAs(drawable: Drawable?, @DrawableRes resId: Int) {
val expected = context.getDrawable(resId)!!.toBitmap()
assertThat(drawable!!.toBitmap().sameAs(expected)).isTrue()
}
}