From 678fa1f4560e79d5fee0d425b0d010a067cdcc9e Mon Sep 17 00:00:00 2001 From: Iliyan Malchev Date: Thu, 22 Sep 2016 15:53:53 -0700 Subject: [PATCH] android.hardware.nfc@1.0: provide a default implementation b/31524912 Test: pass Change-Id: Id9d34f62f4a2b92bdc3beb3e62c89c82743c0ca0 Signed-off-by: Iliyan Malchev --- nfc/1.0/default/Android.mk | 8 ++++ nfc/1.0/default/Nfc.cpp | 76 ++++++++++++++++++++++++++++++++++++++ nfc/1.0/default/Nfc.h | 60 ++++++++++++++++++++++++++++++ 3 files changed, 144 insertions(+) create mode 100644 nfc/1.0/default/Android.mk create mode 100644 nfc/1.0/default/Nfc.cpp create mode 100644 nfc/1.0/default/Nfc.h diff --git a/nfc/1.0/default/Android.mk b/nfc/1.0/default/Android.mk new file mode 100644 index 0000000000..afd0cd64b0 --- /dev/null +++ b/nfc/1.0/default/Android.mk @@ -0,0 +1,8 @@ +LOCAL_PATH:= $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_MODULE := android.hardware.nfc@1.0-impl +LOCAL_MODULE_RELATIVE_PATH := hw +LOCAL_SRC_FILES := Nfc.cpp +LOCAL_SHARED_LIBRARIES := liblog libcutils libhardware libhwbinder libbase libcutils libutils libhidl android.hardware.nfc@1.0 +include $(BUILD_SHARED_LIBRARY) diff --git a/nfc/1.0/default/Nfc.cpp b/nfc/1.0/default/Nfc.cpp new file mode 100644 index 0000000000..9023eccdf2 --- /dev/null +++ b/nfc/1.0/default/Nfc.cpp @@ -0,0 +1,76 @@ +#include +#include +#include "Nfc.h" + +namespace android { +namespace hardware { +namespace nfc { +namespace V1_0 { +namespace implementation { + +sp Nfc::mCallback = NULL; + +Nfc::Nfc(nfc_nci_device_t* device) : mDevice(device) { +} + +// Methods from ::android::hardware::nfc::V1_0::INfc follow. +::android::hardware::Return Nfc::open(const sp& clientCallback) { + mCallback = clientCallback; + return mDevice->open(mDevice, event_callback, data_callback); +} + +::android::hardware::Return Nfc::write(const nfc_data_t& data) { + return mDevice->write(mDevice, data.data.size(), &data.data[0]); +} + +::android::hardware::Return Nfc::core_initialized(const hidl_vec& data) { + hidl_vec copy = data; + return mDevice->core_initialized(mDevice, ©[0]); +} + +::android::hardware::Return Nfc::pre_discover() { + return mDevice->pre_discover(mDevice); +} + +::android::hardware::Return Nfc::close() { + return mDevice->close(mDevice); +} + +::android::hardware::Return Nfc::control_granted() { + return mDevice->control_granted(mDevice); +} + +::android::hardware::Return Nfc::power_cycle() { + return mDevice->power_cycle(mDevice); +} + + +INfc* HIDL_FETCH_INfc(const char *hal) { + nfc_nci_device_t* nfc_device; + int ret = 0; + const hw_module_t* hw_module = NULL; + + ret = hw_get_module (hal, &hw_module); + if (ret == 0) + { + ret = nfc_nci_open (hw_module, &nfc_device); + if (ret != 0) { + ALOGE ("nfc_nci_open %s failed: %d", hal, ret); + } + } + else + ALOGE ("hw_get_module %s failed: %d", hal, ret); + + if (ret == 0) { + return new Nfc(nfc_device); + } else { + ALOGE("Passthrough failed to load legacy HAL."); + return nullptr; + } +} + +} // namespace implementation +} // namespace V1_0 +} // namespace nfc +} // namespace hardware +} // namespace android diff --git a/nfc/1.0/default/Nfc.h b/nfc/1.0/default/Nfc.h new file mode 100644 index 0000000000..98cd57e8eb --- /dev/null +++ b/nfc/1.0/default/Nfc.h @@ -0,0 +1,60 @@ +#ifndef HIDL_GENERATED_android_hardware_nfc_V1_0_Nfc_H_ +#define HIDL_GENERATED_android_hardware_nfc_V1_0_Nfc_H_ + +#include +#include +#include +#include +namespace android { +namespace hardware { +namespace nfc { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::nfc::V1_0::INfc; +using ::android::hardware::nfc::V1_0::INfcClientCallback; +using ::android::hardware::nfc::V1_0::nfc_data_t; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +struct Nfc : public INfc { + Nfc(nfc_nci_device_t* device); + ::android::hardware::Return open(const sp& clientCallback) override; + ::android::hardware::Return write(const nfc_data_t& data) override; + ::android::hardware::Return core_initialized(const hidl_vec& data) override; + ::android::hardware::Return pre_discover() override; + ::android::hardware::Return close() override; + ::android::hardware::Return control_granted() override; + ::android::hardware::Return power_cycle() override; + + static void event_callback(uint8_t event, uint8_t status) { + if (mCallback != nullptr) { + mCallback->sendEvent( + (::android::hardware::nfc::V1_0::nfc_event_t) event, + (::android::hardware::nfc::V1_0::nfc_status_t) status); + } + } + static void data_callback(uint16_t data_len, uint8_t* p_data) { + nfc_data_t data; + data.data.setToExternal(p_data, data_len); + if (mCallback != nullptr) { + mCallback->sendData(data); + } + } + private: + static sp mCallback; + const nfc_nci_device_t* mDevice; +}; + +extern "C" INfc* HIDL_FETCH_INfc(const char* name); + +} // namespace implementation +} // namespace V1_0 +} // namespace nfc +} // namespace hardware +} // namespace android + +#endif // HIDL_GENERATED_android_hardware_nfc_V1_0_Nfc_H_