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
This commit is contained in:
Jack He 2018-10-23 18:13:51 -07:00
parent e14e593d8f
commit caeab05bdb
20 changed files with 227 additions and 192 deletions

20
bluetooth/.clang-format Normal file
View file

@ -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

View file

@ -18,13 +18,13 @@
#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"
@ -159,11 +159,9 @@ void AsyncFdWatcher::ThreadRoutine() {
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;
}
@ -180,14 +178,14 @@ void AsyncFdWatcher::ThreadRoutine() {
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

View file

@ -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

View file

@ -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

View file

@ -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;

View file

@ -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

View file

@ -34,7 +34,8 @@ size_t H4Protocol::Send(uint8_t type, const uint8_t* data, size_t length) {
{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) {

View file

@ -46,9 +46,7 @@ namespace hardware {
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_) {

View file

@ -20,8 +20,8 @@
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <log/log.h>
#include <unistd.h>
namespace android {
namespace hardware {

View file

@ -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<IBluetoothHci>(kMaxThreads);
return defaultPassthroughServiceImplementation<IBluetoothHci>(kMaxThreads);
}

View file

@ -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

View file

@ -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.";

View file

@ -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.";

View file

@ -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__);

View file

@ -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;
}

View file

@ -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<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

View file

@ -28,13 +28,13 @@
#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
@ -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<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();
@ -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);
}
}
}

View file

@ -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<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

View file

@ -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<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

View file

@ -26,85 +26,92 @@
#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;
}
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>(); }
virtual void registerTestServices() override {
registerTestService<IBluetoothAudioOffload>();
}
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<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);
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<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(); };
Return<void> 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<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> suspendStream() override {
parent_.audio_offload->streamSuspended(Status::SUCCESS);
return Void();
};
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().
@ -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;
}