Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9eaa0b83 authored by Henri Chataing's avatar Henri Chataing Committed by Automerger Merge Worker
Browse files

Merge "bluetooth/aidl: Enable HCI reset in default hal only when running on...

Merge "bluetooth/aidl: Enable HCI reset in default hal only when running on emulator devices" into main am: 47710091 am: 6f2789f9 am: 72e2afa6

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/2700504



Change-Id: I4c382e36f5a3f760dba467d87eb10ea6af4347b7
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 0c3474c6 72e2afa6
Loading
Loading
Loading
Loading
+26 −2
Original line number Diff line number Diff line
@@ -55,6 +55,19 @@ namespace aidl::android::hardware::bluetooth::impl {

void OnDeath(void* cookie);

std::optional<std::string> GetSystemProperty(const std::string& property) {
  std::array<char, PROPERTY_VALUE_MAX> value_array{0};
  auto value_len = property_get(property.c_str(), value_array.data(), nullptr);
  if (value_len <= 0) {
    return std::nullopt;
  }
  return std::string(value_array.data(), value_len);
}

bool starts_with(const std::string& str, const std::string& prefix) {
  return str.compare(0, prefix.length(), prefix) == 0;
}

class BluetoothDeathRecipient {
 public:
  BluetoothDeathRecipient(BluetoothHci* hci) : mHci(hci) {}
@@ -232,8 +245,19 @@ ndk::ScopedAStatus BluetoothHci::initialize(

  mDeathRecipient->LinkToDeath(mCb);

  // TODO: This should not be necessary when the device implements rfkill.
  // 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,