uwb: Default HAL implementation

Skeletal implementation of UWB HAL which will be used for
cuttlefish/reference implementation in the future.

Bug: 195992658
Test: Manual verification of HAL booting up and handling HAL
API calls.

Change-Id: I894b7aef893ff2ed4f287f72471326b5211245c3
This commit is contained in:
Roshan Pius
2021-08-27 12:55:02 -07:00
parent 69176b80cf
commit 80c3cc61cb
10 changed files with 306 additions and 0 deletions

View File

@@ -23,6 +23,7 @@ aidl_interface {
enabled: true,
},
apex_available: [
"//apex_available:platform",
"com.android.uwb",
],
min_sdk_version: "current",

View File

@@ -0,0 +1,35 @@
package {
// See: http://go/android-license-faq
// A large-scale-change added 'default_applicable_licenses' to import
// all of the 'license_kinds' from "hardware_interfaces_license"
// to get the below license kinds:
// SPDX-license-identifier-Apache-2.0
default_applicable_licenses: ["hardware_interfaces_license"],
}
cc_binary {
name: "android.hardware.uwb-service",
relative_install_path: "hw",
init_rc: ["uwb-service.rc"],
vintf_fragments: ["uwb-service.xml"],
vendor: true,
cflags: [
"-Wall",
"-Wextra",
"-g",
],
shared_libs: [
"liblog",
"libbinder_ndk",
],
static_libs: [
"libbase",
"libutils",
"android.hardware.uwb-V1-ndk",
],
srcs: [
"service.cpp",
"uwb.cpp",
"uwb_chip.cpp",
],
}

2
uwb/aidl/default/OWNERS Normal file
View File

@@ -0,0 +1,2 @@
# Bug component: 1042770
include platform/packages/modules/Uwb:/OWNERS

View File

@@ -0,0 +1,42 @@
/*
* Copyright 2021, 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 <android-base/logging.h>
#include <android/binder_manager.h>
#include <android/binder_process.h>
#include <utils/StrongPointer.h>
#include "uwb.h"
using ::aidl::android::hardware::uwb::IUwb;
using ::android::sp;
using ::android::base::InitLogging;
using ::android::base::StderrLogger;
using ::android::hardware::uwb::impl::Uwb;
int main(int /*argc*/, char* argv[]) {
InitLogging(argv, StderrLogger);
LOG(INFO) << "UWB HAL starting up";
ABinderProcess_setThreadPoolMaxThreadCount(0);
std::shared_ptr<IUwb> uwb = ndk::SharedRefBase::make<Uwb>();
const std::string instance = std::string() + IUwb::descriptor + "/default";
binder_status_t status = AServiceManager_addService(uwb->asBinder().get(), instance.c_str());
CHECK(status == STATUS_OK);
ABinderProcess_joinThreadPool();
return EXIT_FAILURE; // should not reach
}

View File

@@ -0,0 +1,3 @@
service vendor.uwb_hal /vendor/bin/hw/android.hardware.uwb-service
class hal
user uwb

View File

@@ -0,0 +1,10 @@
<manifest version="1.0" type="device">
<hal format="aidl">
<name>android.hardware.uwb</name>
<version>1</version>
<interface>
<name>IUwb</name>
<instance>default</instance>
</interface>
</hal>
</manifest>

55
uwb/aidl/default/uwb.cpp Normal file
View File

@@ -0,0 +1,55 @@
/*
* Copyright 2021, 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 <android-base/logging.h>
#include "uwb.h"
namespace {
static constexpr char kDefaultChipName[] = "default";
} // namespace
namespace android {
namespace hardware {
namespace uwb {
namespace impl {
using namespace ::aidl::android::hardware::uwb;
// The default implementation of the HAL assumes 1 chip on the device.
Uwb::Uwb() : chips_({{kDefaultChipName, ndk::SharedRefBase::make<UwbChip>(kDefaultChipName)}}) {}
Uwb::~Uwb() {}
::ndk::ScopedAStatus Uwb::getChips(std::vector<std::string>* names) {
for (const auto& chip : chips_) {
names->push_back(chip.first);
}
return ndk::ScopedAStatus::ok();
}
::ndk::ScopedAStatus Uwb::getChip(const std::string& name, std::shared_ptr<IUwbChip>* chip) {
const auto chip_found = chips_.find(name);
if (chip_found == chips_.end()) {
LOG(ERROR) << "Unknown chip name" << name;
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
}
*chip = chip_found->second;
return ndk::ScopedAStatus::ok();
}
} // namespace impl
} // namespace uwb
} // namespace hardware
} // namespace android

49
uwb/aidl/default/uwb.h Normal file
View File

@@ -0,0 +1,49 @@
/*
* Copyright 2021, 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.
*/
#ifndef ANDROID_HARDWARE_UWB_UWB
#define ANDROID_HARDWARE_UWB_UWB
#include <map>
#include <vector>
#include <aidl/android/hardware/uwb/BnUwb.h>
#include <aidl/android/hardware/uwb/IUwbChip.h>
#include "uwb_chip.h"
namespace android {
namespace hardware {
namespace uwb {
namespace impl {
using namespace ::aidl::android::hardware::uwb;
// Default implementation mean't to be used on simulator targets.
class Uwb : public BnUwb {
public:
Uwb();
virtual ~Uwb();
::ndk::ScopedAStatus getChips(std::vector<std::string>* names) override;
::ndk::ScopedAStatus getChip(const std::string& name, std::shared_ptr<IUwbChip>* chip) override;
private:
std::map<std::string, std::shared_ptr<UwbChip>> chips_;
};
} // namespace impl
} // namespace uwb
} // namespace hardware
} // namespace android
#endif // ANDROID_HARDWARE_UWB_UWB

View File

@@ -0,0 +1,57 @@
/*
* Copyright 2021, 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 "uwb.h"
namespace android {
namespace hardware {
namespace uwb {
namespace impl {
using namespace ::aidl::android::hardware::uwb;
UwbChip::UwbChip(const std::string& name) : name_(name) {}
UwbChip::~UwbChip() {}
::ndk::ScopedAStatus UwbChip::getName(std::string* name) {
*name = name_;
return ndk::ScopedAStatus::ok();
}
::ndk::ScopedAStatus UwbChip::open(
const std::shared_ptr<IUwbClientCallback>& /* clientCallback */) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
::ndk::ScopedAStatus UwbChip::close() {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
::ndk::ScopedAStatus UwbChip::coreInit() {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
::ndk::ScopedAStatus UwbChip::getSupportedVendorUciVersion(int32_t* /* version */) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
::ndk::ScopedAStatus UwbChip::sendUciMessage(const std::vector<uint8_t>& /* data */,
int32_t* /* bytes_written */) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
} // namespace impl
} // namespace uwb
} // namespace hardware
} // namespace android

View File

@@ -0,0 +1,52 @@
/*
* Copyright 2021, 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.
*/
#ifndef ANDROID_HARDWARE_UWB_UWBCHIP
#define ANDROID_HARDWARE_UWB_UWBCHIP
#include <vector>
#include <aidl/android/hardware/uwb/BnUwbChip.h>
#include <aidl/android/hardware/uwb/IUwbClientCallback.h>
namespace android {
namespace hardware {
namespace uwb {
namespace impl {
using namespace ::aidl::android::hardware::uwb;
// Default implementation mean't to be used on simulator targets.
class UwbChip : public BnUwbChip {
public:
UwbChip(const std::string& name);
virtual ~UwbChip();
::ndk::ScopedAStatus getName(std::string* name) override;
::ndk::ScopedAStatus open(const std::shared_ptr<IUwbClientCallback>& clientCallback) override;
::ndk::ScopedAStatus close() override;
::ndk::ScopedAStatus coreInit() override;
::ndk::ScopedAStatus getSupportedVendorUciVersion(int32_t* version) override;
::ndk::ScopedAStatus sendUciMessage(const std::vector<uint8_t>& data,
int32_t* bytes_written) override;
private:
std::string name_;
};
} // namespace impl
} // namespace uwb
} // namespace hardware
} // namespace android
#endif // ANDROID_HARDWARE_UWB_UWBCHIP