• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <aidl/android/hardware/nfc/BnNfc.h>
20 #include <aidl/android/hardware/nfc/INfcClientCallback.h>
21 #include <android-base/logging.h>
22 namespace aidl {
23 namespace android {
24 namespace hardware {
25 namespace nfc {
26 
27 using ::aidl::android::hardware::nfc::NfcCloseType;
28 using ::aidl::android::hardware::nfc::NfcConfig;
29 using ::aidl::android::hardware::nfc::NfcStatus;
30 
31 // Default implementation that reports no support NFC.
32 struct Nfc : public BnNfc {
33  public:
34   Nfc() = default;
35 
36   ::ndk::ScopedAStatus open(
37       const std::shared_ptr<INfcClientCallback>& clientCallback) override;
38   ::ndk::ScopedAStatus close(NfcCloseType type) override;
39   ::ndk::ScopedAStatus coreInitialized() override;
40   ::ndk::ScopedAStatus factoryReset() override;
41   ::ndk::ScopedAStatus getConfig(NfcConfig* _aidl_return) override;
42   ::ndk::ScopedAStatus powerCycle() override;
43   ::ndk::ScopedAStatus preDiscover() override;
44   ::ndk::ScopedAStatus write(const std::vector<uint8_t>& data,
45                              int32_t* _aidl_return) override;
46   ::ndk::ScopedAStatus setEnableVerboseLogging(bool enable) override;
47   ::ndk::ScopedAStatus isVerboseLoggingEnabled(bool* _aidl_return) override;
eventCallbackNfc48   static void eventCallback(uint8_t event, uint8_t status) {
49     if (mCallback != nullptr) {
50       auto ret = mCallback->sendEvent((NfcEvent)event, (NfcStatus)status);
51       if (!ret.isOk()) {
52         LOG(ERROR) << "Failed to send event!";
53       }
54     }
55   }
56 
dataCallbackNfc57   static void dataCallback(uint16_t data_len, uint8_t* p_data) {
58     std::vector<uint8_t> data(p_data, p_data + data_len);
59     if (mCallback != nullptr) {
60       auto ret = mCallback->sendData(data);
61       if (!ret.isOk()) {
62         LOG(ERROR) << "Failed to send data!";
63       }
64     }
65   }
66   static std::shared_ptr<INfcClientCallback> mCallback;
67 };
68 
69 }  // namespace nfc
70 }  // namespace hardware
71 }  // namespace android
72 }  // namespace aidl
73