Snap for 8564071 from 39ed6def9c4f3ebae971283806dd85ddf66bc93f to mainline-resolv-release

Change-Id: I6f9a90351d0a8277da1b3a0c190aa73152da8073
diff --git a/Android.bp b/Android.bp
index 03b4318..109b229 100644
--- a/Android.bp
+++ b/Android.bp
@@ -48,6 +48,7 @@
     stem: "libquiche",
     host_supported: true,
     crate_name: "quiche",
+    cargo_env_compat: true,
     srcs: ["src/lib.rs"],
     edition: "2018",
     features: [
@@ -78,6 +79,11 @@
         "libcrypto",
         "libssl",
     ],
+    apex_available: [
+        "//apex_available:platform",
+        "com.android.resolv",
+    ],
+    min_sdk_version: "29",
 }
 
 rust_library {
@@ -98,17 +104,23 @@
         "libcrypto_static",
         "libssl",
     ],
+    apex_available: [
+        "//apex_available:platform",
+        "com.android.resolv",
+    ],
+    min_sdk_version: "29",
 }
 
 rust_defaults {
-    name: "quiche_defaults",
+    name: "quiche_test_defaults",
     crate_name: "quiche",
+    cargo_env_compat: true,
     srcs: ["src/lib.rs"],
     test_suites: ["general-tests"],
     auto_gen_config: true,
     edition: "2018",
     features: [
-        "boringssl",
+        "boringssl-vendored",
         "default",
     ],
     rustlibs: [
@@ -125,12 +137,12 @@
         "examples/cert.key",
         "examples/cert-big.crt",
         "examples/rootca.crt",
-    ]
+    ],
 }
 
 rust_test_host {
     name: "quiche_host_test_src_lib",
-    defaults: ["quiche_defaults"],
+    defaults: ["quiche_test_defaults"],
     test_options: {
         unit_test: true,
     },
@@ -142,7 +154,7 @@
 
 rust_test {
     name: "quiche_device_test_src_lib",
-    defaults: ["quiche_defaults"],
+    defaults: ["quiche_test_defaults"],
     // To run this test in R platform, it's required to statically link
     // libcrypto and libssl.
     static_libs: [
@@ -150,29 +162,3 @@
         "libssl",
     ],
 }
-
-// dependent_library ["feature_list"]
-//   cc-1.0.68
-//   cfg-if-0.1.10
-//   cfg-if-1.0.0
-//   cmake-0.1.45
-//   idna-0.1.5
-//   iovec-0.1.4
-//   lazy_static-1.4.0
-//   libc-0.2.95 "default,std"
-//   libm-0.2.1 "default"
-//   log-0.4.14 "std"
-//   matches-0.1.8
-//   mio-0.6.23 "default,with-deprecated"
-//   net2-0.2.37 "default,duration"
-//   once_cell-1.7.2 "alloc,race,std"
-//   percent-encoding-1.0.1
-//   ring-0.16.20 "alloc,default,dev_urandom_fallback,once_cell"
-//   slab-0.4.3 "default,std"
-//   spin-0.5.2
-//   tinyvec-1.2.0 "alloc,default,tinyvec_macros"
-//   tinyvec_macros-0.1.0
-//   unicode-bidi-0.3.5 "default"
-//   unicode-normalization-0.1.19 "default,std"
-//   untrusted-0.7.1
-//   url-1.7.2
diff --git a/TEST_MAPPING b/TEST_MAPPING
index ba9a257..1d3032b 100644
--- a/TEST_MAPPING
+++ b/TEST_MAPPING
@@ -7,5 +7,13 @@
     {
       "name": "quiche_device_test_src_lib"
     }
+  ],
+  "presubmit-rust": [
+    {
+      "name": "doh_unit_test"
+    },
+    {
+      "name": "quiche_device_test_src_lib"
+    }
   ]
 }
diff --git a/cargo2android.json b/cargo2android.json
index e34fbf5..1317ea7 100644
--- a/cargo2android.json
+++ b/cargo2android.json
@@ -1,12 +1,19 @@
 {
-    "apex-available": [
-      "//apex_available:platform",
-      "com.android.resolv"
-    ],
-    "min_sdk_version": "29",
-    "dependencies": true,
-    "tests": true,
-    "device": true,
-    "run": true,
-    "patch": "patches/Android.bp.patch"
-  }
\ No newline at end of file
+  "apex-available": [
+    "//apex_available:platform",
+    "com.android.resolv"
+  ],
+  "dependencies": true,
+  "device": true,
+  "min-sdk-version": "29",
+  "no-pkg-vers": true,
+  "patch": "patches/Android.bp.patch",
+  "run": true,
+  "test-data": [
+    "src/lib.rs=examples/cert.crt",
+    "src/lib.rs=examples/cert.key",
+    "src/lib.rs=examples/cert-big.crt",
+    "src/lib.rs=examples/rootca.crt"
+  ],
+  "tests": true
+}
diff --git a/patches/Android.bp.patch b/patches/Android.bp.patch
index fbd8d17..48c6dee 100644
--- a/patches/Android.bp.patch
+++ b/patches/Android.bp.patch
@@ -2,7 +2,7 @@
 index aced8a6..578cc68 100644
 --- a/Android.bp
 +++ b/Android.bp
-@@ -43,25 +43,38 @@ cc_library_headers {
+@@ -43,26 +43,39 @@ cc_library_headers {
      min_sdk_version: "29",
  }
  
@@ -13,6 +13,7 @@
      stem: "libquiche",
      host_supported: true,
      crate_name: "quiche",
+     cargo_env_compat: true,
      srcs: ["src/lib.rs"],
      edition: "2018",
      features: [
@@ -46,12 +47,13 @@
          "libcrypto",
          "libssl",
      ],
-@@ -69,52 +82,20 @@ rust_ffi_shared {
+@@ -69,54 +82,20 @@ rust_ffi_shared {
  
  rust_library {
      name: "libquiche",
 -    host_supported: true,
 -    crate_name: "quiche",
+-    cargo_env_compat: true,
 -    srcs: ["src/lib.rs"],
 -    edition: "2018",
 -    features: [
@@ -86,6 +88,7 @@
 -    stem: "libquiche",
 -    host_supported: true,
 -    crate_name: "quiche",
+-    cargo_env_compat: true,
 -    srcs: ["src/lib.rs"],
 -    edition: "2018",
 -    features: [
@@ -105,17 +108,28 @@
 +        "libcrypto_static",
          "libssl",
      ],
+     apex_available: [
+@@ -111,17 +90,13 @@ rust_library_rlib {
+     min_sdk_version: "29",
  }
-@@ -127,7 +108,7 @@ rust_defaults {
+ 
+-rust_test {
+-    name: "quiche_test_src_lib",
+-    host_supported: true,
++rust_defaults {
++    name: "quiche_test_defaults",
+     crate_name: "quiche",
+     cargo_env_compat: true,
+     srcs: ["src/lib.rs"],
+     test_suites: ["general-tests"],
      auto_gen_config: true,
+-    test_options: {
+-        unit_test: true,
+-    },
      edition: "2018",
      features: [
--        "boringssl-vendored",
-+        "boringssl",
-         "default",
-     ],
-     rustlibs: [
-@@ -139,10 +120,12 @@ rust_defaults {
+         "boringssl",
+@@ -136,10 +132,6 @@ rust_test {
          "libring",
          "liburl",
      ],
@@ -123,34 +137,33 @@
 -        "libcrypto",
 -        "libssl",
 -    ],
-+    data: [
-+        "examples/cert.crt",
-+        "examples/cert.key",
-+        "examples/cert-big.crt",
-+        "examples/rootca.crt",
-+    ]
+     data: [
+         "examples/cert.crt",
+         "examples/cert.key",
+@@ -149,3 +118,26 @@ rust_test {
+         "examples/rootca.crt",
+     ],
  }
- 
- rust_test_host {
-@@ -151,11 +134,21 @@ rust_test_host {
-     test_options: {
-         unit_test: true,
-     },
++
++rust_test_host {
++    name: "quiche_host_test_src_lib",
++    defaults: ["quiche_test_defaults"],
++    test_options: {
++        unit_test: true,
++    },
 +    shared_libs: [
 +        "libcrypto",
 +        "libssl",
 +    ],
- }
- 
- rust_test {
-     name: "quiche_device_test_src_lib",
-     defaults: ["quiche_defaults"],
++}
++
++rust_test {
++    name: "quiche_device_test_src_lib",
++    defaults: ["quiche_test_defaults"],
 +    // To run this test in R platform, it's required to statically link
 +    // libcrypto and libssl.
 +    static_libs: [
 +        "libcrypto_static",
 +        "libssl",
 +    ],
- }
- 
- // dependent_library ["feature_list"]
++}
diff --git a/patches/lib.rs-app-proto.patch b/patches/lib.rs-app-proto.patch
new file mode 100644
index 0000000..cd02a46
--- /dev/null
+++ b/patches/lib.rs-app-proto.patch
@@ -0,0 +1,47 @@
+--- a/src/lib.rs
++++ b/src/lib.rs
+@@ -6301,7 +6301,7 @@ mod tests {
+             .load_priv_key_from_pem_file("examples/cert.key")
+             .unwrap();
+         config
+-            .set_application_protos(b"\x06proto1\06proto2")
++            .set_application_protos(b"\x06proto1\x06proto2")
+             .unwrap();
+ 
+         let mut pipe = testing::Pipe::with_server_config(&mut config).unwrap();
+@@ -8347,7 +8347,7 @@ mod tests {
+             .load_priv_key_from_pem_file("examples/cert.key")
+             .unwrap();
+         config
+-            .set_application_protos(b"\x06proto1\06proto2")
++            .set_application_protos(b"\x06proto1\x06proto2")
+             .unwrap();
+ 
+         let mut pipe = testing::Pipe::with_server_config(&mut config).unwrap();
+@@ -8407,7 +8407,7 @@ mod tests {
+             .load_priv_key_from_pem_file("examples/cert.key")
+             .unwrap();
+         config
+-            .set_application_protos(b"\x06proto1\06proto2")
++            .set_application_protos(b"\x06proto1\x06proto2")
+             .unwrap();
+ 
+         let mut pipe = testing::Pipe::with_server_config(&mut config).unwrap();
+@@ -8465,7 +8465,7 @@ mod tests {
+             .load_priv_key_from_pem_file("examples/cert.key")
+             .unwrap();
+         config
+-            .set_application_protos(b"\x06proto1\06proto2")
++            .set_application_protos(b"\x06proto1\x06proto2")
+             .unwrap();
+ 
+         let mut pipe = testing::Pipe::with_server_config(&mut config).unwrap();
+@@ -9509,7 +9509,7 @@ mod tests {
+             .load_priv_key_from_pem_file("examples/cert.key")
+             .unwrap();
+         config
+-            .set_application_protos(b"\x06proto1\06proto2")
++            .set_application_protos(b"\x06proto1\x06proto2")
+             .unwrap();
+ 
+         let mut pipe = testing::Pipe::with_server_config(&mut config).unwrap();
diff --git a/patches/lib.rs.patch b/patches/lib.rs.patch
deleted file mode 100644
index 69f4efc..0000000
--- a/patches/lib.rs.patch
+++ /dev/null
@@ -1,12 +0,0 @@
-diff --git a/src/lib.rs b/src/lib.rs
-index 79c942b..351352c 100644
---- a/src/lib.rs
-+++ b/src/lib.rs
-@@ -4822,6 +4822,7 @@ mod tests {
-     }
- 
-     #[test]
-+    #[ignore = "Android: failure reason unkown."]
-     fn unknown_version() {
-         let mut buf = [0; 65535];
- 
diff --git a/src/lib.rs b/src/lib.rs
index 8ad1194..0087b52 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -5800,7 +5800,6 @@
     }
 
     #[test]
-    #[ignore = "Android: failure reason unkown."]
     fn unknown_version() {
         let mut config = Config::new(0xbabababa).unwrap();
         config
@@ -6301,7 +6300,7 @@
             .load_priv_key_from_pem_file("examples/cert.key")
             .unwrap();
         config
-            .set_application_protos(b"\x06proto1\06proto2")
+            .set_application_protos(b"\x06proto1\x06proto2")
             .unwrap();
 
         let mut pipe = testing::Pipe::with_server_config(&mut config).unwrap();
@@ -8347,7 +8346,7 @@
             .load_priv_key_from_pem_file("examples/cert.key")
             .unwrap();
         config
-            .set_application_protos(b"\x06proto1\06proto2")
+            .set_application_protos(b"\x06proto1\x06proto2")
             .unwrap();
 
         let mut pipe = testing::Pipe::with_server_config(&mut config).unwrap();
@@ -8407,7 +8406,7 @@
             .load_priv_key_from_pem_file("examples/cert.key")
             .unwrap();
         config
-            .set_application_protos(b"\x06proto1\06proto2")
+            .set_application_protos(b"\x06proto1\x06proto2")
             .unwrap();
 
         let mut pipe = testing::Pipe::with_server_config(&mut config).unwrap();
@@ -8465,7 +8464,7 @@
             .load_priv_key_from_pem_file("examples/cert.key")
             .unwrap();
         config
-            .set_application_protos(b"\x06proto1\06proto2")
+            .set_application_protos(b"\x06proto1\x06proto2")
             .unwrap();
 
         let mut pipe = testing::Pipe::with_server_config(&mut config).unwrap();
@@ -9509,7 +9508,7 @@
             .load_priv_key_from_pem_file("examples/cert.key")
             .unwrap();
         config
-            .set_application_protos(b"\x06proto1\06proto2")
+            .set_application_protos(b"\x06proto1\x06proto2")
             .unwrap();
 
         let mut pipe = testing::Pipe::with_server_config(&mut config).unwrap();