Merge "Add Thread resource overlay support" into main am: 09494673bc

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2854386

Change-Id: I746998c5e122f7f5e7382cd56399414ba677ecfa
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Zhanglong Xia 2024-01-03 01:14:17 +00:00 • committed by Automerger Merge Worker
commit 6193dd8303
7 changed files with 73 additions and 5 deletions

View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<!-- These resources are around just to allow their values to be customized
for different hardware and product builds for Thread Network. All
configuration names should use the "config_thread" prefix.
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- 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.
-->
<bool name="config_thread_location_use_for_country_code_enabled">true</bool>
</resources>

View file

@ -43,6 +43,9 @@
<item type="string" name="config_ethernet_iface_regex"/>
<item type="integer" name="config_validationFailureAfterRoamIgnoreTimeMillis" />
<item type="integer" name="config_netstats_validate_import" />
<!-- Configuration values for ThreadNetworkService -->
<item type="bool" name="config_thread_location_use_for_country_code_enabled" />
</policy>
</overlayable>
</resources>

View file

@ -37,6 +37,7 @@ java_library {
"framework-connectivity-t-pre-jarjar",
"framework-location.stubs.module_lib",
"service-connectivity-pre-jarjar",
"ServiceConnectivityResources",
],
static_libs: [
"modules-utils-shell-command-handler",

View file

@ -27,7 +27,9 @@ import android.net.thread.IOperationReceiver;
import android.os.Build;
import android.util.Log;
import com.android.connectivity.resources.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.connectivity.ConnectivityResources;
import java.io.FileDescriptor;
import java.io.PrintWriter;
@ -73,6 +75,7 @@ public class ThreadNetworkCountryCode {
private static final CountryCodeInfo DEFAULT_COUNTRY_CODE_INFO =
new CountryCodeInfo(DEFAULT_COUNTRY_CODE, COUNTRY_CODE_SOURCE_DEFAULT);
private final ConnectivityResources mResources;
private final LocationManager mLocationManager;
@Nullable private final Geocoder mGeocoder;
private final ThreadNetworkControllerService mThreadNetworkControllerService;
@ -123,17 +126,20 @@ public class ThreadNetworkCountryCode {
}
private boolean isLocationUseForCountryCodeEnabled() {
// TODO: b/311324956 read the configuration from the overlay configuration.
return true;
return mResources
.get()
.getBoolean(R.bool.config_thread_location_use_for_country_code_enabled);
}
public ThreadNetworkCountryCode(
LocationManager locationManager,
ThreadNetworkControllerService threadNetworkControllerService,
@Nullable Geocoder geocoder) {
@Nullable Geocoder geocoder,
ConnectivityResources resources) {
mLocationManager = locationManager;
mThreadNetworkControllerService = threadNetworkControllerService;
mGeocoder = geocoder;
mResources = resources;
}
/** Sets up this country code module to listen to location country code changes. */

View file

@ -29,6 +29,7 @@ import android.os.Binder;
import android.os.ParcelFileDescriptor;
import com.android.server.SystemService;
import com.android.server.connectivity.ConnectivityResources;
import java.io.FileDescriptor;
import java.io.PrintWriter;
@ -62,8 +63,10 @@ public class ThreadNetworkService extends IThreadNetworkManager.Stub {
new ThreadNetworkCountryCode(
mContext.getSystemService(LocationManager.class),
mControllerService,
Geocoder.isPresent() ? new Geocoder(mContext) : null);
Geocoder.isPresent() ? new Geocoder(mContext) : null,
new ConnectivityResources(mContext));
mCountryCode.initialize();
mShellCommand = new ThreadNetworkShellCommand(mCountryCode);
}
}

View file

@ -39,12 +39,14 @@ android_test {
"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: [

View file

@ -34,9 +34,11 @@ import static org.mockito.Mockito.doAnswer;
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 android.net.thread.IOperationReceiver;
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 @@ public class ThreadNetworkCountryCodeTest {
@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 class ThreadNetworkCountryCodeTest {
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 @@ public class ThreadNetworkCountryCodeTest {
mThreadNetworkCountryCode =
new ThreadNetworkCountryCode(
mLocationManager, mThreadNetworkControllerService, mGeocoder);
mLocationManager,
mThreadNetworkControllerService,
mGeocoder,
mConnectivityResources);
}
private static Address newAddress(String countryCode) {
@ -121,6 +134,17 @@ public class ThreadNetworkCountryCodeTest {
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);
mThreadNetworkCountryCode.initialize();
verifyNoMoreInteractions(mGeocoder);
verifyNoMoreInteractions(mLocationManager);
}
@Test
public void locationCountryCode_locationChanged_locationCountryCodeIsUsed() {
mThreadNetworkCountryCode.initialize();