• 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         /** class0 Indicates an instant message, which is displayed immediately after being received. */
36         SMS_INSTANT_MESSAGE = 0,
37         /** class1 Indicates an SMS message that can be stored on the device or SIM card based on the storage
38            status. */
39         SMS_OPTIONAL_MESSAGE,
40         /** class2 Indicates an SMS message containing SIM card information, which is to be stored in a SIM card. */
41         SMS_SIM_MESSAGE,
42         /** class3 Indicates an SMS message to be forwarded to another device. */
43         SMS_FORWARD_MESSAGE,
44         /** Indicates an unknown type. */
45         SMS_CLASS_UNKNOWN,
46     };
47 
48     /**
49      * @brief SimMessageStatus
50      * from 3GPP TS 51.011 V4.0.0 (2001-03) section 10.5.3 Parameter Definitions
51      */
52     using SmsSimMessageStatus = enum {
53         SMS_SIM_MESSAGE_STATUS_FREE = 0, /** status free space ON SIM */
54         SMS_SIM_MESSAGE_STATUS_READ = 1, /** REC READ received unread message */
55         SMS_SIM_MESSAGE_STATUS_UNREAD = 3, /** REC UNREAD received read message */
56         SMS_SIM_MESSAGE_STATUS_SENT = 5, /** "STO SENT" stored unsent message (only applicable to SMs) */
57         SMS_SIM_MESSAGE_STATUS_UNSENT = 7, /** "STO UNSENT" stored sent message (only applicable to SMs) */
58     };
59 
60     /**
61      * @brief GetVisibleMessageBody
62      * Obtains the SMS message body
63      * @return std::u16string
64      */
65     std::u16string GetVisibleMessageBody() const;
66 
67     /**
68      * @brief GetVisibleRawAddress
69      * Obtains the address of the sender, which is to be displayed on the UI
70      * @return std::u16string
71      */
72     std::u16string GetVisibleRawAddress() const;
73 
74     /**
75      * @brief GetMessageClass
76      * Obtains the SMS type
77      * @return SmsMessageClass
78      */
79     SmsMessageClass GetMessageClass() const;
80 
81     /**
82      * @brief GetScAddress
83      * Obtains the short message service center (SMSC) address
84      * @return std::u16string
85      */
86     std::u16string GetScAddress() const;
87 
88     /**
89      * @brief GetScTimestamp
90      * Obtains the SMSC timestamp
91      * @return int64_t
92      */
93     int64_t GetScTimestamp() const;
94 
95     /**
96      * @brief IsReplaceMessage
97      * Checks whether the received SMS is a "replace short message"
98      * @return true
99      * @return false
100      */
101     bool IsReplaceMessage() const;
102 
103     /**
104      * @brief GetStatus
105      *
106      * @return int32_t
107      */
108     int32_t GetStatus() const;
109 
110     /**
111      * @brief IsSmsStatusReportMessage
112      *
113      * @return true
114      * @return false
115      */
116     bool IsSmsStatusReportMessage() const;
117 
118     /**
119      * @brief HasReplyPath
120      * Checks whether the received SMS contains "TP-Reply-Path"
121      * @return true
122      * @return false
123      */
124     bool HasReplyPath() const;
125 
126     /**
127      * @brief Get the Icc Message Status object
128      *
129      * @return SmsSimMessageStatus
130      */
131     SmsSimMessageStatus GetIccMessageStatus() const;
132 
133     /**
134      * @brief GetProtocolId
135      *
136      * @return int32_t
137      */
138     int32_t GetProtocolId() const;
139 
140     /**
141      * @brief Get the Pdu
142      *
143      * @return std::vector<unsigned char>
144      */
145     std::vector<unsigned char> GetPdu() const;
146 
147     /**
148      * @brief Create a Message object
149      * Creates an SMS message instance based on the
150      * protocol data unit (PDU) and the specified SMS protocol
151      * @param pdu
152      * @param specification
153      * @return ShortMessage*
154      */
155     static ShortMessage *CreateMessage(std::vector<unsigned char> &pdu, std::u16string specification);
156 
157     /**
158      * @brief Create a Icc Message object
159      * Creates an SMS message instance based on the
160      * ICC protocol data unit (PDU) and the specified SMS protocol
161      * @param pdu
162      * @param specification
163      * @param index
164      * @return ShortMessage
165      */
166     static ShortMessage CreateIccMessage(std::vector<unsigned char> &pdu, std::string specification, int32_t index);
167 
168     /**
169      * @brief GetIndexOnSim
170      *
171      * @return int32_t
172      */
173     int32_t GetIndexOnSim() const;
174 
175     ~ShortMessage() = default;
176     ShortMessage() = default;
177     virtual bool Marshalling(Parcel &parcel) const override;
178     static ShortMessage UnMarshalling(Parcel &parcel);
179 
180 private:
181     bool ReadFromParcel(Parcel &parcel);
182 
183     static constexpr int MIN_ICC_PDU_LEN = 1;
184     std::u16string visibleMessageBody_;
185     std::u16string visibleRawAddress_;
186     SmsMessageClass messageClass_ = SMS_CLASS_UNKNOWN;
187     SmsSimMessageStatus simMessageStatus_ = SMS_SIM_MESSAGE_STATUS_FREE;
188     std::u16string scAddress_;
189     int64_t scTimestamp_ = 0;
190     bool isReplaceMessage_ = false;
191     int32_t status_ = -1;
192     bool isSmsStatusReportMessage_ = false;
193     bool hasReplyPath_ = false;
194     int32_t protocolId_ = -1;
195     std::vector<unsigned char> pdu_;
196     int32_t indexOnSim_ = 0;
197 };
198 } // namespace Telephony
199 } // namespace OHOS
200 #endif