Merge "Support static address configuration"

This commit is contained in:
Mark Chien
2020-03-17 13:26:09 +00:00
committed by Gerrit Code Review
7 changed files with 310 additions and 38 deletions

View File

@@ -35,6 +35,7 @@ import android.net.MacAddress;
import android.net.RouteInfo;
import android.net.TetheredClient;
import android.net.TetheringManager;
import android.net.TetheringRequestParcel;
import android.net.dhcp.DhcpLeaseParcelable;
import android.net.dhcp.DhcpServerCallbacks;
import android.net.dhcp.DhcpServingParamsParcel;
@@ -243,6 +244,10 @@ public class IpServer extends StateMachine {
private IDhcpServer mDhcpServer;
private RaParams mLastRaParams;
private LinkAddress mIpv4Address;
private LinkAddress mStaticIpv4ServerAddr;
private LinkAddress mStaticIpv4ClientAddr;
@NonNull
private List<TetheredClient> mDhcpLeases = Collections.emptyList();
@@ -547,6 +552,8 @@ public class IpServer extends StateMachine {
// into calls to InterfaceController, shared with startIPv4().
mInterfaceCtrl.clearIPv4Address();
mIpv4Address = null;
mStaticIpv4ServerAddr = null;
mStaticIpv4ClientAddr = null;
}
private boolean configureIPv4(boolean enabled) {
@@ -557,7 +564,10 @@ public class IpServer extends StateMachine {
final Inet4Address srvAddr;
int prefixLen = 0;
try {
if (mInterfaceType == TetheringManager.TETHERING_USB
if (mStaticIpv4ServerAddr != null) {
srvAddr = (Inet4Address) mStaticIpv4ServerAddr.getAddress();
prefixLen = mStaticIpv4ServerAddr.getPrefixLength();
} else if (mInterfaceType == TetheringManager.TETHERING_USB
|| mInterfaceType == TetheringManager.TETHERING_NCM) {
srvAddr = (Inet4Address) parseNumericAddress(USB_NEAR_IFACE_ADDR);
prefixLen = USB_PREFIX_LENGTH;
@@ -602,10 +612,6 @@ public class IpServer extends StateMachine {
return false;
}
if (!configureDhcp(enabled, srvAddr, prefixLen)) {
return false;
}
// Directly-connected route.
final IpPrefix ipv4Prefix = new IpPrefix(mIpv4Address.getAddress(),
mIpv4Address.getPrefixLength());
@@ -617,7 +623,8 @@ public class IpServer extends StateMachine {
mLinkProperties.removeLinkAddress(mIpv4Address);
mLinkProperties.removeRoute(route);
}
return true;
return configureDhcp(enabled, srvAddr, prefixLen);
}
private String getRandomWifiIPv4Address() {
@@ -937,6 +944,13 @@ public class IpServer extends StateMachine {
mLinkProperties.setInterfaceName(mIfaceName);
}
private void maybeConfigureStaticIp(final TetheringRequestParcel request) {
if (request == null) return;
mStaticIpv4ServerAddr = request.localIPv4Address;
mStaticIpv4ClientAddr = request.staticClientAddress;
}
class InitialState extends State {
@Override
public void enter() {
@@ -951,9 +965,11 @@ public class IpServer extends StateMachine {
mLastError = TetheringManager.TETHER_ERROR_NO_ERROR;
switch (message.arg1) {
case STATE_LOCAL_ONLY:
maybeConfigureStaticIp((TetheringRequestParcel) message.obj);
transitionTo(mLocalHotspotState);
break;
case STATE_TETHERED:
maybeConfigureStaticIp((TetheringRequestParcel) message.obj);
transitionTo(mTetheredState);
break;
default: