Set underlying connection after establish

This commit is contained in:
M66B 2018-12-07 13:46:30 +01:00
parent 4ec7f60c8c
commit dc1f179012
1 changed files with 13 additions and 11 deletions

View File

@ -1174,7 +1174,19 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private ParcelFileDescriptor startVPN(Builder builder) throws SecurityException {
try {
return builder.establish();
ParcelFileDescriptor pfd = builder.establish();
// Set underlying network
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
Network active = (cm == null ? null : cm.getActiveNetwork());
if (active != null) {
Log.i(TAG, "Setting underlying network=" + cm.getNetworkInfo(active));
setUnderlyingNetworks(new Network[]{active});
}
}
return pfd;
} catch (SecurityException ex) {
throw ex;
} catch (Throwable ex) {
@ -1338,16 +1350,6 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
if (ip6)
builder.addRoute("2000::", 3); // unicast
// Set underlying network
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
Network active = (cm == null ? null : cm.getActiveNetwork());
if (active != null) {
Log.i(TAG, "Setting underlying network=" + cm.getNetworkInfo(active));
builder.setUnderlyingNetworks(new Network[]{active});
}
}
// MTU
int mtu = jni_get_mtu();
Log.i(TAG, "MTU=" + mtu);