• 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, bool isMmsApp = true) = 0;
137 
138     /**
139      * @brief Sends a text type SMS message without saving to database.
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 text [in], indicates sms content.
146      * @param sendCallback [in], indicates callback for send out.
147      * @param deliverCallback [in], indicates callback for delivery to destination user.
148      * @return int32_t, returns {@code 0} if success.
149      */
150     virtual int32_t SendMessageWithoutSave(int32_t slotId, const std::u16string desAddr, const std::u16string scAddr,
151         const std::u16string text, const sptr<ISendShortMessageCallback> &sendCallback,
152         const sptr<IDeliveryShortMessageCallback> &deliverCallback) = 0;
153 
154     /**
155      * @brief Sends a data type SMS message.
156      *
157      * @param slotId [in], indicates the card slot index number,
158      * ranging from {@code 0} to the maximum card slot index number supported by the device.
159      * @param desAddr [in], indicates the destination address.
160      * @param scAddr [in], indicates the sms center address.
161      * @param port [in], indicates the port of data sms.
162      * @param data [in], indicates the array of data sms.
163      * @param dataLen [in], indicates the array length of data sms.
164      * @param sendCallback [in], indicates callback for send out.
165      * @param deliverCallback [in], indicates callback for delivery to destination user.
166      * @return int32_t, returns {@code 0} if success.
167      */
168     virtual int32_t SendMessage(int32_t slotId, const std::u16string desAddr, const std::u16string scAddr,
169         uint16_t port, const uint8_t *data, uint16_t dataLen, const sptr<ISendShortMessageCallback> &sendCallback,
170         const sptr<IDeliveryShortMessageCallback> &deliverCallback) = 0;
171 
172     /**
173      * @brief Sets the address for the Short Message Service Center (SMSC) based on a specified slot ID.
174      *
175      * @param slotId [in], indicates the card slot index number,
176      * ranging from {@code 0} to the maximum card slot index number supported by the device.
177      * @param scAddr [in], indicates the sms center address.
178      * @return int32_t, returns {@code 0} if success.
179      */
180     virtual int32_t SetSmscAddr(int32_t slotId, const std::u16string &scAddr) = 0;
181 
182     /**
183      * @brief Obtains the SMSC address based on a specified slot ID.
184      *
185      * @param slotId [in], indicates the card slot index number,
186      * ranging from {@code 0} to the maximum card slot index number supported by the device.
187      * @param smscAddress [out]
188      * @return int32_t, returns {@code 0} if success.
189      */
190     virtual int32_t GetSmscAddr(int32_t slotId, std::u16string &smscAddress) = 0;
191 
192     /**
193      * @brief Add a sms to sim card.
194      *
195      * @param slotId [in], indicates the card slot index number,
196      * ranging from {@code 0} to the maximum card slot index number supported by the device.
197      * @param smsc [in], indicates the short message service center.
198      * @param pdu [in], indicates the protocol data unit of message.
199      * @param status [in], indicates the status of sim message.
200      * @return int32_t, returns {@code 0} if success.
201      */
202     virtual int32_t AddSimMessage(
203         int32_t slotId, const std::u16string &smsc, const std::u16string &pdu, SimMessageStatus status) = 0;
204 
205     /**
206      * @brief Delete a sms in the sim card.
207      *
208      * @param slotId [in], indicates the card slot index number,
209      * ranging from {@code 0} to the maximum card slot index number supported by the device.
210      * @param msgIndex [in], indicates the message index.
211      * @return int32_t, returns {@code 0} if success.
212      */
213     virtual int32_t DelSimMessage(int32_t slotId, uint32_t msgIndex) = 0;
214 
215     /**
216      * @brief Update a sms in the sim card.
217      *
218      * @param slotId [in], indicates the card slot index number,
219      * ranging from {@code 0} to the maximum card slot index number supported by the device.
220      * @param msgIndex [in], indicates the message index.
221      * @param newStatus [in], indicates the new status of the sim message.
222      * @param pdu [in], indicates the protocol data unit of message.
223      * @param smsc [in], indicates the short message service center.
224      * @return int32_t, returns {@code 0} if success.
225      */
226     virtual int32_t UpdateSimMessage(int32_t slotId, uint32_t msgIndex, SimMessageStatus newStatus,
227         const std::u16string &pdu, const std::u16string &smsc) = 0;
228 
229     /**
230      * @brief Get sim card all the sms.
231      *
232      * @param slotId [in], indicates the card slot index number,
233      * ranging from {@code 0} to the maximum card slot index number supported by the device.
234      * @param message [out], indicates all SMS messages of sim card.
235      * @return int32_t, returns {@code 0} if success.
236      */
237     virtual int32_t GetAllSimMessages(int32_t slotId, std::vector<ShortMessage> &message) = 0;
238 
239     /**
240      * @brief Configure a cell broadcast in a certain band range.
241      *
242      * @param slotId [in], indicates the card slot index number,
243      * ranging from {@code 0} to the maximum card slot index number supported by the device.
244      * @param enable [in], indicates whether to enable cell broadcast.
245      * @param fromMsgId [in], indicates the start message ID.
246      * @param toMsgId [in], indicates the end message ID.
247      * @param netType [in], indicates the network type.
248      * @return int32_t, returns {@code 0} if success.
249      */
250     virtual int32_t SetCBConfig(int32_t slotId, bool enable, uint32_t fromMsgId, uint32_t toMsgId, uint8_t netType) = 0;
251 
252     /**
253      * @brief Configure cell broadcast list in some certain band range.
254      *
255      * @param slotId [in], indicates the card slot index number,
256      * ranging from {@code 0} to the maximum card slot index number supported by the device.
257      * @param messageIds [in], indicates the band ID list.
258      * @param ranType [in], indicates the network type.
259      * @return int32_t, returns {@code 0} if success.
260      */
261     virtual int32_t SetCBConfigList(int32_t slotId, const std::vector<int32_t>& messageIds, int32_t ranType) = 0;
262 
263     /**
264      * @brief Enable or disable IMS SMS.
265      *
266      * @param slotId Indicates the card slot index number,
267      * ranging from {@code 0} to the maximum card slot index number supported by the device.
268      * @param enable Indicates enable or disable Ims sms
269      * ranging {@code 0} disable Ims sms {@code 1} enable Ims sms
270      * @return Returns {@code true} if enable or disable Ims Sms success; returns {@code false} otherwise.
271      */
272     virtual bool SetImsSmsConfig(int32_t slotId, int32_t enable) = 0;
273 
274     /**
275      * @brief Set the Default Sms Slot Id To SmsService
276      *
277      * @param slotId [in], indicates the card slot index number,
278      * ranging from {@code 0} to the maximum card slot index number supported by the device.
279      * @return int32_t, returns {@code 0} if success.
280      */
281     virtual int32_t SetDefaultSmsSlotId(int32_t slotId) = 0;
282 
283     /**
284      * @brief Get the Default Sms Slot Id From SmsService
285      *
286      * @return int32_t, returns {@code 0} if success.
287      */
288     virtual int32_t GetDefaultSmsSlotId() = 0;
289 
290     /**
291      * @brief Get the Default Sms Sim Id From SmsService
292      *
293      * @param simId [out], indicates the sms sim index number.
294      * @return int32_t, returns {@code 0} if success.
295      */
296     virtual int32_t GetDefaultSmsSimId(int32_t &simId) = 0;
297 
298     /**
299      * @brief Calculate Sms Message Split Segment count
300      *
301      * @param message [in], indicates input message.
302      * @param splitMessage [out], indicates the split information.
303      * @return int32_t, returns {@code 0} if success.
304      */
305     virtual int32_t SplitMessage(const std::u16string &message, std::vector<std::u16string> &splitMessage) = 0;
306 
307     /**
308      * @brief Calculate the Sms Message Segments Info
309      *
310      * @param slotId [in], indicates the card slot index number,
311      * ranging from {@code 0} to the maximum card slot index number supported by the device.
312      * @param message [in], indicates input message.
313      * @param force7BitCode [in], indicates sms encode type, 7bit or not.
314      * @param info [out], indicates output sms segment.
315      * @return int32_t, returns {@code 0} if get sms segments info.
316      */
317     virtual int32_t GetSmsSegmentsInfo(
318         int32_t slotId, const std::u16string &message, bool force7BitCode, SmsSegmentsInfo &info) = 0;
319 
320     /**
321      * @brief Check Sms Is supported Ims newtwork
322      *
323      * @param slotId Indicates the card slot index number, ranging from {@code 0} to the maximum card slot index number
324      * supported by the device.
325      * @param isSupported Whether ims SMS is supported.
326      * @return int32_t, returns {@code 0} if success.
327      */
328     virtual int32_t IsImsSmsSupported(int32_t slotId, bool &isSupported) = 0;
329 
330     /**
331      * @brief Get the Ims Short Message Format 3gpp/3gpp2
332      *
333      * @param format Ims short message format
334      * @return int32_t, returns {@code 0} if success.
335      */
336     virtual int32_t GetImsShortMessageFormat(std::u16string &format) = 0;
337 
338     /**
339      * @brief Check whether it is supported Sms Capability
340      *
341      * @return true
342      * @return false
343      */
344     virtual bool HasSmsCapability() = 0;
345 
346     /**
347      * @brief Create a short message
348      *
349      * @param pdu Indicates pdu code,
350      * @param specification Indicates 3gpp or 3gpp2
351      * @param message Indicates a short message object
352      * @return Returns {@code 0} if CreateMessage success
353      */
354     virtual int32_t CreateMessage(std::string pdu, std::string specification, ShortMessage &message) = 0;
355 
356     /**
357      * @brief Mms base64 encode
358      *
359      * @param src Indicates source string,
360      * @param dest Indicates destination string
361      * @return Returns {@code true} if encode success; returns {@code false} otherwise
362      */
363     virtual bool GetBase64Encode(std::string src, std::string &dest) = 0;
364 
365     /**
366      * @brief Mms base64 decode
367      *
368      * @param src Indicates source string,
369      * @param dest Indicates destination string
370      * @return Returns {@code true} if decode success; returns {@code false} otherwise
371      */
372     virtual bool GetBase64Decode(std::string src, std::string &dest) = 0;
373 
374     /**
375      * @brief Get Encode String
376      *
377      * @param encodeString Indicates output string,
378      * @param charset Indicates character set,
379      * @param valLength Indicates input string length,
380      * @param strEncodeString Indicates input string
381      * @return Returns {@code true} if decode success; returns {@code false} otherwise
382      */
383     virtual bool GetEncodeStringFunc(
384         std::string &encodeString, uint32_t charset, uint32_t valLength, std::string strEncodeString) = 0;
385 
386     /**
387      * Send a mms
388      * @param slotId Indicates the card slot index number,
389      * ranging from {@code 0} to the maximum card slot index number supported by the device
390      * @param mmsc Indicates service center of mms
391      * @param data Indicates file path of mms pdu
392      * @param ua Indicates mms user agent
393      * @param uaprof Indicates mms user agent profile
394      * @return Returns {@code 0} if send mms success
395      */
396     virtual int32_t SendMms(int32_t slotId, const std::u16string &mmsc, const std::u16string &data,
397         const std::u16string &ua, const std::u16string &uaprof, int64_t &time, bool isMmsApp = false) = 0;
398 
399     /**
400      * Download a mms
401      * @param slotId Indicates the card slot index number,
402      * ranging from {@code 0} to the maximum card slot index number supported by the device
403      * @param mmsc Indicates service center of mms
404      * @param data Indicates file path of mms pdu
405      * @param ua Indicates mms user agent
406      * @param uaprof Indicates mms user agent profile
407      * @return Returns {@code 0} if download mms success
408      */
409     virtual int32_t DownloadMms(int32_t slotId, const std::u16string &mmsc, std::u16string &data,
410         const std::u16string &ua, const std::u16string &uaprof) = 0;
411 
412 public:
413     DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Telephony.ISmsServiceInterface");
414 };
415 } // namespace Telephony
416 } // namespace OHOS
417 #endif
418