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 "taginfo.h"
16 #include "loghelper.h"
17 #include "nfc_sdk_common.h"
18 #include "parcel.h"
19 #include "refbase.h"
20
21 namespace OHOS {
22 namespace NFC {
23 namespace KITS {
TagInfo(std::vector<int> tagTechList,std::vector<AppExecFwk::PacMap> tagTechExtrasData,std::string & tagUid,int tagRfDiscId,OHOS::sptr<IRemoteObject> tagServiceIface)24 TagInfo::TagInfo(std::vector<int> tagTechList,
25 std::vector<AppExecFwk::PacMap> tagTechExtrasData,
26 std::string& tagUid,
27 int tagRfDiscId,
28 OHOS::sptr<IRemoteObject> tagServiceIface)
29 {
30 tagRfDiscId_ = tagRfDiscId;
31 tagUid_ = tagUid;
32 tagTechList_ = std::move(tagTechList);
33 tagTechExtrasData_ = std::move(tagTechExtrasData);
34 connectedTagTech_ = KITS::TagTechnology::NFC_INVALID_TECH;
35 }
36
~TagInfo()37 TagInfo::~TagInfo()
38 {
39 tagUid_.clear();
40 tagTechList_.clear();
41 connectedTagTech_ = KITS::TagTechnology::NFC_INVALID_TECH;
42 tagRfDiscId_ = 0;
43 }
44
IsTechSupported(KITS::TagTechnology tech)45 bool TagInfo::IsTechSupported(KITS::TagTechnology tech)
46 {
47 for (auto n : tagTechList_) {
48 if (n == static_cast<int>(tech)) {
49 return true;
50 }
51 }
52 return false;
53 }
54
GetTagTechList() const55 std::vector<int> TagInfo::GetTagTechList() const
56 {
57 return std::move(tagTechList_);
58 }
59
GetStringTech(int tech)60 std::string TagInfo::GetStringTech(int tech)
61 {
62 switch (tech) {
63 case static_cast<int>(TagTechnology::NFC_A_TECH):
64 return "NfcA";
65 case static_cast<int>(TagTechnology::NFC_B_TECH):
66 return "NfcB";
67 case static_cast<int>(TagTechnology::NFC_F_TECH):
68 return "NfcF";
69 case static_cast<int>(TagTechnology::NFC_V_TECH):
70 return "NfcV";
71 case static_cast<int>(TagTechnology::NFC_ISODEP_TECH):
72 return "IsoDep";
73 case static_cast<int>(TagTechnology::NFC_MIFARE_CLASSIC_TECH):
74 return "MifareClassic";
75 case static_cast<int>(TagTechnology::NFC_MIFARE_ULTRALIGHT_TECH):
76 return "MifareUL";
77 case static_cast<int>(TagTechnology::NFC_NDEF_TECH):
78 return "Ndef";
79 case static_cast<int>(TagTechnology::NFC_NDEF_FORMATABLE_TECH):
80 return "NdefFormatable";
81 default:
82 break;
83 }
84 return "";
85 }
86
GetTechExtrasByIndex(size_t techIndex)87 AppExecFwk::PacMap TagInfo::GetTechExtrasByIndex(size_t techIndex)
88 {
89 AppExecFwk::PacMap pacmap;
90 if (tagTechList_.size() == 0 || tagTechList_.size() != tagTechExtrasData_.size()) {
91 ErrorLog("Taginfo:: tagTechList_lenth != tagTechExtrasData_length.");
92 return pacmap;
93 }
94 if (techIndex < 0 || techIndex >= tagTechExtrasData_.size()) {
95 return pacmap;
96 }
97 return tagTechExtrasData_[techIndex];
98 }
99
GetTechExtrasByTech(KITS::TagTechnology tech)100 AppExecFwk::PacMap TagInfo::GetTechExtrasByTech(KITS::TagTechnology tech)
101 {
102 AppExecFwk::PacMap pacmap;
103 if (tagTechList_.size() == 0 || tagTechList_.size() != tagTechExtrasData_.size()) {
104 return pacmap;
105 }
106
107 for (size_t i = 0; i < tagTechList_.size(); i++) {
108 if (static_cast<int>(tech) == tagTechList_[i]) {
109 pacmap = tagTechExtrasData_[i];
110 break;
111 }
112 }
113 return pacmap;
114 }
115
GetStringExtrasData(AppExecFwk::PacMap & extrasData,const std::string & extrasName)116 std::string TagInfo::GetStringExtrasData(AppExecFwk::PacMap& extrasData, const std::string& extrasName)
117 {
118 if (extrasData.IsEmpty() || extrasName.empty()) {
119 return "";
120 }
121 return extrasData.GetStringValue(extrasName, "");
122 }
123
GetIntExtrasData(AppExecFwk::PacMap & extrasData,const std::string & extrasName)124 int TagInfo::GetIntExtrasData(AppExecFwk::PacMap& extrasData, const std::string& extrasName)
125 {
126 if (extrasData.IsEmpty() || extrasName.empty()) {
127 return ErrorCode::ERR_TAG_PARAMETERS;
128 }
129 return extrasData.GetIntValue(extrasName, 0);
130 }
131
GetBoolExtrasData(AppExecFwk::PacMap & extrasData,const std::string & extrasName)132 bool TagInfo::GetBoolExtrasData(AppExecFwk::PacMap& extrasData, const std::string& extrasName)
133 {
134 if (extrasData.IsEmpty() || extrasName.empty()) {
135 return false;
136 }
137 return extrasData.GetBooleanValue(extrasName, false);
138 }
139
SetConnectedTagTech(KITS::TagTechnology connectedTagTech)140 void TagInfo::SetConnectedTagTech(KITS::TagTechnology connectedTagTech)
141 {
142 connectedTagTech_ = connectedTagTech;
143 }
144
GetConnectedTagTech() const145 KITS::TagTechnology TagInfo::GetConnectedTagTech() const
146 {
147 return connectedTagTech_;
148 }
149
GetTagUid() const150 std::string TagInfo::GetTagUid() const
151 {
152 return tagUid_;
153 }
154
GetTagRfDiscId() const155 int TagInfo::GetTagRfDiscId() const
156 {
157 return tagRfDiscId_;
158 }
159
160 } // namespace KITS
161 } // namespace NFC
162 } // namespace OHOS