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 24namespace OHOS { 25namespace Telephony { 26static constexpr int8_t TEXT_PORT_NUM = -1; 27static constexpr int16_t WAP_PUSH_PORT = 2948; 28 29SmsReceiveIndexer::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 40SmsReceiveIndexer::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 48SmsReceiveIndexer::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 62std::string SmsReceiveIndexer::GetVisibleAddress() const 63{ 64 return visibleAddress_; 65} 66 67void SmsReceiveIndexer::SetVisibleAddress(const std::string &visibleAddress) 68{ 69 visibleAddress_ = visibleAddress; 70} 71 72std::string SmsReceiveIndexer::GetEraseRefId() const 73{ 74 return eraseRefId_; 75} 76 77void SmsReceiveIndexer::SetEraseRefId(const std::string &eraseRefId) 78{ 79 eraseRefId_ = eraseRefId; 80} 81 82uint16_t SmsReceiveIndexer::GetMsgCount() const 83{ 84 return msgCount_; 85} 86 87void SmsReceiveIndexer::SetMsgCount(uint16_t msgCount) 88{ 89 msgCount_ = msgCount; 90} 91 92uint16_t SmsReceiveIndexer::GetMsgSeqId() const 93{ 94 return msgSeqId_; 95} 96 97void SmsReceiveIndexer::SetMsgSeqId(uint16_t msgSeqId) 98{ 99 msgSeqId_ = msgSeqId; 100} 101 102uint16_t SmsReceiveIndexer::GetMsgRefId() const 103{ 104 return msgRefId_; 105} 106 107void SmsReceiveIndexer::SetMsgRefId(uint16_t msgRefId) 108{ 109 msgRefId_ = msgRefId; 110} 111 112uint16_t SmsReceiveIndexer::GetDataBaseId() const 113{ 114 return dataBaseId_; 115} 116 117void SmsReceiveIndexer::SetDataBaseId(uint16_t dataBaseId) 118{ 119 dataBaseId_ = dataBaseId; 120} 121 122std::string SmsReceiveIndexer::GetOriginatingAddress() const 123{ 124 return originatingAddress_; 125} 126 127void SmsReceiveIndexer::SetOriginatingAddress(const std::string &address) 128{ 129 originatingAddress_ = address; 130} 131 132std::string SmsReceiveIndexer::GetVisibleMessageBody() const 133{ 134 return visibleMessageBody_; 135} 136 137void SmsReceiveIndexer::SetVisibleMessageBody(const std::string &messageBody) 138{ 139 visibleMessageBody_ = messageBody; 140} 141 142bool SmsReceiveIndexer::GetIsCdmaWapPdu() const 143{ 144 return isCdmaWapPdu_; 145} 146 147void SmsReceiveIndexer::SetIsCdmaWapPdu(bool isCdmaWapPdu) 148{ 149 isCdmaWapPdu_ = isCdmaWapPdu; 150} 151 152bool SmsReceiveIndexer::GetIsCdma() const 153{ 154 return isCdma_; 155} 156 157void SmsReceiveIndexer::SetIsCdma(bool isCdma) 158{ 159 isCdma_ = isCdma; 160} 161 162int16_t SmsReceiveIndexer::GetDestPort() const 163{ 164 return destPort_; 165} 166 167void SmsReceiveIndexer::SetDestPort(int16_t destPort) 168{ 169 destPort_ = destPort; 170} 171 172int64_t SmsReceiveIndexer::GetTimestamp() const 173{ 174 return timestamp_; 175} 176 177void SmsReceiveIndexer::SetTimestamp(int64_t timestamp) 178{ 179 timestamp_ = timestamp; 180} 181 182const std::vector<uint8_t>& SmsReceiveIndexer::GetPdu() const 183{ 184 return pdu_; 185} 186 187void SmsReceiveIndexer::SetPdu(const std::vector<uint8_t> &pdu) 188{ 189 pdu_ = pdu; 190} 191 192void SmsReceiveIndexer::SetPdu(const std::vector<uint8_t> &&pdu) 193{ 194 pdu_ = std::forward<const std::vector<uint8_t>>(pdu); 195} 196 197bool SmsReceiveIndexer::GetIsText() const 198{ 199 return (destPort_ == TEXT_PORT_NUM); 200} 201 202bool SmsReceiveIndexer::GetIsWapPushMsg() const 203{ 204 return (destPort_ == WAP_PUSH_PORT); 205} 206 207bool SmsReceiveIndexer::IsSingleMsg() const 208{ 209 return msgCount_ == 1; 210} 211 212std::string SmsReceiveIndexer::GetRawUserData() const 213{ 214 return rawUserData_; 215} 216 217void SmsReceiveIndexer::SetRawUserData(const std::string &rawUserData) 218{ 219 rawUserData_ = rawUserData; 220} 221 222std::string SmsReceiveIndexer::GetRawWapPushUserData() const 223{ 224 return rawWapPushUserData_; 225} 226 227void SmsReceiveIndexer::SetRawWapPushUserData(const std::string &rawWapPushUserData) 228{ 229 rawWapPushUserData_ = rawWapPushUserData; 230} 231} // namespace Telephony 232} // namespace OHOS