From c0e0dbb45446e5e0f7f131f2180c946778e7d711 Mon Sep 17 00:00:00 2001 From: Irfan Sheriff Date: Mon, 17 Jan 2011 12:38:30 -0800 Subject: [PATCH] DO NOT MERGE Pick upstream intf with valid IP conf As a work around for the issue of picking the wrong interface, add a check for selecting an upstream interface that has a valid IP configuration Bug: 3362306 Change-Id: I3e8ab5ef30b69f1adab755d83f5b65c078f73936 --- .../android/net/InterfaceConfiguration.java | 18 ++++++++++++++++++ .../android/server/connectivity/Tethering.java | 8 ++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/core/java/android/net/InterfaceConfiguration.java b/core/java/android/net/InterfaceConfiguration.java index 915c5d7230cae..dcea3af3d42bb 100644 --- a/core/java/android/net/InterfaceConfiguration.java +++ b/core/java/android/net/InterfaceConfiguration.java @@ -51,6 +51,24 @@ public class InterfaceConfiguration implements Parcelable { append(addr & 0xff); } + /** + * This function determines if the interface is up and has a valid IP + * configuration (IP address has a non zero octet). + * + * Note: It is supposed to be quick and hence should not initiate + * any network activity + */ + public boolean isActive() { + try { + if(interfaceFlags.contains("up")) { + if (ipAddr != 0) return true; + } + } catch (NullPointerException e) { + return false; + } + return false; + } + /** Implement the Parcelable interface {@hide} */ public int describeContents() { return 0; diff --git a/services/java/com/android/server/connectivity/Tethering.java b/services/java/com/android/server/connectivity/Tethering.java index f774b299e3de5..1ec9b5116172e 100644 --- a/services/java/com/android/server/connectivity/Tethering.java +++ b/services/java/com/android/server/connectivity/Tethering.java @@ -1173,18 +1173,18 @@ public class Tethering extends INetworkManagementEventObserver.Stub { for (String iface : ifaces) { for (String regex : mUpstreamIfaceRegexs) { if (iface.matches(regex)) { - // verify it is up! + // verify it is active InterfaceConfiguration ifcg = null; try { ifcg = service.getInterfaceConfig(iface); + if (ifcg.isActive()) { + return iface; + } } catch (Exception e) { Log.e(TAG, "Error getting iface config :" + e); // ignore - try next continue; } - if (ifcg.interfaceFlags.contains("up")) { - return iface; - } } } }