Java Code Examples for android.net.VpnService#Builder
The following examples show how to use
android.net.VpnService#Builder .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntraVpnService.java From Intra with Apache License 2.0 | 6 votes |
public VpnService.Builder newBuilder() { VpnService.Builder builder = new VpnService.Builder(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // Some WebRTC apps rely on the ability to bind to specific interfaces, which is only // possible if we allow bypass. builder = builder.allowBypass(); try { // Workaround for any app incompatibility bugs. for (String packageName : PersistentState.getExcludedPackages(this)) { builder = builder.addDisallowedApplication(packageName); } // Play Store incompatibility is a known issue, so always exclude it. builder = builder.addDisallowedApplication("com.android.vending"); } catch (PackageManager.NameNotFoundException e) { LogWrapper.logException(e); Log.e(LOG_TAG, "Failed to exclude an app", e); } } return builder; }
Example 2
Source File: GoVpnAdapter.java From Intra with Apache License 2.0 | 6 votes |
private static ParcelFileDescriptor establishVpn(IntraVpnService vpnService) { try { VpnService.Builder builder = vpnService.newBuilder() .setSession("Intra go-tun2socks VPN") .setMtu(VPN_INTERFACE_MTU) .addAddress(LanIp.GATEWAY.make(IPV4_TEMPLATE), IPV4_PREFIX_LENGTH) .addRoute("0.0.0.0", 0) .addDnsServer(LanIp.DNS.make(IPV4_TEMPLATE)); if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) { builder.addDisallowedApplication(vpnService.getPackageName()); } return builder.establish(); } catch (Exception e) { LogWrapper.logException(e); return null; } }
Example 3
Source File: ProxyService.java From igniter with GNU General Public License v3.0 | 6 votes |
/** * Apply allow or disallow rule on application by package names. */ private void applyApplicationOrientedRule(VpnService.Builder builder) { boolean workInAllowMode = PreferenceUtils.getBooleanPreference(getContentResolver(), Uri.parse(Constants.PREFERENCE_URI), Constants.PREFERENCE_KEY_PROXY_IN_ALLOW_MODE, false); Set<String> exemptAppPackageNames = getExemptAppPackageNames(workInAllowMode); RuleApplier applier; if (workInAllowMode) { exemptAppPackageNames.remove(getPackageName()); // disallow Igniter applier = Builder::addAllowedApplication; } else { exemptAppPackageNames.add(getPackageName()); // disallow Igniter applier = Builder::addDisallowedApplication; } for (String packageName : exemptAppPackageNames) { try { applier.applyRule(builder, packageName); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); setState(STOPPED); } } }
Example 4
Source File: BuilderVPN.java From InviZible with GNU General Public License v3.0 | 5 votes |
@NonNull @Override public VpnService.Builder setMtu(int mtu) { this.mtu = mtu; super.setMtu(mtu); return this; }
Example 5
Source File: BuilderVPN.java From InviZible with GNU General Public License v3.0 | 5 votes |
@NonNull @Override public VpnService.Builder addAllowedApplication(@NonNull String packageName) throws PackageManager.NameNotFoundException { listAllowed.add(packageName); performAllowedOrDisallowed = "allowed"; super.addAllowedApplication(packageName); return this; }
Example 6
Source File: ServiceSinkhole.java From tracker-control-android with GNU General Public License v3.0 | 4 votes |
@Override public VpnService.Builder setMtu(int mtu) { this.mtu = mtu; super.setMtu(mtu); return this; }
Example 7
Source File: ServiceSinkhole.java From NetGuard with GNU General Public License v3.0 | 4 votes |
@Override public VpnService.Builder setMtu(int mtu) { this.mtu = mtu; super.setMtu(mtu); return this; }
Example 8
Source File: ProxyService.java From igniter with GNU General Public License v3.0 | votes |
void applyRule(VpnService.Builder builder, String packageName) throws PackageManager.NameNotFoundException;