当前位置: 首页>>代码示例>>Java>>正文


Java VpnService类代码示例

本文整理汇总了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());
  }
}
 
开发者ID:UWNetworksLab,项目名称:colony,代码行数:18,代码来源:OpenVPN.java

示例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);
}
 
开发者ID:iTXTech,项目名称:Daedalus,代码行数:20,代码来源:BootBroadcastReceiver.java

示例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);
	}
}
 
开发者ID:neilalexander,项目名称:sigmavpn-android,代码行数:13,代码来源:SigmaVPNClient.java

示例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));
    }
}
 
开发者ID:msayan,项目名称:star-dns-changer,代码行数:15,代码来源:MainActivity.java

示例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();
    }
}
 
开发者ID:akashdeepsingh9988,项目名称:Cybernet-VPN,代码行数:15,代码来源:VpnAuthActivity.java

示例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);
}
 
开发者ID:parameshg,项目名称:apc,代码行数:27,代码来源:MainActivity.java

示例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);
    }
}
 
开发者ID:julian-klode,项目名称:dns66,代码行数:25,代码来源:AdVpnService.java

示例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;
}
 
开发者ID:julian-klode,项目名称:dns66,代码行数:19,代码来源:AdVpnThread.java

示例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);
    }
}
 
开发者ID:julian-klode,项目名称:dns66,代码行数:24,代码来源:AdVpnThread.java

示例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);
    }
}
 
开发者ID:MaxSmile,项目名称:EasyVPN-Free,代码行数:24,代码来源:ServerActivity.java

示例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);
  }
}
 
开发者ID:joeysilva-g,项目名称:vpn,代码行数:10,代码来源:ToyVpnClient.java

示例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");
	}
}
 
开发者ID:cernekee,项目名称:ics-openconnect,代码行数:22,代码来源:OpenConnectManagementThread.java

示例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);
    }
}
 
开发者ID:Genymobile,项目名称:gnirehtet,代码行数:12,代码来源:GnirehtetControlReceiver.java

示例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();
}
 
开发者ID:comp500,项目名称:SSLSocks,代码行数:9,代码来源:StunnelVpnService.java

示例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);
}
 
开发者ID:x-falcon,项目名称:Virtual-Hosts,代码行数:9,代码来源:MainActivity.java


注:本文中的android.net.VpnService类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。