1 /*
2  * Copyright (C) 2021-2022 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 NATIVE_COMMON_TYPE_H
17 #define NATIVE_COMMON_TYPE_H
18 
19 #include "call_manager_inner_type.h"
20 #include "napi/native_api.h"
21 #include "napi/native_node_api.h"
22 #include "pac_map.h"
23 #include "telephony_errors.h"
24 
25 namespace OHOS {
26 namespace Telephony {
27 const int16_t BOOL_VALUE_IS_TRUE = 1;
28 const int16_t NATIVE_VERSION = 1;
29 const int16_t NATIVE_FLAGS = 0;
30 const int16_t ZERO_VALUE = 0;
31 const int16_t ONLY_ONE_VALUE = 1;
32 const int16_t TWO_VALUE_LIMIT = 2;
33 const int16_t VALUE_MAXIMUM_LIMIT = 3;
34 const int16_t THREE_VALUE_MAXIMUM_LIMIT = 3;
35 const int16_t FOUR_VALUE_MAXIMUM_LIMIT = 4;
36 const int16_t FIVE_VALUE_MAXIMUM_LIMIT = 5;
37 const int16_t ARRAY_INDEX_FIRST = 0;
38 const int16_t ARRAY_INDEX_SECOND = 1;
39 const int16_t ARRAY_INDEX_THIRD = 2;
40 const int16_t ARRAY_INDEX_FOURTH = 3;
41 const int16_t DATA_LENGTH_ONE = 1;
42 const int16_t DATA_LENGTH_TWO = 2;
43 const int16_t DTMF_DEFAULT_OFF = 10;
44 const int16_t PHONE_NUMBER_MAXIMUM_LIMIT = 255;
45 const int16_t MESSAGE_CONTENT_MAXIMUM_LIMIT = 160;
46 const int16_t NAPI_MAX_TIMEOUT_SECOND = 10;
47 const int16_t UNKNOWN_EVENT = 0;
48 
49 struct AsyncContext {
~AsyncContextAsyncContext50     virtual ~AsyncContext() {}
51     napi_env env = nullptr;
52     napi_async_work work = nullptr;
53     napi_deferred deferred = nullptr;
54     napi_ref callbackRef = nullptr;
55     int32_t callId = 0;
56     int32_t resolved = TELEPHONY_ERROR;
57     char number[kMaxNumberLen + 1] = { 0 };
58     size_t numberLen = 0;
59     napi_value value[VALUE_MAXIMUM_LIMIT] = { 0 };
60     size_t valueLen = 0;
61     int32_t errorCode = TELEPHONY_SUCCESS;
62     int32_t eventId = UNKNOWN_EVENT;
63 };
64 
65 struct DialAsyncContext : AsyncContext {
66     int32_t accountId = -1;
67     int32_t videoState = 0;
68     int32_t dialScene = 0;
69     int32_t dialType = 0;
70 };
71 
72 struct AnswerAsyncContext : AsyncContext {
73     int32_t videoState = 0;
74 };
75 
76 struct BoolResultAsyncContext : AsyncContext {
77     int32_t slotId = 0;
78     bool enabled = false;
79 };
80 
81 struct IntResultAsyncContext : AsyncContext {
82     int32_t result = 0;
83 };
84 
85 struct RejectAsyncContext : AsyncContext {
86     bool isSendSms = false;
87     std::string messageContent = "";
88 };
89 
90 struct ListAsyncContext : AsyncContext {
91     std::vector<std::u16string> listResult {};
92 };
93 
94 struct SupplementAsyncContext : AsyncContext {
95     int32_t slotId = 0;
96     int32_t type = 0;
97     int32_t mode = 0;
98     std::string content = "";
99     bool flag = false;
100     napi_ref thisVar = nullptr;
101 };
102 
103 struct ImsSwitchAsyncContext : AsyncContext {
104     int32_t slotId = 0;
105     bool enabled = false;
106 };
107 
108 struct VoNRSwitchAsyncContext : AsyncContext {
109     int32_t slotId = 0;
110     int32_t state = 0;
111 };
112 
113 struct CallRestrictionAsyncContext : AsyncContext {
114     int32_t slotId = 0;
115     CallRestrictionInfo info;
116     napi_ref thisVar = nullptr;
117 };
118 
119 struct CallBarringPasswordAsyncContext : AsyncContext {
120     int32_t slotId = 0;
121     char oldPassword[kMaxNumberLen + 1] = { 0 };
122     char newPassword[kMaxNumberLen + 1] = { 0 };
123     napi_ref thisVar = nullptr;
124 };
125 
126 struct CallTransferAsyncContext : AsyncContext {
127     int32_t slotId = 0;
128     CallTransferInfo info;
129     napi_ref thisVar = nullptr;
130 };
131 
132 struct UtilsAsyncContext : AsyncContext {
133     int32_t slotId = 0;
134     bool enabled = false;
135     std::u16string formatNumber = u"";
136     std::string code = "";
137 };
138 
139 struct EventCallback {
EventCallbackEventCallback140     EventCallback() : env(nullptr), thisVar(nullptr), callbackRef(nullptr), deferred(nullptr),
141                       callbackBeginTime_(0) {}
142     napi_env env = nullptr;
143     napi_ref thisVar = nullptr;
144     napi_ref callbackRef = nullptr;
145     napi_deferred deferred = nullptr;
146     time_t callbackBeginTime_;
147 };
148 
149 struct AudioAsyncContext : AsyncContext {
150     bool isMute = false;
151     std::string address = "";
152     int32_t deviceType = 0;
153 };
154 
155 struct VideoAsyncContext : AsyncContext {
156     double zoomRatio = 0;
157     int32_t rotation = 0;
158     int32_t callingUid = 0;
159     int32_t callingPid = 0;
160     std::string cameraId = "";
161     std::string surfaceId = "";
162     std::string picturePath = "";
163     std::u16string callingPackage = u"";
164     char path[kMaxNumberLen + 1] = { 0 };
165 };
166 
167 struct OttCallAsyncContext : AsyncContext {
168     std::vector<OttCallDetailsInfo> ottVec {};
169 };
170 
171 struct OttEventAsyncContext : AsyncContext {
172     OttCallEventInfo eventInfo;
173 };
174 
175 struct PostDialAsyncContext : AsyncContext {
176     bool proceed = false;
177 };
178 
179 struct VoIPCallStateAsyncContext : AsyncContext {
180     int32_t state = 0;
181 };
182 
183 struct SendCallUiEventAsyncContext : AsyncContext {
184     std::string eventName = "";
185 };
186 
187 enum CallWaitingStatus {
188     CALL_WAITING_DISABLE = 0,
189     CALL_WAITING_ENABLE,
190 };
191 
192 enum RestrictionStatus {
193     RESTRICTION_DISABLE = 0,
194     RESTRICTION_ENABLE,
195 };
196 
197 enum TransferStatus {
198     TRANSFER_DISABLE = 0,
199     TRANSFER_ENABLE = 1,
200 };
201 
202 struct CallStateWorker {
203     CallAttributeInfo info;
204     EventCallback callback;
205 };
206 
207 struct CallEventWorker {
208     CallEventInfo info;
209     EventCallback callback;
210 };
211 
212 struct CallSupplementWorker {
213     AppExecFwk::PacMap info;
214     EventCallback callback;
215 };
216 
217 struct CallDisconnectedCauseWorker {
218     DisconnectedDetails details;
219     EventCallback callback;
220 };
221 
222 struct CallOttWorker {
223     OttCallRequestId requestId;
224     AppExecFwk::PacMap info;
225     EventCallback callback;
226 };
227 
228 struct MmiCodeWorker {
229     MmiCodeInfo info;
230     EventCallback callback;
231 };
232 
233 struct AudioDeviceWork {
234     AudioDeviceInfo info;
235     EventCallback callback;
236 };
237 
238 struct PostDialDelayWorker {
239     std::string postDialStr;
240     EventCallback callback;
241 };
242 
243 struct ImsCallModeInfoWorker {
244     CallMediaModeInfo callModeInfo;
245     EventCallback callback;
246 };
247 
248 struct CallSessionEventWorker {
249     CallSessionEvent sessionEvent;
250     EventCallback callback;
251 };
252 
253 struct PeerDimensionsWorker {
254     PeerDimensionsDetail peerDimensionsDetail;
255     EventCallback callback;
256 };
257 
258 struct CallDataUsageWorker {
259     int64_t callDataUsage;
260     EventCallback callback;
261 };
262 
263 struct CameraCapbilitiesWorker {
264     CameraCapabilities cameraCapabilities;
265     EventCallback callback;
266 };
267 } // namespace Telephony
268 } // namespace OHOS
269 
270 #endif // NAPI_CALL_MANAGER_TYPES_H
271