diff options
| author | Rashed Abdel-Tawab <rashed@linux.com> | 2017-09-22 19:21:00 -0400 |
|---|---|---|
| committer | Rashed Abdel-Tawab <rashed@linux.com> | 2017-10-01 13:58:46 -0400 |
| commit | c75904f1ab1b314792eaf025ff4f7cdd85bb6c6a (patch) | |
| tree | 667c8dc174d9ac5ec09644cb904850e99defa660 | |
| parent | 1be4dac20757d8c89ec87411df4b7061b3ce73de (diff) | |
| download | android_hardware_lineage_interfaces-c75904f1ab1b314792eaf025ff4f7cdd85bb6c6a.tar.gz android_hardware_lineage_interfaces-c75904f1ab1b314792eaf025ff4f7cdd85bb6c6a.tar.bz2 android_hardware_lineage_interfaces-c75904f1ab1b314792eaf025ff4f7cdd85bb6c6a.zip | |
lineage/interfaces: Fork Nfc HIDL impl
Identical to 36193658d22841d4aec1c9ce1353580cac6ac43e
Change-Id: I1d7e21e36b99f71115fdc6e8df37c3d137e29c28
| -rw-r--r-- | nfc/1.0/Android.bp | 18 | ||||
| -rw-r--r-- | nfc/1.0/Nfc.cpp | 107 | ||||
| -rw-r--r-- | nfc/1.0/Nfc.h | 76 | ||||
| -rw-r--r-- | nfc/Android.bp | 3 |
4 files changed, 204 insertions, 0 deletions
diff --git a/nfc/1.0/Android.bp b/nfc/1.0/Android.bp new file mode 100644 index 0000000..a157f86 --- /dev/null +++ b/nfc/1.0/Android.bp @@ -0,0 +1,18 @@ +cc_library_shared { + name: "android.hardware.nfc@1.0-impl", + defaults: ["hidl_defaults"], + relative_install_path: "hw", + proprietary: true, + srcs: ["Nfc.cpp"], + shared_libs: [ + "liblog", + "libcutils", + "libhardware", + "libbase", + "libcutils", + "libutils", + "libhidlbase", + "libhidltransport", + "android.hardware.nfc@1.0", + ], +} diff --git a/nfc/1.0/Nfc.cpp b/nfc/1.0/Nfc.cpp new file mode 100644 index 0000000..d337a36 --- /dev/null +++ b/nfc/1.0/Nfc.cpp @@ -0,0 +1,107 @@ +#define LOG_TAG "android.hardware.nfc@1.0-impl" + +#include <log/log.h> + +#include <hardware/hardware.h> +#include <hardware/nfc.h> +#include "Nfc.h" + +namespace android { +namespace hardware { +namespace nfc { +namespace V1_0 { +namespace implementation { + +sp<INfcClientCallback> Nfc::mCallback = nullptr; + +Nfc::Nfc(nfc_nci_device_t* device) : mDevice(device), + mDeathRecipient(new NfcDeathRecipient(this)) { +} + +// Methods from ::android::hardware::nfc::V1_0::INfc follow. +::android::hardware::Return<NfcStatus> Nfc::open(const sp<INfcClientCallback>& clientCallback) { + mCallback = clientCallback; + + if (mDevice == nullptr || mCallback == nullptr) { + return NfcStatus::FAILED; + } + mCallback->linkToDeath(mDeathRecipient, 0 /*cookie*/); + int ret = mDevice->open(mDevice, eventCallback, dataCallback); + return ret == 0 ? NfcStatus::OK : NfcStatus::FAILED; +} + +::android::hardware::Return<uint32_t> Nfc::write(const hidl_vec<uint8_t>& data) { + if (mDevice == nullptr) { + return -1; + } + return mDevice->write(mDevice, data.size(), &data[0]); +} + +::android::hardware::Return<NfcStatus> Nfc::coreInitialized(const hidl_vec<uint8_t>& data) { + hidl_vec<uint8_t> copy = data; + + if (mDevice == nullptr) { + return NfcStatus::FAILED; + } + int ret = mDevice->core_initialized(mDevice, ©[0]); + return ret == 0 ? NfcStatus::OK : NfcStatus::FAILED; +} + +::android::hardware::Return<NfcStatus> Nfc::prediscover() { + if (mDevice == nullptr) { + return NfcStatus::FAILED; + } + return mDevice->pre_discover(mDevice) ? NfcStatus::FAILED : NfcStatus::OK; +} + +::android::hardware::Return<NfcStatus> Nfc::close() { + if (mDevice == nullptr || mCallback == nullptr) { + return NfcStatus::FAILED; + } + mCallback->unlinkToDeath(mDeathRecipient); + return mDevice->close(mDevice) ? NfcStatus::FAILED : NfcStatus::OK; +} + +::android::hardware::Return<NfcStatus> Nfc::controlGranted() { + if (mDevice == nullptr) { + return NfcStatus::FAILED; + } + return mDevice->control_granted(mDevice) ? NfcStatus::FAILED : NfcStatus::OK; +} + +::android::hardware::Return<NfcStatus> Nfc::powerCycle() { + if (mDevice == nullptr) { + return NfcStatus::FAILED; + } + return mDevice->power_cycle(mDevice) ? NfcStatus::FAILED : NfcStatus::OK; +} + + +INfc* HIDL_FETCH_INfc(const char * /*name*/) { + nfc_nci_device_t* nfc_device; + int ret = 0; + const hw_module_t* hw_module = nullptr; + + ret = hw_get_module (NFC_NCI_HARDWARE_MODULE_ID, &hw_module); + if (ret == 0) { + ret = nfc_nci_open (hw_module, &nfc_device); + if (ret != 0) { + ALOGE ("nfc_nci_open failed: %d", ret); + } + } + else + ALOGE ("hw_get_module %s failed: %d", NFC_NCI_HARDWARE_MODULE_ID, 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/Nfc.h b/nfc/1.0/Nfc.h new file mode 100644 index 0000000..d8787fd --- /dev/null +++ b/nfc/1.0/Nfc.h @@ -0,0 +1,76 @@ +#ifndef ANDROID_HARDWARE_NFC_V1_0_NFC_H +#define ANDROID_HARDWARE_NFC_V1_0_NFC_H + +#include <android/hardware/nfc/1.0/INfc.h> +#include <hidl/Status.h> +#include <hardware/hardware.h> +#include <hardware/nfc.h> +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::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +struct NfcDeathRecipient : hidl_death_recipient { + NfcDeathRecipient(const sp<INfc> nfc) : mNfc(nfc) { + } + + virtual void serviceDied(uint64_t /*cookie*/, const wp<::android::hidl::base::V1_0::IBase>& /*who*/) { + mNfc->close(); + } + sp<INfc> mNfc; +}; + +struct Nfc : public INfc { + Nfc(nfc_nci_device_t* device); + ::android::hardware::Return<NfcStatus> open(const sp<INfcClientCallback>& clientCallback) override; + ::android::hardware::Return<uint32_t> write(const hidl_vec<uint8_t>& data) override; + ::android::hardware::Return<NfcStatus> coreInitialized(const hidl_vec<uint8_t>& data) override; + ::android::hardware::Return<NfcStatus> prediscover() override; + ::android::hardware::Return<NfcStatus> close() override; + ::android::hardware::Return<NfcStatus> controlGranted() override; + ::android::hardware::Return<NfcStatus> powerCycle() override; + + static void eventCallback(uint8_t event, uint8_t status) { + if (mCallback != nullptr) { + auto ret = mCallback->sendEvent( + (::android::hardware::nfc::V1_0::NfcEvent) event, + (::android::hardware::nfc::V1_0::NfcStatus) status); + if (!ret.isOk()) { + ALOGW("Failed to call back into NFC process."); + } + } + } + static void dataCallback(uint16_t data_len, uint8_t* p_data) { + hidl_vec<uint8_t> data; + data.setToExternal(p_data, data_len); + if (mCallback != nullptr) { + auto ret = mCallback->sendData(data); + if (!ret.isOk()) { + ALOGW("Failed to call back into NFC process."); + } + } + } + private: + static sp<INfcClientCallback> mCallback; + const nfc_nci_device_t* mDevice; + sp<NfcDeathRecipient> mDeathRecipient; +}; + +extern "C" INfc* HIDL_FETCH_INfc(const char* name); + +} // namespace implementation +} // namespace V1_0 +} // namespace nfc +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_NFC_V1_0_NFC_H diff --git a/nfc/Android.bp b/nfc/Android.bp new file mode 100644 index 0000000..58a4473 --- /dev/null +++ b/nfc/Android.bp @@ -0,0 +1,3 @@ +subdirs = [ + "1.0", +] |
