From fb2cdd7fe476e0684ac24f70ff54c757ef3f3c8a Mon Sep 17 00:00:00 2001 From: Benoit Goby Date: Wed, 22 Dec 2010 14:29:40 -0800 Subject: [PATCH 1/3] Add USB Ethernet support Change-Id: Idb333f15818f455eedfb62f81358499dc7419f5b --- core/java/android/net/ConnectivityManager.java | 10 ++++++++-- .../java/com/android/server/ConnectivityService.java | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java index 3d685cbc76..c08700f1d3 100644 --- a/core/java/android/net/ConnectivityManager.java +++ b/core/java/android/net/ConnectivityManager.java @@ -213,10 +213,16 @@ public class ConnectivityManager */ public static final int TYPE_WIMAX = 6; + /** + * Ethernet data connection + * @hide + */ + public static final int TYPE_ETHERNET = 8; + /** {@hide} */ - public static final int TYPE_DUMMY = 7; + public static final int TYPE_DUMMY = 9; /** {@hide} TODO: Need to adjust this for WiMAX. */ - public static final int MAX_RADIO_TYPE = TYPE_WIFI; + public static final int MAX_RADIO_TYPE = TYPE_DUMMY; /** {@hide} TODO: Need to adjust this for WiMAX. */ public static final int MAX_NETWORK_TYPE = TYPE_DUMMY; diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java index f82a243a6b..8e6e043579 100644 --- a/services/java/com/android/server/ConnectivityService.java +++ b/services/java/com/android/server/ConnectivityService.java @@ -18,6 +18,7 @@ package com.android.server; import android.app.Notification; import android.app.NotificationManager; +import android.net.EthernetDataTracker; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; @@ -412,6 +413,10 @@ public class ConnectivityService extends IConnectivityManager.Stub { mNetAttributes[netType].mName); mNetTrackers[netType].startMonitoring(context, mHandler); break; + case ConnectivityManager.TYPE_ETHERNET: + mNetTrackers[netType] = EthernetDataTracker.getInstance(); + mNetTrackers[netType].startMonitoring(context, mHandler); + break; default: loge("Trying to create a DataStateTracker for an unknown radio type " + mNetAttributes[netType].mRadio); From 4397fdfa3477c8d736ea9a33a48c684b84a18def Mon Sep 17 00:00:00 2001 From: Robert Greenwalt Date: Thu, 6 Jan 2011 15:41:07 -0800 Subject: [PATCH 2/3] Fix handling of multiple possible default networks Old code assumed only 2 choices but now we have more. bug:3328196 Change-Id: I92a02b31fae6c53f73b3684581230fad5cb1b82a --- .../android/server/ConnectivityService.java | 72 +++++++------------ 1 file changed, 25 insertions(+), 47 deletions(-) diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java index 3b47bce4a7..b1eead2c13 100644 --- a/services/java/com/android/server/ConnectivityService.java +++ b/services/java/com/android/server/ConnectivityService.java @@ -1132,11 +1132,13 @@ public class ConnectivityService extends IConnectivityManager.Stub { } } - // returns null if no failover available + // returns null if no failover available, otherwise returns the highest + // priority network we're trying private NetworkStateTracker tryFailover(int prevNetType) { /* - * If this is a default network, check if other defaults are available - * or active + * If this is a default network, check if other defaults are available. + * Try to reconnect on all available and let them hash it out when + * more than one connects. */ NetworkStateTracker newNet = null; if (mNetAttributes[prevNetType].isDefault()) { @@ -1149,54 +1151,30 @@ public class ConnectivityService extends IConnectivityManager.Stub { for (int checkType=0; checkType <= ConnectivityManager.MAX_NETWORK_TYPE; checkType++) { if (checkType == prevNetType) continue; if (mNetAttributes[checkType] == null) continue; - if (mNetAttributes[checkType].isDefault()) { - /* TODO - if we have multiple nets we could use - * we may want to put more thought into which we choose - */ - if (checkType == mNetworkPreference) { - newType = checkType; - break; - } - if (mNetAttributes[checkType].mPriority > newPriority) { - newType = checkType; - newPriority = mNetAttributes[newType].mPriority; - } - } - } + if (!mNetAttributes[checkType].isDefault()) continue; + if (!mNetTrackers[checkType].isAvailable()) continue; - if (newType != -1) { - newNet = mNetTrackers[newType]; - /** - * See if the other network is available to fail over to. - * If is not available, we enable it anyway, so that it - * will be able to connect when it does become available, - * but we report a total loss of connectivity rather than - * report that we are attempting to fail over. - */ - if (newNet.isAvailable()) { - NetworkInfo switchTo = newNet.getNetworkInfo(); - switchTo.setFailover(true); - if (!switchTo.isConnectedOrConnecting() || - newNet.isTeardownRequested()) { - newNet.reconnect(); - } - if (DBG) { - if (switchTo.isConnected()) { - log("Switching to already connected " + switchTo.getTypeName()); - } else { - log("Attempting to switch to " + switchTo.getTypeName()); - } - } - } else { - newNet.reconnect(); - newNet = null; // not officially avail.. try anyway, but - // report no failover + NetworkStateTracker tracker = mNetTrackers[checkType]; + NetworkInfo info = tracker.getNetworkInfo(); + if (!info.isConnectedOrConnecting() || + tracker.isTeardownRequested()) { + info.setFailover(true); + tracker.reconnect(); + } + if (DBG) log("Attempting to switch to " + info.getTypeName()); + + // figure out if this is the highest priority network + // so we send an appropriate return value + if (checkType == mNetworkPreference) { + newType = checkType; + } + if (mNetAttributes[checkType].mPriority > newPriority && + newType != mNetworkPreference) { + newType = checkType; + newPriority = mNetAttributes[newType].mPriority; } - } else { - loge("Network failover failing."); } } - return newNet; } From b52dbfe01aece62917e1f128430daf9c9c8f1f9e Mon Sep 17 00:00:00 2001 From: Wink Saville Date: Wed, 26 Jan 2011 15:43:49 -0800 Subject: [PATCH 3/3] Comment out the isAvailable optimization. As the comment says this causes problems if the connection is handling errors. This removes the optimization for now. Bug: 3386481 Change-Id: I6cb00abe8b1949e9b79b4906a6bdab5872b5054d --- .../java/com/android/server/ConnectivityService.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java index bd3c554a5b..e689654110 100644 --- a/services/java/com/android/server/ConnectivityService.java +++ b/services/java/com/android/server/ConnectivityService.java @@ -1152,7 +1152,17 @@ public class ConnectivityService extends IConnectivityManager.Stub { if (checkType == prevNetType) continue; if (mNetAttributes[checkType] == null) continue; if (!mNetAttributes[checkType].isDefault()) continue; - if (!mNetTrackers[checkType].isAvailable()) continue; + +// Enabling the isAvailable() optimization caused mobile to not get +// selected if it was in the middle of error handling. Specifically +// a moble connection that took 30 seconds to complete the DEACTIVATE_DATA_CALL +// would not be available and we wouldn't get connected to anything. +// So removing the isAvailable() optimization below for now. TODO: This +// optimization should work and we need to investigate why it doesn't work. +// This could be related to how DEACTIVATE_DATA_CALL is reporting its +// complete before it is really complete. +// if (!mNetTrackers[checkType].isAvailable()) continue; + // if (currentPriority >= mNetAttributes[checkType].mPriority) continue; NetworkStateTracker checkTracker = mNetTrackers[checkType];