From 9987665d78f81bb453a21f88ad48bf1d0ec2429d Mon Sep 17 00:00:00 2001 From: Chiachang Wang Date: Thu, 10 Mar 2022 15:18:17 +0800 Subject: [PATCH] Add protection for setLocalRoutesExcludedForVpn setLocalRoutesExcludedForVpn() was added in T for local route exclusion in VPN. It relies on the behavior change in netd which is inside platform and will not be updated with mainline update. Add protection on setLocalRoutesExcludedForVpn to prevent the API misused on SDK before T. Bug: 223356811 Test: atest FrameworksNetTests Change-Id: Ic2927f5c335ddd0c3defd4c377542ce6907ab435 --- framework/src/android/net/NetworkAgentConfig.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/framework/src/android/net/NetworkAgentConfig.java b/framework/src/android/net/NetworkAgentConfig.java index b28c00635f..0d2b620c50 100644 --- a/framework/src/android/net/NetworkAgentConfig.java +++ b/framework/src/android/net/NetworkAgentConfig.java @@ -24,6 +24,8 @@ import android.annotation.SystemApi; import android.os.Parcel; import android.os.Parcelable; +import com.android.modules.utils.build.SdkLevel; + import java.util.Objects; /** @@ -473,6 +475,9 @@ public final class NetworkAgentConfig implements Parcelable { @NonNull @SystemApi(client = MODULE_LIBRARIES) public Builder setLocalRoutesExcludedForVpn(boolean excludeLocalRoutes) { + if (!SdkLevel.isAtLeastT()) { + throw new UnsupportedOperationException("Method is not supported"); + } mConfig.excludeLocalRouteVpn = excludeLocalRoutes; return this; }