Merge "Clarify `adb bugreport` failures on pre-N devices."
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/include_vndk/log/log.h b/liblog/include_vndk/log/log.h
index ab4adc4..fee18c6 100644
--- a/liblog/include_vndk/log/log.h
+++ b/liblog/include_vndk/log/log.h
@@ -1,10 +1,11 @@
 /*Special log.h file for VNDK linking modules*/
 
-#ifndef _LIBS_LOG_LOG_H
-#define _LIBS_LOG_LOG_H
+#pragma once
 
-/* Historically vendors have depended on this header being included. */
+/* Historically vendors have depended on these headers being included. */
 #include <fcntl.h>
+#include <pthread.h>
+#include <unistd.h>
 
 #include <android/log.h>
 #include <log/log_id.h>
@@ -24,5 +25,3 @@
 #ifndef LOG_TAG
 #define LOG_TAG NULL
 #endif
-
-#endif /*_LIBS_LOG_LOG_H*/
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/LogBuffer.h b/logd/LogBuffer.h
index a98c4b9..0259266 100644
--- a/logd/LogBuffer.h
+++ b/logd/LogBuffer.h
@@ -19,6 +19,7 @@
 #include <sys/types.h>
 
 #include <functional>
+#include <memory>
 
 #include <log/log.h>
 #include <log/log_read.h>
@@ -62,6 +63,7 @@
                     const char* msg, uint16_t len) = 0;
 
     virtual std::unique_ptr<FlushToState> CreateFlushToState(uint64_t start, LogMask log_mask) = 0;
+    virtual void DeleteFlushToState(std::unique_ptr<FlushToState>) {}
     virtual bool FlushTo(
             LogWriter* writer, FlushToState& state,
             const std::function<FilterResult(log_id_t log_id, pid_t pid, uint64_t sequence,
diff --git a/logd/LogReaderThread.cpp b/logd/LogReaderThread.cpp
index 4a8be01..6ac9741 100644
--- a/logd/LogReaderThread.cpp
+++ b/logd/LogReaderThread.cpp
@@ -72,6 +72,7 @@
                     [this](log_id_t log_id, pid_t pid, uint64_t sequence, log_time realtime) {
                         return FilterFirstPass(log_id, pid, sequence, realtime);
                     });
+            log_buffer_->DeleteFlushToState(std::move(first_pass_state));
         }
         bool flush_success = log_buffer_->FlushTo(
                 writer_.get(), *flush_to_state_,
@@ -105,6 +106,10 @@
         }
     }
 
+    lock.unlock();
+    log_buffer_->DeleteFlushToState(std::move(flush_to_state_));
+    lock.lock();
+
     writer_->Release();
 
     auto& log_reader_threads = reader_list_->reader_threads();
diff --git a/logd/LogReaderThread.h b/logd/LogReaderThread.h
index 20624f2..f1b673f 100644
--- a/logd/LogReaderThread.h
+++ b/logd/LogReaderThread.h
@@ -53,7 +53,7 @@
 
     bool IsWatching(log_id_t id) const { return flush_to_state_->log_mask() & (1 << id); }
     bool IsWatchingMultiple(LogMask log_mask) const {
-        return flush_to_state_->log_mask() & log_mask;
+        return flush_to_state_ && flush_to_state_->log_mask() & log_mask;
     }
 
     std::string name() const { return writer_->name(); }
diff --git a/logd/SerializedLogBuffer.cpp b/logd/SerializedLogBuffer.cpp
index fa90878..6d1576f 100644
--- a/logd/SerializedLogBuffer.cpp
+++ b/logd/SerializedLogBuffer.cpp
@@ -201,6 +201,11 @@
     return std::make_unique<SerializedFlushToState>(start, log_mask);
 }
 
+void SerializedLogBuffer::DeleteFlushToState(std::unique_ptr<FlushToState> state) {
+    auto lock = std::unique_lock{lock_};
+    state.reset();
+}
+
 bool SerializedLogBuffer::FlushTo(
         LogWriter* writer, FlushToState& abstract_state,
         const std::function<FilterResult(log_id_t log_id, pid_t pid, uint64_t sequence,
diff --git a/logd/SerializedLogBuffer.h b/logd/SerializedLogBuffer.h
index 294cfe6..9164526 100644
--- a/logd/SerializedLogBuffer.h
+++ b/logd/SerializedLogBuffer.h
@@ -42,6 +42,7 @@
     int Log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, pid_t tid, const char* msg,
             uint16_t len) override;
     std::unique_ptr<FlushToState> CreateFlushToState(uint64_t start, LogMask log_mask) override;
+    void DeleteFlushToState(std::unique_ptr<FlushToState> state) override;
     bool FlushTo(LogWriter* writer, FlushToState& state,
                  const std::function<FilterResult(log_id_t log_id, pid_t pid, uint64_t sequence,
                                                   log_time realtime)>& filter) override;
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 {