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
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;
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;
- }
}
}
}