本文整理汇总了Java中android.net.LinkProperties类的典型用法代码示例。如果您正苦于以下问题:Java LinkProperties类的具体用法?Java LinkProperties怎么用?Java LinkProperties使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LinkProperties类属于android.net包,在下文中一共展示了LinkProperties类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDnsServers
import android.net.LinkProperties; //导入依赖的package包/类
@TargetApi(23)
private static List<InetAddress> getDnsServers(Context context) {
List<InetAddress> servers = new ArrayList<>();
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
//Network[] networks = connectivityManager == null ? null : connectivityManager.getAllNetworks();
Network[] networks = connectivityManager == null ? null : new Network[]{connectivityManager.getActiveNetwork()};
if (networks == null) {
return servers;
}
for(int i = 0; i < networks.length; ++i) {
LinkProperties linkProperties = connectivityManager.getLinkProperties(networks[i]);
if (linkProperties != null) {
servers.addAll(linkProperties.getDnsServers());
}
}
for(InetAddress server : servers) {
Log.d("dns","DNS server: " + Strings.nullToEmpty(server.getHostName()) + " (" + server.getHostAddress() + ")");
}
return servers;
}
示例2: findVpnNetwork
import android.net.LinkProperties; //导入依赖的package包/类
private Network findVpnNetwork() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
Network[] networks = cm.getAllNetworks();
for (Network network : networks) {
LinkProperties linkProperties = cm.getLinkProperties(network);
List<LinkAddress> addresses = linkProperties.getLinkAddresses();
for (LinkAddress addr : addresses) {
if (addr.getAddress().equals(VPN_ADDRESS)) {
return network;
}
}
}
return null;
}
示例3: after
import android.net.LinkProperties; //导入依赖的package包/类
@Override
protected void after(XParam param) throws Throwable {
switch (mMethod) {
case getAddresses:
case getAllAddresses:
if (param.getResult() != null)
if (isRestricted(param))
param.setResult(new ArrayList<InetAddress>());
break;
case getAllLinkAddresses:
case getLinkAddresses:
if (param.getResult() != null)
if (isRestricted(param))
param.setResult(new ArrayList<LinkAddress>());
break;
case getStackedLinks:
if (param.getResult() != null)
if (isRestricted(param))
param.setResult(new ArrayList<LinkProperties>());
break;
}
}
示例4: getDnsServers
import android.net.LinkProperties; //导入依赖的package包/类
@TargetApi(21)
private static List<InetAddress> getDnsServers(Context context) {
List<InetAddress> servers = new ArrayList<>();
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Network[] networks = connectivityManager == null ? null : connectivityManager.getAllNetworks();
if (networks == null) {
return getDnsServersPreLollipop();
}
for(int i = 0; i < networks.length; ++i) {
LinkProperties linkProperties = connectivityManager.getLinkProperties(networks[i]);
if (linkProperties != null) {
servers.addAll(linkProperties.getDnsServers());
}
}
if (servers.size() > 0) {
Log.d(Config.LOGTAG,"used lollipop variant to discover dns servers in "+networks.length+" networks");
}
return servers.size() > 0 ? servers : getDnsServersPreLollipop();
}
示例5: getDnsServers
import android.net.LinkProperties; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
@CalledByNative
private static byte[][] getDnsServers() {
ConnectivityManager connectivityManager =
(ConnectivityManager) ContextUtils.getApplicationContext().getSystemService(
Context.CONNECTIVITY_SERVICE);
if (connectivityManager == null) {
return new byte[0][0];
}
Network network = connectivityManager.getActiveNetwork();
if (network == null) {
return new byte[0][0];
}
LinkProperties linkProperties = connectivityManager.getLinkProperties(network);
if (linkProperties == null) {
return new byte[0][0];
}
List<InetAddress> dnsServersList = linkProperties.getDnsServers();
byte[][] dnsServers = new byte[dnsServersList.size()][];
for (int i = 0; i < dnsServersList.size(); i++) {
dnsServers[i] = dnsServersList.get(i).getAddress();
}
return dnsServers;
}
示例6: getActiveInterface
import android.net.LinkProperties; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
private String getActiveInterface() {
final Network network = cm.getActiveNetwork();
if (network == null) {
return null;
}
final LinkProperties linkInfo = cm.getLinkProperties(network);
if (linkInfo == null) {
return null;
}
final List<LinkAddress> linkAddress = linkInfo.getLinkAddresses();
if (linkAddress.isEmpty()) {
return null;
}
final InetAddress address = linkAddress.get(0).getAddress();
return address.getHostAddress();
}
示例7: getDnsServers
import android.net.LinkProperties; //导入依赖的package包/类
@TargetApi(21)
private static List<InetAddress> getDnsServers(Context context) {
List<InetAddress> servers = new ArrayList<>();
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Network[] networks = connectivityManager == null ? null : connectivityManager.getAllNetworks();
if (networks == null) {
return getDnsServersPreLollipop();
}
for(int i = 0; i < networks.length; ++i) {
LinkProperties linkProperties = connectivityManager.getLinkProperties(networks[i]);
if (linkProperties != null) {
if (hasDefaultRoute(linkProperties)) {
servers.addAll(0, linkProperties.getDnsServers());
} else {
servers.addAll(linkProperties.getDnsServers());
}
}
}
if (servers.size() > 0) {
Log.d(Config.LOGTAG, "used lollipop variant to discover dns servers in " + networks.length + " networks");
}
return servers.size() > 0 ? servers : getDnsServersPreLollipop();
}
示例8: getIp
import android.net.LinkProperties; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private String getIp(LinkProperties lp) {
List<LinkAddress> las = lp.getLinkAddresses();
for(LinkAddress la: las) {
InetAddress inetAddress = la.getAddress();
if (inetAddress instanceof Inet4Address) {
//Log.d(TAG, lp.getInterfaceName() + ": " + inetAddress.getHostAddress());
return inetAddress.getHostAddress();
}
}
return null;
}
示例9: getLP
import android.net.LinkProperties; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private LinkProperties getLP(ConnectivityManager connMgr, int cap) {
Network nets[] = connMgr.getAllNetworks();
for (Network n: nets) {
LinkProperties lp = connMgr.getLinkProperties(n);
NetworkCapabilities np = connMgr.getNetworkCapabilities(n);
String iname = lp.getInterfaceName();
if (iname != null && np != null) {
//Log.d(TAG, ">>> " + iname + ": " + np.hasTransport(cap));
if (np.hasTransport(cap))
return lp;
}
}
return null;
}
示例10: getDefaultDNS
import android.net.LinkProperties; //导入依赖的package包/类
public static List<String> getDefaultDNS(Context context) {
String dns1 = null;
String dns2 = null;
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Network an = cm.getActiveNetwork();
if (an != null) {
LinkProperties lp = cm.getLinkProperties(an);
if (lp != null) {
List<InetAddress> dns = lp.getDnsServers();
if (dns != null) {
if (dns.size() > 0)
dns1 = dns.get(0).getHostAddress();
if (dns.size() > 1)
dns2 = dns.get(1).getHostAddress();
for (InetAddress d : dns)
Log.i(TAG, "DNS from LP: " + d.getHostAddress());
}
}
}
} else {
dns1 = jni_getprop("net.dns1");
dns2 = jni_getprop("net.dns2");
}
List<String> listDns = new ArrayList<>();
listDns.add(TextUtils.isEmpty(dns1) ? "8.8.8.8" : dns1);
listDns.add(TextUtils.isEmpty(dns2) ? "8.8.4.4" : dns2);
return listDns;
}
示例11: onLinkPropertiesChanged
import android.net.LinkProperties; //导入依赖的package包/类
@Override
public void onLinkPropertiesChanged(Network network, LinkProperties linkProperties) {
super.onLinkPropertiesChanged(network, linkProperties);
if (!linkProperties.toString().equals(mLastLinkProperties)) {
mLastLinkProperties = linkProperties.toString();
VpnStatus.logDebug(String.format("Linkproperties of %s: %s", network, linkProperties));
}
}
示例12: onLinkPropertiesChanged
import android.net.LinkProperties; //导入依赖的package包/类
@Override
public void onLinkPropertiesChanged(Network network, LinkProperties linkProperties) {
// A link property change may indicate the IP address changes.
// so forward the new NetworkInformation to the observer.
Logging.d(TAG, "link properties changed: " + linkProperties.toString());
onNetworkChanged(network);
}
示例13: getIPAddresses
import android.net.LinkProperties; //导入依赖的package包/类
@SuppressLint("NewApi")
IPAddress[] getIPAddresses(LinkProperties linkProperties) {
IPAddress[] ipAddresses = new IPAddress[linkProperties.getLinkAddresses().size()];
int i = 0;
for (LinkAddress linkAddress : linkProperties.getLinkAddresses()) {
ipAddresses[i] = new IPAddress(linkAddress.getAddress().getAddress());
++i;
}
return ipAddresses;
}
示例14: getDnsServerAddresses
import android.net.LinkProperties; //导入依赖的package包/类
@Override
@TargetApi(21)
public String[] getDnsServerAddresses() {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Network[] networks = connectivityManager == null ? null : connectivityManager.getAllNetworks();
if (networks == null) {
return new String[0];
}
List<String> servers = new ArrayList<>();
int vpnOffset = 0;
for(Network network : networks) {
LinkProperties linkProperties = connectivityManager.getLinkProperties(network);
NetworkInfo networkInfo = connectivityManager.getNetworkInfo(network);
if (linkProperties != null) {
if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_VPN) {
final List<String> tmp = getIPv4First(linkProperties.getDnsServers());
servers.addAll(0, tmp);
vpnOffset += tmp.size();
} else if (hasDefaultRoute(linkProperties)) {
servers.addAll(vpnOffset, getIPv4First(linkProperties.getDnsServers()));
} else {
servers.addAll(getIPv4First(linkProperties.getDnsServers()));
}
}
}
return servers.toArray(new String[servers.size()]);
}
示例15: hasDefaultRoute
import android.net.LinkProperties; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static boolean hasDefaultRoute(LinkProperties linkProperties) {
for(RouteInfo route: linkProperties.getRoutes()) {
if (route.isDefaultRoute()) {
return true;
}
}
return false;
}