Reputation: 582
So I'm trying to block Google Chrome from accessing the Internet whereas other applications can do so. I'm using VPNService API provided by android. The VPN service is setup correctly but I'm unable to block chrome.
This is the -
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setupVPN();
}
return START_NOT_STICKY;
}
private void setupVPN() {
try {
Builder builder = new Builder();
builder.setSession("MyVPNService")
.addAddress("192.168.0.1", 24)
.addDnsServer("8.8.8.8")
.addRoute("0.0.0.0", 0)
.addDisallowedApplication("com.android.chrome")
.establish();
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
}
I tried using addDisallowedApplication
but as android doc says
Adds an application that's denied access to the VPN connection. By default, all applications are allowed access, except for those denied through this method. Denied applications will use networking as if the VPN wasn't running. A VpnService.Builder may have only a set of allowed applications OR a set of disallowed ones, but not both. Calling this method after addAllowedApplication(String) has already been called, or vice versa, will throw an UnsupportedOperationException. packageName must be the canonical name of a currently installed application. PackageManager.NameNotFoundException is thrown if there's no such application.
So how do I successfully block Chrome or any other application?
Upvotes: 1
Views: 2148
Reputation: 342
I can confirm that addDisallowedApplication
does work; as described it excludes the given package from using the VPN.
In your case that would mean that Chrome does not use the VPN but the "normal", plain connection. Of course this does not block it in any way.
If you want to block Chrome via a VPN you might want to use addAllowedApplication
. Of course you then have to make sure that your VPN server does block the connection.
Upvotes: 2