Search in sources :

Example 6 with State

use of android.net.NetworkInfo.State in project android_frameworks_base by DirtyUnicorns.

the class NetworkState method validateNetworkConnection.

/**
     * Verify the network state to connection
     * @return false if any of the state transitions were not valid
     */
private boolean validateNetworkConnection() {
    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;
}
Also used : State(android.net.NetworkInfo.State)

Example 7 with State

use of android.net.NetworkInfo.State in project android_frameworks_base by DirtyUnicorns.

the class NetworkState method validateNetworkDisconnection.

/**
     * Verify the network state to disconnection
     * @return false if any of the state transitions were not valid
     */
private boolean validateNetworkDisconnection() {
    // 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;
}
Also used : State(android.net.NetworkInfo.State)

Example 8 with State

use of android.net.NetworkInfo.State in project android_frameworks_base by ResurrectionRemix.

the class NetworkState method validateNetworkConnection.

/**
     * Verify the network state to connection
     * @return false if any of the state transitions were not valid
     */
private boolean validateNetworkConnection() {
    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;
}
Also used : State(android.net.NetworkInfo.State)

Example 9 with State

use of android.net.NetworkInfo.State in project android_frameworks_base by crdroidandroid.

the class NetworkState method validateNetworkDisconnection.

/**
     * Verify the network state to disconnection
     * @return false if any of the state transitions were not valid
     */
private boolean validateNetworkDisconnection() {
    // 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;
}
Also used : State(android.net.NetworkInfo.State)

Example 10 with State

use of android.net.NetworkInfo.State in project android_frameworks_base by ParanoidAndroid.

the class NetworkState method transitToDisconnection.

/*
     * Transition from CONNECTED -> DISCONNECTED:
     *    CONNECTED->DISCONNECTING->DISCONNECTED
     * return false if any state transition is not valid and save a message in mReason
     */
public boolean transitToDisconnection() {
    mReason = "states: " + printStates();
    if (mStateDepository.get(0) != State.CONNECTED) {
        mReason += " initial state should be CONNECTED, but it is " + mStateDepository.get(0) + ".";
        return false;
    }
    State lastState = mStateDepository.get(mStateDepository.size() - 1);
    if (lastState != mTransitionTarget) {
        mReason += " the last state should be DISCONNECTED, but it is " + lastState;
        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 {
            mReason += " Transition state from " + preState.toString() + " to " + curState.toString() + " is not valid.";
            return false;
        }
    }
    return true;
}
Also used : State(android.net.NetworkInfo.State)

Aggregations

State (android.net.NetworkInfo.State)17 ConnectivityManager (android.net.ConnectivityManager)3 NetworkInfo (android.net.NetworkInfo)2