1*4d7e907cSAndroid Build Coastguard Worker /*
2*4d7e907cSAndroid Build Coastguard Worker * Copyright (C) 2023 The Android Open Source Project
3*4d7e907cSAndroid Build Coastguard Worker *
4*4d7e907cSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*4d7e907cSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*4d7e907cSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*4d7e907cSAndroid Build Coastguard Worker *
8*4d7e907cSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*4d7e907cSAndroid Build Coastguard Worker *
10*4d7e907cSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*4d7e907cSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*4d7e907cSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*4d7e907cSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*4d7e907cSAndroid Build Coastguard Worker * limitations under the License.
15*4d7e907cSAndroid Build Coastguard Worker */
16*4d7e907cSAndroid Build Coastguard Worker
17*4d7e907cSAndroid Build Coastguard Worker #include <aidl/Gtest.h>
18*4d7e907cSAndroid Build Coastguard Worker #include <aidl/Vintf.h>
19*4d7e907cSAndroid Build Coastguard Worker #include <aidl/android/hardware/bluetooth/ranging/BnBluetoothChannelSoundingSessionCallback.h>
20*4d7e907cSAndroid Build Coastguard Worker #include <aidl/android/hardware/bluetooth/ranging/IBluetoothChannelSounding.h>
21*4d7e907cSAndroid Build Coastguard Worker #include <aidl/android/hardware/bluetooth/ranging/IBluetoothChannelSoundingSessionCallback.h>
22*4d7e907cSAndroid Build Coastguard Worker #include <android-base/logging.h>
23*4d7e907cSAndroid Build Coastguard Worker #include <android/binder_manager.h>
24*4d7e907cSAndroid Build Coastguard Worker #include <android/binder_process.h>
25*4d7e907cSAndroid Build Coastguard Worker #include <binder/IServiceManager.h>
26*4d7e907cSAndroid Build Coastguard Worker #include <utils/Log.h>
27*4d7e907cSAndroid Build Coastguard Worker
28*4d7e907cSAndroid Build Coastguard Worker using aidl::android::hardware::bluetooth::ranging::
29*4d7e907cSAndroid Build Coastguard Worker BluetoothChannelSoundingParameters;
30*4d7e907cSAndroid Build Coastguard Worker using aidl::android::hardware::bluetooth::ranging::
31*4d7e907cSAndroid Build Coastguard Worker BnBluetoothChannelSoundingSessionCallback;
32*4d7e907cSAndroid Build Coastguard Worker using aidl::android::hardware::bluetooth::ranging::ChannelSoudingRawData;
33*4d7e907cSAndroid Build Coastguard Worker using aidl::android::hardware::bluetooth::ranging::ChannelSoundingProcedureData;
34*4d7e907cSAndroid Build Coastguard Worker using aidl::android::hardware::bluetooth::ranging::Config;
35*4d7e907cSAndroid Build Coastguard Worker using aidl::android::hardware::bluetooth::ranging::CsSecurityLevel;
36*4d7e907cSAndroid Build Coastguard Worker using aidl::android::hardware::bluetooth::ranging::IBluetoothChannelSounding;
37*4d7e907cSAndroid Build Coastguard Worker using aidl::android::hardware::bluetooth::ranging::
38*4d7e907cSAndroid Build Coastguard Worker IBluetoothChannelSoundingSession;
39*4d7e907cSAndroid Build Coastguard Worker using aidl::android::hardware::bluetooth::ranging::
40*4d7e907cSAndroid Build Coastguard Worker IBluetoothChannelSoundingSessionCallback;
41*4d7e907cSAndroid Build Coastguard Worker using aidl::android::hardware::bluetooth::ranging::ProcedureEnableConfig;
42*4d7e907cSAndroid Build Coastguard Worker using aidl::android::hardware::bluetooth::ranging::RangingResult;
43*4d7e907cSAndroid Build Coastguard Worker using aidl::android::hardware::bluetooth::ranging::Reason;
44*4d7e907cSAndroid Build Coastguard Worker using aidl::android::hardware::bluetooth::ranging::ResultType;
45*4d7e907cSAndroid Build Coastguard Worker using aidl::android::hardware::bluetooth::ranging::SessionType;
46*4d7e907cSAndroid Build Coastguard Worker using aidl::android::hardware::bluetooth::ranging::VendorSpecificData;
47*4d7e907cSAndroid Build Coastguard Worker using ndk::ScopedAStatus;
48*4d7e907cSAndroid Build Coastguard Worker
49*4d7e907cSAndroid Build Coastguard Worker enum class RangingHalVersion : uint8_t {
50*4d7e907cSAndroid Build Coastguard Worker V_UNAVAILABLE = 0,
51*4d7e907cSAndroid Build Coastguard Worker V_1,
52*4d7e907cSAndroid Build Coastguard Worker V_2,
53*4d7e907cSAndroid Build Coastguard Worker };
54*4d7e907cSAndroid Build Coastguard Worker
55*4d7e907cSAndroid Build Coastguard Worker class BluetoothChannelSoundingSessionCallback
56*4d7e907cSAndroid Build Coastguard Worker : public BnBluetoothChannelSoundingSessionCallback {
57*4d7e907cSAndroid Build Coastguard Worker public:
58*4d7e907cSAndroid Build Coastguard Worker ScopedAStatus onOpened(Reason reason) override;
59*4d7e907cSAndroid Build Coastguard Worker ScopedAStatus onOpenFailed(Reason reason) override;
60*4d7e907cSAndroid Build Coastguard Worker ScopedAStatus onResult(const RangingResult& in_result) override;
61*4d7e907cSAndroid Build Coastguard Worker ScopedAStatus onClose(Reason reason) override;
62*4d7e907cSAndroid Build Coastguard Worker ScopedAStatus onCloseFailed(Reason reason) override;
63*4d7e907cSAndroid Build Coastguard Worker };
64*4d7e907cSAndroid Build Coastguard Worker
onOpened(Reason)65*4d7e907cSAndroid Build Coastguard Worker ScopedAStatus BluetoothChannelSoundingSessionCallback::onOpened(
66*4d7e907cSAndroid Build Coastguard Worker Reason /*reason*/) {
67*4d7e907cSAndroid Build Coastguard Worker return ::ndk::ScopedAStatus::ok();
68*4d7e907cSAndroid Build Coastguard Worker }
onOpenFailed(Reason)69*4d7e907cSAndroid Build Coastguard Worker ScopedAStatus BluetoothChannelSoundingSessionCallback::onOpenFailed(
70*4d7e907cSAndroid Build Coastguard Worker Reason /*reason*/) {
71*4d7e907cSAndroid Build Coastguard Worker return ::ndk::ScopedAStatus::ok();
72*4d7e907cSAndroid Build Coastguard Worker }
onResult(const RangingResult &)73*4d7e907cSAndroid Build Coastguard Worker ScopedAStatus BluetoothChannelSoundingSessionCallback::onResult(
74*4d7e907cSAndroid Build Coastguard Worker const RangingResult& /*in_result*/) {
75*4d7e907cSAndroid Build Coastguard Worker return ::ndk::ScopedAStatus::ok();
76*4d7e907cSAndroid Build Coastguard Worker }
onClose(Reason)77*4d7e907cSAndroid Build Coastguard Worker ScopedAStatus BluetoothChannelSoundingSessionCallback::onClose(
78*4d7e907cSAndroid Build Coastguard Worker Reason /*reason*/) {
79*4d7e907cSAndroid Build Coastguard Worker return ::ndk::ScopedAStatus::ok();
80*4d7e907cSAndroid Build Coastguard Worker }
onCloseFailed(Reason)81*4d7e907cSAndroid Build Coastguard Worker ScopedAStatus BluetoothChannelSoundingSessionCallback::onCloseFailed(
82*4d7e907cSAndroid Build Coastguard Worker Reason /*reason*/) {
83*4d7e907cSAndroid Build Coastguard Worker return ::ndk::ScopedAStatus::ok();
84*4d7e907cSAndroid Build Coastguard Worker }
85*4d7e907cSAndroid Build Coastguard Worker
86*4d7e907cSAndroid Build Coastguard Worker class BluetoothRangingTest : public ::testing::TestWithParam<std::string> {
87*4d7e907cSAndroid Build Coastguard Worker public:
SetUp()88*4d7e907cSAndroid Build Coastguard Worker virtual void SetUp() override {
89*4d7e907cSAndroid Build Coastguard Worker ALOGI("SetUp Ranging Test");
90*4d7e907cSAndroid Build Coastguard Worker bluetooth_channel_sounding_ = IBluetoothChannelSounding::fromBinder(
91*4d7e907cSAndroid Build Coastguard Worker ndk::SpAIBinder(AServiceManager_waitForService(GetParam().c_str())));
92*4d7e907cSAndroid Build Coastguard Worker hal_version_ = GetRangingHalVersion();
93*4d7e907cSAndroid Build Coastguard Worker ASSERT_GT(hal_version_, RangingHalVersion::V_UNAVAILABLE);
94*4d7e907cSAndroid Build Coastguard Worker ASSERT_NE(bluetooth_channel_sounding_, nullptr);
95*4d7e907cSAndroid Build Coastguard Worker }
96*4d7e907cSAndroid Build Coastguard Worker
TearDown()97*4d7e907cSAndroid Build Coastguard Worker virtual void TearDown() override {
98*4d7e907cSAndroid Build Coastguard Worker ALOGI("TearDown Ranging Test");
99*4d7e907cSAndroid Build Coastguard Worker bluetooth_channel_sounding_ = nullptr;
100*4d7e907cSAndroid Build Coastguard Worker ASSERT_EQ(bluetooth_channel_sounding_, nullptr);
101*4d7e907cSAndroid Build Coastguard Worker }
102*4d7e907cSAndroid Build Coastguard Worker
103*4d7e907cSAndroid Build Coastguard Worker ScopedAStatus getVendorSpecificData(
104*4d7e907cSAndroid Build Coastguard Worker std::optional<std::vector<std::optional<VendorSpecificData>>>*
105*4d7e907cSAndroid Build Coastguard Worker _aidl_return);
106*4d7e907cSAndroid Build Coastguard Worker ScopedAStatus getSupportedSessionTypes(
107*4d7e907cSAndroid Build Coastguard Worker std::optional<std::vector<SessionType>>* _aidl_return);
108*4d7e907cSAndroid Build Coastguard Worker ScopedAStatus getMaxSupportedCsSecurityLevel(CsSecurityLevel* _aidl_return);
109*4d7e907cSAndroid Build Coastguard Worker ScopedAStatus getSupportedCsSecurityLevels(
110*4d7e907cSAndroid Build Coastguard Worker std::vector<CsSecurityLevel>* _aidl_return);
111*4d7e907cSAndroid Build Coastguard Worker ScopedAStatus openSession(
112*4d7e907cSAndroid Build Coastguard Worker const BluetoothChannelSoundingParameters& in_params,
113*4d7e907cSAndroid Build Coastguard Worker const std::shared_ptr<IBluetoothChannelSoundingSessionCallback>&
114*4d7e907cSAndroid Build Coastguard Worker in_callback,
115*4d7e907cSAndroid Build Coastguard Worker std::shared_ptr<IBluetoothChannelSoundingSession>* _aidl_return);
116*4d7e907cSAndroid Build Coastguard Worker
initBluetoothChannelSoundingSession(std::shared_ptr<IBluetoothChannelSoundingSession> * session)117*4d7e907cSAndroid Build Coastguard Worker ScopedAStatus initBluetoothChannelSoundingSession(
118*4d7e907cSAndroid Build Coastguard Worker std::shared_ptr<IBluetoothChannelSoundingSession>* session) {
119*4d7e907cSAndroid Build Coastguard Worker BluetoothChannelSoundingParameters params;
120*4d7e907cSAndroid Build Coastguard Worker std::shared_ptr<BluetoothChannelSoundingSessionCallback> callback = nullptr;
121*4d7e907cSAndroid Build Coastguard Worker callback =
122*4d7e907cSAndroid Build Coastguard Worker ndk::SharedRefBase::make<BluetoothChannelSoundingSessionCallback>();
123*4d7e907cSAndroid Build Coastguard Worker ScopedAStatus status = openSession(params, callback, session);
124*4d7e907cSAndroid Build Coastguard Worker return status;
125*4d7e907cSAndroid Build Coastguard Worker }
126*4d7e907cSAndroid Build Coastguard Worker
GetRangingHalVersion()127*4d7e907cSAndroid Build Coastguard Worker RangingHalVersion GetRangingHalVersion() {
128*4d7e907cSAndroid Build Coastguard Worker int32_t aidl_version = 0;
129*4d7e907cSAndroid Build Coastguard Worker if (bluetooth_channel_sounding_ == nullptr) {
130*4d7e907cSAndroid Build Coastguard Worker return RangingHalVersion::V_UNAVAILABLE;
131*4d7e907cSAndroid Build Coastguard Worker }
132*4d7e907cSAndroid Build Coastguard Worker auto aidl_ret_val =
133*4d7e907cSAndroid Build Coastguard Worker bluetooth_channel_sounding_->getInterfaceVersion(&aidl_version);
134*4d7e907cSAndroid Build Coastguard Worker if (!aidl_ret_val.isOk()) {
135*4d7e907cSAndroid Build Coastguard Worker return RangingHalVersion::V_UNAVAILABLE;
136*4d7e907cSAndroid Build Coastguard Worker }
137*4d7e907cSAndroid Build Coastguard Worker switch (aidl_version) {
138*4d7e907cSAndroid Build Coastguard Worker case 1:
139*4d7e907cSAndroid Build Coastguard Worker return RangingHalVersion::V_1;
140*4d7e907cSAndroid Build Coastguard Worker case 2:
141*4d7e907cSAndroid Build Coastguard Worker return RangingHalVersion::V_2;
142*4d7e907cSAndroid Build Coastguard Worker default:
143*4d7e907cSAndroid Build Coastguard Worker return RangingHalVersion::V_UNAVAILABLE;
144*4d7e907cSAndroid Build Coastguard Worker }
145*4d7e907cSAndroid Build Coastguard Worker return RangingHalVersion::V_UNAVAILABLE;
146*4d7e907cSAndroid Build Coastguard Worker }
147*4d7e907cSAndroid Build Coastguard Worker
148*4d7e907cSAndroid Build Coastguard Worker public:
149*4d7e907cSAndroid Build Coastguard Worker RangingHalVersion hal_version_ = RangingHalVersion::V_UNAVAILABLE;
150*4d7e907cSAndroid Build Coastguard Worker
151*4d7e907cSAndroid Build Coastguard Worker private:
152*4d7e907cSAndroid Build Coastguard Worker std::shared_ptr<IBluetoothChannelSounding> bluetooth_channel_sounding_;
153*4d7e907cSAndroid Build Coastguard Worker };
154*4d7e907cSAndroid Build Coastguard Worker
getVendorSpecificData(std::optional<std::vector<std::optional<VendorSpecificData>>> * _aidl_return)155*4d7e907cSAndroid Build Coastguard Worker ScopedAStatus BluetoothRangingTest::getVendorSpecificData(
156*4d7e907cSAndroid Build Coastguard Worker std::optional<std::vector<std::optional<VendorSpecificData>>>*
157*4d7e907cSAndroid Build Coastguard Worker _aidl_return) {
158*4d7e907cSAndroid Build Coastguard Worker return bluetooth_channel_sounding_->getVendorSpecificData(_aidl_return);
159*4d7e907cSAndroid Build Coastguard Worker }
getSupportedSessionTypes(std::optional<std::vector<SessionType>> * _aidl_return)160*4d7e907cSAndroid Build Coastguard Worker ScopedAStatus BluetoothRangingTest::getSupportedSessionTypes(
161*4d7e907cSAndroid Build Coastguard Worker std::optional<std::vector<SessionType>>* _aidl_return) {
162*4d7e907cSAndroid Build Coastguard Worker return bluetooth_channel_sounding_->getSupportedSessionTypes(_aidl_return);
163*4d7e907cSAndroid Build Coastguard Worker }
164*4d7e907cSAndroid Build Coastguard Worker
getMaxSupportedCsSecurityLevel(CsSecurityLevel * _aidl_return)165*4d7e907cSAndroid Build Coastguard Worker ScopedAStatus BluetoothRangingTest::getMaxSupportedCsSecurityLevel(
166*4d7e907cSAndroid Build Coastguard Worker CsSecurityLevel* _aidl_return) {
167*4d7e907cSAndroid Build Coastguard Worker return bluetooth_channel_sounding_->getMaxSupportedCsSecurityLevel(
168*4d7e907cSAndroid Build Coastguard Worker _aidl_return);
169*4d7e907cSAndroid Build Coastguard Worker }
170*4d7e907cSAndroid Build Coastguard Worker
getSupportedCsSecurityLevels(std::vector<CsSecurityLevel> * _aidl_return)171*4d7e907cSAndroid Build Coastguard Worker ScopedAStatus BluetoothRangingTest::getSupportedCsSecurityLevels(
172*4d7e907cSAndroid Build Coastguard Worker std::vector<CsSecurityLevel>* _aidl_return) {
173*4d7e907cSAndroid Build Coastguard Worker return bluetooth_channel_sounding_->getSupportedCsSecurityLevels(
174*4d7e907cSAndroid Build Coastguard Worker _aidl_return);
175*4d7e907cSAndroid Build Coastguard Worker }
176*4d7e907cSAndroid Build Coastguard Worker
openSession(const BluetoothChannelSoundingParameters & in_params,const std::shared_ptr<IBluetoothChannelSoundingSessionCallback> & in_callback,std::shared_ptr<IBluetoothChannelSoundingSession> * _aidl_return)177*4d7e907cSAndroid Build Coastguard Worker ScopedAStatus BluetoothRangingTest::openSession(
178*4d7e907cSAndroid Build Coastguard Worker const BluetoothChannelSoundingParameters& in_params,
179*4d7e907cSAndroid Build Coastguard Worker const std::shared_ptr<IBluetoothChannelSoundingSessionCallback>&
180*4d7e907cSAndroid Build Coastguard Worker in_callback,
181*4d7e907cSAndroid Build Coastguard Worker std::shared_ptr<IBluetoothChannelSoundingSession>* _aidl_return) {
182*4d7e907cSAndroid Build Coastguard Worker return bluetooth_channel_sounding_->openSession(in_params, in_callback,
183*4d7e907cSAndroid Build Coastguard Worker _aidl_return);
184*4d7e907cSAndroid Build Coastguard Worker }
185*4d7e907cSAndroid Build Coastguard Worker
TEST_P(BluetoothRangingTest,SetupAndTearDown)186*4d7e907cSAndroid Build Coastguard Worker TEST_P(BluetoothRangingTest, SetupAndTearDown) {}
187*4d7e907cSAndroid Build Coastguard Worker
TEST_P(BluetoothRangingTest,GetVendorSpecificData)188*4d7e907cSAndroid Build Coastguard Worker TEST_P(BluetoothRangingTest, GetVendorSpecificData) {
189*4d7e907cSAndroid Build Coastguard Worker std::optional<std::vector<std::optional<VendorSpecificData>>>
190*4d7e907cSAndroid Build Coastguard Worker vendor_specific_data;
191*4d7e907cSAndroid Build Coastguard Worker ScopedAStatus status = getVendorSpecificData(&vendor_specific_data);
192*4d7e907cSAndroid Build Coastguard Worker ASSERT_TRUE(status.isOk());
193*4d7e907cSAndroid Build Coastguard Worker }
194*4d7e907cSAndroid Build Coastguard Worker
TEST_P(BluetoothRangingTest,GetSupportedSessionTypes)195*4d7e907cSAndroid Build Coastguard Worker TEST_P(BluetoothRangingTest, GetSupportedSessionTypes) {
196*4d7e907cSAndroid Build Coastguard Worker std::optional<std::vector<SessionType>> supported_session_types;
197*4d7e907cSAndroid Build Coastguard Worker ScopedAStatus status = getSupportedSessionTypes(&supported_session_types);
198*4d7e907cSAndroid Build Coastguard Worker ASSERT_TRUE(status.isOk());
199*4d7e907cSAndroid Build Coastguard Worker }
200*4d7e907cSAndroid Build Coastguard Worker
TEST_P(BluetoothRangingTest,GetMaxSupportedCsSecurityLevel)201*4d7e907cSAndroid Build Coastguard Worker TEST_P(BluetoothRangingTest, GetMaxSupportedCsSecurityLevel) {
202*4d7e907cSAndroid Build Coastguard Worker if (hal_version_ > RangingHalVersion::V_1) {
203*4d7e907cSAndroid Build Coastguard Worker GTEST_SKIP();
204*4d7e907cSAndroid Build Coastguard Worker }
205*4d7e907cSAndroid Build Coastguard Worker CsSecurityLevel security_level;
206*4d7e907cSAndroid Build Coastguard Worker ScopedAStatus status = getMaxSupportedCsSecurityLevel(&security_level);
207*4d7e907cSAndroid Build Coastguard Worker ASSERT_TRUE(status.isOk());
208*4d7e907cSAndroid Build Coastguard Worker }
209*4d7e907cSAndroid Build Coastguard Worker
TEST_P(BluetoothRangingTest,GetSupportedCsSecurityLevels)210*4d7e907cSAndroid Build Coastguard Worker TEST_P(BluetoothRangingTest, GetSupportedCsSecurityLevels) {
211*4d7e907cSAndroid Build Coastguard Worker if (hal_version_ < RangingHalVersion::V_2) {
212*4d7e907cSAndroid Build Coastguard Worker GTEST_SKIP();
213*4d7e907cSAndroid Build Coastguard Worker }
214*4d7e907cSAndroid Build Coastguard Worker std::vector<CsSecurityLevel> supported_security_levels;
215*4d7e907cSAndroid Build Coastguard Worker ScopedAStatus status =
216*4d7e907cSAndroid Build Coastguard Worker getSupportedCsSecurityLevels(&supported_security_levels);
217*4d7e907cSAndroid Build Coastguard Worker ASSERT_GT(static_cast<uint8_t>(supported_security_levels.size()), 0);
218*4d7e907cSAndroid Build Coastguard Worker ASSERT_TRUE(status.isOk());
219*4d7e907cSAndroid Build Coastguard Worker }
220*4d7e907cSAndroid Build Coastguard Worker
TEST_P(BluetoothRangingTest,OpenSession)221*4d7e907cSAndroid Build Coastguard Worker TEST_P(BluetoothRangingTest, OpenSession) {
222*4d7e907cSAndroid Build Coastguard Worker BluetoothChannelSoundingParameters params;
223*4d7e907cSAndroid Build Coastguard Worker std::shared_ptr<BluetoothChannelSoundingSessionCallback> callback = nullptr;
224*4d7e907cSAndroid Build Coastguard Worker callback =
225*4d7e907cSAndroid Build Coastguard Worker ndk::SharedRefBase::make<BluetoothChannelSoundingSessionCallback>();
226*4d7e907cSAndroid Build Coastguard Worker std::shared_ptr<IBluetoothChannelSoundingSession> session;
227*4d7e907cSAndroid Build Coastguard Worker ScopedAStatus status = openSession(params, callback, &session);
228*4d7e907cSAndroid Build Coastguard Worker ASSERT_TRUE(status.isOk());
229*4d7e907cSAndroid Build Coastguard Worker }
230*4d7e907cSAndroid Build Coastguard Worker
TEST_P(BluetoothRangingTest,GetVendorSpecificReplies)231*4d7e907cSAndroid Build Coastguard Worker TEST_P(BluetoothRangingTest, GetVendorSpecificReplies) {
232*4d7e907cSAndroid Build Coastguard Worker std::shared_ptr<IBluetoothChannelSoundingSession> session;
233*4d7e907cSAndroid Build Coastguard Worker auto status = initBluetoothChannelSoundingSession(&session);
234*4d7e907cSAndroid Build Coastguard Worker ASSERT_TRUE(status.isOk());
235*4d7e907cSAndroid Build Coastguard Worker if (session != nullptr) {
236*4d7e907cSAndroid Build Coastguard Worker std::optional<std::vector<std::optional<VendorSpecificData>>>
237*4d7e907cSAndroid Build Coastguard Worker vendor_specific_data;
238*4d7e907cSAndroid Build Coastguard Worker status = session->getVendorSpecificReplies(&vendor_specific_data);
239*4d7e907cSAndroid Build Coastguard Worker ASSERT_TRUE(status.isOk());
240*4d7e907cSAndroid Build Coastguard Worker }
241*4d7e907cSAndroid Build Coastguard Worker }
242*4d7e907cSAndroid Build Coastguard Worker
TEST_P(BluetoothRangingTest,GetSupportedResultTypes)243*4d7e907cSAndroid Build Coastguard Worker TEST_P(BluetoothRangingTest, GetSupportedResultTypes) {
244*4d7e907cSAndroid Build Coastguard Worker std::shared_ptr<IBluetoothChannelSoundingSession> session;
245*4d7e907cSAndroid Build Coastguard Worker auto status = initBluetoothChannelSoundingSession(&session);
246*4d7e907cSAndroid Build Coastguard Worker ASSERT_TRUE(status.isOk());
247*4d7e907cSAndroid Build Coastguard Worker if (session != nullptr) {
248*4d7e907cSAndroid Build Coastguard Worker std::vector<ResultType> supported_result_types;
249*4d7e907cSAndroid Build Coastguard Worker status = session->getSupportedResultTypes(&supported_result_types);
250*4d7e907cSAndroid Build Coastguard Worker ASSERT_TRUE(status.isOk());
251*4d7e907cSAndroid Build Coastguard Worker }
252*4d7e907cSAndroid Build Coastguard Worker }
253*4d7e907cSAndroid Build Coastguard Worker
TEST_P(BluetoothRangingTest,IsAbortedProcedureRequired)254*4d7e907cSAndroid Build Coastguard Worker TEST_P(BluetoothRangingTest, IsAbortedProcedureRequired) {
255*4d7e907cSAndroid Build Coastguard Worker std::shared_ptr<IBluetoothChannelSoundingSession> session;
256*4d7e907cSAndroid Build Coastguard Worker auto status = initBluetoothChannelSoundingSession(&session);
257*4d7e907cSAndroid Build Coastguard Worker ASSERT_TRUE(status.isOk());
258*4d7e907cSAndroid Build Coastguard Worker if (session != nullptr) {
259*4d7e907cSAndroid Build Coastguard Worker bool is_abort_procedure_required = true;
260*4d7e907cSAndroid Build Coastguard Worker status = session->isAbortedProcedureRequired(&is_abort_procedure_required);
261*4d7e907cSAndroid Build Coastguard Worker ASSERT_TRUE(status.isOk());
262*4d7e907cSAndroid Build Coastguard Worker }
263*4d7e907cSAndroid Build Coastguard Worker }
264*4d7e907cSAndroid Build Coastguard Worker
TEST_P(BluetoothRangingTest,WriteRawData)265*4d7e907cSAndroid Build Coastguard Worker TEST_P(BluetoothRangingTest, WriteRawData) {
266*4d7e907cSAndroid Build Coastguard Worker if (hal_version_ > RangingHalVersion::V_1) {
267*4d7e907cSAndroid Build Coastguard Worker GTEST_SKIP();
268*4d7e907cSAndroid Build Coastguard Worker }
269*4d7e907cSAndroid Build Coastguard Worker std::shared_ptr<IBluetoothChannelSoundingSession> session;
270*4d7e907cSAndroid Build Coastguard Worker auto status = initBluetoothChannelSoundingSession(&session);
271*4d7e907cSAndroid Build Coastguard Worker ASSERT_TRUE(status.isOk());
272*4d7e907cSAndroid Build Coastguard Worker if (session != nullptr) {
273*4d7e907cSAndroid Build Coastguard Worker ChannelSoudingRawData raw_data;
274*4d7e907cSAndroid Build Coastguard Worker status = session->writeRawData(raw_data);
275*4d7e907cSAndroid Build Coastguard Worker ASSERT_TRUE(status.isOk());
276*4d7e907cSAndroid Build Coastguard Worker }
277*4d7e907cSAndroid Build Coastguard Worker }
278*4d7e907cSAndroid Build Coastguard Worker
TEST_P(BluetoothRangingTest,WriteProcedureData)279*4d7e907cSAndroid Build Coastguard Worker TEST_P(BluetoothRangingTest, WriteProcedureData) {
280*4d7e907cSAndroid Build Coastguard Worker if (hal_version_ < RangingHalVersion::V_2) {
281*4d7e907cSAndroid Build Coastguard Worker GTEST_SKIP();
282*4d7e907cSAndroid Build Coastguard Worker }
283*4d7e907cSAndroid Build Coastguard Worker std::shared_ptr<IBluetoothChannelSoundingSession> session;
284*4d7e907cSAndroid Build Coastguard Worker auto status = initBluetoothChannelSoundingSession(&session);
285*4d7e907cSAndroid Build Coastguard Worker ASSERT_TRUE(status.isOk());
286*4d7e907cSAndroid Build Coastguard Worker if (session != nullptr) {
287*4d7e907cSAndroid Build Coastguard Worker ChannelSoundingProcedureData procedure_data;
288*4d7e907cSAndroid Build Coastguard Worker status = session->writeProcedureData(procedure_data);
289*4d7e907cSAndroid Build Coastguard Worker ASSERT_TRUE(status.isOk());
290*4d7e907cSAndroid Build Coastguard Worker }
291*4d7e907cSAndroid Build Coastguard Worker }
292*4d7e907cSAndroid Build Coastguard Worker
TEST_P(BluetoothRangingTest,UpdateChannelSoundingConfig)293*4d7e907cSAndroid Build Coastguard Worker TEST_P(BluetoothRangingTest, UpdateChannelSoundingConfig) {
294*4d7e907cSAndroid Build Coastguard Worker if (hal_version_ < RangingHalVersion::V_2) {
295*4d7e907cSAndroid Build Coastguard Worker GTEST_SKIP();
296*4d7e907cSAndroid Build Coastguard Worker }
297*4d7e907cSAndroid Build Coastguard Worker std::shared_ptr<IBluetoothChannelSoundingSession> session;
298*4d7e907cSAndroid Build Coastguard Worker auto status = initBluetoothChannelSoundingSession(&session);
299*4d7e907cSAndroid Build Coastguard Worker ASSERT_TRUE(status.isOk());
300*4d7e907cSAndroid Build Coastguard Worker if (session != nullptr) {
301*4d7e907cSAndroid Build Coastguard Worker Config config;
302*4d7e907cSAndroid Build Coastguard Worker status = session->updateChannelSoundingConfig(config);
303*4d7e907cSAndroid Build Coastguard Worker ASSERT_TRUE(status.isOk());
304*4d7e907cSAndroid Build Coastguard Worker }
305*4d7e907cSAndroid Build Coastguard Worker }
306*4d7e907cSAndroid Build Coastguard Worker
TEST_P(BluetoothRangingTest,UpdateProcedureEnableConfig)307*4d7e907cSAndroid Build Coastguard Worker TEST_P(BluetoothRangingTest, UpdateProcedureEnableConfig) {
308*4d7e907cSAndroid Build Coastguard Worker if (hal_version_ < RangingHalVersion::V_2) {
309*4d7e907cSAndroid Build Coastguard Worker GTEST_SKIP();
310*4d7e907cSAndroid Build Coastguard Worker }
311*4d7e907cSAndroid Build Coastguard Worker std::shared_ptr<IBluetoothChannelSoundingSession> session;
312*4d7e907cSAndroid Build Coastguard Worker auto status = initBluetoothChannelSoundingSession(&session);
313*4d7e907cSAndroid Build Coastguard Worker ASSERT_TRUE(status.isOk());
314*4d7e907cSAndroid Build Coastguard Worker if (session != nullptr) {
315*4d7e907cSAndroid Build Coastguard Worker ProcedureEnableConfig procedure_enable_config;
316*4d7e907cSAndroid Build Coastguard Worker status = session->updateProcedureEnableConfig(procedure_enable_config);
317*4d7e907cSAndroid Build Coastguard Worker ASSERT_TRUE(status.isOk());
318*4d7e907cSAndroid Build Coastguard Worker }
319*4d7e907cSAndroid Build Coastguard Worker }
320*4d7e907cSAndroid Build Coastguard Worker
TEST_P(BluetoothRangingTest,UpdateBleConnInterval)321*4d7e907cSAndroid Build Coastguard Worker TEST_P(BluetoothRangingTest, UpdateBleConnInterval) {
322*4d7e907cSAndroid Build Coastguard Worker if (hal_version_ < RangingHalVersion::V_2) {
323*4d7e907cSAndroid Build Coastguard Worker GTEST_SKIP();
324*4d7e907cSAndroid Build Coastguard Worker }
325*4d7e907cSAndroid Build Coastguard Worker std::shared_ptr<IBluetoothChannelSoundingSession> session;
326*4d7e907cSAndroid Build Coastguard Worker auto status = initBluetoothChannelSoundingSession(&session);
327*4d7e907cSAndroid Build Coastguard Worker ASSERT_TRUE(status.isOk());
328*4d7e907cSAndroid Build Coastguard Worker if (session != nullptr) {
329*4d7e907cSAndroid Build Coastguard Worker int ble_conn_interval = 10;
330*4d7e907cSAndroid Build Coastguard Worker status = session->updateBleConnInterval(ble_conn_interval);
331*4d7e907cSAndroid Build Coastguard Worker ASSERT_TRUE(status.isOk());
332*4d7e907cSAndroid Build Coastguard Worker }
333*4d7e907cSAndroid Build Coastguard Worker }
334*4d7e907cSAndroid Build Coastguard Worker
TEST_P(BluetoothRangingTest,CloseSession)335*4d7e907cSAndroid Build Coastguard Worker TEST_P(BluetoothRangingTest, CloseSession) {
336*4d7e907cSAndroid Build Coastguard Worker std::shared_ptr<IBluetoothChannelSoundingSession> session;
337*4d7e907cSAndroid Build Coastguard Worker auto status = initBluetoothChannelSoundingSession(&session);
338*4d7e907cSAndroid Build Coastguard Worker ASSERT_TRUE(status.isOk());
339*4d7e907cSAndroid Build Coastguard Worker if (session != nullptr) {
340*4d7e907cSAndroid Build Coastguard Worker status = session->close(Reason::LOCAL_STACK_REQUEST);
341*4d7e907cSAndroid Build Coastguard Worker ASSERT_TRUE(status.isOk());
342*4d7e907cSAndroid Build Coastguard Worker }
343*4d7e907cSAndroid Build Coastguard Worker }
344*4d7e907cSAndroid Build Coastguard Worker
345*4d7e907cSAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(BluetoothRangingTest);
346*4d7e907cSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(PerInstance, BluetoothRangingTest,
347*4d7e907cSAndroid Build Coastguard Worker testing::ValuesIn(android::getAidlHalInstanceNames(
348*4d7e907cSAndroid Build Coastguard Worker IBluetoothChannelSounding::descriptor)),
349*4d7e907cSAndroid Build Coastguard Worker android::PrintInstanceNameToString);
350*4d7e907cSAndroid Build Coastguard Worker
main(int argc,char ** argv)351*4d7e907cSAndroid Build Coastguard Worker int main(int argc, char** argv) {
352*4d7e907cSAndroid Build Coastguard Worker ::testing::InitGoogleTest(&argc, argv);
353*4d7e907cSAndroid Build Coastguard Worker ABinderProcess_startThreadPool();
354*4d7e907cSAndroid Build Coastguard Worker int status = RUN_ALL_TESTS();
355*4d7e907cSAndroid Build Coastguard Worker ALOGI("Test result = %d", status);
356*4d7e907cSAndroid Build Coastguard Worker return status;
357*4d7e907cSAndroid Build Coastguard Worker }