1/* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15#ifndef NFC_EVENT_HANDLER_H 16#define NFC_EVENT_HANDLER_H 17#include "common_event_manager.h" 18#include "event_handler.h" 19#include "nfc_service.h" 20#include "tag_dispatcher.h" 21 22namespace OHOS { 23namespace NFC { 24class NfcService; 25class CeService; 26class NfcPollingManager; 27class NfcRoutingManager; 28class NfcEventHandler final : public AppExecFwk::EventHandler { 29public: 30 explicit NfcEventHandler(const std::shared_ptr<AppExecFwk::EventRunner>& runner, 31 std::weak_ptr<NfcService> service); 32 ~NfcEventHandler(); 33 NfcEventHandler& operator=(const NfcEventHandler&) = delete; 34 NfcEventHandler(const NfcEventHandler&) = delete; 35 36 void Intialize(std::weak_ptr<TAG::TagDispatcher> tagDispatcher, 37 std::weak_ptr<CeService> ceService, 38 std::weak_ptr<NfcPollingManager> nfcPollingManager, 39 std::weak_ptr<NfcRoutingManager> nfcRoutingManager, 40 std::weak_ptr<NCI::INciNfccInterface> nciNfccProxy); 41 void ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event) override; 42 43 void SubscribeScreenChangedEvent(); 44 void SubscribePackageChangedEvent(); 45 void SubscribeShutdownEvent(); 46 void SubscribeDataShareChangedEvent(); 47 bool IsScreenOn(); 48 bool IsScreenLocked(); 49 ScreenState CheckScreenState(); 50 51protected: 52 // Screen Changed Receiver 53 class ScreenChangedReceiver; 54 // Package Changed Receiver 55 class PackageChangedReceiver; 56 // Shutdown Event Receiver 57 class ShutdownEventReceiver; 58 // DataShare changed Receiver 59 class DataShareChangedReceiver; 60 61private: 62 std::shared_ptr<EventFwk::CommonEventSubscriber> screenSubscriber_ {}; 63 std::shared_ptr<EventFwk::CommonEventSubscriber> pkgSubscriber_ {}; 64 std::shared_ptr<EventFwk::CommonEventSubscriber> shutdownSubscriber_ {}; 65 std::shared_ptr<EventFwk::CommonEventSubscriber> dataShareSubscriber_ {}; 66 67 std::weak_ptr<NfcService> nfcService_ {}; 68 std::weak_ptr<TAG::TagDispatcher> tagDispatcher_ {}; 69 std::weak_ptr<CeService> ceService_ {}; 70 std::weak_ptr<NfcPollingManager> nfcPollingManager_ {}; 71 std::weak_ptr<NfcRoutingManager> nfcRoutingManager_ {}; 72 std::weak_ptr<NCI::INciNfccInterface> nciNfccProxy_ {}; 73 74 std::mutex commonEventMutex_ {}; 75 76 static constexpr const int WAIT_PROCESS_EVENT_TIMES = 60 * 1000; 77}; 78} // namespace NFC 79} // namespace OHOS 80#endif // NFC_EVENT_HANDLER_H 81