Merge "[Thread] add country code overlay to enable/disable setting Thread country code" into main am: adb71602c5 am: 6183394f07
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/3545881
Change-Id: I1823145478473a8daf18f3d5627360898a49b213
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/service/ServiceConnectivityResources/res/values/config_thread.xml b/service/ServiceConnectivityResources/res/values/config_thread.xml
index 128a98f..a458c7f 100644
--- a/service/ServiceConnectivityResources/res/values/config_thread.xml
+++ b/service/ServiceConnectivityResources/res/values/config_thread.xml
@@ -30,6 +30,15 @@
-->
<bool name="config_thread_border_router_default_enabled">false</bool>
+ <!-- Whether to enable or disable setting Thread country code from the telephony, wifi, location,
+ etc. The country code could be used by the Thread co-processor for setting the fixed output
+ power of Thread radio. If the device needs to dynamically change the max output power according
+ to the user scenario to meet the requirement of Specific Absorption Rate (SAR), it should call
+ the API `setChannelMaxPowers()` to change the max output power, and this configuration could be
+ set to false to disable the Thread service from setting the Thread country code.
+ -->
+ <bool name="config_thread_country_code_enabled">true</bool>
+
<!-- Whether to use location APIs in the algorithm to determine country code or not.
If disabled, will use other sources (telephony, wifi, etc) to determine device location for
Thread Network regulatory purposes.
diff --git a/thread/service/java/com/android/server/thread/ThreadNetworkControllerService.java b/thread/service/java/com/android/server/thread/ThreadNetworkControllerService.java
index 7063357..d859fb2 100644
--- a/thread/service/java/com/android/server/thread/ThreadNetworkControllerService.java
+++ b/thread/service/java/com/android/server/thread/ThreadNetworkControllerService.java
@@ -628,12 +628,15 @@
boolean srpServerWaitEnabled = mResources.get().getBoolean(srpServerConfig);
int autoJoinConfig = R.bool.config_thread_border_router_auto_join_enabled;
boolean autoJoinEnabled = mResources.get().getBoolean(autoJoinConfig);
+ boolean countryCodeEnabled =
+ mResources.get().getBoolean(R.bool.config_thread_country_code_enabled);
return new OtDaemonConfiguration.Builder()
.setBorderRouterEnabled(threadConfig.isBorderRouterEnabled())
.setNat64Enabled(threadConfig.isNat64Enabled())
.setDhcpv6PdEnabled(threadConfig.isDhcpv6PdEnabled())
.setSrpServerWaitForBorderRoutingEnabled(srpServerWaitEnabled)
.setBorderRouterAutoJoinEnabled(autoJoinEnabled)
+ .setCountryCodeEnabled(countryCodeEnabled)
.build();
}
diff --git a/thread/service/java/com/android/server/thread/ThreadNetworkCountryCode.java b/thread/service/java/com/android/server/thread/ThreadNetworkCountryCode.java
index a96d06e..16196fa 100644
--- a/thread/service/java/com/android/server/thread/ThreadNetworkCountryCode.java
+++ b/thread/service/java/com/android/server/thread/ThreadNetworkCountryCode.java
@@ -17,6 +17,7 @@
package com.android.server.thread;
import static android.net.thread.ThreadNetworkException.ERROR_UNSUPPORTED_FEATURE;
+
import static com.android.server.thread.ThreadPersistentSettings.KEY_COUNTRY_CODE;
import android.annotation.Nullable;
@@ -223,6 +224,10 @@
.getBoolean(R.bool.config_thread_location_use_for_country_code_enabled);
}
+ private boolean isCountryCodeEnabled() {
+ return mResources.get().getBoolean(R.bool.config_thread_country_code_enabled);
+ }
+
public ThreadNetworkCountryCode(
LocationManager locationManager,
ThreadNetworkControllerService threadNetworkControllerService,
@@ -270,6 +275,11 @@
/** Sets up this country code module to listen to location country code changes. */
public synchronized void initialize() {
+ if (!isCountryCodeEnabled()) {
+ LOG.i("Thread country code is disabled");
+ return;
+ }
+
registerGeocoderCountryCodeCallback();
registerWifiCountryCodeCallback();
registerTelephonyCountryCodeCallback();
@@ -654,6 +664,7 @@
/** Dumps the current state of this ThreadNetworkCountryCode object. */
public synchronized void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
pw.println("---- Dump of ThreadNetworkCountryCode begin ----");
+ pw.println("isCountryCodeEnabled : " + isCountryCodeEnabled());
pw.println("mIsCpSettingCountryCodeSupported: " + mIsCpSettingCountryCodeSupported);
pw.println("mOverrideCountryCodeInfo : " + mOverrideCountryCodeInfo);
pw.println("mTelephonyCountryCodeSlotInfoMap: " + mTelephonyCountryCodeSlotInfoMap);
diff --git a/thread/tests/unit/src/com/android/server/thread/ThreadNetworkControllerServiceTest.java b/thread/tests/unit/src/com/android/server/thread/ThreadNetworkControllerServiceTest.java
index 95ebda5..63d6130 100644
--- a/thread/tests/unit/src/com/android/server/thread/ThreadNetworkControllerServiceTest.java
+++ b/thread/tests/unit/src/com/android/server/thread/ThreadNetworkControllerServiceTest.java
@@ -261,6 +261,7 @@
.thenReturn(TEST_MODEL_NAME);
when(mResources.getStringArray(eq(R.array.config_thread_mdns_vendor_specific_txts)))
.thenReturn(new String[] {});
+ when(mResources.getBoolean(eq(R.bool.config_thread_country_code_enabled))).thenReturn(true);
final AtomicFile storageFile = new AtomicFile(tempFolder.newFile("thread_settings.xml"));
mPersistentSettings = new ThreadPersistentSettings(storageFile, mConnectivityResources);
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 6eb9b50..1a6b3cc 100644
--- a/thread/tests/unit/src/com/android/server/thread/ThreadNetworkCountryCodeTest.java
+++ b/thread/tests/unit/src/com/android/server/thread/ThreadNetworkCountryCodeTest.java
@@ -206,6 +206,21 @@
}
@Test
+ public void initialize_countryCodeDisabled_defaultCountryCodeIsUsed() {
+ when(mResources.getBoolean(R.bool.config_thread_country_code_enabled)).thenReturn(false);
+
+ mThreadNetworkCountryCode.initialize();
+
+ verifyNoMoreInteractions(mWifiManager);
+ verifyNoMoreInteractions(mTelephonyManager);
+ verifyNoMoreInteractions(mSubscriptionManager);
+ verifyNoMoreInteractions(mGeocoder);
+ verifyNoMoreInteractions(mLocationManager);
+
+ assertThat(mThreadNetworkCountryCode.getCountryCode()).isEqualTo(DEFAULT_COUNTRY_CODE);
+ }
+
+ @Test
public void initialize_locationUseIsDisabled_locationFunctionIsNotCalled() {
when(mResources.getBoolean(R.bool.config_thread_location_use_for_country_code_enabled))
.thenReturn(false);
@@ -507,6 +522,7 @@
mThreadNetworkCountryCode.dump(new FileDescriptor(), printWriter, null);
String outputString = stringWriter.toString();
+ assertThat(outputString).contains("isCountryCodeEnabled");
assertThat(outputString).contains("mIsCpSettingCountryCodeSupported");
assertThat(outputString).contains("mOverrideCountryCodeInfo");
assertThat(outputString).contains("mTelephonyCountryCodeSlotInfoMap");