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 NAPI_SMS_H 17 #define NAPI_SMS_H 18 19 #include <codecvt> 20 #include <cstring> 21 #include <locale> 22 #include <memory> 23 #include <string> 24 #include <vector> 25 26 #include "base_context.h" 27 #include "i_sms_service_interface.h" 28 #include "napi/native_api.h" 29 #include "napi/native_node_api.h" 30 #include "napi_util.h" 31 #include "short_message.h" 32 #include "sms_service_manager_client.h" 33 #include "telephony_log_wrapper.h" 34 #include "telephony_types.h" 35 36 namespace OHOS { 37 namespace Telephony { 38 const int32_t DEFAULT_ERROR = -1; 39 const int32_t MESSAGE_UNKNOWN_STATUS = -1; 40 const int32_t MESSAGE_PARAMETER_NOT_MATCH = 0; 41 const int32_t TEXT_MESSAGE_PARAMETER_MATCH = 1; 42 const int32_t RAW_DATA_MESSAGE_PARAMETER_MATCH = 2; 43 constexpr int32_t MAX_TEXT_SHORT_MESSAGE_LENGTH = 4096; 44 constexpr size_t BUFF_LENGTH = 1001; 45 constexpr int32_t PROPERTY_NAME_SIZE = 1001; 46 constexpr int32_t NORMAL_STRING_SIZE = 1001; 47 constexpr int32_t NONE_PARAMETER = 0; 48 constexpr int32_t ONE_PARAMETER = 1; 49 constexpr int32_t TWO_PARAMETERS = 2; 50 constexpr int32_t THREE_PARAMETERS = 3; 51 constexpr int32_t FOUR_PARAMETERS = 4; 52 constexpr int32_t PARAMETERS_INDEX_TWO = 2; 53 constexpr int32_t INVALID_PORT = -1; 54 constexpr int32_t MIN_PORT = 0; 55 constexpr int32_t MAX_PORT = 0xffff; 56 constexpr int32_t CB_RANGE_LIST_MAX_SIZE = 256; 57 58 enum class ShortMessageClass { 59 /** Indicates an unknown type. */ 60 UNKNOWN, 61 /** Indicates an instant message, which is displayed immediately after being received. */ 62 INSTANT_MESSAGE, 63 /** Indicates an SMS message that can be stored on the device or SIM card based on the storage status. */ 64 OPTIONAL_MESSAGE, 65 /** Indicates an SMS message containing SIM card information, which is to be stored in a SIM card. */ 66 SIM_MESSAGE, 67 /** Indicates an SMS message to be forwarded to another device. */ 68 FORWARD_MESSAGE 69 }; 70 71 enum SendSmsResult { 72 /** 73 * Indicates that the SMS message is successfully sent. 74 */ 75 SEND_SMS_SUCCESS = 0, 76 77 /** 78 * Indicates that sending the SMS message fails due to an unknown reason. 79 */ 80 SEND_SMS_FAILURE_UNKNOWN = 1, 81 82 /** 83 * Indicates that sending the SMS fails because the modem is powered off. 84 */ 85 SEND_SMS_FAILURE_RADIO_OFF = 2, 86 87 /** 88 * Indicates that sending the SMS message fails because the network is unavailable 89 * or does not support sending or reception of SMS messages. 90 */ 91 SEND_SMS_FAILURE_SERVICE_UNAVAILABLE = 3 92 }; 93 94 enum RanType { 95 TYPE_GSM = 1, 96 TYPE_CDMA = 2, 97 }; 98 99 struct SendMessageContext : BaseContext { 100 int32_t slotId = DEFAULT_SIM_SLOT_ID; 101 std::u16string destinationHost = u""; 102 std::u16string serviceCenter = u""; 103 std::u16string textContent = u""; 104 std::vector<uint8_t> rawDataContent; 105 napi_ref thisVarRef = nullptr; 106 napi_async_work work = nullptr; 107 napi_ref sendCallbackRef = nullptr; 108 napi_ref deliveryCallbackRef = nullptr; 109 int32_t messageType = MESSAGE_PARAMETER_NOT_MATCH; 110 uint16_t destinationPort = 0; 111 bool isPersist = true; 112 }; 113 114 struct CreateMessageContext : BaseContext { 115 std::vector<unsigned char> pdu {}; 116 std::string specification = ""; 117 ShortMessage *shortMessage = nullptr; 118 }; 119 120 struct SetDefaultSmsSlotIdContext : BaseContext { 121 int32_t slotId = DEFAULT_SIM_SLOT_ID; 122 bool setResult = false; 123 }; 124 125 struct IsImsSmsSupportedContext : BaseContext { 126 int32_t slotId = DEFAULT_SIM_SLOT_ID; 127 bool setResult = false; 128 }; 129 130 struct GetDefaultSmsSlotIdContext : BaseContext { 131 int32_t defaultSmsSlotId = DEFAULT_SIM_SLOT_ID; 132 }; 133 134 struct GetDefaultSmsSimIdContext : BaseContext { 135 int32_t defaultSmsSimId = DEFAULT_SIM_SLOT_ID; 136 }; 137 138 struct SetSmscAddrContext : BaseContext { 139 int32_t slotId = DEFAULT_SIM_SLOT_ID; 140 std::string smscAddr = ""; 141 bool setResult = false; 142 }; 143 144 struct GetSmscAddrContext : BaseContext { 145 int32_t slotId = DEFAULT_SIM_SLOT_ID; 146 std::string smscAddr = ""; 147 }; 148 149 struct AddSimMessageContext : BaseContext { 150 int32_t slotId = DEFAULT_SIM_SLOT_ID; 151 std::string smsc = ""; 152 std::string pdu = ""; 153 int32_t status = MESSAGE_UNKNOWN_STATUS; 154 bool addResult = false; 155 }; 156 157 struct DelSimMessageContext : BaseContext { 158 int32_t slotId = DEFAULT_SIM_SLOT_ID; 159 int32_t msgIndex = DEFAULT_ERROR; 160 bool deleteResult = false; 161 }; 162 163 struct UpdateSimMessageContext : BaseContext { 164 int32_t slotId = DEFAULT_SIM_SLOT_ID; 165 int32_t msgIndex = DEFAULT_ERROR; 166 bool updateResult = false; 167 int32_t newStatus = MESSAGE_UNKNOWN_STATUS; 168 std::string pdu = ""; 169 std::string smsc = ""; 170 }; 171 172 struct GetAllSimMessagesContext : BaseContext { 173 int32_t slotId = DEFAULT_SIM_SLOT_ID; 174 std::vector<ShortMessage> messageArray; 175 }; 176 177 struct CBConfigContext : BaseContext { 178 int32_t slotId = DEFAULT_SIM_SLOT_ID; 179 bool enable = false; 180 int32_t startMessageId = DEFAULT_ERROR; 181 int32_t endMessageId = DEFAULT_ERROR; 182 int32_t ranType = DEFAULT_ERROR; 183 bool setResult = false; 184 }; 185 186 struct CBConfigListContext : BaseContext { 187 int32_t slotId = DEFAULT_SIM_SLOT_ID; 188 std::vector<int32_t> messageIds; 189 int32_t ranType = DEFAULT_ERROR; 190 bool setResult = false; 191 }; 192 193 struct SplitMessageContext : BaseContext { 194 int32_t slotId = DEFAULT_SIM_SLOT_ID; 195 std::string content = ""; 196 std::vector<std::u16string> messageArray; 197 }; 198 199 struct GetSmsSegmentsInfoContext : BaseContext { 200 int32_t slotId = DEFAULT_SIM_SLOT_ID; 201 std::string content = ""; 202 bool force7BitCode = false; 203 int32_t splitCount = 0; 204 int32_t encodeCount = 0; 205 int32_t encodeCountRemaining = 0; 206 ISmsServiceInterface::SmsSegmentsInfo::SmsSegmentCodeScheme scheme; 207 }; 208 209 template<typename T> 210 struct SingleValueContext : BaseContext { 211 T value; 212 }; 213 } // namespace Telephony 214 } // namespace OHOS 215 #endif // NAPI_SMS_H