diff --git a/Tethering/src/android/net/ip/IpServer.java b/Tethering/src/android/net/ip/IpServer.java index 2bb19db8e7..965c1a14d9 100644 --- a/Tethering/src/android/net/ip/IpServer.java +++ b/Tethering/src/android/net/ip/IpServer.java @@ -68,6 +68,7 @@ import com.android.networkstack.tethering.BpfCoordinator; import com.android.networkstack.tethering.BpfCoordinator.ClientInfo; import com.android.networkstack.tethering.BpfCoordinator.Ipv6ForwardingRule; import com.android.networkstack.tethering.PrivateAddressCoordinator; +import com.android.networkstack.tethering.TetheringConfiguration; import com.android.networkstack.tethering.util.InterfaceSet; import com.android.networkstack.tethering.util.PrefixUtils; @@ -285,8 +286,8 @@ public class IpServer extends StateMachine { public IpServer( String ifaceName, Looper looper, int interfaceType, SharedLog log, INetd netd, @NonNull BpfCoordinator coordinator, Callback callback, - boolean usingLegacyDhcp, boolean usingBpfOffload, - PrivateAddressCoordinator addressCoordinator, Dependencies deps) { + TetheringConfiguration config, PrivateAddressCoordinator addressCoordinator, + Dependencies deps) { super(ifaceName, looper); mLog = log.forSubComponent(ifaceName); mNetd = netd; @@ -296,8 +297,8 @@ public class IpServer extends StateMachine { mIfaceName = ifaceName; mInterfaceType = interfaceType; mLinkProperties = new LinkProperties(); - mUsingLegacyDhcp = usingLegacyDhcp; - mUsingBpfOffload = usingBpfOffload; + mUsingLegacyDhcp = config.useLegacyDhcpServer(); + mUsingBpfOffload = config.isBpfOffloadEnabled(); mPrivateAddressCoordinator = addressCoordinator; mDeps = deps; resetLinkProperties(); diff --git a/Tethering/src/com/android/networkstack/tethering/Tethering.java b/Tethering/src/com/android/networkstack/tethering/Tethering.java index 301a6824d4..07fce08995 100644 --- a/Tethering/src/com/android/networkstack/tethering/Tethering.java +++ b/Tethering/src/com/android/networkstack/tethering/Tethering.java @@ -1745,7 +1745,7 @@ public class Tethering { // TODO: Randomize DHCPv4 ranges, especially in hotspot mode. // Legacy DHCP server is disabled if passed an empty ranges array - final String[] dhcpRanges = cfg.enableLegacyDhcpServer + final String[] dhcpRanges = cfg.useLegacyDhcpServer() ? cfg.legacyDhcpRanges : new String[0]; try { NetdUtils.tetherStart(mNetd, true /** usingLegacyDnsProxy */, dhcpRanges); @@ -2722,8 +2722,7 @@ public class Tethering { mLog.i("adding IpServer for: " + iface); final TetherState tetherState = new TetherState( new IpServer(iface, mLooper, interfaceType, mLog, mNetd, mBpfCoordinator, - makeControlCallback(), mConfig.enableLegacyDhcpServer, - mConfig.isBpfOffloadEnabled(), mPrivateAddressCoordinator, + makeControlCallback(), mConfig, mPrivateAddressCoordinator, mDeps.getIpServerDependencies()), isNcm); mTetherStates.put(iface, tetherState); tetherState.ipServer.start(); diff --git a/Tethering/src/com/android/networkstack/tethering/TetheringConfiguration.java b/Tethering/src/com/android/networkstack/tethering/TetheringConfiguration.java index 8488a9a5bf..eaf85899a1 100644 --- a/Tethering/src/com/android/networkstack/tethering/TetheringConfiguration.java +++ b/Tethering/src/com/android/networkstack/tethering/TetheringConfiguration.java @@ -136,7 +136,6 @@ public class TetheringConfiguration { public final Collection preferredUpstreamIfaceTypes; public final String[] legacyDhcpRanges; public final String[] defaultIPv4DNS; - public final boolean enableLegacyDhcpServer; public final String[] provisioningApp; public final String provisioningAppNoUi; @@ -145,6 +144,7 @@ public class TetheringConfiguration { public final int activeDataSubId; + private final boolean mEnableLegacyDhcpServer; private final int mOffloadPollInterval; // TODO: Add to TetheringConfigurationParcel if required. private final boolean mEnableBpfOffload; @@ -195,7 +195,7 @@ public class TetheringConfiguration { legacyDhcpRanges = getLegacyDhcpRanges(res); defaultIPv4DNS = copy(DEFAULT_IPV4_DNS); mEnableBpfOffload = getEnableBpfOffload(res); - enableLegacyDhcpServer = getEnableLegacyDhcpServer(res); + mEnableLegacyDhcpServer = getEnableLegacyDhcpServer(res); provisioningApp = getResourceStringArray(res, R.array.config_mobile_hotspot_provision_app); provisioningAppNoUi = getResourceString(res, @@ -217,6 +217,11 @@ public class TetheringConfiguration { configLog.log(toString()); } + /** Check whether using legacy dhcp server. */ + public boolean useLegacyDhcpServer() { + return mEnableLegacyDhcpServer; + } + /** Check whether using ncm for usb tethering */ public boolean isUsingNcm() { return mUsbTetheringFunction == TETHER_USB_NCM_FUNCTION; @@ -300,7 +305,7 @@ public class TetheringConfiguration { pw.println(mEnableBpfOffload); pw.print("enableLegacyDhcpServer: "); - pw.println(enableLegacyDhcpServer); + pw.println(mEnableLegacyDhcpServer); pw.print("enableWifiP2pDedicatedIp: "); pw.println(mEnableWifiP2pDedicatedIp); @@ -326,7 +331,7 @@ public class TetheringConfiguration { sj.add(String.format("provisioningApp:%s", makeString(provisioningApp))); sj.add(String.format("provisioningAppNoUi:%s", provisioningAppNoUi)); sj.add(String.format("enableBpfOffload:%s", mEnableBpfOffload)); - sj.add(String.format("enableLegacyDhcpServer:%s", enableLegacyDhcpServer)); + sj.add(String.format("enableLegacyDhcpServer:%s", mEnableLegacyDhcpServer)); return String.format("TetheringConfiguration{%s}", sj.toString()); } @@ -576,7 +581,7 @@ public class TetheringConfiguration { parcel.legacyDhcpRanges = legacyDhcpRanges; parcel.defaultIPv4DNS = defaultIPv4DNS; - parcel.enableLegacyDhcpServer = enableLegacyDhcpServer; + parcel.enableLegacyDhcpServer = mEnableLegacyDhcpServer; parcel.provisioningApp = provisioningApp; parcel.provisioningAppNoUi = provisioningAppNoUi; parcel.provisioningCheckPeriod = provisioningCheckPeriod; diff --git a/Tethering/tests/unit/src/android/net/ip/IpServerTest.java b/Tethering/tests/unit/src/android/net/ip/IpServerTest.java index a3c46c2fbd..41bbc4cf33 100644 --- a/Tethering/tests/unit/src/android/net/ip/IpServerTest.java +++ b/Tethering/tests/unit/src/android/net/ip/IpServerTest.java @@ -228,9 +228,11 @@ public class IpServerTest { doReturn(mIpNeighborMonitor).when(mDependencies).getIpNeighborMonitor(any(), any(), neighborCaptor.capture()); + when(mTetherConfig.isBpfOffloadEnabled()).thenReturn(usingBpfOffload); + when(mTetherConfig.useLegacyDhcpServer()).thenReturn(usingLegacyDhcp); mIpServer = new IpServer( IFACE_NAME, mLooper.getLooper(), interfaceType, mSharedLog, mNetd, mBpfCoordinator, - mCallback, usingLegacyDhcp, usingBpfOffload, mAddressCoordinator, mDependencies); + mCallback, mTetherConfig, mAddressCoordinator, mDependencies); mIpServer.start(); mNeighborEventConsumer = neighborCaptor.getValue(); @@ -281,7 +283,8 @@ public class IpServerTest { when(mSharedLog.forSubComponent(anyString())).thenReturn(mSharedLog); when(mAddressCoordinator.requestDownstreamAddress(any(), anyBoolean())).thenReturn( mTestAddress); - when(mTetherConfig.isBpfOffloadEnabled()).thenReturn(true /* default value */); + when(mTetherConfig.isBpfOffloadEnabled()).thenReturn(DEFAULT_USING_BPF_OFFLOAD); + when(mTetherConfig.useLegacyDhcpServer()).thenReturn(false /* default value */); mBpfDeps = new BpfCoordinator.Dependencies() { @NonNull @@ -360,8 +363,8 @@ public class IpServerTest { when(mDependencies.getIpNeighborMonitor(any(), any(), any())) .thenReturn(mIpNeighborMonitor); mIpServer = new IpServer(IFACE_NAME, mLooper.getLooper(), TETHERING_BLUETOOTH, mSharedLog, - mNetd, mBpfCoordinator, mCallback, false /* usingLegacyDhcp */, - DEFAULT_USING_BPF_OFFLOAD, mAddressCoordinator, mDependencies); + mNetd, mBpfCoordinator, mCallback, mTetherConfig, mAddressCoordinator, + mDependencies); mIpServer.start(); mLooper.dispatchAll(); verify(mCallback).updateInterfaceState( diff --git a/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringConfigurationTest.java b/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringConfigurationTest.java index 11e19ebc0b..e8bb31554a 100644 --- a/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringConfigurationTest.java +++ b/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringConfigurationTest.java @@ -95,7 +95,6 @@ public class TetheringConfigurationTest { @Mock private ModuleInfo mMi; private Context mMockContext; private boolean mHasTelephonyManager; - private boolean mEnableLegacyDhcpServer; private MockitoSession mMockingSession; private MockContentResolver mContentResolver; @@ -185,7 +184,6 @@ public class TetheringConfigurationTest { mHasTelephonyManager = true; mMockContext = new MockContext(mContext); - mEnableLegacyDhcpServer = false; mContentResolver = new MockContentResolver(mMockContext); mContentResolver.addProvider(Settings.AUTHORITY, new FakeSettingsProvider()); @@ -397,7 +395,7 @@ public class TetheringConfigurationTest { final TetheringConfiguration enableByRes = new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID); - assertTrue(enableByRes.enableLegacyDhcpServer); + assertTrue(enableByRes.useLegacyDhcpServer()); when(mResources.getBoolean(R.bool.config_tether_enable_legacy_dhcp_server)).thenReturn( false); @@ -407,7 +405,7 @@ public class TetheringConfigurationTest { final TetheringConfiguration enableByDevConfig = new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID); - assertTrue(enableByDevConfig.enableLegacyDhcpServer); + assertTrue(enableByDevConfig.useLegacyDhcpServer()); } @Test @@ -421,7 +419,7 @@ public class TetheringConfigurationTest { final TetheringConfiguration cfg = new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID); - assertFalse(cfg.enableLegacyDhcpServer); + assertFalse(cfg.useLegacyDhcpServer()); } @Test