1bc2ed2b3Sopenharmony_ci/* 2bc2ed2b3Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 3bc2ed2b3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4bc2ed2b3Sopenharmony_ci * you may not use this file except in compliance with the License. 5bc2ed2b3Sopenharmony_ci * You may obtain a copy of the License at 6bc2ed2b3Sopenharmony_ci * 7bc2ed2b3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8bc2ed2b3Sopenharmony_ci * 9bc2ed2b3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10bc2ed2b3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11bc2ed2b3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12bc2ed2b3Sopenharmony_ci * See the License for the specific language governing permissions and 13bc2ed2b3Sopenharmony_ci * limitations under the License. 14bc2ed2b3Sopenharmony_ci */ 15bc2ed2b3Sopenharmony_ci#ifndef NFC_CONTROLLER_H 16bc2ed2b3Sopenharmony_ci#define NFC_CONTROLLER_H 17bc2ed2b3Sopenharmony_ci 18bc2ed2b3Sopenharmony_ci#include "ndef_msg_callback_stub.h" 19bc2ed2b3Sopenharmony_ci#include "nfc_controller_callback_stub.h" 20bc2ed2b3Sopenharmony_ci#include "nfc_controller_proxy.h" 21bc2ed2b3Sopenharmony_ci#include "nfc_sdk_common.h" 22bc2ed2b3Sopenharmony_ci#include "infc_controller_callback.h" 23bc2ed2b3Sopenharmony_ci#include "infc_controller_service.h" 24bc2ed2b3Sopenharmony_ci#ifdef VENDOR_APPLICATIONS_ENABLED 25bc2ed2b3Sopenharmony_ci#include "iquery_app_info_callback.h" 26bc2ed2b3Sopenharmony_ci#endif 27bc2ed2b3Sopenharmony_ci 28bc2ed2b3Sopenharmony_cinamespace OHOS { 29bc2ed2b3Sopenharmony_cinamespace NFC { 30bc2ed2b3Sopenharmony_cinamespace KITS { 31bc2ed2b3Sopenharmony_cistatic const std::string NFC_SERVICE_NAME = "nfc"; 32bc2ed2b3Sopenharmony_ci 33bc2ed2b3Sopenharmony_ciclass NfcController final { 34bc2ed2b3Sopenharmony_cipublic: 35bc2ed2b3Sopenharmony_ci explicit NfcController(); 36bc2ed2b3Sopenharmony_ci ~NfcController(); 37bc2ed2b3Sopenharmony_ci 38bc2ed2b3Sopenharmony_ci /** 39bc2ed2b3Sopenharmony_ci * @Description Get an object of nfc controller. 40bc2ed2b3Sopenharmony_ci * @param void 41bc2ed2b3Sopenharmony_ci * @return an object of nfc controller 42bc2ed2b3Sopenharmony_ci */ 43bc2ed2b3Sopenharmony_ci static NfcController &GetInstance(); 44bc2ed2b3Sopenharmony_ci /** 45bc2ed2b3Sopenharmony_ci * @Description Turn on Nfc of the device. 46bc2ed2b3Sopenharmony_ci * @param void 47bc2ed2b3Sopenharmony_ci * @return Errorcode of turn on nfc. if return 0, means successful. 48bc2ed2b3Sopenharmony_ci */ 49bc2ed2b3Sopenharmony_ci int TurnOn(); 50bc2ed2b3Sopenharmony_ci /** 51bc2ed2b3Sopenharmony_ci * @Description Turn off Nfc of the device. 52bc2ed2b3Sopenharmony_ci * @param void 53bc2ed2b3Sopenharmony_ci * @return Errorcode of turn off nfc. if return 0, means successful. 54bc2ed2b3Sopenharmony_ci */ 55bc2ed2b3Sopenharmony_ci int TurnOff(); 56bc2ed2b3Sopenharmony_ci /** 57bc2ed2b3Sopenharmony_ci * @Description Get nfc state of device. 58bc2ed2b3Sopenharmony_ci * @param void 59bc2ed2b3Sopenharmony_ci * @return nfc state. 60bc2ed2b3Sopenharmony_ci */ 61bc2ed2b3Sopenharmony_ci int GetNfcState(); 62bc2ed2b3Sopenharmony_ci /** 63bc2ed2b3Sopenharmony_ci * @Checks whether a device supports NFC. 64bc2ed2b3Sopenharmony_ci * @param void 65bc2ed2b3Sopenharmony_ci * @return If the device supports NFC return 1; otherwise return 0. 66bc2ed2b3Sopenharmony_ci */ 67bc2ed2b3Sopenharmony_ci bool IsNfcAvailable(); 68bc2ed2b3Sopenharmony_ci /** 69bc2ed2b3Sopenharmony_ci * @Description Checks whether NFC is enabled. 70bc2ed2b3Sopenharmony_ci * @param isOpen The output for checking nfc is open or not. 71bc2ed2b3Sopenharmony_ci * @return The status code of calling function. 72bc2ed2b3Sopenharmony_ci */ 73bc2ed2b3Sopenharmony_ci int IsNfcOpen(bool &isOpen); 74bc2ed2b3Sopenharmony_ci /** 75bc2ed2b3Sopenharmony_ci * @Description Registers the callback for nfc state changed notification. 76bc2ed2b3Sopenharmony_ci * @param callback the callback to be registered. 77bc2ed2b3Sopenharmony_ci * @param type the type for this callback, it's "nfcStateChange" 78bc2ed2b3Sopenharmony_ci * @return The status code for register operation. 79bc2ed2b3Sopenharmony_ci */ 80bc2ed2b3Sopenharmony_ci ErrorCode RegListener(const sptr<INfcControllerCallback> &callback, const std::string& type); 81bc2ed2b3Sopenharmony_ci /** 82bc2ed2b3Sopenharmony_ci * @Description Unregisters the callback for nfc state changed notification. 83bc2ed2b3Sopenharmony_ci * @param type the type for this callback, it's "nfcStateChange" 84bc2ed2b3Sopenharmony_ci * @return The status code for unregister operation. 85bc2ed2b3Sopenharmony_ci */ 86bc2ed2b3Sopenharmony_ci ErrorCode UnregListener(const std::string& type); 87bc2ed2b3Sopenharmony_ci 88bc2ed2b3Sopenharmony_ci /** 89bc2ed2b3Sopenharmony_ci * @brief Get the Tag Service Iface object 90bc2ed2b3Sopenharmony_ci * 91bc2ed2b3Sopenharmony_ci * @return OHOS::sptr<IRemoteObject> the remote object of tag service. 92bc2ed2b3Sopenharmony_ci */ 93bc2ed2b3Sopenharmony_ci OHOS::sptr<IRemoteObject> GetTagServiceIface(); 94bc2ed2b3Sopenharmony_ci 95bc2ed2b3Sopenharmony_ci OHOS::sptr<IRemoteObject> GetHceServiceIface(); 96bc2ed2b3Sopenharmony_ci 97bc2ed2b3Sopenharmony_ci void OnRemoteDied(const wptr<IRemoteObject> &remoteObject); 98bc2ed2b3Sopenharmony_ci 99bc2ed2b3Sopenharmony_ci ErrorCode RegNdefMsgCb(const sptr<INdefMsgCallback> &callback); 100bc2ed2b3Sopenharmony_ci 101bc2ed2b3Sopenharmony_ci#ifdef VENDOR_APPLICATIONS_ENABLED 102bc2ed2b3Sopenharmony_ci ErrorCode RegQueryApplicationCb(const std::string& type, 103bc2ed2b3Sopenharmony_ci QueryApplicationByVendor tagCallback, QueryHceAppByVendor hceCallback); 104bc2ed2b3Sopenharmony_ci 105bc2ed2b3Sopenharmony_ci ErrorCode RegCardEmulationNotifyCb(OnCardEmulationNotifyCb callback); 106bc2ed2b3Sopenharmony_ci ErrorCode NotifyEventStatus(int eventType, int arg1 = 0, std::string arg2 = ""); 107bc2ed2b3Sopenharmony_ci#endif 108bc2ed2b3Sopenharmony_ci 109bc2ed2b3Sopenharmony_ciprivate: 110bc2ed2b3Sopenharmony_ci class NfcServiceDeathRecipient : public IRemoteObject::DeathRecipient { 111bc2ed2b3Sopenharmony_ci public: 112bc2ed2b3Sopenharmony_ci explicit NfcServiceDeathRecipient(NfcController &client) : client_(client) {} 113bc2ed2b3Sopenharmony_ci ~NfcServiceDeathRecipient() override = default; 114bc2ed2b3Sopenharmony_ci void OnRemoteDied(const wptr<IRemoteObject> &remoteObject) override 115bc2ed2b3Sopenharmony_ci { 116bc2ed2b3Sopenharmony_ci client_.OnRemoteDied(remoteObject); 117bc2ed2b3Sopenharmony_ci } 118bc2ed2b3Sopenharmony_ci private: 119bc2ed2b3Sopenharmony_ci NfcController &client_; 120bc2ed2b3Sopenharmony_ci }; 121bc2ed2b3Sopenharmony_ci 122bc2ed2b3Sopenharmony_ciprivate: 123bc2ed2b3Sopenharmony_ci static void InitNfcRemoteSA(); 124bc2ed2b3Sopenharmony_ci 125bc2ed2b3Sopenharmony_ciprivate: 126bc2ed2b3Sopenharmony_ci static bool initialized_; 127bc2ed2b3Sopenharmony_ci static std::shared_ptr<NfcControllerProxy> nfcControllerProxy_; 128bc2ed2b3Sopenharmony_ci static std::weak_ptr<OHOS::NFC::INfcControllerService> nfcControllerService_; 129bc2ed2b3Sopenharmony_ci static std::mutex mutex_; 130bc2ed2b3Sopenharmony_ci static bool remoteDied_; 131bc2ed2b3Sopenharmony_ci static sptr<IRemoteObject> remote_; 132bc2ed2b3Sopenharmony_ci static sptr<IRemoteObject::DeathRecipient> deathRecipient_; 133bc2ed2b3Sopenharmony_ci}; 134bc2ed2b3Sopenharmony_ci} // namespace KITS 135bc2ed2b3Sopenharmony_ci} // namespace NFC 136bc2ed2b3Sopenharmony_ci} // namespace OHOS 137bc2ed2b3Sopenharmony_ci#endif // NFC_CONTROLLER_H 138