Add IpManager.ProvisioningRequest class
am: 93b1a36e31
* commit '93b1a36e31b42c5b33a0164f2832ab9aa12d9a00':
Add IpManager.ProvisioningRequest class
This commit is contained in:
@@ -115,6 +115,64 @@ public class IpManager extends StateMachine {
|
|||||||
public void onReachabilityLost(String logMsg) {}
|
public void onReachabilityLost(String logMsg) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class encapsulates parameters to be passed to
|
||||||
|
* IpManager#startProvisioning(). A defensive copy is made by IpManager
|
||||||
|
* and the values specified herein are in force until IpManager#stop()
|
||||||
|
* is called.
|
||||||
|
*
|
||||||
|
* Example use:
|
||||||
|
*
|
||||||
|
* final ProvisioningConfiguration config =
|
||||||
|
* mIpManager.buildProvisioningConfiguration()
|
||||||
|
* .withPreDhcpAction()
|
||||||
|
* .build();
|
||||||
|
* mIpManager.startProvisioning(config);
|
||||||
|
* ...
|
||||||
|
* mIpManager.stop();
|
||||||
|
*
|
||||||
|
* The specified provisioning configuration will only be active until
|
||||||
|
* IpManager#stop() is called. Future calls to IpManager#startProvisioning()
|
||||||
|
* must specify the configuration again.
|
||||||
|
*/
|
||||||
|
public static class ProvisioningConfiguration {
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
private ProvisioningConfiguration mConfig = new ProvisioningConfiguration();
|
||||||
|
|
||||||
|
public Builder withoutIpReachabilityMonitor() {
|
||||||
|
mConfig.mUsingIpReachabilityMonitor = false;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder withPreDhcpAction() {
|
||||||
|
mConfig.mRequestedPreDhcpAction = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder withStaticConfiguration(StaticIpConfiguration staticConfig) {
|
||||||
|
mConfig.mStaticIpConfig = staticConfig;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProvisioningConfiguration build() {
|
||||||
|
return new ProvisioningConfiguration(mConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* package */ boolean mUsingIpReachabilityMonitor = true;
|
||||||
|
/* package */ boolean mRequestedPreDhcpAction;
|
||||||
|
/* package */ StaticIpConfiguration mStaticIpConfig;
|
||||||
|
|
||||||
|
public ProvisioningConfiguration() {}
|
||||||
|
|
||||||
|
public ProvisioningConfiguration(ProvisioningConfiguration other) {
|
||||||
|
mUsingIpReachabilityMonitor = other.mUsingIpReachabilityMonitor;
|
||||||
|
mRequestedPreDhcpAction = other.mRequestedPreDhcpAction;
|
||||||
|
mStaticIpConfig = other.mStaticIpConfig;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static final int CMD_STOP = 1;
|
private static final int CMD_STOP = 1;
|
||||||
private static final int CMD_START = 2;
|
private static final int CMD_START = 2;
|
||||||
private static final int CMD_CONFIRM = 3;
|
private static final int CMD_CONFIRM = 3;
|
||||||
@@ -145,7 +203,7 @@ public class IpManager extends StateMachine {
|
|||||||
private IpReachabilityMonitor mIpReachabilityMonitor;
|
private IpReachabilityMonitor mIpReachabilityMonitor;
|
||||||
private BaseDhcpStateMachine mDhcpStateMachine;
|
private BaseDhcpStateMachine mDhcpStateMachine;
|
||||||
private DhcpResults mDhcpResults;
|
private DhcpResults mDhcpResults;
|
||||||
private StaticIpConfiguration mStaticIpConfig;
|
private ProvisioningConfiguration mConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Member variables accessed both from within the StateMachine thread
|
* Member variables accessed both from within the StateMachine thread
|
||||||
@@ -211,14 +269,24 @@ public class IpManager extends StateMachine {
|
|||||||
mNetlinkTracker = null;
|
mNetlinkTracker = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startProvisioning(StaticIpConfiguration staticIpConfig) {
|
public static ProvisioningConfiguration.Builder buildProvisioningConfiguration() {
|
||||||
|
return new ProvisioningConfiguration.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startProvisioning(ProvisioningConfiguration req) {
|
||||||
getInterfaceIndex();
|
getInterfaceIndex();
|
||||||
sendMessage(CMD_START, staticIpConfig);
|
sendMessage(CMD_START, new ProvisioningConfiguration(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Delete this.
|
||||||
|
public void startProvisioning(StaticIpConfiguration staticIpConfig) {
|
||||||
|
startProvisioning(buildProvisioningConfiguration()
|
||||||
|
.withStaticConfiguration(staticIpConfig)
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startProvisioning() {
|
public void startProvisioning() {
|
||||||
getInterfaceIndex();
|
startProvisioning(new ProvisioningConfiguration());
|
||||||
sendMessage(CMD_START);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
@@ -296,7 +364,7 @@ public class IpManager extends StateMachine {
|
|||||||
private void resetLinkProperties() {
|
private void resetLinkProperties() {
|
||||||
mNetlinkTracker.clearLinkProperties();
|
mNetlinkTracker.clearLinkProperties();
|
||||||
mDhcpResults = null;
|
mDhcpResults = null;
|
||||||
mStaticIpConfig = null;
|
mConfiguration = null;
|
||||||
|
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
mLinkProperties = new LinkProperties();
|
mLinkProperties = new LinkProperties();
|
||||||
@@ -533,7 +601,7 @@ public class IpManager extends StateMachine {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_START:
|
case CMD_START:
|
||||||
mStaticIpConfig = (StaticIpConfiguration) msg.obj;
|
mConfiguration = (ProvisioningConfiguration) msg.obj;
|
||||||
transitionTo(mStartedState);
|
transitionTo(mStartedState);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -591,23 +659,23 @@ public class IpManager extends StateMachine {
|
|||||||
Log.e(mTag, "Unable to change interface settings: " + ie);
|
Log.e(mTag, "Unable to change interface settings: " + ie);
|
||||||
}
|
}
|
||||||
|
|
||||||
mIpReachabilityMonitor = new IpReachabilityMonitor(
|
if (mConfiguration.mUsingIpReachabilityMonitor) {
|
||||||
mContext,
|
mIpReachabilityMonitor = new IpReachabilityMonitor(
|
||||||
mInterfaceName,
|
mContext,
|
||||||
new IpReachabilityMonitor.Callback() {
|
mInterfaceName,
|
||||||
@Override
|
new IpReachabilityMonitor.Callback() {
|
||||||
public void notifyLost(InetAddress ip, String logMsg) {
|
@Override
|
||||||
if (mCallback.usingIpReachabilityMonitor()) {
|
public void notifyLost(InetAddress ip, String logMsg) {
|
||||||
mCallback.onReachabilityLost(logMsg);
|
mCallback.onReachabilityLost(logMsg);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
// If we have a StaticIpConfiguration attempt to apply it and
|
// If we have a StaticIpConfiguration attempt to apply it and
|
||||||
// handle the result accordingly.
|
// handle the result accordingly.
|
||||||
if (mStaticIpConfig != null) {
|
if (mConfiguration.mStaticIpConfig != null) {
|
||||||
if (applyStaticIpConfig()) {
|
if (applyStaticIpConfig()) {
|
||||||
handleIPv4Success(new DhcpResults(mStaticIpConfig));
|
handleIPv4Success(new DhcpResults(mConfiguration.mStaticIpConfig));
|
||||||
} else {
|
} else {
|
||||||
if (VDBG) { Log.d(mTag, "onProvisioningFailure()"); }
|
if (VDBG) { Log.d(mTag, "onProvisioningFailure()"); }
|
||||||
mCallback.onProvisioningFailure(getLinkProperties());
|
mCallback.onProvisioningFailure(getLinkProperties());
|
||||||
@@ -623,8 +691,10 @@ public class IpManager extends StateMachine {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exit() {
|
public void exit() {
|
||||||
mIpReachabilityMonitor.stop();
|
if (mIpReachabilityMonitor != null) {
|
||||||
mIpReachabilityMonitor = null;
|
mIpReachabilityMonitor.stop();
|
||||||
|
mIpReachabilityMonitor = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (mDhcpStateMachine != null) {
|
if (mDhcpStateMachine != null) {
|
||||||
mDhcpStateMachine.sendMessage(DhcpClient.CMD_STOP_DHCP);
|
mDhcpStateMachine.sendMessage(DhcpClient.CMD_STOP_DHCP);
|
||||||
@@ -650,7 +720,7 @@ public class IpManager extends StateMachine {
|
|||||||
// that both probes (a) on-link neighbors and (b) does
|
// that both probes (a) on-link neighbors and (b) does
|
||||||
// a DHCPv4 RENEW. We used to do this on Wi-Fi framework
|
// a DHCPv4 RENEW. We used to do this on Wi-Fi framework
|
||||||
// roams.
|
// roams.
|
||||||
if (mCallback.usingIpReachabilityMonitor()) {
|
if (mIpReachabilityMonitor != null) {
|
||||||
mIpReachabilityMonitor.probeAll();
|
mIpReachabilityMonitor.probeAll();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -679,7 +749,11 @@ public class IpManager extends StateMachine {
|
|||||||
|
|
||||||
case DhcpClient.CMD_PRE_DHCP_ACTION:
|
case DhcpClient.CMD_PRE_DHCP_ACTION:
|
||||||
if (VDBG) { Log.d(mTag, "onPreDhcpAction()"); }
|
if (VDBG) { Log.d(mTag, "onPreDhcpAction()"); }
|
||||||
mCallback.onPreDhcpAction();
|
if (mConfiguration.mRequestedPreDhcpAction) {
|
||||||
|
mCallback.onPreDhcpAction();
|
||||||
|
} else {
|
||||||
|
sendMessage(EVENT_PRE_DHCP_ACTION_COMPLETE);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DhcpClient.CMD_POST_DHCP_ACTION: {
|
case DhcpClient.CMD_POST_DHCP_ACTION: {
|
||||||
@@ -717,7 +791,7 @@ public class IpManager extends StateMachine {
|
|||||||
|
|
||||||
private boolean applyStaticIpConfig() {
|
private boolean applyStaticIpConfig() {
|
||||||
final InterfaceConfiguration ifcg = new InterfaceConfiguration();
|
final InterfaceConfiguration ifcg = new InterfaceConfiguration();
|
||||||
ifcg.setLinkAddress(mStaticIpConfig.ipAddress);
|
ifcg.setLinkAddress(mConfiguration.mStaticIpConfig.ipAddress);
|
||||||
ifcg.setInterfaceUp();
|
ifcg.setInterfaceUp();
|
||||||
try {
|
try {
|
||||||
mNwService.setInterfaceConfig(mInterfaceName, ifcg);
|
mNwService.setInterfaceConfig(mInterfaceName, ifcg);
|
||||||
|
|||||||
Reference in New Issue
Block a user