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