Add a dependency object in TetheringConfiguration
Address a TODO in TetheringConfiguration to use a dependency object instead of static mocking on DeviceConfig. This avoids TetheringConfiguration dependencies on internal implementation of DeviceConfigUtils, unblocking changes in DeviceConfigUtils. Bug: 279108992 Test: atest TetheringTests (cherry picked from https://android-review.googlesource.com/q/commit:6d38c018523688004b3d43e6794bec5eba8aee03) Merged-In: I252eaadff85fa47b894e989b4f2527b00c5dca56 Change-Id: I252eaadff85fa47b894e989b4f2527b00c5dca56
This commit is contained in:
committed by
Cherrypicker Worker
parent
97a5bc6287
commit
fc6693065b
@@ -39,6 +39,8 @@ import android.telephony.SubscriptionManager;
|
|||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.modules.utils.build.SdkLevel;
|
import com.android.modules.utils.build.SdkLevel;
|
||||||
import com.android.net.module.util.DeviceConfigUtils;
|
import com.android.net.module.util.DeviceConfigUtils;
|
||||||
@@ -158,6 +160,8 @@ public class TetheringConfiguration {
|
|||||||
|
|
||||||
public final int activeDataSubId;
|
public final int activeDataSubId;
|
||||||
|
|
||||||
|
private final Dependencies mDeps;
|
||||||
|
|
||||||
private final boolean mEnableLegacyDhcpServer;
|
private final boolean mEnableLegacyDhcpServer;
|
||||||
private final int mOffloadPollInterval;
|
private final int mOffloadPollInterval;
|
||||||
// TODO: Add to TetheringConfigurationParcel if required.
|
// TODO: Add to TetheringConfigurationParcel if required.
|
||||||
@@ -170,7 +174,31 @@ public class TetheringConfiguration {
|
|||||||
private final int mUsbTetheringFunction;
|
private final int mUsbTetheringFunction;
|
||||||
protected final ContentResolver mContentResolver;
|
protected final ContentResolver mContentResolver;
|
||||||
|
|
||||||
public TetheringConfiguration(Context ctx, SharedLog log, int id) {
|
/**
|
||||||
|
* A class wrapping dependencies of {@link TetheringConfiguration}, useful for testing.
|
||||||
|
*/
|
||||||
|
@VisibleForTesting
|
||||||
|
public static class Dependencies {
|
||||||
|
boolean isFeatureEnabled(@NonNull Context context, @NonNull String namespace,
|
||||||
|
@NonNull String name, @NonNull String moduleName, boolean defaultEnabled) {
|
||||||
|
return DeviceConfigUtils.isFeatureEnabled(context, namespace, name,
|
||||||
|
moduleName, defaultEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean getDeviceConfigBoolean(@NonNull String namespace, @NonNull String name,
|
||||||
|
boolean defaultValue) {
|
||||||
|
return DeviceConfig.getBoolean(namespace, name, defaultValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public TetheringConfiguration(@NonNull Context ctx, @NonNull SharedLog log, int id) {
|
||||||
|
this(ctx, log, id, new Dependencies());
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
public TetheringConfiguration(@NonNull Context ctx, @NonNull SharedLog log, int id,
|
||||||
|
@NonNull Dependencies deps) {
|
||||||
|
mDeps = deps;
|
||||||
final SharedLog configLog = log.forSubComponent("config");
|
final SharedLog configLog = log.forSubComponent("config");
|
||||||
|
|
||||||
activeDataSubId = id;
|
activeDataSubId = id;
|
||||||
@@ -583,17 +611,7 @@ public class TetheringConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean getDeviceConfigBoolean(final String name, final boolean defaultValue) {
|
private boolean getDeviceConfigBoolean(final String name, final boolean defaultValue) {
|
||||||
// Due to the limitation of static mock for testing, using #getDeviceConfigProperty instead
|
return mDeps.getDeviceConfigBoolean(NAMESPACE_CONNECTIVITY, name, defaultValue);
|
||||||
// of DeviceConfig#getBoolean. If using #getBoolean here, the test can't know that the
|
|
||||||
// returned boolean value comes from device config or default value (because of null
|
|
||||||
// property string). See the test case testBpfOffload{*} in TetheringConfigurationTest.java.
|
|
||||||
final String value = getDeviceConfigProperty(name);
|
|
||||||
return value != null ? Boolean.parseBoolean(value) : defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
protected String getDeviceConfigProperty(String name) {
|
|
||||||
return DeviceConfig.getProperty(NAMESPACE_CONNECTIVITY, name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -610,10 +628,9 @@ public class TetheringConfiguration {
|
|||||||
return isFeatureEnabled(ctx, NAMESPACE_TETHERING, featureVersionFlag);
|
return isFeatureEnabled(ctx, NAMESPACE_TETHERING, featureVersionFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
private boolean isFeatureEnabled(Context ctx, String namespace, String featureVersionFlag) {
|
||||||
protected boolean isFeatureEnabled(Context ctx, String namespace, String featureVersionFlag) {
|
return mDeps.isFeatureEnabled(ctx, namespace, featureVersionFlag, TETHERING_MODULE_NAME,
|
||||||
return DeviceConfigUtils.isFeatureEnabled(ctx, namespace, featureVersionFlag,
|
false /* defaultEnabled */);
|
||||||
TETHERING_MODULE_NAME, false /* defaultEnabled */);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Resources getResources(Context ctx, int subId) {
|
private Resources getResources(Context ctx, int subId) {
|
||||||
|
|||||||
@@ -19,22 +19,26 @@ package com.android.networkstack.tethering;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.android.net.module.util.SharedLog;
|
import com.android.net.module.util.SharedLog;
|
||||||
|
|
||||||
/** FakeTetheringConfiguration is used to override static method for testing. */
|
/** FakeTetheringConfiguration is used to override static method for testing. */
|
||||||
public class FakeTetheringConfiguration extends TetheringConfiguration {
|
public class FakeTetheringConfiguration extends TetheringConfiguration {
|
||||||
FakeTetheringConfiguration(Context ctx, SharedLog log, int id) {
|
FakeTetheringConfiguration(Context ctx, SharedLog log, int id) {
|
||||||
super(ctx, log, id);
|
super(ctx, log, id, new Dependencies() {
|
||||||
|
@Override
|
||||||
|
boolean isFeatureEnabled(@NonNull Context context, @NonNull String namespace,
|
||||||
|
@NonNull String name, @NonNull String moduleName, boolean defaultEnabled) {
|
||||||
|
return defaultEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getDeviceConfigProperty(final String name) {
|
boolean getDeviceConfigBoolean(@NonNull String namespace, @NonNull String name,
|
||||||
return null;
|
boolean defaultValue) {
|
||||||
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
@Override
|
|
||||||
protected boolean isFeatureEnabled(Context ctx, String namespace, String featureVersionFlag) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -21,14 +21,13 @@ import static android.net.ConnectivityManager.TYPE_MOBILE;
|
|||||||
import static android.net.ConnectivityManager.TYPE_MOBILE_DUN;
|
import static android.net.ConnectivityManager.TYPE_MOBILE_DUN;
|
||||||
import static android.net.ConnectivityManager.TYPE_MOBILE_HIPRI;
|
import static android.net.ConnectivityManager.TYPE_MOBILE_HIPRI;
|
||||||
import static android.net.ConnectivityManager.TYPE_WIFI;
|
import static android.net.ConnectivityManager.TYPE_WIFI;
|
||||||
import static android.provider.DeviceConfig.NAMESPACE_CONNECTIVITY;
|
|
||||||
import static android.telephony.CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL;
|
import static android.telephony.CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL;
|
||||||
import static android.telephony.CarrierConfigManager.KEY_REQUIRE_ENTITLEMENT_CHECKS_BOOL;
|
import static android.telephony.CarrierConfigManager.KEY_REQUIRE_ENTITLEMENT_CHECKS_BOOL;
|
||||||
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||||
|
|
||||||
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
|
|
||||||
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession;
|
|
||||||
import static com.android.networkstack.apishim.ConstantsShim.KEY_CARRIER_SUPPORTS_TETHERING_BOOL;
|
import static com.android.networkstack.apishim.ConstantsShim.KEY_CARRIER_SUPPORTS_TETHERING_BOOL;
|
||||||
|
import static com.android.networkstack.tethering.TetheringConfiguration.OVERRIDE_TETHER_ENABLE_BPF_OFFLOAD;
|
||||||
|
import static com.android.networkstack.tethering.TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER;
|
||||||
import static com.android.networkstack.tethering.TetheringConfiguration.TETHER_FORCE_USB_FUNCTIONS;
|
import static com.android.networkstack.tethering.TetheringConfiguration.TETHER_FORCE_USB_FUNCTIONS;
|
||||||
import static com.android.networkstack.tethering.TetheringConfiguration.TETHER_USB_NCM_FUNCTION;
|
import static com.android.networkstack.tethering.TetheringConfiguration.TETHER_USB_NCM_FUNCTION;
|
||||||
import static com.android.networkstack.tethering.TetheringConfiguration.TETHER_USB_RNDIS_FUNCTION;
|
import static com.android.networkstack.tethering.TetheringConfiguration.TETHER_USB_RNDIS_FUNCTION;
|
||||||
@@ -39,6 +38,7 @@ import static org.junit.Assert.assertFalse;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -49,12 +49,13 @@ import android.content.pm.PackageManager;
|
|||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.PersistableBundle;
|
import android.os.PersistableBundle;
|
||||||
import android.provider.DeviceConfig;
|
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.telephony.CarrierConfigManager;
|
import android.telephony.CarrierConfigManager;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.test.mock.MockContentResolver;
|
import android.test.mock.MockContentResolver;
|
||||||
|
import android.util.ArrayMap;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.test.filters.SmallTest;
|
import androidx.test.filters.SmallTest;
|
||||||
import androidx.test.runner.AndroidJUnit4;
|
import androidx.test.runner.AndroidJUnit4;
|
||||||
|
|
||||||
@@ -73,8 +74,7 @@ import org.junit.Rule;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoSession;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.mockito.quality.Strictness;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@@ -102,13 +102,13 @@ public class TetheringConfigurationTest {
|
|||||||
@Mock private ModuleInfo mMi;
|
@Mock private ModuleInfo mMi;
|
||||||
private Context mMockContext;
|
private Context mMockContext;
|
||||||
private boolean mHasTelephonyManager;
|
private boolean mHasTelephonyManager;
|
||||||
private MockitoSession mMockingSession;
|
|
||||||
private MockContentResolver mContentResolver;
|
private MockContentResolver mContentResolver;
|
||||||
private final PersistableBundle mCarrierConfig = new PersistableBundle();
|
private final PersistableBundle mCarrierConfig = new PersistableBundle();
|
||||||
|
private final MockDependencies mDeps = new MockDependencies();
|
||||||
|
|
||||||
private class MockTetheringConfiguration extends TetheringConfiguration {
|
private class MockTetheringConfiguration extends TetheringConfiguration {
|
||||||
MockTetheringConfiguration(Context ctx, SharedLog log, int id) {
|
MockTetheringConfiguration(Context ctx, SharedLog log, int id) {
|
||||||
super(ctx, log, id);
|
super(ctx, log, id, mDeps);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -151,19 +151,43 @@ public class TetheringConfigurationTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class MockDependencies extends TetheringConfiguration.Dependencies {
|
||||||
|
private ArrayMap<String, Boolean> mMockFlags = new ArrayMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isFeatureEnabled(@NonNull Context context, @NonNull String namespace,
|
||||||
|
@NonNull String name, @NonNull String moduleName, boolean defaultEnabled) {
|
||||||
|
return isMockFlagEnabled(name, defaultEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean getDeviceConfigBoolean(@NonNull String namespace, @NonNull String name,
|
||||||
|
boolean defaultValue) {
|
||||||
|
// Flags should use isFeatureEnabled instead of getBoolean; see comments in
|
||||||
|
// DeviceConfigUtils. getBoolean should only be used for the two legacy flags below.
|
||||||
|
assertTrue(OVERRIDE_TETHER_ENABLE_BPF_OFFLOAD.equals(name)
|
||||||
|
|| TETHER_ENABLE_LEGACY_DHCP_SERVER.equals(name));
|
||||||
|
|
||||||
|
// Use the same mocking strategy as isFeatureEnabled for testing
|
||||||
|
return isMockFlagEnabled(name, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isMockFlagEnabled(@NonNull String name, boolean defaultEnabled) {
|
||||||
|
final Boolean flag = mMockFlags.getOrDefault(name, defaultEnabled);
|
||||||
|
// Value in the map can also be null
|
||||||
|
if (flag != null) return flag;
|
||||||
|
return defaultEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setFeatureEnabled(@NonNull String flag, Boolean enabled) {
|
||||||
|
mMockFlags.put(flag, enabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
// TODO: use a dependencies class instead of mock statics.
|
MockitoAnnotations.initMocks(this);
|
||||||
mMockingSession = mockitoSession()
|
setTetherForceUpstreamAutomaticFlagEnabled(null);
|
||||||
.initMocks(this)
|
|
||||||
.mockStatic(DeviceConfig.class)
|
|
||||||
.strictness(Strictness.WARN)
|
|
||||||
.startMocking();
|
|
||||||
DeviceConfigUtils.resetPackageVersionCacheForTest();
|
|
||||||
doReturn(null).when(
|
|
||||||
() -> DeviceConfig.getProperty(eq(NAMESPACE_CONNECTIVITY),
|
|
||||||
eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER)));
|
|
||||||
setTetherForceUpstreamAutomaticFlagVersion(null);
|
|
||||||
|
|
||||||
final PackageInfo pi = new PackageInfo();
|
final PackageInfo pi = new PackageInfo();
|
||||||
pi.setLongVersionCode(TEST_PACKAGE_VERSION);
|
pi.setLongVersionCode(TEST_PACKAGE_VERSION);
|
||||||
@@ -202,7 +226,6 @@ public class TetheringConfigurationTest {
|
|||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
mMockingSession.finishMocking();
|
|
||||||
DeviceConfigUtils.resetPackageVersionCacheForTest();
|
DeviceConfigUtils.resetPackageVersionCacheForTest();
|
||||||
// Call {@link #clearSettingsProvider()} before and after using FakeSettingsProvider.
|
// Call {@link #clearSettingsProvider()} before and after using FakeSettingsProvider.
|
||||||
FakeSettingsProvider.clearSettingsProvider();
|
FakeSettingsProvider.clearSettingsProvider();
|
||||||
@@ -211,7 +234,7 @@ public class TetheringConfigurationTest {
|
|||||||
private TetheringConfiguration getTetheringConfiguration(int... legacyTetherUpstreamTypes) {
|
private TetheringConfiguration getTetheringConfiguration(int... legacyTetherUpstreamTypes) {
|
||||||
when(mResources.getIntArray(R.array.config_tether_upstream_types)).thenReturn(
|
when(mResources.getIntArray(R.array.config_tether_upstream_types)).thenReturn(
|
||||||
legacyTetherUpstreamTypes);
|
legacyTetherUpstreamTypes);
|
||||||
return new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
return new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID, mDeps);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -297,7 +320,7 @@ public class TetheringConfigurationTest {
|
|||||||
when(mTelephonyManager.isTetheringApnRequired()).thenReturn(false);
|
when(mTelephonyManager.isTetheringApnRequired()).thenReturn(false);
|
||||||
|
|
||||||
final TetheringConfiguration cfg = new TetheringConfiguration(
|
final TetheringConfiguration cfg = new TetheringConfiguration(
|
||||||
mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
mMockContext, mLog, INVALID_SUBSCRIPTION_ID, mDeps);
|
||||||
final Iterator<Integer> upstreamIterator = cfg.preferredUpstreamIfaceTypes.iterator();
|
final Iterator<Integer> upstreamIterator = cfg.preferredUpstreamIfaceTypes.iterator();
|
||||||
assertTrue(upstreamIterator.hasNext());
|
assertTrue(upstreamIterator.hasNext());
|
||||||
assertEquals(TYPE_ETHERNET, upstreamIterator.next().intValue());
|
assertEquals(TYPE_ETHERNET, upstreamIterator.next().intValue());
|
||||||
@@ -320,7 +343,7 @@ public class TetheringConfigurationTest {
|
|||||||
when(mTelephonyManager.isTetheringApnRequired()).thenReturn(false);
|
when(mTelephonyManager.isTetheringApnRequired()).thenReturn(false);
|
||||||
|
|
||||||
final TetheringConfiguration cfg = new TetheringConfiguration(
|
final TetheringConfiguration cfg = new TetheringConfiguration(
|
||||||
mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
mMockContext, mLog, INVALID_SUBSCRIPTION_ID, mDeps);
|
||||||
final Iterator<Integer> upstreamIterator = cfg.preferredUpstreamIfaceTypes.iterator();
|
final Iterator<Integer> upstreamIterator = cfg.preferredUpstreamIfaceTypes.iterator();
|
||||||
assertTrue(upstreamIterator.hasNext());
|
assertTrue(upstreamIterator.hasNext());
|
||||||
assertEquals(TYPE_ETHERNET, upstreamIterator.next().intValue());
|
assertEquals(TYPE_ETHERNET, upstreamIterator.next().intValue());
|
||||||
@@ -338,7 +361,7 @@ public class TetheringConfigurationTest {
|
|||||||
when(mTelephonyManager.isTetheringApnRequired()).thenReturn(false);
|
when(mTelephonyManager.isTetheringApnRequired()).thenReturn(false);
|
||||||
|
|
||||||
final TetheringConfiguration cfg = new TetheringConfiguration(
|
final TetheringConfiguration cfg = new TetheringConfiguration(
|
||||||
mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
mMockContext, mLog, INVALID_SUBSCRIPTION_ID, mDeps);
|
||||||
final Iterator<Integer> upstreamIterator = cfg.preferredUpstreamIfaceTypes.iterator();
|
final Iterator<Integer> upstreamIterator = cfg.preferredUpstreamIfaceTypes.iterator();
|
||||||
assertTrue(upstreamIterator.hasNext());
|
assertTrue(upstreamIterator.hasNext());
|
||||||
assertEquals(TYPE_WIFI, upstreamIterator.next().intValue());
|
assertEquals(TYPE_WIFI, upstreamIterator.next().intValue());
|
||||||
@@ -350,27 +373,26 @@ public class TetheringConfigurationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initializeBpfOffloadConfiguration(
|
private void initializeBpfOffloadConfiguration(
|
||||||
final boolean fromRes, final String fromDevConfig) {
|
final boolean fromRes, final Boolean fromDevConfig) {
|
||||||
when(mResources.getBoolean(R.bool.config_tether_enable_bpf_offload)).thenReturn(fromRes);
|
when(mResources.getBoolean(R.bool.config_tether_enable_bpf_offload)).thenReturn(fromRes);
|
||||||
doReturn(fromDevConfig).when(
|
mDeps.setFeatureEnabled(
|
||||||
() -> DeviceConfig.getProperty(eq(NAMESPACE_CONNECTIVITY),
|
TetheringConfiguration.OVERRIDE_TETHER_ENABLE_BPF_OFFLOAD, fromDevConfig);
|
||||||
eq(TetheringConfiguration.OVERRIDE_TETHER_ENABLE_BPF_OFFLOAD)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBpfOffloadEnabledByResource() {
|
public void testBpfOffloadEnabledByResource() {
|
||||||
initializeBpfOffloadConfiguration(true, null /* unset */);
|
initializeBpfOffloadConfiguration(true, null /* unset */);
|
||||||
final TetheringConfiguration enableByRes =
|
final TetheringConfiguration enableByRes =
|
||||||
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID, mDeps);
|
||||||
assertTrue(enableByRes.isBpfOffloadEnabled());
|
assertTrue(enableByRes.isBpfOffloadEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBpfOffloadEnabledByDeviceConfigOverride() {
|
public void testBpfOffloadEnabledByDeviceConfigOverride() {
|
||||||
for (boolean res : new boolean[]{true, false}) {
|
for (boolean res : new boolean[]{true, false}) {
|
||||||
initializeBpfOffloadConfiguration(res, "true");
|
initializeBpfOffloadConfiguration(res, true);
|
||||||
final TetheringConfiguration enableByDevConOverride =
|
final TetheringConfiguration enableByDevConOverride =
|
||||||
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID, mDeps);
|
||||||
assertTrue(enableByDevConOverride.isBpfOffloadEnabled());
|
assertTrue(enableByDevConOverride.isBpfOffloadEnabled());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -379,16 +401,16 @@ public class TetheringConfigurationTest {
|
|||||||
public void testBpfOffloadDisabledByResource() {
|
public void testBpfOffloadDisabledByResource() {
|
||||||
initializeBpfOffloadConfiguration(false, null /* unset */);
|
initializeBpfOffloadConfiguration(false, null /* unset */);
|
||||||
final TetheringConfiguration disableByRes =
|
final TetheringConfiguration disableByRes =
|
||||||
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID, mDeps);
|
||||||
assertFalse(disableByRes.isBpfOffloadEnabled());
|
assertFalse(disableByRes.isBpfOffloadEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBpfOffloadDisabledByDeviceConfigOverride() {
|
public void testBpfOffloadDisabledByDeviceConfigOverride() {
|
||||||
for (boolean res : new boolean[]{true, false}) {
|
for (boolean res : new boolean[]{true, false}) {
|
||||||
initializeBpfOffloadConfiguration(res, "false");
|
initializeBpfOffloadConfiguration(res, false);
|
||||||
final TetheringConfiguration disableByDevConOverride =
|
final TetheringConfiguration disableByDevConOverride =
|
||||||
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID, mDeps);
|
||||||
assertFalse(disableByDevConOverride.isBpfOffloadEnabled());
|
assertFalse(disableByDevConOverride.isBpfOffloadEnabled());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -397,22 +419,18 @@ public class TetheringConfigurationTest {
|
|||||||
public void testNewDhcpServerDisabled() {
|
public void testNewDhcpServerDisabled() {
|
||||||
when(mResources.getBoolean(R.bool.config_tether_enable_legacy_dhcp_server)).thenReturn(
|
when(mResources.getBoolean(R.bool.config_tether_enable_legacy_dhcp_server)).thenReturn(
|
||||||
true);
|
true);
|
||||||
doReturn("false").when(
|
mDeps.setFeatureEnabled(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER, false);
|
||||||
() -> DeviceConfig.getProperty(eq(NAMESPACE_CONNECTIVITY),
|
|
||||||
eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER)));
|
|
||||||
|
|
||||||
final TetheringConfiguration enableByRes =
|
final TetheringConfiguration enableByRes =
|
||||||
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID, mDeps);
|
||||||
assertTrue(enableByRes.useLegacyDhcpServer());
|
assertTrue(enableByRes.useLegacyDhcpServer());
|
||||||
|
|
||||||
when(mResources.getBoolean(R.bool.config_tether_enable_legacy_dhcp_server)).thenReturn(
|
when(mResources.getBoolean(R.bool.config_tether_enable_legacy_dhcp_server)).thenReturn(
|
||||||
false);
|
false);
|
||||||
doReturn("true").when(
|
mDeps.setFeatureEnabled(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER, true);
|
||||||
() -> DeviceConfig.getProperty(eq(NAMESPACE_CONNECTIVITY),
|
|
||||||
eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER)));
|
|
||||||
|
|
||||||
final TetheringConfiguration enableByDevConfig =
|
final TetheringConfiguration enableByDevConfig =
|
||||||
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID, mDeps);
|
||||||
assertTrue(enableByDevConfig.useLegacyDhcpServer());
|
assertTrue(enableByDevConfig.useLegacyDhcpServer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -420,12 +438,10 @@ public class TetheringConfigurationTest {
|
|||||||
public void testNewDhcpServerEnabled() {
|
public void testNewDhcpServerEnabled() {
|
||||||
when(mResources.getBoolean(R.bool.config_tether_enable_legacy_dhcp_server)).thenReturn(
|
when(mResources.getBoolean(R.bool.config_tether_enable_legacy_dhcp_server)).thenReturn(
|
||||||
false);
|
false);
|
||||||
doReturn("false").when(
|
mDeps.setFeatureEnabled(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER, false);
|
||||||
() -> DeviceConfig.getProperty(eq(NAMESPACE_CONNECTIVITY),
|
|
||||||
eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER)));
|
|
||||||
|
|
||||||
final TetheringConfiguration cfg =
|
final TetheringConfiguration cfg =
|
||||||
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID, mDeps);
|
||||||
|
|
||||||
assertFalse(cfg.useLegacyDhcpServer());
|
assertFalse(cfg.useLegacyDhcpServer());
|
||||||
}
|
}
|
||||||
@@ -433,7 +449,7 @@ public class TetheringConfigurationTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testOffloadIntervalByResource() {
|
public void testOffloadIntervalByResource() {
|
||||||
final TetheringConfiguration intervalByDefault =
|
final TetheringConfiguration intervalByDefault =
|
||||||
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID, mDeps);
|
||||||
assertEquals(TetheringConfiguration.DEFAULT_TETHER_OFFLOAD_POLL_INTERVAL_MS,
|
assertEquals(TetheringConfiguration.DEFAULT_TETHER_OFFLOAD_POLL_INTERVAL_MS,
|
||||||
intervalByDefault.getOffloadPollInterval());
|
intervalByDefault.getOffloadPollInterval());
|
||||||
|
|
||||||
@@ -442,7 +458,7 @@ public class TetheringConfigurationTest {
|
|||||||
when(mResources.getInteger(R.integer.config_tether_offload_poll_interval)).thenReturn(
|
when(mResources.getInteger(R.integer.config_tether_offload_poll_interval)).thenReturn(
|
||||||
override);
|
override);
|
||||||
final TetheringConfiguration overrideByRes =
|
final TetheringConfiguration overrideByRes =
|
||||||
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID, mDeps);
|
||||||
assertEquals(override, overrideByRes.getOffloadPollInterval());
|
assertEquals(override, overrideByRes.getOffloadPollInterval());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -451,7 +467,7 @@ public class TetheringConfigurationTest {
|
|||||||
public void testGetResourcesBySubId() {
|
public void testGetResourcesBySubId() {
|
||||||
setUpResourceForSubId();
|
setUpResourceForSubId();
|
||||||
final TetheringConfiguration cfg = new TetheringConfiguration(
|
final TetheringConfiguration cfg = new TetheringConfiguration(
|
||||||
mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
mMockContext, mLog, INVALID_SUBSCRIPTION_ID, mDeps);
|
||||||
assertTrue(cfg.provisioningApp.length == 0);
|
assertTrue(cfg.provisioningApp.length == 0);
|
||||||
final int anyValidSubId = 1;
|
final int anyValidSubId = 1;
|
||||||
final MockTetheringConfiguration mockCfg =
|
final MockTetheringConfiguration mockCfg =
|
||||||
@@ -493,7 +509,7 @@ public class TetheringConfigurationTest {
|
|||||||
mockService(Context.CARRIER_CONFIG_SERVICE,
|
mockService(Context.CARRIER_CONFIG_SERVICE,
|
||||||
CarrierConfigManager.class, null);
|
CarrierConfigManager.class, null);
|
||||||
final TetheringConfiguration cfg = new TetheringConfiguration(
|
final TetheringConfiguration cfg = new TetheringConfiguration(
|
||||||
mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
mMockContext, mLog, INVALID_SUBSCRIPTION_ID, mDeps);
|
||||||
|
|
||||||
assertTrue(cfg.isCarrierSupportTethering);
|
assertTrue(cfg.isCarrierSupportTethering);
|
||||||
assertTrue(cfg.isCarrierConfigAffirmsEntitlementCheckRequired);
|
assertTrue(cfg.isCarrierConfigAffirmsEntitlementCheckRequired);
|
||||||
@@ -506,7 +522,7 @@ public class TetheringConfigurationTest {
|
|||||||
CarrierConfigManager.class, mCarrierConfigManager);
|
CarrierConfigManager.class, mCarrierConfigManager);
|
||||||
when(mCarrierConfigManager.getConfigForSubId(anyInt())).thenReturn(null);
|
when(mCarrierConfigManager.getConfigForSubId(anyInt())).thenReturn(null);
|
||||||
final TetheringConfiguration cfg = new TetheringConfiguration(
|
final TetheringConfiguration cfg = new TetheringConfiguration(
|
||||||
mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
mMockContext, mLog, INVALID_SUBSCRIPTION_ID, mDeps);
|
||||||
|
|
||||||
assertTrue(cfg.isCarrierSupportTethering);
|
assertTrue(cfg.isCarrierSupportTethering);
|
||||||
assertTrue(cfg.isCarrierConfigAffirmsEntitlementCheckRequired);
|
assertTrue(cfg.isCarrierConfigAffirmsEntitlementCheckRequired);
|
||||||
@@ -521,7 +537,7 @@ public class TetheringConfigurationTest {
|
|||||||
mCarrierConfig.putBoolean(KEY_CARRIER_SUPPORTS_TETHERING_BOOL, false);
|
mCarrierConfig.putBoolean(KEY_CARRIER_SUPPORTS_TETHERING_BOOL, false);
|
||||||
when(mCarrierConfigManager.getConfigForSubId(anyInt())).thenReturn(mCarrierConfig);
|
when(mCarrierConfigManager.getConfigForSubId(anyInt())).thenReturn(mCarrierConfig);
|
||||||
final TetheringConfiguration cfg = new TetheringConfiguration(
|
final TetheringConfiguration cfg = new TetheringConfiguration(
|
||||||
mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
mMockContext, mLog, INVALID_SUBSCRIPTION_ID, mDeps);
|
||||||
|
|
||||||
if (SdkLevel.isAtLeastT()) {
|
if (SdkLevel.isAtLeastT()) {
|
||||||
assertFalse(cfg.isCarrierSupportTethering);
|
assertFalse(cfg.isCarrierSupportTethering);
|
||||||
@@ -535,13 +551,13 @@ public class TetheringConfigurationTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testEnableLegacyWifiP2PAddress() throws Exception {
|
public void testEnableLegacyWifiP2PAddress() throws Exception {
|
||||||
final TetheringConfiguration defaultCfg = new TetheringConfiguration(
|
final TetheringConfiguration defaultCfg = new TetheringConfiguration(
|
||||||
mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
mMockContext, mLog, INVALID_SUBSCRIPTION_ID, mDeps);
|
||||||
assertFalse(defaultCfg.shouldEnableWifiP2pDedicatedIp());
|
assertFalse(defaultCfg.shouldEnableWifiP2pDedicatedIp());
|
||||||
|
|
||||||
when(mResources.getBoolean(R.bool.config_tether_enable_legacy_wifi_p2p_dedicated_ip))
|
when(mResources.getBoolean(R.bool.config_tether_enable_legacy_wifi_p2p_dedicated_ip))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
final TetheringConfiguration testCfg = new TetheringConfiguration(
|
final TetheringConfiguration testCfg = new TetheringConfiguration(
|
||||||
mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
mMockContext, mLog, INVALID_SUBSCRIPTION_ID, mDeps);
|
||||||
assertTrue(testCfg.shouldEnableWifiP2pDedicatedIp());
|
assertTrue(testCfg.shouldEnableWifiP2pDedicatedIp());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -576,16 +592,13 @@ public class TetheringConfigurationTest {
|
|||||||
public void testChooseUpstreamAutomatically_FlagOverride() throws Exception {
|
public void testChooseUpstreamAutomatically_FlagOverride() throws Exception {
|
||||||
when(mResources.getBoolean(R.bool.config_tether_upstream_automatic))
|
when(mResources.getBoolean(R.bool.config_tether_upstream_automatic))
|
||||||
.thenReturn(false);
|
.thenReturn(false);
|
||||||
setTetherForceUpstreamAutomaticFlagVersion(TEST_PACKAGE_VERSION - 1);
|
setTetherForceUpstreamAutomaticFlagEnabled(true);
|
||||||
assertTrue(DeviceConfigUtils.isFeatureEnabled(mMockContext, NAMESPACE_CONNECTIVITY,
|
|
||||||
TetheringConfiguration.TETHER_FORCE_UPSTREAM_AUTOMATIC_VERSION, APEX_NAME, false));
|
|
||||||
|
|
||||||
assertChooseUpstreamAutomaticallyIs(true);
|
assertChooseUpstreamAutomaticallyIs(true);
|
||||||
|
|
||||||
setTetherForceUpstreamAutomaticFlagVersion(0L);
|
setTetherForceUpstreamAutomaticFlagEnabled(null);
|
||||||
assertChooseUpstreamAutomaticallyIs(false);
|
assertChooseUpstreamAutomaticallyIs(false);
|
||||||
|
|
||||||
setTetherForceUpstreamAutomaticFlagVersion(Long.MAX_VALUE);
|
setTetherForceUpstreamAutomaticFlagEnabled(false);
|
||||||
assertChooseUpstreamAutomaticallyIs(false);
|
assertChooseUpstreamAutomaticallyIs(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -593,7 +606,7 @@ public class TetheringConfigurationTest {
|
|||||||
public void testChooseUpstreamAutomatically_FlagOverrideOnSAndT() throws Exception {
|
public void testChooseUpstreamAutomatically_FlagOverrideOnSAndT() throws Exception {
|
||||||
when(mResources.getBoolean(R.bool.config_tether_upstream_automatic))
|
when(mResources.getBoolean(R.bool.config_tether_upstream_automatic))
|
||||||
.thenReturn(false);
|
.thenReturn(false);
|
||||||
setTetherForceUpstreamAutomaticFlagVersion(TEST_PACKAGE_VERSION - 1);
|
setTetherForceUpstreamAutomaticFlagEnabled(true);
|
||||||
assertChooseUpstreamAutomaticallyIs(false);
|
assertChooseUpstreamAutomaticallyIs(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -604,28 +617,24 @@ public class TetheringConfigurationTest {
|
|||||||
// TETHER_FORCE_UPSTREAM_AUTOMATIC_VERSION is.
|
// TETHER_FORCE_UPSTREAM_AUTOMATIC_VERSION is.
|
||||||
when(mResources.getBoolean(R.bool.config_tether_upstream_automatic))
|
when(mResources.getBoolean(R.bool.config_tether_upstream_automatic))
|
||||||
.thenReturn(false);
|
.thenReturn(false);
|
||||||
setTetherForceUpstreamAutomaticFlagVersion(TEST_PACKAGE_VERSION - 1);
|
setTetherForceUpstreamAutomaticFlagEnabled(true);
|
||||||
assertTrue(DeviceConfigUtils.isFeatureEnabled(mMockContext, NAMESPACE_CONNECTIVITY,
|
|
||||||
TetheringConfiguration.TETHER_FORCE_UPSTREAM_AUTOMATIC_VERSION, APEX_NAME, false));
|
|
||||||
|
|
||||||
assertChooseUpstreamAutomaticallyIs(true);
|
assertChooseUpstreamAutomaticallyIs(true);
|
||||||
|
|
||||||
setTetherForceUpstreamAutomaticFlagVersion(0L);
|
setTetherForceUpstreamAutomaticFlagEnabled(null);
|
||||||
assertChooseUpstreamAutomaticallyIs(true);
|
assertChooseUpstreamAutomaticallyIs(true);
|
||||||
|
|
||||||
setTetherForceUpstreamAutomaticFlagVersion(Long.MAX_VALUE);
|
setTetherForceUpstreamAutomaticFlagEnabled(false);
|
||||||
assertChooseUpstreamAutomaticallyIs(true);
|
assertChooseUpstreamAutomaticallyIs(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setTetherForceUpstreamAutomaticFlagVersion(Long version) {
|
private void setTetherForceUpstreamAutomaticFlagEnabled(Boolean enabled) {
|
||||||
doReturn(version == null ? null : Long.toString(version)).when(
|
mDeps.setFeatureEnabled(
|
||||||
() -> DeviceConfig.getProperty(eq(NAMESPACE_CONNECTIVITY),
|
TetheringConfiguration.TETHER_FORCE_UPSTREAM_AUTOMATIC_VERSION, enabled);
|
||||||
eq(TetheringConfiguration.TETHER_FORCE_UPSTREAM_AUTOMATIC_VERSION)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertChooseUpstreamAutomaticallyIs(boolean value) {
|
private void assertChooseUpstreamAutomaticallyIs(boolean value) {
|
||||||
assertEquals(value, new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID)
|
assertEquals(value, new TetheringConfiguration(
|
||||||
.chooseUpstreamAutomatically);
|
mMockContext, mLog, INVALID_SUBSCRIPTION_ID, mDeps).chooseUpstreamAutomatically);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -654,7 +663,7 @@ public class TetheringConfigurationTest {
|
|||||||
|
|
||||||
private void assertIsUsingNcm(boolean expected) {
|
private void assertIsUsingNcm(boolean expected) {
|
||||||
final TetheringConfiguration cfg =
|
final TetheringConfiguration cfg =
|
||||||
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID, mDeps);
|
||||||
assertEquals(expected, cfg.isUsingNcm());
|
assertEquals(expected, cfg.isUsingNcm());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -704,7 +713,7 @@ public class TetheringConfigurationTest {
|
|||||||
|
|
||||||
private void assertUsbAndNcmRegexs(final String[] usbRegexs, final String[] ncmRegexs) {
|
private void assertUsbAndNcmRegexs(final String[] usbRegexs, final String[] ncmRegexs) {
|
||||||
final TetheringConfiguration cfg =
|
final TetheringConfiguration cfg =
|
||||||
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID, mDeps);
|
||||||
assertArrayEquals(usbRegexs, cfg.tetherableUsbRegexs);
|
assertArrayEquals(usbRegexs, cfg.tetherableUsbRegexs);
|
||||||
assertArrayEquals(ncmRegexs, cfg.tetherableNcmRegexs);
|
assertArrayEquals(ncmRegexs, cfg.tetherableNcmRegexs);
|
||||||
}
|
}
|
||||||
@@ -716,28 +725,28 @@ public class TetheringConfigurationTest {
|
|||||||
|
|
||||||
final int defaultSubnetPrefixLength = 0;
|
final int defaultSubnetPrefixLength = 0;
|
||||||
final TetheringConfiguration defaultCfg =
|
final TetheringConfiguration defaultCfg =
|
||||||
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID, mDeps);
|
||||||
assertEquals(defaultSubnetPrefixLength, defaultCfg.getP2pLeasesSubnetPrefixLength());
|
assertEquals(defaultSubnetPrefixLength, defaultCfg.getP2pLeasesSubnetPrefixLength());
|
||||||
|
|
||||||
final int prefixLengthTooSmall = -1;
|
final int prefixLengthTooSmall = -1;
|
||||||
when(mResources.getInteger(R.integer.config_p2p_leases_subnet_prefix_length)).thenReturn(
|
when(mResources.getInteger(R.integer.config_p2p_leases_subnet_prefix_length)).thenReturn(
|
||||||
prefixLengthTooSmall);
|
prefixLengthTooSmall);
|
||||||
final TetheringConfiguration tooSmallCfg =
|
final TetheringConfiguration tooSmallCfg =
|
||||||
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID, mDeps);
|
||||||
assertEquals(defaultSubnetPrefixLength, tooSmallCfg.getP2pLeasesSubnetPrefixLength());
|
assertEquals(defaultSubnetPrefixLength, tooSmallCfg.getP2pLeasesSubnetPrefixLength());
|
||||||
|
|
||||||
final int prefixLengthTooLarge = 31;
|
final int prefixLengthTooLarge = 31;
|
||||||
when(mResources.getInteger(R.integer.config_p2p_leases_subnet_prefix_length)).thenReturn(
|
when(mResources.getInteger(R.integer.config_p2p_leases_subnet_prefix_length)).thenReturn(
|
||||||
prefixLengthTooLarge);
|
prefixLengthTooLarge);
|
||||||
final TetheringConfiguration tooLargeCfg =
|
final TetheringConfiguration tooLargeCfg =
|
||||||
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID, mDeps);
|
||||||
assertEquals(defaultSubnetPrefixLength, tooLargeCfg.getP2pLeasesSubnetPrefixLength());
|
assertEquals(defaultSubnetPrefixLength, tooLargeCfg.getP2pLeasesSubnetPrefixLength());
|
||||||
|
|
||||||
final int p2pLeasesSubnetPrefixLength = 27;
|
final int p2pLeasesSubnetPrefixLength = 27;
|
||||||
when(mResources.getInteger(R.integer.config_p2p_leases_subnet_prefix_length)).thenReturn(
|
when(mResources.getInteger(R.integer.config_p2p_leases_subnet_prefix_length)).thenReturn(
|
||||||
p2pLeasesSubnetPrefixLength);
|
p2pLeasesSubnetPrefixLength);
|
||||||
final TetheringConfiguration p2pCfg =
|
final TetheringConfiguration p2pCfg =
|
||||||
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID, mDeps);
|
||||||
assertEquals(p2pLeasesSubnetPrefixLength, p2pCfg.getP2pLeasesSubnetPrefixLength());
|
assertEquals(p2pLeasesSubnetPrefixLength, p2pCfg.getP2pLeasesSubnetPrefixLength());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user