1 /*
2  * Copyright (C) 2023 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_STATE_CHANGE_CALLBACK_H
16 #define NFC_STATE_CHANGE_CALLBACK_H
17 
18 #include "data_ability_observer_stub.h"
19 #include "nfc_data_share_impl.h"
20 #include "infc_controller_callback.h"
21 
22 namespace OHOS {
23 namespace NFC {
24 namespace KITS {
25 class NfcStateChangeCallback : public AAFwk::DataAbilityObserverStub {
26 public:
NfcStateChangeCallback(sptr<INfcControllerCallback> callback)27     explicit NfcStateChangeCallback(sptr<INfcControllerCallback> callback) : callback_(callback)
28     {}
~NfcStateChangeCallback()29     virtual ~NfcStateChangeCallback() {}
OnChange()30     void OnChange() override
31     {
32         if (callback_ == nullptr) {
33             return;
34         }
35         int state = NfcState::STATE_OFF;
36         Uri nfcEnableUri(NFC_DATA_URI);
37         DelayedSingleton<NfcDataShareImpl>::GetInstance()->
38             GetValue(nfcEnableUri, DATA_SHARE_KEY_STATE, state);
39         callback_->OnNfcStateChanged(state);
40     }
41 
42 private:
43     sptr<INfcControllerCallback> callback_;
44 };
45 } // namespace KITS
46 } // namespace NFC
47 } // namespace OHOS
48 #endif // NFC_STATE_CHANGE_CALLBACK_H
49