• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef SHORT_MESSAGE_H
17 #define SHORT_MESSAGE_H
18 
19 #include <codecvt>
20 #include <locale>
21 #include <memory>
22 
23 #include "parcel.h"
24 
25 namespace OHOS {
26 namespace Telephony {
27 class ShortMessage : public Parcelable {
28 public:
29     /**
30      * @brief SmsMessageClass
31      * Indicates the SMS type.
32      * from 3GPP TS 23.038 V4.3.0 5 CBS Data Coding Scheme.
33      */
34     using SmsMessageClass = enum {
35         /**
36          * class0 Indicates an instant message, which is displayed immediately after being received.
37          */
38         SMS_INSTANT_MESSAGE = 0,
39         /**
40          * class1 Indicates an SMS message that can be stored on the device
41          * or SIM card based on the storage status.
42          */
43         SMS_OPTIONAL_MESSAGE,
44         /**
45          * class2 Indicates an SMS message containing SIM card information,
46          * which is to be stored in a SIM card.
47          */
48         SMS_SIM_MESSAGE,
49         /**
50          * class3 Indicates an SMS message to be forwarded to another device.
51          */
52         SMS_FORWARD_MESSAGE,
53         /**
54          * Indicates an unknown type.
55          */
56         SMS_CLASS_UNKNOWN,
57     };
58 
59     /**
60      * @brief SimMessageStatus
61      * from 3GPP TS 51.011 V4.0.0 (2001-03) section 10.5.3 Parameter Definitions.
62      */
63     using SmsSimMessageStatus = enum {
64         /**
65          * status free space ON SIM.
66          */
67         SMS_SIM_MESSAGE_STATUS_FREE = 0,
68         /**
69          * REC READ received unread message.
70          */
71         SMS_SIM_MESSAGE_STATUS_READ = 1,
72         /**
73          * REC UNREAD received read message.
74          */
75         SMS_SIM_MESSAGE_STATUS_UNREAD = 3,
76         /**
77          * "STO SENT" stored unsent message (only applicable to SMs).
78          */
79         SMS_SIM_MESSAGE_STATUS_SENT = 5,
80         /**
81          * "STO UNSENT" stored sent message (only applicable to SMs).
82          */
83         SMS_SIM_MESSAGE_STATUS_UNSENT = 7,
84     };
85 
86     /**
87      * @brief Obtains the SMS message body.
88      *
89      * @return std::u16string returns the message body.
90      */
91     std::u16string GetVisibleMessageBody() const;
92 
93     /**
94      * @brief Obtains the address of the sender, which is to be displayed on the UI.
95      *
96      * @return std::u16string returns the raw address.
97      */
98     std::u16string GetVisibleRawAddress() const;
99 
100     /**
101      * @brief Obtains the SMS type.
102      *
103      * @return returns SMS type, {@link SmsMessageClass}.
104      */
105     SmsMessageClass GetMessageClass() const;
106 
107     /**
108      * @brief Obtains the short message service center (SMSC) address.
109      *
110      * @param smscAddress SMS center address
111      * @return Interface execution results.
112      */
113     int32_t GetScAddress(std::u16string &smscAddress) const;
114 
115     /**
116      * @brief Obtains the SMSC timestamp.
117      *
118      * @return int64_t returns the SMSC timestamp.
119      */
120     int64_t GetScTimestamp() const;
121 
122     /**
123      * @brief Checks whether the received SMS is a "replace short message".
124      *
125      * @return returns true if the received SMS is a "replace short message", false otherwise.
126      */
127     bool IsReplaceMessage() const;
128 
129     /**
130      * @brief Indicates the SMS message status from the SMS-STATUS-REPORT message sent by the
131      * Short Message Service Center (SMSC).
132      *
133      * @return int32_t returns the SMS message status from the SMS-STATUS-REPORT message.
134      */
135     int32_t GetStatus() const;
136 
137     /**
138      * @brief Indicates whether the current message is SMS-STATUS-REPORT.
139      *
140      * @return Returns true if the current message is SMS-STATUS-REPORT, false otherwise.
141      */
142     bool IsSmsStatusReportMessage() const;
143 
144     /**
145      * @brief Checks whether the received SMS contains "TP-Reply-Path"
146      *
147      * @return returns true if the received SMS contains "TP-Reply-Path", false otherwise.
148      */
149     bool HasReplyPath() const;
150 
151     /**
152      * @brief Get the Icc Message Status object.
153      *
154      * @return returns from 3GPP TS 51.011 V4.0.0 (2001-03) section 10.5.3 Parameter Definitions.
155      * {@link SmsSimMessageStatus}
156      */
157     SmsSimMessageStatus GetIccMessageStatus() const;
158 
159     /**
160      * @brief Get the protocol id used for sending SMS messages.
161      *
162      * @return int32_t returns protocol id used for sending SMS messages
163      */
164     int32_t GetProtocolId() const;
165 
166     /**
167      * @brief Get the protocol data unit.
168      *
169      * @return returns the pdu code
170      */
171     std::vector<unsigned char> GetPdu() const;
172 
173     /**
174      * @brief Create a Message object
175      * Creates an SMS message instance based on the
176      * protocol data unit (PDU) and the specified SMS protocol.
177      *
178      * @param pdu Indicates pdu code.
179      * @param specification Indicates 3gpp or 3gpp2.
180      * @return Returns {@code 0} if CreateMessage success
181      */
182     static int32_t CreateMessage(
183         std::vector<unsigned char> &pdu, std::u16string specification, ShortMessage &messageObj);
184 
185     /**
186      * @brief Create a Icc Message object
187      * Creates an SMS message instance based on the
188      * ICC protocol data unit (PDU) and the specified SMS protocol
189      *
190      * @param pdu Indicates pdu code.
191      * @param specification Indicates 3gpp or 3gpp2.
192      * @param index Indicates the message index.
193      * @return returns a ShortMessage object
194      */
195     static ShortMessage CreateIccMessage(std::vector<unsigned char> &pdu, std::string specification, int32_t index);
196 
197     /**
198      * @brief GetIndexOnSim
199      *
200      * @return int32_t returns the index
201      */
202     int32_t GetIndexOnSim() const;
203 
204     ~ShortMessage() = default;
205     ShortMessage() = default;
206     virtual bool Marshalling(Parcel &parcel) const override;
207     static ShortMessage UnMarshalling(Parcel &parcel);
208     bool ReadFromParcel(Parcel &parcel);
209 
210 public:
211     static constexpr int MIN_ICC_PDU_LEN = 1;
212     std::u16string visibleMessageBody_;
213     std::u16string visibleRawAddress_;
214     SmsMessageClass messageClass_ = SMS_CLASS_UNKNOWN;
215     SmsSimMessageStatus simMessageStatus_ = SMS_SIM_MESSAGE_STATUS_FREE;
216     std::u16string scAddress_;
217     int64_t scTimestamp_ = 0;
218     bool isReplaceMessage_ = false;
219     int32_t status_ = -1;
220     bool isSmsStatusReportMessage_ = false;
221     bool hasReplyPath_ = false;
222     int32_t protocolId_ = -1;
223     std::vector<unsigned char> pdu_;
224     int32_t indexOnSim_ = 0;
225 };
226 } // namespace Telephony
227 } // namespace OHOS
228 #endif