• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-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 
16 #ifndef SMS_BASE_MESSAGE__H
17 #define SMS_BASE_MESSAGE__H
18 
19 #include <cmath>
20 #include <memory>
21 
22 #include "cdma_sms_transport_message.h"
23 #include "gsm_sms_tpdu_codec.h"
24 #include "msg_text_convert_common.h"
25 #include "sms_common_utils.h"
26 #include "string_utils.h"
27 #include "unicode/brkiter.h"
28 
29 namespace OHOS {
30 namespace Telephony {
31 typedef struct {
32     uint16_t msgRef;
33     uint16_t seqNum;
34     uint16_t totalSeg;
35     bool is8Bits;
36 } SmsConcat;
37 
38 typedef struct {
39     uint16_t destPort;
40     uint16_t originPort;
41     bool is8Bits;
42 } SmsAppPortAddr;
43 
44 typedef struct {
45     bool bStore;
46     uint16_t msgInd;
47     uint16_t waitMsgNum;
48 } SpecialSmsIndication;
49 
50 struct SplitInfo {
51     std::string text = "";
52     std::vector<uint8_t> encodeData {};
53     DataCodingScheme encodeType = DataCodingScheme::DATA_CODING_7BIT;
54     MSG_LANGUAGE_ID_T langId = 0;
55 };
56 
57 struct LengthInfo {
58     uint8_t dcs = 0;
59     uint8_t msgSegCount = 0;
60     uint16_t msgEncodeCount = 0;
61     uint8_t msgRemainCount = 0;
62 };
63 
64 class SmsBaseMessage {
65 public:
66     SmsBaseMessage() = default;
67     virtual ~SmsBaseMessage() = default;
68     virtual void SetSmscAddr(const std::string &scAddress);
69     virtual std::string GetSmscAddr() const;
70     virtual std::string GetOriginatingAddress() const;
71     virtual std::string GetVisibleOriginatingAddress() const;
72     virtual std::string GetVisibleMessageBody() const;
73     virtual std::string GetEmailAddress() const;
74     virtual std::string GetEmailMessageBody() const;
75     virtual bool IsEmail() const;
76     virtual enum SmsMessageClass GetMessageClass() const;
77     std::vector<uint8_t> GetRawPdu() const;
78     std::string GetRawUserData() const;
79     std::string GetRawWapPushUserData() const;
80     virtual int64_t GetScTimestamp() const;
81     virtual int GetStatus() const;
82     virtual int GetProtocolId() const;
83     virtual bool IsReplaceMessage();
84     virtual bool IsCphsMwi() const;
85     virtual bool IsMwiClear() const;
86     virtual bool IsMwiSet() const;
87     virtual bool IsMwiNotStore() const;
88     virtual bool IsSmsStatusReportMessage() const;
89     virtual bool HasReplyPath() const;
90     virtual std::shared_ptr<SmsConcat> GetConcatMsg();
91     virtual std::shared_ptr<SmsAppPortAddr> GetPortAddress();
92     virtual std::shared_ptr<SpecialSmsIndication> GetSpecialSmsInd();
93     virtual bool IsConcatMsg();
94     virtual bool IsWapPushMsg();
95     virtual void ConvertMessageClass(enum SmsMessageClass msgClass);
96     virtual int GetMsgRef();
97     virtual int GetSegmentSize(
98         DataCodingScheme &codingScheme, int dataLen, bool bPortNum, MSG_LANGUAGE_ID_T &langId) const;
99     virtual void SplitMessage(std::vector<struct SplitInfo> &splitResult, const std::string &text, bool force7BitCode,
100         DataCodingScheme &codingType, bool bPortNum, const std::string &desAddr);
101     virtual int32_t GetIndexOnSim() const;
102     virtual void SetIndexOnSim(int32_t index);
103     virtual int32_t GetSmsSegmentsInfo(const std::string &message, bool force7BitCode, LengthInfo &lenInfo);
104     virtual int GetMaxSegmentSize(
105         DataCodingScheme &codingScheme, int dataLen, bool bPortNum, MSG_LANGUAGE_ID_T &langId, int replyAddrLen) const;
106     virtual void SplitMessageUcs2(std::vector<struct SplitInfo> &splitResult, const uint8_t* decodeData,
107         int32_t encodeLen, int32_t segSize, DataCodingScheme &codingType);
108 
109 protected:
110     constexpr static int16_t MAX_MSG_TEXT_LEN = 1530;
111     constexpr static int16_t MAX_REPLY_PID = 8;
112     std::string scAddress_;
113     std::string originatingAddress_;
114     std::string visibleMessageBody_;
115     enum SmsMessageClass msgClass_ = SMS_CLASS_UNKNOWN;
116     int64_t scTimestamp_;
117     int status_;
118     int protocolId_;
119     bool bReplaceMessage_;
120     bool bStatusReportMessage_;
121     bool bMwi_;
122     bool bMwiSense_;
123     bool bCphsMwi_;
124     bool bMwiClear_;
125     bool bMwiSet_;
126     bool bMwiNotStore_;
127     bool hasReplyPath_;
128     bool bMoreMsg_;
129     bool bHeaderInd_;
130     int headerCnt_;
131     int headerDataLen_;
132     int msgRef_;
133     bool bCompressed_;
134     bool bIndActive_;
135     int codingScheme_;
136     int codingGroup_;
137     std::vector<uint8_t> rawPdu_;
138     std::string rawUserData_;
139     std::string rawWapPushUserData_;
140     struct SmsUDPackage smsUserData_;
141     struct SmsTpud smsWapPushUserData_;
142     std::shared_ptr<SmsConcat> smsConcat_;
143     std::shared_ptr<SmsAppPortAddr> portAddress_;
144     std::shared_ptr<SpecialSmsIndication> specialSmsInd_;
145     int32_t indexOnSim_ = -1;
146     std::string emailFrom_;
147     std::string emailBody_;
148     bool isEmail_ = false;
149 
150 private:
151     virtual int DecodeMessage(uint8_t *decodeData, unsigned int length, DataCodingScheme &codingType,
152         const std::string &msgText, bool &bAbnormal, MSG_LANGUAGE_ID_T &langId) = 0;
153     void ConvertSpiltToUtf8(SplitInfo &split, const DataCodingScheme &codingType);
154     int32_t FindNextUnicodePosition(int32_t index, int32_t segSizeHalf, icu::BreakIterator *fullDataIter,
155         const icu::UnicodeString &fullData);
156 };
157 } // namespace Telephony
158 } // namespace OHOS
159 #endif
160