• 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 SMS_SERVICE_MANAGER_CLIENT_H
17 #define SMS_SERVICE_MANAGER_CLIENT_H
18 
19 #include <mutex>
20 #include <string>
21 #include <vector>
22 
23 #include "i_sms_service_interface.h"
24 #include "singleton.h"
25 
26 namespace OHOS {
27 namespace Telephony {
28 class SmsServiceManagerClient : public std::enable_shared_from_this<SmsServiceManagerClient> {
29     DECLARE_SINGLETON(SmsServiceManagerClient)
30 public:
31     /**
32      * @brief Init the proxy of SmsService.
33      */
34     bool InitSmsServiceProxy();
35 
36     /**
37      * @brief Reset the proxy of SmsService.
38      */
39     void ResetSmsServiceProxy();
40 
41     /**
42      * @brief Set the Default Sms Slot Id To SmsService
43      *
44      * @param slotId [in], indicates the card slot index number,
45      * ranging from {@code 0} to the maximum card slot index number supported by the device.
46      * @return int32_t, returns {@code 0} if success.
47      */
48     int32_t SetDefaultSmsSlotId(int32_t slotId);
49 
50     /**
51      * @brief Get the Default Sms Slot Id From SmsService
52      *
53      * @return int32_t, returns {@code 0} if success.
54      */
55     int32_t GetDefaultSmsSlotId();
56 
57     /**
58      * @brief Get the Default Sms Sim Id From SmsService
59      *
60      * @param simId [out], indicates the sms sim index number.
61      * @return int32_t, returns {@code 0} if success.
62      */
63     int32_t GetDefaultSmsSimId(int32_t &simId);
64 
65     /**
66      * @brief Sends a text type SMS message.
67      *
68      * @param slotId [in], indicates the card slot index number,
69      * ranging from {@code 0} to the maximum card slot index number supported by the device.
70      * @param desAddr [in], indicates the destination address.
71      * @param scAddr [in], indicates the sms center address.
72      * @param text [in], indicates sms content.
73      * @param sendCallback [in], indicates callback for send out.
74      * @param deliverCallback [in], indicates callback for delivery to destination user.
75      * @return int32_t, returns {@code 0} if success.
76      */
77     int32_t SendMessage(int32_t slotId, const std::u16string desAddr, const std::u16string scAddr,
78         const std::u16string text, const sptr<ISendShortMessageCallback> &callback,
79         const sptr<IDeliveryShortMessageCallback> &deliveryCallback);
80 
81     /**
82      * @brief Sends a data type SMS message.
83      *
84      * @param slotId [in], indicates the card slot index number,
85      * ranging from {@code 0} to the maximum card slot index number supported by the device.
86      * @param desAddr [in], indicates the destination address.
87      * @param scAddr [in], indicates the sms center address.
88      * @param port [in], indicates the port of data sms.
89      * @param data [in], indicates the array of data sms.
90      * @param dataLen [in], indicates the array length of data sms.
91      * @param sendCallback [in], indicates callback for send out.
92      * @param deliverCallback [in], indicates callback for delivery to destination user.
93      * @return int32_t, returns {@code 0} if success.
94      */
95     int32_t SendMessage(int32_t slotId, const std::u16string desAddr, const std::u16string scAddr,
96         uint16_t port, const uint8_t *data, uint16_t dataLen, const sptr<ISendShortMessageCallback> &callback,
97         const sptr<IDeliveryShortMessageCallback> &deliveryCallback);
98 
99     /**
100      * @brief Sends a text type SMS message without saving database.
101      *
102      * @param slotId [in], indicates the card slot index number,
103      * ranging from {@code 0} to the maximum card slot index number supported by the device.
104      * @param desAddr [in], indicates the destination address.
105      * @param scAddr [in], indicates the sms center address.
106      * @param text [in], indicates sms content.
107      * @param callback [in], indicates callback for send out.
108      * @param deliveryCallback [in], indicates callback for delivery to destination user.
109      * @return int32_t, returns {@code 0} if success.
110      */
111     int32_t SendMessageWithoutSave(int32_t slotId, const std::u16string desAddr, const std::u16string scAddr,
112         const std::u16string text, const sptr<ISendShortMessageCallback> &callback,
113         const sptr<IDeliveryShortMessageCallback> &deliveryCallback);
114 
115     /**
116      * @brief Sets the address for the Short Message Service Center (SMSC) based on a specified slot ID.
117      *
118      * @param slotId [in], indicates the card slot index number,
119      * ranging from {@code 0} to the maximum card slot index number supported by the device.
120      * @param scAddr [in], indicates the sms center address.
121      * @return int32_t, returns {@code 0} if success.
122      */
123     int32_t SetScAddress(int32_t slotId, const std::u16string &scAddr);
124 
125     /**
126      * @brief Obtains the SMSC address based on a specified slot ID.
127      *
128      * @param slotId [in], indicates the card slot index number,
129      * ranging from {@code 0} to the maximum card slot index number supported by the device.
130      * @param smscAddress [out]
131      * @return int32_t, returns {@code 0} if success.
132      */
133     int32_t GetScAddress(int32_t slotId, std::u16string &smscAddress);
134 
135     /**
136      * @brief Add a sms to sim card.
137      *
138      * @param slotId [in], indicates the card slot index number,
139      * ranging from {@code 0} to the maximum card slot index number supported by the device.
140      * @param smsc [in], indicates the short message service center.
141      * @param pdu [in], indicates the protocol data unit of message.
142      * @param status [in], indicates the status of sim message.
143      * @return int32_t, returns {@code 0} if success.
144      */
145     int32_t AddSimMessage(int32_t slotId, const std::u16string &smsc, const std::u16string &pdu,
146         ISmsServiceInterface::SimMessageStatus status);
147 
148     /**
149      * @brief Delete a sms in the sim card.
150      *
151      * @param slotId [in], indicates the card slot index number,
152      * ranging from {@code 0} to the maximum card slot index number supported by the device.
153      * @param msgIndex [in], indicates the message index.
154      * @return int32_t, returns {@code 0} if success.
155      */
156     int32_t DelSimMessage(int32_t slotId, uint32_t msgIndex);
157 
158     /**
159      * @brief Update a sms in the sim card.
160      *
161      * @param slotId [in], indicates the card slot index number,
162      * ranging from {@code 0} to the maximum card slot index number supported by the device.
163      * @param msgIndex [in], indicates the message index.
164      * @param newStatus [in], indicates the new status of the sim message.
165      * @param pdu [in], indicates the protocol data unit of message.
166      * @param smsc [in], indicates the short message service center.
167      * @return int32_t, returns {@code 0} if success.
168      */
169     int32_t UpdateSimMessage(int32_t slotId, uint32_t msgIndex, ISmsServiceInterface::SimMessageStatus newStatus,
170         const std::u16string &pdu, const std::u16string &smsc);
171 
172     /**
173      * @brief Get sim card all the sms.
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 message [out], indicates all SMS messages of sim card.
178      * @return int32_t, returns {@code 0} if success.
179      */
180     int32_t GetAllSimMessages(int32_t slotId, std::vector<ShortMessage> &message);
181 
182     /**
183      * @brief Configure a cell broadcast in a certain band range.
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 enable [in], indicates whether to enable cell broadcast.
188      * @param fromMsgId [in], indicates the start message ID.
189      * @param toMsgId [in], indicates the end message ID.
190      * @param netType [in], indicates the network type.
191      * @return int32_t, returns {@code 0} if success.
192      */
193     int32_t SetCBConfig(int32_t slotId, bool enable, uint32_t startMessageId, uint32_t endMessageId, uint8_t ranType);
194 
195     /**
196      * @brief SetImsSmsConfig enable or disable IMS SMS.
197      *
198      * @param slotId Indicates the card slot index number,
199      * ranging from {@code 0} to the maximum card slot index number supported by the device.
200      * @param enable Indicates enable or disable Ims sms
201      * ranging {@code 0} disable Ims sms {@code 1} enable Ims sms
202      * @return Returns {@code true} if enable or disable Ims Sms success; returns {@code false} otherwise.
203      */
204     bool SetImsSmsConfig(int32_t slotId, int32_t enable);
205 
206     /**
207      * @brief Calculate Sms Message Split Segment count
208      *
209      * @param message [in], indicates input message.
210      * @param splitMessage [out], indicates the split information.
211      * @return int32_t, returns {@code 0} if success.
212      */
213     int32_t SplitMessage(const std::u16string &message, std::vector<std::u16string> &splitMessage);
214 
215     /**
216      * @brief Calculate the Sms Message Segments Info
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 message [in], indicates input message.
221      * @param force7BitCode [in], indicates sms encode type, 7bit or not.
222      * @param segInfo [out], indicates output sms segment.
223      * @return int32_t, returns {@code 0} if get sms segments info.
224      */
225     int32_t GetSmsSegmentsInfo(int32_t slotId, const std::u16string &message, bool force7BitCode,
226         ISmsServiceInterface::SmsSegmentsInfo &segInfo);
227 
228     /**
229      * @brief Check Sms Is supported Ims newtwork
230      *
231      * @param slotId Indicates the card slot index number, ranging from {@code 0} to the maximum card
232      * slot index number supported by the device.
233      * @param isSupported Whether ims SMS is supported.
234      * @return int32_t, returns {@code 0} if success.
235      */
236     int32_t IsImsSmsSupported(int32_t slotId, bool &isSupported);
237 
238     /**
239      * @brief Get the Ims Short Message Format 3gpp/3gpp2
240      *
241      * @param format Ims short message format
242      * @return int32_t, returns {@code 0} if success.
243      */
244     int32_t GetImsShortMessageFormat(std::u16string &format);
245 
246     /**
247      * @brief Check whether it is supported Sms Capability
248      *
249      * @return {@code true} if UE has sms capability; returns {@code false} otherwise.
250      */
251     bool HasSmsCapability();
252 
253     /**
254      * @brief Create a short message
255      *
256      * @param pdu Indicates pdu code,
257      * @param specification Indicates 3gpp or 3gpp2
258      * @param message Indicates a short message object
259      * @return Returns {@code 0} if CreateMessage success
260      */
261     int32_t CreateMessage(std::string pdu, std::string specification, ShortMessage &message);
262 
263     /**
264      * @brief Mms base64 encode
265      *
266      * @param src Indicates source string,
267      * @param dest Indicates destination string
268      * @return Returns {@code true} if encode success; returns {@code false} otherwise
269      */
270     bool GetBase64Encode(std::string src, std::string &dest);
271 
272     /**
273      * @brief Mms base64 decode
274      *
275      * @param src Indicates source string,
276      * @param dest Indicates destination string
277      * @return Returns {@code true} if decode success; returns {@code false} otherwise
278      */
279     bool GetBase64Decode(std::string src, std::string &dest);
280 
281     /**
282      * @brief Get Encode String
283      *
284      * @param encodeString Indicates output string,
285      * @param charset Indicates character set,
286      * @param valLength Indicates input string length,
287      * @param strEncodeString Indicates input string
288      * @return Returns {@code true} if decode success; returns {@code false} otherwise
289      */
290     bool GetEncodeStringFunc(
291         std::string &encodeString, uint32_t charset, uint32_t valLength, std::string strEncodeString);
292 
293     /**
294      * Send a Mms.
295      * @param slotId Indicates the card slot index number,
296      * ranging from {@code 0} to the maximum card slot index number supported by
297      * the device
298      * @param mmsc Indicates service center of mms
299      * @param data Indicates mms pdu byte array
300      * @param ua Indicates mms user agent
301      * @param uaprof Indicates mms user agent profile
302      * @param time Indicates timestamp for hap call function of SDK
303      * @return Returns {@code 0} if send mms success; returns {@code false} otherwise
304      */
305     int32_t SendMms(int32_t slotId, const std::u16string &mmsc, const std::u16string &data, const std::u16string &ua,
306         const std::u16string &uaprof, int64_t &time);
307 
308     /**
309      * Download a Mms.
310      * @param slotId Indicates the card slot index number,
311      * ranging from {@code 0} to the maximum card slot index number supported by
312      * the device
313      * @param mmsc Indicates service center of mms
314      * @param data Indicates mms pdu byte array
315      * @param ua Indicates mms user agent
316      * @param uaprof Indicates mms user agent profile
317      * @return Returns {@code 0} if download mms success; returns {@code false} otherwise
318      */
319     int32_t DownloadMms(int32_t slotId, const std::u16string &mmsc, std::u16string &data, const std::u16string &ua,
320         const std::u16string &uaprof);
321 
322 private:
323     std::mutex mutex_;
324     std::mutex mmsMutex_;
325     sptr<ISmsServiceInterface> smsServiceInterface_;
326     sptr<IRemoteObject::DeathRecipient> recipient_;
327 };
328 
329 /**
330  * @brief Enumerates the result of sending SMS.
331  */
332 enum class SmsSendResult {
333     /**
334      * Indicates that the SMS message is successfully sent.
335      */
336     SEND_SMS_SUCCESS = 0,
337     /**
338      * Indicates that sending the SMS message fails due to an unknown reason.
339      */
340     SEND_SMS_FAILURE_UNKNOWN = 1,
341     /**
342      * Indicates that sending the SMS fails because the modem is powered off.
343      */
344     SEND_SMS_FAILURE_RADIO_OFF = 2,
345     /**
346      * Indicates that sending the SMS message fails because the network is unavailable
347      * or does not support sending or reception of SMS messages.
348      */
349     SEND_SMS_FAILURE_SERVICE_UNAVAILABLE = 3
350 };
351 } // namespace Telephony
352 } // namespace OHOS
353 #endif // SMS_SERVICE_MANAGER_CLIENT_H
354