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?