Snap for 8072266 from 6ee91ee624dbef287f3ef0f2cd6edb3d90101ffb to mainline-sdkext-release

Change-Id: I7baecf16e07d9c05b19994766f1459f495b278c9
diff --git a/Android.bp b/Android.bp
index 026870c..dd7e8c6 100644
--- a/Android.bp
+++ b/Android.bp
@@ -158,10 +158,10 @@
 // stable and have no defined version number. These could be called 10000, but they use the next
 // integer so if the next SDK release happens to use that integer, we don't need to rename them.
 java_library {
-    name: "NetworkStackApi32Shims",
+    name: "NetworkStackApi33Shims",
     defaults: ["NetworkStackShimsDefaults"],
     srcs: [
-        "apishim/32/**/*.java",
+        "apishim/33/**/*.java",
     ],
     libs: [
         "NetworkStackShimsCommon",
@@ -185,12 +185,13 @@
         "NetworkStackApi29Shims",
         "NetworkStackApi30Shims",
         "NetworkStackApi31Shims",
-        "NetworkStackApi32Shims",
+        "NetworkStackApi33Shims",
     ],
     sdk_version: "module_current",
     visibility: [
         "//packages/modules/Connectivity/Tethering",
         "//packages/modules/Connectivity/tests/cts/net",
+        "//packages/modules/Connectivity/tests/cts/hostside/app",
     ],
 }
 
@@ -211,6 +212,7 @@
     visibility: [
         "//packages/modules/Connectivity/Tethering",
         "//packages/modules/Connectivity/tests/cts/net",
+        "//packages/modules/Connectivity/tests/cts/hostside/app",
     ],
 }
 
diff --git a/apishim/29/com/android/networkstack/apishim/api29/VpnServiceBuilderShimImpl.java b/apishim/29/com/android/networkstack/apishim/api29/VpnServiceBuilderShimImpl.java
new file mode 100644
index 0000000..0f221bf
--- /dev/null
+++ b/apishim/29/com/android/networkstack/apishim/api29/VpnServiceBuilderShimImpl.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.networkstack.apishim.api29;
+
+import android.net.IpPrefix;
+import android.net.VpnService;
+
+import com.android.networkstack.apishim.common.UnsupportedApiLevelException;
+import com.android.networkstack.apishim.common.VpnServiceBuilderShim;
+
+/**
+ * Implementation of {@link com.android.networkstack.apishim.common.VpnServiceBuilderShim}.
+ */
+public class VpnServiceBuilderShimImpl implements VpnServiceBuilderShim {
+
+    /**
+     * Get a new instance of {@link VpnServiceBuilderShim}.
+     */
+    public static VpnServiceBuilderShim newInstance() {
+        return new VpnServiceBuilderShimImpl();
+    }
+
+    @Override
+    public VpnService.Builder excludeRoute(VpnService.Builder builder, IpPrefix prefix)
+            throws UnsupportedApiLevelException {
+        throw new UnsupportedApiLevelException("Only supported after API level 31.");
+    }
+
+    @Override
+    public VpnService.Builder addRoute(VpnService.Builder builder, IpPrefix prefix)
+            throws UnsupportedApiLevelException {
+        throw new UnsupportedApiLevelException("Only supported after API level 31.");
+    }
+}
diff --git a/apishim/31/com/android/networkstack/apishim/api31/VpnServiceBuilderShimImpl.java b/apishim/31/com/android/networkstack/apishim/api31/VpnServiceBuilderShimImpl.java
new file mode 100644
index 0000000..8b82935
--- /dev/null
+++ b/apishim/31/com/android/networkstack/apishim/api31/VpnServiceBuilderShimImpl.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.networkstack.apishim.api31;
+
+/**
+ * Implementation of {@link com.android.networkstack.apishim.common.VpnServiceBuilderShim}.
+ */
+public class VpnServiceBuilderShimImpl extends
+        com.android.networkstack.apishim.api29.VpnServiceBuilderShimImpl {
+}
diff --git a/apishim/32/com/android/networkstack/apishim/CaptivePortalDataShimImpl.java b/apishim/33/com/android/networkstack/apishim/CaptivePortalDataShimImpl.java
similarity index 92%
rename from apishim/32/com/android/networkstack/apishim/CaptivePortalDataShimImpl.java
rename to apishim/33/com/android/networkstack/apishim/CaptivePortalDataShimImpl.java
index 2056b1b..63fa021 100644
--- a/apishim/32/com/android/networkstack/apishim/CaptivePortalDataShimImpl.java
+++ b/apishim/33/com/android/networkstack/apishim/CaptivePortalDataShimImpl.java
@@ -27,7 +27,7 @@
 /**
  * Compatibility implementation of {@link CaptivePortalDataShim}.
  */
-@RequiresApi(Build.VERSION_CODES.S) // Change to T when version code available, and adding T methods
+@RequiresApi(Build.VERSION_CODES.TIRAMISU)
 public class CaptivePortalDataShimImpl
         extends com.android.networkstack.apishim.api31.CaptivePortalDataShimImpl {
     // Currently identical to the API 31 shim, so inherit everything
diff --git a/apishim/32/com/android/networkstack/apishim/ConnectivityManagerShimImpl.java b/apishim/33/com/android/networkstack/apishim/ConnectivityManagerShimImpl.java
similarity index 92%
rename from apishim/32/com/android/networkstack/apishim/ConnectivityManagerShimImpl.java
rename to apishim/33/com/android/networkstack/apishim/ConnectivityManagerShimImpl.java
index a7aa0c8..7675960 100644
--- a/apishim/32/com/android/networkstack/apishim/ConnectivityManagerShimImpl.java
+++ b/apishim/33/com/android/networkstack/apishim/ConnectivityManagerShimImpl.java
@@ -26,7 +26,7 @@
 /**
  * Compatibility implementation of {@link ConnectivityManagerShim}.
  */
-@RequiresApi(Build.VERSION_CODES.S) // Change to T when version code available, and adding T methods
+@RequiresApi(Build.VERSION_CODES.TIRAMISU)
 public class ConnectivityManagerShimImpl
         extends com.android.networkstack.apishim.api31.ConnectivityManagerShimImpl  {
     // Currently identical to the API 31 shim, so inherit everything
diff --git a/apishim/32/com/android/networkstack/apishim/ConstantsShim.java b/apishim/33/com/android/networkstack/apishim/ConstantsShim.java
similarity index 96%
rename from apishim/32/com/android/networkstack/apishim/ConstantsShim.java
rename to apishim/33/com/android/networkstack/apishim/ConstantsShim.java
index 0a5b555..6d146f5 100644
--- a/apishim/32/com/android/networkstack/apishim/ConstantsShim.java
+++ b/apishim/33/com/android/networkstack/apishim/ConstantsShim.java
@@ -29,5 +29,5 @@
      * the shimmed objects and methods themselves.
      */
     @VisibleForTesting
-    public static final int VERSION = 32;
+    public static final int VERSION = 33;
 }
diff --git a/apishim/32/com/android/networkstack/apishim/NetworkInformationShimImpl.java b/apishim/33/com/android/networkstack/apishim/NetworkInformationShimImpl.java
similarity index 91%
rename from apishim/32/com/android/networkstack/apishim/NetworkInformationShimImpl.java
rename to apishim/33/com/android/networkstack/apishim/NetworkInformationShimImpl.java
index 28aa75c..d51ef40 100644
--- a/apishim/32/com/android/networkstack/apishim/NetworkInformationShimImpl.java
+++ b/apishim/33/com/android/networkstack/apishim/NetworkInformationShimImpl.java
@@ -25,7 +25,7 @@
 /**
  * Compatibility implementation of {@link NetworkInformationShim}.
  */
-@RequiresApi(Build.VERSION_CODES.S) // Change to T when version code available, and adding T methods
+@RequiresApi(Build.VERSION_CODES.TIRAMISU)
 public class NetworkInformationShimImpl
         extends com.android.networkstack.apishim.api31.NetworkInformationShimImpl {
     // Currently identical to the API 31 shim, so inherit everything
diff --git a/apishim/32/com/android/networkstack/apishim/NetworkRequestShimImpl.java b/apishim/33/com/android/networkstack/apishim/NetworkRequestShimImpl.java
similarity index 86%
rename from apishim/32/com/android/networkstack/apishim/NetworkRequestShimImpl.java
rename to apishim/33/com/android/networkstack/apishim/NetworkRequestShimImpl.java
index 95ae5ba..72dfef2 100644
--- a/apishim/32/com/android/networkstack/apishim/NetworkRequestShimImpl.java
+++ b/apishim/33/com/android/networkstack/apishim/NetworkRequestShimImpl.java
@@ -23,9 +23,9 @@
 import com.android.networkstack.apishim.common.NetworkRequestShim;
 
 /**
- * Implementation of {@link NetworkRequestShim} for API 31.
+ * Implementation of {@link NetworkRequestShim} for API 33.
  */
-@RequiresApi(Build.VERSION_CODES.S) // Change to T when version code available, and adding T methods
+@RequiresApi(Build.VERSION_CODES.TIRAMISU)
 public class NetworkRequestShimImpl
         extends com.android.networkstack.apishim.api31.NetworkRequestShimImpl {
     // Currently identical to the API 31 shim, so inherit everything
diff --git a/apishim/32/com/android/networkstack/apishim/NetworkShimImpl.java b/apishim/33/com/android/networkstack/apishim/NetworkShimImpl.java
similarity index 91%
rename from apishim/32/com/android/networkstack/apishim/NetworkShimImpl.java
rename to apishim/33/com/android/networkstack/apishim/NetworkShimImpl.java
index 2e31a78..0968c4c 100644
--- a/apishim/32/com/android/networkstack/apishim/NetworkShimImpl.java
+++ b/apishim/33/com/android/networkstack/apishim/NetworkShimImpl.java
@@ -25,7 +25,7 @@
 /**
  * Compatibility implementation of {@link com.android.networkstack.apishim.common.NetworkShim}.
  */
-@RequiresApi(Build.VERSION_CODES.S) // Change to T when version code available, and adding T methods
+@RequiresApi(Build.VERSION_CODES.TIRAMISU)
 public class NetworkShimImpl extends com.android.networkstack.apishim.api30.NetworkShimImpl {
     // Currently, this is the same as the API 31 shim, so inherit everything from that.
     protected NetworkShimImpl(@NonNull Network network) {
diff --git a/apishim/32/com/android/networkstack/apishim/SettingsShimImpl.java b/apishim/33/com/android/networkstack/apishim/SettingsShimImpl.java
similarity index 90%
rename from apishim/32/com/android/networkstack/apishim/SettingsShimImpl.java
rename to apishim/33/com/android/networkstack/apishim/SettingsShimImpl.java
index 46d2102..cd3a463 100644
--- a/apishim/32/com/android/networkstack/apishim/SettingsShimImpl.java
+++ b/apishim/33/com/android/networkstack/apishim/SettingsShimImpl.java
@@ -23,9 +23,9 @@
 import com.android.networkstack.apishim.common.SettingsShim;
 
 /**
- * Compatibility implementation of {@link SettingsShim} for API 31.
+ * Compatibility implementation of {@link SettingsShim} for API 33.
  */
-@RequiresApi(Build.VERSION_CODES.S) // Change to T when version code available, and adding T methods
+@RequiresApi(Build.VERSION_CODES.TIRAMISU)
 public class SettingsShimImpl
         extends com.android.networkstack.apishim.api30.SettingsShimImpl {
     // Currently identical to the API 31 shim, so inherit everything
diff --git a/apishim/32/com/android/networkstack/apishim/SocketUtilsShimImpl.java b/apishim/33/com/android/networkstack/apishim/SocketUtilsShimImpl.java
similarity index 91%
rename from apishim/32/com/android/networkstack/apishim/SocketUtilsShimImpl.java
rename to apishim/33/com/android/networkstack/apishim/SocketUtilsShimImpl.java
index 2f4e500..d4ab534 100644
--- a/apishim/32/com/android/networkstack/apishim/SocketUtilsShimImpl.java
+++ b/apishim/33/com/android/networkstack/apishim/SocketUtilsShimImpl.java
@@ -23,7 +23,7 @@
 /**
  * Implementation of {@link com.android.networkstack.apishim.common.SocketUtilsShim}.
  */
-@RequiresApi(Build.VERSION_CODES.S) // Change to T when version code available, and adding T methods
+@RequiresApi(Build.VERSION_CODES.TIRAMISU)
 public class SocketUtilsShimImpl
         extends com.android.networkstack.apishim.api30.SocketUtilsShimImpl {
     // Currently, this is the same as the API 31 shim, so inherit everything from that.
diff --git a/apishim/33/com/android/networkstack/apishim/VpnServiceBuilderShimImpl.java b/apishim/33/com/android/networkstack/apishim/VpnServiceBuilderShimImpl.java
new file mode 100644
index 0000000..da8f774
--- /dev/null
+++ b/apishim/33/com/android/networkstack/apishim/VpnServiceBuilderShimImpl.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.networkstack.apishim;
+
+import android.net.IpPrefix;
+import android.net.VpnService;
+import android.os.Build;
+
+import androidx.annotation.RequiresApi;
+
+import com.android.modules.utils.build.SdkLevel;
+import com.android.networkstack.apishim.common.UnsupportedApiLevelException;
+import com.android.networkstack.apishim.common.VpnServiceBuilderShim;
+
+/**
+ * Implementation of {@link com.android.networkstack.apishim.common.VpnServiceBuilderShim}.
+ */
+@RequiresApi(Build.VERSION_CODES.TIRAMISU)
+public class VpnServiceBuilderShimImpl extends
+        com.android.networkstack.apishim.api31.VpnServiceBuilderShimImpl {
+
+    /**
+     * Get a new instance of {@link VpnServiceBuilderShim}.
+     */
+    @RequiresApi(Build.VERSION_CODES.Q)
+    public static VpnServiceBuilderShim newInstance() {
+        if (SdkLevel.isAtLeastT()) {
+            return new VpnServiceBuilderShimImpl();
+        } else {
+            return new com.android.networkstack.apishim.api31.VpnServiceBuilderShimImpl();
+        }
+    }
+
+    @Override
+    public VpnService.Builder excludeRoute(VpnService.Builder builder, IpPrefix prefix)
+            throws UnsupportedApiLevelException {
+        return builder.excludeRoute(prefix);
+    }
+
+    @Override
+    public VpnService.Builder addRoute(VpnService.Builder builder, IpPrefix prefix)
+            throws UnsupportedApiLevelException {
+        return builder.addRoute(prefix);
+    }
+}
diff --git a/apishim/common/com/android/networkstack/apishim/common/VpnServiceBuilderShim.java b/apishim/common/com/android/networkstack/apishim/common/VpnServiceBuilderShim.java
new file mode 100644
index 0000000..fbfcf6c
--- /dev/null
+++ b/apishim/common/com/android/networkstack/apishim/common/VpnServiceBuilderShim.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.networkstack.apishim.common;
+
+import android.net.IpPrefix;
+import android.net.VpnService;
+
+/** Shim for {@link VpnService.Builder}. */
+public interface VpnServiceBuilderShim {
+    /**
+     * @see VpnService.Builder#excludeRoute(IpPrefix)
+     */
+    VpnService.Builder excludeRoute(VpnService.Builder builder, IpPrefix prefix)
+            throws UnsupportedApiLevelException;
+
+    /**
+     * @see VpnService.Builder#addRoute(IpPrefix)
+     */
+    VpnService.Builder addRoute(VpnService.Builder builder, IpPrefix prefix)
+            throws UnsupportedApiLevelException;
+}