本文整理汇总了Java中android.net.VpnService.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java VpnService.Builder方法的具体用法?Java VpnService.Builder怎么用?Java VpnService.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.net.VpnService
的用法示例。
在下文中一共展示了VpnService.Builder方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newDNSServer
import android.net.VpnService; //导入方法依赖的package包/类
void newDNSServer(VpnService.Builder builder, String format, byte[] ipv6Template, InetAddress addr) throws UnknownHostException {
// Optimally we'd allow either one, but the forwarder checks if upstream size is empty, so
// we really need to acquire both an ipv6 and an ipv4 subnet.
if (addr instanceof Inet6Address && ipv6Template == null) {
Log.i(TAG, "newDNSServer: Ignoring DNS server " + addr);
} else if (addr instanceof Inet4Address && format == null) {
Log.i(TAG, "newDNSServer: Ignoring DNS server " + addr);
} else if (addr instanceof Inet4Address) {
upstreamDnsServers.add(addr);
String alias = String.format(format, upstreamDnsServers.size() + 1);
Log.i(TAG, "configure: Adding DNS Server " + addr + " as " + alias);
builder.addDnsServer(alias);
builder.addRoute(alias, 32);
vpnWatchDog.setTarget(InetAddress.getByName(alias));
} else if (addr instanceof Inet6Address) {
upstreamDnsServers.add(addr);
ipv6Template[ipv6Template.length - 1] = (byte) (upstreamDnsServers.size() + 1);
InetAddress i6addr = Inet6Address.getByAddress(ipv6Template);
Log.i(TAG, "configure: Adding DNS Server " + addr + " as " + i6addr);
builder.addDnsServer(i6addr);
vpnWatchDog.setTarget(i6addr);
}
}
示例2: addDefaultRoutes
import android.net.VpnService; //导入方法依赖的package包/类
private void addDefaultRoutes(VpnService.Builder b, LibOpenConnect.IPInfo ip, ArrayList<String> subnets) {
boolean ip4def = true, ip6def = true;
for (String s : subnets) {
if (s.contains(":")) {
ip6def = false;
} else {
ip4def = false;
}
}
if (ip4def && ip.addr != null) {
b.addRoute("0.0.0.0", 0);
log("ROUTE: 0.0.0.0/0");
}
if (ip6def && ip.netmask6 != null) {
b.addRoute("::", 0);
log("ROUTE: ::/0");
}
}
示例3: configure
import android.net.VpnService; //导入方法依赖的package包/类
private void configure(String parameters) throws Exception {
// If the old interface has exactly the same parameters, use it!
if (mInterface != null) {
Log.i(TAG, "Using the previous interface");
return;
}
// Configure a builder while parsing the parameters.
VpnService.Builder builder = new VpnService.Builder();
builder.addAddress(mTunAddress, mTunPrefixLen);
Log.i(TAG, "set tunnel address: " + mTunAddress + "/" + mTunPrefixLen);
builder.setMtu(mMTU);
// add US routes
builder.addRoute("0.0.0.0", 0);
builder.addDnsServer("8.8.8.8");
// Close the old interface since the parameters have been changed.
try {
mInterface.close();
} catch (Exception e) {
// ignore
}
// Create a new interface using the builder and save the parameters.
mInterface = builder.setSession(mServerAddress)
.setConfigureIntent(mConfigureIntent)
.establish();
//mParameters = parameters;
Log.i(TAG, "New interface: " + parameters);
}
示例4: onCreate
import android.net.VpnService; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
builder = new VpnService.Builder();
builder.addAddress(VPN_ADDRESS, 32);
builder.addRoute(VPN_ROUTE, 0);
builder.establish();
}
示例5: addSubnetRoutes
import android.net.VpnService; //导入方法依赖的package包/类
private void addSubnetRoutes(VpnService.Builder b, LibOpenConnect.IPInfo ip, ArrayList<String> subnets) {
for (String s : subnets) {
s = s.trim();
try {
if (s.contains(":")) {
String ss[] = s.split("/");
if (ss.length == 1) {
b.addRoute(ss[0], 128);
} else {
b.addRoute(ss[0], Integer.parseInt(ss[1]));
}
log("ROUTE: " + s);
} else {
CIDRIP cdr;
if (!s.contains("/")) {
cdr = new CIDRIP(s + "/32");
} else {
cdr = new CIDRIP(s);
}
b.addRoute(cdr.mIp, cdr.len);
log("ROUTE: " + cdr.mIp + "/" + cdr.len);
}
} catch (Exception e) {
log("ROUTE: skipping invalid route '" + s + "'");
}
}
}
示例6: setMtu
import android.net.VpnService; //导入方法依赖的package包/类
@Override
public VpnService.Builder setMtu(int mtu) {
this.mtu = mtu;
super.setMtu(mtu);
return this;
}
示例7: getVpnServiceBuilder
import android.net.VpnService; //导入方法依赖的package包/类
public Builder getVpnServiceBuilder() {
VpnService.Builder b = new VpnService.Builder();
b.setSession(profile.mName);
b.setConfigureIntent(getMainActivityIntent());
return b;
}