blob: 445e2f6b03532bb900b182987ceb5d4cfb95844e [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef SMSMESSAGEBASE_H_
18#define SMSMESSAGEBASE_H_
19
20#include <cstdint>
21#include <string>
22#include <memory>
23#include <vector>
24#include "SmsAddress.h"
25#include "SmsConstants.h"
26#include "SmsHeader.h"
27#include "HexDump.h"
28
29class SmsMessageBase {
30public:
31 SmsMessageBase();
32 virtual ~SmsMessageBase();
33 /** TP-Message-Reference - Message Reference of sent message. @hide */
34 int mMessageRef = 0;
35 class SubmitPduBase {
36 public:
37 uint8_t* encodedScAddress = nullptr; // Null if not applicable.
38 uint32_t encodedScAddress_length = 0;
39 uint8_t* encodedMessage = nullptr;
40 uint32_t encodedMessage_length = 0;
41
42 std::string toString() {
43
44 return "SubmitPdu: encodedScAddress = "
45 + HexDump::dumpHexString(encodedScAddress, encodedScAddress_length)
46 + ", encodedMessage = "
47 + HexDump::dumpHexString(encodedMessage, encodedMessage_length);
48 }
49 };
50 /**
51 * Returns the address of the SMS service center that relayed this message
52 * or null if there is none.
53 */
54 std::string getServiceCenterAddress() {
55 return mScAddress;
56 }
57 std::string getOriginatingAddress() {
58 if (mOriginatingAddress == nullptr) {
59 return nullptr;
60 }
61
62 return mOriginatingAddress->getAddressString();
63 }
64 /**
65 * Returns the originating address, or email from address if this message
66 * was from an email gateway. Returns null if originating address
67 * unavailable.
68 */
69 std::string getDisplayOriginatingAddress() {
70 if (mIsEmail) {
71 return mEmailFrom;
72 } else {
73 return getOriginatingAddress();
74 }
75 }
76 /**
77 * Returns the message body as a String, if it exists and is text based.
78 * @return message body is there is one, otherwise null
79 */
80 std::string getMessageBody() {
81 return mMessageBody;
82 }
83
84 /**
85 * Returns the class of this message.
86 */
87 virtual SmsConstants::MessageClass getMessageClass() = 0;
88
89 /**
90 * Returns the message body, or email message body if this message was from
91 * an email gateway. Returns null if message body unavailable.
92 */
93 std::string getDisplayMessageBody() {
94 if (mIsEmail) {
95 return mEmailBody;
96 } else {
97 return getMessageBody();
98 }
99 }
100
101 /**
102 * Unofficial convention of a subject line enclosed in parens empty string
103 * if not present
104 */
105 std::string getPseudoSubject() {
106 return mPseudoSubject.empty() ? "" : mPseudoSubject;
107 }
108
109 /**
110 * Returns the service centre timestamp in currentTimeMillis() format
111 */
112 long getTimestampMillis() {
113 return mScTimeMillis;
114 }
115
116 /**
117 * Returns true if message is an email.
118 *
119 * @return true if this message came through an email gateway and email
120 * sender / subject / parsed body are available
121 */
122 bool isEmail() {
123 return mIsEmail;
124 }
125
126 /**
127 * @return if isEmail() is true, body of the email sent through the gateway.
128 * null otherwise
129 */
130 std::string getEmailBody() {
131 return mEmailBody;
132 }
133
134 /**
135 * @return if isEmail() is true, email from address of email sent through
136 * the gateway. null otherwise
137 */
138 std::string getEmailFrom() {
139 return mEmailFrom;
140 }
141
142 /**
143 * Get protocol identifier.
144 */
145 virtual int getProtocolIdentifier() = 0;
146
147 /**
148 * See TS 23.040 9.2.3.9 returns true if this is a "replace short message"
149 * SMS
150 */
151 virtual bool isReplace() = 0;
152
153 /**
154 * Returns true for CPHS MWI toggle message.
155 *
156 * @return true if this is a CPHS MWI toggle message See CPHS 4.2 section
157 * B.4.2
158 */
159 virtual bool isCphsMwiMessage() = 0;
160
161 /**
162 * returns true if this message is a CPHS voicemail / message waiting
163 * indicator (MWI) clear message
164 */
165 virtual bool isMWIClearMessage() = 0;
166
167 /**
168 * returns true if this message is a CPHS voicemail / message waiting
169 * indicator (MWI) set message
170 */
171 virtual bool isMWISetMessage() = 0;
172
173 /**
174 * returns true if this message is a "Message Waiting Indication Group:
175 * Discard Message" notification and should not be stored.
176 */
177 virtual bool isMwiDontStore() = 0;
178
179 /**
180 * returns the user data section minus the user data header if one was
181 * present.
182 */
183 std::vector<uint8_t> getUserData() {
184 return mUserData;
185 }
186
187 /**
188 * Returns an object representing the user data header
189 *
190 * {@hide}
191 */
192 std::shared_ptr<SmsHeader> getUserDataHeader() {
193 return mUserDataHeader;
194 }
195
196 /**
197 * TODO(cleanup): The term PDU is used in a seemingly non-unique
198 * manner -- for example, what is the difference between this byte
199 * array and the contents of SubmitPdu objects. Maybe a more
200 * illustrative term would be appropriate.
201 */
202
203 /**
204 * Returns the raw PDU for the message.
205 */
206 std::vector<uint8_t> getPdu() {
207 return mPdu;
208 }
209
210 /**
211 * For an SMS-STATUS-REPORT message, this returns the status field from
212 * the status report. This field indicates the status of a previously
213 * submitted SMS, if requested. See TS 23.040, 9.2.3.15 TP-Status for a
214 * description of values.
215 *
216 * @return 0 indicates the previously sent message was received.
217 * See TS 23.040, 9.9.2.3.15 for a description of other possible
218 * values.
219 */
220 virtual int getStatus() = 0;
221
222 /**
223 * Return true iff the message is a SMS-STATUS-REPORT message.
224 */
225 virtual bool isStatusReportMessage() = 0;
226
227 /**
228 * Returns true iff the <code>TP-Reply-Path</code> bit is set in
229 * this message.
230 */
231 virtual bool isReplyPathPresent() = 0;
232
233 /**
234 * Returns the status of the message on the ICC (read, unread, sent, unsent).
235 *
236 * @return the status of the message on the ICC. These are:
237 * SmsManager.STATUS_ON_ICC_FREE
238 * SmsManager.STATUS_ON_ICC_READ
239 * SmsManager.STATUS_ON_ICC_UNREAD
240 * SmsManager.STATUS_ON_ICC_SEND
241 * SmsManager.STATUS_ON_ICC_UNSENT
242 */
243 int getStatusOnIcc() {
244 return mStatusOnIcc;
245 }
246
247 /**
248 * Returns the record index of the message on the ICC (1-based index).
249 * @return the record index of the message on the ICC, or -1 if this
250 * SmsMessage was not created from a ICC SMS EF record.
251 */
252 int getIndexOnIcc() {
253 return mIndexOnIcc;
254 }
255protected:
256 void parseMessageBody();
257 void extractEmailAddressFromMessageBody();
258protected:
259 /** {@hide} The address of the SMSC. May be null */
260 std::string mScAddress;
261
262 /** {@hide} The address of the sender */
263 std::shared_ptr<SmsAddress> mOriginatingAddress = nullptr;
264
265 /** {@hide} The message body as a string. May be null if the message isn't text */
266 std::string mMessageBody;
267
268 /** {@hide} */
269 std::string mPseudoSubject;
270
271 /** {@hide} Non-null if this is an email gateway message */
272 std::string mEmailFrom;
273
274 /** {@hide} Non-null if this is an email gateway message */
275 std::string mEmailBody;
276
277 /** {@hide} */
278 bool mIsEmail = false;
279
280 /** {@hide} Time when SC (service centre) received the message */
281 long mScTimeMillis;
282
283 /** {@hide} The raw PDU of the message */
284 //uint8_t* mPdu = nullptr;
285 //uint32_t mPdu_length = 0;
286 std::vector<uint8_t> mPdu;
287
288 /** {@hide} The raw bytes for the user data section of the message */
289 std::vector<uint8_t> mUserData;
290// uint8_t* mUserData = nullptr;
291// uint32_t mUserData_length = 0;
292
293 /** {@hide} */
294
295 std::shared_ptr<SmsHeader> mUserDataHeader;
296
297 // "Message Waiting Indication Group"
298 // 23.038 Section 4
299 /** {@hide} */
300 bool mIsMwi = false;
301
302 /** {@hide} */
303 bool mMwiSense = false;
304
305 /** {@hide} */
306 bool mMwiDontStore = false;
307
308 /**
309 * Indicates status for messages stored on the ICC.
310 */
311 int mStatusOnIcc = -1;
312
313 /**
314 * Record index of message in the EF.
315 */
316 int mIndexOnIcc = -1;
317
318};
319
320#endif /* SMSMESSAGEBASE_H_ */