Search in sources :

Example 1 with State

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

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 2 with State

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

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 3 with State

use of android.net.NetworkInfo.State in project platform_frameworks_base by android.

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 4 with State

use of android.net.NetworkInfo.State in project platform_frameworks_base by android.

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 5 with State

use of android.net.NetworkInfo.State in project KJFrameForAndroid by kymjs.

the class SystemTool method isWiFi.

/**
     * 判断是否为wifi联网
     */
public static boolean isWiFi(Context cxt) {
    ConnectivityManager cm = (ConnectivityManager) cxt.getSystemService(Context.CONNECTIVITY_SERVICE);
    // wifi的状态:ConnectivityManager.TYPE_WIFI
    // 3G的状态:ConnectivityManager.TYPE_MOBILE
    State state = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
    return State.CONNECTED == state;
}
Also used : ConnectivityManager(android.net.ConnectivityManager) State(android.net.NetworkInfo.State)

Aggregations

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