Merge tag 'android-13.0.0_r52' into int/13/fp3

Android 13.0.0 Release 52 (TQ3A.230605.012)

* tag 'android-13.0.0_r52':
  New HSUM (Headless System User Mode) build for cf phone
  Allow downstream devices to configure ro.product.board
  bt_vhci_forwarder: Drop partial packets

Change-Id: I6ecd221095584bf6ee09886a47c7a4a6935ac564
diff --git a/guest/commands/bt_vhci_forwarder/main.cpp b/guest/commands/bt_vhci_forwarder/main.cpp
index 2f1aab2..d1bb588 100644
--- a/guest/commands/bt_vhci_forwarder/main.cpp
+++ b/guest/commands/bt_vhci_forwarder/main.cpp
@@ -128,6 +128,9 @@
         send(vhci_fd, HCI_ISODATA_PKT, raw_iso.data(), raw_iso.size());
       },
       []() { LOG(INFO) << "HCI socket device disconnected"; });
+
+  bool before_first_command = true;
+
   while (true) {
     int ret = TEMP_FAILURE_RETRY(poll(fds, 2, -1));
     if (ret < 0) {
@@ -141,6 +144,7 @@
       if (c < 0) {
         PLOG(ERROR) << "vhci to virtio-console failed";
       }
+      before_first_command = false;
     }
     if (fds[1].revents & POLLHUP) {
       LOG(ERROR) << "PollHUP";
@@ -148,6 +152,16 @@
       continue;
     }
     if (fds[1].revents & (POLLIN | POLLERR)) {
+      if (before_first_command) {
+        // Drop any data left in the virtio-console from a previous reset.
+        ssize_t bytes = TEMP_FAILURE_RETRY(read(virtio_fd, buf, kBufferSize));
+        if (bytes < 0) {
+          LOG(ERROR) << "virtio_fd ready, but read failed " << strerror(errno);
+        } else {
+          LOG(INFO) << "Discarding " << bytes << " bytes from virtio_fd.";
+        }
+        continue;
+      }
       // 'virtio-console to vhci' depends on H4Packetizer because vhci expects
       // full packet, but the data from virtio-console could be partial.
       h4.OnDataReady(virtio_fd);
diff --git a/shared/BoardConfig.mk b/shared/BoardConfig.mk
index b59b39c..721e272 100644
--- a/shared/BoardConfig.mk
+++ b/shared/BoardConfig.mk
@@ -23,7 +23,9 @@
 include build/make/target/board/BoardConfigMainlineCommon.mk
 TARGET_NO_BOOTLOADER := $(__TARGET_NO_BOOTLOADER)
 
+ifndef TARGET_BOOTLOADER_BOARD_NAME
 TARGET_BOOTLOADER_BOARD_NAME := cutf
+endif
 
 BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE := $(TARGET_RO_FILE_SYSTEM_TYPE)
 
diff --git a/vsoc_x86_64/phone/OWNERS b/vsoc_x86_64/phone/OWNERS
new file mode 100644
index 0000000..e0d597b
--- /dev/null
+++ b/vsoc_x86_64/phone/OWNERS
@@ -0,0 +1 @@
+per-file *hsum*.mk = file:platform/frameworks/base:/MULTIUSER_OWNERS
diff --git a/vsoc_x86_64_only/phone/aosp_cf_hsum.mk b/vsoc_x86_64_only/phone/aosp_cf_hsum.mk
new file mode 100644
index 0000000..3abca8c
--- /dev/null
+++ b/vsoc_x86_64_only/phone/aosp_cf_hsum.mk
@@ -0,0 +1,28 @@
+#
+# Copyright (C) 2022 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.
+#
+
+# Inherit mostly from aosp_cf_x86_64_phone
+$(call inherit-product, device/google/cuttlefish/vsoc_x86_64_only/phone/aosp_cf.mk)
+PRODUCT_NAME := aosp_cf_x86_64_only_phone_hsum
+PRODUCT_MODEL := Cuttlefish x86_64 phone 64-bit only Headless System User Mode
+
+# Set Headless System User Mode
+PRODUCT_SYSTEM_DEFAULT_PROPERTIES = \
+    ro.fw.mu.headless_system_user=true
+
+# TODO(b/204071542): add package allow-list; something like
+# PRODUCT_COPY_FILES += \
+#    device/google/cuttlefish/SOME_PATH/preinstalled-packages.xml:$(TARGET_COPY_OUT_PRODUCT)/etc/sysconfig/preinstalled-packages-cf_phone.xml