I am trying to make a VPN Service work on android.
To do this, I think I have to use the Builder class provided in the VpnService class, which is provided by the android SDK. Now when I try to do this, the method
builder.establish()
returns null. Here is the full method I wrote;
// If theInterface still exists from last time, reuse it, it has the same parameters.
if (theInterface != null) {
return;
}
// configure the VPN settings.
Builder builder = new Builder();
builder.setMtu(1500);
builder.addAddress("10.0.2.0", 32);
builder.addRoute("0.0.0.0", 0);
try {
theInterface.close();
} catch (Exception e) {
// Ignore
}
theInterface = builder.establish();
Log.i(TAG + "IMPORTANT", builder.toString());
The code crashes at:
Log.i(TAG + "IMPORTANT", builder.toString());
When debugging, the debugger says 'theInterface = null' throughout the entire execution of the program.
EDIT:
I have looked trough the Builder class which is located in android.net.VpnService
In this class, it seems that there is a hidden class (IConnectivityManager), maybe my problem has something to do with this...
Here is the piece of code I'm talking about.
/**
* Use IConnectivityManager since those methods are hidden and not
* available in ConnectivityManager.
*/
private static IConnectivityManager getService() {
return IConnectivityManager.Stub.asInterface(
ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
}
as VpnService.Builder.establish documents:
Returns ParcelFileDescriptor of the VPN interface, or null if the application is not prepared.
need call VpnService.prepare: http://developer.android.com/reference/android/net/VpnService.html#prepare(android.content.Context) first
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With