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 Enable or disable IMS SMS. 254 * 255 * @param slotId Indicates the card slot index number, 256 * ranging from {@code 0} to the maximum card slot index number supported by the device. 257 * @param enable Indicates enable or disable Ims sms 258 * ranging {@code 0} disable Ims sms {@code 1} enable Ims sms 259 * @return Returns {@code true} if enable or disable Ims Sms success; returns {@code false} otherwise. 260 */ 261 virtual bool SetImsSmsConfig(int32_t slotId, int32_t enable) = 0; 262 263 /** 264 * @brief Set the Default Sms Slot Id To SmsService 265 * 266 * @param slotId [in], indicates the card slot index number, 267 * ranging from {@code 0} to the maximum card slot index number supported by the device. 268 * @return int32_t, returns {@code 0} if success. 269 */ 270 virtual int32_t SetDefaultSmsSlotId(int32_t slotId) = 0; 271 272 /** 273 * @brief Get the Default Sms Slot Id From SmsService 274 * 275 * @return int32_t, returns {@code 0} if success. 276 */ 277 virtual int32_t GetDefaultSmsSlotId() = 0; 278 279 /** 280 * @brief Get the Default Sms Sim Id From SmsService 281 * 282 * @param simId [out], indicates the sms sim index number. 283 * @return int32_t, returns {@code 0} if success. 284 */ 285 virtual int32_t GetDefaultSmsSimId(int32_t &simId) = 0; 286 287 /** 288 * @brief Calculate Sms Message Split Segment count 289 * 290 * @param message [in], indicates input message. 291 * @param splitMessage [out], indicates the split information. 292 * @return int32_t, returns {@code 0} if success. 293 */ 294 virtual int32_t SplitMessage(const std::u16string &message, std::vector<std::u16string> &splitMessage) = 0; 295 296 /** 297 * @brief Calculate the Sms Message Segments Info 298 * 299 * @param slotId [in], indicates the card slot index number, 300 * ranging from {@code 0} to the maximum card slot index number supported by the device. 301 * @param message [in], indicates input message. 302 * @param force7BitCode [in], indicates sms encode type, 7bit or not. 303 * @param info [out], indicates output sms segment. 304 * @return int32_t, returns {@code 0} if get sms segments info. 305 */ 306 virtual int32_t GetSmsSegmentsInfo( 307 int32_t slotId, const std::u16string &message, bool force7BitCode, SmsSegmentsInfo &info) = 0; 308 309 /** 310 * @brief Check Sms Is supported Ims newtwork 311 * 312 * @param slotId Indicates the card slot index number, ranging from {@code 0} to the maximum card slot index number 313 * supported by the device. 314 * @param isSupported Whether ims SMS is supported. 315 * @return int32_t, returns {@code 0} if success. 316 */ 317 virtual int32_t IsImsSmsSupported(int32_t slotId, bool &isSupported) = 0; 318 319 /** 320 * @brief Get the Ims Short Message Format 3gpp/3gpp2 321 * 322 * @param format Ims short message format 323 * @return int32_t, returns {@code 0} if success. 324 */ 325 virtual int32_t GetImsShortMessageFormat(std::u16string &format) = 0; 326 327 /** 328 * @brief Check whether it is supported Sms Capability 329 * 330 * @return true 331 * @return false 332 */ 333 virtual bool HasSmsCapability() = 0; 334 335 /** 336 * @brief Create a short message 337 * 338 * @param pdu Indicates pdu code, 339 * @param specification Indicates 3gpp or 3gpp2 340 * @param message Indicates a short message object 341 * @return Returns {@code 0} if CreateMessage success 342 */ 343 virtual int32_t CreateMessage(std::string pdu, std::string specification, ShortMessage &message) = 0; 344 345 /** 346 * @brief Mms base64 encode 347 * 348 * @param src Indicates source string, 349 * @param dest Indicates destination string 350 * @return Returns {@code true} if encode success; returns {@code false} otherwise 351 */ 352 virtual bool GetBase64Encode(std::string src, std::string &dest) = 0; 353 354 /** 355 * @brief Mms base64 decode 356 * 357 * @param src Indicates source string, 358 * @param dest Indicates destination string 359 * @return Returns {@code true} if decode success; returns {@code false} otherwise 360 */ 361 virtual bool GetBase64Decode(std::string src, std::string &dest) = 0; 362 363 /** 364 * @brief Get Encode String 365 * 366 * @param encodeString Indicates output string, 367 * @param charset Indicates character set, 368 * @param valLength Indicates input string length, 369 * @param strEncodeString Indicates input string 370 * @return Returns {@code true} if decode success; returns {@code false} otherwise 371 */ 372 virtual bool GetEncodeStringFunc( 373 std::string &encodeString, uint32_t charset, uint32_t valLength, std::string strEncodeString) = 0; 374 375 /** 376 * Send a mms 377 * @param slotId Indicates the card slot index number, 378 * ranging from {@code 0} to the maximum card slot index number supported by the device 379 * @param mmsc Indicates service center of mms 380 * @param data Indicates file path of mms pdu 381 * @param ua Indicates mms user agent 382 * @param uaprof Indicates mms user agent profile 383 * @return Returns {@code 0} if send mms success 384 */ 385 virtual int32_t SendMms(int32_t slotId, const std::u16string &mmsc, const std::u16string &data, 386 const std::u16string &ua, const std::u16string &uaprof, int64_t &time, bool isMmsApp = false) = 0; 387 388 /** 389 * Download a mms 390 * @param slotId Indicates the card slot index number, 391 * ranging from {@code 0} to the maximum card slot index number supported by the device 392 * @param mmsc Indicates service center of mms 393 * @param data Indicates file path of mms pdu 394 * @param ua Indicates mms user agent 395 * @param uaprof Indicates mms user agent profile 396 * @return Returns {@code 0} if download mms success 397 */ 398 virtual int32_t DownloadMms(int32_t slotId, const std::u16string &mmsc, std::u16string &data, 399 const std::u16string &ua, const std::u16string &uaprof) = 0; 400 401 public: 402 DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Telephony.ISmsServiceInterface"); 403 }; 404 } // namespace Telephony 405 } // namespace OHOS 406 #endif 407