• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 = 31;
46 constexpr int32_t PROPERTY_NAME_SIZE = 32;
47 constexpr int32_t NORMAL_STRING_SIZE = 64;
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 {
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 SetSmscAddrContext : BaseContext {
134     int32_t slotId = DEFAULT_SIM_SLOT_ID;
135     std::string smscAddr = "";
136     bool setResult = false;
137 };
138 
139 struct GetSmscAddrContext : BaseContext {
140     int32_t slotId = DEFAULT_SIM_SLOT_ID;
141     std::string smscAddr = "";
142 };
143 
144 struct AddSimMessageContext : BaseContext {
145     int32_t slotId = DEFAULT_SIM_SLOT_ID;
146     std::string smsc = "";
147     std::string pdu = "";
148     int32_t status = MESSAGE_UNKNOWN_STATUS;
149     bool addResult = false;
150 };
151 
152 struct DelSimMessageContext : BaseContext {
153     int32_t slotId = DEFAULT_SIM_SLOT_ID;
154     int32_t msgIndex = DEFAULT_ERROR;
155     bool deleteResult = false;
156 };
157 
158 struct UpdateSimMessageContext : BaseContext {
159     int32_t slotId = DEFAULT_SIM_SLOT_ID;
160     int32_t msgIndex = DEFAULT_ERROR;
161     bool updateResult = false;
162     int32_t newStatus = MESSAGE_UNKNOWN_STATUS;
163     std::string pdu = "";
164     std::string smsc = "";
165 };
166 
167 struct GetAllSimMessagesContext : BaseContext {
168     int32_t slotId = DEFAULT_SIM_SLOT_ID;
169     std::vector<ShortMessage> messageArray;
170 };
171 
172 struct CBConfigContext : BaseContext {
173     int32_t slotId = DEFAULT_SIM_SLOT_ID;
174     bool enable = false;
175     int32_t startMessageId = DEFAULT_ERROR;
176     int32_t endMessageId = DEFAULT_ERROR;
177     int32_t ranType = DEFAULT_ERROR;
178     bool setResult = false;
179 };
180 
181 struct SplitMessageContext : BaseContext {
182     int32_t slotId = DEFAULT_SIM_SLOT_ID;
183     std::string content = "";
184     std::vector<std::u16string> messageArray;
185 };
186 
187 struct GetSmsSegmentsInfoContext : BaseContext {
188     int32_t slotId = DEFAULT_SIM_SLOT_ID;
189     std::string content = "";
190     bool force7BitCode = false;
191     int32_t splitCount;
192     int32_t encodeCount;
193     int32_t encodeCountRemaining;
194     ISmsServiceInterface::SmsSegmentsInfo::SmsSegmentCodeScheme scheme;
195 };
196 
197 template<typename T>
198 struct SingleValueContext : BaseContext {
199     T value;
200 };
201 } // namespace Telephony
202 } // namespace OHOS
203 #endif // NAPI_SMS_H