• 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_SERVICE_INTERFACE_H
17 #define SMS_SERVICE_INTERFACE_H
18 
19 #include "i_delivery_short_message_callback.h"
20 #include "i_send_short_message_callback.h"
21 #include "iremote_broker.h"
22 #include "short_message.h"
23 
24 namespace OHOS {
25 namespace Telephony {
26 class ISmsServiceInterface : public IRemoteBroker {
27 public:
28     /**
29      * @brief SimMessageStatus
30      * from 3GPP TS 27.005 V4.1.0 (2001-09) section 3 Parameter Definitions
31      */
32     using SimMessageStatus = enum {
33         /**
34          * REC UNREAD received unread message.
35          */
36         SIM_MESSAGE_STATUS_UNREAD = 0,
37 
38         /**
39          * REC READ received read message.
40          */
41         SIM_MESSAGE_STATUS_READ = 1,
42 
43         /**
44          * "STO UNSENT" stored unsent message (only applicable to SMs).
45          */
46         SIM_MESSAGE_STATUS_UNSENT = 2,
47 
48         /**
49          * "STO SENT" stored sent message (only applicable to SMs).
50          */
51         SIM_MESSAGE_STATUS_SENT = 3,
52     };
53 
54     /**
55      * @brief Indicates the encoding scheme of Sms.
56      * from  3GPP TS 23.038 [9] DCS
57      */
58     enum class SmsEncodingScheme {
59         /**
60          * Indicates an unknown encoding scheme.
61          */
62         SMS_ENCODING_UNKNOWN = 0,
63 
64         /**
65          * Indicates that the encoding scheme is 7-digit.
66          */
67         SMS_ENCODING_7BIT,
68 
69         /**
70          * Indicates that the encoding scheme is 8-digit.
71          */
72         SMS_ENCODING_8BIT,
73 
74         /**
75          * Indicates that the encoding schemes is 16-digit.
76          */
77         SMS_ENCODING_16BIT,
78     };
79 
80     /**
81      * @brief Indicates the SMS message segment information.
82      */
83     struct SmsSegmentsInfo {
84         /**
85          * Indicates the split count for the SMS message segment information.
86          */
87         int32_t msgSegCount = 0;
88         /**
89          * Indicates the encoding count for the SMS message segment information.
90          */
91         int32_t msgEncodingCount = 0;
92         /**
93          * Indicates the remaining encoding count for the SMS message segment information.
94          */
95         int32_t msgRemainCount = 0;
96 
97         /**
98          * Defines the encoding scheme of sms segment.
99          */
100         enum class SmsSegmentCodeScheme {
101             /**
102              * Indicates an unknown encoding scheme.
103              */
104             SMS_ENCODING_UNKNOWN = 0,
105             /**
106              * Indicates that the encoding scheme is 7-digit.
107              */
108             SMS_ENCODING_7BIT,
109             /**
110              * Indicates that the encoding scheme is 8-digit.
111              */
112             SMS_ENCODING_8BIT,
113             /**
114              * Indicates that the encoding scheme is 16-digit.
115              */
116             SMS_ENCODING_16BIT,
117         } msgCodeScheme = SmsSegmentCodeScheme::SMS_ENCODING_UNKNOWN;
118     };
119 
120     virtual ~ISmsServiceInterface() = default;
121 
122     /**
123      * @brief Sends a text type SMS message.
124      *
125      * @param slotId [in], indicates the card slot index number,
126      * ranging from {@code 0} to the maximum card slot index number supported by the device.
127      * @param desAddr [in], indicates the destination address.
128      * @param scAddr [in], indicates the sms center address.
129      * @param text [in], indicates sms content.
130      * @param sendCallback [in], indicates callback for send out.
131      * @param deliverCallback [in], indicates callback for delivery to destination user.
132      * @return int32_t, returns {@code 0} if success.
133      */
134     virtual int32_t SendMessage(int32_t slotId, const std::u16string desAddr, const std::u16string scAddr,
135         const std::u16string text, const sptr<ISendShortMessageCallback> &sendCallback,
136         const sptr<IDeliveryShortMessageCallback> &deliverCallback) = 0;
137 
138     /**
139      * @brief Sends a data type SMS message.
140      *
141      * @param slotId [in], indicates the card slot index number,
142      * ranging from {@code 0} to the maximum card slot index number supported by the device.
143      * @param desAddr [in], indicates the destination address.
144      * @param scAddr [in], indicates the sms center address.
145      * @param port [in], indicates the port of data sms.
146      * @param data [in], indicates the array of data sms.
147      * @param dataLen [in], indicates the array length of data sms.
148      * @param sendCallback [in], indicates callback for send out.
149      * @param deliverCallback [in], indicates callback for delivery to destination user.
150      * @return int32_t, returns {@code 0} if success.
151      */
152     virtual int32_t SendMessage(int32_t slotId, const std::u16string desAddr, const std::u16string scAddr,
153         uint16_t port, const uint8_t *data, uint16_t dataLen, const sptr<ISendShortMessageCallback> &sendCallback,
154         const sptr<IDeliveryShortMessageCallback> &deliverCallback) = 0;
155 
156     /**
157      * @brief Sets the address for the Short Message Service Center (SMSC) based on a specified slot ID.
158      *
159      * @param slotId [in], indicates the card slot index number,
160      * ranging from {@code 0} to the maximum card slot index number supported by the device.
161      * @param scAddr [in], indicates the sms center address.
162      * @return int32_t, returns {@code 0} if success.
163      */
164     virtual int32_t SetSmscAddr(int32_t slotId, const std::u16string &scAddr) = 0;
165 
166     /**
167      * @brief Obtains the SMSC address based on a specified slot ID.
168      *
169      * @param slotId [in], indicates the card slot index number,
170      * ranging from {@code 0} to the maximum card slot index number supported by the device.
171      * @param smscAddress [out]
172      * @return int32_t, returns {@code 0} if success.
173      */
174     virtual int32_t GetSmscAddr(int32_t slotId, std::u16string &smscAddress) = 0;
175 
176     /**
177      * @brief Add a sms to sim card.
178      *
179      * @param slotId [in], indicates the card slot index number,
180      * ranging from {@code 0} to the maximum card slot index number supported by the device.
181      * @param smsc [in], indicates the short message service center.
182      * @param pdu [in], indicates the protocol data unit of message.
183      * @param status [in], indicates the status of sim message.
184      * @return int32_t, returns {@code 0} if success.
185      */
186     virtual int32_t AddSimMessage(
187         int32_t slotId, const std::u16string &smsc, const std::u16string &pdu, SimMessageStatus status) = 0;
188 
189     /**
190      * @brief Delete a sms in the sim card.
191      *
192      * @param slotId [in], indicates the card slot index number,
193      * ranging from {@code 0} to the maximum card slot index number supported by the device.
194      * @param msgIndex [in], indicates the message index.
195      * @return int32_t, returns {@code 0} if success.
196      */
197     virtual int32_t DelSimMessage(int32_t slotId, uint32_t msgIndex) = 0;
198 
199     /**
200      * @brief Update a sms in the sim card.
201      *
202      * @param slotId [in], indicates the card slot index number,
203      * ranging from {@code 0} to the maximum card slot index number supported by the device.
204      * @param msgIndex [in], indicates the message index.
205      * @param newStatus [in], indicates the new status of the sim message.
206      * @param pdu [in], indicates the protocol data unit of message.
207      * @param smsc [in], indicates the short message service center.
208      * @return int32_t, returns {@code 0} if success.
209      */
210     virtual int32_t UpdateSimMessage(int32_t slotId, uint32_t msgIndex, SimMessageStatus newStatus,
211         const std::u16string &pdu, const std::u16string &smsc) = 0;
212 
213     /**
214      * @brief Get sim card all the sms.
215      *
216      * @param slotId [in], indicates the card slot index number,
217      * ranging from {@code 0} to the maximum card slot index number supported by the device.
218      * @param message [out], indicates all SMS messages of sim card.
219      * @return int32_t, returns {@code 0} if success.
220      */
221     virtual int32_t GetAllSimMessages(int32_t slotId, std::vector<ShortMessage> &message) = 0;
222 
223     /**
224      * @brief Configure a cell broadcast in a certain band range.
225      *
226      * @param slotId [in], indicates the card slot index number,
227      * ranging from {@code 0} to the maximum card slot index number supported by the device.
228      * @param enable [in], indicates whether to enable cell broadcast.
229      * @param fromMsgId [in], indicates the start message ID.
230      * @param toMsgId [in], indicates the end message ID.
231      * @param netType [in], indicates the network type.
232      * @return int32_t, returns {@code 0} if success.
233      */
234     virtual int32_t SetCBConfig(int32_t slotId, bool enable, uint32_t fromMsgId, uint32_t toMsgId, uint8_t netType) = 0;
235 
236     /**
237      * @brief Enable or disable IMS SMS.
238      *
239      * @param slotId Indicates the card slot index number,
240      * ranging from {@code 0} to the maximum card slot index number supported by the device.
241      * @param enable Indicates enable or disable Ims sms
242      * ranging {@code 0} disable Ims sms {@code 1} enable Ims sms
243      * @return Returns {@code true} if enable or disable Ims Sms success; returns {@code false} otherwise.
244      */
245     virtual bool SetImsSmsConfig(int32_t slotId, int32_t enable) = 0;
246 
247     /**
248      * @brief Set the Default Sms Slot Id To SmsService
249      *
250      * @param slotId [in], indicates the card slot index number,
251      * ranging from {@code 0} to the maximum card slot index number supported by the device.
252      * @return int32_t, returns {@code 0} if success.
253      */
254     virtual int32_t SetDefaultSmsSlotId(int32_t slotId) = 0;
255 
256     /**
257      * @brief Get the Default Sms Slot Id From SmsService
258      *
259      * @return int32_t, returns {@code 0} if success.
260      */
261     virtual int32_t GetDefaultSmsSlotId() = 0;
262 
263     /**
264      * @brief Get the Default Sms Sim Id From SmsService
265      *
266      * @param simId [out], indicates the sms sim index number.
267      * @return int32_t, returns {@code 0} if success.
268      */
269     virtual int32_t GetDefaultSmsSimId(int32_t &simId) = 0;
270 
271     /**
272      * @brief Calculate Sms Message Split Segment count
273      *
274      * @param message [in], indicates input message.
275      * @param splitMessage [out], indicates the split information.
276      * @return int32_t, returns {@code 0} if success.
277      */
278     virtual int32_t SplitMessage(const std::u16string &message, std::vector<std::u16string> &splitMessage) = 0;
279 
280     /**
281      * @brief Calculate the Sms Message Segments Info
282      *
283      * @param slotId [in], indicates the card slot index number,
284      * ranging from {@code 0} to the maximum card slot index number supported by the device.
285      * @param message [in], indicates input message.
286      * @param force7BitCode [in], indicates sms encode type, 7bit or not.
287      * @param info [out], indicates output sms segment.
288      * @return int32_t, returns {@code 0} if get sms segments info.
289      */
290     virtual int32_t GetSmsSegmentsInfo(
291         int32_t slotId, const std::u16string &message, bool force7BitCode, SmsSegmentsInfo &info) = 0;
292 
293     /**
294      * @brief Check Sms Is supported Ims newtwork
295      *
296      * @param slotId Indicates the card slot index number, ranging from {@code 0} to the maximum card slot index number
297      * supported by the device.
298      * @param isSupported Whether ims SMS is supported.
299      * @return int32_t, returns {@code 0} if success.
300      */
301     virtual int32_t IsImsSmsSupported(int32_t slotId, bool &isSupported) = 0;
302 
303     /**
304      * @brief Get the Ims Short Message Format 3gpp/3gpp2
305      *
306      * @param format Ims short message format
307      * @return int32_t, returns {@code 0} if success.
308      */
309     virtual int32_t GetImsShortMessageFormat(std::u16string &format) = 0;
310 
311     /**
312      * @brief Check whether it is supported Sms Capability
313      *
314      * @return true
315      * @return false
316      */
317     virtual bool HasSmsCapability() = 0;
318 
319     /**
320      * @brief Create a short message
321      *
322      * @param pdu Indicates pdu code,
323      * @param specification Indicates 3gpp or 3gpp2
324      * @param message Indicates a short message object
325      * @return Returns {@code 0} if CreateMessage success
326      */
327     virtual int32_t CreateMessage(std::string pdu, std::string specification, ShortMessage &message) = 0;
328 
329     /**
330      * @brief Mms base64 encode
331      *
332      * @param src Indicates source string,
333      * @param dest Indicates destination string
334      * @return Returns {@code true} if encode success; returns {@code false} otherwise
335      */
336     virtual bool GetBase64Encode(std::string src, std::string &dest) = 0;
337 
338     /**
339      * @brief Mms base64 decode
340      *
341      * @param src Indicates source string,
342      * @param dest Indicates destination string
343      * @return Returns {@code true} if decode success; returns {@code false} otherwise
344      */
345     virtual bool GetBase64Decode(std::string src, std::string &dest) = 0;
346 
347     /**
348      * @brief Get Encode String
349      *
350      * @param encodeString Indicates output string,
351      * @param charset Indicates character set,
352      * @param valLength Indicates input string length,
353      * @param strEncodeString Indicates input string
354      * @return Returns {@code true} if decode success; returns {@code false} otherwise
355      */
356     virtual bool GetEncodeStringFunc(
357         std::string &encodeString, uint32_t charset, uint32_t valLength, std::string strEncodeString) = 0;
358 
359     /**
360      * Send a mms
361      * @param slotId Indicates the card slot index number,
362      * ranging from {@code 0} to the maximum card slot index number supported by the device
363      * @param mmsc Indicates service center of mms
364      * @param data Indicates file path of mms pdu
365      * @param ua Indicates mms user agent
366      * @param uaprof Indicates mms user agent profile
367      * @return Returns {@code 0} if send mms success
368      */
369     virtual int32_t SendMms(int32_t slotId, const std::u16string &mmsc, const std::u16string &data,
370         const std::u16string &ua, const std::u16string &uaprof) = 0;
371 
372     /**
373      * Download a mms
374      * @param slotId Indicates the card slot index number,
375      * ranging from {@code 0} to the maximum card slot index number supported by the device
376      * @param mmsc Indicates service center of mms
377      * @param data Indicates file path of mms pdu
378      * @param ua Indicates mms user agent
379      * @param uaprof Indicates mms user agent profile
380      * @return Returns {@code 0} if download mms success
381      */
382     virtual int32_t DownloadMms(int32_t slotId, const std::u16string &mmsc, const std::u16string &data,
383         const std::u16string &ua, const std::u16string &uaprof) = 0;
384 
385 public:
386     DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Telephony.ISmsServiceInterface");
387 };
388 } // namespace Telephony
389 } // namespace OHOS
390 #endif
391