author | Yifan Hong <elsk@google.com> | |
Fri, 26 Oct 2018 21:11:23 +0000 (21:11 +0000) | ||
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | |
Fri, 26 Oct 2018 21:11:23 +0000 (21:11 +0000) |
20 files changed:
diff --git a/bluetooth/.clang-format b/bluetooth/.clang-format
--- /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
+
index 7c74643871e1c64a643dfbbb9b94ae81daa18d18..18098ca12cd667e3972180d422fd735533b8e057 100644 (file)
#include "async_fd_watcher.h"
+#include <log/log.h>
#include <algorithm>
#include <atomic>
#include <condition_variable>
#include <map>
#include <mutex>
#include <thread>
-#include <log/log.h>
#include <vector>
#include "fcntl.h"
#include "sys/select.h"
TimeoutCallback saved_cb;
{
std::unique_lock<std::mutex> 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;
}
std::unique_lock<std::mutex> 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
index 358cbc3d2d2dcad6f3313bbd247e6c5ed9b195c3..b51f92111ded09f1dd502eab99f0995eb9f1ee22 100644 (file)
std::chrono::milliseconds timeout_ms_;
};
-
-} // namespace async
-} // namespace bluetooth
-} // namespace hardware
-} // namespace android
+} // namespace async
+} // namespace bluetooth
+} // namespace hardware
+} // namespace android
index 94bf6161cc9bfd102c466be5924759c3d17b9986..010a1132444ff17ee6adc471486349d6437108c4 100644 (file)
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
index e2797b117123885ecadaac3f24ba5152382b0640..c9669900832122a631a5aec11028ac23f1b7b1da 100644 (file)
namespace V1_0 {
namespace implementation {
-using ::android::hardware::Return;
using ::android::hardware::hidl_vec;
+using ::android::hardware::Return;
class BluetoothDeathRecipient;
index c140e522458630acb6cdcaf63a373ae9f1c68534..c4035b7075e3888d04a01be3ec48668ff8d9c78d 100644 (file)
// 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
index df4050771fe5e06db867b4d27fb318025ff4c22b..98e3273f3152dc158f053e9f297be6964bd6a9c7 100644 (file)
{const_cast<uint8_t*>(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) {
index 71f43284b1763a9a6585e24d347d1860b493ea0a..7cb3a113f13096c33a9cbd46795f8e31ead92d4f 100644 (file)
namespace bluetooth {
namespace hci {
-const hidl_vec<uint8_t>& HciPacketizer::GetPacket() const {
- return packet_;
-}
+const hidl_vec<uint8_t>& HciPacketizer::GetPacket() const { return packet_; }
void HciPacketizer::OnDataReady(int fd, HciPacketType packet_type) {
switch (state_) {
index bf94dfe884599f1b3907eb38a05456ef2024a5e6..7e88dc44dddb73bad76f64173d2964c925e42458 100644 (file)
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
-#include <unistd.h>
#include <log/log.h>
+#include <unistd.h>
namespace android {
namespace hardware {
index 3a7aad02c72a8f477c4542235e0adb2f717ca720..dd3f6a9d0cf7219ed667bbc9b4ff01338de36c7c 100644 (file)
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<IBluetoothHci>(kMaxThreads);
+ return defaultPassthroughServiceImplementation<IBluetoothHci>(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 ee7d8d133abe9c17a8a984dae2b98e0acebbd09f..07d8d54307caf4b3bb2da0731104b3bd9383b1e2 100644 (file)
});
// 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);
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 ad08086c7ea4c193e97a8c206ea4deb6ebbed703..ba56c0d6f33de466239c6e4b449b38735b0f2c5c 100644 (file)
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 d45058e22c42af620fe0d364bb553f8adb444717..60dbc880d73bcd62ff8113ff4a935743930b8061 100644 (file)
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.";
index 6ac4fb42712845d795f5d76c616626232c8eb008..70de01e06dd7dc48166e725a2f9015cb79861f8c 100644 (file)
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;
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.
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__);
index a8f5bb403d31d4cb3992b2a7c33a11403301a4a7..e5f02f3793a0f8d8b50091ef631d417e67e86107 100644 (file)
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;
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;
}
index a401ee6e55ab12eee0969eeadc70e160733ec4d5..36f4e1b08ec2ecaccecd7e97b349680d6c54211a 100644 (file)
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);
void HandleIncomingEvent(const hidl_vec<uint8_t>& 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 439c5fb1422464963238da865075fda545d63355..ae84ec2bc528b00f2e3116d9e7ef805b83ed956c 100644 (file)
#include <VtsHalHidlTargetTestEnvBase.h>
#include <queue>
-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
}
virtual void TearDown() override {
- // Should not be checked in production code
- ASSERT_TRUE(bluetooth->close().isOk());
- handle_no_ops();
- EXPECT_EQ(static_cast<size_t>(0), event_queue.size());
- EXPECT_EQ(static_cast<size_t>(0), sco_queue.size());
- EXPECT_EQ(static_cast<size_t>(0), acl_queue.size());
+ // Should not be checked in production code
+ ASSERT_TRUE(bluetooth->close().isOk());
+ handle_no_ops();
+ EXPECT_EQ(static_cast<size_t>(0), event_queue.size());
+ EXPECT_EQ(static_cast<size_t>(0), sco_queue.size());
+ EXPECT_EQ(static_cast<size_t>(0), acl_queue.size());
}
void setBufferSizes();
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);
}
}
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);
}
}
}
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);
}
}
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 2a66abe685712d19e39bc63b237daa7f494bd064..9abb88d519a2e0478e902f7172cb4bf530548c0a 100644 (file)
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<void> 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<void> 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<void> 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 5d07b5bca3455dae96b62df9389253db5fc3d5b5..16a83c2a11fc4da4533b59a43dfc826bc687e6c0 100644 (file)
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<void> streamStarted(::android::hardware::bluetooth::a2dp::V1_0::Status status) override;
- Return<void> streamSuspended(
- ::android::hardware::bluetooth::a2dp::V1_0::Status status) override;
- Return<void> 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<void> streamStarted(
+ ::android::hardware::bluetooth::a2dp::V1_0::Status status) override;
+ Return<void> streamSuspended(
+ ::android::hardware::bluetooth::a2dp::V1_0::Status status) override;
+ Return<void> 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 1a0342f3341ea8f06626dd079aa0bef4186903a0..d8d0c29828232679898dc6f69d1912bc0c38492a 100644 (file)
#include <VtsHalHidlTargetTestBase.h>
#include <VtsHalHidlTargetTestEnvBase.h>
-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;
- }
-
- virtual void registerTestServices() override { registerTestService<IBluetoothAudioOffload>(); }
-
- private:
- BluetoothA2dpHidlEnvironment() {}
+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<IBluetoothAudioOffload>();
+ }
+
+ 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<IBluetoothAudioOffload>(
+ BluetoothA2dpHidlEnvironment::Instance()
+ ->getServiceName<IBluetoothAudioOffload>());
+ 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<BluetoothA2dpHidlTest>,
+ public IBluetoothAudioHost {
+ BluetoothA2dpHidlTest& parent_;
+
public:
- virtual void SetUp() override {
- // currently test passthrough mode only
- audio_offload = ::testing::VtsHalHidlTargetTestBase::getService<IBluetoothAudioOffload>(
- BluetoothA2dpHidlEnvironment::Instance()->getServiceName<IBluetoothAudioOffload>());
- 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<BluetoothA2dpHidlTest>,
- public IBluetoothAudioHost {
- BluetoothA2dpHidlTest& parent_;
-
- public:
- BluetoothAudioHost(BluetoothA2dpHidlTest& parent) : parent_(parent){};
- virtual ~BluetoothAudioHost() = default;
-
- Return<void> startStream() override {
- parent_.audio_offload->streamStarted(Status::SUCCESS);
- return Void();
- };
-
- Return<void> suspendStream() override {
- parent_.audio_offload->streamSuspended(Status::SUCCESS);
- return Void();
- };
-
- Return<void> stopStream() override { return Void(); };
+ BluetoothAudioHost(BluetoothA2dpHidlTest& parent) : parent_(parent){};
+ virtual ~BluetoothAudioHost() = default;
+
+ Return<void> startStream() override {
+ parent_.audio_offload->streamStarted(Status::SUCCESS);
+ return Void();
+ };
+
+ Return<void> suspendStream() override {
+ parent_.audio_offload->streamSuspended(Status::SUCCESS);
+ return Void();
};
- // audio_host is for the Audio HAL to send stream start/suspend/stop commands to Bluetooth
- sp<IBluetoothAudioHost> audio_host;
- // audio_offload is for the Bluetooth HAL to report session started/ended and handled audio
- // stream started/suspended
- sp<IBluetoothAudioOffload> audio_offload;
- // codec is the currently used codec
- CodecConfiguration codec;
+ Return<void> stopStream() override { return Void(); };
+ };
+
+ // audio_host is for the Audio HAL to send stream start/suspend/stop commands
+ // to Bluetooth
+ sp<IBluetoothAudioHost> audio_host;
+ // audio_offload is for the Bluetooth HAL to report session started/ended and
+ // handled audio stream started/suspended
+ sp<IBluetoothAudioOffload> audio_offload;
+ // codec is the currently used codec
+ CodecConfiguration codec;
};
// Empty test: Initialize()/Close() are called in SetUp()/TearDown().
// 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;
}