Add Thread resource overlay support
This CL adds resource overlay support to allow developers to
change the default configuration of using the location country code.
Bug: b/311324956
Test: Set the resource overlay in cuttlefish, check the default
configuration via the command `dumpsys thread_network`.
Change-Id: Ide853975e8244f06a382b2eda4844e030539b95d
diff --git a/thread/tests/unit/Android.bp b/thread/tests/unit/Android.bp
index 74b4a35..c7887bc 100644
--- a/thread/tests/unit/Android.bp
+++ b/thread/tests/unit/Android.bp
@@ -39,12 +39,14 @@
"guava-android-testlib",
"mockito-target-extended-minus-junit4",
"net-tests-utils",
+ "service-connectivity-pre-jarjar",
"service-thread-pre-jarjar",
"truth",
],
libs: [
"android.test.base",
"android.test.runner",
+ "ServiceConnectivityResources",
],
jarjar_rules: ":connectivity-jarjar-rules",
jni_libs: [
diff --git a/thread/tests/unit/src/com/android/server/thread/ThreadNetworkCountryCodeTest.java b/thread/tests/unit/src/com/android/server/thread/ThreadNetworkCountryCodeTest.java
index f51aa0a..a0eff6c 100644
--- a/thread/tests/unit/src/com/android/server/thread/ThreadNetworkCountryCodeTest.java
+++ b/thread/tests/unit/src/com/android/server/thread/ThreadNetworkCountryCodeTest.java
@@ -34,9 +34,11 @@
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import android.content.pm.PackageManager;
+import android.content.res.Resources;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
@@ -47,6 +49,9 @@
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
+import com.android.connectivity.resources.R;
+import com.android.server.connectivity.ConnectivityResources;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -71,6 +76,8 @@
@Mock ThreadNetworkControllerService mThreadNetworkControllerService;
@Mock PackageManager mPackageManager;
@Mock Location mLocation;
+ @Mock Resources mResources;
+ @Mock ConnectivityResources mConnectivityResources;
private ThreadNetworkCountryCode mThreadNetworkCountryCode;
private boolean mErrorSetCountryCode;
@@ -83,6 +90,9 @@
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
+ when(mConnectivityResources.get()).thenReturn(mResources);
+ when(mResources.getBoolean(anyInt())).thenReturn(true);
+
when(mLocation.getLatitude()).thenReturn(0.0);
when(mLocation.getLongitude()).thenReturn(0.0);
@@ -105,7 +115,10 @@
mThreadNetworkCountryCode =
new ThreadNetworkCountryCode(
- mLocationManager, mThreadNetworkControllerService, mGeocoder);
+ mLocationManager,
+ mThreadNetworkControllerService,
+ mGeocoder,
+ mConnectivityResources);
}
private static Address newAddress(String countryCode) {
@@ -122,6 +135,17 @@
}
@Test
+ public void initialize_locationUseIsDisabled_locationFunctionIsNotCalled() {
+ when(mResources.getBoolean(R.bool.config_thread_location_use_for_country_code_enabled))
+ .thenReturn(false);
+
+ mThreadNetworkCountryCode.initialize();
+
+ verifyNoMoreInteractions(mGeocoder);
+ verifyNoMoreInteractions(mLocationManager);
+ }
+
+ @Test
public void locationCountryCode_locationChanged_locationCountryCodeIsUsed() {
mThreadNetworkCountryCode.initialize();