Migrate legacy dhcp server config to DeviceConfig
Legacy dhcp server can also be enabled by resource config.
Bug: 144814607
Test: -build, flash, boot
-atest TetheringTests
Change-Id: I8ae5fa3d5bbd88129bd0890f71be6f8a1bfec0eb
This commit is contained in:
@@ -32,6 +32,7 @@
|
|||||||
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
||||||
<uses-permission android:name="android.permission.MANAGE_USB" />
|
<uses-permission android:name="android.permission.MANAGE_USB" />
|
||||||
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
|
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.READ_DEVICE_CONFIG" />
|
||||||
<uses-permission android:name="android.permission.READ_NETWORK_USAGE_HISTORY" />
|
<uses-permission android:name="android.permission.READ_NETWORK_USAGE_HISTORY" />
|
||||||
<uses-permission android:name="android.permission.TETHER_PRIVILEGED" />
|
<uses-permission android:name="android.permission.TETHER_PRIVILEGED" />
|
||||||
<uses-permission android:name="android.permission.UPDATE_APP_OPS_STATS" />
|
<uses-permission android:name="android.permission.UPDATE_APP_OPS_STATS" />
|
||||||
|
|||||||
@@ -49,6 +49,9 @@
|
|||||||
<item>"bt-pan"</item>
|
<item>"bt-pan"</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<!-- Use the old dnsmasq DHCP server for tethering instead of the framework implementation. -->
|
||||||
|
<bool translatable="false" name="config_tether_enable_legacy_dhcp_server">false</bool>
|
||||||
|
|
||||||
<!-- Dhcp range (min, max) to use for tethering purposes -->
|
<!-- Dhcp range (min, max) to use for tethering purposes -->
|
||||||
<string-array translatable="false" name="config_tether_dhcp_range">
|
<string-array translatable="false" name="config_tether_dhcp_range">
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
<item type="array" name="config_tether_wifi_p2p_regexs"/>
|
<item type="array" name="config_tether_wifi_p2p_regexs"/>
|
||||||
<item type="array" name="config_tether_bluetooth_regexs"/>
|
<item type="array" name="config_tether_bluetooth_regexs"/>
|
||||||
<item type="array" name="config_tether_dhcp_range"/>
|
<item type="array" name="config_tether_dhcp_range"/>
|
||||||
|
<item type="bool" name="config_tether_enable_legacy_dhcp_server"/>
|
||||||
<item type="array" name="config_tether_upstream_types"/>
|
<item type="array" name="config_tether_upstream_types"/>
|
||||||
<item type="bool" name="config_tether_upstream_automatic"/>
|
<item type="bool" name="config_tether_upstream_automatic"/>
|
||||||
<!-- Configuration values for tethering entitlement check -->
|
<!-- Configuration values for tethering entitlement check -->
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import static android.net.ConnectivityManager.TYPE_ETHERNET;
|
|||||||
import static android.net.ConnectivityManager.TYPE_MOBILE;
|
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.provider.Settings.Global.TETHER_ENABLE_LEGACY_DHCP_SERVER;
|
import static android.provider.DeviceConfig.NAMESPACE_CONNECTIVITY;
|
||||||
|
|
||||||
import static com.android.internal.R.array.config_mobile_hotspot_provision_app;
|
import static com.android.internal.R.array.config_mobile_hotspot_provision_app;
|
||||||
import static com.android.internal.R.array.config_tether_bluetooth_regexs;
|
import static com.android.internal.R.array.config_tether_bluetooth_regexs;
|
||||||
@@ -33,13 +33,13 @@ import static com.android.internal.R.array.config_tether_wifi_regexs;
|
|||||||
import static com.android.internal.R.bool.config_tether_upstream_automatic;
|
import static com.android.internal.R.bool.config_tether_upstream_automatic;
|
||||||
import static com.android.internal.R.integer.config_mobile_hotspot_provision_check_period;
|
import static com.android.internal.R.integer.config_mobile_hotspot_provision_check_period;
|
||||||
import static com.android.internal.R.string.config_mobile_hotspot_provision_app_no_ui;
|
import static com.android.internal.R.string.config_mobile_hotspot_provision_app_no_ui;
|
||||||
|
import static com.android.networkstack.tethering.R.bool.config_tether_enable_legacy_dhcp_server;
|
||||||
|
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.net.TetheringConfigurationParcel;
|
import android.net.TetheringConfigurationParcel;
|
||||||
import android.net.util.SharedLog;
|
import android.net.util.SharedLog;
|
||||||
import android.provider.Settings;
|
import android.provider.DeviceConfig;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@@ -84,6 +84,12 @@ public class TetheringConfiguration {
|
|||||||
|
|
||||||
private static final String[] DEFAULT_IPV4_DNS = {"8.8.4.4", "8.8.8.8"};
|
private static final String[] DEFAULT_IPV4_DNS = {"8.8.4.4", "8.8.8.8"};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use the old dnsmasq DHCP server for tethering instead of the framework implementation.
|
||||||
|
*/
|
||||||
|
public static final String TETHER_ENABLE_LEGACY_DHCP_SERVER =
|
||||||
|
"tether_enable_legacy_dhcp_server";
|
||||||
|
|
||||||
public final String[] tetherableUsbRegexs;
|
public final String[] tetherableUsbRegexs;
|
||||||
public final String[] tetherableWifiRegexs;
|
public final String[] tetherableWifiRegexs;
|
||||||
public final String[] tetherableWifiP2pRegexs;
|
public final String[] tetherableWifiP2pRegexs;
|
||||||
@@ -122,7 +128,7 @@ public class TetheringConfiguration {
|
|||||||
|
|
||||||
legacyDhcpRanges = getLegacyDhcpRanges(res);
|
legacyDhcpRanges = getLegacyDhcpRanges(res);
|
||||||
defaultIPv4DNS = copy(DEFAULT_IPV4_DNS);
|
defaultIPv4DNS = copy(DEFAULT_IPV4_DNS);
|
||||||
enableLegacyDhcpServer = getEnableLegacyDhcpServer(ctx);
|
enableLegacyDhcpServer = getEnableLegacyDhcpServer(res);
|
||||||
|
|
||||||
provisioningApp = getResourceStringArray(res, config_mobile_hotspot_provision_app);
|
provisioningApp = getResourceStringArray(res, config_mobile_hotspot_provision_app);
|
||||||
provisioningAppNoUi = getProvisioningAppNoUi(res);
|
provisioningAppNoUi = getProvisioningAppNoUi(res);
|
||||||
@@ -332,10 +338,14 @@ public class TetheringConfiguration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean getEnableLegacyDhcpServer(Context ctx) {
|
private boolean getEnableLegacyDhcpServer(final Resources res) {
|
||||||
final ContentResolver cr = ctx.getContentResolver();
|
return getResourceBoolean(res, config_tether_enable_legacy_dhcp_server)
|
||||||
final int intVal = Settings.Global.getInt(cr, TETHER_ENABLE_LEGACY_DHCP_SERVER, 0);
|
|| getDeviceConfigBoolean(TETHER_ENABLE_LEGACY_DHCP_SERVER);
|
||||||
return intVal != 0;
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
protected boolean getDeviceConfigBoolean(final String name) {
|
||||||
|
return DeviceConfig.getBoolean(NAMESPACE_CONNECTIVITY, name, false /** defaultValue */);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Resources getResources(Context ctx, int subId) {
|
private Resources getResources(Context ctx, int subId) {
|
||||||
|
|||||||
@@ -22,10 +22,12 @@ import static android.net.TetheringManager.TETHERING_WIFI;
|
|||||||
import static android.net.TetheringManager.TETHER_ERROR_ENTITLEMENT_UNKONWN;
|
import static android.net.TetheringManager.TETHER_ERROR_ENTITLEMENT_UNKONWN;
|
||||||
import static android.net.TetheringManager.TETHER_ERROR_NO_ERROR;
|
import static android.net.TetheringManager.TETHER_ERROR_NO_ERROR;
|
||||||
import static android.net.TetheringManager.TETHER_ERROR_PROVISION_FAILED;
|
import static android.net.TetheringManager.TETHER_ERROR_PROVISION_FAILED;
|
||||||
|
import static android.provider.DeviceConfig.NAMESPACE_CONNECTIVITY;
|
||||||
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.doReturn;
|
||||||
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession;
|
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession;
|
||||||
|
import static com.android.networkstack.tethering.R.bool.config_tether_enable_legacy_dhcp_server;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
@@ -39,7 +41,6 @@ import static org.mockito.Mockito.times;
|
|||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.net.util.SharedLog;
|
import android.net.util.SharedLog;
|
||||||
@@ -49,9 +50,8 @@ import android.os.PersistableBundle;
|
|||||||
import android.os.ResultReceiver;
|
import android.os.ResultReceiver;
|
||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
import android.os.test.TestLooper;
|
import android.os.test.TestLooper;
|
||||||
import android.provider.Settings;
|
import android.provider.DeviceConfig;
|
||||||
import android.telephony.CarrierConfigManager;
|
import android.telephony.CarrierConfigManager;
|
||||||
import android.test.mock.MockContentResolver;
|
|
||||||
|
|
||||||
import androidx.test.filters.SmallTest;
|
import androidx.test.filters.SmallTest;
|
||||||
import androidx.test.runner.AndroidJUnit4;
|
import androidx.test.runner.AndroidJUnit4;
|
||||||
@@ -60,7 +60,6 @@ import com.android.internal.R;
|
|||||||
import com.android.internal.util.State;
|
import com.android.internal.util.State;
|
||||||
import com.android.internal.util.StateMachine;
|
import com.android.internal.util.StateMachine;
|
||||||
import com.android.internal.util.test.BroadcastInterceptingContext;
|
import com.android.internal.util.test.BroadcastInterceptingContext;
|
||||||
import com.android.internal.util.test.FakeSettingsProvider;
|
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -94,7 +93,6 @@ public final class EntitlementManagerTest {
|
|||||||
private final PersistableBundle mCarrierConfig = new PersistableBundle();
|
private final PersistableBundle mCarrierConfig = new PersistableBundle();
|
||||||
private final TestLooper mLooper = new TestLooper();
|
private final TestLooper mLooper = new TestLooper();
|
||||||
private Context mMockContext;
|
private Context mMockContext;
|
||||||
private MockContentResolver mContentResolver;
|
|
||||||
|
|
||||||
private TestStateMachine mSM;
|
private TestStateMachine mSM;
|
||||||
private WrappedEntitlementManager mEnMgr;
|
private WrappedEntitlementManager mEnMgr;
|
||||||
@@ -110,11 +108,6 @@ public final class EntitlementManagerTest {
|
|||||||
public Resources getResources() {
|
public Resources getResources() {
|
||||||
return mResources;
|
return mResources;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ContentResolver getContentResolver() {
|
|
||||||
return mContentResolver;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WrappedEntitlementManager extends EntitlementManager {
|
public class WrappedEntitlementManager extends EntitlementManager {
|
||||||
@@ -151,13 +144,17 @@ public final class EntitlementManagerTest {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mMockingSession = mockitoSession()
|
mMockingSession = mockitoSession()
|
||||||
.initMocks(this)
|
.initMocks(this)
|
||||||
.spyStatic(SystemProperties.class)
|
.mockStatic(SystemProperties.class)
|
||||||
|
.mockStatic(DeviceConfig.class)
|
||||||
.strictness(Strictness.WARN)
|
.strictness(Strictness.WARN)
|
||||||
.startMocking();
|
.startMocking();
|
||||||
// Don't disable tethering provisioning unless requested.
|
// Don't disable tethering provisioning unless requested.
|
||||||
doReturn(false).when(
|
doReturn(false).when(
|
||||||
() -> SystemProperties.getBoolean(
|
() -> SystemProperties.getBoolean(
|
||||||
eq(EntitlementManager.DISABLE_PROVISIONING_SYSPROP_KEY), anyBoolean()));
|
eq(EntitlementManager.DISABLE_PROVISIONING_SYSPROP_KEY), anyBoolean()));
|
||||||
|
doReturn(false).when(
|
||||||
|
() -> DeviceConfig.getBoolean(eq(NAMESPACE_CONNECTIVITY),
|
||||||
|
eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER), anyBoolean()));
|
||||||
|
|
||||||
when(mResources.getStringArray(R.array.config_tether_dhcp_range))
|
when(mResources.getStringArray(R.array.config_tether_dhcp_range))
|
||||||
.thenReturn(new String[0]);
|
.thenReturn(new String[0]);
|
||||||
@@ -169,10 +166,9 @@ public final class EntitlementManagerTest {
|
|||||||
.thenReturn(new String[0]);
|
.thenReturn(new String[0]);
|
||||||
when(mResources.getIntArray(R.array.config_tether_upstream_types))
|
when(mResources.getIntArray(R.array.config_tether_upstream_types))
|
||||||
.thenReturn(new int[0]);
|
.thenReturn(new int[0]);
|
||||||
|
when(mResources.getBoolean(config_tether_enable_legacy_dhcp_server)).thenReturn(false);
|
||||||
when(mLog.forSubComponent(anyString())).thenReturn(mLog);
|
when(mLog.forSubComponent(anyString())).thenReturn(mLog);
|
||||||
|
|
||||||
mContentResolver = new MockContentResolver();
|
|
||||||
mContentResolver.addProvider(Settings.AUTHORITY, new FakeSettingsProvider());
|
|
||||||
mMockContext = new MockContext(mContext);
|
mMockContext = new MockContext(mContext);
|
||||||
mSM = new TestStateMachine();
|
mSM = new TestStateMachine();
|
||||||
mEnMgr = new WrappedEntitlementManager(mMockContext, mSM, mLog, EVENT_EM_UPDATE);
|
mEnMgr = new WrappedEntitlementManager(mMockContext, mSM, mLog, EVENT_EM_UPDATE);
|
||||||
|
|||||||
@@ -21,40 +21,44 @@ 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.Settings.Global.TETHER_ENABLE_LEGACY_DHCP_SERVER;
|
import static android.provider.DeviceConfig.NAMESPACE_CONNECTIVITY;
|
||||||
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.internal.R.array.config_mobile_hotspot_provision_app;
|
import static com.android.internal.R.array.config_mobile_hotspot_provision_app;
|
||||||
import static com.android.internal.R.array.config_tether_bluetooth_regexs;
|
import static com.android.internal.R.array.config_tether_bluetooth_regexs;
|
||||||
import static com.android.internal.R.array.config_tether_dhcp_range;
|
import static com.android.internal.R.array.config_tether_dhcp_range;
|
||||||
import static com.android.internal.R.array.config_tether_upstream_types;
|
import static com.android.internal.R.array.config_tether_upstream_types;
|
||||||
import static com.android.internal.R.array.config_tether_usb_regexs;
|
import static com.android.internal.R.array.config_tether_usb_regexs;
|
||||||
import static com.android.internal.R.array.config_tether_wifi_regexs;
|
import static com.android.internal.R.array.config_tether_wifi_regexs;
|
||||||
|
import static com.android.networkstack.tethering.R.bool.config_tether_enable_legacy_dhcp_server;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.mockito.Matchers.anyBoolean;
|
||||||
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.net.util.SharedLog;
|
import android.net.util.SharedLog;
|
||||||
import android.provider.Settings;
|
import android.provider.DeviceConfig;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.test.mock.MockContentResolver;
|
|
||||||
|
|
||||||
import androidx.test.filters.SmallTest;
|
import androidx.test.filters.SmallTest;
|
||||||
import androidx.test.runner.AndroidJUnit4;
|
import androidx.test.runner.AndroidJUnit4;
|
||||||
|
|
||||||
import com.android.internal.util.test.BroadcastInterceptingContext;
|
import com.android.internal.util.test.BroadcastInterceptingContext;
|
||||||
import com.android.internal.util.test.FakeSettingsProvider;
|
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
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.MockitoAnnotations;
|
import org.mockito.MockitoSession;
|
||||||
|
import org.mockito.quality.Strictness;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@@ -69,9 +73,10 @@ public class TetheringConfigurationTest {
|
|||||||
@Mock private TelephonyManager mTelephonyManager;
|
@Mock private TelephonyManager mTelephonyManager;
|
||||||
@Mock private Resources mResources;
|
@Mock private Resources mResources;
|
||||||
@Mock private Resources mResourcesForSubId;
|
@Mock private Resources mResourcesForSubId;
|
||||||
private MockContentResolver mContentResolver;
|
|
||||||
private Context mMockContext;
|
private Context mMockContext;
|
||||||
private boolean mHasTelephonyManager;
|
private boolean mHasTelephonyManager;
|
||||||
|
private boolean mEnableLegacyDhcpServer;
|
||||||
|
private MockitoSession mMockingSession;
|
||||||
|
|
||||||
private class MockTetheringConfiguration extends TetheringConfiguration {
|
private class MockTetheringConfiguration extends TetheringConfiguration {
|
||||||
MockTetheringConfiguration(Context ctx, SharedLog log, int id) {
|
MockTetheringConfiguration(Context ctx, SharedLog log, int id) {
|
||||||
@@ -101,16 +106,20 @@ public class TetheringConfigurationTest {
|
|||||||
}
|
}
|
||||||
return super.getSystemService(name);
|
return super.getSystemService(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ContentResolver getContentResolver() {
|
|
||||||
return mContentResolver;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
MockitoAnnotations.initMocks(this);
|
// TODO: use a dependencies class instead of mock statics.
|
||||||
|
mMockingSession = mockitoSession()
|
||||||
|
.initMocks(this)
|
||||||
|
.mockStatic(DeviceConfig.class)
|
||||||
|
.strictness(Strictness.WARN)
|
||||||
|
.startMocking();
|
||||||
|
doReturn(false).when(
|
||||||
|
() -> DeviceConfig.getBoolean(eq(NAMESPACE_CONNECTIVITY),
|
||||||
|
eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER), anyBoolean()));
|
||||||
|
|
||||||
when(mResources.getStringArray(config_tether_dhcp_range)).thenReturn(new String[0]);
|
when(mResources.getStringArray(config_tether_dhcp_range)).thenReturn(new String[0]);
|
||||||
when(mResources.getStringArray(config_tether_usb_regexs)).thenReturn(new String[0]);
|
when(mResources.getStringArray(config_tether_usb_regexs)).thenReturn(new String[0]);
|
||||||
when(mResources.getStringArray(config_tether_wifi_regexs))
|
when(mResources.getStringArray(config_tether_wifi_regexs))
|
||||||
@@ -119,10 +128,15 @@ public class TetheringConfigurationTest {
|
|||||||
when(mResources.getIntArray(config_tether_upstream_types)).thenReturn(new int[0]);
|
when(mResources.getIntArray(config_tether_upstream_types)).thenReturn(new int[0]);
|
||||||
when(mResources.getStringArray(config_mobile_hotspot_provision_app))
|
when(mResources.getStringArray(config_mobile_hotspot_provision_app))
|
||||||
.thenReturn(new String[0]);
|
.thenReturn(new String[0]);
|
||||||
mContentResolver = new MockContentResolver();
|
when(mResources.getBoolean(config_tether_enable_legacy_dhcp_server)).thenReturn(false);
|
||||||
mContentResolver.addProvider(Settings.AUTHORITY, new FakeSettingsProvider());
|
|
||||||
mHasTelephonyManager = true;
|
mHasTelephonyManager = true;
|
||||||
mMockContext = new MockContext(mContext);
|
mMockContext = new MockContext(mContext);
|
||||||
|
mEnableLegacyDhcpServer = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
mMockingSession.finishMocking();
|
||||||
}
|
}
|
||||||
|
|
||||||
private TetheringConfiguration getTetheringConfiguration(int... legacyTetherUpstreamTypes) {
|
private TetheringConfiguration getTetheringConfiguration(int... legacyTetherUpstreamTypes) {
|
||||||
@@ -268,19 +282,35 @@ public class TetheringConfigurationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNewDhcpServerDisabled() {
|
public void testNewDhcpServerDisabled() {
|
||||||
Settings.Global.putInt(mContentResolver, TETHER_ENABLE_LEGACY_DHCP_SERVER, 1);
|
when(mResources.getBoolean(config_tether_enable_legacy_dhcp_server)).thenReturn(true);
|
||||||
|
doReturn(false).when(
|
||||||
|
() -> DeviceConfig.getBoolean(eq(NAMESPACE_CONNECTIVITY),
|
||||||
|
eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER), anyBoolean()));
|
||||||
|
|
||||||
final TetheringConfiguration cfg = new TetheringConfiguration(
|
final TetheringConfiguration enableByRes =
|
||||||
mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
||||||
assertTrue(cfg.enableLegacyDhcpServer);
|
assertTrue(enableByRes.enableLegacyDhcpServer);
|
||||||
|
|
||||||
|
when(mResources.getBoolean(config_tether_enable_legacy_dhcp_server)).thenReturn(false);
|
||||||
|
doReturn(true).when(
|
||||||
|
() -> DeviceConfig.getBoolean(eq(NAMESPACE_CONNECTIVITY),
|
||||||
|
eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER), anyBoolean()));
|
||||||
|
|
||||||
|
final TetheringConfiguration enableByDevConfig =
|
||||||
|
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
||||||
|
assertTrue(enableByDevConfig.enableLegacyDhcpServer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNewDhcpServerEnabled() {
|
public void testNewDhcpServerEnabled() {
|
||||||
Settings.Global.putInt(mContentResolver, TETHER_ENABLE_LEGACY_DHCP_SERVER, 0);
|
when(mResources.getBoolean(config_tether_enable_legacy_dhcp_server)).thenReturn(false);
|
||||||
|
doReturn(false).when(
|
||||||
|
() -> DeviceConfig.getBoolean(eq(NAMESPACE_CONNECTIVITY),
|
||||||
|
eq(TetheringConfiguration.TETHER_ENABLE_LEGACY_DHCP_SERVER), anyBoolean()));
|
||||||
|
|
||||||
|
final TetheringConfiguration cfg =
|
||||||
|
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
||||||
|
|
||||||
final TetheringConfiguration cfg = new TetheringConfiguration(
|
|
||||||
mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
|
||||||
assertFalse(cfg.enableLegacyDhcpServer);
|
assertFalse(cfg.enableLegacyDhcpServer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,9 +35,10 @@ import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_STATE;
|
|||||||
import static android.net.wifi.WifiManager.IFACE_IP_MODE_LOCAL_ONLY;
|
import static android.net.wifi.WifiManager.IFACE_IP_MODE_LOCAL_ONLY;
|
||||||
import static android.net.wifi.WifiManager.IFACE_IP_MODE_TETHERED;
|
import static android.net.wifi.WifiManager.IFACE_IP_MODE_TETHERED;
|
||||||
import static android.net.wifi.WifiManager.WIFI_AP_STATE_ENABLED;
|
import static android.net.wifi.WifiManager.WIFI_AP_STATE_ENABLED;
|
||||||
import static android.provider.Settings.Global.TETHER_ENABLE_LEGACY_DHCP_SERVER;
|
|
||||||
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||||
|
|
||||||
|
import static com.android.networkstack.tethering.R.bool.config_tether_enable_legacy_dhcp_server;
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
@@ -269,6 +270,11 @@ public class TetheringTest {
|
|||||||
super(ctx, log, id);
|
super(ctx, log, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean getDeviceConfigBoolean(final String name) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Resources getResourcesForSubIdWrapper(Context ctx, int subId) {
|
protected Resources getResourcesForSubIdWrapper(Context ctx, int subId) {
|
||||||
return mResources;
|
return mResources;
|
||||||
@@ -428,6 +434,7 @@ public class TetheringTest {
|
|||||||
.thenReturn(new int[0]);
|
.thenReturn(new int[0]);
|
||||||
when(mResources.getBoolean(com.android.internal.R.bool.config_tether_upstream_automatic))
|
when(mResources.getBoolean(com.android.internal.R.bool.config_tether_upstream_automatic))
|
||||||
.thenReturn(false);
|
.thenReturn(false);
|
||||||
|
when(mResources.getBoolean(config_tether_enable_legacy_dhcp_server)).thenReturn(false);
|
||||||
when(mNetd.interfaceGetList())
|
when(mNetd.interfaceGetList())
|
||||||
.thenReturn(new String[] {
|
.thenReturn(new String[] {
|
||||||
TEST_MOBILE_IFNAME, TEST_WLAN_IFNAME, TEST_USB_IFNAME, TEST_P2P_IFNAME});
|
TEST_MOBILE_IFNAME, TEST_WLAN_IFNAME, TEST_USB_IFNAME, TEST_P2P_IFNAME});
|
||||||
@@ -440,7 +447,6 @@ public class TetheringTest {
|
|||||||
when(mContext.getSystemService(Context.NOTIFICATION_SERVICE)).thenReturn(null);
|
when(mContext.getSystemService(Context.NOTIFICATION_SERVICE)).thenReturn(null);
|
||||||
mContentResolver = new MockContentResolver(mServiceContext);
|
mContentResolver = new MockContentResolver(mServiceContext);
|
||||||
mContentResolver.addProvider(Settings.AUTHORITY, new FakeSettingsProvider());
|
mContentResolver.addProvider(Settings.AUTHORITY, new FakeSettingsProvider());
|
||||||
Settings.Global.putInt(mContentResolver, TETHER_ENABLE_LEGACY_DHCP_SERVER, 0);
|
|
||||||
mIntents = new Vector<>();
|
mIntents = new Vector<>();
|
||||||
mBroadcastReceiver = new BroadcastReceiver() {
|
mBroadcastReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
@@ -692,7 +698,7 @@ public class TetheringTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void workingMobileUsbTethering_IPv4LegacyDhcp() {
|
public void workingMobileUsbTethering_IPv4LegacyDhcp() {
|
||||||
Settings.Global.putInt(mContentResolver, TETHER_ENABLE_LEGACY_DHCP_SERVER, 1);
|
when(mResources.getBoolean(config_tether_enable_legacy_dhcp_server)).thenReturn(true);
|
||||||
sendConfigurationChanged();
|
sendConfigurationChanged();
|
||||||
final UpstreamNetworkState upstreamState = buildMobileIPv4UpstreamState();
|
final UpstreamNetworkState upstreamState = buildMobileIPv4UpstreamState();
|
||||||
runUsbTethering(upstreamState);
|
runUsbTethering(upstreamState);
|
||||||
|
|||||||
Reference in New Issue
Block a user