use of android.net.NetworkInfo.State in project android_frameworks_base by ParanoidAndroid.
the class NetworkState method transitToConnection.
// DISCONNECTED->CONNECTING->CONNECTED
public boolean transitToConnection() {
mReason = "states: " + printStates();
if (mStateDepository.get(0) != State.DISCONNECTED) {
mReason += " initial state should be DISCONNECTED, but it is " + mStateDepository.get(0) + ".";
return false;
}
State lastState = mStateDepository.get(mStateDepository.size() - 1);
if (lastState != mTransitionTarget) {
mReason += "The last state should be " + mTransitionTarget + ", but it is " + lastState;
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 {
mReason += " Transition state from " + preState.toString() + " to " + curState.toString() + " is not valid.";
return false;
}
}
return true;
}
use of android.net.NetworkInfo.State in project android_frameworks_base by AOSPA.
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;
}
use of android.net.NetworkInfo.State in project android_frameworks_base by AOSPA.
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;
}
use of android.net.NetworkInfo.State in project android_frameworks_base by ResurrectionRemix.
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;
}
use of android.net.NetworkInfo.State in project teaTime by ancfdy.
the class AppNetworkMgr method isNetworkConnected.
/**
* 判断网络是否连接
*
* @param context 上下文
* @return boolean 网络连接状态
*/
public static boolean isNetworkConnected(Context context) {
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
//获取连接对象
if (mNetworkInfo != null) {
//判断是TYPE_MOBILE网络
if (ConnectivityManager.TYPE_MOBILE == mNetworkInfo.getType()) {
AppLogMessageMgr.i("AppNetworkMgr", "网络连接类型为:TYPE_MOBILE");
//判断移动网络连接状态
State STATE_MOBILE = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
if (STATE_MOBILE == State.CONNECTED) {
AppLogMessageMgr.i("AppNetworkMgrd", "网络连接类型为:TYPE_MOBILE, 网络连接状态CONNECTED成功!");
return mNetworkInfo.isAvailable();
}
}
//判断是TYPE_WIFI网络
if (ConnectivityManager.TYPE_WIFI == mNetworkInfo.getType()) {
AppLogMessageMgr.i("AppNetworkMgr", "网络连接类型为:TYPE_WIFI");
//判断WIFI网络状态
State STATE_WIFI = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
if (STATE_WIFI == State.CONNECTED) {
AppLogMessageMgr.i("AppNetworkMgr", "网络连接类型为:TYPE_WIFI, 网络连接状态CONNECTED成功!");
return mNetworkInfo.isAvailable();
}
}
}
}
return false;
}
Aggregations