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 Configure cell broadcast list in some certain band range. 197 * 198 * @param slotId [in], indicates the card slot index number, 199 * ranging from {@code 0} to the maximum card slot index number supported by the device. 200 * @param messageIds [in], indicates the band ID list. 201 * @param ranType [in], indicates the network type. 202 * @return int32_t, returns {@code 0} if success. 203 */ 204 int32_t SetCBConfigList(int32_t slotId, const std::vector<int32_t>& messageIds, int32_t ranType); 205 206 /** 207 * @brief SetImsSmsConfig enable or disable IMS SMS. 208 * 209 * @param slotId Indicates the card slot index number, 210 * ranging from {@code 0} to the maximum card slot index number supported by the device. 211 * @param enable Indicates enable or disable Ims sms 212 * ranging {@code 0} disable Ims sms {@code 1} enable Ims sms 213 * @return Returns {@code true} if enable or disable Ims Sms success; returns {@code false} otherwise. 214 */ 215 bool SetImsSmsConfig(int32_t slotId, int32_t enable); 216 217 /** 218 * @brief Calculate Sms Message Split Segment count 219 * 220 * @param message [in], indicates input message. 221 * @param splitMessage [out], indicates the split information. 222 * @return int32_t, returns {@code 0} if success. 223 */ 224 int32_t SplitMessage(const std::u16string &message, std::vector<std::u16string> &splitMessage); 225 226 /** 227 * @brief Calculate the Sms Message Segments Info 228 * 229 * @param slotId [in], indicates the card slot index number, 230 * ranging from {@code 0} to the maximum card slot index number supported by the device. 231 * @param message [in], indicates input message. 232 * @param force7BitCode [in], indicates sms encode type, 7bit or not. 233 * @param segInfo [out], indicates output sms segment. 234 * @return int32_t, returns {@code 0} if get sms segments info. 235 */ 236 int32_t GetSmsSegmentsInfo(int32_t slotId, const std::u16string &message, bool force7BitCode, 237 ISmsServiceInterface::SmsSegmentsInfo &segInfo); 238 239 /** 240 * @brief Check Sms Is supported Ims newtwork 241 * 242 * @param slotId Indicates the card slot index number, ranging from {@code 0} to the maximum card 243 * slot index number supported by the device. 244 * @param isSupported Whether ims SMS is supported. 245 * @return int32_t, returns {@code 0} if success. 246 */ 247 int32_t IsImsSmsSupported(int32_t slotId, bool &isSupported); 248 249 /** 250 * @brief Get the Ims Short Message Format 3gpp/3gpp2 251 * 252 * @param format Ims short message format 253 * @return int32_t, returns {@code 0} if success. 254 */ 255 int32_t GetImsShortMessageFormat(std::u16string &format); 256 257 /** 258 * @brief Check whether it is supported Sms Capability 259 * 260 * @return {@code true} if UE has sms capability; returns {@code false} otherwise. 261 */ 262 bool HasSmsCapability(); 263 264 /** 265 * @brief Create a short message 266 * 267 * @param pdu Indicates pdu code, 268 * @param specification Indicates 3gpp or 3gpp2 269 * @param message Indicates a short message object 270 * @return Returns {@code 0} if CreateMessage success 271 */ 272 int32_t CreateMessage(std::string pdu, std::string specification, ShortMessage &message); 273 274 /** 275 * @brief Mms base64 encode 276 * 277 * @param src Indicates source string, 278 * @param dest Indicates destination string 279 * @return Returns {@code true} if encode success; returns {@code false} otherwise 280 */ 281 bool GetBase64Encode(std::string src, std::string &dest); 282 283 /** 284 * @brief Mms base64 decode 285 * 286 * @param src Indicates source string, 287 * @param dest Indicates destination string 288 * @return Returns {@code true} if decode success; returns {@code false} otherwise 289 */ 290 bool GetBase64Decode(std::string src, std::string &dest); 291 292 /** 293 * @brief Get Encode String 294 * 295 * @param encodeString Indicates output string, 296 * @param charset Indicates character set, 297 * @param valLength Indicates input string length, 298 * @param strEncodeString Indicates input string 299 * @return Returns {@code true} if decode success; returns {@code false} otherwise 300 */ 301 bool GetEncodeStringFunc( 302 std::string &encodeString, uint32_t charset, uint32_t valLength, std::string strEncodeString); 303 304 /** 305 * Send a Mms. 306 * @param slotId Indicates the card slot index number, 307 * ranging from {@code 0} to the maximum card slot index number supported by 308 * the device 309 * @param mmsc Indicates service center of mms 310 * @param data Indicates mms pdu byte array 311 * @param ua Indicates mms user agent 312 * @param uaprof Indicates mms user agent profile 313 * @param time Indicates timestamp for hap call function of SDK 314 * @return Returns {@code 0} if send mms success; returns {@code false} otherwise 315 */ 316 int32_t SendMms(int32_t slotId, const std::u16string &mmsc, const std::u16string &data, const std::u16string &ua, 317 const std::u16string &uaprof, int64_t &time); 318 319 /** 320 * Download a Mms. 321 * @param slotId Indicates the card slot index number, 322 * ranging from {@code 0} to the maximum card slot index number supported by 323 * the device 324 * @param mmsc Indicates service center of mms 325 * @param data Indicates mms pdu byte array 326 * @param ua Indicates mms user agent 327 * @param uaprof Indicates mms user agent profile 328 * @return Returns {@code 0} if download mms success; returns {@code false} otherwise 329 */ 330 int32_t DownloadMms(int32_t slotId, const std::u16string &mmsc, std::u16string &data, const std::u16string &ua, 331 const std::u16string &uaprof); 332 333 private: 334 std::mutex mutex_; 335 std::mutex mmsMutex_; 336 sptr<ISmsServiceInterface> smsServiceInterface_; 337 sptr<IRemoteObject::DeathRecipient> recipient_; 338 }; 339 340 /** 341 * @brief Enumerates the result of sending SMS. 342 */ 343 enum class SmsSendResult { 344 /** 345 * Indicates that the SMS message is successfully sent. 346 */ 347 SEND_SMS_SUCCESS = 0, 348 /** 349 * Indicates that sending the SMS message fails due to an unknown reason. 350 */ 351 SEND_SMS_FAILURE_UNKNOWN = 1, 352 /** 353 * Indicates that sending the SMS fails because the modem is powered off. 354 */ 355 SEND_SMS_FAILURE_RADIO_OFF = 2, 356 /** 357 * Indicates that sending the SMS message fails because the network is unavailable 358 * or does not support sending or reception of SMS messages. 359 */ 360 SEND_SMS_FAILURE_SERVICE_UNAVAILABLE = 3 361 }; 362 } // namespace Telephony 363 } // namespace OHOS 364 #endif // SMS_SERVICE_MANAGER_CLIENT_H 365