Duplicate DhcpStateMachine public constants into DhcpClient

This is so we can ultimately delete DhcpStateMachine altogether.

Bug: 24837343
Bug: 26991160
Change-Id: If116639e5f72c97cfc67f748dc5f6433dccd9cf0
This commit is contained in:
Erik Kline
2016-02-12 00:17:02 +09:00
parent 989594638a
commit 3b74289fdf
2 changed files with 60 additions and 40 deletions

View File

@@ -29,7 +29,6 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.net.DhcpResults;
import android.net.BaseDhcpStateMachine;
import android.net.DhcpStateMachine;
import android.net.InterfaceConfiguration;
import android.net.LinkAddress;
import android.net.NetworkUtils;
@@ -105,12 +104,35 @@ public class DhcpClient extends BaseDhcpStateMachine {
// t=0, t=2, t=6, t=14, t=30, allowing for 10% jitter.
private static final int DHCP_TIMEOUT_MS = 36 * SECONDS;
private static final int PUBLIC_BASE = Protocol.BASE_DHCP;
/* Commands from controller to start/stop DHCP */
public static final int CMD_START_DHCP = PUBLIC_BASE + 1;
public static final int CMD_STOP_DHCP = PUBLIC_BASE + 2;
public static final int CMD_RENEW_DHCP = PUBLIC_BASE + 3;
/* Notification from DHCP state machine prior to DHCP discovery/renewal */
public static final int CMD_PRE_DHCP_ACTION = PUBLIC_BASE + 4;
/* Notification from DHCP state machine post DHCP discovery/renewal. Indicates
* success/failure */
public static final int CMD_POST_DHCP_ACTION = PUBLIC_BASE + 5;
/* Notification from DHCP state machine before quitting */
public static final int CMD_ON_QUIT = PUBLIC_BASE + 6;
/* Command from controller to indicate DHCP discovery/renewal can continue
* after pre DHCP action is complete */
public static final int CMD_PRE_DHCP_ACTION_COMPLETE = PUBLIC_BASE + 7;
/* Message.arg1 arguments to CMD_POST_DHCP notification */
public static final int DHCP_SUCCESS = 1;
public static final int DHCP_FAILURE = 2;
// Messages.
private static final int BASE = Protocol.BASE_DHCP + 100;
private static final int CMD_KICK = BASE + 1;
private static final int CMD_RECEIVED_PACKET = BASE + 2;
private static final int CMD_TIMEOUT = BASE + 3;
private static final int CMD_ONESHOT_TIMEOUT = BASE + 4;
private static final int PRIVATE_BASE = Protocol.BASE_DHCP + 100;
private static final int CMD_KICK = PRIVATE_BASE + 1;
private static final int CMD_RECEIVED_PACKET = PRIVATE_BASE + 2;
private static final int CMD_TIMEOUT = PRIVATE_BASE + 3;
private static final int CMD_ONESHOT_TIMEOUT = PRIVATE_BASE + 4;
// DHCP parameters that we request.
private static final byte[] REQUESTED_PARAMS = new byte[] {
@@ -210,7 +232,7 @@ public class DhcpClient extends BaseDhcpStateMachine {
// Used to time out PacketRetransmittingStates.
mTimeoutIntent = createStateMachineCommandIntent("TIMEOUT", CMD_TIMEOUT);
// Used to schedule DHCP renews.
mRenewIntent = createStateMachineCommandIntent("RENEW", DhcpStateMachine.CMD_RENEW_DHCP);
mRenewIntent = createStateMachineCommandIntent("RENEW", CMD_RENEW_DHCP);
// Used to tell the caller when its request (CMD_START_DHCP or CMD_RENEW_DHCP) timed out.
// TODO: when the legacy DHCP client is gone, make the client fully asynchronous and
// remove this.
@@ -437,13 +459,12 @@ public class DhcpClient extends BaseDhcpStateMachine {
}
private void notifySuccess() {
mController.sendMessage(DhcpStateMachine.CMD_POST_DHCP_ACTION,
DhcpStateMachine.DHCP_SUCCESS, 0, new DhcpResults(mDhcpLease));
mController.sendMessage(
CMD_POST_DHCP_ACTION, DHCP_SUCCESS, 0, new DhcpResults(mDhcpLease));
}
private void notifyFailure() {
mController.sendMessage(DhcpStateMachine.CMD_POST_DHCP_ACTION,
DhcpStateMachine.DHCP_FAILURE, 0, null);
mController.sendMessage(CMD_POST_DHCP_ACTION, DHCP_FAILURE, 0, null);
}
private void clearDhcpState() {
@@ -465,7 +486,7 @@ public class DhcpClient extends BaseDhcpStateMachine {
protected void onQuitting() {
Log.d(TAG, "onQuitting");
mController.sendMessage(DhcpStateMachine.CMD_ON_QUIT);
mController.sendMessage(CMD_ON_QUIT);
}
private void maybeLog(String msg) {
@@ -479,17 +500,17 @@ public class DhcpClient extends BaseDhcpStateMachine {
private String messageName(int what) {
switch (what) {
case DhcpStateMachine.CMD_START_DHCP:
case CMD_START_DHCP:
return "CMD_START_DHCP";
case DhcpStateMachine.CMD_STOP_DHCP:
case CMD_STOP_DHCP:
return "CMD_STOP_DHCP";
case DhcpStateMachine.CMD_RENEW_DHCP:
case CMD_RENEW_DHCP:
return "CMD_RENEW_DHCP";
case DhcpStateMachine.CMD_PRE_DHCP_ACTION:
case CMD_PRE_DHCP_ACTION:
return "CMD_PRE_DHCP_ACTION";
case DhcpStateMachine.CMD_PRE_DHCP_ACTION_COMPLETE:
case CMD_PRE_DHCP_ACTION_COMPLETE:
return "CMD_PRE_DHCP_ACTION_COMPLETE";
case DhcpStateMachine.CMD_POST_DHCP_ACTION:
case CMD_POST_DHCP_ACTION:
return "CMD_POST_DHCP_ACTION";
case CMD_KICK:
return "CMD_KICK";
@@ -532,14 +553,14 @@ public class DhcpClient extends BaseDhcpStateMachine {
@Override
public void enter() {
super.enter();
mController.sendMessage(DhcpStateMachine.CMD_PRE_DHCP_ACTION);
mController.sendMessage(CMD_PRE_DHCP_ACTION);
}
@Override
public boolean processMessage(Message message) {
super.processMessage(message);
switch (message.what) {
case DhcpStateMachine.CMD_PRE_DHCP_ACTION_COMPLETE:
case CMD_PRE_DHCP_ACTION_COMPLETE:
transitionTo(mOtherState);
return HANDLED;
default:
@@ -574,7 +595,7 @@ public class DhcpClient extends BaseDhcpStateMachine {
public boolean processMessage(Message message) {
super.processMessage(message);
switch (message.what) {
case DhcpStateMachine.CMD_START_DHCP:
case CMD_START_DHCP:
scheduleOneshotTimeout();
if (mRegisteredForPreDhcpNotification) {
transitionTo(mWaitBeforeStartState);
@@ -630,7 +651,7 @@ public class DhcpClient extends BaseDhcpStateMachine {
public boolean processMessage(Message message) {
super.processMessage(message);
switch (message.what) {
case DhcpStateMachine.CMD_STOP_DHCP:
case CMD_STOP_DHCP:
transitionTo(mStoppedState);
return HANDLED;
case CMD_ONESHOT_TIMEOUT:
@@ -854,7 +875,7 @@ public class DhcpClient extends BaseDhcpStateMachine {
public boolean processMessage(Message message) {
super.processMessage(message);
switch (message.what) {
case DhcpStateMachine.CMD_RENEW_DHCP:
case CMD_RENEW_DHCP:
if (mRegisteredForPreDhcpNotification) {
transitionTo(mWaitBeforeRenewalState);
} else {

View File

@@ -258,12 +258,12 @@ public class IpManager extends StateMachine {
return "EVENT_PRE_DHCP_ACTION_COMPLETE";
case EVENT_NETLINK_LINKPROPERTIES_CHANGED:
return "EVENT_NETLINK_LINKPROPERTIES_CHANGED";
case DhcpStateMachine.CMD_PRE_DHCP_ACTION:
return "DhcpStateMachine.CMD_PRE_DHCP_ACTION";
case DhcpStateMachine.CMD_POST_DHCP_ACTION:
return "DhcpStateMachine.CMD_POST_DHCP_ACTION";
case DhcpStateMachine.CMD_ON_QUIT:
return "DhcpStateMachine.CMD_ON_QUIT";
case DhcpClient.CMD_PRE_DHCP_ACTION:
return "DhcpClient.CMD_PRE_DHCP_ACTION";
case DhcpClient.CMD_POST_DHCP_ACTION:
return "DhcpClient.CMD_POST_DHCP_ACTION";
case DhcpClient.CMD_ON_QUIT:
return "DhcpClient.CMD_ON_QUIT";
}
return "UNKNOWN:" + Integer.toString(what);
}
@@ -541,7 +541,7 @@ public class IpManager extends StateMachine {
setLinkProperties(assembleLinkProperties());
break;
case DhcpStateMachine.CMD_ON_QUIT:
case DhcpClient.CMD_ON_QUIT:
// Everything is already stopped.
Log.e(mTag, "Unexpected CMD_ON_QUIT (already stopped).");
break;
@@ -565,7 +565,7 @@ public class IpManager extends StateMachine {
@Override
public boolean processMessage(Message msg) {
switch (msg.what) {
case DhcpStateMachine.CMD_ON_QUIT:
case DhcpClient.CMD_ON_QUIT:
mDhcpStateMachine = null;
transitionTo(mStoppedState);
break;
@@ -617,7 +617,7 @@ public class IpManager extends StateMachine {
// Start DHCPv4.
makeDhcpStateMachine();
mDhcpStateMachine.registerForPreDhcpNotification();
mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_START_DHCP);
mDhcpStateMachine.sendMessage(DhcpClient.CMD_START_DHCP);
}
}
@@ -627,7 +627,7 @@ public class IpManager extends StateMachine {
mIpReachabilityMonitor = null;
if (mDhcpStateMachine != null) {
mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_STOP_DHCP);
mDhcpStateMachine.sendMessage(DhcpClient.CMD_STOP_DHCP);
mDhcpStateMachine.doQuit();
}
@@ -660,8 +660,7 @@ public class IpManager extends StateMachine {
// calls completedPreDhcpAction() after provisioning with
// a static IP configuration.
if (mDhcpStateMachine != null) {
mDhcpStateMachine.sendMessage(
DhcpStateMachine.CMD_PRE_DHCP_ACTION_COMPLETE);
mDhcpStateMachine.sendMessage(DhcpClient.CMD_PRE_DHCP_ACTION_COMPLETE);
}
break;
@@ -678,12 +677,12 @@ public class IpManager extends StateMachine {
break;
}
case DhcpStateMachine.CMD_PRE_DHCP_ACTION:
case DhcpClient.CMD_PRE_DHCP_ACTION:
if (VDBG) { Log.d(mTag, "onPreDhcpAction()"); }
mCallback.onPreDhcpAction();
break;
case DhcpStateMachine.CMD_POST_DHCP_ACTION: {
case DhcpClient.CMD_POST_DHCP_ACTION: {
// Note that onPostDhcpAction() is likely to be
// asynchronous, and thus there is no guarantee that we
// will be able to observe any of its effects here.
@@ -692,10 +691,10 @@ public class IpManager extends StateMachine {
final DhcpResults dhcpResults = (DhcpResults) msg.obj;
switch (msg.arg1) {
case DhcpStateMachine.DHCP_SUCCESS:
case DhcpClient.DHCP_SUCCESS:
handleIPv4Success(dhcpResults);
break;
case DhcpStateMachine.DHCP_FAILURE:
case DhcpClient.DHCP_FAILURE:
handleIPv4Failure();
break;
default:
@@ -704,7 +703,7 @@ public class IpManager extends StateMachine {
break;
}
case DhcpStateMachine.CMD_ON_QUIT:
case DhcpClient.CMD_ON_QUIT:
// DHCPv4 quit early for some reason.
Log.e(mTag, "Unexpected CMD_ON_QUIT.");
mDhcpStateMachine = null;