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