Merge "Support disconnecting while trying to connect."
This commit is contained in:
committed by
Android (Google) Code Review
commit
0741b352db
@@ -257,31 +257,43 @@ public abstract class NetworkAgent extends Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* called to go through our list of requests and see if we're
|
* Called to go through our list of requests and see if we're
|
||||||
* good enough to try connecting.
|
* good enough to try connecting, or if we have gotten worse and
|
||||||
|
* need to disconnect.
|
||||||
*
|
*
|
||||||
* Only does connects - we disconnect when requested via
|
* Once we are registered, does nothing: we disconnect when requested via
|
||||||
* CMD_CHANNEL_DISCONNECTED, generated by either a loss of connection
|
* CMD_CHANNEL_DISCONNECTED, generated by either a loss of connection
|
||||||
* between modules (bearer or ConnectivityService dies) or more commonly
|
* between modules (bearer or ConnectivityService dies) or more commonly
|
||||||
* when the NetworkInfo reports to ConnectivityService it is disconnected.
|
* when the NetworkInfo reports to ConnectivityService it is disconnected.
|
||||||
*/
|
*/
|
||||||
private void evalScores() {
|
private void evalScores() {
|
||||||
if (mConnectionRequested) {
|
synchronized(mLockObj) {
|
||||||
if (VDBG) log("evalScores - already trying - size=" + mNetworkRequests.size());
|
if (mRegistered) {
|
||||||
// already trying
|
if (VDBG) log("evalScores - already connected - size=" + mNetworkRequests.size());
|
||||||
return;
|
// already trying
|
||||||
}
|
|
||||||
if (VDBG) log("evalScores!");
|
|
||||||
for (int i=0; i < mNetworkRequests.size(); i++) {
|
|
||||||
int score = mNetworkRequests.valueAt(i).score;
|
|
||||||
if (VDBG) log(" checking request Min " + score + " vs my score " + mNetworkScore);
|
|
||||||
if (score < mNetworkScore) {
|
|
||||||
// have a request that has a lower scored network servicing it
|
|
||||||
// (or no network) than we could provide, so lets connect!
|
|
||||||
mConnectionRequested = true;
|
|
||||||
connect();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (VDBG) log("evalScores!");
|
||||||
|
for (int i=0; i < mNetworkRequests.size(); i++) {
|
||||||
|
int score = mNetworkRequests.valueAt(i).score;
|
||||||
|
if (VDBG) log(" checking request Min " + score + " vs my score " + mNetworkScore);
|
||||||
|
if (score < mNetworkScore) {
|
||||||
|
// have a request that has a lower scored network servicing it
|
||||||
|
// (or no network) than we could provide, so let's connect!
|
||||||
|
mConnectionRequested = true;
|
||||||
|
connect();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Our score is not high enough to satisfy any current request.
|
||||||
|
// This can happen if our score goes down after a connection is
|
||||||
|
// requested but before we actually connect. In this case, disconnect
|
||||||
|
// rather than continue trying - there's no point connecting if we know
|
||||||
|
// we'll just be torn down as soon as we do.
|
||||||
|
if (mConnectionRequested) {
|
||||||
|
mConnectionRequested = false;
|
||||||
|
disconnect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user