Pass whole TetheringConfiguration to IpServer
This is a no-op CL that passing whole TetheringConfiguration to IpServer to reduce the number of IpServer constructor parameters. Bug: 170056953 Test: atest TetheringTests Change-Id: I4ec17f7ecaefd7f275139ad9c7f7551635b192c9
This commit is contained in:
@@ -68,6 +68,7 @@ import com.android.networkstack.tethering.BpfCoordinator;
|
|||||||
import com.android.networkstack.tethering.BpfCoordinator.ClientInfo;
|
import com.android.networkstack.tethering.BpfCoordinator.ClientInfo;
|
||||||
import com.android.networkstack.tethering.BpfCoordinator.Ipv6ForwardingRule;
|
import com.android.networkstack.tethering.BpfCoordinator.Ipv6ForwardingRule;
|
||||||
import com.android.networkstack.tethering.PrivateAddressCoordinator;
|
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.InterfaceSet;
|
||||||
import com.android.networkstack.tethering.util.PrefixUtils;
|
import com.android.networkstack.tethering.util.PrefixUtils;
|
||||||
|
|
||||||
@@ -285,8 +286,8 @@ public class IpServer extends StateMachine {
|
|||||||
public IpServer(
|
public IpServer(
|
||||||
String ifaceName, Looper looper, int interfaceType, SharedLog log,
|
String ifaceName, Looper looper, int interfaceType, SharedLog log,
|
||||||
INetd netd, @NonNull BpfCoordinator coordinator, Callback callback,
|
INetd netd, @NonNull BpfCoordinator coordinator, Callback callback,
|
||||||
boolean usingLegacyDhcp, boolean usingBpfOffload,
|
TetheringConfiguration config, PrivateAddressCoordinator addressCoordinator,
|
||||||
PrivateAddressCoordinator addressCoordinator, Dependencies deps) {
|
Dependencies deps) {
|
||||||
super(ifaceName, looper);
|
super(ifaceName, looper);
|
||||||
mLog = log.forSubComponent(ifaceName);
|
mLog = log.forSubComponent(ifaceName);
|
||||||
mNetd = netd;
|
mNetd = netd;
|
||||||
@@ -296,8 +297,8 @@ public class IpServer extends StateMachine {
|
|||||||
mIfaceName = ifaceName;
|
mIfaceName = ifaceName;
|
||||||
mInterfaceType = interfaceType;
|
mInterfaceType = interfaceType;
|
||||||
mLinkProperties = new LinkProperties();
|
mLinkProperties = new LinkProperties();
|
||||||
mUsingLegacyDhcp = usingLegacyDhcp;
|
mUsingLegacyDhcp = config.useLegacyDhcpServer();
|
||||||
mUsingBpfOffload = usingBpfOffload;
|
mUsingBpfOffload = config.isBpfOffloadEnabled();
|
||||||
mPrivateAddressCoordinator = addressCoordinator;
|
mPrivateAddressCoordinator = addressCoordinator;
|
||||||
mDeps = deps;
|
mDeps = deps;
|
||||||
resetLinkProperties();
|
resetLinkProperties();
|
||||||
|
|||||||
@@ -1745,7 +1745,7 @@ public class Tethering {
|
|||||||
|
|
||||||
// TODO: Randomize DHCPv4 ranges, especially in hotspot mode.
|
// TODO: Randomize DHCPv4 ranges, especially in hotspot mode.
|
||||||
// Legacy DHCP server is disabled if passed an empty ranges array
|
// 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];
|
? cfg.legacyDhcpRanges : new String[0];
|
||||||
try {
|
try {
|
||||||
NetdUtils.tetherStart(mNetd, true /** usingLegacyDnsProxy */, dhcpRanges);
|
NetdUtils.tetherStart(mNetd, true /** usingLegacyDnsProxy */, dhcpRanges);
|
||||||
@@ -2722,8 +2722,7 @@ public class Tethering {
|
|||||||
mLog.i("adding IpServer for: " + iface);
|
mLog.i("adding IpServer for: " + iface);
|
||||||
final TetherState tetherState = new TetherState(
|
final TetherState tetherState = new TetherState(
|
||||||
new IpServer(iface, mLooper, interfaceType, mLog, mNetd, mBpfCoordinator,
|
new IpServer(iface, mLooper, interfaceType, mLog, mNetd, mBpfCoordinator,
|
||||||
makeControlCallback(), mConfig.enableLegacyDhcpServer,
|
makeControlCallback(), mConfig, mPrivateAddressCoordinator,
|
||||||
mConfig.isBpfOffloadEnabled(), mPrivateAddressCoordinator,
|
|
||||||
mDeps.getIpServerDependencies()), isNcm);
|
mDeps.getIpServerDependencies()), isNcm);
|
||||||
mTetherStates.put(iface, tetherState);
|
mTetherStates.put(iface, tetherState);
|
||||||
tetherState.ipServer.start();
|
tetherState.ipServer.start();
|
||||||
|
|||||||
@@ -143,7 +143,6 @@ public class TetheringConfiguration {
|
|||||||
public final Collection<Integer> preferredUpstreamIfaceTypes;
|
public final Collection<Integer> preferredUpstreamIfaceTypes;
|
||||||
public final String[] legacyDhcpRanges;
|
public final String[] legacyDhcpRanges;
|
||||||
public final String[] defaultIPv4DNS;
|
public final String[] defaultIPv4DNS;
|
||||||
public final boolean enableLegacyDhcpServer;
|
|
||||||
|
|
||||||
public final String[] provisioningApp;
|
public final String[] provisioningApp;
|
||||||
public final String provisioningAppNoUi;
|
public final String provisioningAppNoUi;
|
||||||
@@ -152,6 +151,7 @@ public class TetheringConfiguration {
|
|||||||
|
|
||||||
public final int activeDataSubId;
|
public final int activeDataSubId;
|
||||||
|
|
||||||
|
private final boolean mEnableLegacyDhcpServer;
|
||||||
private final int mOffloadPollInterval;
|
private final int mOffloadPollInterval;
|
||||||
// TODO: Add to TetheringConfigurationParcel if required.
|
// TODO: Add to TetheringConfigurationParcel if required.
|
||||||
private final boolean mEnableBpfOffload;
|
private final boolean mEnableBpfOffload;
|
||||||
@@ -203,7 +203,7 @@ public class TetheringConfiguration {
|
|||||||
legacyDhcpRanges = getLegacyDhcpRanges(res);
|
legacyDhcpRanges = getLegacyDhcpRanges(res);
|
||||||
defaultIPv4DNS = copy(DEFAULT_IPV4_DNS);
|
defaultIPv4DNS = copy(DEFAULT_IPV4_DNS);
|
||||||
mEnableBpfOffload = getEnableBpfOffload(res);
|
mEnableBpfOffload = getEnableBpfOffload(res);
|
||||||
enableLegacyDhcpServer = getEnableLegacyDhcpServer(res);
|
mEnableLegacyDhcpServer = getEnableLegacyDhcpServer(res);
|
||||||
|
|
||||||
provisioningApp = getResourceStringArray(res, R.array.config_mobile_hotspot_provision_app);
|
provisioningApp = getResourceStringArray(res, R.array.config_mobile_hotspot_provision_app);
|
||||||
provisioningAppNoUi = getResourceString(res,
|
provisioningAppNoUi = getResourceString(res,
|
||||||
@@ -230,6 +230,11 @@ public class TetheringConfiguration {
|
|||||||
configLog.log(toString());
|
configLog.log(toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Check whether using legacy dhcp server. */
|
||||||
|
public boolean useLegacyDhcpServer() {
|
||||||
|
return mEnableLegacyDhcpServer;
|
||||||
|
}
|
||||||
|
|
||||||
/** Check whether using ncm for usb tethering */
|
/** Check whether using ncm for usb tethering */
|
||||||
public boolean isUsingNcm() {
|
public boolean isUsingNcm() {
|
||||||
return mUsbTetheringFunction == TETHER_USB_NCM_FUNCTION;
|
return mUsbTetheringFunction == TETHER_USB_NCM_FUNCTION;
|
||||||
@@ -313,7 +318,7 @@ public class TetheringConfiguration {
|
|||||||
pw.println(mEnableBpfOffload);
|
pw.println(mEnableBpfOffload);
|
||||||
|
|
||||||
pw.print("enableLegacyDhcpServer: ");
|
pw.print("enableLegacyDhcpServer: ");
|
||||||
pw.println(enableLegacyDhcpServer);
|
pw.println(mEnableLegacyDhcpServer);
|
||||||
|
|
||||||
pw.print("enableWifiP2pDedicatedIp: ");
|
pw.print("enableWifiP2pDedicatedIp: ");
|
||||||
pw.println(mEnableWifiP2pDedicatedIp);
|
pw.println(mEnableWifiP2pDedicatedIp);
|
||||||
@@ -342,7 +347,7 @@ public class TetheringConfiguration {
|
|||||||
sj.add(String.format("provisioningApp:%s", makeString(provisioningApp)));
|
sj.add(String.format("provisioningApp:%s", makeString(provisioningApp)));
|
||||||
sj.add(String.format("provisioningAppNoUi:%s", provisioningAppNoUi));
|
sj.add(String.format("provisioningAppNoUi:%s", provisioningAppNoUi));
|
||||||
sj.add(String.format("enableBpfOffload:%s", mEnableBpfOffload));
|
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());
|
return String.format("TetheringConfiguration{%s}", sj.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -596,7 +601,7 @@ public class TetheringConfiguration {
|
|||||||
|
|
||||||
parcel.legacyDhcpRanges = legacyDhcpRanges;
|
parcel.legacyDhcpRanges = legacyDhcpRanges;
|
||||||
parcel.defaultIPv4DNS = defaultIPv4DNS;
|
parcel.defaultIPv4DNS = defaultIPv4DNS;
|
||||||
parcel.enableLegacyDhcpServer = enableLegacyDhcpServer;
|
parcel.enableLegacyDhcpServer = mEnableLegacyDhcpServer;
|
||||||
parcel.provisioningApp = provisioningApp;
|
parcel.provisioningApp = provisioningApp;
|
||||||
parcel.provisioningAppNoUi = provisioningAppNoUi;
|
parcel.provisioningAppNoUi = provisioningAppNoUi;
|
||||||
parcel.provisioningCheckPeriod = provisioningCheckPeriod;
|
parcel.provisioningCheckPeriod = provisioningCheckPeriod;
|
||||||
|
|||||||
@@ -228,9 +228,11 @@ public class IpServerTest {
|
|||||||
doReturn(mIpNeighborMonitor).when(mDependencies).getIpNeighborMonitor(any(), any(),
|
doReturn(mIpNeighborMonitor).when(mDependencies).getIpNeighborMonitor(any(), any(),
|
||||||
neighborCaptor.capture());
|
neighborCaptor.capture());
|
||||||
|
|
||||||
|
when(mTetherConfig.isBpfOffloadEnabled()).thenReturn(usingBpfOffload);
|
||||||
|
when(mTetherConfig.useLegacyDhcpServer()).thenReturn(usingLegacyDhcp);
|
||||||
mIpServer = new IpServer(
|
mIpServer = new IpServer(
|
||||||
IFACE_NAME, mLooper.getLooper(), interfaceType, mSharedLog, mNetd, mBpfCoordinator,
|
IFACE_NAME, mLooper.getLooper(), interfaceType, mSharedLog, mNetd, mBpfCoordinator,
|
||||||
mCallback, usingLegacyDhcp, usingBpfOffload, mAddressCoordinator, mDependencies);
|
mCallback, mTetherConfig, mAddressCoordinator, mDependencies);
|
||||||
mIpServer.start();
|
mIpServer.start();
|
||||||
mNeighborEventConsumer = neighborCaptor.getValue();
|
mNeighborEventConsumer = neighborCaptor.getValue();
|
||||||
|
|
||||||
@@ -281,7 +283,8 @@ public class IpServerTest {
|
|||||||
when(mSharedLog.forSubComponent(anyString())).thenReturn(mSharedLog);
|
when(mSharedLog.forSubComponent(anyString())).thenReturn(mSharedLog);
|
||||||
when(mAddressCoordinator.requestDownstreamAddress(any(), anyBoolean())).thenReturn(
|
when(mAddressCoordinator.requestDownstreamAddress(any(), anyBoolean())).thenReturn(
|
||||||
mTestAddress);
|
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() {
|
mBpfDeps = new BpfCoordinator.Dependencies() {
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -360,8 +363,8 @@ public class IpServerTest {
|
|||||||
when(mDependencies.getIpNeighborMonitor(any(), any(), any()))
|
when(mDependencies.getIpNeighborMonitor(any(), any(), any()))
|
||||||
.thenReturn(mIpNeighborMonitor);
|
.thenReturn(mIpNeighborMonitor);
|
||||||
mIpServer = new IpServer(IFACE_NAME, mLooper.getLooper(), TETHERING_BLUETOOTH, mSharedLog,
|
mIpServer = new IpServer(IFACE_NAME, mLooper.getLooper(), TETHERING_BLUETOOTH, mSharedLog,
|
||||||
mNetd, mBpfCoordinator, mCallback, false /* usingLegacyDhcp */,
|
mNetd, mBpfCoordinator, mCallback, mTetherConfig, mAddressCoordinator,
|
||||||
DEFAULT_USING_BPF_OFFLOAD, mAddressCoordinator, mDependencies);
|
mDependencies);
|
||||||
mIpServer.start();
|
mIpServer.start();
|
||||||
mLooper.dispatchAll();
|
mLooper.dispatchAll();
|
||||||
verify(mCallback).updateInterfaceState(
|
verify(mCallback).updateInterfaceState(
|
||||||
|
|||||||
@@ -95,7 +95,6 @@ public class TetheringConfigurationTest {
|
|||||||
@Mock private ModuleInfo mMi;
|
@Mock private ModuleInfo mMi;
|
||||||
private Context mMockContext;
|
private Context mMockContext;
|
||||||
private boolean mHasTelephonyManager;
|
private boolean mHasTelephonyManager;
|
||||||
private boolean mEnableLegacyDhcpServer;
|
|
||||||
private MockitoSession mMockingSession;
|
private MockitoSession mMockingSession;
|
||||||
private MockContentResolver mContentResolver;
|
private MockContentResolver mContentResolver;
|
||||||
|
|
||||||
@@ -186,7 +185,6 @@ public class TetheringConfigurationTest {
|
|||||||
|
|
||||||
mHasTelephonyManager = true;
|
mHasTelephonyManager = true;
|
||||||
mMockContext = new MockContext(mContext);
|
mMockContext = new MockContext(mContext);
|
||||||
mEnableLegacyDhcpServer = false;
|
|
||||||
|
|
||||||
mContentResolver = new MockContentResolver(mMockContext);
|
mContentResolver = new MockContentResolver(mMockContext);
|
||||||
mContentResolver.addProvider(Settings.AUTHORITY, new FakeSettingsProvider());
|
mContentResolver.addProvider(Settings.AUTHORITY, new FakeSettingsProvider());
|
||||||
@@ -398,7 +396,7 @@ public class TetheringConfigurationTest {
|
|||||||
|
|
||||||
final TetheringConfiguration enableByRes =
|
final TetheringConfiguration enableByRes =
|
||||||
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
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(
|
when(mResources.getBoolean(R.bool.config_tether_enable_legacy_dhcp_server)).thenReturn(
|
||||||
false);
|
false);
|
||||||
@@ -408,7 +406,7 @@ public class TetheringConfigurationTest {
|
|||||||
|
|
||||||
final TetheringConfiguration enableByDevConfig =
|
final TetheringConfiguration enableByDevConfig =
|
||||||
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
||||||
assertTrue(enableByDevConfig.enableLegacyDhcpServer);
|
assertTrue(enableByDevConfig.useLegacyDhcpServer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -422,7 +420,7 @@ public class TetheringConfigurationTest {
|
|||||||
final TetheringConfiguration cfg =
|
final TetheringConfiguration cfg =
|
||||||
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
|
||||||
|
|
||||||
assertFalse(cfg.enableLegacyDhcpServer);
|
assertFalse(cfg.useLegacyDhcpServer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user