Merge changes from topic "Bluetooth_Ranging" into main am: 64930a6379 am: bbb0d88c14 am: 997ede9b43

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/2850249

Change-Id: Ic75fdfd1a48ab9b9ca3ae0ab37e1e70d0e5cdb5d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Chienyuan Huang 2023-12-11 23:13:53 +00:00 committed by Automerger Merge Worker
commit 84c0d6a455
8 changed files with 305 additions and 0 deletions

View file

@ -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"],
}

View file

@ -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<std::optional<VendorSpecificData>>>* /*_aidl_return*/) {
return ::ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus BluetoothChannelSounding::getSupportedSessionTypes(
std::optional<std::vector<SessionType>>* _aidl_return) {
std::vector<SessionType> 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<IBluetoothChannelSoundingSessionCallback>&
in_callback,
std::shared_ptr<IBluetoothChannelSoundingSession>* _aidl_return) {
if (in_callback == nullptr) {
return ndk::ScopedAStatus::fromExceptionCodeWithMessage(
EX_ILLEGAL_ARGUMENT, "Invalid nullptr callback");
}
std::shared_ptr<BluetoothChannelSoundingSession> session = nullptr;
session = ndk::SharedRefBase::make<BluetoothChannelSoundingSession>(
in_callback, Reason::LOCAL_STACK_REQUEST);
*_aidl_return = session;
return ::ndk::ScopedAStatus::ok();
}
} // namespace aidl::android::hardware::bluetooth::ranging::impl

View file

@ -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 <aidl/android/hardware/bluetooth/ranging/BnBluetoothChannelSounding.h>
#include <vector>
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<std::vector<std::optional<VendorSpecificData>>>*
_aidl_return) override;
ndk::ScopedAStatus getSupportedSessionTypes(
std::optional<std::vector<SessionType>>* _aidl_return) override;
ndk::ScopedAStatus getMaxSupportedCsSecurityLevel(
CsSecurityLevel* _aidl_return) override;
ndk::ScopedAStatus openSession(
const BluetoothChannelSoundingParameters& in_params,
const std::shared_ptr<IBluetoothChannelSoundingSessionCallback>&
in_callback,
std::shared_ptr<IBluetoothChannelSoundingSession>* _aidl_return) override;
};
} // namespace aidl::android::hardware::bluetooth::ranging::impl

View file

@ -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<IBluetoothChannelSoundingSessionCallback> callback,
Reason reason) {
callback_ = callback;
callback_->onOpened(reason);
}
ndk::ScopedAStatus BluetoothChannelSoundingSession::getVendorSpecificReplies(
std::optional<
std::vector<std::optional<VendorSpecificData>>>* /*_aidl_return*/) {
return ::ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus BluetoothChannelSoundingSession::getSupportedResultTypes(
std::vector<ResultType>* _aidl_return) {
std::vector<ResultType> 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

View file

@ -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 <aidl/android/hardware/bluetooth/ranging/BnBluetoothChannelSoundingSession.h>
#include <aidl/android/hardware/bluetooth/ranging/IBluetoothChannelSoundingSessionCallback.h>
#include <vector>
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<IBluetoothChannelSoundingSessionCallback> callback,
Reason reason);
ndk::ScopedAStatus getVendorSpecificReplies(
std::optional<std::vector<std::optional<VendorSpecificData>>>*
_aidl_return) override;
ndk::ScopedAStatus getSupportedResultTypes(
std::vector<ResultType>* _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<IBluetoothChannelSoundingSessionCallback> callback_;
};
} // namespace aidl::android::hardware::bluetooth::ranging::impl

View file

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

View file

@ -0,0 +1,7 @@
<manifest version="1.0" type="device">
<hal format="aidl">
<name>android.hardware.bluetooth.ranging</name>
<version>1</version>
<fqname>IBluetoothChannelSounding/default</fqname>
</hal>
</manifest>

View file

@ -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 <android/binder_manager.h>
#include <android/binder_process.h>
#include <utils/Log.h>
#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<BluetoothChannelSounding> service =
ndk::SharedRefBase::make<BluetoothChannelSounding>();
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;
}