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 #include "nfc_ability_connection_callback.h"
16 #include "loghelper.h"
17 
18 namespace OHOS {
19 namespace NFC {
NfcAbilityConnectionCallback()20 NfcAbilityConnectionCallback::NfcAbilityConnectionCallback()
21 {
22     serviceConnected_ = false;
23 }
24 
~NfcAbilityConnectionCallback()25 NfcAbilityConnectionCallback::~NfcAbilityConnectionCallback()
26 {
27     serviceConnected_ = false;
28 }
29 
OnAbilityConnectDone(const AppExecFwk::ElementName & element,const sptr<IRemoteObject> & remoteObject,int resultCode)30 void NfcAbilityConnectionCallback::OnAbilityConnectDone(const AppExecFwk::ElementName &element,
31                                                         const sptr<IRemoteObject> &remoteObject, int resultCode)
32 {
33     InfoLog("service connected: %{public}s, result code %{public}d", element.GetURI().c_str(), resultCode);
34     serviceConnected_ = true;
35     connectedElement_.SetBundleName(element.GetBundleName());
36     connectedElement_.SetAbilityName(element.GetAbilityName());
37     connectedElement_.SetDeviceID(element.GetDeviceID());
38     connectedElement_.SetModuleName(element.GetModuleName());
39     if (hceManager_.expired()) {
40         ErrorLog("hce manager is expired");
41         return;
42     }
43     hceManager_.lock()->HandleQueueData();
44 }
45 
OnAbilityDisconnectDone(const AppExecFwk::ElementName & element,int resultCode)46 void NfcAbilityConnectionCallback::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode)
47 {
48     InfoLog("service disconnected done: %{public}s, result code %{public}d", element.GetURI().c_str(), resultCode);
49     serviceConnected_ = false;
50     connectedElement_.SetBundleName("");
51     connectedElement_.SetAbilityName("");
52     connectedElement_.SetDeviceID("");
53     connectedElement_.SetModuleName("");
54 }
ServiceConnected()55 bool NfcAbilityConnectionCallback::ServiceConnected()
56 {
57     return serviceConnected_;
58 }
SetHceManager(std::weak_ptr<HostCardEmulationManager> hceManager)59 void NfcAbilityConnectionCallback::SetHceManager(std::weak_ptr<HostCardEmulationManager> hceManager)
60 {
61     hceManager_ = hceManager;
62 }
GetConnectedElement()63 AppExecFwk::ElementName NfcAbilityConnectionCallback::GetConnectedElement()
64 {
65     return connectedElement_;
66 }
67 } // namespace NFC
68 } // namespace OHOS
69