Project

General

Profile

Issue #1792 ยป 0001-Fix-RepWifi-connection-not-correctly-reported-to-use.patch

Wolfgang Wiedmeyer, 08/13/2017 08:02 PM

View differences:

services/core/java/com/android/server/ConnectivityService.java
import java.io.PrintWriter;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.UnknownHostException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.SortedSet;
......
final int uid = Binder.getCallingUid();
NetworkState state = getUnfilteredActiveNetworkState(uid);
NetworkInfo ni = getFilteredNetworkInfo(state.networkInfo, state.linkProperties, uid);
// TODO RepWifi extension. Remove when a low-level, long-lived solution is found.
if (ni == null) {
ni = getNetworkInfoByInterfaceName(IFACE_NAME_WIFI);
}
if (ni == null) {
ni = getNetworkInfoByInterfaceName(IFACE_NAME_TETHER);
}
maybeLogBlockedNetworkInfo(ni, uid);
return ni;
}
// TODO RepWifi extension. Remove when a low-level, long-lived solution is found.
private static final String IFACE_NAME_WIFI = "wlan0";
private static final String IFACE_NAME_TETHER = "rndis0";
private NetworkInfo getNetworkInfoByInterfaceName(String ifname) {
try {
int type = 0;
String typeName = null;
if (ifname == IFACE_NAME_WIFI) {
type = ConnectivityManager.TYPE_WIFI;
typeName = "WIFI";
} else if (ifname == IFACE_NAME_TETHER) {
type = ConnectivityManager.TYPE_ETHERNET;
typeName = "ETHERNET";
} else {
return null;
}
NetworkInterface nifRep = NetworkInterface.getByName(ifname);
if (nifRep == null) {
return null;
}
Enumeration<InetAddress> ads = nifRep.getInetAddresses();
if (ads == null) {
return null;
}
while (ads.hasMoreElements()) {
InetAddress a = ads.nextElement();
if (a.getHostAddress() != null && a.isSiteLocalAddress()) {
// if the interface has a valid IP address in the range of a
// local network we consider it is connected to an AP.
NetworkInfo ninfo = new NetworkInfo(type, 0, typeName, "");
ninfo.setDetailedState(DetailedState.CONNECTED, null, null);
ninfo.setIsAvailable(true);
return ninfo;
}
}
// if we reached here, the interface has no valid address
return null;
} catch (Exception e) {
// Exceptions are suppressed to avoid crashing the surrounding system service.
// This is only a best-effort hack.
return null;
}
}
@Override
public Network getActiveNetwork() {
    (1-1/1)