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 #include "nfc_event_publisher.h" 16 #include "nfc_sdk_common.h" 17 #include "loghelper.h" 18 #include "want.h" 19 #include "common_event_manager.h" 20 21 namespace OHOS { 22 namespace NFC { PublishNfcStateChanged(int newState)23void NfcEventPublisher::PublishNfcStateChanged(int newState) 24 { 25 // notify the common event for nfc state changed. 26 AAFwk::Want want; 27 want.SetAction(KITS::COMMON_EVENT_NFC_ACTION_STATE_CHANGED); 28 want.SetParam(KITS::NFC_EXTRA_STATE, newState); 29 EventFwk::CommonEventData data; 30 data.SetWant(want); 31 data.SetCode(newState); 32 EventFwk::CommonEventManager::PublishCommonEvent(data); 33 } 34 PublishNfcFieldStateChanged(bool isFieldOn)35void NfcEventPublisher::PublishNfcFieldStateChanged(bool isFieldOn) 36 { 37 // notify the common event for field on/off. 38 AAFwk::Want want; 39 if (isFieldOn) { 40 want.SetAction(KITS::COMMON_EVENT_NFC_ACTION_RF_FIELD_ON_DETECTED); 41 } else { 42 want.SetAction(KITS::COMMON_EVENT_NFC_ACTION_RF_FIELD_OFF_DETECTED); 43 } 44 EventFwk::CommonEventData data; 45 data.SetWant(want); 46 EventFwk::CommonEventManager::PublishCommonEvent(data); 47 } 48 } // NFC 49 } // OHOS