• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 HCE_SESSION_H
16 #define HCE_SESSION_H
17 
18 #include "access_token.h"
19 #include "element_name.h"
20 #include "infc_service.h"
21 #include "ihce_session.h"
22 #include "hce_session_stub.h"
23 #include "host_card_emulation_manager.h"
24 #include "ability_info.h"
25 
26 namespace OHOS {
27 namespace NFC {
28 namespace HCE {
29 using AppExecFwk::AbilityInfo;
30 using OHOS::AppExecFwk::ElementName;
31 class HceSession final : public HceSessionStub {
32 public:
33     // Constructor/Destructor
34     explicit HceSession(std::shared_ptr<NFC::INfcService> service);
35     ~HceSession() override;
36 
37     HceSession(const HceSession &) = delete;
38     HceSession &operator=(const HceSession &) = delete;
39 
40     int32_t CallbackEnter(uint32_t code) override;
41     int32_t CallbackExit(uint32_t code, int32_t result) override;
42 
43     ErrCode RegHceCmdCallback(const sptr<IHceCmdCallback>& cb, const std::string& type) override;
44 
45     ErrCode UnregHceCmdCallback(const sptr<IHceCmdCallback>& cb, const std::string& type) override;
46 
47     KITS::ErrorCode UnRegAllCallback(Security::AccessToken::AccessTokenID callerToken);
48     KITS::ErrorCode HandleWhenRemoteDie(Security::AccessToken::AccessTokenID callerToken);
49 
50     ErrCode SendRawFrame(const std::string& hexCmdData, bool raw, std::string& hexRespData) override;
51 
52     ErrCode GetPaymentServices(CePaymentServicesParcelable& parcelable) override;
53 
54     ErrCode IsDefaultService(const ElementName& element, const std::string& type, bool& isDefaultService) override;
55 
56     ErrCode StartHce(const ElementName& element, const std::vector<std::string>& aids) override;
57 
58     ErrCode StopHce(const ElementName& element) override;
59 
60     void RemoveHceDeathRecipient(const wptr<IRemoteObject>& remote);
61 
62 private:
63 #ifdef NFC_SIM_FEATURE
64     void AppendSimBundle(std::vector<AbilityInfo> &paymentAbilityInfos);
65 #endif
66 
67     std::weak_ptr<NFC::INfcService> nfcService_{};
68     std::weak_ptr<CeService> ceService_{};
69     std::mutex mutex_{};
70     sptr<KITS::IHceCmdCallback> hceCmdCallback_ = nullptr;
71     sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr;
72 };
73 } // namespace HCE
74 } // namespace NFC
75 } // namespace OHOS
76 #endif
77