diff --git a/bluetooth/aidl/default/BluetoothHci.cpp b/bluetooth/aidl/default/BluetoothHci.cpp index d4e4b34c6e..940f2adc5b 100644 --- a/bluetooth/aidl/default/BluetoothHci.cpp +++ b/bluetooth/aidl/default/BluetoothHci.cpp @@ -176,7 +176,10 @@ void BluetoothHci::reset() { mFdWatcher.WatchFdForNonBlockingReads(mFd, [this](int) { mH4->OnDataReady(); }); - send(PacketType::COMMAND, reset); + ndk::ScopedAStatus result = send(PacketType::COMMAND, reset); + if (!result.isOk()) { + ALOGE("Error sending reset command"); + } auto status = resetFuture.wait_for(std::chrono::seconds(1)); mFdWatcher.StopWatchingFileDescriptors(); if (status == std::future_status::ready) { @@ -303,30 +306,35 @@ ndk::ScopedAStatus BluetoothHci::close() { ndk::ScopedAStatus BluetoothHci::sendHciCommand( const std::vector& packet) { - send(PacketType::COMMAND, packet); - return ndk::ScopedAStatus::ok(); + return send(PacketType::COMMAND, packet); } ndk::ScopedAStatus BluetoothHci::sendAclData( const std::vector& packet) { - send(PacketType::ACL_DATA, packet); - return ndk::ScopedAStatus::ok(); + return send(PacketType::ACL_DATA, packet); } ndk::ScopedAStatus BluetoothHci::sendScoData( const std::vector& packet) { - send(PacketType::SCO_DATA, packet); - return ndk::ScopedAStatus::ok(); + return send(PacketType::SCO_DATA, packet); } ndk::ScopedAStatus BluetoothHci::sendIsoData( const std::vector& packet) { - send(PacketType::ISO_DATA, packet); + return send(PacketType::ISO_DATA, packet); +} + +ndk::ScopedAStatus BluetoothHci::send(PacketType type, + const std::vector& v) { + if (mH4 == nullptr) { + return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE); + } + if (v.empty()) { + ALOGE("Packet is empty, no data was found to be sent"); + return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); + } + mH4->Send(type, v); return ndk::ScopedAStatus::ok(); } -void BluetoothHci::send(PacketType type, const std::vector& v) { - mH4->Send(type, v); -} - } // namespace aidl::android::hardware::bluetooth::impl diff --git a/bluetooth/aidl/default/BluetoothHci.h b/bluetooth/aidl/default/BluetoothHci.h index 85aafc8197..477cc5c907 100644 --- a/bluetooth/aidl/default/BluetoothHci.h +++ b/bluetooth/aidl/default/BluetoothHci.h @@ -66,8 +66,9 @@ class BluetoothHci : public BnBluetoothHci { ::android::hardware::bluetooth::async::AsyncFdWatcher mFdWatcher; int getFdFromDevPath(); - void send(::android::hardware::bluetooth::hci::PacketType type, - const std::vector& packet); + [[nodiscard]] ndk::ScopedAStatus send( + ::android::hardware::bluetooth::hci::PacketType type, + const std::vector& packet); std::unique_ptr management_{}; // Send a reset command and discard all packets until a reset is received.