summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2014-05-28 21:38:02 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-05-28 21:38:03 +0000
commitc039803160c692216d6dff874ba0af0fb0dc3ee0 (patch)
treede26036b8e0794ae5ff6193235b935e89f5a6d53
parentb9a65de1f79d92326abcccc295c18f24afb83053 (diff)
parent38fe3984531b5a8ae5f41a5212f1b6a66adc61de (diff)
downloadframeworks_base-c039803160c692216d6dff874ba0af0fb0dc3ee0.zip
frameworks_base-c039803160c692216d6dff874ba0af0fb0dc3ee0.tar.gz
frameworks_base-c039803160c692216d6dff874ba0af0fb0dc3ee0.tar.bz2
Merge "DO NOT MERGE - Support disconnecting while trying to connect." into lmp-preview-dev
-rw-r--r--core/java/android/net/NetworkAgent.java46
1 files changed, 29 insertions, 17 deletions
diff --git a/core/java/android/net/NetworkAgent.java b/core/java/android/net/NetworkAgent.java
index c2b06a2..1c18ba5 100644
--- a/core/java/android/net/NetworkAgent.java
+++ b/core/java/android/net/NetworkAgent.java
@@ -257,31 +257,43 @@ public abstract class NetworkAgent extends Handler {
}
/**
- * called to go through our list of requests and see if we're
- * good enough to try connecting.
+ * Called to go through our list of requests and see if we're
+ * 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
* between modules (bearer or ConnectivityService dies) or more commonly
* when the NetworkInfo reports to ConnectivityService it is disconnected.
*/
private void evalScores() {
- if (mConnectionRequested) {
- if (VDBG) log("evalScores - already trying - size=" + mNetworkRequests.size());
- // already trying
- 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 lets connect!
- mConnectionRequested = true;
- connect();
+ synchronized(mLockObj) {
+ if (mRegistered) {
+ if (VDBG) log("evalScores - already connected - size=" + mNetworkRequests.size());
+ // already trying
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();
+ }
}
}