Skip to content

Commit 05f14e2

Browse files
isheriffAndroid (Google) Code Review
authored andcommitted
Merge "DO NOT MERGE Pick upstream intf with valid IP conf" into gingerbread
2 parents 568845a + c0e0dbb commit 05f14e2

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

core/java/android/net/InterfaceConfiguration.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ private static void putAddress(StringBuffer buf, int addr) {
5151
append(addr & 0xff);
5252
}
5353

54+
/**
55+
* This function determines if the interface is up and has a valid IP
56+
* configuration (IP address has a non zero octet).
57+
*
58+
* Note: It is supposed to be quick and hence should not initiate
59+
* any network activity
60+
*/
61+
public boolean isActive() {
62+
try {
63+
if(interfaceFlags.contains("up")) {
64+
if (ipAddr != 0) return true;
65+
}
66+
} catch (NullPointerException e) {
67+
return false;
68+
}
69+
return false;
70+
}
71+
5472
/** Implement the Parcelable interface {@hide} */
5573
public int describeContents() {
5674
return 0;

services/java/com/android/server/connectivity/Tethering.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,18 +1173,18 @@ protected String findActiveUpstreamIface() {
11731173
for (String iface : ifaces) {
11741174
for (String regex : mUpstreamIfaceRegexs) {
11751175
if (iface.matches(regex)) {
1176-
// verify it is up!
1176+
// verify it is active
11771177
InterfaceConfiguration ifcg = null;
11781178
try {
11791179
ifcg = service.getInterfaceConfig(iface);
1180+
if (ifcg.isActive()) {
1181+
return iface;
1182+
}
11801183
} catch (Exception e) {
11811184
Log.e(TAG, "Error getting iface config :" + e);
11821185
// ignore - try next
11831186
continue;
11841187
}
1185-
if (ifcg.interfaceFlags.contains("up")) {
1186-
return iface;
1187-
}
11881188
}
11891189
}
11901190
}

0 commit comments

Comments
 (0)