Improved has46

pull/214/head
M66B 12 months ago
parent b4902b9165
commit b5f19f9e2d

@ -23,6 +23,7 @@ import android.accounts.AccountsException;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.LinkAddress;
import android.net.LinkProperties;
import android.net.Network;
import android.net.NetworkCapabilities;
@ -651,7 +652,19 @@ public class ConnectionHelper {
ConnectivityManager cm = Helper.getSystemService(context, ConnectivityManager.class);
Network active = (cm == null ? null : cm.getActiveNetwork());
LinkProperties props = (active == null ? null : cm.getLinkProperties(active));
ifacename = (props == null ? null : props.getInterfaceName());
List<LinkAddress> las = (props == null ? null : props.getLinkAddresses());
if (las != null)
for (LinkAddress la : las) {
InetAddress addr = la.getAddress();
boolean local = (addr.isLoopbackAddress() || addr.isLinkLocalAddress());
if (local)
continue;
if (addr instanceof Inet4Address)
has4 = true;
else if (addr instanceof Inet6Address)
has6 = true;
}
return new boolean[]{has4, has6};
} catch (Throwable ex) {
Log.e(ex);
}

Loading…
Cancel
Save