• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef ANDROID_HARDWARE_NFC_V1_2_NFC_H
2 #define ANDROID_HARDWARE_NFC_V1_2_NFC_H
3 
4 #include <android/hardware/nfc/1.2/INfc.h>
5 #include <android/hardware/nfc/1.2/types.h>
6 #include <hidl/MQDescriptor.h>
7 #include <hidl/Status.h>
8 #include <log/log.h>
9 
10 namespace android {
11 namespace hardware {
12 namespace nfc {
13 namespace V1_2 {
14 namespace implementation {
15 
16 using ::android::sp;
17 using ::android::hardware::hidl_array;
18 using ::android::hardware::hidl_memory;
19 using ::android::hardware::hidl_string;
20 using ::android::hardware::hidl_vec;
21 using ::android::hardware::Return;
22 using ::android::hardware::Void;
23 using ::android::hardware::nfc::V1_2::INfc;
24 using ::android::hidl::base::V1_0::IBase;
25 
26 struct Nfc : public V1_2::INfc, public hidl_death_recipient {
27  public:
28   // Methods from ::android::hardware::nfc::V1_0::INfc follow.
29   Return<V1_0::NfcStatus> open(
30       const sp<V1_0::INfcClientCallback>& clientCallback) override;
31   Return<V1_0::NfcStatus> open_1_1(
32       const sp<V1_1::INfcClientCallback>& clientCallback) override;
33   Return<uint32_t> write(const hidl_vec<uint8_t>& data) override;
34   Return<V1_0::NfcStatus> coreInitialized(
35       const hidl_vec<uint8_t>& data) override;
36   Return<V1_0::NfcStatus> prediscover() override;
37   Return<V1_0::NfcStatus> close() override;
38   Return<V1_0::NfcStatus> controlGranted() override;
39   Return<V1_0::NfcStatus> powerCycle() override;
40 
41   // Methods from ::android::hardware::nfc::V1_1::INfc follow.
42   Return<void> factoryReset() override;
43   Return<V1_0::NfcStatus> closeForPowerOffCase() override;
44   Return<void> getConfig(getConfig_cb config) override;
45   Return<void> getConfig_1_2(getConfig_1_2_cb config) override;
46 
eventCallbackNfc47   static void eventCallback(uint8_t event, uint8_t status) {
48     if (mCallbackV1_1 != nullptr) {
49       auto ret = mCallbackV1_1->sendEvent_1_1((V1_1::NfcEvent)event,
50                                               (V1_0::NfcStatus)status);
51       if (!ret.isOk()) {
52         ALOGW("failed to send event!!!");
53       }
54     } else if (mCallbackV1_0 != nullptr) {
55       auto ret = mCallbackV1_0->sendEvent((V1_0::NfcEvent)event,
56                                           (V1_0::NfcStatus)status);
57       if (!ret.isOk()) {
58         ALOGE("failed to send event!!!");
59       }
60     }
61   }
62 
dataCallbackNfc63   static void dataCallback(uint16_t data_len, uint8_t* p_data) {
64     hidl_vec<uint8_t> data;
65     data.setToExternal(p_data, data_len);
66     if (mCallbackV1_1 != nullptr) {
67       auto ret = mCallbackV1_1->sendData(data);
68       if (!ret.isOk()) {
69         ALOGW("failed to send data!!!");
70       }
71     } else if (mCallbackV1_0 != nullptr) {
72       auto ret = mCallbackV1_0->sendData(data);
73       if (!ret.isOk()) {
74         ALOGE("failed to send data!!!");
75       }
76     }
77   }
78 
serviceDiedNfc79   virtual void serviceDied(uint64_t /*cookie*/, const wp<IBase>& /*who*/) {
80     close();
81   }
82 
83  private:
84   static sp<V1_1::INfcClientCallback> mCallbackV1_1;
85   static sp<V1_0::INfcClientCallback> mCallbackV1_0;
86 };
87 }  // namespace implementation
88 }  // namespace V1_2
89 }  // namespace nfc
90 }  // namespace hardware
91 }  // namespace android
92 
93 #endif  // ANDROID_HARDWARE_NFC_V1_2_NFC_H
94