/* * Copyright (C) 2023-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef CE_SERVICE_H #define CE_SERVICE_H #include "nfc_service.h" #include "host_card_emulation_manager.h" #include "inci_ce_interface.h" #include "ihce_cmd_callback.h" #include "app_data_parser.h" #include "common_event_manager.h" #include "element_name.h" #include "idefault_payment_service_change_callback.h" #include "default_payment_service_change_callback.h" namespace OHOS { namespace NFC { class NfcService; class NfcEventHandler; class HostCardEmulationManager; using OHOS::AppExecFwk::ElementName; class CeService : public IDefaultPaymentServiceChangeCallback, public std::enable_shared_from_this { public: struct AidEntry { std::string aid; int route; int aidInfo; int power; bool operator==(const AidEntry &other) const { return aid == other.aid && route == other.route && aidInfo == other.aidInfo && power == other.power; } }; explicit CeService(std::weak_ptr nfcService, std::weak_ptr nciCeProxy); ~CeService(); void HandleFieldActivated(); void HandleFieldDeactivated(); void OnCardEmulationData(const std::vector &data); void OnCardEmulationActivated(); void OnCardEmulationDeactivated(); static void PublishFieldOnOrOffCommonEvent(bool isFieldOn); bool RegHceCmdCallback(const sptr &callback, const std::string &type, Security::AccessToken::AccessTokenID callerToken); bool UnRegHceCmdCallback(const std::string &type, Security::AccessToken::AccessTokenID callerToken); bool UnRegAllCallback(Security::AccessToken::AccessTokenID callerToken); bool IsDefaultService(ElementName &element, const std::string &type); bool SendHostApduData(const std::string &hexCmdData, bool raw, std::string &hexRespData, Security::AccessToken::AccessTokenID callerToken); bool InitConfigAidRouting(); void OnDefaultPaymentServiceChange() override; OHOS::sptr AsObject() override; void Initialize(); void Deinitialize(); void OnAppAddOrChangeOrRemove(std::shared_ptr data); void ConfigRoutingAndCommit(); private: void BuildAidEntries(std::map &aidEntries); void ClearAidEntriesCache(); uint64_t lastFieldOnTime_ = 0; uint64_t lastFieldOffTime_ = 0; std::weak_ptr nfcService_{}; friend class NfcService; std::weak_ptr nciCeProxy_{}; std::shared_ptr hostCardEmulationManager_{}; ElementName defaultPaymentElement_; sptr dataRdbObserver_; std::mutex configRoutingMutex_ {}; std::map aidToAidEntry_{}; }; } // namespace NFC } // namespace OHOS #endif