1 /*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #define LOG_TAG "bluetooth_a2dp_hidl_hal_test"
18
19 #include <android-base/logging.h>
20 #include <android/hardware/bluetooth/a2dp/1.0/IBluetoothAudioHost.h>
21 #include <android/hardware/bluetooth/a2dp/1.0/IBluetoothAudioOffload.h>
22 #include <gtest/gtest.h>
23 #include <hardware/bluetooth.h>
24 #include <hidl/GtestPrinter.h>
25 #include <hidl/MQDescriptor.h>
26 #include <hidl/ServiceManagement.h>
27 #include <utils/Log.h>
28
29 #include <VtsHalHidlTargetCallbackBase.h>
30
31 using ::android::sp;
32 using ::android::hardware::Return;
33 using ::android::hardware::Void;
34 using ::android::hardware::bluetooth::a2dp::V1_0::BitsPerSample;
35 using ::android::hardware::bluetooth::a2dp::V1_0::ChannelMode;
36 using ::android::hardware::bluetooth::a2dp::V1_0::CodecConfiguration;
37 using ::android::hardware::bluetooth::a2dp::V1_0::CodecType;
38 using ::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioHost;
39 using ::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioOffload;
40 using ::android::hardware::bluetooth::a2dp::V1_0::SampleRate;
41 using ::android::hardware::bluetooth::a2dp::V1_0::Status;
42
43 // The main test class for Bluetooth A2DP HIDL HAL.
44 class BluetoothA2dpHidlTest : public ::testing::TestWithParam<std::string> {
45 public:
SetUp()46 virtual void SetUp() override {
47 // currently test passthrough mode only
48 audio_offload = IBluetoothAudioOffload::getService(GetParam());
49 ASSERT_NE(audio_offload, nullptr);
50
51 audio_host = new BluetoothAudioHost(*this);
52 ASSERT_NE(audio_host, nullptr);
53
54 codec.codecType = CodecType::AAC;
55 codec.sampleRate = SampleRate::RATE_44100;
56 codec.bitsPerSample = BitsPerSample::BITS_16;
57 codec.channelMode = ChannelMode::STEREO;
58 codec.encodedAudioBitrate = 320000;
59 codec.peerMtu = 1000;
60 }
61
TearDown()62 virtual void TearDown() override {}
63
64 // A simple test implementation of IBluetoothAudioHost.
65 class BluetoothAudioHost
66 : public ::testing::VtsHalHidlTargetCallbackBase<BluetoothA2dpHidlTest>,
67 public IBluetoothAudioHost {
68 BluetoothA2dpHidlTest& parent_;
69
70 public:
BluetoothAudioHost(BluetoothA2dpHidlTest & parent)71 BluetoothAudioHost(BluetoothA2dpHidlTest& parent) : parent_(parent){};
72 virtual ~BluetoothAudioHost() = default;
73
startStream()74 Return<void> startStream() override {
75 parent_.audio_offload->streamStarted(Status::SUCCESS);
76 return Void();
77 };
78
suspendStream()79 Return<void> suspendStream() override {
80 parent_.audio_offload->streamSuspended(Status::SUCCESS);
81 return Void();
82 };
83
stopStream()84 Return<void> stopStream() override { return Void(); };
85 };
86
87 // audio_host is for the Audio HAL to send stream start/suspend/stop commands
88 // to Bluetooth
89 sp<IBluetoothAudioHost> audio_host;
90 // audio_offload is for the Bluetooth HAL to report session started/ended and
91 // handled audio stream started/suspended
92 sp<IBluetoothAudioOffload> audio_offload;
93 // codec is the currently used codec
94 CodecConfiguration codec;
95 };
96
97 // Empty test: Initialize()/Close() are called in SetUp()/TearDown().
TEST_P(BluetoothA2dpHidlTest,InitializeAndClose)98 TEST_P(BluetoothA2dpHidlTest, InitializeAndClose) {}
99
100 // Test start and end session
TEST_P(BluetoothA2dpHidlTest,StartAndEndSession)101 TEST_P(BluetoothA2dpHidlTest, StartAndEndSession) {
102 EXPECT_EQ(Status::SUCCESS, audio_offload->startSession(audio_host, codec));
103 audio_offload->endSession();
104 }
105
106 INSTANTIATE_TEST_SUITE_P(
107 PerInstance, BluetoothA2dpHidlTest,
108 testing::ValuesIn(android::hardware::getAllHalInstanceNames(
109 IBluetoothAudioOffload::descriptor)),
110 android::hardware::PrintInstanceNameToString);
111
112 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(BluetoothA2dpHidlTest);
113