Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 678fa1f4 authored by Iliyan Malchev's avatar Iliyan Malchev
Browse files

android.hardware.nfc@1.0: provide a default implementation



b/31524912
Test: pass

Change-Id: Id9d34f62f4a2b92bdc3beb3e62c89c82743c0ca0
Signed-off-by: default avatarIliyan Malchev <malchev@google.com>
parent 998892cc
Loading
Loading
Loading
Loading
+8 −0
Original line number Original line Diff line number Diff line
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)
+76 −0
Original line number Original line Diff line number Diff line
#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 = NULL;

Nfc::Nfc(nfc_nci_device_t* device) : mDevice(device) {
}

// Methods from ::android::hardware::nfc::V1_0::INfc follow.
::android::hardware::Return<int32_t> Nfc::open(const sp<INfcClientCallback>& clientCallback)  {
    mCallback = clientCallback;
    return mDevice->open(mDevice, event_callback, data_callback);
}

::android::hardware::Return<int32_t> Nfc::write(const nfc_data_t& data)  {
    return mDevice->write(mDevice, data.data.size(), &data.data[0]);
}

::android::hardware::Return<int32_t> Nfc::core_initialized(const hidl_vec<uint8_t>& data)  {
    hidl_vec<uint8_t> copy = data;
    return mDevice->core_initialized(mDevice, &copy[0]);
}

::android::hardware::Return<int32_t> Nfc::pre_discover()  {
    return mDevice->pre_discover(mDevice);
}

::android::hardware::Return<int32_t> Nfc::close()  {
    return mDevice->close(mDevice);
}

::android::hardware::Return<int32_t> Nfc::control_granted()  {
    return mDevice->control_granted(mDevice);
}

::android::hardware::Return<int32_t> 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

nfc/1.0/default/Nfc.h

0 → 100644
+60 −0
Original line number Original line Diff line number Diff line
#ifndef HIDL_GENERATED_android_hardware_nfc_V1_0_Nfc_H_
#define HIDL_GENERATED_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::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<int32_t> open(const sp<INfcClientCallback>& clientCallback)  override;
  ::android::hardware::Return<int32_t> write(const nfc_data_t& data)  override;
  ::android::hardware::Return<int32_t> core_initialized(const hidl_vec<uint8_t>& data)  override;
  ::android::hardware::Return<int32_t> pre_discover()  override;
  ::android::hardware::Return<int32_t> close()  override;
  ::android::hardware::Return<int32_t> control_granted()  override;
  ::android::hardware::Return<int32_t> 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<INfcClientCallback> 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_