Merge "Fix state transition verification." into klp-dev

This commit is contained in:
Xia Wang
2014-03-18 22:10:32 +00:00
committed by Android (Google) Code Review

View File

@ -101,9 +101,10 @@ public class NetworkState {
} }
/* /*
* Transition from CONNECTED -> DISCONNECTED: * Verifies state transition from CONNECTED->...-> DISCONNECTED.
* CONNECTED->DISCONNECTING->DISCONNECTED *
* return false if any state transition is not valid and save a message in mReason * returns false if initial state or target state is not correct, or if there is
* any transition from DISCONNECTING/DISCONNECTED -> CONNECTED.
*/ */
public boolean transitToDisconnection () { public boolean transitToDisconnection () {
mReason = "states: " + printStates(); mReason = "states: " + printStates();
@ -120,13 +121,13 @@ public class NetworkState {
for (int i = 1; i < mStateDepository.size() - 1; i++) { for (int i = 1; i < mStateDepository.size() - 1; i++) {
State preState = mStateDepository.get(i-1); State preState = mStateDepository.get(i-1);
State curState = mStateDepository.get(i); State curState = mStateDepository.get(i);
if ((preState == State.CONNECTED) && ((curState == State.DISCONNECTING) || if (preState == curState) {
continue;
} else if ((preState == State.CONNECTED) && ((curState == State.DISCONNECTING) ||
(curState == State.DISCONNECTED))) { (curState == State.DISCONNECTED))) {
continue; continue;
} else if ((preState == State.DISCONNECTING) && (curState == State.DISCONNECTED)) { } else if ((preState == State.DISCONNECTING) && (curState == State.DISCONNECTED)) {
continue; continue;
} else if ((preState == State.DISCONNECTED) && (curState == State.DISCONNECTED)) {
continue;
} else { } else {
mReason += " Transition state from " + preState.toString() + " to " + mReason += " Transition state from " + preState.toString() + " to " +
curState.toString() + " is not valid."; curState.toString() + " is not valid.";
@ -136,7 +137,12 @@ public class NetworkState {
return true; return true;
} }
// DISCONNECTED->CONNECTING->CONNECTED /*
* Verifies state transition from DISCONNECTED->...-> CONNECTED.
*
* returns false if initial state or target state is not correct, or if there is
* any transition from CONNECED -> DISCONNECTED.
*/
public boolean transitToConnection() { public boolean transitToConnection() {
mReason = "states: " + printStates(); mReason = "states: " + printStates();
if (mStateDepository.get(0) != State.DISCONNECTED) { if (mStateDepository.get(0) != State.DISCONNECTED) {
@ -152,14 +158,15 @@ public class NetworkState {
for (int i = 1; i < mStateDepository.size(); i++) { for (int i = 1; i < mStateDepository.size(); i++) {
State preState = mStateDepository.get(i-1); State preState = mStateDepository.get(i-1);
State curState = mStateDepository.get(i); State curState = mStateDepository.get(i);
if (preState == curState) {
continue;
}
if ((preState == State.DISCONNECTED) && ((curState == State.CONNECTING) || if ((preState == State.DISCONNECTED) && ((curState == State.CONNECTING) ||
(curState == State.CONNECTED) || (curState == State.DISCONNECTED))) { (curState == State.CONNECTED))) {
continue; continue;
} else if ((preState == State.CONNECTING) && (curState == State.CONNECTED)) { } else if ((preState == State.CONNECTING) && (curState == State.CONNECTED)) {
continue; continue;
} else if ((preState == State.CONNECTED) && (curState == State.CONNECTED)) { } else {
continue;
} else {
mReason += " Transition state from " + preState.toString() + " to " + mReason += " Transition state from " + preState.toString() + " to " +
curState.toString() + " is not valid."; curState.toString() + " is not valid.";
return false; return false;