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 bool InitSmsServiceProxy(); 33 void ResetSmsServiceProxy(); 34 35 int32_t SetDefaultSmsSlotId(int32_t slotId); 36 int32_t GetDefaultSmsSlotId(); 37 int32_t SendMessage(int32_t slotId, const std::u16string desAddr, const std::u16string scAddr, 38 const std::u16string text, const sptr<ISendShortMessageCallback> &callback, 39 const sptr<IDeliveryShortMessageCallback> &deliveryCallback); 40 int32_t SendMessage(int32_t slotId, const std::u16string desAddr, const std::u16string scAddr, 41 uint16_t port, const uint8_t *data, uint16_t dataLen, const sptr<ISendShortMessageCallback> &callback, 42 const sptr<IDeliveryShortMessageCallback> &deliveryCallback); 43 int32_t SetScAddress(int32_t slotId, const std::u16string &scAddr); 44 int32_t GetScAddress(int32_t slotId, std::u16string &smscAddress); 45 int32_t AddSimMessage(int32_t slotId, const std::u16string &smsc, const std::u16string &pdu, 46 ISmsServiceInterface::SimMessageStatus status); 47 int32_t DelSimMessage(int32_t slotId, uint32_t msgIndex); 48 int32_t UpdateSimMessage(int32_t slotId, uint32_t msgIndex, ISmsServiceInterface::SimMessageStatus newStatus, 49 const std::u16string &pdu, const std::u16string &smsc); 50 int32_t GetAllSimMessages(int32_t slotId, std::vector<ShortMessage> &message); 51 int32_t SetCBConfig(int32_t slotId, bool enable, uint32_t startMessageId, uint32_t endMessageId, uint8_t ranType); 52 bool SetImsSmsConfig(int32_t slotId, int32_t enable); 53 int32_t SplitMessage(const std::u16string &message, std::vector<std::u16string> &splitMessage); 54 int32_t GetSmsSegmentsInfo(int32_t slotId, const std::u16string &message, bool force7BitCode, 55 ISmsServiceInterface::SmsSegmentsInfo &segInfo); 56 int32_t IsImsSmsSupported(int32_t slotId, bool &isSupported); 57 int32_t GetImsShortMessageFormat(std::u16string &format); 58 bool HasSmsCapability(); 59 int32_t CreateMessage(std::string pdu, std::string specification, ShortMessage &message); 60 bool GetBase64Encode(std::string src, std::string &dest); 61 bool GetBase64Decode(std::string src, std::string &dest); 62 bool GetEncodeStringFunc( 63 std::string &encodeString, uint32_t charset, uint32_t valLength, std::string strEncodeString); 64 65 private: 66 std::mutex mutex_; 67 sptr<ISmsServiceInterface> smsServiceInterface_; 68 sptr<IRemoteObject::DeathRecipient> recipient_; 69 }; 70 71 enum class SmsSendResult { 72 /** 73 * Indicates that the SMS message is successfully sent. 74 */ 75 SEND_SMS_SUCCESS = 0, 76 /** 77 * Indicates that sending the SMS message fails due to an unknown reason. 78 */ 79 SEND_SMS_FAILURE_UNKNOWN = 1, 80 /** 81 * Indicates that sending the SMS fails because the modem is powered off. 82 */ 83 SEND_SMS_FAILURE_RADIO_OFF = 2, 84 /** 85 * Indicates that sending the SMS message fails because the network is unavailable 86 * or does not support sending or reception of SMS messages. 87 */ 88 SEND_SMS_FAILURE_SERVICE_UNAVAILABLE = 3 89 }; 90 } // namespace Telephony 91 } // namespace OHOS 92 #endif // SMS_SERVICE_MANAGER_CLIENT_H