Merge "Remove the default implementation for NFC aidl HAL" into main
This commit is contained in:
commit
4372ea1bd1
9 changed files with 0 additions and 466 deletions
|
@ -1,33 +0,0 @@
|
|||
package {
|
||||
default_team: "trendy_team_fwk_nfc",
|
||||
// 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.nfc-service.example",
|
||||
relative_install_path: "hw",
|
||||
init_rc: ["nfc-service-example.rc"],
|
||||
vintf_fragments: ["nfc-service-example.xml"],
|
||||
vendor: true,
|
||||
cflags: [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
],
|
||||
shared_libs: [
|
||||
"libbase",
|
||||
"liblog",
|
||||
"libutils",
|
||||
"libbinder_ndk",
|
||||
"android.hardware.nfc-V1-ndk",
|
||||
],
|
||||
srcs: [
|
||||
"main.cpp",
|
||||
"Nfc.cpp",
|
||||
"Vendor_hal_api.cpp",
|
||||
],
|
||||
}
|
|
@ -1,160 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 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 "Nfc.h"
|
||||
|
||||
#include <android-base/logging.h>
|
||||
|
||||
#include "Vendor_hal_api.h"
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace nfc {
|
||||
|
||||
std::shared_ptr<INfcClientCallback> Nfc::mCallback = nullptr;
|
||||
AIBinder_DeathRecipient* clientDeathRecipient = nullptr;
|
||||
|
||||
void OnDeath(void* cookie) {
|
||||
if (Nfc::mCallback != nullptr && !AIBinder_isAlive(Nfc::mCallback->asBinder().get())) {
|
||||
LOG(INFO) << __func__ << " Nfc service has died";
|
||||
Nfc* nfc = static_cast<Nfc*>(cookie);
|
||||
nfc->close(NfcCloseType::DISABLE);
|
||||
}
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus Nfc::open(const std::shared_ptr<INfcClientCallback>& clientCallback) {
|
||||
LOG(INFO) << "open";
|
||||
if (clientCallback == nullptr) {
|
||||
LOG(INFO) << "Nfc::open null callback";
|
||||
return ndk::ScopedAStatus::fromServiceSpecificError(
|
||||
static_cast<int32_t>(NfcStatus::FAILED));
|
||||
}
|
||||
Nfc::mCallback = clientCallback;
|
||||
|
||||
clientDeathRecipient = AIBinder_DeathRecipient_new(OnDeath);
|
||||
auto linkRet = AIBinder_linkToDeath(clientCallback->asBinder().get(), clientDeathRecipient,
|
||||
this /* cookie */);
|
||||
if (linkRet != STATUS_OK) {
|
||||
LOG(ERROR) << __func__ << ": linkToDeath failed: " << linkRet;
|
||||
// Just ignore the error.
|
||||
}
|
||||
|
||||
int ret = Vendor_hal_open(eventCallback, dataCallback);
|
||||
return ret == 0 ? ndk::ScopedAStatus::ok()
|
||||
: ndk::ScopedAStatus::fromServiceSpecificError(
|
||||
static_cast<int32_t>(NfcStatus::FAILED));
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus Nfc::close(NfcCloseType type) {
|
||||
LOG(INFO) << "close";
|
||||
if (Nfc::mCallback == nullptr) {
|
||||
LOG(ERROR) << __func__ << "mCallback null";
|
||||
return ndk::ScopedAStatus::fromServiceSpecificError(
|
||||
static_cast<int32_t>(NfcStatus::FAILED));
|
||||
}
|
||||
int ret = 0;
|
||||
if (type == NfcCloseType::HOST_SWITCHED_OFF) {
|
||||
ret = Vendor_hal_close_off();
|
||||
} else {
|
||||
ret = Vendor_hal_close();
|
||||
}
|
||||
Nfc::mCallback = nullptr;
|
||||
AIBinder_DeathRecipient_delete(clientDeathRecipient);
|
||||
clientDeathRecipient = nullptr;
|
||||
return ret == 0 ? ndk::ScopedAStatus::ok()
|
||||
: ndk::ScopedAStatus::fromServiceSpecificError(
|
||||
static_cast<int32_t>(NfcStatus::FAILED));
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus Nfc::coreInitialized() {
|
||||
LOG(INFO) << "coreInitialized";
|
||||
if (Nfc::mCallback == nullptr) {
|
||||
LOG(ERROR) << __func__ << "mCallback null";
|
||||
return ndk::ScopedAStatus::fromServiceSpecificError(
|
||||
static_cast<int32_t>(NfcStatus::FAILED));
|
||||
}
|
||||
int ret = Vendor_hal_core_initialized();
|
||||
|
||||
return ret == 0 ? ndk::ScopedAStatus::ok()
|
||||
: ndk::ScopedAStatus::fromServiceSpecificError(
|
||||
static_cast<int32_t>(NfcStatus::FAILED));
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus Nfc::factoryReset() {
|
||||
LOG(INFO) << "factoryReset";
|
||||
Vendor_hal_factoryReset();
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus Nfc::getConfig(NfcConfig* _aidl_return) {
|
||||
LOG(INFO) << "getConfig";
|
||||
NfcConfig nfcVendorConfig;
|
||||
Vendor_hal_getConfig(nfcVendorConfig);
|
||||
|
||||
*_aidl_return = nfcVendorConfig;
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus Nfc::powerCycle() {
|
||||
LOG(INFO) << "powerCycle";
|
||||
if (Nfc::mCallback == nullptr) {
|
||||
LOG(ERROR) << __func__ << "mCallback null";
|
||||
return ndk::ScopedAStatus::fromServiceSpecificError(
|
||||
static_cast<int32_t>(NfcStatus::FAILED));
|
||||
}
|
||||
return Vendor_hal_power_cycle() ? ndk::ScopedAStatus::fromServiceSpecificError(
|
||||
static_cast<int32_t>(NfcStatus::FAILED))
|
||||
: ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus Nfc::preDiscover() {
|
||||
LOG(INFO) << "preDiscover";
|
||||
if (Nfc::mCallback == nullptr) {
|
||||
LOG(ERROR) << __func__ << "mCallback null";
|
||||
return ndk::ScopedAStatus::fromServiceSpecificError(
|
||||
static_cast<int32_t>(NfcStatus::FAILED));
|
||||
}
|
||||
return Vendor_hal_pre_discover() ? ndk::ScopedAStatus::fromServiceSpecificError(
|
||||
static_cast<int32_t>(NfcStatus::FAILED))
|
||||
: ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus Nfc::write(const std::vector<uint8_t>& data, int32_t* _aidl_return) {
|
||||
LOG(INFO) << "write";
|
||||
if (Nfc::mCallback == nullptr) {
|
||||
LOG(ERROR) << __func__ << "mCallback null";
|
||||
return ndk::ScopedAStatus::fromServiceSpecificError(
|
||||
static_cast<int32_t>(NfcStatus::FAILED));
|
||||
}
|
||||
*_aidl_return = Vendor_hal_write(data.size(), &data[0]);
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
::ndk::ScopedAStatus Nfc::setEnableVerboseLogging(bool enable) {
|
||||
LOG(INFO) << "setVerboseLogging";
|
||||
Vendor_hal_setVerboseLogging(enable);
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus Nfc::isVerboseLoggingEnabled(bool* _aidl_return) {
|
||||
*_aidl_return = Vendor_hal_getVerboseLogging();
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
} // namespace nfc
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <aidl/android/hardware/nfc/BnNfc.h>
|
||||
#include <aidl/android/hardware/nfc/INfcClientCallback.h>
|
||||
#include <android-base/logging.h>
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace nfc {
|
||||
|
||||
using ::aidl::android::hardware::nfc::NfcCloseType;
|
||||
using ::aidl::android::hardware::nfc::NfcConfig;
|
||||
using ::aidl::android::hardware::nfc::NfcStatus;
|
||||
|
||||
// Default implementation that reports no support NFC.
|
||||
struct Nfc : public BnNfc {
|
||||
public:
|
||||
Nfc() = default;
|
||||
|
||||
::ndk::ScopedAStatus open(const std::shared_ptr<INfcClientCallback>& clientCallback) override;
|
||||
::ndk::ScopedAStatus close(NfcCloseType type) override;
|
||||
::ndk::ScopedAStatus coreInitialized() override;
|
||||
::ndk::ScopedAStatus factoryReset() override;
|
||||
::ndk::ScopedAStatus getConfig(NfcConfig* _aidl_return) override;
|
||||
::ndk::ScopedAStatus powerCycle() override;
|
||||
::ndk::ScopedAStatus preDiscover() override;
|
||||
::ndk::ScopedAStatus write(const std::vector<uint8_t>& data, int32_t* _aidl_return) override;
|
||||
::ndk::ScopedAStatus setEnableVerboseLogging(bool enable) override;
|
||||
::ndk::ScopedAStatus isVerboseLoggingEnabled(bool* _aidl_return) override;
|
||||
|
||||
static void eventCallback(uint8_t event, uint8_t status) {
|
||||
if (mCallback != nullptr) {
|
||||
auto ret = mCallback->sendEvent((NfcEvent)event, (NfcStatus)status);
|
||||
if (!ret.isOk()) {
|
||||
LOG(ERROR) << "Failed to send event!";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void dataCallback(uint16_t data_len, uint8_t* p_data) {
|
||||
std::vector<uint8_t> data(p_data, p_data + data_len);
|
||||
if (mCallback != nullptr) {
|
||||
auto ret = mCallback->sendData(data);
|
||||
if (!ret.isOk()) {
|
||||
LOG(ERROR) << "Failed to send data!";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static std::shared_ptr<INfcClientCallback> mCallback;
|
||||
};
|
||||
|
||||
} // namespace nfc
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
|
@ -1,71 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 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/properties.h>
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "Vendor_hal_api.h"
|
||||
|
||||
bool logging = false;
|
||||
|
||||
int Vendor_hal_open(nfc_stack_callback_t* p_cback, nfc_stack_data_callback_t* p_data_cback) {
|
||||
(void)p_cback;
|
||||
(void)p_data_cback;
|
||||
// nothing to open in this example
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Vendor_hal_write(uint16_t data_len, const uint8_t* p_data) {
|
||||
(void)data_len;
|
||||
(void)p_data;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Vendor_hal_core_initialized() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Vendor_hal_pre_discover() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Vendor_hal_close() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Vendor_hal_close_off() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Vendor_hal_power_cycle() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Vendor_hal_factoryReset() {}
|
||||
|
||||
void Vendor_hal_getConfig(NfcConfig& config) {
|
||||
(void)config;
|
||||
}
|
||||
|
||||
void Vendor_hal_setVerboseLogging(bool enable) {
|
||||
logging = enable;
|
||||
}
|
||||
|
||||
bool Vendor_hal_getVerboseLogging() {
|
||||
return logging;
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 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.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <aidl/android/hardware/nfc/INfc.h>
|
||||
#include <aidl/android/hardware/nfc/NfcConfig.h>
|
||||
#include <aidl/android/hardware/nfc/NfcEvent.h>
|
||||
#include <aidl/android/hardware/nfc/NfcStatus.h>
|
||||
#include <aidl/android/hardware/nfc/PresenceCheckAlgorithm.h>
|
||||
#include <aidl/android/hardware/nfc/ProtocolDiscoveryConfig.h>
|
||||
#include "hardware_nfc.h"
|
||||
|
||||
using aidl::android::hardware::nfc::NfcConfig;
|
||||
using aidl::android::hardware::nfc::NfcEvent;
|
||||
using aidl::android::hardware::nfc::NfcStatus;
|
||||
using aidl::android::hardware::nfc::PresenceCheckAlgorithm;
|
||||
using aidl::android::hardware::nfc::ProtocolDiscoveryConfig;
|
||||
|
||||
int Vendor_hal_open(nfc_stack_callback_t* p_cback, nfc_stack_data_callback_t* p_data_cback);
|
||||
int Vendor_hal_write(uint16_t data_len, const uint8_t* p_data);
|
||||
|
||||
int Vendor_hal_core_initialized();
|
||||
|
||||
int Vendor_hal_pre_discover();
|
||||
|
||||
int Vendor_hal_close();
|
||||
|
||||
int Vendor_hal_close_off();
|
||||
|
||||
int Vendor_hal_power_cycle();
|
||||
|
||||
void Vendor_hal_factoryReset();
|
||||
|
||||
void Vendor_hal_getConfig(NfcConfig& config);
|
||||
|
||||
void Vendor_hal_setVerboseLogging(bool enable);
|
||||
|
||||
bool Vendor_hal_getVerboseLogging();
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 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.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
typedef uint8_t nfc_event_t;
|
||||
typedef uint8_t nfc_status_t;
|
||||
|
||||
/*
|
||||
* The callback passed in from the NFC stack that the HAL
|
||||
* can use to pass events back to the stack.
|
||||
*/
|
||||
typedef void(nfc_stack_callback_t)(nfc_event_t event, nfc_status_t event_status);
|
||||
|
||||
/*
|
||||
* The callback passed in from the NFC stack that the HAL
|
||||
* can use to pass incomming data to the stack.
|
||||
*/
|
||||
typedef void(nfc_stack_data_callback_t)(uint16_t data_len, uint8_t* p_data);
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 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 "Nfc.h"
|
||||
using ::aidl::android::hardware::nfc::Nfc;
|
||||
|
||||
int main() {
|
||||
LOG(INFO) << "NFC HAL starting up";
|
||||
if (!ABinderProcess_setThreadPoolMaxThreadCount(1)) {
|
||||
LOG(INFO) << "failed to set thread pool max thread count";
|
||||
return 1;
|
||||
}
|
||||
std::shared_ptr<Nfc> nfc_service = ndk::SharedRefBase::make<Nfc>();
|
||||
|
||||
const std::string instance = std::string() + Nfc::descriptor + "/default";
|
||||
binder_status_t status =
|
||||
AServiceManager_addService(nfc_service->asBinder().get(), instance.c_str());
|
||||
CHECK(status == STATUS_OK);
|
||||
ABinderProcess_joinThreadPool();
|
||||
return 0;
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
service nfc_hal_service /vendor/bin/hw/android.hardware.nfc-service.st
|
||||
class hal
|
||||
user nfc
|
||||
group nfc
|
|
@ -1,6 +0,0 @@
|
|||
<manifest version="1.0" type="device">
|
||||
<hal format="aidl">
|
||||
<name>android.hardware.nfc</name>
|
||||
<fqname>INfc/default</fqname>
|
||||
</hal>
|
||||
</manifest>
|
Loading…
Reference in a new issue