Merge "DynamicsProcessing: Add pre and post equalizer test" into main
diff --git a/bluetooth/aidl/Android.bp b/bluetooth/aidl/Android.bp
index 4ee2f49..0daecf7 100644
--- a/bluetooth/aidl/Android.bp
+++ b/bluetooth/aidl/Android.bp
@@ -16,6 +16,13 @@
     srcs: ["android/hardware/bluetooth/*.aidl"],
     stability: "vintf",
     backend: {
+        cpp: {
+            // FIXME should this be disabled?
+            // prefer NDK backend which can be used anywhere
+            // If you disable this, you also need to delete the C++
+            // translate code.
+            enabled: true,
+        },
         rust: {
             enabled: true,
         },
@@ -37,4 +44,5 @@
         },
     ],
     frozen: true,
+
 }
diff --git a/bluetooth/aidl/default/Android.bp b/bluetooth/aidl/default/Android.bp
index d3f6364..46a6983 100644
--- a/bluetooth/aidl/default/Android.bp
+++ b/bluetooth/aidl/default/Android.bp
@@ -2,61 +2,58 @@
     default_applicable_licenses: ["Android-Apache-2.0"],
 }
 
-cc_library_static {
-    name: "libbluetoothhcihalimpl",
-    vendor_available: true,
-    host_supported: true,
-    srcs: [
-        "BluetoothHci.cpp",
-        "net_bluetooth_mgmt.cpp",
-    ],
+cc_defaults {
+    name: "android.hardware.bluetooth-service-build-defaults",
     cflags: [
         "-Wall",
         "-Wextra",
     ],
-    header_libs: [
-        "libbluetooth_offload_hal_headers",
+    shared_libs: [
+        "android.hardware.bluetooth-V1-ndk",
+        "libbase",
+        "libbinder_ndk",
+        "libcutils",
+        "libhidlbase",
+        "liblog",
+        "libutils",
     ],
     static_libs: [
         "android.hardware.bluetooth.async",
         "android.hardware.bluetooth.hci",
-    ],
-    shared_libs: [
-        "libbase",
-        "libcutils",
-        "liblog",
-        "libutils",
+        "libbluetooth_offload_hal",
     ],
 }
 
-rust_binary {
+cc_library_static {
+    name: "libbluetoothhcihalimpl",
+    vendor_available: true,
+    defaults: ["android.hardware.bluetooth-service-build-defaults"],
+    srcs: [
+        "BluetoothHci.cpp",
+        "net_bluetooth_mgmt.cpp",
+    ],
+}
+
+cc_binary {
     name: "android.hardware.bluetooth-service.default",
-    crate_name: "bluetooth_hci_hal_server",
     relative_install_path: "hw",
     init_rc: ["bluetooth-service-default.rc"],
     vintf_fragments: [":manifest_android.hardware.bluetooth-service.default.xml"],
     vendor: true,
-    prefer_rlib: true,
-    srcs: ["main.rs"],
-    rustlibs: [
-        "android.hardware.bluetooth-V1-rust",
-        "libbluetooth_offload_hal",
-        "libbluetooth_offload_leaudio_hci",
-        "libbinder_rs",
-        "liblogger",
-        "liblog_rust",
-    ],
-    static_libs: [
-        "android.hardware.bluetooth.async",
-        "android.hardware.bluetooth.hci",
-        "libbluetoothhcihalimpl",
+    defaults: ["android.hardware.bluetooth-service-build-defaults"],
+    srcs: [
+        "service.cpp",
     ],
     shared_libs: [
+        "android.hardware.bluetooth-V1-ndk",
         "libbase",
-        "libc++",
-        "libcutils",
-        "liblog",
+        "libbinder_ndk",
+        "libhidlbase",
         "libutils",
+        "liblog",
+    ],
+    static_libs: [
+        "libbluetoothhcihalimpl",
     ],
 }
 
diff --git a/bluetooth/aidl/default/BluetoothHci.cpp b/bluetooth/aidl/default/BluetoothHci.cpp
index bcdb67e..5ac3afe 100644
--- a/bluetooth/aidl/default/BluetoothHci.cpp
+++ b/bluetooth/aidl/default/BluetoothHci.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright 2024 The Android Open Source Project
+ * Copyright 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.
@@ -16,20 +16,18 @@
 
 #define LOG_TAG "android.hardware.bluetooth.service.default"
 
+#include "BluetoothHci.h"
+
 #include <cutils/properties.h>
 #include <fcntl.h>
-#include <hal/ffi.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <poll.h>
 #include <string.h>
+#include <sys/uio.h>
 #include <termios.h>
 
-#include <future>
-#include <memory>
-#include <vector>
-
-#include "async_fd_watcher.h"
-#include "h4_protocol.h"
 #include "log/log.h"
-#include "net_bluetooth_mgmt.h"
 
 namespace {
 int SetTerminalRaw(int fd) {
@@ -46,6 +44,7 @@
 
 using namespace ::android::hardware::bluetooth::hci;
 using namespace ::android::hardware::bluetooth::async;
+using aidl::android::hardware::bluetooth::hal::Status;
 
 namespace aidl::android::hardware::bluetooth::impl {
 
@@ -62,298 +61,234 @@
   return str.compare(0, prefix.length(), prefix) == 0;
 }
 
-class Hal {
- public:
-  Hal(const std::string& dev_path = "/dev/hvc5") {
-    char property_bytes[PROPERTY_VALUE_MAX];
-    property_get("vendor.ser.bt-uart", property_bytes, dev_path.c_str());
-    mDevPath = std::string(property_bytes);
-  }
+BluetoothHci::BluetoothHci(const std::string& dev_path) {
+  char property_bytes[PROPERTY_VALUE_MAX];
+  property_get("vendor.ser.bt-uart", property_bytes, dev_path.c_str());
+  mDevPath = std::string(property_bytes);
+}
 
-  static void Initialize(void* instance,
-                         const struct hal_callbacks* callbacks) {
-    static_cast<Hal*>(instance)->Initialize(callbacks);
-  }
-
-  static void Close(void* instance) { static_cast<Hal*>(instance)->Close(); }
-
-  static void SendCommand(void* instance, const uint8_t* data, size_t len) {
-    static_cast<Hal*>(instance)->SendCommand(
-        std::vector<uint8_t>(data, data + len));
-  }
-
-  static void SendAcl(void* instance, const uint8_t* data, size_t len) {
-    static_cast<Hal*>(instance)->SendAcl(
-        std::vector<uint8_t>(data, data + len));
-  }
-
-  static void SendSco(void* instance, const uint8_t* data, size_t len) {
-    static_cast<Hal*>(instance)->SendSco(
-        std::vector<uint8_t>(data, data + len));
-  }
-
-  static void SendIso(void* instance, const uint8_t* data, size_t len) {
-    static_cast<Hal*>(instance)->SendIso(
-        std::vector<uint8_t>(data, data + len));
-  }
-
- private:
-  int getFdFromDevPath() {
-    int fd = open(mDevPath.c_str(), O_RDWR);
-    if (fd < 0) {
-      ALOGE("Could not connect to bt: %s (%s)", mDevPath.c_str(),
-            strerror(errno));
-      return fd;
-    }
-    if (int ret = SetTerminalRaw(fd) < 0) {
-      ALOGI("Could not make %s a raw terminal %d(%s)", mDevPath.c_str(), ret,
-            strerror(errno));
-    }
+int BluetoothHci::getFdFromDevPath() {
+  int fd = open(mDevPath.c_str(), O_RDWR);
+  if (fd < 0) {
+    ALOGE("Could not connect to bt: %s (%s)", mDevPath.c_str(),
+          strerror(errno));
     return fd;
   }
+  if (int ret = SetTerminalRaw(fd) < 0) {
+    ALOGI("Could not make %s a raw terminal %d(%s)", mDevPath.c_str(), ret,
+          strerror(errno));
+  }
+  return fd;
+}
 
-  void reset() {
-    // Send a reset command and wait until the command complete comes back.
+void BluetoothHci::reset() {
+  // Send a reset command and wait until the command complete comes back.
 
-    std::vector<uint8_t> reset = {0x03, 0x0c, 0x00};
+  std::vector<uint8_t> reset = {0x03, 0x0c, 0x00};
 
-    auto resetPromise = std::make_shared<std::promise<void>>();
-    auto resetFuture = resetPromise->get_future();
+  auto resetPromise = std::make_shared<std::promise<void>>();
+  auto resetFuture = resetPromise->get_future();
 
-    mH4 = std::make_shared<H4Protocol>(
-        mFd,
-        [](const std::vector<uint8_t>& raw_command) {
-          ALOGI("Discarding %d bytes with command type",
-                static_cast<int>(raw_command.size()));
-        },
-        [](const std::vector<uint8_t>& raw_acl) {
-          ALOGI("Discarding %d bytes with acl type",
-                static_cast<int>(raw_acl.size()));
-        },
-        [](const std::vector<uint8_t>& raw_sco) {
-          ALOGI("Discarding %d bytes with sco type",
-                static_cast<int>(raw_sco.size()));
-        },
-        [resetPromise](const std::vector<uint8_t>& raw_event) {
-          std::vector<uint8_t> reset_complete = {0x0e, 0x04, 0x01,
-                                                 0x03, 0x0c, 0x00};
-          bool valid = raw_event.size() == 6 &&
-                       raw_event[0] == reset_complete[0] &&
-                       raw_event[1] == reset_complete[1] &&
-                       // Don't compare the number of packets field.
-                       raw_event[3] == reset_complete[3] &&
-                       raw_event[4] == reset_complete[4] &&
-                       raw_event[5] == reset_complete[5];
-          if (valid) {
-            resetPromise->set_value();
-          } else {
-            ALOGI("Discarding %d bytes with event type",
-                  static_cast<int>(raw_event.size()));
-          }
-        },
-        [](const std::vector<uint8_t>& raw_iso) {
-          ALOGI("Discarding %d bytes with iso type",
-                static_cast<int>(raw_iso.size()));
-        },
-        [this]() {
-          ALOGI("HCI socket device disconnected while waiting for reset");
-          mFdWatcher.StopWatchingFileDescriptors();
-        });
-    mFdWatcher.WatchFdForNonBlockingReads(mFd,
-                                          [this](int) { mH4->OnDataReady(); });
+  mH4 = std::make_shared<H4Protocol>(
+      mFd,
+      [](const std::vector<uint8_t>& raw_command) {
+        ALOGI("Discarding %d bytes with command type",
+              static_cast<int>(raw_command.size()));
+      },
+      [](const std::vector<uint8_t>& raw_acl) {
+        ALOGI("Discarding %d bytes with acl type",
+              static_cast<int>(raw_acl.size()));
+      },
+      [](const std::vector<uint8_t>& raw_sco) {
+        ALOGI("Discarding %d bytes with sco type",
+              static_cast<int>(raw_sco.size()));
+      },
+      [resetPromise](const std::vector<uint8_t>& raw_event) {
+        std::vector<uint8_t> reset_complete = {0x0e, 0x04, 0x01,
+                                               0x03, 0x0c, 0x00};
+        bool valid = raw_event.size() == 6 &&
+                     raw_event[0] == reset_complete[0] &&
+                     raw_event[1] == reset_complete[1] &&
+                     // Don't compare the number of packets field.
+                     raw_event[3] == reset_complete[3] &&
+                     raw_event[4] == reset_complete[4] &&
+                     raw_event[5] == reset_complete[5];
+        if (valid) {
+          resetPromise->set_value();
+        } else {
+          ALOGI("Discarding %d bytes with event type",
+                static_cast<int>(raw_event.size()));
+        }
+      },
+      [](const std::vector<uint8_t>& raw_iso) {
+        ALOGI("Discarding %d bytes with iso type",
+              static_cast<int>(raw_iso.size()));
+      },
+      [this]() {
+        ALOGI("HCI socket device disconnected while waiting for reset");
+        mFdWatcher.StopWatchingFileDescriptors();
+      });
+  mFdWatcher.WatchFdForNonBlockingReads(mFd,
+                                        [this](int) { mH4->OnDataReady(); });
 
-    if (!send(PacketType::COMMAND, reset)) {
-      ALOGE("Error sending reset command");
-    }
-    auto status = resetFuture.wait_for(std::chrono::seconds(1));
-    mFdWatcher.StopWatchingFileDescriptors();
-    if (status == std::future_status::ready) {
-      ALOGI("HCI Reset successful");
-    } else {
-      ALOGE("HCI Reset Response not received in one second");
-    }
-
-    resetPromise.reset();
+  send(PacketType::COMMAND, reset);
+  auto status = resetFuture.wait_for(std::chrono::seconds(1));
+  mFdWatcher.StopWatchingFileDescriptors();
+  if (status == std::future_status::ready) {
+    ALOGI("HCI Reset successful");
+  } else {
+    ALOGE("HCI Reset Response not received in one second");
   }
 
-  void Initialize(const struct hal_callbacks* callbacks) {
-    ALOGI(__func__);
+  resetPromise.reset();
+}
 
-    HalState old_state = HalState::READY;
-    {
-      std::lock_guard<std::mutex> guard(mStateMutex);
-      if (mState != HalState::READY) {
-        old_state = mState;
-      } else {
-        mState = HalState::INITIALIZING;
-      }
-    }
+void BluetoothHci::initialize(
+    const std::shared_ptr<hal::IBluetoothHciCallbacks>& cb) {
+  ALOGI(__func__);
 
-    if (old_state != HalState::READY) {
-      ALOGE("initialize: Unexpected State %d", static_cast<int>(old_state));
-      Close();
-      callbacks->initialization_complete(callbacks->handle,
-                                         STATUS_ALREADY_INITIALIZED);
-      return;
-    }
-
-    mCallbacks = std::make_unique<struct hal_callbacks>(*callbacks);
-    management_.reset(new NetBluetoothMgmt);
-    mFd = management_->openHci();
-    if (mFd < 0) {
-      management_.reset();
-
-      ALOGI("Unable to open Linux interface, trying default path.");
-      mFd = getFdFromDevPath();
-      if (mFd < 0) {
-        mState = HalState::READY;
-        mCallbacks->initialization_complete(mCallbacks->handle,
-                                            STATUS_UNABLE_TO_OPEN_INTERFACE);
-        return;
-      }
-    }
-
-    // TODO: HCI Reset on emulators since the bluetooth controller
-    // cannot be powered on/off during the HAL setup; and the stack
-    // might received spurious packets/events during boottime.
-    // Proper solution would be to use bt-virtio or vsock to better
-    // control the link to rootcanal and the controller lifetime.
-    const std::string kBoardProperty = "ro.product.board";
-    const std::string kCuttlefishBoard = "cutf";
-    auto board_name = GetSystemProperty(kBoardProperty);
-    if (board_name.has_value() &&
-        (starts_with(board_name.value(), "cutf") ||
-         starts_with(board_name.value(), "goldfish"))) {
-      reset();
-    }
-
-    mH4 = std::make_shared<H4Protocol>(
-        mFd,
-        [](const std::vector<uint8_t>& /* raw_command */) {
-          LOG_ALWAYS_FATAL("Unexpected command!");
-        },
-        [this](const std::vector<uint8_t>& raw_acl) {
-          mCallbacks->acl_received(mCallbacks->handle, raw_acl.data(),
-                                   raw_acl.size());
-        },
-        [this](const std::vector<uint8_t>& raw_sco) {
-          mCallbacks->sco_received(mCallbacks->handle, raw_sco.data(),
-                                   raw_sco.size());
-        },
-        [this](const std::vector<uint8_t>& raw_event) {
-          mCallbacks->event_received(mCallbacks->handle, raw_event.data(),
-                                     raw_event.size());
-        },
-        [this](const std::vector<uint8_t>& raw_iso) {
-          mCallbacks->iso_received(mCallbacks->handle, raw_iso.data(),
-                                   raw_iso.size());
-        },
-        [this]() {
-          ALOGI("HCI socket device disconnected");
-          mFdWatcher.StopWatchingFileDescriptors();
-        });
-    mFdWatcher.WatchFdForNonBlockingReads(mFd,
-                                          [this](int) { mH4->OnDataReady(); });
-
-    {
-      std::lock_guard<std::mutex> guard(mStateMutex);
-      mState = HalState::ONE_CLIENT;
-    }
-
-    ALOGI("initialization complete");
-    mCallbacks->initialization_complete(mCallbacks->handle, STATUS_SUCCESS);
+  if (cb == nullptr) {
+    ALOGE("cb == nullptr! -> Unable to call initializationComplete(ERR)");
+    abort();
   }
 
-  void Close() {
-    ALOGI(__func__);
-    {
-      std::lock_guard<std::mutex> guard(mStateMutex);
-      if (mState != HalState::ONE_CLIENT) {
-        LOG_ALWAYS_FATAL_IF(mState == HalState::INITIALIZING,
-                            "mState is INITIALIZING");
-        ALOGI("Already closed");
-        return;
-      }
-      mCallbacks.reset();
-      mState = HalState::CLOSING;
-    }
-
-    mFdWatcher.StopWatchingFileDescriptors();
-
-    if (management_) {
-      management_->closeHci();
-    } else {
-      ::close(mFd);
-    }
-
-    {
-      std::lock_guard<std::mutex> guard(mStateMutex);
-      mState = HalState::READY;
-      mH4 = nullptr;
-    }
-  }
-
-  void SendCommand(const std::vector<uint8_t>& data) {
-    send(PacketType::COMMAND, data);
-  }
-  void SendAcl(const std::vector<uint8_t>& data) {
-    send(PacketType::ACL_DATA, data);
-  }
-  void SendSco(const std::vector<uint8_t>& data) {
-    send(PacketType::SCO_DATA, data);
-  }
-  void SendIso(const std::vector<uint8_t>& data) {
-    send(PacketType::ISO_DATA, data);
-  }
-
-  bool send(PacketType type, const std::vector<uint8_t>& v) {
-    if (v.empty()) {
-      ALOGE("Packet is empty, no data was found to be sent");
-      return false;
-    }
-
+  HalState old_state = HalState::READY;
+  {
     std::lock_guard<std::mutex> guard(mStateMutex);
-    if (mH4 == nullptr) {
-      ALOGE("Illegal State");
-      return false;
+    if (mState != HalState::READY) {
+      old_state = mState;
+    } else {
+      mState = HalState::INITIALIZING;
     }
-
-    mH4->Send(type, v);
-    return true;
   }
 
-  std::unique_ptr<struct hal_callbacks> mCallbacks;
-  std::string mDevPath;
-  int mFd{-1};
-  ::android::hardware::bluetooth::async::AsyncFdWatcher mFdWatcher;
-  std::shared_ptr<::android::hardware::bluetooth::hci::H4Protocol> mH4;
-  std::unique_ptr<NetBluetoothMgmt> management_{};
+  if (old_state != HalState::READY) {
+    ALOGE("initialize: Unexpected State %d", static_cast<int>(old_state));
+    close();
+    cb->initializationComplete(Status::ALREADY_INITIALIZED);
+  }
 
-  // Don't close twice or open before close is complete
-  std::mutex mStateMutex;
-  enum class HalState {
-    READY,
-    INITIALIZING,
-    ONE_CLIENT,
-    CLOSING,
-  } mState{HalState::READY};
-};
+  mCb = cb;
+  management_.reset(new NetBluetoothMgmt);
+  mFd = management_->openHci();
+  if (mFd < 0) {
+    management_.reset();
+
+    ALOGI("Unable to open Linux interface, trying default path.");
+    mFd = getFdFromDevPath();
+    if (mFd < 0) {
+      mState = HalState::READY;
+      cb->initializationComplete(Status::UNABLE_TO_OPEN_INTERFACE);
+    }
+  }
+
+  // TODO: HCI Reset on emulators since the bluetooth controller
+  // cannot be powered on/off during the HAL setup; and the stack
+  // might received spurious packets/events during boottime.
+  // Proper solution would be to use bt-virtio or vsock to better
+  // control the link to rootcanal and the controller lifetime.
+  const std::string kBoardProperty = "ro.product.board";
+  const std::string kCuttlefishBoard = "cutf";
+  auto board_name = GetSystemProperty(kBoardProperty);
+  if (board_name.has_value() && (
+        starts_with(board_name.value(), "cutf") ||
+        starts_with(board_name.value(), "goldfish"))) {
+    reset();
+  }
+
+  mH4 = std::make_shared<H4Protocol>(
+      mFd,
+      [](const std::vector<uint8_t>& /* raw_command */) {
+        LOG_ALWAYS_FATAL("Unexpected command!");
+      },
+      [this](const std::vector<uint8_t>& raw_acl) {
+        mCb->aclDataReceived(raw_acl);
+      },
+      [this](const std::vector<uint8_t>& raw_sco) {
+        mCb->scoDataReceived(raw_sco);
+      },
+      [this](const std::vector<uint8_t>& raw_event) {
+        mCb->hciEventReceived(raw_event);
+      },
+      [this](const std::vector<uint8_t>& raw_iso) {
+        mCb->isoDataReceived(raw_iso);
+      },
+      [this]() {
+        ALOGI("HCI socket device disconnected");
+        mFdWatcher.StopWatchingFileDescriptors();
+      });
+  mFdWatcher.WatchFdForNonBlockingReads(mFd,
+                                        [this](int) { mH4->OnDataReady(); });
+
+  {
+    std::lock_guard<std::mutex> guard(mStateMutex);
+    mState = HalState::ONE_CLIENT;
+  }
+  ALOGI("initialization complete");
+  mCb->initializationComplete(Status::SUCCESS);
+}
+
+void BluetoothHci::close() {
+  ALOGI(__func__);
+  {
+    std::lock_guard<std::mutex> guard(mStateMutex);
+    if (mState != HalState::ONE_CLIENT) {
+      LOG_ALWAYS_FATAL_IF(mState == HalState::INITIALIZING,
+                          "mState is INITIALIZING");
+      ALOGI("Already closed");
+    }
+    mState = HalState::CLOSING;
+  }
+
+  mFdWatcher.StopWatchingFileDescriptors();
+
+  if (management_) {
+    management_->closeHci();
+  } else {
+    ::close(mFd);
+  }
+
+  {
+    std::lock_guard<std::mutex> guard(mStateMutex);
+    mState = HalState::READY;
+    mH4 = nullptr;
+  }
+}
+
+void BluetoothHci::clientDied() {
+  ALOGI(__func__);
+  close();
+}
+
+void BluetoothHci::sendHciCommand(const std::vector<uint8_t>& packet) {
+  return send(PacketType::COMMAND, packet);
+}
+
+void BluetoothHci::sendAclData(const std::vector<uint8_t>& packet) {
+  return send(PacketType::ACL_DATA, packet);
+}
+
+void BluetoothHci::sendScoData(const std::vector<uint8_t>& packet) {
+  return send(PacketType::SCO_DATA, packet);
+}
+
+void BluetoothHci::sendIsoData(const std::vector<uint8_t>& packet) {
+  return send(PacketType::ISO_DATA, packet);
+}
+
+void BluetoothHci::send(PacketType type, const std::vector<uint8_t>& v) {
+  if (v.empty()) {
+    ALOGE("Packet is empty, no data was found to be sent");
+    abort();
+  }
+
+  std::lock_guard<std::mutex> guard(mStateMutex);
+  if (mH4 == nullptr) {
+    ALOGE("Illegal State");
+    abort();
+  }
+
+  mH4->Send(type, v);
+}
 
 }  // namespace aidl::android::hardware::bluetooth::impl
-
-extern "C" {
-
-using namespace aidl::android::hardware::bluetooth::impl;
-
-struct hal_interface hal_new() {
-  return (struct hal_interface){
-      .handle = new Hal(),
-      .initialize = &Hal::Initialize,
-      .close = &Hal::Close,
-      .send_command = &Hal::SendCommand,
-      .send_acl = &Hal::SendAcl,
-      .send_sco = &Hal::SendSco,
-      .send_iso = &Hal::SendIso,
-  };
-}
-}
diff --git a/bluetooth/aidl/default/BluetoothHci.h b/bluetooth/aidl/default/BluetoothHci.h
new file mode 100644
index 0000000..5c31468
--- /dev/null
+++ b/bluetooth/aidl/default/BluetoothHci.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright 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.
+ */
+
+#pragma once
+
+#include <hal/ffi.h>
+
+#include <future>
+#include <string>
+
+#include "async_fd_watcher.h"
+#include "h4_protocol.h"
+#include "net_bluetooth_mgmt.h"
+
+namespace aidl::android::hardware::bluetooth::impl {
+
+// This Bluetooth HAL implementation connects with a serial port at dev_path_.
+class BluetoothHci : public hal::IBluetoothHci {
+ public:
+  BluetoothHci(const std::string& dev_path = "/dev/hvc5");
+
+  void initialize(
+      const std::shared_ptr<hal::IBluetoothHciCallbacks>& cb) override;
+
+  void sendHciCommand(const std::vector<uint8_t>& packet) override;
+
+  void sendAclData(const std::vector<uint8_t>& packet) override;
+
+  void sendScoData(const std::vector<uint8_t>& packet) override;
+
+  void sendIsoData(const std::vector<uint8_t>& packet) override;
+
+  void close() override;
+
+  void clientDied() override;
+
+  static void OnPacketReady();
+
+  static BluetoothHci* get();
+
+ private:
+  int mFd{-1};
+  std::shared_ptr<hal::IBluetoothHciCallbacks> mCb = nullptr;
+
+  std::shared_ptr<::android::hardware::bluetooth::hci::H4Protocol> mH4;
+
+  std::string mDevPath;
+
+  ::android::hardware::bluetooth::async::AsyncFdWatcher mFdWatcher;
+
+  int getFdFromDevPath();
+  void send(::android::hardware::bluetooth::hci::PacketType type,
+            const std::vector<uint8_t>& packet);
+  std::unique_ptr<NetBluetoothMgmt> management_{};
+
+  // Send a reset command and discard all packets until a reset is received.
+  void reset();
+
+  // Don't close twice or open before close is complete
+  std::mutex mStateMutex;
+  enum class HalState {
+    READY,
+    INITIALIZING,
+    ONE_CLIENT,
+    CLOSING,
+  } mState{HalState::READY};
+};
+
+}  // namespace aidl::android::hardware::bluetooth::impl
diff --git a/bluetooth/aidl/default/main.rs b/bluetooth/aidl/default/main.rs
deleted file mode 100644
index b30162a..0000000
--- a/bluetooth/aidl/default/main.rs
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright 2024, 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.
-
-use android_hardware_bluetooth::aidl::android::hardware::bluetooth::IBluetoothHci::{
-    self,
-    IBluetoothHci as _
-};
-use android_hardware_bluetooth::binder;
-use bluetooth_offload_hal::{ HciHalProxy, CInterface };
-use bluetooth_offload_leaudio_hci::LeAudioModuleBuilder;
-use log;
-use std::panic;
-
-fn new_hal() -> CInterface {
-    extern "C" { fn hal_new() -> CInterface; }
-    unsafe { hal_new() }
-}
-
-fn main() {
-    logger::init(
-        logger::Config::default()
-            .with_max_level(log::LevelFilter::Debug)
-            .with_tag_on_device("android.hardware.bluetooth"),
-    );
-
-    panic::set_hook(Box::new(|panic_info| {
-        log::error!("{}", panic_info);
-    }));
-
-    log::info!("Bluetooth HAL starting up");
-
-    binder::ProcessState::set_thread_pool_max_thread_count(0);
-    binder::ProcessState::start_thread_pool();
-
-    binder::add_service(
-        &format!("{}/default", IBluetoothHci::BpBluetoothHci::get_descriptor()),
-        IBluetoothHci::BnBluetoothHci::new_binder(
-            HciHalProxy::new(
-                vec![ Box::new(LeAudioModuleBuilder {}) ],
-                new_hal()
-            ),
-            binder::BinderFeatures::default(),
-        ).as_binder()
-    ).expect("Failed to register service");
-
-    binder::ProcessState::join_thread_pool();
-}
diff --git a/bluetooth/aidl/default/service.cpp b/bluetooth/aidl/default/service.cpp
new file mode 100644
index 0000000..9e1a22c
--- /dev/null
+++ b/bluetooth/aidl/default/service.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright 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.
+ */
+
+#define LOG_TAG "aidl.android.hardware.bluetooth.service.default"
+
+#include <android/binder_manager.h>
+#include <android/binder_process.h>
+#include <hidl/HidlSupport.h>
+#include <hidl/HidlTransportSupport.h>
+
+#include "BluetoothHci.h"
+
+using ::aidl::android::hardware::bluetooth::hal::IBluetoothHci_addService;
+using ::aidl::android::hardware::bluetooth::impl::BluetoothHci;
+using ::android::hardware::configureRpcThreadpool;
+using ::android::hardware::joinRpcThreadpool;
+
+int main(int /* argc */, char** /* argv */) {
+  ALOGI("Bluetooth HAL starting");
+  if (!ABinderProcess_setThreadPoolMaxThreadCount(0)) {
+    ALOGI("failed to set thread pool max thread count");
+    return 1;
+  }
+
+  IBluetoothHci_addService(new BluetoothHci());
+  ABinderProcess_joinThreadPool();
+  return 0;
+}
diff --git a/bluetooth/audio/aidl/default/A2dpOffloadCodecSbc.cpp b/bluetooth/audio/aidl/default/A2dpOffloadCodecSbc.cpp
index 6b9046c..10c347b 100644
--- a/bluetooth/audio/aidl/default/A2dpOffloadCodecSbc.cpp
+++ b/bluetooth/audio/aidl/default/A2dpOffloadCodecSbc.cpp
@@ -102,7 +102,7 @@
   kBlockLength16
 };
 
-enum { kSubbands8 = kSubbands.first, kSubbands4 };
+enum { kSubbands4 = kSubbands.first, kSubbands8 };
 
 enum {
   kAllocationMethodSnr = kAllocationMethod.first,
@@ -486,7 +486,7 @@
   }
 
   min_bitpool = std::max(min_bitpool, uint8_t(lcaps.get(kMinimumBitpool)));
-  max_bitpool = std::max(max_bitpool, uint8_t(lcaps.get(kMaximumBitpool)));
+  max_bitpool = std::min(max_bitpool, uint8_t(lcaps.get(kMaximumBitpool)));
 
   if (hint) {
     min_bitpool =
diff --git a/bluetooth/socket/aidl/android/hardware/bluetooth/socket/LeCocCapabilities.aidl b/bluetooth/socket/aidl/android/hardware/bluetooth/socket/LeCocCapabilities.aidl
index 003da11..9cd63d6 100644
--- a/bluetooth/socket/aidl/android/hardware/bluetooth/socket/LeCocCapabilities.aidl
+++ b/bluetooth/socket/aidl/android/hardware/bluetooth/socket/LeCocCapabilities.aidl
@@ -37,8 +37,9 @@
     /**
      * The value used by the Host stack for the local Maximum Packet Size shall be the value
      * LE_ACL_Data_Packet_Length returned by the controller in response to the command HCI LE Read
-     * Buffer Size. Then, the MPS size must be in range 1 to 255. We do not make the MPS
-     * configurable in HAL because using the maximum value does not require a large amount of
-     * memory.
+     * Buffer Size if Total_Num_LE_ACL_Data_Packets is not zero. The MPS shall be the value
+     * ACL_Data_Packet_Length returned in response to the command HCI Read Buffer Size if
+     * Total_Num_LE_ACL_Data_Packets is zero. We do not make the MPS configurable in HAL because
+     * using the maximum value does not require a large amount of memory.
      */
 }
diff --git a/configstore/OWNERS b/configstore/OWNERS
index 70ad434..74789b5 100644
--- a/configstore/OWNERS
+++ b/configstore/OWNERS
@@ -1,3 +1,2 @@
 # Bug component: 24939
 
-lpy@google.com
diff --git a/confirmationui/1.0/default/OWNERS b/confirmationui/1.0/default/OWNERS
index 17aed51..d8b8840 100644
--- a/confirmationui/1.0/default/OWNERS
+++ b/confirmationui/1.0/default/OWNERS
@@ -1,3 +1,2 @@
 # Bug component: 1124672
-jdanis@google.com
 swillden@google.com
diff --git a/confirmationui/1.0/vts/OWNERS b/confirmationui/1.0/vts/OWNERS
index aa07242..b0ee996 100644
--- a/confirmationui/1.0/vts/OWNERS
+++ b/confirmationui/1.0/vts/OWNERS
@@ -1,4 +1,3 @@
 # Bug component: 1124672
-jdanis@google.com
 swillden@google.com
 yim@google.com
diff --git a/confirmationui/support/OWNERS b/confirmationui/support/OWNERS
index 17aed51..d8b8840 100644
--- a/confirmationui/support/OWNERS
+++ b/confirmationui/support/OWNERS
@@ -1,3 +1,2 @@
 # Bug component: 1124672
-jdanis@google.com
 swillden@google.com
diff --git a/gatekeeper/1.0/default/OWNERS b/gatekeeper/1.0/default/OWNERS
index c97fba6..d552a9a 100644
--- a/gatekeeper/1.0/default/OWNERS
+++ b/gatekeeper/1.0/default/OWNERS
@@ -1,3 +1,2 @@
 # Bug component: 1124862
-jdanis@google.com
 swillden@google.com
diff --git a/gatekeeper/1.0/software/OWNERS b/gatekeeper/1.0/software/OWNERS
index c97fba6..d552a9a 100644
--- a/gatekeeper/1.0/software/OWNERS
+++ b/gatekeeper/1.0/software/OWNERS
@@ -1,3 +1,2 @@
 # Bug component: 1124862
-jdanis@google.com
 swillden@google.com
diff --git a/gnss/OWNERS b/gnss/OWNERS
index 57982e7..2c54f9f 100644
--- a/gnss/OWNERS
+++ b/gnss/OWNERS
@@ -2,7 +2,6 @@
 
 gomo@google.com
 smalkos@google.com
-trong@google.com
 wyattriley@google.com
 yim@google.com
 yuhany@google.com
diff --git a/graphics/OWNERS b/graphics/OWNERS
index 4317831..9ba1ee0 100644
--- a/graphics/OWNERS
+++ b/graphics/OWNERS
@@ -5,5 +5,4 @@
 alecmouri@google.com
 chrisforbes@google.com
 jreck@google.com
-lpy@google.com
 sumir@google.com
diff --git a/ir/OWNERS b/ir/OWNERS
index 04de9ef..376fe0a 100644
--- a/ir/OWNERS
+++ b/ir/OWNERS
@@ -1,2 +1,2 @@
 # Bug component: 163905
-connoro@google.com
+devinmoore@google.com
\ No newline at end of file
diff --git a/nfc/1.0/default/OWNERS b/nfc/1.0/default/OWNERS
index 5febd1d..e681870 100644
--- a/nfc/1.0/default/OWNERS
+++ b/nfc/1.0/default/OWNERS
@@ -1,2 +1 @@
 rmojumder@google.com
-zachoverflow@google.com
diff --git a/nfc/1.2/vts/OWNERS b/nfc/1.2/vts/OWNERS
index 21d4df1..eeeadd1 100644
--- a/nfc/1.2/vts/OWNERS
+++ b/nfc/1.2/vts/OWNERS
@@ -1,3 +1,2 @@
-zachoverflow@google.com
 jackcwyu@google.com
 georgekgchang@google.com
diff --git a/nfc/aidl/vts/functional/VtsNfcBehaviorChangesTest.cpp b/nfc/aidl/vts/functional/VtsNfcBehaviorChangesTest.cpp
index 9c44c3a..d3fcbb3 100644
--- a/nfc/aidl/vts/functional/VtsNfcBehaviorChangesTest.cpp
+++ b/nfc/aidl/vts/functional/VtsNfcBehaviorChangesTest.cpp
@@ -153,8 +153,7 @@
                     SyncEventGuard guard(sNfaVsCommand);
                     sNfaVsCommand.notifyOne();
                 } break;
-                case NCI_ANDROID_SET_PASSIVE_OBSERVER_TECH:
-                case NCI_ANDROID_PASSIVE_OBSERVE: {
+                case NCI_ANDROID_SET_PASSIVE_OBSERVER_TECH: {
                     if (param_len == 5) {
                         if ((p_param[0] & NCI_MT_MASK) == (NCI_MT_RSP << NCI_MT_SHIFT)) {
                             sVSCmdStatus = p_param[4];
@@ -190,36 +189,6 @@
 }
 
 /*
- * Enable passive observe mode.
- */
-tNFA_STATUS static nfaObserveModeEnable(bool enable) {
-    tNFA_STATUS status = NFA_STATUS_FAILED;
-
-    status = NFA_StopRfDiscovery();
-    if (status == NFA_STATUS_OK) {
-        if (!sNfaEnableDisablePollingEvent.wait(1000)) {
-            LOG(WARNING) << "Timeout waiting to disable NFC RF discovery";
-            return NFA_STATUS_TIMEOUT;
-        }
-    }
-
-    uint8_t cmd[] = {NCI_ANDROID_PASSIVE_OBSERVE,
-                     static_cast<uint8_t>(enable ? NCI_ANDROID_PASSIVE_OBSERVE_PARAM_ENABLE
-                                                 : NCI_ANDROID_PASSIVE_OBSERVE_PARAM_DISABLE)};
-
-    status = NFA_SendVsCommand(NCI_MSG_PROP_ANDROID, sizeof(cmd), cmd, nfaVSCallback);
-
-    if (status == NFA_STATUS_OK) {
-        if (!sNfaVsCommand.wait(1000)) {
-            LOG(WARNING) << "Timeout waiting for set observe mode command response";
-            return NFA_STATUS_TIMEOUT;
-        }
-    }
-
-    return status;
-}
-
-/*
  * Get observe mode state.
  */
 tNFA_STATUS static nfaQueryObserveModeState() {
@@ -322,33 +291,6 @@
 };
 
 /*
- * ObserveModeEnableDisable:
- * Attempts to enable observe mode. Does not test Observe Mode functionality,
- * but simply verifies that the enable command responds successfully.
- *
- * @VsrTest = GMS-VSR-3.2.8-001
- */
-TEST_P(NfcBehaviorChanges, ObserveModeEnableDisable) {
-    if (get_vsr_api_level() < 202404) {
-        GTEST_SKIP() << "Skipping test for board API level < 202404";
-    }
-
-    tNFA_STATUS status = nfaObserveModeEnable(true);
-    ASSERT_EQ(status, NFA_STATUS_OK);
-
-    status = nfaQueryObserveModeState();
-    ASSERT_EQ(status, NFA_STATUS_OK);
-    ASSERT_NE(sObserveModeState, 0);
-
-    status = nfaObserveModeEnable(false);
-    ASSERT_EQ(status, NFA_STATUS_OK);
-
-    status = nfaQueryObserveModeState();
-    ASSERT_EQ(status, NFA_STATUS_OK);
-    ASSERT_EQ(sObserveModeState, 0);
-}
-
-/*
  * SetPassiveObserverTech_getCaps:
  * Verifies GET_CAPS returns get correct value for observe mode capabilities.
  */
diff --git a/power/1.0/vts/OWNERS b/power/1.0/vts/OWNERS
index 6de2cd5..53948b9 100644
--- a/power/1.0/vts/OWNERS
+++ b/power/1.0/vts/OWNERS
@@ -1,2 +1 @@
 # Bug component: 158088
-connoro@google.com
diff --git a/power/1.1/vts/functional/OWNERS b/power/1.1/vts/functional/OWNERS
index 6de2cd5..53948b9 100644
--- a/power/1.1/vts/functional/OWNERS
+++ b/power/1.1/vts/functional/OWNERS
@@ -1,2 +1 @@
 # Bug component: 158088
-connoro@google.com
diff --git a/security/secretkeeper/OWNERS b/security/secretkeeper/OWNERS
index acf4c6c..d63ba9b 100644
--- a/security/secretkeeper/OWNERS
+++ b/security/secretkeeper/OWNERS
@@ -1,6 +1,5 @@
 # Bug component: 867125
 
-alanstokes@google.com
 drysdale@google.com
 hasinitg@google.com
 shikhapanwar@google.com
diff --git a/threadnetwork/aidl/default/Android.bp b/threadnetwork/aidl/default/Android.bp
index a840fa3..481f027 100644
--- a/threadnetwork/aidl/default/Android.bp
+++ b/threadnetwork/aidl/default/Android.bp
@@ -45,6 +45,41 @@
     ],
 }
 
+cc_library_static {
+    name: "android.hardware.threadnetwork.lib",
+
+    vendor: true,
+    export_include_dirs: ["."],
+
+    defaults: ["android.hardware.threadnetwork-service.defaults"],
+
+    srcs: [
+        "service.cpp",
+        "thread_chip.cpp",
+        "utils.cpp",
+    ],
+
+    shared_libs: [
+        "libbinder_ndk",
+        "liblog",
+    ],
+
+    static_libs: [
+        "android.hardware.threadnetwork-V1-ndk",
+        "libbase",
+        "libcutils",
+        "libutils",
+        "openthread-common",
+        "openthread-hdlc",
+        "openthread-platform",
+        "openthread-posix",
+        "openthread-spi",
+        "openthread-url",
+    ],
+
+    stl: "c++_static",
+}
+
 cc_defaults {
     name: "android.hardware.threadnetwork-service.defaults",
     product_variables: {
diff --git a/threadnetwork/aidl/default/thread_chip.cpp b/threadnetwork/aidl/default/thread_chip.cpp
index e312728..ba0baf2 100644
--- a/threadnetwork/aidl/default/thread_chip.cpp
+++ b/threadnetwork/aidl/default/thread_chip.cpp
@@ -83,6 +83,11 @@
                 mRxFrameBuffer.GetFrame(), mRxFrameBuffer.GetFrame() + mRxFrameBuffer.GetLength()));
     }
 
+    if (mVendorCallback != nullptr) {
+        mVendorCallback->onReceiveSpinelFrame(std::vector<uint8_t>(
+                mRxFrameBuffer.GetFrame(), mRxFrameBuffer.GetFrame() + mRxFrameBuffer.GetLength()));
+    }
+
     mRxFrameBuffer.DiscardFrame();
 }
 
@@ -193,6 +198,10 @@
     }
 }
 
+void ThreadChip::setVendorCallback(const std::shared_ptr<IThreadChipCallback>& vendorCallback) {
+    mVendorCallback = vendorCallback;
+}
+
 ndk::ScopedAStatus ThreadChip::errorStatus(int32_t error, const char* message) {
     return ndk::ScopedAStatus(AStatus_fromServiceSpecificErrorWithMessage(error, message));
 }
diff --git a/threadnetwork/aidl/default/thread_chip.hpp b/threadnetwork/aidl/default/thread_chip.hpp
index d07d049..6f23efe 100644
--- a/threadnetwork/aidl/default/thread_chip.hpp
+++ b/threadnetwork/aidl/default/thread_chip.hpp
@@ -43,6 +43,7 @@
     ndk::ScopedAStatus hardwareReset() override;
     void Update(otSysMainloopContext& context) override;
     void Process(const otSysMainloopContext& context) override;
+    void setVendorCallback(const std::shared_ptr<IThreadChipCallback>& vendorCallback);
 
   private:
     static void onBinderDiedJump(void* context);
@@ -59,6 +60,7 @@
     std::shared_ptr<ot::Spinel::SpinelInterface> mSpinelInterface;
     ot::Spinel::SpinelInterface::RxFrameBuffer mRxFrameBuffer;
     std::shared_ptr<IThreadChipCallback> mCallback;
+    std::shared_ptr<IThreadChipCallback> mVendorCallback;
     ::ndk::ScopedAIBinder_DeathRecipient mDeathRecipient;
 };
 
diff --git a/wifi/OWNERS b/wifi/OWNERS
index c10bbab..ec21f2e 100644
--- a/wifi/OWNERS
+++ b/wifi/OWNERS
@@ -7,4 +7,3 @@
 # This will get them auto-assigned to the on-call triage engineer, ensuring quickest response.
 #
 arabawy@google.com
-etancohen@google.com