• 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      * @param smscAddress SMS center address
85      * @return Interface execution results
86      */
87     int32_t GetScAddress(std::u16string &smscAddress) const;
88 
89     /**
90      * @brief GetScTimestamp
91      * Obtains the SMSC timestamp
92      * @return int64_t
93      */
94     int64_t GetScTimestamp() const;
95 
96     /**
97      * @brief IsReplaceMessage
98      * Checks whether the received SMS is a "replace short message"
99      * @return true
100      * @return false
101      */
102     bool IsReplaceMessage() const;
103 
104     /**
105      * @brief GetStatus
106      *
107      * @return int32_t
108      */
109     int32_t GetStatus() const;
110 
111     /**
112      * @brief IsSmsStatusReportMessage
113      *
114      * @return true
115      * @return false
116      */
117     bool IsSmsStatusReportMessage() const;
118 
119     /**
120      * @brief HasReplyPath
121      * Checks whether the received SMS contains "TP-Reply-Path"
122      * @return true
123      * @return false
124      */
125     bool HasReplyPath() const;
126 
127     /**
128      * @brief Get the Icc Message Status object
129      *
130      * @return SmsSimMessageStatus
131      */
132     SmsSimMessageStatus GetIccMessageStatus() const;
133 
134     /**
135      * @brief GetProtocolId
136      *
137      * @return int32_t
138      */
139     int32_t GetProtocolId() const;
140 
141     /**
142      * @brief Get the Pdu
143      *
144      * @return std::vector<unsigned char>
145      */
146     std::vector<unsigned char> GetPdu() const;
147 
148     /**
149      * @brief Create a Message object
150      * Creates an SMS message instance based on the
151      * protocol data unit (PDU) and the specified SMS protocol
152      * @param pdu
153      * @param specification
154      * @return Returns {@code 0} if CreateMessage success
155      */
156     static int32_t CreateMessage(
157         std::vector<unsigned char> &pdu, std::u16string specification, ShortMessage &messageObj);
158 
159     /**
160      * @brief Create a Icc Message object
161      * Creates an SMS message instance based on the
162      * ICC protocol data unit (PDU) and the specified SMS protocol
163      * @param pdu
164      * @param specification
165      * @param index
166      * @return ShortMessage
167      */
168     static ShortMessage CreateIccMessage(std::vector<unsigned char> &pdu, std::string specification, int32_t index);
169 
170     /**
171      * @brief GetIndexOnSim
172      *
173      * @return int32_t
174      */
175     int32_t GetIndexOnSim() const;
176 
177     ~ShortMessage() = default;
178     ShortMessage() = default;
179     virtual bool Marshalling(Parcel &parcel) const override;
180     static ShortMessage UnMarshalling(Parcel &parcel);
181     bool ReadFromParcel(Parcel &parcel);
182 
183 public:
184     static constexpr int MIN_ICC_PDU_LEN = 1;
185     std::u16string visibleMessageBody_;
186     std::u16string visibleRawAddress_;
187     SmsMessageClass messageClass_ = SMS_CLASS_UNKNOWN;
188     SmsSimMessageStatus simMessageStatus_ = SMS_SIM_MESSAGE_STATUS_FREE;
189     std::u16string scAddress_;
190     int64_t scTimestamp_ = 0;
191     bool isReplaceMessage_ = false;
192     int32_t status_ = -1;
193     bool isSmsStatusReportMessage_ = false;
194     bool hasReplyPath_ = false;
195     int32_t protocolId_ = -1;
196     std::vector<unsigned char> pdu_;
197     int32_t indexOnSim_ = 0;
198 };
199 } // namespace Telephony
200 } // namespace OHOS
201 #endif