Merge "Reland: "Remove logging symlinks from system/core/include""
diff --git a/adb/client/bugreport.cpp b/adb/client/bugreport.cpp
index f2e722a..b765a30 100644
--- a/adb/client/bugreport.cpp
+++ b/adb/client/bugreport.cpp
@@ -224,7 +224,8 @@
         // 'bugreport' would generate a lot of output the user might not be prepared to handle).
         fprintf(stderr,
                 "Failed to get bugreportz version: 'bugreportz -v' returned '%s' (code %d).\n"
-                "If the device does not run Android 7.0 or above, try 'adb bugreport' instead.\n",
+                "If the device does not run Android 7.0 or above, try this instead:\n"
+                "\tadb bugreport > bugreport.txt\n",
                 bugz_output.c_str(), status);
         return status != 0 ? status : -1;
     }
diff --git a/fs_mgr/libdm/Android.bp b/fs_mgr/libdm/Android.bp
index e425284..a0bc44d 100644
--- a/fs_mgr/libdm/Android.bp
+++ b/fs_mgr/libdm/Android.bp
@@ -99,7 +99,3 @@
         "liblog",
     ],
 }
-
-vts_config {
-    name: "VtsKernelLibdmTest",
-}
diff --git a/fs_mgr/libdm/AndroidTest.xml b/fs_mgr/libdm/AndroidTest.xml
deleted file mode 100644
index b4e0c23..0000000
--- a/fs_mgr/libdm/AndroidTest.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2019 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.
--->
-<configuration description="Config for VTS VtsKernelLibdmTest">
-    <option name="config-descriptor:metadata" key="plan" value="vts-kernel" />
-    <target_preparer class="com.android.compatibility.common.tradefed.targetprep.VtsFilePusher">
-        <option name="abort-on-push-failure" value="false"/>
-        <option name="push-group" value="HostDrivenTest.push"/>
-    </target_preparer>
-    <test class="com.android.tradefed.testtype.VtsMultiDeviceTest">
-      <option name="test-module-name" value="VtsKernelLibdmTest"/>
-        <option name="binary-test-source" value="_32bit::DATA/nativetest/libdm_test/libdm_test" />
-        <option name="binary-test-source" value="_64bit::DATA/nativetest64/libdm_test/libdm_test" />
-        <option name="binary-test-type" value="gtest"/>
-        <option name="test-timeout" value="1m"/>
-        <option name="precondition-first-api-level" value="29" />
-    </test>
-</configuration>
-
diff --git a/fs_mgr/liblp/Android.bp b/fs_mgr/liblp/Android.bp
index a779a78..9517bd3 100644
--- a/fs_mgr/liblp/Android.bp
+++ b/fs_mgr/liblp/Android.bp
@@ -107,7 +107,3 @@
     name: "vts_kernel_liblp_test",
     defaults: ["liblp_test_defaults"],
 }
-
-vts_config {
-    name: "VtsKernelLiblpTest",
-}
diff --git a/fs_mgr/liblp/AndroidTest.xml b/fs_mgr/liblp/AndroidTest.xml
deleted file mode 100644
index 2eb0ad1..0000000
--- a/fs_mgr/liblp/AndroidTest.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2019 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.
--->
-<configuration description="Config for VTS VtsKernelLiblpTest">
-    <option name="config-descriptor:metadata" key="plan" value="vts-kernel" />
-    <target_preparer class="com.android.compatibility.common.tradefed.targetprep.VtsFilePusher">
-        <option name="abort-on-push-failure" value="false"/>
-        <option name="push-group" value="HostDrivenTest.push"/>
-    </target_preparer>
-    <test class="com.android.tradefed.testtype.VtsMultiDeviceTest">
-      <option name="test-module-name" value="VtsKernelLiblpTest"/>
-        <option name="binary-test-source" value="_32bit::DATA/nativetest/vts_kernel_liblp_test/vts_kernel_liblp_test" />
-        <option name="binary-test-source" value="_64bit::DATA/nativetest64/vts_kernel_liblp_test/vts_kernel_liblp_test" />
-        <option name="binary-test-type" value="gtest"/>
-        <option name="test-timeout" value="1m"/>
-        <option name="precondition-first-api-level" value="29" />
-    </test>
-</configuration>
-
diff --git a/fs_mgr/libsnapshot/Android.bp b/fs_mgr/libsnapshot/Android.bp
index db2e16c..6e81c8b 100644
--- a/fs_mgr/libsnapshot/Android.bp
+++ b/fs_mgr/libsnapshot/Android.bp
@@ -267,12 +267,6 @@
     defaults: ["libsnapshot_test_defaults"],
 }
 
-// For VTS 10
-vts_config {
-    name: "VtsLibsnapshotTest",
-    test_config: "VtsLibsnapshotTest.xml"
-}
-
 cc_binary {
     name: "snapshotctl",
     srcs: [
diff --git a/fs_mgr/libsnapshot/VtsLibsnapshotTest.xml b/fs_mgr/libsnapshot/VtsLibsnapshotTest.xml
deleted file mode 100644
index b53b51e..0000000
--- a/fs_mgr/libsnapshot/VtsLibsnapshotTest.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2020 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.
--->
-<configuration description="Config for VTS VtsLibsnapshotTest">
-    <option name="config-descriptor:metadata" key="plan" value="vts-kernel"/>
-    <target_preparer class="com.android.compatibility.common.tradefed.targetprep.VtsFilePusher">
-        <option name="abort-on-push-failure" value="false"/>
-        <option name="push-group" value="HostDrivenTest.push"/>
-    </target_preparer>
-    <test class="com.android.tradefed.testtype.VtsMultiDeviceTest">
-        <option name="test-module-name" value="VtsLibsnapshotTest"/>
-        <option name="binary-test-source" value="_32bit::DATA/nativetest/vts_libsnapshot_test/vts_libsnapshot_test"/>
-        <option name="binary-test-source" value="_64bit::DATA/nativetest64/vts_libsnapshot_test/vts_libsnapshot_test"/>
-        <option name="binary-test-type" value="gtest"/>
-        <option name="test-timeout" value="5m"/>
-    </test>
-</configuration>
diff --git a/fs_mgr/tests/Android.bp b/fs_mgr/tests/Android.bp
index f68ab87..9ed283a 100644
--- a/fs_mgr/tests/Android.bp
+++ b/fs_mgr/tests/Android.bp
@@ -17,7 +17,6 @@
     test_suites: [
         "cts",
         "device-tests",
-        "vts10",
     ],
     compile_multilib: "both",
     multilib: {
diff --git a/init/Android.bp b/init/Android.bp
index 3f2cd07..13b1876 100644
--- a/init/Android.bp
+++ b/init/Android.bp
@@ -273,7 +273,6 @@
     test_suites: [
         "cts",
         "device-tests",
-        "vts10",
     ],
 }
 
diff --git a/liblog/tests/Android.bp b/liblog/tests/Android.bp
index a17d90c..171aafd 100644
--- a/liblog/tests/Android.bp
+++ b/liblog/tests/Android.bp
@@ -98,7 +98,6 @@
     test_suites: [
         "cts",
         "device-tests",
-        "vts10",
     ],
 }
 
diff --git a/libprocessgroup/profiles/Android.bp b/libprocessgroup/profiles/Android.bp
index ccc6f62..c371ef7 100644
--- a/libprocessgroup/profiles/Android.bp
+++ b/libprocessgroup/profiles/Android.bp
@@ -104,8 +104,3 @@
         "vts",
     ],
 }
-
-vts_config {
-    name: "VtsProcessgroupValidateTest",
-    test_config: "vts_processgroup_validate_test.xml",
-}
diff --git a/libprocessgroup/profiles/vts_processgroup_validate_test.xml b/libprocessgroup/profiles/vts_processgroup_validate_test.xml
deleted file mode 100644
index 21d29cd..0000000
--- a/libprocessgroup/profiles/vts_processgroup_validate_test.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2019 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.
--->
-<configuration description="Config for VtsProcessgroupValidateTest">
-    <option name="config-descriptor:metadata" key="plan" value="vts-treble" />
-    <target_preparer class="com.android.compatibility.common.tradefed.targetprep.VtsFilePusher">
-        <option name="abort-on-push-failure" value="false"/>
-        <option name="push-group" value="HostDrivenTest.push"/>
-    </target_preparer>
-    <test class="com.android.tradefed.testtype.VtsMultiDeviceTest">
-        <option name="test-module-name" value="VtsProcessgroupValidateTest"/>
-        <option name="binary-test-working-directory" value="_32bit::/data/nativetest/" />
-        <option name="binary-test-working-directory" value="_64bit::/data/nativetest64/" />
-        <option name="binary-test-source" value="_32bit::DATA/nativetest/vts_processgroup_validate_test/vts_processgroup_validate_test" />
-        <option name="binary-test-source" value="_64bit::DATA/nativetest64/vts_processgroup_validate_test/vts_processgroup_validate_test" />
-        <option name="binary-test-type" value="gtest"/>
-        <option name="binary-test-disable-framework" value="false"/>
-        <option name="test-timeout" value="30s"/>
-    </test>
-</configuration>
diff --git a/libutils/String8.cpp b/libutils/String8.cpp
index c837891..3dc2026 100644
--- a/libutils/String8.cpp
+++ b/libutils/String8.cpp
@@ -309,8 +309,14 @@
     n = vsnprintf(nullptr, 0, fmt, tmp_args);
     va_end(tmp_args);
 
-    if (n != 0) {
+    if (n < 0) return UNKNOWN_ERROR;
+
+    if (n > 0) {
         size_t oldLength = length();
+        if ((size_t)n > SIZE_MAX - 1 ||
+            oldLength > SIZE_MAX - (size_t)n - 1) {
+            return NO_MEMORY;
+        }
         char* buf = lockBuffer(oldLength + n);
         if (buf) {
             vsnprintf(buf + oldLength, n + 1, fmt, args);
diff --git a/logd/Android.bp b/logd/Android.bp
index 335a174..a7de561 100644
--- a/logd/Android.bp
+++ b/logd/Android.bp
@@ -186,7 +186,6 @@
     test_suites: [
         "cts",
         "device-tests",
-        "vts10",
     ],
 }
 
diff --git a/logd/SerializedLogChunkTest.cpp b/logd/SerializedLogChunkTest.cpp
index 3b45125..862c3fe 100644
--- a/logd/SerializedLogChunkTest.cpp
+++ b/logd/SerializedLogChunkTest.cpp
@@ -99,13 +99,9 @@
             "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"                  // Timestamp
             "\x0C\x00last message";                             // msg_len + message
 
-    for (size_t i = 0; i < chunk_size; ++i) {
-        if (i < sizeof(expected_buffer_data)) {
-            EXPECT_EQ(static_cast<uint8_t>(expected_buffer_data[i]), chunk.data()[i])
-                    << "position: " << i;
-        } else {
-            EXPECT_EQ(0, chunk.data()[i]) << "position: " << i;
-        }
+    for (size_t i = 0; i < sizeof(expected_buffer_data); ++i) {
+        EXPECT_EQ(static_cast<uint8_t>(expected_buffer_data[i]), chunk.data()[i])
+                << "position: " << i;
     }
 }
 
diff --git a/trusty/keymaster/set_attestation_key/set_attestation_key.cpp b/trusty/keymaster/set_attestation_key/set_attestation_key.cpp
index a89a4a8..6f74833 100644
--- a/trusty/keymaster/set_attestation_key/set_attestation_key.cpp
+++ b/trusty/keymaster/set_attestation_key/set_attestation_key.cpp
@@ -292,9 +292,14 @@
                 value = xmlTextReaderConstValue(xml);
                 uint32_t cmd;
                 if (xmlStrEqual(element, BAD_CAST "PrivateKey")) {
-                    cmd = KM_SET_ATTESTATION_KEY;
-                } else if (xmlStrEqual(element, BAD_CAST "WrappedPrivateKey")) {
-                    cmd = KM_SET_WRAPPED_ATTESTATION_KEY;
+                    if (xmlStrEqual(element_format, BAD_CAST "pem")) {
+                        cmd = KM_SET_ATTESTATION_KEY;
+                    } else if (xmlStrEqual(element_format, BAD_CAST "iecs")) {
+                        cmd = KM_SET_WRAPPED_ATTESTATION_KEY;
+                    } else {
+                        printf("unsupported key format: %s\n", element_format);
+                        return -1;
+                    }
                 } else if (xmlStrEqual(element, BAD_CAST "Certificate")) {
                     cmd = KM_APPEND_ATTESTATION_CERT_CHAIN;
                 } else {