本文整理汇总了Java中android.net.VpnService类的典型用法代码示例。如果您正苦于以下问题:Java VpnService类的具体用法?Java VpnService怎么用?Java VpnService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
VpnService类属于android.net包,在下文中一共展示了VpnService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startVPNWithProfile
import android.net.VpnService; //导入依赖的package包/类
private void startVPNWithProfile(VpnProfile vp) {
Intent vpnPermissionIntent = VpnService.prepare(getBaseContext());
int needPassword = vp.needUserPWInput(false);
if (vpnPermissionIntent != null || needPassword != 0) {
// VPN has not been prepared, this intent will prompt the user for
// permissions, and subsequently launch OpenVPN.
Intent shortVPNIntent = new Intent(Intent.ACTION_MAIN);
shortVPNIntent.setClass(getBaseContext(), de.blinkt.openvpn.LaunchVPN.class);
shortVPNIntent.putExtra(de.blinkt.openvpn.LaunchVPN.EXTRA_KEY, vp.getUUIDString());
shortVPNIntent.putExtra(de.blinkt.openvpn.LaunchVPN.EXTRA_HIDELOG, true);
shortVPNIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.cordova.getActivity().startActivity(shortVPNIntent);
} else {
Log.d(LOG_TAG, "Starting OpenVPN.");
VPNLaunchHelper.startOpenVpn(vp, getBaseContext());
}
}
示例2: onReceive
import android.net.VpnService; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
if (Daedalus.getPrefs().getBoolean("settings_boot", false)) {
Intent vIntent = VpnService.prepare(context);
if (vIntent != null) {
vIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(vIntent);
}
DaedalusVpnService.primaryServer = DNSServerHelper.getAddressById(DNSServerHelper.getPrimary());
DaedalusVpnService.secondaryServer = DNSServerHelper.getAddressById(DNSServerHelper.getSecondary());
context.startService((new Intent(context, DaedalusVpnService.class)).setAction(DaedalusVpnService.ACTION_ACTIVATE));
Logger.info("Triggered boot receiver");
}
Daedalus.updateShortcut(context);
}
示例3: startVPNService
import android.net.VpnService; //导入依赖的package包/类
public void startVPNService()
{
if (!checkVPNServiceActive())
{
Intent intent = VpnService.prepare(this);
if (intent != null)
startActivityForResult(intent, 0);
else
onActivityResult(0, RESULT_OK, null);
}
}
示例4: startDNS
import android.net.VpnService; //导入依赖的package包/类
private void startDNS() {
if (presenter.isWorking()) {
presenter.stopService();
} else if (isValid()) {
Intent intent = VpnService.prepare(this);
if (intent != null) {
startActivityForResult(intent, REQUEST_CONNECT);
} else {
onActivityResult(REQUEST_CONNECT, RESULT_OK, null);
}
} else {
makeSnackbar(getString(R.string.enter_valid_dns));
}
}
示例5: onCreate
import android.net.VpnService; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mConfig = getIntent().getStringExtra(KEY_CONFIG);
mUsername = getIntent().getStringExtra(KEY_USERNAME);
mPw = getIntent().getStringExtra(KEY_PASSWORD);
Intent intent = VpnService.prepare(this);
if (intent != null) {
startActivityForResult(intent, 0);
} else {
startVpn();
finish();
}
}
示例6: onOptionsItemSelected
import android.net.VpnService; //导入依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
int id = item.getItemId();
if (id == R.id.action_settings)
{
startActivity(new Intent(this, SettingsActivity.class));
}
if (id == R.id.action_vpn)
{
Intent intent = VpnService.prepare(this);
if (intent != null)
{
startActivityForResult(intent, VPN_REQUEST_CODE);
}
else
{
onActivityResult(VPN_REQUEST_CODE, RESULT_OK, null);
}
}
return super.onOptionsItemSelected(item);
}
示例7: checkStartVpnOnBoot
import android.net.VpnService; //导入依赖的package包/类
public static void checkStartVpnOnBoot(Context context) {
Log.i("BOOT", "Checking whether to start ad buster on boot");
Configuration config = FileHelper.loadCurrentSettings(context);
if (config == null || !config.autoStart) {
return;
}
if (!context.getSharedPreferences("state", MODE_PRIVATE).getBoolean("isActive", false)) {
return;
}
if (VpnService.prepare(context) != null) {
Log.i("BOOT", "VPN preparation not confirmed by user, changing enabled to false");
}
Log.i("BOOT", "Starting ad buster from boot");
NotificationChannels.onCreate(context);
Intent intent = getStartIntent(context);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && config.showNotification) {
context.startForegroundService(intent);
} else {
context.startService(intent);
}
}
示例8: getDnsServers
import android.net.VpnService; //导入依赖的package包/类
private static Set<InetAddress> getDnsServers(Context context) throws VpnNetworkException {
Set<InetAddress> out = new HashSet<>();
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(VpnService.CONNECTIVITY_SERVICE);
// Seriously, Android? Seriously?
NetworkInfo activeInfo = cm.getActiveNetworkInfo();
if (activeInfo == null)
throw new VpnNetworkException("No DNS Server");
for (Network nw : cm.getAllNetworks()) {
NetworkInfo ni = cm.getNetworkInfo(nw);
if (ni == null || !ni.isConnected() || ni.getType() != activeInfo.getType()
|| ni.getSubtype() != activeInfo.getSubtype())
continue;
for (InetAddress address : cm.getLinkProperties(nw).getDnsServers())
out.add(address);
}
return out;
}
示例9: 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);
}
}
示例10: startVpn
import android.net.VpnService; //导入依赖的package包/类
private void startVpn() {
stopwatch = new Stopwatch();
connectedServer = currentServer;
hideCurrentConnection = true;
adbBlockCheck.setEnabled(false);
Intent intent = VpnService.prepare(this);
if (intent != null) {
VpnStatus.updateStateString("USER_VPN_PERMISSION", "", R.string.state_user_vpn_permission,
VpnStatus.ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT);
// Start the query
try {
startActivityForResult(intent, START_VPN_PROFILE);
} catch (ActivityNotFoundException ane) {
// Shame on you Sony! At least one user reported that
// an official Sony Xperia Arc S image triggers this exception
VpnStatus.logError(R.string.no_vpn_support_image);
}
} else {
onActivityResult(START_VPN_PROFILE, Activity.RESULT_OK, null);
}
}
示例11: onClick
import android.net.VpnService; //导入依赖的package包/类
@Override
public void onClick(View v) {
Intent intent = VpnService.prepare(this);
if (intent != null) {
startActivityForResult(intent, 0);
} else {
onActivityResult(0, RESULT_OK, null);
}
}
示例12: 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");
}
}
示例13: startGnirehtet
import android.net.VpnService; //导入依赖的package包/类
private void startGnirehtet(Context context, VpnConfiguration config) {
Intent vpnIntent = VpnService.prepare(context);
if (vpnIntent == null) {
Log.d(TAG, "VPN was already authorized");
// we got the permission, start the service now
GnirehtetService.start(context, config);
} else {
Log.w(TAG, "VPN requires the authorization from the user, requesting...");
requestAuthorization(context, vpnIntent, config);
}
}
示例14: 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();
}
示例15: startVPN
import android.net.VpnService; //导入依赖的package包/类
private void startVPN() {
waitingForVPNStart = false;
Intent vpnIntent = VpnService.prepare(this);
if (vpnIntent != null)
startActivityForResult(vpnIntent, VPN_REQUEST_CODE);
else
onActivityResult(VPN_REQUEST_CODE, RESULT_OK, null);
}