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