diff --git a/bluetooth/ranging/aidl/default/Android.bp b/bluetooth/ranging/aidl/default/Android.bp new file mode 100644 index 0000000000..5072a43141 --- /dev/null +++ b/bluetooth/ranging/aidl/default/Android.bp @@ -0,0 +1,29 @@ +package { + default_applicable_licenses: ["Android-Apache-2.0"], +} + +cc_binary { + name: "android.hardware.bluetooth.ranging-service.default", + relative_install_path: "hw", + init_rc: ["bluetooth-ranging-service-default.rc"], + vintf_fragments: [":manifest_android.hardware.bluetooth.ranging-service.default.xml"], + vendor: true, + srcs: [ + "BluetoothChannelSounding.cpp", + "BluetoothChannelSoundingSession.cpp", + "service.cpp", + ], + shared_libs: [ + "android.hardware.bluetooth.ranging-V1-ndk", + "libbase", + "libbinder_ndk", + "libhidlbase", + "libutils", + "liblog", + ], +} + +filegroup { + name: "manifest_android.hardware.bluetooth.ranging-service.default.xml", + srcs: ["bluetooth-ranging-service-default.xml"], +} diff --git a/bluetooth/ranging/aidl/default/BluetoothChannelSounding.cpp b/bluetooth/ranging/aidl/default/BluetoothChannelSounding.cpp new file mode 100644 index 0000000000..3807d4f8f3 --- /dev/null +++ b/bluetooth/ranging/aidl/default/BluetoothChannelSounding.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2023 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. + */ + +#include "BluetoothChannelSounding.h" + +#include "BluetoothChannelSoundingSession.h" + +namespace aidl::android::hardware::bluetooth::ranging::impl { + +BluetoothChannelSounding::BluetoothChannelSounding() {} +BluetoothChannelSounding::~BluetoothChannelSounding() {} + +ndk::ScopedAStatus BluetoothChannelSounding::getVendorSpecificData( + std::optional< + std::vector>>* /*_aidl_return*/) { + return ::ndk::ScopedAStatus::ok(); +} +ndk::ScopedAStatus BluetoothChannelSounding::getSupportedSessionTypes( + std::optional>* _aidl_return) { + std::vector supported_session_types = {}; + *_aidl_return = supported_session_types; + return ::ndk::ScopedAStatus::ok(); +} +ndk::ScopedAStatus BluetoothChannelSounding::getMaxSupportedCsSecurityLevel( + CsSecurityLevel* _aidl_return) { + CsSecurityLevel security_level = CsSecurityLevel::NOT_SUPPORTED; + *_aidl_return = security_level; + return ::ndk::ScopedAStatus::ok(); +} +ndk::ScopedAStatus BluetoothChannelSounding::openSession( + const BluetoothChannelSoundingParameters& /*in_params*/, + const std::shared_ptr& + in_callback, + std::shared_ptr* _aidl_return) { + if (in_callback == nullptr) { + return ndk::ScopedAStatus::fromExceptionCodeWithMessage( + EX_ILLEGAL_ARGUMENT, "Invalid nullptr callback"); + } + std::shared_ptr session = nullptr; + session = ndk::SharedRefBase::make( + in_callback, Reason::LOCAL_STACK_REQUEST); + *_aidl_return = session; + return ::ndk::ScopedAStatus::ok(); +} +} // namespace aidl::android::hardware::bluetooth::ranging::impl diff --git a/bluetooth/ranging/aidl/default/BluetoothChannelSounding.h b/bluetooth/ranging/aidl/default/BluetoothChannelSounding.h new file mode 100644 index 0000000000..d6b5c03112 --- /dev/null +++ b/bluetooth/ranging/aidl/default/BluetoothChannelSounding.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2023 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. + */ + +#include + +#include + +namespace aidl::android::hardware::bluetooth::ranging::impl { + +using ::aidl::android::hardware::bluetooth::ranging:: + BluetoothChannelSoundingParameters; +using ::aidl::android::hardware::bluetooth::ranging::BnBluetoothChannelSounding; +using ::aidl::android::hardware::bluetooth::ranging::CsSecurityLevel; +using ::aidl::android::hardware::bluetooth::ranging:: + IBluetoothChannelSoundingSession; +using ::aidl::android::hardware::bluetooth::ranging:: + IBluetoothChannelSoundingSessionCallback; +using ::aidl::android::hardware::bluetooth::ranging::SessionType; +using ::aidl::android::hardware::bluetooth::ranging::VendorSpecificData; + +class BluetoothChannelSounding : public BnBluetoothChannelSounding { + public: + BluetoothChannelSounding(); + ~BluetoothChannelSounding(); // Add the destructor declaration + ndk::ScopedAStatus getVendorSpecificData( + std::optional>>* + _aidl_return) override; + ndk::ScopedAStatus getSupportedSessionTypes( + std::optional>* _aidl_return) override; + ndk::ScopedAStatus getMaxSupportedCsSecurityLevel( + CsSecurityLevel* _aidl_return) override; + ndk::ScopedAStatus openSession( + const BluetoothChannelSoundingParameters& in_params, + const std::shared_ptr& + in_callback, + std::shared_ptr* _aidl_return) override; +}; + +} // namespace aidl::android::hardware::bluetooth::ranging::impl diff --git a/bluetooth/ranging/aidl/default/BluetoothChannelSoundingSession.cpp b/bluetooth/ranging/aidl/default/BluetoothChannelSoundingSession.cpp new file mode 100644 index 0000000000..6c58a07f80 --- /dev/null +++ b/bluetooth/ranging/aidl/default/BluetoothChannelSoundingSession.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2023 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. + */ + +#include "BluetoothChannelSoundingSession.h" + +namespace aidl::android::hardware::bluetooth::ranging::impl { + +BluetoothChannelSoundingSession::BluetoothChannelSoundingSession( + std::shared_ptr callback, + Reason reason) { + callback_ = callback; + callback_->onOpened(reason); +} + +ndk::ScopedAStatus BluetoothChannelSoundingSession::getVendorSpecificReplies( + std::optional< + std::vector>>* /*_aidl_return*/) { + return ::ndk::ScopedAStatus::ok(); +} +ndk::ScopedAStatus BluetoothChannelSoundingSession::getSupportedResultTypes( + std::vector* _aidl_return) { + std::vector supported_result_types = {ResultType::RESULT_METERS}; + *_aidl_return = supported_result_types; + return ::ndk::ScopedAStatus::ok(); +} +ndk::ScopedAStatus BluetoothChannelSoundingSession::isAbortedProcedureRequired( + bool* _aidl_return) { + *_aidl_return = false; + return ::ndk::ScopedAStatus::ok(); +} +ndk::ScopedAStatus BluetoothChannelSoundingSession::writeRawData( + const ChannelSoudingRawData& /*in_rawData*/) { + RangingResult ranging_result; + ranging_result.resultMeters = 0.0; + callback_->onResult(ranging_result); + return ::ndk::ScopedAStatus::ok(); +} +ndk::ScopedAStatus BluetoothChannelSoundingSession::close(Reason in_reason) { + callback_->onClose(in_reason); + return ::ndk::ScopedAStatus::ok(); +} +} // namespace aidl::android::hardware::bluetooth::ranging::impl diff --git a/bluetooth/ranging/aidl/default/BluetoothChannelSoundingSession.h b/bluetooth/ranging/aidl/default/BluetoothChannelSoundingSession.h new file mode 100644 index 0000000000..6703f7fe9b --- /dev/null +++ b/bluetooth/ranging/aidl/default/BluetoothChannelSoundingSession.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2023 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. + */ + +#include +#include + +#include + +namespace aidl::android::hardware::bluetooth::ranging::impl { + +using ::aidl::android::hardware::bluetooth::ranging::ChannelSoudingRawData; +using ::aidl::android::hardware::bluetooth::ranging::Reason; +using ::aidl::android::hardware::bluetooth::ranging::ResultType; +using ::aidl::android::hardware::bluetooth::ranging::VendorSpecificData; + +class BluetoothChannelSoundingSession + : public BnBluetoothChannelSoundingSession { + public: + BluetoothChannelSoundingSession( + std::shared_ptr callback, + Reason reason); + + ndk::ScopedAStatus getVendorSpecificReplies( + std::optional>>* + _aidl_return) override; + ndk::ScopedAStatus getSupportedResultTypes( + std::vector* _aidl_return) override; + ndk::ScopedAStatus isAbortedProcedureRequired(bool* _aidl_return) override; + ndk::ScopedAStatus writeRawData( + const ChannelSoudingRawData& in_rawData) override; + ndk::ScopedAStatus close(Reason in_reason) override; + + private: + std::shared_ptr callback_; +}; + +} // namespace aidl::android::hardware::bluetooth::ranging::impl diff --git a/bluetooth/ranging/aidl/default/bluetooth-ranging-service-default.rc b/bluetooth/ranging/aidl/default/bluetooth-ranging-service-default.rc new file mode 100644 index 0000000000..fabb409c8a --- /dev/null +++ b/bluetooth/ranging/aidl/default/bluetooth-ranging-service-default.rc @@ -0,0 +1,6 @@ +service vendor.bluetooth.ranging-default /vendor/bin/hw/android.hardware.bluetooth.ranging-service.default + class hal + capabilities BLOCK_SUSPEND NET_ADMIN SYS_NICE + user bluetooth + group bluetooth + task_profiles HighPerformance diff --git a/bluetooth/ranging/aidl/default/bluetooth-ranging-service-default.xml b/bluetooth/ranging/aidl/default/bluetooth-ranging-service-default.xml new file mode 100644 index 0000000000..fe3613dfbc --- /dev/null +++ b/bluetooth/ranging/aidl/default/bluetooth-ranging-service-default.xml @@ -0,0 +1,7 @@ + + + android.hardware.bluetooth.ranging + 1 + IBluetoothChannelSounding/default + + diff --git a/bluetooth/ranging/aidl/default/service.cpp b/bluetooth/ranging/aidl/default/service.cpp new file mode 100644 index 0000000000..83e539ec4f --- /dev/null +++ b/bluetooth/ranging/aidl/default/service.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2023 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. + */ + +#define LOG_TAG "aidl.android.hardware.bluetooth.ranging.service.default" + +#include +#include +#include + +#include "BluetoothChannelSounding.h" +#include "BluetoothChannelSoundingSession.h" + +using ::aidl::android::hardware::bluetooth::ranging::impl:: + BluetoothChannelSounding; + +int main(int /* argc */, char** /* argv */) { + ALOGI("Bluetooth Ranging HAL registering"); + if (!ABinderProcess_setThreadPoolMaxThreadCount(0)) { + ALOGE("Failed to set thread pool max thread count"); + return 1; + } + + std::shared_ptr service = + ndk::SharedRefBase::make(); + std::string instance = + std::string() + BluetoothChannelSounding::descriptor + "/default"; + auto result = + AServiceManager_addService(service->asBinder().get(), instance.c_str()); + if (result == STATUS_OK) { + ABinderProcess_joinThreadPool(); + } else { + ALOGE("Could not register as a service!"); + } + return 0; +}