From caeab05bdbdf20035617893de411ae09df30c778 Mon Sep 17 00:00:00 2001 From: Jack He Date: Tue, 23 Oct 2018 18:13:51 -0700 Subject: [PATCH] Apply clang-format to Bluetooth related HAL code - cp system/bt/.clang-format hardware/interfaces/bluetooth/ - modify hardware/interfaces/bluetooth/.clang-format to match context - find . -type f \( -iname \*.cpp -o -iname \*.h -o -iname \*.cc \) | xargs clang-format --style=file -i Test: make Change-Id: I82e4f26e1efeb715aff7de8a15c3db06e02967a4 --- bluetooth/.clang-format | 20 +++ bluetooth/1.0/default/async_fd_watcher.cc | 18 +-- bluetooth/1.0/default/async_fd_watcher.h | 9 +- bluetooth/1.0/default/bluetooth_address.h | 10 +- bluetooth/1.0/default/bluetooth_hci.h | 2 +- bluetooth/1.0/default/bt_vendor_lib.h | 13 +- bluetooth/1.0/default/h4_protocol.cc | 3 +- bluetooth/1.0/default/hci_packetizer.cc | 4 +- bluetooth/1.0/default/hci_protocol.cc | 2 +- bluetooth/1.0/default/service.cpp | 4 +- .../default/test/async_fd_watcher_unittest.cc | 22 +-- .../1.0/default/test/h4_protocol_unittest.cc | 2 +- .../1.0/default/test/mct_protocol_unittest.cc | 2 +- bluetooth/1.0/default/test/properties.cc | 6 +- bluetooth/1.0/default/vendor_interface.cc | 5 +- bluetooth/1.0/default/vendor_interface.h | 10 +- .../VtsHalBluetoothV1_0TargetTest.cpp | 48 +++--- .../1.0/default/BluetoothAudioOffload.cpp | 61 +++---- .../a2dp/1.0/default/BluetoothAudioOffload.h | 27 ++-- .../VtsHalBluetoothA2dpV1_0TargetTest.cpp | 151 +++++++++--------- 20 files changed, 227 insertions(+), 192 deletions(-) create mode 100644 bluetooth/.clang-format diff --git a/bluetooth/.clang-format b/bluetooth/.clang-format new file mode 100644 index 0000000000..956499428d --- /dev/null +++ b/bluetooth/.clang-format @@ -0,0 +1,20 @@ +# +# Copyright 2018 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. +# + +BasedOnStyle: Google +CommentPragmas: NOLINT:.* +DerivePointerAlignment: false + diff --git a/bluetooth/1.0/default/async_fd_watcher.cc b/bluetooth/1.0/default/async_fd_watcher.cc index 7c74643871..18098ca12c 100644 --- a/bluetooth/1.0/default/async_fd_watcher.cc +++ b/bluetooth/1.0/default/async_fd_watcher.cc @@ -18,13 +18,13 @@ #include "async_fd_watcher.h" +#include #include #include #include #include #include #include -#include #include #include "fcntl.h" #include "sys/select.h" @@ -159,11 +159,9 @@ void AsyncFdWatcher::ThreadRoutine() { TimeoutCallback saved_cb; { std::unique_lock guard(timeout_mutex_); - if (timeout_ms_ > std::chrono::milliseconds(0)) - saved_cb = timeout_cb_; + if (timeout_ms_ > std::chrono::milliseconds(0)) saved_cb = timeout_cb_; } - if (saved_cb != nullptr) - saved_cb(); + if (saved_cb != nullptr) saved_cb(); continue; } @@ -180,14 +178,14 @@ void AsyncFdWatcher::ThreadRoutine() { std::unique_lock guard(internal_mutex_); for (auto& it : watched_fds_) { if (FD_ISSET(it.first, &read_fds)) { - it.second(it.first); + it.second(it.first); } } } } } -} // namespace async -} // namespace bluetooth -} // namespace hardware -} // namespace android +} // namespace async +} // namespace bluetooth +} // namespace hardware +} // namespace android diff --git a/bluetooth/1.0/default/async_fd_watcher.h b/bluetooth/1.0/default/async_fd_watcher.h index 358cbc3d2d..b51f92111d 100644 --- a/bluetooth/1.0/default/async_fd_watcher.h +++ b/bluetooth/1.0/default/async_fd_watcher.h @@ -60,8 +60,7 @@ class AsyncFdWatcher { std::chrono::milliseconds timeout_ms_; }; - -} // namespace async -} // namespace bluetooth -} // namespace hardware -} // namespace android +} // namespace async +} // namespace bluetooth +} // namespace hardware +} // namespace android diff --git a/bluetooth/1.0/default/bluetooth_address.h b/bluetooth/1.0/default/bluetooth_address.h index 94bf6161cc..010a113244 100644 --- a/bluetooth/1.0/default/bluetooth_address.h +++ b/bluetooth/1.0/default/bluetooth_address.h @@ -54,8 +54,8 @@ class BluetoothAddress { static bool get_local_address(uint8_t* addr); }; -} // namespace implementation -} // namespace V1_0 -} // namespace bluetooth -} // namespace hardware -} // namespace android +} // namespace implementation +} // namespace V1_0 +} // namespace bluetooth +} // namespace hardware +} // namespace android diff --git a/bluetooth/1.0/default/bluetooth_hci.h b/bluetooth/1.0/default/bluetooth_hci.h index e2797b1171..c966990083 100644 --- a/bluetooth/1.0/default/bluetooth_hci.h +++ b/bluetooth/1.0/default/bluetooth_hci.h @@ -29,8 +29,8 @@ namespace bluetooth { namespace V1_0 { namespace implementation { -using ::android::hardware::Return; using ::android::hardware::hidl_vec; +using ::android::hardware::Return; class BluetoothDeathRecipient; diff --git a/bluetooth/1.0/default/bt_vendor_lib.h b/bluetooth/1.0/default/bt_vendor_lib.h index c140e52245..c4035b7075 100644 --- a/bluetooth/1.0/default/bt_vendor_lib.h +++ b/bluetooth/1.0/default/bt_vendor_lib.h @@ -418,13 +418,12 @@ extern const bt_vendor_interface_t BLUETOOTH_VENDOR_LIB_INTERFACE; // DIRECTORIES. // ONLY USED INSIDE transmit_cb. // DO NOT USE IN NEW HAL IMPLEMENTATIONS GOING FORWARD -typedef struct -{ - uint16_t event; - uint16_t len; - uint16_t offset; - uint16_t layer_specific; - uint8_t data[]; +typedef struct { + uint16_t event; + uint16_t len; + uint16_t offset; + uint16_t layer_specific; + uint8_t data[]; } HC_BT_HDR; // /MODIFICATION diff --git a/bluetooth/1.0/default/h4_protocol.cc b/bluetooth/1.0/default/h4_protocol.cc index df4050771f..98e3273f31 100644 --- a/bluetooth/1.0/default/h4_protocol.cc +++ b/bluetooth/1.0/default/h4_protocol.cc @@ -34,7 +34,8 @@ size_t H4Protocol::Send(uint8_t type, const uint8_t* data, size_t length) { {const_cast(data), length}}; ssize_t ret = 0; do { - ret = TEMP_FAILURE_RETRY(writev(uart_fd_, iov, sizeof(iov) / sizeof(iov[0]))); + ret = + TEMP_FAILURE_RETRY(writev(uart_fd_, iov, sizeof(iov) / sizeof(iov[0]))); } while (-1 == ret && EAGAIN == errno); if (ret == -1) { diff --git a/bluetooth/1.0/default/hci_packetizer.cc b/bluetooth/1.0/default/hci_packetizer.cc index 71f43284b1..7cb3a113f1 100644 --- a/bluetooth/1.0/default/hci_packetizer.cc +++ b/bluetooth/1.0/default/hci_packetizer.cc @@ -46,9 +46,7 @@ namespace hardware { namespace bluetooth { namespace hci { -const hidl_vec& HciPacketizer::GetPacket() const { - return packet_; -} +const hidl_vec& HciPacketizer::GetPacket() const { return packet_; } void HciPacketizer::OnDataReady(int fd, HciPacketType packet_type) { switch (state_) { diff --git a/bluetooth/1.0/default/hci_protocol.cc b/bluetooth/1.0/default/hci_protocol.cc index bf94dfe884..7e88dc44dd 100644 --- a/bluetooth/1.0/default/hci_protocol.cc +++ b/bluetooth/1.0/default/hci_protocol.cc @@ -20,8 +20,8 @@ #include #include #include -#include #include +#include namespace android { namespace hardware { diff --git a/bluetooth/1.0/default/service.cpp b/bluetooth/1.0/default/service.cpp index 3a7aad02c7..dd3f6a9d0c 100644 --- a/bluetooth/1.0/default/service.cpp +++ b/bluetooth/1.0/default/service.cpp @@ -24,9 +24,9 @@ static const size_t kMaxThreads = 5; // Generated HIDL files -using android::hardware::bluetooth::V1_0::IBluetoothHci; using android::hardware::defaultPassthroughServiceImplementation; +using android::hardware::bluetooth::V1_0::IBluetoothHci; int main() { - return defaultPassthroughServiceImplementation(kMaxThreads); + return defaultPassthroughServiceImplementation(kMaxThreads); } diff --git a/bluetooth/1.0/default/test/async_fd_watcher_unittest.cc b/bluetooth/1.0/default/test/async_fd_watcher_unittest.cc index ee7d8d133a..07d8d54307 100644 --- a/bluetooth/1.0/default/test/async_fd_watcher_unittest.cc +++ b/bluetooth/1.0/default/test/async_fd_watcher_unittest.cc @@ -252,13 +252,13 @@ TEST_F(AsyncFdWatcherSocketTest, TimedOutSchedulesTimeout) { }); // Set a timeout flag in each callback. - conn_watcher.ConfigureTimeout( - std::chrono::milliseconds(500), - [&conn_watcher, &timed_out, &timed_out2]() { - timed_out = true; - conn_watcher.ConfigureTimeout(std::chrono::seconds(1), + conn_watcher.ConfigureTimeout(std::chrono::milliseconds(500), + [&conn_watcher, &timed_out, &timed_out2]() { + timed_out = true; + conn_watcher.ConfigureTimeout( + std::chrono::seconds(1), [&timed_out2]() { timed_out2 = true; }); - }); + }); EXPECT_FALSE(timed_out); EXPECT_FALSE(timed_out2); sleep(1); @@ -385,8 +385,8 @@ TEST_F(AsyncFdWatcherSocketTest, RepeatedTimeOutTest) { CleanUpServer(); } -} // namespace implementation -} // namespace V1_0 -} // namespace bluetooth -} // namespace hardware -} // namespace android +} // namespace implementation +} // namespace V1_0 +} // namespace bluetooth +} // namespace hardware +} // namespace android diff --git a/bluetooth/1.0/default/test/h4_protocol_unittest.cc b/bluetooth/1.0/default/test/h4_protocol_unittest.cc index ad08086c7e..ba56c0d6f3 100644 --- a/bluetooth/1.0/default/test/h4_protocol_unittest.cc +++ b/bluetooth/1.0/default/test/h4_protocol_unittest.cc @@ -36,8 +36,8 @@ namespace bluetooth { namespace V1_0 { namespace implementation { -using ::testing::Eq; using hci::H4Protocol; +using ::testing::Eq; static char sample_data1[100] = "A point is that which has no part."; static char sample_data2[100] = "A line is breadthless length."; diff --git a/bluetooth/1.0/default/test/mct_protocol_unittest.cc b/bluetooth/1.0/default/test/mct_protocol_unittest.cc index d45058e22c..60dbc880d7 100644 --- a/bluetooth/1.0/default/test/mct_protocol_unittest.cc +++ b/bluetooth/1.0/default/test/mct_protocol_unittest.cc @@ -36,8 +36,8 @@ namespace bluetooth { namespace V1_0 { namespace implementation { -using ::testing::Eq; using hci::MctProtocol; +using ::testing::Eq; static char sample_data1[100] = "A point is that which has no part."; static char sample_data2[100] = "A line is breadthless length."; diff --git a/bluetooth/1.0/default/test/properties.cc b/bluetooth/1.0/default/test/properties.cc index 6ac4fb4271..70de01e06d 100644 --- a/bluetooth/1.0/default/test/properties.cc +++ b/bluetooth/1.0/default/test/properties.cc @@ -36,7 +36,7 @@ int num_properties = 0; struct property properties[MAX_PROPERTIES]; // Find the correct entry. -static int property_find(const char *key) { +static int property_find(const char* key) { for (int i = 0; i < num_properties; i++) { if (strncmp(properties[i].key, key, PROP_KEY_MAX) == 0) { return i; @@ -45,7 +45,7 @@ static int property_find(const char *key) { return MAX_PROPERTIES; } -int property_set(const char *key, const char *value) { +int property_set(const char* key, const char* value) { if (strnlen(value, PROP_VALUE_MAX) > PROP_VALUE_MAX) return -1; // Check to see if the property exists. @@ -63,7 +63,7 @@ int property_set(const char *key, const char *value) { return 0; } -int property_get(const char *key, char *value, const char *default_value) { +int property_get(const char* key, char* value, const char* default_value) { // This doesn't mock the behavior of default value if (default_value != NULL) ALOGE("%s: default_value is ignored!", __func__); diff --git a/bluetooth/1.0/default/vendor_interface.cc b/bluetooth/1.0/default/vendor_interface.cc index a8f5bb403d..e5f02f3793 100644 --- a/bluetooth/1.0/default/vendor_interface.cc +++ b/bluetooth/1.0/default/vendor_interface.cc @@ -35,8 +35,8 @@ static const int INVALID_FD = -1; namespace { -using android::hardware::bluetooth::V1_0::implementation::VendorInterface; using android::hardware::hidl_vec; +using android::hardware::bluetooth::V1_0::implementation::VendorInterface; struct { tINT_CMD_CBACK cb; @@ -258,8 +258,7 @@ bool VendorInterface::Open(InitializeCompleteCallback initialize_complete_cb, fd_watcher_.WatchFdForNonBlockingReads( fd_list[CH_EVT], [mct_hci](int fd) { mct_hci->OnEventDataReady(fd); }); fd_watcher_.WatchFdForNonBlockingReads( - fd_list[CH_ACL_IN], - [mct_hci](int fd) { mct_hci->OnAclDataReady(fd); }); + fd_list[CH_ACL_IN], [mct_hci](int fd) { mct_hci->OnAclDataReady(fd); }); hci_ = mct_hci; } diff --git a/bluetooth/1.0/default/vendor_interface.h b/bluetooth/1.0/default/vendor_interface.h index a401ee6e55..36f4e1b08e 100644 --- a/bluetooth/1.0/default/vendor_interface.h +++ b/bluetooth/1.0/default/vendor_interface.h @@ -40,9 +40,9 @@ class VendorInterface { PacketReadCallback event_cb, PacketReadCallback acl_cb, PacketReadCallback sco_cb); static void Shutdown(); - static VendorInterface *get(); + static VendorInterface* get(); - size_t Send(uint8_t type, const uint8_t *data, size_t length); + size_t Send(uint8_t type, const uint8_t* data, size_t length); void OnFirmwareConfigured(uint8_t result); @@ -58,15 +58,15 @@ class VendorInterface { void HandleIncomingEvent(const hidl_vec& hci_packet); - void *lib_handle_; - bt_vendor_interface_t *lib_interface_; + void* lib_handle_; + bt_vendor_interface_t* lib_interface_; async::AsyncFdWatcher fd_watcher_; InitializeCompleteCallback initialize_complete_cb_; hci::HciProtocol* hci_; PacketReadCallback event_cb_; - FirmwareStartupTimer *firmware_startup_timer_; + FirmwareStartupTimer* firmware_startup_timer_; }; } // namespace implementation diff --git a/bluetooth/1.0/vts/functional/VtsHalBluetoothV1_0TargetTest.cpp b/bluetooth/1.0/vts/functional/VtsHalBluetoothV1_0TargetTest.cpp index 439c5fb142..ae84ec2bc5 100644 --- a/bluetooth/1.0/vts/functional/VtsHalBluetoothV1_0TargetTest.cpp +++ b/bluetooth/1.0/vts/functional/VtsHalBluetoothV1_0TargetTest.cpp @@ -28,13 +28,13 @@ #include #include -using ::android::hardware::bluetooth::V1_0::IBluetoothHci; -using ::android::hardware::bluetooth::V1_0::IBluetoothHciCallbacks; -using ::android::hardware::bluetooth::V1_0::Status; +using ::android::sp; using ::android::hardware::hidl_vec; using ::android::hardware::Return; using ::android::hardware::Void; -using ::android::sp; +using ::android::hardware::bluetooth::V1_0::IBluetoothHci; +using ::android::hardware::bluetooth::V1_0::IBluetoothHciCallbacks; +using ::android::hardware::bluetooth::V1_0::Status; #define HCI_MINIMUM_HCI_VERSION 5 // Bluetooth Core Specification 3.0 + HS #define HCI_MINIMUM_LMP_VERSION 5 // Bluetooth Core Specification 3.0 + HS @@ -191,12 +191,12 @@ class BluetoothHidlTest : public ::testing::VtsHalHidlTargetTestBase { } virtual void TearDown() override { - // Should not be checked in production code - ASSERT_TRUE(bluetooth->close().isOk()); - handle_no_ops(); - EXPECT_EQ(static_cast(0), event_queue.size()); - EXPECT_EQ(static_cast(0), sco_queue.size()); - EXPECT_EQ(static_cast(0), acl_queue.size()); + // Should not be checked in production code + ASSERT_TRUE(bluetooth->close().isOk()); + handle_no_ops(); + EXPECT_EQ(static_cast(0), event_queue.size()); + EXPECT_EQ(static_cast(0), sco_queue.size()); + EXPECT_EQ(static_cast(0), acl_queue.size()); } void setBufferSizes(); @@ -659,10 +659,11 @@ TEST_F(BluetoothHidlTest, LoopbackModeSinglePackets) { EXPECT_LT(0, max_sco_data_packet_length); sendAndCheckSCO(1, max_sco_data_packet_length, sco_connection_handles[0]); int sco_packets_sent = 1; - int completed_packets = wait_for_completed_packets_event(sco_connection_handles[0]); + int completed_packets = + wait_for_completed_packets_event(sco_connection_handles[0]); if (sco_packets_sent != completed_packets) { - ALOGW("%s: packets_sent (%d) != completed_packets (%d)", __func__, sco_packets_sent, - completed_packets); + ALOGW("%s: packets_sent (%d) != completed_packets (%d)", __func__, + sco_packets_sent, completed_packets); } } @@ -670,10 +671,11 @@ TEST_F(BluetoothHidlTest, LoopbackModeSinglePackets) { EXPECT_LT(0, max_acl_data_packet_length); sendAndCheckACL(1, max_acl_data_packet_length, acl_connection_handles[0]); int acl_packets_sent = 1; - int completed_packets = wait_for_completed_packets_event(acl_connection_handles[0]); + int completed_packets = + wait_for_completed_packets_event(acl_connection_handles[0]); if (acl_packets_sent != completed_packets) { - ALOGW("%s: packets_sent (%d) != completed_packets (%d)", __func__, acl_packets_sent, - completed_packets); + ALOGW("%s: packets_sent (%d) != completed_packets (%d)", __func__, + acl_packets_sent, completed_packets); } } } @@ -695,10 +697,11 @@ TEST_F(BluetoothHidlTest, LoopbackModeBandwidth) { sendAndCheckSCO(NUM_SCO_PACKETS_BANDWIDTH, max_sco_data_packet_length, sco_connection_handles[0]); int sco_packets_sent = NUM_SCO_PACKETS_BANDWIDTH; - int completed_packets = wait_for_completed_packets_event(sco_connection_handles[0]); + int completed_packets = + wait_for_completed_packets_event(sco_connection_handles[0]); if (sco_packets_sent != completed_packets) { - ALOGW("%s: packets_sent (%d) != completed_packets (%d)", __func__, sco_packets_sent, - completed_packets); + ALOGW("%s: packets_sent (%d) != completed_packets (%d)", __func__, + sco_packets_sent, completed_packets); } } @@ -707,10 +710,11 @@ TEST_F(BluetoothHidlTest, LoopbackModeBandwidth) { sendAndCheckACL(NUM_ACL_PACKETS_BANDWIDTH, max_acl_data_packet_length, acl_connection_handles[0]); int acl_packets_sent = NUM_ACL_PACKETS_BANDWIDTH; - int completed_packets = wait_for_completed_packets_event(acl_connection_handles[0]); + int completed_packets = + wait_for_completed_packets_event(acl_connection_handles[0]); if (acl_packets_sent != completed_packets) { - ALOGW("%s: packets_sent (%d) != completed_packets (%d)", __func__, acl_packets_sent, - completed_packets); + ALOGW("%s: packets_sent (%d) != completed_packets (%d)", __func__, + acl_packets_sent, completed_packets); } } } diff --git a/bluetooth/a2dp/1.0/default/BluetoothAudioOffload.cpp b/bluetooth/a2dp/1.0/default/BluetoothAudioOffload.cpp index 2a66abe685..9abb88d519 100644 --- a/bluetooth/a2dp/1.0/default/BluetoothAudioOffload.cpp +++ b/bluetooth/a2dp/1.0/default/BluetoothAudioOffload.cpp @@ -23,47 +23,52 @@ namespace a2dp { namespace V1_0 { namespace implementation { -IBluetoothAudioOffload* HIDL_FETCH_IBluetoothAudioOffload(const char* /* name */) { - return new BluetoothAudioOffload(); +IBluetoothAudioOffload* HIDL_FETCH_IBluetoothAudioOffload( + const char* /* name */) { + return new BluetoothAudioOffload(); } -// Methods from ::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioOffload follow. -Return<::android::hardware::bluetooth::a2dp::V1_0::Status> BluetoothAudioOffload::startSession( - const sp<::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioHost>& hostIf __unused, - const ::android::hardware::bluetooth::a2dp::V1_0::CodecConfiguration& codecConfig __unused) { - /** - * Initialize the audio platform if codecConfiguration is supported. - * Save the the IBluetoothAudioHost interface, so that it can be used - * later to send stream control commands to the HAL client, based on - * interaction with Audio framework. - */ - return ::android::hardware::bluetooth::a2dp::V1_0::Status::FAILURE; +// Methods from +// ::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioOffload follow. +Return<::android::hardware::bluetooth::a2dp::V1_0::Status> +BluetoothAudioOffload::startSession( + const sp<::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioHost>& + hostIf __unused, + const ::android::hardware::bluetooth::a2dp::V1_0::CodecConfiguration& + codecConfig __unused) { + /** + * Initialize the audio platform if codecConfiguration is supported. + * Save the the IBluetoothAudioHost interface, so that it can be used + * later to send stream control commands to the HAL client, based on + * interaction with Audio framework. + */ + return ::android::hardware::bluetooth::a2dp::V1_0::Status::FAILURE; } Return BluetoothAudioOffload::streamStarted( ::android::hardware::bluetooth::a2dp::V1_0::Status status __unused) { - /** - * Streaming on control path has started, - * HAL server should start the streaming on data path. - */ - return Void(); + /** + * Streaming on control path has started, + * HAL server should start the streaming on data path. + */ + return Void(); } Return BluetoothAudioOffload::streamSuspended( ::android::hardware::bluetooth::a2dp::V1_0::Status status __unused) { - /** - * Streaming on control path has suspend, - * HAL server should suspend the streaming on data path. - */ - return Void(); + /** + * Streaming on control path has suspend, + * HAL server should suspend the streaming on data path. + */ + return Void(); } Return BluetoothAudioOffload::endSession() { - /** - * Cleanup the audio platform as remote A2DP Sink device is no - * longer active - */ - return Void(); + /** + * Cleanup the audio platform as remote A2DP Sink device is no + * longer active + */ + return Void(); } } // namespace implementation diff --git a/bluetooth/a2dp/1.0/default/BluetoothAudioOffload.h b/bluetooth/a2dp/1.0/default/BluetoothAudioOffload.h index 5d07b5bca3..16a83c2a11 100644 --- a/bluetooth/a2dp/1.0/default/BluetoothAudioOffload.h +++ b/bluetooth/a2dp/1.0/default/BluetoothAudioOffload.h @@ -28,27 +28,32 @@ namespace a2dp { namespace V1_0 { namespace implementation { +using ::android::sp; using ::android::hardware::hidl_array; using ::android::hardware::hidl_memory; using ::android::hardware::hidl_string; using ::android::hardware::hidl_vec; using ::android::hardware::Return; using ::android::hardware::Void; -using ::android::sp; struct BluetoothAudioOffload : public IBluetoothAudioOffload { - BluetoothAudioOffload() {} - // Methods from ::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioOffload follow. - Return<::android::hardware::bluetooth::a2dp::V1_0::Status> startSession( - const sp<::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioHost>& hostIf, - const ::android::hardware::bluetooth::a2dp::V1_0::CodecConfiguration& codecConfig) override; - Return streamStarted(::android::hardware::bluetooth::a2dp::V1_0::Status status) override; - Return streamSuspended( - ::android::hardware::bluetooth::a2dp::V1_0::Status status) override; - Return endSession() override; + BluetoothAudioOffload() {} + // Methods from + // ::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioOffload follow. + Return<::android::hardware::bluetooth::a2dp::V1_0::Status> startSession( + const sp<::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioHost>& + hostIf, + const ::android::hardware::bluetooth::a2dp::V1_0::CodecConfiguration& + codecConfig) override; + Return streamStarted( + ::android::hardware::bluetooth::a2dp::V1_0::Status status) override; + Return streamSuspended( + ::android::hardware::bluetooth::a2dp::V1_0::Status status) override; + Return endSession() override; }; -extern "C" IBluetoothAudioOffload* HIDL_FETCH_IBluetoothAudioOffload(const char* name); +extern "C" IBluetoothAudioOffload* HIDL_FETCH_IBluetoothAudioOffload( + const char* name); } // namespace implementation } // namespace V1_0 diff --git a/bluetooth/a2dp/1.0/vts/functional/VtsHalBluetoothA2dpV1_0TargetTest.cpp b/bluetooth/a2dp/1.0/vts/functional/VtsHalBluetoothA2dpV1_0TargetTest.cpp index 1a0342f334..d8d0c29828 100644 --- a/bluetooth/a2dp/1.0/vts/functional/VtsHalBluetoothA2dpV1_0TargetTest.cpp +++ b/bluetooth/a2dp/1.0/vts/functional/VtsHalBluetoothA2dpV1_0TargetTest.cpp @@ -26,85 +26,92 @@ #include #include -using ::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioHost; -using ::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioOffload; -using ::android::hardware::bluetooth::a2dp::V1_0::Status; -using ::android::hardware::bluetooth::a2dp::V1_0::CodecType; -using ::android::hardware::bluetooth::a2dp::V1_0::SampleRate; +using ::android::sp; +using ::android::hardware::Return; +using ::android::hardware::Void; using ::android::hardware::bluetooth::a2dp::V1_0::BitsPerSample; using ::android::hardware::bluetooth::a2dp::V1_0::ChannelMode; using ::android::hardware::bluetooth::a2dp::V1_0::CodecConfiguration; -using ::android::hardware::Return; -using ::android::hardware::Void; -using ::android::sp; +using ::android::hardware::bluetooth::a2dp::V1_0::CodecType; +using ::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioHost; +using ::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioOffload; +using ::android::hardware::bluetooth::a2dp::V1_0::SampleRate; +using ::android::hardware::bluetooth::a2dp::V1_0::Status; // Test environment for Bluetooth HIDL A2DP HAL. -class BluetoothA2dpHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase { - public: - // get the test environment singleton - static BluetoothA2dpHidlEnvironment* Instance() { - static BluetoothA2dpHidlEnvironment* instance = new BluetoothA2dpHidlEnvironment; - return instance; - } +class BluetoothA2dpHidlEnvironment + : public ::testing::VtsHalHidlTargetTestEnvBase { + public: + // get the test environment singleton + static BluetoothA2dpHidlEnvironment* Instance() { + static BluetoothA2dpHidlEnvironment* instance = + new BluetoothA2dpHidlEnvironment; + return instance; + } - virtual void registerTestServices() override { registerTestService(); } + virtual void registerTestServices() override { + registerTestService(); + } - private: - BluetoothA2dpHidlEnvironment() {} + private: + BluetoothA2dpHidlEnvironment() {} }; // The main test class for Bluetooth A2DP HIDL HAL. class BluetoothA2dpHidlTest : public ::testing::VtsHalHidlTargetTestBase { + public: + virtual void SetUp() override { + // currently test passthrough mode only + audio_offload = + ::testing::VtsHalHidlTargetTestBase::getService( + BluetoothA2dpHidlEnvironment::Instance() + ->getServiceName()); + ASSERT_NE(audio_offload, nullptr); + + audio_host = new BluetoothAudioHost(*this); + ASSERT_NE(audio_host, nullptr); + + codec.codecType = CodecType::AAC; + codec.sampleRate = SampleRate::RATE_44100; + codec.bitsPerSample = BitsPerSample::BITS_16; + codec.channelMode = ChannelMode::STEREO; + codec.encodedAudioBitrate = 320000; + codec.peerMtu = 1000; + } + + virtual void TearDown() override {} + + // A simple test implementation of IBluetoothAudioHost. + class BluetoothAudioHost + : public ::testing::VtsHalHidlTargetCallbackBase, + public IBluetoothAudioHost { + BluetoothA2dpHidlTest& parent_; + public: - virtual void SetUp() override { - // currently test passthrough mode only - audio_offload = ::testing::VtsHalHidlTargetTestBase::getService( - BluetoothA2dpHidlEnvironment::Instance()->getServiceName()); - ASSERT_NE(audio_offload, nullptr); + BluetoothAudioHost(BluetoothA2dpHidlTest& parent) : parent_(parent){}; + virtual ~BluetoothAudioHost() = default; - audio_host = new BluetoothAudioHost(*this); - ASSERT_NE(audio_host, nullptr); - - codec.codecType = CodecType::AAC; - codec.sampleRate = SampleRate::RATE_44100; - codec.bitsPerSample = BitsPerSample::BITS_16; - codec.channelMode = ChannelMode::STEREO; - codec.encodedAudioBitrate = 320000; - codec.peerMtu = 1000; - } - - virtual void TearDown() override {} - - // A simple test implementation of IBluetoothAudioHost. - class BluetoothAudioHost - : public ::testing::VtsHalHidlTargetCallbackBase, - public IBluetoothAudioHost { - BluetoothA2dpHidlTest& parent_; - - public: - BluetoothAudioHost(BluetoothA2dpHidlTest& parent) : parent_(parent){}; - virtual ~BluetoothAudioHost() = default; - - Return startStream() override { - parent_.audio_offload->streamStarted(Status::SUCCESS); - return Void(); - }; - - Return suspendStream() override { - parent_.audio_offload->streamSuspended(Status::SUCCESS); - return Void(); - }; - - Return stopStream() override { return Void(); }; + Return startStream() override { + parent_.audio_offload->streamStarted(Status::SUCCESS); + return Void(); }; - // audio_host is for the Audio HAL to send stream start/suspend/stop commands to Bluetooth - sp audio_host; - // audio_offload is for the Bluetooth HAL to report session started/ended and handled audio - // stream started/suspended - sp audio_offload; - // codec is the currently used codec - CodecConfiguration codec; + Return suspendStream() override { + parent_.audio_offload->streamSuspended(Status::SUCCESS); + return Void(); + }; + + Return stopStream() override { return Void(); }; + }; + + // audio_host is for the Audio HAL to send stream start/suspend/stop commands + // to Bluetooth + sp audio_host; + // audio_offload is for the Bluetooth HAL to report session started/ended and + // handled audio stream started/suspended + sp audio_offload; + // codec is the currently used codec + CodecConfiguration codec; }; // Empty test: Initialize()/Close() are called in SetUp()/TearDown(). @@ -112,15 +119,15 @@ TEST_F(BluetoothA2dpHidlTest, InitializeAndClose) {} // Test start and end session TEST_F(BluetoothA2dpHidlTest, StartAndEndSession) { - EXPECT_EQ(Status::SUCCESS, audio_offload->startSession(audio_host, codec)); - audio_offload->endSession(); + EXPECT_EQ(Status::SUCCESS, audio_offload->startSession(audio_host, codec)); + audio_offload->endSession(); } int main(int argc, char** argv) { - ::testing::AddGlobalTestEnvironment(BluetoothA2dpHidlEnvironment::Instance()); - ::testing::InitGoogleTest(&argc, argv); - BluetoothA2dpHidlEnvironment::Instance()->init(&argc, argv); - int status = RUN_ALL_TESTS(); - LOG(INFO) << "Test result = " << status; - return status; + ::testing::AddGlobalTestEnvironment(BluetoothA2dpHidlEnvironment::Instance()); + ::testing::InitGoogleTest(&argc, argv); + BluetoothA2dpHidlEnvironment::Instance()->init(&argc, argv); + int status = RUN_ALL_TESTS(); + LOG(INFO) << "Test result = " << status; + return status; }