Implement VpnService.setBlocking().
Bug: 12879610 Change-Id: I3a0ad9eae5f7dd9c01f75b9da71810bad38f9fec
This commit is contained in:
@@ -577,7 +577,7 @@ public class VpnService extends Service {
|
||||
* @return this {@link Builder} object to facilitate chaining method calls.
|
||||
*/
|
||||
public Builder setBlocking(boolean blocking) {
|
||||
// TODO
|
||||
mConfig.blocking = blocking;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,7 @@ public class VpnConfig implements Parcelable {
|
||||
public PendingIntent configureIntent;
|
||||
public long startTime = -1;
|
||||
public boolean legacy;
|
||||
public boolean blocking;
|
||||
|
||||
public void addLegacyRoutes(String routesStr) {
|
||||
if (routesStr.trim().equals("")) {
|
||||
@@ -120,6 +121,7 @@ public class VpnConfig implements Parcelable {
|
||||
out.writeParcelable(configureIntent, flags);
|
||||
out.writeLong(startTime);
|
||||
out.writeInt(legacy ? 1 : 0);
|
||||
out.writeInt(blocking ? 1 : 0);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<VpnConfig> CREATOR =
|
||||
@@ -138,6 +140,7 @@ public class VpnConfig implements Parcelable {
|
||||
config.configureIntent = in.readParcelable(null);
|
||||
config.startTime = in.readLong();
|
||||
config.legacy = in.readInt() != 0;
|
||||
config.blocking = in.readInt() != 0;
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
@@ -77,6 +77,7 @@ import com.android.internal.net.VpnProfile;
|
||||
import com.android.server.net.BaseNetworkObserver;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetAddress;
|
||||
@@ -470,6 +471,13 @@ public class Vpn {
|
||||
if (oldInterface != null && !oldInterface.equals(interfaze)) {
|
||||
jniReset(oldInterface);
|
||||
}
|
||||
|
||||
try {
|
||||
IoUtils.setBlocking(tun.getFileDescriptor(), config.blocking);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(
|
||||
"Cannot set tunnel's fd as blocking=" + config.blocking, e);
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
IoUtils.closeQuietly(tun);
|
||||
agentDisconnect();
|
||||
|
||||
Reference in New Issue
Block a user