Methods Summary |
---|
public java.lang.String | getFailureReason()Fetch the reason for network state transition failure
return mReason;
|
public java.util.List | getTransitionStates()Fetch the different network state transitions
return mStateDepository;
|
public java.lang.String | printStates()Print the network state
StringBuilder stateBuilder = new StringBuilder();
for (int i = 0; i < mStateDepository.size(); i++) {
stateBuilder.append(" ").append(mStateDepository.get(i).toString()).append("->");
}
return stateBuilder.toString();
|
public void | recordState(android.net.NetworkInfo.State currentState)Record the current state of the network
mStateDepository.add(currentState);
|
public void | resetNetworkState()Reinitialize the network state
mStateDepository.clear();
mTransitionDirection = StateTransitionDirection.DO_NOTHING;
mTransitionTarget = State.UNKNOWN;
|
public void | setStateTransitionCriteria(android.net.NetworkInfo.State initState, com.android.bandwidthtest.NetworkState$StateTransitionDirection transitionDir, android.net.NetworkInfo.State targetState)Set the transition criteria
if (!mStateDepository.isEmpty()) {
mStateDepository.clear();
}
mStateDepository.add(initState);
mTransitionDirection = transitionDir;
mTransitionTarget = targetState;
Log.v(LOG_TAG, "setStateTransitionCriteria: " + printStates());
|
public java.lang.String | toString(){@inheritDoc}
StringBuilder builder = new StringBuilder();
builder.append("mTransitionDirection: ").append(mTransitionDirection.toString()).
append("; ").append("states:").
append(printStates()).append("; ");
return builder.toString();
|
private boolean | validateNetworkConnection()Verify the network state to connection
StringBuffer str = new StringBuffer("States ");
str.append(printStates());
if (mStateDepository.get(0) != State.DISCONNECTED) {
str.append(String.format(" Initial state should be DISCONNECTED, but it is %s.",
mStateDepository.get(0)));
mReason = str.toString();
return false;
}
State lastState = mStateDepository.get(mStateDepository.size() - 1);
if ( lastState != mTransitionTarget) {
str.append(String.format(" Last state should be %s, but it is %s", mTransitionTarget,
lastState));
mReason = str.toString();
return false;
}
for (int i = 1; i < mStateDepository.size(); i++) {
State preState = mStateDepository.get(i-1);
State curState = mStateDepository.get(i);
if ((preState == State.DISCONNECTED) && ((curState == State.CONNECTING) ||
(curState == State.CONNECTED) || (curState == State.DISCONNECTED))) {
continue;
} else if ((preState == State.CONNECTING) && (curState == State.CONNECTED)) {
continue;
} else if ((preState == State.CONNECTED) && (curState == State.CONNECTED)) {
continue;
} else {
str.append(String.format(" Transition state from %s to %s is not valid.",
preState.toString(), curState.toString()));
mReason = str.toString();
return false;
}
}
mReason = str.toString();
return true;
|
private boolean | validateNetworkDisconnection()Verify the network state to disconnection
// Transition from CONNECTED -> DISCONNECTED: CONNECTED->DISCONNECTING->DISCONNECTED
StringBuffer str = new StringBuffer ("States: ");
str.append(printStates());
if (mStateDepository.get(0) != State.CONNECTED) {
str.append(String.format(" Initial state should be CONNECTED, but it is %s.",
mStateDepository.get(0)));
mReason = str.toString();
return false;
}
State lastState = mStateDepository.get(mStateDepository.size() - 1);
if ( lastState != mTransitionTarget) {
str.append(String.format(" Last state should be DISCONNECTED, but it is %s",
lastState));
mReason = str.toString();
return false;
}
for (int i = 1; i < mStateDepository.size() - 1; i++) {
State preState = mStateDepository.get(i-1);
State curState = mStateDepository.get(i);
if ((preState == State.CONNECTED) && ((curState == State.DISCONNECTING) ||
(curState == State.DISCONNECTED))) {
continue;
} else if ((preState == State.DISCONNECTING) && (curState == State.DISCONNECTED)) {
continue;
} else if ((preState == State.DISCONNECTED) && (curState == State.DISCONNECTED)) {
continue;
} else {
str.append(String.format(" Transition state from %s to %s is not valid",
preState.toString(), curState.toString()));
mReason = str.toString();
return false;
}
}
mReason = str.toString();
return true;
|
private boolean | validateNetworkStates()Verify that network states are valid
if (mStateDepository.isEmpty()) {
Log.v(LOG_TAG, "no state is recorded");
mReason = "no state is recorded.";
return false;
} else if (mStateDepository.size() > 1) {
Log.v(LOG_TAG, "no broadcast is expected, instead broadcast is probably received");
mReason = "no broadcast is expected, instead broadcast is probably received";
return false;
} else if (mStateDepository.get(0) != mTransitionTarget) {
Log.v(LOG_TAG, String.format("%s is expected, but it is %s",
mTransitionTarget.toString(),
mStateDepository.get(0).toString()));
mReason = String.format("%s is expected, but it is %s",
mTransitionTarget.toString(),
mStateDepository.get(0).toString());
return false;
}
return true;
|
public boolean | validateStateTransition()Verify the state transition
Log.v(LOG_TAG, String.format("Print state depository: %s", printStates()));
switch (mTransitionDirection) {
case DO_NOTHING:
Log.v(LOG_TAG, "No direction requested, verifying network states");
return validateNetworkStates();
case TO_CONNECTION:
Log.v(LOG_TAG, "Transition to CONNECTED");
return validateNetworkConnection();
case TO_DISCONNECTION:
Log.v(LOG_TAG, "Transition to DISCONNECTED");
return validateNetworkDisconnection();
default:
Log.e(LOG_TAG, "Invalid transition direction.");
return false;
}
|