From 0ad175531b803ce9ac8941c32e2e6db30e5bac6d Mon Sep 17 00:00:00 2001 From: lucaslin Date: Mon, 22 Mar 2021 15:07:41 +0800 Subject: [PATCH] Have a new method in NetworkAgentConfig.Builder to set allowBypass Have a new method in NetworkAgentConfig.Builder for Vpn to set allowBypass. Bug: 182963397 Test: m Change-Id: I3f244464438325ee7f8a1b953d3fb28186293628 --- .../framework/api/module-lib-current.txt | 2 ++ .../src/android/net/NetworkAgentConfig.java | 23 +++++++++++++++++++ .../com/android/server/connectivity/Vpn.java | 5 ++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/packages/Connectivity/framework/api/module-lib-current.txt b/packages/Connectivity/framework/api/module-lib-current.txt index 9ca6d8fedc680..663a4ff9dbf54 100644 --- a/packages/Connectivity/framework/api/module-lib-current.txt +++ b/packages/Connectivity/framework/api/module-lib-current.txt @@ -36,9 +36,11 @@ package android.net { public final class NetworkAgentConfig implements android.os.Parcelable { method @Nullable public String getSubscriberId(); + method public boolean isBypassableVpn(); } public static final class NetworkAgentConfig.Builder { + method @NonNull public android.net.NetworkAgentConfig.Builder setBypassableVpn(boolean); method @NonNull public android.net.NetworkAgentConfig.Builder setSubscriberId(@Nullable String); } diff --git a/packages/Connectivity/framework/src/android/net/NetworkAgentConfig.java b/packages/Connectivity/framework/src/android/net/NetworkAgentConfig.java index 5e50a6404acb3..0bd2371bfca8b 100644 --- a/packages/Connectivity/framework/src/android/net/NetworkAgentConfig.java +++ b/packages/Connectivity/framework/src/android/net/NetworkAgentConfig.java @@ -63,6 +63,16 @@ public final class NetworkAgentConfig implements Parcelable { return explicitlySelected; } + /** + * @return whether this VPN connection can be bypassed by the apps. + * + * @hide + */ + @SystemApi(client = MODULE_LIBRARIES) + public boolean isBypassableVpn() { + return allowBypass; + } + /** * Set if the user desires to use this network even if it is unvalidated. This field has meaning * only if {@link explicitlySelected} is true. If it is, this field must also be set to the @@ -346,6 +356,19 @@ public final class NetworkAgentConfig implements Parcelable { return this; } + /** + * Sets whether the apps can bypass the VPN connection. + * + * @return this builder, to facilitate chaining. + * @hide + */ + @NonNull + @SystemApi(client = MODULE_LIBRARIES) + public Builder setBypassableVpn(boolean allowBypass) { + mConfig.allowBypass = allowBypass; + return this; + } + /** * Returns the constructed {@link NetworkAgentConfig} object. */ diff --git a/services/core/java/com/android/server/connectivity/Vpn.java b/services/core/java/com/android/server/connectivity/Vpn.java index 64173bbcc500f..1b39d848097d8 100644 --- a/services/core/java/com/android/server/connectivity/Vpn.java +++ b/services/core/java/com/android/server/connectivity/Vpn.java @@ -1248,8 +1248,9 @@ public class Vpn { mLegacyState = LegacyVpnInfo.STATE_CONNECTING; updateState(DetailedState.CONNECTING, "agentConnect"); - NetworkAgentConfig networkAgentConfig = new NetworkAgentConfig.Builder().build(); - networkAgentConfig.allowBypass = mConfig.allowBypass && !mLockdown; + final NetworkAgentConfig networkAgentConfig = new NetworkAgentConfig.Builder() + .setBypassableVpn(mConfig.allowBypass && !mLockdown) + .build(); capsBuilder.setOwnerUid(mOwnerUID); capsBuilder.setAdministratorUids(new int[] {mOwnerUID});