1 /*
2 * Copyright (C) 2021 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
16 #include "sms_receive_indexer.h"
17
18 #include "cstdint"
19 #include "iosfwd"
20 #include "string"
21 #include "type_traits"
22 #include "vector"
23
24 namespace OHOS {
25 namespace Telephony {
26 static constexpr int8_t TEXT_PORT_NUM = -1;
27 static constexpr int16_t WAP_PUSH_PORT = 2948;
28
SmsReceiveIndexer()29 SmsReceiveIndexer::SmsReceiveIndexer()
30 {
31 timestamp_ = 0;
32 destPort_ = 0;
33 msgSeqId_ = 0;
34 msgRefId_ = 0;
35 msgCount_ = 1;
36 isCdma_ = false;
37 isCdmaWapPdu_ = false;
38 }
39
SmsReceiveIndexer(const std::vector<uint8_t> & pdu,int64_t timestamp,int16_t destPort,bool isCdma,const std::string & address,const std::string & visibleAddress,uint16_t msgRefId,uint16_t msgSeqId,uint16_t msgCount,bool isCdmaWapPdu,const std::string & messageBody)40 SmsReceiveIndexer::SmsReceiveIndexer(const std::vector<uint8_t> &pdu, int64_t timestamp, int16_t destPort, bool isCdma,
41 const std::string &address, const std::string &visibleAddress, uint16_t msgRefId, uint16_t msgSeqId,
42 uint16_t msgCount, bool isCdmaWapPdu, const std::string &messageBody)
43 : pdu_(pdu), timestamp_(timestamp), destPort_(destPort), isCdma_(isCdma), isCdmaWapPdu_(isCdmaWapPdu),
44 visibleMessageBody_(messageBody), originatingAddress_(address), msgRefId_(msgRefId), msgSeqId_(msgSeqId),
45 msgCount_(msgCount), visibleAddress_(visibleAddress)
46 {}
47
SmsReceiveIndexer(const std::vector<uint8_t> & pdu,int64_t timestamp,int16_t destPort,bool isCdma,bool isCdmaWapPdu,const std::string & address,const std::string & visibleAddress,const std::string & messageBody)48 SmsReceiveIndexer::SmsReceiveIndexer(const std::vector<uint8_t> &pdu, int64_t timestamp, int16_t destPort, bool isCdma,
49 bool isCdmaWapPdu, const std::string &address, const std::string &visibleAddress, const std::string &messageBody)
50 : pdu_(pdu), timestamp_(timestamp), destPort_(destPort), isCdma_(isCdma), isCdmaWapPdu_(isCdmaWapPdu),
51 visibleMessageBody_(messageBody), originatingAddress_(address), visibleAddress_(visibleAddress)
52 {
53 if (isCdma_ && isCdmaWapPdu_) {
54 msgSeqId_ = 0;
55 } else {
56 msgSeqId_ = 1;
57 }
58 msgRefId_ = 0;
59 msgCount_ = 1;
60 }
61
GetVisibleAddress() const62 std::string SmsReceiveIndexer::GetVisibleAddress() const
63 {
64 return visibleAddress_;
65 }
66
SetVisibleAddress(const std::string & visibleAddress)67 void SmsReceiveIndexer::SetVisibleAddress(const std::string &visibleAddress)
68 {
69 visibleAddress_ = visibleAddress;
70 }
71
GetEraseRefId() const72 std::string SmsReceiveIndexer::GetEraseRefId() const
73 {
74 return eraseRefId_;
75 }
76
SetEraseRefId(const std::string & eraseRefId)77 void SmsReceiveIndexer::SetEraseRefId(const std::string &eraseRefId)
78 {
79 eraseRefId_ = eraseRefId;
80 }
81
GetMsgCount() const82 uint16_t SmsReceiveIndexer::GetMsgCount() const
83 {
84 return msgCount_;
85 }
86
SetMsgCount(uint16_t msgCount)87 void SmsReceiveIndexer::SetMsgCount(uint16_t msgCount)
88 {
89 msgCount_ = msgCount;
90 }
91
GetMsgSeqId() const92 uint16_t SmsReceiveIndexer::GetMsgSeqId() const
93 {
94 return msgSeqId_;
95 }
96
SetMsgSeqId(uint16_t msgSeqId)97 void SmsReceiveIndexer::SetMsgSeqId(uint16_t msgSeqId)
98 {
99 msgSeqId_ = msgSeqId;
100 }
101
GetMsgRefId() const102 uint16_t SmsReceiveIndexer::GetMsgRefId() const
103 {
104 return msgRefId_;
105 }
106
SetMsgRefId(uint16_t msgRefId)107 void SmsReceiveIndexer::SetMsgRefId(uint16_t msgRefId)
108 {
109 msgRefId_ = msgRefId;
110 }
111
GetDataBaseId() const112 uint16_t SmsReceiveIndexer::GetDataBaseId() const
113 {
114 return dataBaseId_;
115 }
116
SetDataBaseId(uint16_t dataBaseId)117 void SmsReceiveIndexer::SetDataBaseId(uint16_t dataBaseId)
118 {
119 dataBaseId_ = dataBaseId;
120 }
121
GetOriginatingAddress() const122 std::string SmsReceiveIndexer::GetOriginatingAddress() const
123 {
124 return originatingAddress_;
125 }
126
SetOriginatingAddress(const std::string & address)127 void SmsReceiveIndexer::SetOriginatingAddress(const std::string &address)
128 {
129 originatingAddress_ = address;
130 }
131
GetVisibleMessageBody() const132 std::string SmsReceiveIndexer::GetVisibleMessageBody() const
133 {
134 return visibleMessageBody_;
135 }
136
SetVisibleMessageBody(const std::string & messageBody)137 void SmsReceiveIndexer::SetVisibleMessageBody(const std::string &messageBody)
138 {
139 visibleMessageBody_ = messageBody;
140 }
141
GetIsCdmaWapPdu() const142 bool SmsReceiveIndexer::GetIsCdmaWapPdu() const
143 {
144 return isCdmaWapPdu_;
145 }
146
SetIsCdmaWapPdu(bool isCdmaWapPdu)147 void SmsReceiveIndexer::SetIsCdmaWapPdu(bool isCdmaWapPdu)
148 {
149 isCdmaWapPdu_ = isCdmaWapPdu;
150 }
151
GetIsCdma() const152 bool SmsReceiveIndexer::GetIsCdma() const
153 {
154 return isCdma_;
155 }
156
SetIsCdma(bool isCdma)157 void SmsReceiveIndexer::SetIsCdma(bool isCdma)
158 {
159 isCdma_ = isCdma;
160 }
161
GetDestPort() const162 int16_t SmsReceiveIndexer::GetDestPort() const
163 {
164 return destPort_;
165 }
166
SetDestPort(int16_t destPort)167 void SmsReceiveIndexer::SetDestPort(int16_t destPort)
168 {
169 destPort_ = destPort;
170 }
171
GetTimestamp() const172 int64_t SmsReceiveIndexer::GetTimestamp() const
173 {
174 return timestamp_;
175 }
176
SetTimestamp(int64_t timestamp)177 void SmsReceiveIndexer::SetTimestamp(int64_t timestamp)
178 {
179 timestamp_ = timestamp;
180 }
181
GetPdu() const182 const std::vector<uint8_t>& SmsReceiveIndexer::GetPdu() const
183 {
184 return pdu_;
185 }
186
SetPdu(const std::vector<uint8_t> & pdu)187 void SmsReceiveIndexer::SetPdu(const std::vector<uint8_t> &pdu)
188 {
189 pdu_ = pdu;
190 }
191
SetPdu(const std::vector<uint8_t> && pdu)192 void SmsReceiveIndexer::SetPdu(const std::vector<uint8_t> &&pdu)
193 {
194 pdu_ = std::forward<const std::vector<uint8_t>>(pdu);
195 }
196
GetIsText() const197 bool SmsReceiveIndexer::GetIsText() const
198 {
199 return (destPort_ == TEXT_PORT_NUM);
200 }
201
GetIsWapPushMsg() const202 bool SmsReceiveIndexer::GetIsWapPushMsg() const
203 {
204 return (destPort_ == WAP_PUSH_PORT);
205 }
206
IsSingleMsg() const207 bool SmsReceiveIndexer::IsSingleMsg() const
208 {
209 return msgCount_ == 1;
210 }
211
GetRawUserData() const212 std::string SmsReceiveIndexer::GetRawUserData() const
213 {
214 return rawUserData_;
215 }
216
SetRawUserData(const std::string & rawUserData)217 void SmsReceiveIndexer::SetRawUserData(const std::string &rawUserData)
218 {
219 rawUserData_ = rawUserData;
220 }
221
GetWapPusRawUserData() const222 std::string SmsReceiveIndexer::GetWapPusRawUserData() const
223 {
224 return rawWapPushUserData_;
225 }
226
SetRawWapPushUserData(const std::string & rawWapPushUserData)227 void SmsReceiveIndexer::SetRawWapPushUserData(const std::string &rawWapPushUserData)
228 {
229 rawWapPushUserData_ = rawWapPushUserData;
230 }
231 } // namespace Telephony
232 } // namespace OHOS