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