• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 = 31;
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 = 0;
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     int32_t x = 0;
157     int32_t y = 0;
158     int32_t z = 0;
159     int32_t width = 0;
160     int32_t height = 0;
161     double zoomRatio = 0;
162     int32_t rotation = 0;
163     int32_t callingUid = 0;
164     int32_t callingPid = 0;
165     std::string cameraId = "";
166     std::u16string callingPackage = u"";
167     char path[kMaxNumberLen + 1] = { 0 };
168 };
169 
170 struct OttCallAsyncContext : AsyncContext {
171     std::vector<OttCallDetailsInfo> ottVec {};
172 };
173 
174 struct OttEventAsyncContext : AsyncContext {
175     OttCallEventInfo eventInfo;
176 };
177 
178 struct PostDialAsyncContext : AsyncContext {
179     bool proceed = false;
180 };
181 
182 enum CallWaitingStatus {
183     CALL_WAITING_DISABLE = 0,
184     CALL_WAITING_ENABLE,
185 };
186 
187 enum RestrictionStatus {
188     RESTRICTION_DISABLE = 0,
189     RESTRICTION_ENABLE,
190 };
191 
192 enum TransferStatus {
193     TRANSFER_DISABLE = 0,
194     TRANSFER_ENABLE = 1,
195 };
196 
197 struct CallStateWorker {
198     CallAttributeInfo info;
199     EventCallback callback;
200 };
201 
202 struct CallEventWorker {
203     CallEventInfo info;
204     EventCallback callback;
205 };
206 
207 struct CallSupplementWorker {
208     AppExecFwk::PacMap info;
209     EventCallback callback;
210 };
211 
212 struct CallDisconnectedCauseWorker {
213     DisconnectedDetails details;
214     EventCallback callback;
215 };
216 
217 struct CallOttWorker {
218     OttCallRequestId requestId;
219     AppExecFwk::PacMap info;
220     EventCallback callback;
221 };
222 
223 struct MmiCodeWorker {
224     MmiCodeInfo info;
225     EventCallback callback;
226 };
227 
228 struct AudioDeviceWork {
229     AudioDeviceInfo info;
230     EventCallback callback;
231 };
232 
233 struct PostDialDelayWorker {
234     std::string postDialStr;
235     EventCallback callback;
236 };
237 } // namespace Telephony
238 } // namespace OHOS
239 
240 #endif // NAPI_CALL_MANAGER_TYPES_H
241