[Thread] do not set the country code again if the co-processor doesn't support it

Some the co-processors do not support setting the country code. This
commit enables the CountryCode module doesn't set the country again
after it knows that the co-processor doesn't support setting the
country code.

Bug: b/402276117
Test: atest ThreadNetworkUnitTests:ThreadNetworkCountryCodeTest#setCountryCodeNotSupported_returnUnsupportedFeatureError_countryCodeNotSetAgain

Change-Id: I8ca1f7aed3774a086e114e91d8100fb7fe9e3664
This commit is contained in:
Zhanglong Xia 2025-03-17 15:41:25 +08:00
commit f6187b99c7

View file

@ -17,6 +17,7 @@
package com.android.server.thread;
import static android.net.thread.ThreadNetworkException.ERROR_INTERNAL_ERROR;
import static android.net.thread.ThreadNetworkException.ERROR_UNSUPPORTED_FEATURE;
import static com.android.server.thread.ThreadNetworkCountryCode.DEFAULT_COUNTRY_CODE;
import static com.android.server.thread.ThreadPersistentSettings.KEY_COUNTRY_CODE;
@ -109,6 +110,7 @@ public class ThreadNetworkCountryCodeTest {
private ThreadNetworkCountryCode mThreadNetworkCountryCode;
private boolean mErrorSetCountryCode;
private boolean mErrorUnsupportedFeatureSetCountryCode;
@Captor private ArgumentCaptor<LocationListener> mLocationListenerCaptor;
@Captor private ArgumentCaptor<Geocoder.GeocodeListener> mGeocodeListenerCaptor;
@ -143,6 +145,10 @@ public class ThreadNetworkCountryCodeTest {
if (mErrorSetCountryCode) {
cb.onError(ERROR_INTERNAL_ERROR, new String("Invalid country code"));
} else if (mErrorUnsupportedFeatureSetCountryCode) {
cb.onError(
ERROR_UNSUPPORTED_FEATURE,
new String("Setting country code is not supported"));
} else {
cb.onSuccess();
}
@ -452,6 +458,22 @@ public class ThreadNetworkCountryCodeTest {
assertThat(mThreadNetworkCountryCode.getCountryCode()).isEqualTo(DEFAULT_COUNTRY_CODE);
}
@Test
public void setCountryCodeNotSupported_returnUnsupportedFeatureError_countryCodeNotSetAgain() {
mThreadNetworkCountryCode.initialize();
assertThat(mThreadNetworkCountryCode.getCountryCode()).isEqualTo(DEFAULT_COUNTRY_CODE);
mErrorUnsupportedFeatureSetCountryCode = true;
mThreadNetworkCountryCode.setOverrideCountryCode(TEST_COUNTRY_CODE_CN);
verify(mThreadNetworkControllerService)
.setCountryCode(eq(TEST_COUNTRY_CODE_CN), mOperationReceiverCaptor.capture());
mThreadNetworkCountryCode.setOverrideCountryCode(TEST_COUNTRY_CODE_US);
verifyNoMoreInteractions(mThreadNetworkControllerService);
assertThat(mThreadNetworkCountryCode.getCountryCode()).isEqualTo(DEFAULT_COUNTRY_CODE);
}
@Test
public void settingsCountryCode_settingsCountryCodeIsActive_settingsCountryCodeIsUsed() {
when(mPersistentSettings.get(KEY_COUNTRY_CODE)).thenReturn(TEST_COUNTRY_CODE_CN);
@ -468,6 +490,7 @@ public class ThreadNetworkCountryCodeTest {
mThreadNetworkCountryCode.dump(new FileDescriptor(), printWriter, null);
String outputString = stringWriter.toString();
assertThat(outputString).contains("mIsCpSettingCountryCodeSupported");
assertThat(outputString).contains("mOverrideCountryCodeInfo");
assertThat(outputString).contains("mTelephonyCountryCodeSlotInfoMap");
assertThat(outputString).contains("mTelephonyCountryCodeInfo");