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