summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTreehugger Robot2018-10-24 18:07:47 -0500
committerGerrit Code Review2018-10-24 18:07:47 -0500
commitf89cfc82f963ea84ca43c67c69b576143c9e2ae4 (patch)
treeeadea938005ceed5805faac8205131f4e02bf372 /bluetooth/a2dp/1.0
parent44a5e5f768469943f84d26a466c10325e6b9def5 (diff)
parentcaeab05bdbdf20035617893de411ae09df30c778 (diff)
downloadplatform-hardware-interfaces-f89cfc82f963ea84ca43c67c69b576143c9e2ae4.tar.gz
platform-hardware-interfaces-f89cfc82f963ea84ca43c67c69b576143c9e2ae4.tar.xz
platform-hardware-interfaces-f89cfc82f963ea84ca43c67c69b576143c9e2ae4.zip
Merge "Apply clang-format to Bluetooth related HAL code"
Diffstat (limited to 'bluetooth/a2dp/1.0')
-rw-r--r--bluetooth/a2dp/1.0/default/BluetoothAudioOffload.cpp61
-rw-r--r--bluetooth/a2dp/1.0/default/BluetoothAudioOffload.h27
-rw-r--r--bluetooth/a2dp/1.0/vts/functional/VtsHalBluetoothA2dpV1_0TargetTest.cpp157
3 files changed, 131 insertions, 114 deletions
diff --git a/bluetooth/a2dp/1.0/default/BluetoothAudioOffload.cpp b/bluetooth/a2dp/1.0/default/BluetoothAudioOffload.cpp
index 2a66abe6..9abb88d5 100644
--- a/bluetooth/a2dp/1.0/default/BluetoothAudioOffload.cpp
+++ b/bluetooth/a2dp/1.0/default/BluetoothAudioOffload.cpp
@@ -23,47 +23,52 @@ namespace a2dp {
23namespace V1_0 { 23namespace V1_0 {
24namespace implementation { 24namespace implementation {
25 25
26IBluetoothAudioOffload* HIDL_FETCH_IBluetoothAudioOffload(const char* /* name */) { 26IBluetoothAudioOffload* HIDL_FETCH_IBluetoothAudioOffload(
27 return new BluetoothAudioOffload(); 27 const char* /* name */) {
28 return new BluetoothAudioOffload();
28} 29}
29 30
30// Methods from ::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioOffload follow. 31// Methods from
31Return<::android::hardware::bluetooth::a2dp::V1_0::Status> BluetoothAudioOffload::startSession( 32// ::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioOffload follow.
32 const sp<::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioHost>& hostIf __unused, 33Return<::android::hardware::bluetooth::a2dp::V1_0::Status>
33 const ::android::hardware::bluetooth::a2dp::V1_0::CodecConfiguration& codecConfig __unused) { 34BluetoothAudioOffload::startSession(
34 /** 35 const sp<::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioHost>&
35 * Initialize the audio platform if codecConfiguration is supported. 36 hostIf __unused,
36 * Save the the IBluetoothAudioHost interface, so that it can be used 37 const ::android::hardware::bluetooth::a2dp::V1_0::CodecConfiguration&
37 * later to send stream control commands to the HAL client, based on 38 codecConfig __unused) {
38 * interaction with Audio framework. 39 /**
39 */ 40 * Initialize the audio platform if codecConfiguration is supported.
40 return ::android::hardware::bluetooth::a2dp::V1_0::Status::FAILURE; 41 * Save the the IBluetoothAudioHost interface, so that it can be used
42 * later to send stream control commands to the HAL client, based on
43 * interaction with Audio framework.
44 */
45 return ::android::hardware::bluetooth::a2dp::V1_0::Status::FAILURE;
41} 46}
42 47
43Return<void> BluetoothAudioOffload::streamStarted( 48Return<void> BluetoothAudioOffload::streamStarted(
44 ::android::hardware::bluetooth::a2dp::V1_0::Status status __unused) { 49 ::android::hardware::bluetooth::a2dp::V1_0::Status status __unused) {
45 /** 50 /**
46 * Streaming on control path has started, 51 * Streaming on control path has started,
47 * HAL server should start the streaming on data path. 52 * HAL server should start the streaming on data path.
48 */ 53 */
49 return Void(); 54 return Void();
50} 55}
51 56
52Return<void> BluetoothAudioOffload::streamSuspended( 57Return<void> BluetoothAudioOffload::streamSuspended(
53 ::android::hardware::bluetooth::a2dp::V1_0::Status status __unused) { 58 ::android::hardware::bluetooth::a2dp::V1_0::Status status __unused) {
54 /** 59 /**
55 * Streaming on control path has suspend, 60 * Streaming on control path has suspend,
56 * HAL server should suspend the streaming on data path. 61 * HAL server should suspend the streaming on data path.
57 */ 62 */
58 return Void(); 63 return Void();
59} 64}
60 65
61Return<void> BluetoothAudioOffload::endSession() { 66Return<void> BluetoothAudioOffload::endSession() {
62 /** 67 /**
63 * Cleanup the audio platform as remote A2DP Sink device is no 68 * Cleanup the audio platform as remote A2DP Sink device is no
64 * longer active 69 * longer active
65 */ 70 */
66 return Void(); 71 return Void();
67} 72}
68 73
69} // namespace implementation 74} // namespace implementation
diff --git a/bluetooth/a2dp/1.0/default/BluetoothAudioOffload.h b/bluetooth/a2dp/1.0/default/BluetoothAudioOffload.h
index 5d07b5bc..16a83c2a 100644
--- a/bluetooth/a2dp/1.0/default/BluetoothAudioOffload.h
+++ b/bluetooth/a2dp/1.0/default/BluetoothAudioOffload.h
@@ -28,27 +28,32 @@ namespace a2dp {
28namespace V1_0 { 28namespace V1_0 {
29namespace implementation { 29namespace implementation {
30 30
31using ::android::sp;
31using ::android::hardware::hidl_array; 32using ::android::hardware::hidl_array;
32using ::android::hardware::hidl_memory; 33using ::android::hardware::hidl_memory;
33using ::android::hardware::hidl_string; 34using ::android::hardware::hidl_string;
34using ::android::hardware::hidl_vec; 35using ::android::hardware::hidl_vec;
35using ::android::hardware::Return; 36using ::android::hardware::Return;
36using ::android::hardware::Void; 37using ::android::hardware::Void;
37using ::android::sp;
38 38
39struct BluetoothAudioOffload : public IBluetoothAudioOffload { 39struct BluetoothAudioOffload : public IBluetoothAudioOffload {
40 BluetoothAudioOffload() {} 40 BluetoothAudioOffload() {}
41 // Methods from ::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioOffload follow. 41 // Methods from
42 Return<::android::hardware::bluetooth::a2dp::V1_0::Status> startSession( 42 // ::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioOffload follow.
43 const sp<::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioHost>& hostIf, 43 Return<::android::hardware::bluetooth::a2dp::V1_0::Status> startSession(
44 const ::android::hardware::bluetooth::a2dp::V1_0::CodecConfiguration& codecConfig) override; 44 const sp<::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioHost>&
45 Return<void> streamStarted(::android::hardware::bluetooth::a2dp::V1_0::Status status) override; 45 hostIf,
46 Return<void> streamSuspended( 46 const ::android::hardware::bluetooth::a2dp::V1_0::CodecConfiguration&
47 ::android::hardware::bluetooth::a2dp::V1_0::Status status) override; 47 codecConfig) override;
48 Return<void> endSession() override; 48 Return<void> streamStarted(
49 ::android::hardware::bluetooth::a2dp::V1_0::Status status) override;
50 Return<void> streamSuspended(
51 ::android::hardware::bluetooth::a2dp::V1_0::Status status) override;
52 Return<void> endSession() override;
49}; 53};
50 54
51extern "C" IBluetoothAudioOffload* HIDL_FETCH_IBluetoothAudioOffload(const char* name); 55extern "C" IBluetoothAudioOffload* HIDL_FETCH_IBluetoothAudioOffload(
56 const char* name);
52 57
53} // namespace implementation 58} // namespace implementation
54} // namespace V1_0 59} // 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 1a0342f3..d8d0c298 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 @@
26#include <VtsHalHidlTargetTestBase.h> 26#include <VtsHalHidlTargetTestBase.h>
27#include <VtsHalHidlTargetTestEnvBase.h> 27#include <VtsHalHidlTargetTestEnvBase.h>
28 28
29using ::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioHost; 29using ::android::sp;
30using ::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioOffload; 30using ::android::hardware::Return;
31using ::android::hardware::bluetooth::a2dp::V1_0::Status; 31using ::android::hardware::Void;
32using ::android::hardware::bluetooth::a2dp::V1_0::CodecType;
33using ::android::hardware::bluetooth::a2dp::V1_0::SampleRate;
34using ::android::hardware::bluetooth::a2dp::V1_0::BitsPerSample; 32using ::android::hardware::bluetooth::a2dp::V1_0::BitsPerSample;
35using ::android::hardware::bluetooth::a2dp::V1_0::ChannelMode; 33using ::android::hardware::bluetooth::a2dp::V1_0::ChannelMode;
36using ::android::hardware::bluetooth::a2dp::V1_0::CodecConfiguration; 34using ::android::hardware::bluetooth::a2dp::V1_0::CodecConfiguration;
37using ::android::hardware::Return; 35using ::android::hardware::bluetooth::a2dp::V1_0::CodecType;
38using ::android::hardware::Void; 36using ::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioHost;
39using ::android::sp; 37using ::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioOffload;
38using ::android::hardware::bluetooth::a2dp::V1_0::SampleRate;
39using ::android::hardware::bluetooth::a2dp::V1_0::Status;
40 40
41// Test environment for Bluetooth HIDL A2DP HAL. 41// Test environment for Bluetooth HIDL A2DP HAL.
42class BluetoothA2dpHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase { 42class BluetoothA2dpHidlEnvironment
43 public: 43 : public ::testing::VtsHalHidlTargetTestEnvBase {
44 // get the test environment singleton 44 public:
45 static BluetoothA2dpHidlEnvironment* Instance() { 45 // get the test environment singleton
46 static BluetoothA2dpHidlEnvironment* instance = new BluetoothA2dpHidlEnvironment; 46 static BluetoothA2dpHidlEnvironment* Instance() {
47 return instance; 47 static BluetoothA2dpHidlEnvironment* instance =
48 } 48 new BluetoothA2dpHidlEnvironment;
49 49 return instance;
50 virtual void registerTestServices() override { registerTestService<IBluetoothAudioOffload>(); } 50 }
51 51
52 private: 52 virtual void registerTestServices() override {
53 BluetoothA2dpHidlEnvironment() {} 53 registerTestService<IBluetoothAudioOffload>();
54 }
55
56 private:
57 BluetoothA2dpHidlEnvironment() {}
54}; 58};
55 59
56// The main test class for Bluetooth A2DP HIDL HAL. 60// The main test class for Bluetooth A2DP HIDL HAL.
57class BluetoothA2dpHidlTest : public ::testing::VtsHalHidlTargetTestBase { 61class BluetoothA2dpHidlTest : public ::testing::VtsHalHidlTargetTestBase {
62 public:
63 virtual void SetUp() override {
64 // currently test passthrough mode only
65 audio_offload =
66 ::testing::VtsHalHidlTargetTestBase::getService<IBluetoothAudioOffload>(
67 BluetoothA2dpHidlEnvironment::Instance()
68 ->getServiceName<IBluetoothAudioOffload>());
69 ASSERT_NE(audio_offload, nullptr);
70
71 audio_host = new BluetoothAudioHost(*this);
72 ASSERT_NE(audio_host, nullptr);
73
74 codec.codecType = CodecType::AAC;
75 codec.sampleRate = SampleRate::RATE_44100;
76 codec.bitsPerSample = BitsPerSample::BITS_16;
77 codec.channelMode = ChannelMode::STEREO;
78 codec.encodedAudioBitrate = 320000;
79 codec.peerMtu = 1000;
80 }
81
82 virtual void TearDown() override {}
83
84 // A simple test implementation of IBluetoothAudioHost.
85 class BluetoothAudioHost
86 : public ::testing::VtsHalHidlTargetCallbackBase<BluetoothA2dpHidlTest>,
87 public IBluetoothAudioHost {
88 BluetoothA2dpHidlTest& parent_;
89
58 public: 90 public:
59 virtual void SetUp() override { 91 BluetoothAudioHost(BluetoothA2dpHidlTest& parent) : parent_(parent){};
60 // currently test passthrough mode only 92 virtual ~BluetoothAudioHost() = default;
61 audio_offload = ::testing::VtsHalHidlTargetTestBase::getService<IBluetoothAudioOffload>( 93
62 BluetoothA2dpHidlEnvironment::Instance()->getServiceName<IBluetoothAudioOffload>()); 94 Return<void> startStream() override {
63 ASSERT_NE(audio_offload, nullptr); 95 parent_.audio_offload->streamStarted(Status::SUCCESS);
64 96 return Void();
65 audio_host = new BluetoothAudioHost(*this); 97 };
66 ASSERT_NE(audio_host, nullptr); 98
67 99 Return<void> suspendStream() override {
68 codec.codecType = CodecType::AAC; 100 parent_.audio_offload->streamSuspended(Status::SUCCESS);
69 codec.sampleRate = SampleRate::RATE_44100; 101 return Void();
70 codec.bitsPerSample = BitsPerSample::BITS_16;
71 codec.channelMode = ChannelMode::STEREO;
72 codec.encodedAudioBitrate = 320000;
73 codec.peerMtu = 1000;
74 }
75
76 virtual void TearDown() override {}
77
78 // A simple test implementation of IBluetoothAudioHost.
79 class BluetoothAudioHost
80 : public ::testing::VtsHalHidlTargetCallbackBase<BluetoothA2dpHidlTest>,
81 public IBluetoothAudioHost {
82 BluetoothA2dpHidlTest& parent_;
83
84 public:
85 BluetoothAudioHost(BluetoothA2dpHidlTest& parent) : parent_(parent){};
86 virtual ~BluetoothAudioHost() = default;
87
88 Return<void> startStream() override {
89 parent_.audio_offload->streamStarted(Status::SUCCESS);
90 return Void();
91 };
92
93 Return<void> suspendStream() override {
94 parent_.audio_offload->streamSuspended(Status::SUCCESS);
95 return Void();
96 };
97
98 Return<void> stopStream() override { return Void(); };
99 }; 102 };
100 103
101 // audio_host is for the Audio HAL to send stream start/suspend/stop commands to Bluetooth 104 Return<void> stopStream() override { return Void(); };
102 sp<IBluetoothAudioHost> audio_host; 105 };
103 // audio_offload is for the Bluetooth HAL to report session started/ended and handled audio 106
104 // stream started/suspended 107 // audio_host is for the Audio HAL to send stream start/suspend/stop commands
105 sp<IBluetoothAudioOffload> audio_offload; 108 // to Bluetooth
106 // codec is the currently used codec 109 sp<IBluetoothAudioHost> audio_host;
107 CodecConfiguration codec; 110 // audio_offload is for the Bluetooth HAL to report session started/ended and
111 // handled audio stream started/suspended
112 sp<IBluetoothAudioOffload> audio_offload;
113 // codec is the currently used codec
114 CodecConfiguration codec;
108}; 115};
109 116
110// Empty test: Initialize()/Close() are called in SetUp()/TearDown(). 117// Empty test: Initialize()/Close() are called in SetUp()/TearDown().
@@ -112,15 +119,15 @@ TEST_F(BluetoothA2dpHidlTest, InitializeAndClose) {}
112 119
113// Test start and end session 120// Test start and end session
114TEST_F(BluetoothA2dpHidlTest, StartAndEndSession) { 121TEST_F(BluetoothA2dpHidlTest, StartAndEndSession) {
115 EXPECT_EQ(Status::SUCCESS, audio_offload->startSession(audio_host, codec)); 122 EXPECT_EQ(Status::SUCCESS, audio_offload->startSession(audio_host, codec));
116 audio_offload->endSession(); 123 audio_offload->endSession();
117} 124}
118 125
119int main(int argc, char** argv) { 126int main(int argc, char** argv) {
120 ::testing::AddGlobalTestEnvironment(BluetoothA2dpHidlEnvironment::Instance()); 127 ::testing::AddGlobalTestEnvironment(BluetoothA2dpHidlEnvironment::Instance());
121 ::testing::InitGoogleTest(&argc, argv); 128 ::testing::InitGoogleTest(&argc, argv);
122 BluetoothA2dpHidlEnvironment::Instance()->init(&argc, argv); 129 BluetoothA2dpHidlEnvironment::Instance()->init(&argc, argv);
123 int status = RUN_ALL_TESTS(); 130 int status = RUN_ALL_TESTS();
124 LOG(INFO) << "Test result = " << status; 131 LOG(INFO) << "Test result = " << status;
125 return status; 132 return status;
126} 133}