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:
@@ -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_NO_ERROR;
|
||||
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 com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
|
||||
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.assertFalse;
|
||||
@@ -39,7 +41,6 @@ import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.net.util.SharedLog;
|
||||
@@ -49,9 +50,8 @@ import android.os.PersistableBundle;
|
||||
import android.os.ResultReceiver;
|
||||
import android.os.SystemProperties;
|
||||
import android.os.test.TestLooper;
|
||||
import android.provider.Settings;
|
||||
import android.provider.DeviceConfig;
|
||||
import android.telephony.CarrierConfigManager;
|
||||
import android.test.mock.MockContentResolver;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
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.StateMachine;
|
||||
import com.android.internal.util.test.BroadcastInterceptingContext;
|
||||
import com.android.internal.util.test.FakeSettingsProvider;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -94,7 +93,6 @@ public final class EntitlementManagerTest {
|
||||
private final PersistableBundle mCarrierConfig = new PersistableBundle();
|
||||
private final TestLooper mLooper = new TestLooper();
|
||||
private Context mMockContext;
|
||||
private MockContentResolver mContentResolver;
|
||||
|
||||
private TestStateMachine mSM;
|
||||
private WrappedEntitlementManager mEnMgr;
|
||||
@@ -110,11 +108,6 @@ public final class EntitlementManagerTest {
|
||||
public Resources getResources() {
|
||||
return mResources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContentResolver getContentResolver() {
|
||||
return mContentResolver;
|
||||
}
|
||||
}
|
||||
|
||||
public class WrappedEntitlementManager extends EntitlementManager {
|
||||
@@ -151,13 +144,17 @@ public final class EntitlementManagerTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mMockingSession = mockitoSession()
|
||||
.initMocks(this)
|
||||
.spyStatic(SystemProperties.class)
|
||||
.mockStatic(SystemProperties.class)
|
||||
.mockStatic(DeviceConfig.class)
|
||||
.strictness(Strictness.WARN)
|
||||
.startMocking();
|
||||
// Don't disable tethering provisioning unless requested.
|
||||
doReturn(false).when(
|
||||
() -> SystemProperties.getBoolean(
|
||||
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))
|
||||
.thenReturn(new String[0]);
|
||||
@@ -169,10 +166,9 @@ public final class EntitlementManagerTest {
|
||||
.thenReturn(new String[0]);
|
||||
when(mResources.getIntArray(R.array.config_tether_upstream_types))
|
||||
.thenReturn(new int[0]);
|
||||
when(mResources.getBoolean(config_tether_enable_legacy_dhcp_server)).thenReturn(false);
|
||||
when(mLog.forSubComponent(anyString())).thenReturn(mLog);
|
||||
|
||||
mContentResolver = new MockContentResolver();
|
||||
mContentResolver.addProvider(Settings.AUTHORITY, new FakeSettingsProvider());
|
||||
mMockContext = new MockContext(mContext);
|
||||
mSM = new TestStateMachine();
|
||||
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_HIPRI;
|
||||
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 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_tether_bluetooth_regexs;
|
||||
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_usb_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.assertFalse;
|
||||
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 android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.net.util.SharedLog;
|
||||
import android.provider.Settings;
|
||||
import android.provider.DeviceConfig;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.test.mock.MockContentResolver;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
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.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.MockitoSession;
|
||||
import org.mockito.quality.Strictness;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
@@ -69,9 +73,10 @@ public class TetheringConfigurationTest {
|
||||
@Mock private TelephonyManager mTelephonyManager;
|
||||
@Mock private Resources mResources;
|
||||
@Mock private Resources mResourcesForSubId;
|
||||
private MockContentResolver mContentResolver;
|
||||
private Context mMockContext;
|
||||
private boolean mHasTelephonyManager;
|
||||
private boolean mEnableLegacyDhcpServer;
|
||||
private MockitoSession mMockingSession;
|
||||
|
||||
private class MockTetheringConfiguration extends TetheringConfiguration {
|
||||
MockTetheringConfiguration(Context ctx, SharedLog log, int id) {
|
||||
@@ -101,16 +106,20 @@ public class TetheringConfigurationTest {
|
||||
}
|
||||
return super.getSystemService(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContentResolver getContentResolver() {
|
||||
return mContentResolver;
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
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_usb_regexs)).thenReturn(new String[0]);
|
||||
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.getStringArray(config_mobile_hotspot_provision_app))
|
||||
.thenReturn(new String[0]);
|
||||
mContentResolver = new MockContentResolver();
|
||||
mContentResolver.addProvider(Settings.AUTHORITY, new FakeSettingsProvider());
|
||||
when(mResources.getBoolean(config_tether_enable_legacy_dhcp_server)).thenReturn(false);
|
||||
mHasTelephonyManager = true;
|
||||
mMockContext = new MockContext(mContext);
|
||||
mEnableLegacyDhcpServer = false;
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
mMockingSession.finishMocking();
|
||||
}
|
||||
|
||||
private TetheringConfiguration getTetheringConfiguration(int... legacyTetherUpstreamTypes) {
|
||||
@@ -268,19 +282,35 @@ public class TetheringConfigurationTest {
|
||||
|
||||
@Test
|
||||
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(
|
||||
mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
||||
assertTrue(cfg.enableLegacyDhcpServer);
|
||||
final TetheringConfiguration enableByRes =
|
||||
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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_TETHERED;
|
||||
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 com.android.networkstack.tethering.R.bool.config_tether_enable_legacy_dhcp_server;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -269,6 +270,11 @@ public class TetheringTest {
|
||||
super(ctx, log, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean getDeviceConfigBoolean(final String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Resources getResourcesForSubIdWrapper(Context ctx, int subId) {
|
||||
return mResources;
|
||||
@@ -428,6 +434,7 @@ public class TetheringTest {
|
||||
.thenReturn(new int[0]);
|
||||
when(mResources.getBoolean(com.android.internal.R.bool.config_tether_upstream_automatic))
|
||||
.thenReturn(false);
|
||||
when(mResources.getBoolean(config_tether_enable_legacy_dhcp_server)).thenReturn(false);
|
||||
when(mNetd.interfaceGetList())
|
||||
.thenReturn(new String[] {
|
||||
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);
|
||||
mContentResolver = new MockContentResolver(mServiceContext);
|
||||
mContentResolver.addProvider(Settings.AUTHORITY, new FakeSettingsProvider());
|
||||
Settings.Global.putInt(mContentResolver, TETHER_ENABLE_LEGACY_DHCP_SERVER, 0);
|
||||
mIntents = new Vector<>();
|
||||
mBroadcastReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
@@ -692,7 +698,7 @@ public class TetheringTest {
|
||||
|
||||
@Test
|
||||
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();
|
||||
final UpstreamNetworkState upstreamState = buildMobileIPv4UpstreamState();
|
||||
runUsbTethering(upstreamState);
|
||||
|
||||
Reference in New Issue
Block a user