Reputation: 1064
I hope you all are well.
I have implement VPNService in My application. I have refer https://github.com/hexene/LocalVPN github code to create the VPN.
I want to know about the request/response,
How to know Which application send the request or which application receive the response using the VPNService.
I want to block some application request in VPNService.
Thanks in advance.
Upvotes: 3
Views: 1327
Reputation: 401
If you just need a simple VpnService that blocks application traffic, without needing the extra feature of handling the packet tcp/udp headers that LocalVPN offers, you can just use ToyVPN (https://android.googlesource.com/platform/development/+/master/samples/ToyVpn) and use builder.addAllowedApplication or builder.addDisallowedApplication.
ToyVpnConnection.java:
for (String packageName : mPackages) {
try {
if (mAllow) {
builder.addAllowedApplication(packageName);
} else {
builder.addDisallowedApplication(packageName);
}
} catch (PackageManager.NameNotFoundException e){
Log.w(getTag(), "Package not available: " + packageName, e);
}
}
However, if you need low level access to the packets like with LocalVPN, then I am unsure how to do this. If you find out, please post any tips on accomplishing this as I am currently trying to figure this out myself!
Upvotes: 1