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_PROXY_H 17 #define SMS_SERVICE_PROXY_H 18 19 #include "i_sms_service_interface.h" 20 21 #include "iremote_object.h" 22 #include "iremote_proxy.h" 23 #include "sms_service_ipc_interface_code.h" 24 25 namespace OHOS { 26 namespace Telephony { 27 class SmsServiceProxy : public IRemoteProxy<ISmsServiceInterface> { 28 public: 29 explicit SmsServiceProxy(const sptr<IRemoteObject> &impl); 30 virtual ~SmsServiceProxy() = default; 31 32 /** 33 * @brief SendMessage 34 * Sends a text or data SMS message. 35 * @param slotId [in] 36 * @param desAddr [in] 37 * @param scAddr [in] 38 * @param text [in] 39 * @param sendCallback [in] 40 * @param deliverCallback [in] 41 * @return int32_t 42 */ 43 int32_t SendMessage(int32_t slotId, const std::u16string desAddr, const std::u16string scAddr, 44 const std::u16string text, const sptr<ISendShortMessageCallback> &sendCallback, 45 const sptr<IDeliveryShortMessageCallback> &deliverCallback, bool isMmsApp = true) override; 46 47 /** 48 * @brief SendMessageWithoutSave 49 * Sends a text or data SMS message without save to database. 50 * @param slotId [in] 51 * @param desAddr [in] 52 * @param scAddr [in] 53 * @param text [in] 54 * @param sendCallback [in] 55 * @param deliverCallback [in] 56 * @return int32_t 57 */ 58 int32_t SendMessageWithoutSave(int32_t slotId, const std::u16string desAddr, const std::u16string scAddr, 59 const std::u16string text, const sptr<ISendShortMessageCallback> &sendCallback, 60 const sptr<IDeliveryShortMessageCallback> &deliverCallback) override; 61 62 /** 63 * @brief SendMessage 64 * Sends a text or data SMS message. 65 * @param slotId [in] 66 * @param desAddr [in] 67 * @param scAddr [in] 68 * @param port [in] 69 * @param data [in] 70 * @param dataLen [in] 71 * @param sendCallback [in] 72 * @param deliverCallback [in]. 73 * @return int32_t 74 */ 75 int32_t SendMessage(int32_t slotId, const std::u16string desAddr, const std::u16string scAddr, uint16_t port, 76 const uint8_t *data, uint16_t dataLen, const sptr<ISendShortMessageCallback> &sendCallback, 77 const sptr<IDeliveryShortMessageCallback> &deliverCallback) override; 78 79 /** 80 * @brief SetSmscAddr 81 * Sets the address for the Short Message Service Center (SMSC) based on a specified slot ID. 82 * @param slotId [in] 83 * @param scAddr [in] 84 * @return int32_t 85 */ 86 int32_t SetSmscAddr(int32_t slotId, const std::u16string &scAddr) override; 87 88 /** 89 * @brief GetSmscAddr 90 * Obtains the SMSC address based on a specified slot ID. 91 * @param slotId [in] 92 * @param smscAddress [out] 93 * @return Interface execution results. 94 */ 95 int32_t GetSmscAddr(int32_t slotId, std::u16string &smscAddress) override; 96 97 /** 98 * @brief AddSimMessage 99 * Add a sms to sim card. 100 * @param slotId [in] 101 * @param smsc [in] 102 * @param pdu [in] 103 * @param status [in] 104 * @return int32_t 105 */ 106 int32_t AddSimMessage( 107 int32_t slotId, const std::u16string &smsc, const std::u16string &pdu, SimMessageStatus status) override; 108 109 /** 110 * @brief DelSimMessage 111 * Delete a sms in the sim card. 112 * @param slotId [in] 113 * @param msgIndex [in] 114 * @return int32_t 115 */ 116 int32_t DelSimMessage(int32_t slotId, uint32_t msgIndex) override; 117 118 /** 119 * @brief UpdateSimMessage 120 * Update a sms in the sim card. 121 * @param slotId [in] 122 * @param msgIndex [in] 123 * @param newStatus [in] 124 * @param pdu [in] 125 * @param smsc [in] 126 * @return int32_t 127 */ 128 int32_t UpdateSimMessage(int32_t slotId, uint32_t msgIndex, SimMessageStatus newStatus, const std::u16string &pdu, 129 const std::u16string &smsc) override; 130 131 /** 132 * @brief GetAllSimMessages 133 * Get sim card all the sms. 134 * @param slotId [in] 135 * @return int32_t 136 */ 137 int32_t GetAllSimMessages(int32_t slotId, std::vector<ShortMessage> &message) override; 138 139 /** 140 * @brief SetCBConfig 141 * Configure a cell broadcast in a certain band range. 142 * @param slotId [in] 143 * @param enable [in] 144 * @param fromMsgId [in] 145 * @param toMsgId [in] 146 * @param netType [in] 147 * @return true 148 * @return false 149 */ 150 int32_t SetCBConfig(int32_t slotId, bool enable, uint32_t fromMsgId, uint32_t toMsgId, uint8_t netType) override; 151 152 /** 153 * @brief SetCBConfigList 154 * Configure cell broadcast list in some certain band range. 155 * @param slotId [in] 156 * @param messageIds [in] 157 * @param ranType [in] 158 * @return true 159 * @return false 160 */ 161 int32_t SetCBConfigList(int32_t slotId, const std::vector<int32_t>& messageIds, int32_t ranType) override; 162 163 /** 164 * @brief SetImsSmsConfig enable or disable IMS SMS. 165 * @param slotId Indicates the card slot index number, 166 * ranging from {@code 0} to the maximum card slot index number supported by the device. 167 * @param enable Indicates enable or disable Ims sms 168 * ranging {@code 0} disable Ims sms {@code 1} enable Ims sms 169 * @return Returns {@code true} if enable or disable Ims Sms success; returns {@code false} otherwise. 170 */ 171 bool SetImsSmsConfig(int32_t slotId, int32_t enable) override; 172 173 /** 174 * @brief SetDefaultSmsSlotId 175 * Set the Default Sms Slot Id To SmsService 176 * @param slotId [in] 177 * @return int32_t 178 */ 179 int32_t SetDefaultSmsSlotId(int32_t slotId) override; 180 181 /** 182 * @brief GetDefaultSmsSlotId 183 * Get the Default Sms Slot Id From SmsService 184 * @return int32_t 185 */ 186 int32_t GetDefaultSmsSlotId() override; 187 188 /** 189 * Get the Default Sms Sim Id From SmsService 190 */ 191 int32_t GetDefaultSmsSimId(int32_t &simId) override; 192 193 /** 194 * @brief SplitMessage 195 * calculate Sms Message Split Segment count 196 * @param message [in] 197 * @return int32_t 198 */ 199 int32_t SplitMessage(const std::u16string &message, std::vector<std::u16string> &splitMessage) override; 200 201 /** 202 * @brief GetSmsSegmentsInfo 203 * calculate the Sms Message Segments Info 204 * @param slotId [in] 205 * @param message [in] 206 * @param force7BitCode [in] 207 * @param info [out] 208 * @return Returns {@code 0} if get sms segments info 209 */ 210 int32_t GetSmsSegmentsInfo(int32_t slotId, const std::u16string &message, bool force7BitCode, 211 ISmsServiceInterface::SmsSegmentsInfo &segInfo) override; 212 213 /** 214 * Check Sms Is supported Ims newtwork 215 * Hide this for inner system use 216 * @param slotId Indicates the card slot index number, ranging from {@code 0} to the maximum card slot index number 217 * supported by the device. 218 * @param isSupported Whether ims SMS is supported. 219 * @return Interface execution results. 220 */ 221 int32_t IsImsSmsSupported(int32_t slotId, bool &isSupported) override; 222 223 /** 224 * @brief GetImsShortMessageFormat 225 * Get the Ims Short Message Format 3gpp/3gpp2 226 * Hide this for inner system use 227 * @return int32_t 228 */ 229 int32_t GetImsShortMessageFormat(std::u16string &format) override; 230 231 /** 232 * @brief HasSmsCapability 233 * Check whether it is supported Sms Capability 234 * @return true 235 * @return false 236 */ 237 bool HasSmsCapability() override; 238 239 /** 240 * create a short message 241 * @param pdu Indicates pdu code, 242 * @param specification Indicates 3gpp or 3gpp2 243 * @param ShortMessage Indicates a short message object 244 * @return Returns {@code 0} if CreateMessage success 245 */ 246 int32_t CreateMessage(std::string pdu, std::string specification, ShortMessage &message) override; 247 248 /** 249 * mms base64 encode 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) override; 255 256 /** 257 * mms base64 decode 258 * @param src Indicates source string, 259 * @param dest Indicates destination string 260 * @return Returns {@code true} if decode success; returns {@code false} otherwise 261 */ 262 bool GetBase64Decode(std::string src, std::string &dest) override; 263 264 /** 265 * Get Encode String 266 * @param encodeString Indicates output string, 267 * @param charset Indicates character set, 268 * @param valLength Indicates input string length, 269 * @param strEncodeString Indicates input string 270 * @return Returns {@code true} if decode success; returns {@code false} otherwise 271 */ 272 bool GetEncodeStringFunc( 273 std::string &encodeString, uint32_t charset, uint32_t valLength, std::string strEncodeString) override; 274 275 /** 276 * Send a mms 277 * @param slotId Indicates the card slot index number, 278 * ranging from {@code 0} to the maximum card slot index number supported by the device 279 * @param mmsc Indicates service center of mms 280 * @param data Indicates file path of mms pdu 281 * @param ua Indicates mms user agent 282 * @param uaprof Indicates mms user agent profile 283 * @param time Indicates milliSecond while get Mms call 284 * @param isMmsApp Indicates whether system message hap call this 285 * @return Returns {@code 0} if send mms success; returns {@code false} otherwise 286 */ 287 int32_t SendMms(int32_t slotId, const std::u16string &mmsc, const std::u16string &data, const std::u16string &ua, 288 const std::u16string &uaprof, int64_t &time, bool isMmsApp = true) override; 289 290 /** 291 * Download a mms 292 * @param slotId Indicates the card slot index number, 293 * ranging from {@code 0} to the maximum card slot index number supported by the device 294 * @param mmsc Indicates service center of mms 295 * @param ua Indicates mms user agent 296 * @param uaprof Indicates mms user agent profile 297 * @return Returns {@code 0} if download mms success; returns {@code false} otherwise 298 */ 299 int32_t DownloadMms(int32_t slotId, const std::u16string &mmsc, std::u16string &data, const std::u16string &ua, 300 const std::u16string &uaprof) override; 301 302 private: 303 static inline BrokerDelegator<SmsServiceProxy> delegator_; 304 sptr<IRemoteObject> localObject_; 305 }; 306 307 class SmsServiceDeathRecipient : public IRemoteObject::DeathRecipient { 308 public: 309 virtual void OnRemoteDied(const wptr<IRemoteObject> &remote); 310 SmsServiceDeathRecipient(); 311 virtual ~SmsServiceDeathRecipient(); 312 static bool GotDeathRecipient(); 313 static bool gotDeathRecipient_; 314 }; 315 } // namespace Telephony 316 } // namespace OHOS 317 #endif // SMS_SERVICE_PROXY_H 318